I am using snmp4j.jar. I want to do a snmpwalk on if-table
to get ifDescr
from all the rows. Using netsnmp :
snmpwalk -v2c -c**** -t 1 1.2.3.4 ifDescr
I can get ...
IF-MIB::ifDescr.1 = STRING: ATM0
IF-MIB::ifDescr.2 = STRING: Ethernet0
....
I want to do the same with using snmp4j. Any idea how to do that? I followed some tutorial but I am not clear exactly what to do.
Here is the snippet of the code . Hope it help someone .
public Map<String, InterfaceInfoObject> getTableAsStrings(OID[] oids, String communityString) {
TableUtils tUtils = new TableUtils(snmp, new DefaultPDUFactory());
List<TableEvent> events = tUtils.getTable(getTarget(), oids, null, null);
Map<String,InterfaceInfoObject> indexMap = new LinkedHashMap<String,InterfaceInfoObject>();
for (TableEvent event : events) {
if(event.isError()) {
throw new RuntimeException(event.getErrorMessage());
}
for(VariableBinding vb: event.getColumns()) {
InterfaceInfoObject infterfaceInfo = new InterfaceInfoObject();
String oid = vb.getOid().toString();
String index = event.getIndex().toString();
String colValue = vb.getVariable().toString();
if(indexMap.containsKey(index)){
getInferfaceObjectAndsetValues(indexMap, oid, index, colValue);
}else{
putInferfaceInfoObjInMap(indexMap, infterfaceInfo, oid, index,
colValue);
}
}
}
return indexMap;