How do I implement a custom MIB in PySNMP?

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ā€¦

Best answer

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.