Search code examples
javasnmpsnmp4j

How can I traverse SNMP/MIB tree with names and not the numbers (snmp4j)


I am tying to understand snmp; I was able to run the example at http://www.shivasoft.in/blog/java/snmp/create-snmp-client-in-java-using-snmp4j/ to traverse the SNMP tree and get the following results

    1.3.6.1.2.1.1.1.0 : OCTET STRING : Hardware: Intel64 Family  bla bla bla
    1.3.6.1.2.1.1.2.0 : OBJECT IDENTIFIER : 1.3.6.1.4.1.311.1.1.3.1.1
    1.3.6.1.2.1.1.3.0 : TimeTicks : 2 days, 0:56:16.59
    1.3.6.1.2.1.1.4.0 : OCTET STRING : 
    1.3.6.1.2.1.1.5.0 : OCTET STRING : KASHILI-LTP.internal.harmonia.com
    1.3.6.1.2.1.1.6.0 : OCTET STRING : 
    1.3.6.1.2.1.1.7.0 : Integer32 : 76

The numbers in format 1.3.6.1.x.x are going to be the keys into hashmap; I want to make these numbers more user friendly. How would I do that? May be I can pass MIB file to my java code(?). I want the output where all the numbers 1.3.6.x.x are replaced with actual names so that I know what they are (in Linux shell, I can get that effect by passing -m switch to snmpwalk)


Solution

  • The numeric OIDs always have a translation into names, defined in a MIB file, as you've already realized. The snmpwalk command (from net-snmp) is able to load MIB files and display the human-readable variable names. If you walk some more equipment, however, you will soon discover that many machines use MIBs that even net-snmp doesn't know about. You can download those MIB files and load them into net-snmp (see net-snmp documentation).

    Sadly, snmp4j does not support MIB loading in its free version. There seems to be a commercially available library from the same vendor, called SMIPro, which seems like it could do what you need. I haven't tried it, though. They seem to have a trial license available if you want.