etingof / pysnmp

Python SNMP library
http://snmplabs.com/pysnmp/
BSD 2-Clause "Simplified" License
582 stars 200 forks source link

Unable to Load Custom MIBs #277

Closed JoshuaFry closed 5 years ago

JoshuaFry commented 5 years ago

I am having trouble loading in MIBs that are dependent on others. I have a directory for both compiled .py MIBs and one for none compiled .mib files. My approach is to load the MIBs into a mibBuilder then pass that into a MibViewController to resolve the OIDs with. What is the correct way to load in MIBs that are dependent on others?

  `mibBuilder = builder.MibBuilder()
    print('Setting MIB sources...')
    mibBuilder.addMibSources(builder.DirMibSource('/Users/admin/project_hearsay/api_v1/compiled_mibs'))
    print(mibBuilder.getMibSources())
    print('done')
    print('Loading MIB modules...'),
    try:
        mibBuilder.loadModules('ANDREW-MIB', 'WIRELESS-INNOVATIONS-PRODUCTS-MIB')
    except Exception as e:
        print(e)
    print('done')
    mibView = view.MibViewController(mibBuilder)

    responses = 0
    timeouts = 0
    for (errorIndication, errorStatus, errorIndex, response) in self.bulk_cmd(
        SnmpEngine(),
        CommunityData("public"),
        UdpTransportTarget((device.ip_address, device.snmp_port_number)),
        ContextData(),
        0, 50,
        ObjectType(ObjectIdentity(manufacturer_alarm_table_oid(device)).resolveWithMib(mibView)),
        lookupNames=True, lookupValues=True,
        lexicographicMode=False,
    ):
        if self.nextcmd_error(errorIndex, errorIndication, errorStatus):
            self.handle_next_cmd_error()
            timeouts += 1
            if timeouts > 4:
                return
            continue

        if response is not None:
            responses += 1
            for oid, value in response:

                print(oid.prettyPrint(), value.prettyPrint())`

---> Error Loading MIB modules... MIB module '/Users/admin/project_hearsay/api_v1/compiled_mibs/WIRELESS-INNOVATIONS-PRODUCTS-MIB/Users/admin/project_hearsay/api_v1/compiled_mibs/WIRELESS-INNOVATIONS-PRODUCTS-MIB.py' load error: ['Traceback (most recent call last):\n', ' File "/Users/admin/project_hearsay/env/lib/python3.7/site-packages/pysnmp/smi/builder.py", line 344, in loadModule\n exec(codeObj, g)\n', ' File "/Users/admin/project_hearsay/api_v1/compiled_mibs/WIRELESS-INNOVATIONS-PRODUCTS-MIB.py", line 11, in <module>\n wirelessInnovations, = mibBuilder.importSymbols("ANDREW-MIB", "wirelessInnovations")\n', ' File "/Users/admin/project_hearsay/env/lib/python3.7/site-packages/pysnmp/smi/builder.py", line 426, in importSymbols\n \'No module %s loaded at %s\' % (modName, self)\n', 'pysnmp.smi.error.MibNotFoundError: No module ANDREW-MIB loaded at <pysnmp.smi.builder.MibBuilder object at 0x105f94198>\n']caused by <class 'pysnmp.smi.error.MibNotFoundError'>: No module ANDREW-MIB loaded at <pysnmp.smi.builder.MibBuilder object at 0x105f94198>

It seems that even though I am adding in the ANDREW-MIB to be loaded it's not recognized by the next module.

I want to be able to fully resolve all OIDs, right now this is as far as I can get SNMPv2-SMI::enterprises.331.1.2.1.1.2.6.1.11.1 Some values are also returned as an OID and I'd like to resolve them as well.

Any help would be greatly appreciated.

JoshuaFry commented 5 years ago

The issue stemmed from the compilation of the MIB file. I got this to work just fine using different files.

etingof commented 5 years ago

Awesome!

If you can share the working MIB(s), we could put them to http://mibs.snmplabs.com/asn1 so pysnmp would pull them from there and work out of the box...