How to add row to a table?
This page describes how rows with SNMP values can be added to a SNMP4J-Agent table.
To add a row to a DefaultMOTable
-
Make sure that the
MOTableModelused by the table is an instance of theMutableMOTableModel. -
Create the row values as an array of Variable instances:
Variable[] com2secValues = new Variable[] {new OctetString("public"), // community namenew OctetString("publicSecName"), // security namegetAgent().getContextEngineID(), // local engine IDnew OctetString(""), // default context namenew OctetString(), // transport tagnew Integer32(StorageType.nonVolatile), // storage typenew Integer32(RowStatus.active) // row status}; -
Let the SNMP4J-Agent API create a new row based on the provided values and the index sub-OID for the new row. The new will be created by the
MOTableRowFactoryassigned toMOMutableTableModelof thesnmpCommunityTable. If the row factory is not set (for example to aDefaultMOFactoryinstance) then an exception will be thrown:MOTableRow newRow = snmpCommunityTable.createRow(new OctetString("public").toSubIndex(true), com2secValues); -
Add the newly created row to the table:
((MOMutableTableModel)snmpCommunityTable.getModel()).addRow(newRow);