I am trying to implement an SNMP Agent in Java. I use snmp4j library (http://www.snmp4j.org/). Currently, my agent works on localhost/4700. I tried to send snmpget request thanks to the following request:
snmpget -v2c -c public localhost:4700 1.3.6.1.4.1.1.99.5.4.1.3.1.1
but I only get something like "No such instance currently exists at this OID" Here is my problem: I don't know how to create one. I tried to add rows to my MOTable, but it doesn't seem to work.
Here is a summary of my class implementing 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)
}));
}
}
But the requests bellow still don't work.
snmpget -v2c -c public localhost:4700 1.3.6.1.4.1.1.99.5.4.1.3.1.1
snmpget -v2c -c public localhost:4700 1.3.6.1.4.1.1.99.5.4.1.3.1.1.0
snmpget -v2c -c public localhost:4700 1.3.6.1.4.1.1.99.5.4.1.3.1.1.1
I must did not understand how correctly create rows. Could you explain me how I should do ?
Thank you very much !
Just a little precision: I added those lines to my program:
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})));
The first returns: 2 (as expected)
The second returns: 123 (as expected)
The third returns: null... here, I don't understand why !