2

I'm new to snmp4j. I used the sample code in [1] to extract some meaningful information from a SNMP stream.

In the sample code, oid and value of the variable is extracted, but the value comes without its units. For example

,oid 1.3.6.1.4.1.2021.4.6.0 (SNMP-MIB::memAvailReal.0) gives the value 13385068 without its unit KB. Is there a way to get the value with its units in snmp4j?

Can somebody please look in to this?

[1]https://gist.github.com/akirad/5597203

Sajini
  • 59
  • 1
  • 2
  • 5

1 Answers1

3

I believe that the value you're retrieving is simply a SCALAR of type Integer32.

The description in the MIB is "Available Real/Physical Memory Space on the host."

It doesn't even specify the units there, so I don't think there's anywhere to retrieve the units data from. Happy to be corrected by someone if I'm wrong though!

memAvailReal OBJECT-TYPE
    SYNTAX  Integer32
    MAX-ACCESS  read-only
    STATUS  current
    DESCRIPTION
    "Available Real/Physical Memory Space on the host."
    ::= { memory 6 }

In other words, its a numeric value and the descriptive metadata from the MIB file doesn't even reveal the units so there's no where to get that info from in code.

Edit:

I googled around some more and found another version of the UCD-SNMP-MIB with this definition:

memAvailReal OBJECT-TYPE
    SYNTAX  Integer32
    UNITS       "kB"
    MAX-ACCESS  read-only
    STATUS  current
    DESCRIPTION
    "The amount of real/physical memory currently unused
         or available."
    ::= { memory 6 }

So the info is available in this version of the MIB...

It looks like you can probably make use of this information using the SmiManager class:

http://www.snmp4j.org/smi/doc/com/snmp4j/smi/SmiManager.html

https://oosnmp.net/confluence/pages/viewpage.action?pageId=5799973

But integrating SmiManager into your application might not be trivial (and on looking into it a little bit further , it appears that there's a licence required to use SmiManager!).

For my own little project I'm pre-parsing MIBs and storing the parts of them I need in my NoSQL database rather than including full-blown MIB parsing support. That way I can have a dict of metadata associated with every OID that is easier to access/update and manipulate.

Hope that helps.

Matt Coubrough
  • 3,739
  • 2
  • 26
  • 40
  • Thanx Matt, but when you invoke the snmpwalk command in terminal it shows the units as well. e.g. UCD-SNMP-MIB::memAvailReal.0 = INTEGER: 9799456 kB How this is possible? – Sajini May 26 '14 at 08:25
  • @Sajini Then I'll vote up your question! I really want to know too. Normally a MIB has a UNITS entry, but when you posted I googled for your MIB and what I posted is what I found... do you have the relevant MIB? – Matt Coubrough May 26 '14 at 08:26
  • @Sajini I found another version of the MIB online which includes a UNITS definition, so have updated my answer. – Matt Coubrough May 26 '14 at 09:10