Agente SNMP em Java: Como adicionar novas linhas no MOTable
Eu estou tentando implementar um agente SNMP em Java. Eu uso a biblioteca snmp4j (http://www.snmp4j.org/). Atualmente, meu agente trabalha em localhost / 4700. Tentei enviar o pedido do snmpget graças ao seguinte pedido:
snmpget -v2c -c public localhost:4700 1.3.6.1.4.1.1.99.5.4.1.3.1.1
mas eu só recebo algo como "Nenhuma instância existe atualmente neste OID" Aqui está o meu problema: eu não sei como criar um. Eu tentei adicionar linhas ao meu MOTable, mas parece não funcionar.
Aqui está um resumo da minha classe implementando o 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)
}));
}
}
Mas os pedidos abaixo ainda não funcionam.
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
Eu não devo entender como criar linhas corretamente. Você poderia me explicar como devo fazer?
Muito obrigado !
Apenas um pouco de precisão: eu adicionei essas linhas ao meu programa:
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})));
O primeiro retorna: 2 (como esperado)
O segundo retorna: 123 (como esperado)
O terceiro retorna: null ... aqui, não entendo porque!