2

I have two MIBS files, MIB1 and MIB2, MIB2 is importing elements from MIB1. I've run smilint and build-pysnmp-mib, actually smidump as I was not be able to pre-load the file exporting elements with build-pysnmp-mib.

With smidump I have two MIB .py modules, MIB1.py and MIB2.py, however when I write my SNMP agent, pysnmp is not able to find MIB1.py exporting module. I got this error

Traceback (most recent call last):
  File "snmpagent.py", line 165, in <module>
    agent = SNMPAgent(objects)
  File "snmpagent.py", line 90, in __init__
    mibObject.objectType)
  File "/usr/lib/python2.7/dist-packages/pysnmp/smi/builder.py", line 299, in importSymbols
    self.loadModules(modName, **userCtx)
  File "/usr/lib/python2.7/dist-packages/pysnmp/smi/builder.py", line 259, in loadModules
    'MIB module \"%s\" load error: %s' % (modPath, traceback.format_exception(*sys.exc_info()))
pysnmp.smi.error.SmiError: MIB module "./MIB2.py" load error: ['Traceback (most recent call last):\n', '  File "/usr/lib/python2.7/dist-packages/pysnmp/smi/builder.py", line 255, in loadModules\n    exec(modData, g)\n', '  File "<string>", line 17, in <module>\n', '  File "/usr/lib/python2.7/dist-packages/pysnmp/smi/builder.py", line 302, in importSymbols\n    \'No module %s loaded at %s\' % (modName, self)\n', 'SmiError: No module MIB1 loaded at <pysnmp.smi.builder.MibBuilder instance at 0x7f99213c0b48>\n']

I have tried updating SMIPATH, and also loading manually the .py module with

mibPath = mibBuilder.getMibSources() + (builder.DirMibSource('path'),)
mibBuilder.setMibSources(*mibPath)
mibBuilder.loadModules(
    'MIB1',
)

I'm running pysnmp on Ubuntu 14.04 and Python 2.7.6.

Can anybody help me out on this?

jht
  • 141
  • 10

1 Answers1

2

Please use mibdump.py tool from the pysmi package to compile ASN.1 MIBs into Python/pysnmp module. That tool will handle all the dependencies and produce much better MIBs. Generated MIBs are backward compatible with all previous pysnmp versions. The pysmi package runs on Python 2 & 3 out-of-the-box.

Since pysnmp 4.3, no explicit ASN.1 MIB compilation step is required -- pysnmp 4.3+ will automatically invoke pysmi to find/download/compile ASN.1 MIB and hand it over to pysnmp.

It is always better to upgrade to the latest pysnmp whenever possible.

Ilya Etingof
  • 5,440
  • 1
  • 17
  • 21
  • Is there any way to make mibdump.py runs with python 2.7? Thks – jht Mar 21 '16 at 12:18
  • mibdump.py works with Python 2.7. Why do you think it does not? – Ilya Etingof Mar 21 '16 at 12:38
  • I managed to make it run, but still same error, where should I copy the new .py files? – jht Mar 21 '16 at 12:54
  • You can place MIB .py files at any location, then configure pysnmp to use it by calling .DirMibSource() in your script. – Ilya Etingof Apr 02 '16 at 08:44
  • Were you able to run it successfully? I am hitting the same issue. – npatel Oct 25 '17 at 02:06
  • @npatel Can you please share code snippet and the error it causes? Here is [the manual page](http://snmplabs.com/pysnmp/docs/api-reference.html#pysnmp.smi.rfc1902.ObjectIdentity.addMibSource) explaining how to set the search path for Pythonized MIBs. – Ilya Etingof Oct 27 '17 at 09:52