|
To delete a row from an SNMP table, the table should be a SMIv1 table with EntryStatus column defined or a SMIv2 table with RowStatus column defined. For more information on EntryStatus and RowStatus, refer SNMP Table Basics.
To delete a row in an SNMP table, both High-Level API and Low-Level API can be used.
The deleteRow(oid) method in the SnmpTable class can be used for deleting a row in the SNMP table, where oid is the status (either RowStatus or EntryStatus) column name appended by the index value of the row to be deleted.
From SMIv2 tables
The deleteRow(oid)method in the SnmpTable class can be used for deleting a row in the SNMP table. To delete a row in a SNMP table, the rowStatus value should be set to the value of 'Destroy(6)'. The deleteRow method does this internally and we need to give the rowStatus.index oid alone.
The following method in the SnmpTable class is used to delete a row, where table is the instance of the SnmpTable class.
|
table.deleteRow(rowStatus.indexvalue); |
| ID | managerHost | managerPort | rowStatus |
|---|---|---|---|
|
1 |
localhost |
161 |
1 |
|
2 |
server |
1030 |
1 |
|
3 |
printer |
8001 |
1 |
|
4 |
switch |
8080 |
1 |
To delete the fourth row in the sample table, the following piece of code can be used.
|
SnmpTable table = new SnmpTable( ); table.deleteRow(rowStatus.4) |
This deletes the fourth row of the table having the index value "4". Note that the method deleteRow takes the "index value" as the argument and not the serial number of the rows.
| ID | managerHost | managerPort | rowStatus |
|---|---|---|---|
|
3 |
localhost |
161 |
1 |
|
4 |
server |
1030 |
1 |
|
5 |
printer |
8001 |
1 |
|
6 |
switch |
8080 |
1 |
Assuming we have another table with the above index values, the table.deleteRow deletes the second row of the table and not the fourth row.
From SMIv1 tables
To delete a row in a SMIv1 table, the entryStatus value should be set to 'Invalid(4)'. The deleteRow method does this internally and we need to give only the entryStatus.index OID.
To delete the second row with index 4 in the sample table, the following code can be used.
|
table.deleteRow(entryStatus.4); |
View the complete example present in <tutorials/highlevelapi/DeleteRow.java>.
To retrieve the table data using the low level API, the SnmpAPI, SnmpSession and the SnmpPDU classes of the snmp2 package has to be used.
For deleting a row from the table, the RowStatus (for SMIv2 tables) or the EntryStatus (for SMIv1 tables) column should be set to 6 and 4 respectively. For more information on rowStatus and EntryStatus refer the SNMP Table Basics section.
From SMIv2 table
To delete a row in an SNMP table with index 15, the rowStatus value for that row should be set to 'Destroy(6)'.
The following command creates SnmpOID for the columnOID in the sample table where the numeric OIDs for the rowStatus column are.1.3.6.1.4.1.2.2.1.4.
|
SnmpOID oid=new SnmpOID(".1.3.6.1.4.1.2.2.1.4.15"); |
The following command creates the SnmpVar object with the value and the type of the value.
|
SnmpVar var = SnmpVar.createVariable("6",SnmpAPI.INTEGER);//6 refers to destroy. |
The following code snippet creates SnmpVariableBindings using this SnmpOID and SnmpVar and adds it to the PDU using addVariableBinding().
|
SnmpVarBind varbind = new SnmpVarBind(oid,var); pdu.addVariableBinding(varbind); |
Then perform session.syncSend(pdu) to delete the row with index 15 from the table.
From SMIv1 table
The procedure for deleting a row from the SMIv1 table is the same as the that of SMIv2 table. Note that the entryStatus value should be set to the value of 'Invalid(4)' to delete a row in a SMIv1 table.
View the complete example present in <tutorials/lowlevelapi/DeleteRowSMIv2.java>.
|