Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/348.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java中的SNMP代理:如何在MOTable中添加新行_Java_Snmp_Mib_Snmp4j - Fatal编程技术网

Java中的SNMP代理:如何在MOTable中添加新行

Java中的SNMP代理:如何在MOTable中添加新行,java,snmp,mib,snmp4j,Java,Snmp,Mib,Snmp4j,我正在尝试用Java实现SNMP代理。 我使用snmp4j库()。 目前,我的代理在localhost/4700上工作。 由于以下请求,我尝试发送snmpget请求: snmpget -v2c -c public localhost:4700 1.3.6.1.4.1.1.99.5.4.1.3.1.1 但我得到的只是类似“在这个OID上目前不存在这样的实例” 我的问题是:我不知道如何创建一个。我试图在MOTable中添加行,但似乎不起作用 下面是我实现MOGRoup的类的摘要 public cl

我正在尝试用Java实现SNMP代理。 我使用snmp4j库()。 目前,我的代理在localhost/4700上工作。 由于以下请求,我尝试发送snmpget请求:

snmpget -v2c -c public localhost:4700 1.3.6.1.4.1.1.99.5.4.1.3.1.1
但我得到的只是类似“在这个OID上目前不存在这样的实例” 我的问题是:我不知道如何创建一个。我试图在MOTable中添加行,但似乎不起作用

下面是我实现MOGRoup的类的摘要

public class MyMIB 
//--AgentGen BEGIN=_EXTENDS
//--AgentGen END
implements MOGroup 
//--AgentGen BEGIN=_IMPLEMENTS
//--AgentGen END
{
    .
    .
    .

public static final OID oidTableEntry = 
    new OID(new int[] { 1,3,6,1,4,1,1,99,5,4,1,3,1 });
    .
    .
    .

private void createTableEntry(MOFactory moFactory) {
// Index definition
    .
    .
    .

// Table model
tableEntryModel = 
  moFactory.createTableModel(oidTableEntry,
                         tableEntryIndex,
                         tableEntryColumns);
((MOMutableTableModel)tableEntryModel).setRowFactory(
  new TableEntryRowFactory());
tableEntry = 
  moFactory.createTable(oidTableEntry,
                    tableEntryIndex,
                    tableEntryColumns,
                    tableEntryModel);

//Adding rows
ArrayList<Integer> oidMon1List= new ArrayList<Integer>();
oidRow1List = this.getListFromArray(oidTableEntry.getValue());
oidRow1List.add(1);

ArrayList<Integer> oidMon2List= new ArrayList<Integer>();
oidRow2List = this.getListFromArray(oidTableEntry.getValue());
oidRow2List.add(2);

DefaultMOMutableTableModel model =
               (DefaultMOMutableTableModel)tableEntry.getModel();

synchronized(model){
model.addRow(
        model.createRow(
                new OID(getArrayFromList(oidRow1List)), 
                new Variable[]{
                    new Integer32(123)
                    }));

model.addRow(
        model.createRow(
                new OID(getArrayFromList(oidRow2List)), 
                new Variable[]{
                    new Integer32(456)
                    }));   
    }
}
我一定不明白如何正确地创建行。你能解释一下我该怎么做吗

多谢各位

精确一点:我在程序中添加了这些行:

System.out.println("Get row count: " +tableEntryModel.getRowCount());

//first row
System.out.println("TEST1: " +model.getRow(new OID(new int[] {1,3,6,1,4,1,1,99,5,4,1,3,1,1})).getValue(0));
System.out.println("TEST2: " +tableEntry.getValue(new OID(new int[] {1,3,6,1,4,1,1,99,5,4,1,3,1,1,0})));
第一次返回:2(如预期)

第二次返回:123(如预期)


第三个返回:null。。。在这里,我不明白为什么

好吧,我找到了问题所在。 实际上,我的代码是有效的,只是我的请求不正确

                                        | oidColumn 1.3.6.1.4.1.1.99.5.4.1.3.1.1
 oidRow1 1.3.6.1.4.1.1.99.5.4.1.3.1.1   |       oidColumn.oidRow1
 oidRow2 1.3.6.1.4.1.1.99.5.4.1.3.1.2   |       oidColumn.oidRow2
因此,如果我想获得行1的第一个值,我必须提出以下请求:

snmpget -v2c -c public localhost:4700 1.3.6.1.4.1.1.99.5.4.1.3.1.1.1.3.6.1.4.1.1.99.5.4.1.3.1.1

我想说,代码和请求不匹配。我想代码就是问题所在, 因为在SNMP4J代理中,表单元格的实例OID是由

<tableEntryOID>.<columnSubID>.<rowIndexOID>
然后可以使用

snmpget -v2c -c public localhost:4700 1.3.6.1.4.1.1.99.5.4.1.3.1.1.1
model.addRow(       
    model.createRow(       
            new OID(1), new Variable[]{ new Integer32(123) })); 
snmpget -v2c -c public localhost:4700 1.3.6.1.4.1.1.99.5.4.1.3.1.1.1