|
To add a new row to a SNMP table from the manager, the table should be an SMIv1 table with EntryStatus column defined in it. For more information on EntryStatus, refer SNMP Table Basics.
To add a row to a SNMP table, both High-Level API and Low-Level API can be used.
The following method in the SnmpTable class can be used to add a new row to the table.
|
addRow(boolean Status, String[] oidlist, String[] values) |
where
Status - the entryStatus
oidlist - the OID for the row to be added
values - the values to be set in the row.
For SMIv1 Tables
Let us now add a row to the sample table.
| ID | managerHost | managerPort |
|---|---|---|
|
1 |
localhost |
161 |
|
2 |
server |
1030 |
|
3 |
printer |
8001 |
|
4 |
switch |
8080 |
The essential prerequisite is the table should have the entryStatus column defined in it.
|
ID |
managerHost |
managerPort |
entryStatus |
|---|---|---|---|
|
1 |
localhost |
161 |
1 |
|
2 |
server |
1030 |
1 |
|
3 |
printer |
8001 |
1 |
|
4 |
switch |
8080 |
1 |
In this table to add the fifth row with ID = 5, managerHost =webserver, and managerPort=1080, the following code can be used.
|
SnmpTable table = new SnmpTable(); String oidlist = {"managerHost.5", "managerPort.5", "entryStatus.5"}; String values ={"webserver", "1080", "2"}; table.addRow(true, oidlist, values); |
The EntryStatus value 2 stands for createRequest. After row creation, this value is set to underCreation(3). The modified table is shown below.
|
ID |
managerHost |
managerPort |
entryStatus |
|---|---|---|---|
|
1 |
localhost |
161 |
1 |
|
2 |
server |
1030 |
1 |
|
3 |
printer |
8001 |
1 |
|
4 |
switch |
8080 |
1 |
|
5 |
webserver |
1080 |
underCreation(3) |
The entry remains in this state until the entry is configured, the status is then set to valid(1). If there is a delay in configuring the entry, that is, if the status remain underCreation(3) for a long time, the agent sets the status to invalid(4). View the complete example present in <tutorials/highlevelapi/AddRow.java>.
To retrieve the table data using the low-level API, the SnmpAPI, SnmpSession, and the SnmpPDU classes of the snmp2 package are to be used.
For SMIv1 tables
|
ID |
managerHost |
managerPort |
entryStatus |
|---|---|---|---|
|
3 |
localhost |
161 |
1 |
|
6 |
server |
1030 |
1 |
|
8 |
printer |
8001 |
1 |
|
12 |
switch |
8080 |
1 |
The following code snippet creates SnmpOID[] for the columnOIDs to add a row to this table with index 15 where the numeric OIDs for these columnOIDs are .1.3.6.1.4.1.2.2.1.1,.1.3.6.1.4.1.2.2.1.2, .1.3.6.1.4.1.2.2.1.3, and .1.3.6.1.4.1.2.2.1.4.
|
SnmpOID oid[]=new SnmpOID[4]; oid[1]=new SnmpOID(".1.3.6.1.4.1.2.2.1.1.15"); oid[2]=new SnmpOID(".1.3.6.1.4.1.2.2.1.2.15"); oid[3]=new SnmpOID(".1.3.6.1.4.1.2.2.1.3.15"); oid[4]=new SnmpOID(".1.3.6.1.4.1.2.2.1.4.15"); |
The following code creates the SnmpVar objects with the value and the type of the value.
|
SnmpVar var[]=new SnmpVar[4]; var[0]=SnmpVar.createVariable("15",SnmpAPI.INTEGER); var[1]=SnmpVar.createVariable("switch2",SnmpAPI.STRING); var[2]=SnmpVar.createVariable("9000",SnmpAPI.INTEGER); var[3]=SnmpVar.createVariable("2",SnmpAPI.INTEGER); // the value 2 refers to createRequest. |
The entryStatus value 2 stands for createRequest. The following code creates SnmpVariableBindings using this SnmpOID and SnmpVar and adds it to the PDU using addVariableBinding().
|
for(int i=0;i<oid.length;i++) { SnmpVarBind varbind=new SnmpVarBind(oid[i],var[i]); pdu.addVariableBinding(varbind); } |
Then perform session.syncSend(pdu) to add a new row to the table. Now the entryStatus column value is changed to underCreation(3) by the agent. The entry remains in this state until the entry is configured and then the status is set to valid(1). If there is a delay in configuring the entry, then the agent sets the status to invalid(4).
View the complete example present in <tutorials/lowlevelapi/AddRow.java>.
|