Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Translating pysnmp oids to human readable strings

Reply
Thread Tools

Translating pysnmp oids to human readable strings

 
 
SpamMePlease PleasePlease
Guest
Posts: n/a
 
      03-06-2009
On Fri, Mar 6, 2009 at 9:03 AM, Shantanu Joshi <(E-Mail Removed)> wrote:
>
> SpamMePlease PleasePlease <(E-Mail Removed)> writes:
>
>> On Fri, Mar 6, 2009 at 6:56 AM, Shantanu Joshi <(E-Mail Removed)> 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
>>> http://pysnmp.sourceforge.net/docs/4...l#MIB-SERVICES.
>>>
>>>
>>>>>> 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
>>> ()
>>> --
>>> http://mail.python.org/mailman/listinfo/python-list
>>>

>>
>> 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.38.101.161.119.1.38. 101.161.118 (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 iso.org.dod.internet.
> jnxBgpM2PeerIdentifier has OID .1.3.6.1.4.1.2636.5.1.1.2.1.1.1.1
> (if I've got the right MIB, I searched for jnxBgpM2PeerIdentifier on
> Google and got the BGP4-V2-MIB-JUNIPER MIB file). The .1.3.6.1.4.1
> corresponds to iso.org.dod.internet.private.enterprises, 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?
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>


Thats a good one, sir! I managed to create jnx-bgpmib2.py 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!
 
Reply With Quote
 
 
 
 
Shantanu Joshi
Guest
Posts: n/a
 
      03-06-2009

SpamMePlease PleasePlease <(E-Mail Removed)> writes:

>
> 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 snmp.py
> ('/usr/lib/python2.4/site-packages/pysnmp/v4/smi/mibs/instances',
> '/usr/lib/python2.4/site-packages/pysnmp/v4/smi/mibs')
> Traceback (most recent call last):
> File "snmp.py", line 7, in ?
> mibBuilder = builder.MibBuilder().loadModules('jnx-bgpmib2')
> File "//usr/lib/python2.4/site-packages/pysnmp/v4/smi/builder.py",
> line 82, in loadModules
> raise error.SmiError(
> pysnmp.smi.error.SmiError: MIB module
> "/usr/lib/python2.4/site-packages/pysnmp/v4/smi/mibs/instances/jnx-bgpmib2.py"
> load error: MIB file ".py" not found in search path
> rivendell# ls -lA
> /usr/lib/python2.4/site-packages/pysnmp/v4/smi/mibs/instances/jnx-bgpmib2.py
> -rw-r--r-- 1 root root 2687 Mar 6 06:50
> /usr/lib/python2.4/site-packages/pysnmp/v4/smi/mibs/instances/jnx-bgpmib2.py
>
> Any clue what about is done wrong?


The pysnmp library is not able to find your generated file. Either copy
your generated file to /usr/lib/python2.4/site-packages/pysnmp/v4/smi/mibs/instances
or call setMibPath on the mibBuilder instance before calling loadModules
to add the current directory (or whatever directory holds your generated
file).
 
Reply With Quote
 
 
 
 
SpamMePlease PleasePlease
Guest
Posts: n/a
 
      03-07-2009
On Fri, Mar 6, 2009 at 2:14 PM, Shantanu Joshi <(E-Mail Removed)> wrote:
>
> SpamMePlease PleasePlease <(E-Mail Removed)> writes:
>
>>
>> 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 snmp.py
>> ('/usr/lib/python2.4/site-packages/pysnmp/v4/smi/mibs/instances',
>> '/usr/lib/python2.4/site-packages/pysnmp/v4/smi/mibs')
>> Traceback (most recent call last):
>> * File "snmp.py", line 7, in ?
>> * * mibBuilder = builder.MibBuilder().loadModules('jnx-bgpmib2')
>> * File "//usr/lib/python2.4/site-packages/pysnmp/v4/smi/builder.py",
>> line 82, in loadModules
>> * * raise error.SmiError(
>> pysnmp.smi.error.SmiError: MIB module
>> "/usr/lib/python2.4/site-packages/pysnmp/v4/smi/mibs/instances/jnx-bgpmib2.py"
>> load error: MIB file ".py" not found in search path
>> rivendell# ls -lA
>> /usr/lib/python2.4/site-packages/pysnmp/v4/smi/mibs/instances/jnx-bgpmib2.py
>> -rw-r--r-- 1 root root 2687 Mar *6 06:50
>> /usr/lib/python2.4/site-packages/pysnmp/v4/smi/mibs/instances/jnx-bgpmib2.py
>>
>> Any clue what about is done wrong?

>
> The pysnmp library is not able to find your generated file. Either copy
> your generated file to /usr/lib/python2.4/site-packages/pysnmp/v4/smi/mibs/instances
> or call setMibPath on the mibBuilder instance before calling loadModules
> to add the current directory (or whatever directory holds your generated
> file).
> --
> http://mail.python.org/mailman/listinfo/python-list
>


The thing is that I have copied the file (as you may see, I did 'ls
-lA' on it. If the file wasnt there, the error message was different.
Also, the setMibPath doesent seem to work, as I tried to set up it to
any value, and right after that I was performing getMibPath which was
giving me unchanged default paths. Keep in mind, that whole path setu
up code has executed without any error.
So, what is correct and working way to supply my code with that
converted mib file?

--
--------------------
Spank The Spam!
 
Reply With Quote
 
rdmurray@bitdance.com
Guest
Posts: n/a
 
      03-07-2009
SpamMePlease PleasePlease <(E-Mail Removed)> wrote:
> On Fri, Mar 6, 2009 at 2:14 PM, Shantanu Joshi <(E-Mail Removed)> wrote:
> >
> > SpamMePlease PleasePlease <(E-Mail Removed)> writes:
> >
> >> 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 snmp.py
> >> ('/usr/lib/python2.4/site-packages/pysnmp/v4/smi/mibs/instances',
> >> '/usr/lib/python2.4/site-packages/pysnmp/v4/smi/mibs')
> >> Traceback (most recent call last):
> >> * File "snmp.py", line 7, in ?
> >> * * mibBuilder = builder.MibBuilder().loadModules('jnx-bgpmib2')
> >> * File "//usr/lib/python2.4/site-packages/pysnmp/v4/smi/builder.py",
> >> line 82, in loadModules
> >> * * raise error.SmiError(
> >> pysnmp.smi.error.SmiError: MIB module
> >> "/usr/lib/python2.4/site-packages/pysnmp/v4/smi/mibs/instances/jnx-bgpmib2.py"
> >> load error: MIB file ".py" not found in search path
> >> rivendell# ls -lA
> >> /usr/lib/python2.4/site-packages/pysnmp/v4/smi/mibs/instances/jnx-bgpmib2.py
> >> -rw-r--r-- 1 root root 2687 Mar *6 06:50
> >> /usr/lib/python2.4/site-packages/pysnmp/v4/smi/mibs/instances/jnx-bgpmib2.py
> >>
> >> Any clue what about is done wrong?

> >
> > The pysnmp library is not able to find your generated file. Either copy
> > your generated file to /usr/lib/python2.4/site-packages/pysnmp/v4/smi/mibs/instances
> > or call setMibPath on the mibBuilder instance before calling loadModules
> > to add the current directory (or whatever directory holds your generated
> > file).
> > --
> > http://mail.python.org/mailman/listinfo/python-list
> >

>
> The thing is that I have copied the file (as you may see, I did 'ls
> -lA' on it. If the file wasnt there, the error message was different.
> Also, the setMibPath doesent seem to work, as I tried to set up it to
> any value, and right after that I was performing getMibPath which was
> giving me unchanged default paths. Keep in mind, that whole path setu
> up code has executed without any error.
> So, what is correct and working way to supply my code with that
> converted mib file?


I have absolutely no knowledge of pysnmp, but from reading the error
message I'd guess that you have a '.py' somewhere where you shouldn't.
Either the filename shouldn't have a .py, or you are referring to
the thing to be loaded with a '.py' on the end of the name when you
should be omitting it.

But like I said, I'm speaking out of my hat here, since I've never
worked with pysnmp.

--RDM

 
Reply With Quote
 
SpamMePlease PleasePlease
Guest
Posts: n/a
 
      03-07-2009
On Sat, Mar 7, 2009 at 8:33 PM, <(E-Mail Removed)> wrote:
> SpamMePlease PleasePlease <(E-Mail Removed)> wrote:
>> On Fri, Mar 6, 2009 at 2:14 PM, Shantanu Joshi <(E-Mail Removed)> wrote:
>> >
>> > SpamMePlease PleasePlease <(E-Mail Removed)> writes:
>> >
>> >> 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 snmp.py
>> >> ('/usr/lib/python2.4/site-packages/pysnmp/v4/smi/mibs/instances',
>> >> '/usr/lib/python2.4/site-packages/pysnmp/v4/smi/mibs')
>> >> Traceback (most recent call last):
>> >> * File "snmp.py", line 7, in ?
>> >> * * mibBuilder = builder.MibBuilder().loadModules('jnx-bgpmib2')
>> >> * File "//usr/lib/python2.4/site-packages/pysnmp/v4/smi/builder.py",
>> >> line 82, in loadModules
>> >> * * raise error.SmiError(
>> >> pysnmp.smi.error.SmiError: MIB module
>> >> "/usr/lib/python2.4/site-packages/pysnmp/v4/smi/mibs/instances/jnx-bgpmib2.py"
>> >> load error: MIB file ".py" not found in search path
>> >> rivendell# ls -lA
>> >> /usr/lib/python2.4/site-packages/pysnmp/v4/smi/mibs/instances/jnx-bgpmib2.py
>> >> -rw-r--r-- 1 root root 2687 Mar *6 06:50
>> >> /usr/lib/python2.4/site-packages/pysnmp/v4/smi/mibs/instances/jnx-bgpmib2.py
>> >>
>> >> Any clue what about is done wrong?
>> >
>> > The pysnmp library is not able to find your generated file. Either copy
>> > your generated file to /usr/lib/python2.4/site-packages/pysnmp/v4/smi/mibs/instances
>> > or call setMibPath on the mibBuilder instance before calling loadModules
>> > to add the current directory (or whatever directory holds your generated
>> > file).
>> > --
>> > http://mail.python.org/mailman/listinfo/python-list
>> >

>>
>> The thing is that I have copied the file (as you may see, I did 'ls
>> -lA' on it. If the file wasnt there, the error message was different.
>> Also, the setMibPath doesent seem to work, as I tried to set up it to
>> any value, and right after that I was performing getMibPath which was
>> giving me unchanged default paths. Keep in mind, that whole path setu
>> up code has executed without any error.
>> So, what is correct and working way to supply my code with that
>> converted mib file?

>
> I have absolutely no knowledge of pysnmp, but from reading the error
> message I'd guess that you have a '.py' somewhere where you shouldn't.
> Either the filename shouldn't have a .py, or you are referring to
> the thing to be loaded with a '.py' on the end of the name when you
> should be omitting it.
>
> But like I said, I'm speaking out of my hat here, since I've never
> worked with pysnmp.
>
> --RDM
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>


All modules in mentioned by pysnmp directory have .py in name, and
while invoked in the code, they dont. But I also tried some
combinations, with no luck.

--
--------------------
Spank The Spam!
 
Reply With Quote
 
Shantanu Joshi
Guest
Posts: n/a
 
      03-09-2009
SpamMePlease PleasePlease <(E-Mail Removed)> writes:

> On Fri, Mar 6, 2009 at 2:14 PM, Shantanu Joshi <(E-Mail Removed)> wrote:
>>
>> SpamMePlease PleasePlease <(E-Mail Removed)> writes:
>>

> .. snip
>
> The thing is that I have copied the file (as you may see, I did 'ls
> -lA' on it. If the file wasnt there, the error message was different.
> Also, the setMibPath doesent seem to work, as I tried to set up it to
> any value, and right after that I was performing getMibPath which was
> giving me unchanged default paths. Keep in mind, that whole path setu
> up code has executed without any error.
> So, what is correct and working way to supply my code with that
> converted mib file?


Works for me.

> [shantanu@tiamat:~/Documents/snmp]$ ls
> AV-AES-MIB.mib
> [shantanu@tiamat:~/Documents/snmp]$ smidump AV-AES-MIB.mib -k > AV-AES-MIB.txt
> smidump: module `AV-AES-MIB.mib' contains errors, expect flawed output
> [shantanu@tiamat:~/Documents/snmp]$ build-pysnmp-mib AV-AES-MIB.txt > AV-AES-MIB.py
> [shantanu@tiamat:~/Documents/snmp]$ ls
> AV-AES-MIB.mib AV-AES-MIB.txt AV-AES-MIB.py
> [shantanu@tiamat:~/Documents/snmp]$ sudo cp AV-AES.py /usr/lib/python2.5/site-packages/pysnmp/v4/smi/mibs/instances
> [shantanu@tiamat:~/Documents/snmp]$ ls /usr/lib/python2.5/site-packages/pysnmp/v4/smi/mibs/instances
> AV-AES-MIB.py __SNMP-FRAMEWORK-MIB.py __SNMP-MPD-MIB.pyc __SNMP-USER-BASED-SM-MIB.py __SNMP-VIEW-BASED-ACM-MIB.pyc __init__.py
> __PYSNMP-USM-MIB.py __SNMP-FRAMEWORK-MIB.pyc __SNMP-TARGET-MIB.py __SNMP-USER-BASED-SM-MIB.pyc __SNMPv2-MIB.py __init__.pyc
> __PYSNMP-USM-MIB.pyc __SNMP-MPD-MIB.py __SNMP-TARGET-MIB.pyc __SNMP-VIEW-BASED-ACM-MIB.py __SNMPv2-MIB.pyc
> [shantanu@tiamat:~/Documents/snmp]$
> [shantanu@tiamat:~/Documents/snmp]$ ipython
> Python 2.5.2 (r252:60911, Sep 30 2008, 15:41:3
> Type "copyright", "credits" or "license" for more information.
>
> IPython 0.8.4 -- An enhanced Interactive Python.
> ? -> Introduction and overview of IPython's features.
> %quickref -> Quick reference.
> help -> Python's own help system.
> object? -> Details about 'object'. ?object also works, ?? prints more.
>
> In [1]: from pysnmp.smi import builder, view
>
> In [2]: mibBuilder = builder.MibBuilder().loadModules('AV-AES-MIB')
>
> In [3]: mibViewController = view.MibViewController(mibBuilder)
>
> In [4]: oid, label, suffix = mibViewController.getNodeName((1,3,6,1,4,1,6889,2, 27,2,2,2))
>
> In [5]: print oid
> (1, 3, 6, 1, 4, 1, 6889, 2, 27, 2, 2)
>
> In [6]: print label
> ('iso', 'org', 'dod', 'internet', 'private', 'enterprises', [...])
>
> In [7]: print suffix
> (2,)
>
> In [8]:


I think you should check that the file you are generating is correct,
and can be read properly. If that doesn't help, you should try on the
pysnmp-users mailing list at http://sourceforge.net/mail/?group_id=14735.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to convert x (elapsed) milliseconds into human-readable format "..d..h..m..s" ? Ulf Meinhardt Java 0 09-13-2009 07:58 AM
Human readable number formatting Alex Willmer Python 9 09-28-2005 06:22 PM
human readable IPTC field names Jonah Bossewitch Python 0 01-12-2005 08:36 PM
lightweight human-readable config? Maxim Khesin Python 13 10-31-2003 08:45 PM
Human-readable storage for types (with no pointers)? Konstantin Shemyak C Programming 4 09-12-2003 04:18 PM



Advertisments