Translating pysnmp oids to human readable strings

SpamMePlease PleasePlease spankthespam at
Fri Mar 6 12:58:58 CET 2009

On Fri, Mar 6, 2009 at 11:37 AM, SpamMePlease PleasePlease
<spankthespam at> wrote:
> On Fri, Mar 6, 2009 at 9:03 AM, Shantanu Joshi <weemadarthur at> wrote:
>> SpamMePlease PleasePlease <spankthespam at> writes:
>>> On Fri, Mar 6, 2009 at 6:56 AM, Shantanu Joshi <weemadarthur at> wrote:
>>>> You need to parse the MIB file to get the human-readable names
>>>> corresponding to the OIDs. The pysnmp library already provides this
>>>> functionality. I haven't used this feature myself (I mainly use pysnmp
>>>> to automate SNMP walk requests, like the one in your code), but the
>>>> documentation at found the below example at
>>>>>>> from pysnmp.smi import builder, view
>>>>>>> mibBuilder = builder.MibBuilder().loadModules('SNMPv2-MIB')
>>>>>>> mibViewController = view.MibViewController(mibBuilder)
>>>>>>> oid,label,suffix = mibViewController.getNodeName((1,3,6,1,2,'mib-2',1,'sysDescr'))
>>>>>>> print oid
>>>> (1, 3, 6, 1, 2, 1, 1, 1)
>>>>>>> print label
>>>> ('iso', 'org', 'dod', 'internet', 'mgmt', 'mib-2', 'system', 'sysDescr')
>>>>>>> print suffix
>>>> ()
>>>> --
>>> Yes, I have seen that, but I cant get it working as expected (or it
>>> doesent to what expected at all). I cant make it return values like:
>>> jnxBgpM2PeerIdentifier.0.ipv4. (the one
>>> of many I got from snmpwalk) but instead I am getting bunch of words
>>> like iso, internet, mgmt, which is no way close to desired effect.
>>> Still no luck - anybody with a clue?
>> Every node in a MIB file is rooted at
>> jnxBgpM2PeerIdentifier has OID .
>> (if I've got the right MIB, I searched for jnxBgpM2PeerIdentifier on
>> Google and got the BGP4-V2-MIB-JUNIPER MIB file). The .
>> corresponds to, so you can
>> safely skip that part. The next value 2636, is uniquely assigned to
>> Juniper, and the rest is up to whatever scheme Juniper uses to prepare
>> mibs.
>> The pysnmp library doesn't know anything about BGP4-V2-MIB-JUNIPER MIB,
>> since it is not one of the standard MIBS, so it will parse everything up
>> to what is defined in the standard mibs and return the rest in numeric
>> form. There was a paragraph on the page I linked which described how to
>> prepare MIB files for consumption by pysnmp. Did you try that?
>> --
> Thats a good one, sir! I managed to create out from
> /usr/share/snmp/mibs/jnx-bgpmib2.txt that contains the mibs snmpwalk
> found for me. Now, in what way can I 'feed' the pysnmp with this new
> file and how to ask it kindly to convert these number strings into
> nice readable strings?
> --
> --------------------
> Spank The Spam!

I actually tried to load the new file with following code:

print builder.MibBuilder().getMibPath()
mibBuilder = builder.MibBuilder().loadModules('jnx-bgpmib2')

but I am experiencing the error:

rivendell # python
Traceback (most recent call last):
  File "", line 7, in ?
    mibBuilder = builder.MibBuilder().loadModules('jnx-bgpmib2')
  File "//usr/lib/python2.4/site-packages/pysnmp/v4/smi/",
line 82, in loadModules
    raise error.SmiError(
pysnmp.smi.error.SmiError: MIB module
load error: MIB file ".py" not found in search path
rivendell# ls -lA
-rw-r--r-- 1 root root 2687 Mar  6 06:50

Any clue what about is done wrong?

Spank The Spam!

More information about the Python-list mailing list