0

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.

k1eran
  • 4,492
  • 8
  • 50
  • 73
harpal18
  • 137
  • 1
  • 9
  • 20
  • If you followed a tutorial, please provide a link to it and paste here the code you are using. Also, please describe 1. what you expect the code to do, and 2. what it actually seems to do. – Jolta Jan 08 '15 at 01:19
  • Thank @Jolta ..but i figured it out using http://www.snmp4j.org/doc/org/snmp4j/util/TableUtils.html – harpal18 Jan 09 '15 at 06:36

1 Answers1

1

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;
harpal18
  • 137
  • 1
  • 9
  • 20