How do I implement a custom MIB in PySNMP?
Asked Answered
O

1

7

I already have the MIB text file (do I need to make this into a .py file somehow??). I am trying to use PySNMP (not net-snmp). I have been able to connect to my device and print out some info, but the info was not very helpful (just ObjectName, ObjectIdentifier, etc). I want to be able to communicate with the device (send commands to change and read values), but all of the tutorials I have seen seem to be of little help. Does anyone know how I can use my custom MIB to effectively communicate with my device? Any good sites I am missing? http://pysnmp.sourceforge.net/ is ok, but I need something else...

Orangeman answered 5/6, 2012 at 0:18 Comment(5)
Does your device already support the commands you wish? Or are you designing those from scratch yourself?Abigael
Did you find this one: code.google.com/p/pycopia ? The SNMP subpackage, specifically. If so, what did you think of it?Rigamarole
@sarnold: yes, my device is supposed to already have SNMP enabled.Orangeman
@Keith: it looks like pycopia does not support SNMPv3, which seems to be the best version to use.Orangeman
@superagentintern Well, most places actually use v2c in practice. v3 could be added, but it hasn't been necessary...Rigamarole
E
7

To use MIBs with pysnmp you should first convert your MIB into pysnmp format (which is a collection of Python objects). The conversion is done with the pysnmp/tools/build-pysnmp-mib shell script in the following manner:

$ sh build-pysnmp-mib -h
build-pysnmp-mib: illegal option -- h
Convert MIB text file into PySNMP-compliant module, see http://pysnmp.sf.net.
Usage: build-pysnmp-mib [-o pysnmp-mib-file ] [ mib-text-file ]

Make sure you also have libsmi installed (pysnmp scripts use the smidump tool from libsmi distribution).

Unless you put your new pysnmp MIB file into pysnmp/smi/mibs/ (which is not a good idea), you would also have to point pysnmp to the location where your own MIBs are. This could be done as explained here.

Once you are done with the MIB, you can use it from your scripts as explained here.

You could make a quick check how your new MIB works by invoking pysnmpget/pysnmpset tools shipped with the pysnmp-apps package.

BTW, chances are that the MIB you need to work with is already converted into pysnmp format and distributed with the pysnmp-mibs package.

Exorcise answered 5/6, 2012 at 16:1 Comment(2)
Is there any way to convert the MIB on Windows 7? Cygwin sounds like it might work, but I'm having issues with downloading/installing. Will PowerShell work?Orangeman
Have no experience with Cygwin. The conversion also works out of the box on MacOS X once you build libsmi there.Exorcise

© 2022 - 2024 — McMap. All rights reserved.