question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Loading uncompiled MIB files.

See original GitHub issue

I’m stumped on what I would think would be a simple task. The sample script “SNMP MIB browser” gives every indication that compiler.addMibCompiler(mibBuilder, sources=['/usr/share/snmp/mibs']) adds a MIB compiler to load uncompiled MIBs and that mibBuilder.addMibSources(builder.DirMibSource('/opt/pysnmp_mibs')) is to add a source containing pre-compiled MIBs.

#!/usr/bin/env python
from pysnmp import debug
from pysnmp.smi import builder, view, compiler, rfc1902, error

def main():
#    debug.setLogger(debug.Debug('all'))
    mibBuilder = builder.MibBuilder()
    compiler.addMibCompiler(mibBuilder, sources = ['file:///home/user/python-udp/MIBs', ])
    mibBuilder.loadModules('SNMPv2-SMI')
    mibBuilder.loadModules('SNMPv2-TC')
    mibBuilder.loadModules('INET-ADDRESS-MIB')
    mibBuilder.loadModules('IANAifType-MIB')
    mibViewController = view.MibViewController(mibBuilder)
    modName = mibViewController.getFirstModuleName()
    while 1:
        if modName: print(modName)
        try:
            modName = mibViewController.getNextModuleName(modName)
        except error.SmiError:
            break
    return

if __name__ == '__main__':
    main()

The loadModules() all work until the one to load IANAifType-MIB which is the first one which isn’t included in pysnmp itself. At no point does it give any indication that it’s looking in the directory I specified. I’ve tried numerous variations on the theme but cannot find anything which works. Is there a concise code snippet for loading uncompiled MIBs? Thanks in advance.

Traceback (most recent call last):
  File "./loadmib.py", line 24, in <module>
    main()
  File "./loadmib.py", line 12, in main
    mibBuilder.loadModules('IANAifType-MIB')
  File "/home/user/python-udp/venv/lib/python2.7/site-packages/pysnmp/smi/builder.py", line 388, in loadModules
    raise error.MibNotFoundError('%s compilation error(s): %s' % (modName, errs))
pysnmp.smi.error.MibNotFoundError: IANAifType-MIB compilation error(s): missingcaused by <class 'pysnmp.smi.error.MibNotFoundError'>: MIB file "IANAifType-MIB.py[co]" not found in search path (DirMibSource('/home/user/python-udp/venv/lib/python2.7/site-packages/pysnmp/smi/mibs'), DirMibSource('/home/user/python-udp/venv/lib/python2.7/site-packages/pysnmp/smi/mibs/instances'), DirMibSource('pysnmp_mibs'), DirMibSource('/home/user/.pysnmp/mibs'))caused by <type 'exceptions.IOError'>: [Errno 2] No suitable module found: 'IANAifType-MIB'

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
etingofcommented, Jan 19, 2019

Your code seems correct and it works for me. Try adding some pysmi debugging:

from pysmi import debug as pysmi_debug
pysmi_debug.setLogger(pysmi_debug.Debug('compiler'))

To see the search process:

2019-01-19 09:18:24,569 pysmi: trying source FileReader{"/home/user/python-udp/MIBs"}
2019-01-19 09:18:25,362 pysmi: no IANAifType-MIB found at FileReader{"/home/user/python-udp/MIBs"}
2019-01-19 09:18:25,362 pysmi: no IANAifType-MIB found everywhere
2019-01-19 09:18:25,362 pysmi: MIBs analyzed 0, MIBs failed 1

BTW, if you add this URL to the MIBs repo, all your MIBs would be resolved:

    compiler.addMibCompiler(mibBuilder, sources = [
        'file:///home/user/python-udp/MIBs',
        'http://mibs.snmplabs.com/asn1/'])
1reaction
etingofcommented, Jan 19, 2019

Do you also have the SNMPv2-SMI MIB in your local collection?

Generally, to compile a MIB you have to have all the MIBs it imports (and the MIBs they import and so forth). In other words, you have to have all the MIBs in the dependency chain in uncompiled form.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncompiled MIB problem...
I tried to load the file as is using the MIB browser that comes with OpManager 5.6; however, it does not work. I...
Read more >
Loading Compiled MIBs - WebNMS
WebNMS SNMP API allows loading of compiled MIB files. The compiled MIB files reduce the loading time considerably when compared to direct loading....
Read more >
a MIB Compiler supporting SMIv1 and SMIv2
This module can be use to compile MIBs (recursively or not) or load already compiled MIBs for later use. Some tasks can be...
Read more >
Managing MIB files - IBM
Compiling a MIB file. You can compile Management Information Base (MIB) files that are located on the IBM Flex System Manager. Loading MIB...
Read more >
MIB File Won't Import/Compile - ScienceLogic Support
In some cases, the platform administrator may be able to fix certain issues themselves, but the vendor should make their MIB files compatible ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found