etingof / pysnmp

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

compiling Aruba MIBs for use with this module #381

Open mroe1234 opened 4 years ago

mroe1234 commented 4 years ago

Following one of the examples I am working on a very simple example:

from pysnmp.hlapi import *

iterator = getCmd(
    SnmpEngine(),
    CommunityData('abcd'),
    UdpTransportTarget(('controller.local', 161)),
    ContextData(),
    ObjectType(
        ObjectIdentity(
            "WLSX-SYSTEMEXT-MIB", "wlsxSysExtCpuUsedPercent",30)
    )
)

errorIndication, errorStatus, errorIndex, varBinds = next(iterator)

if errorIndication:
    print(errorIndication)

elif errorStatus:
    print('%s at %s' % (errorStatus.prettyPrint(),
                        errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))

else:
    for varBind in varBinds:
        print(' = '.join([x.prettyPrint() for x in varBind]))

I have been able to download the MIBs and I have been able to compile them successfully in to: ARUBA-MIB.py, ARUBA-TC.py, WLSX-SYSTEMEXT-MIB.py

However when I run the above code I get the follow traceback:

$ python3 getstats.py 
Traceback (most recent call last):
  File "/home/mus3/.local/lib/python3.7/site-packages/pysnmp/smi/builder.py", line 362, in loadModule
    exec(codeObj, g)
  File "/home/mus3/.pysnmp/mibs/ARUBA-TC.py", line 12, in <module>
    NotificationType, Integer32, MibIdentifier, IpAddress, Counter64, ModuleIdentity, Gauge32, Bits, MibScalar, MibTable, MibTableRow, MibTableColumn, ObjectSyntax, ObjectIdentity, Counter32, TimeTicks, Unsigned32, iso = mibBuilder.importSymbols("SNMPv2-SMI", "NotificationType", "Integer32", "MibIdentifier", "IpAddress", "Counter64", "ModuleIdentity", "Gauge32", "Bits", "MibScalar", "MibTable", "MibTableRow", "MibTableColumn", "ObjectSyntax", "ObjectIdentity", "Counter32", "TimeTicks", "Unsigned32", "iso")
  File "/home/mus3/.local/lib/python3.7/site-packages/pysnmp/smi/builder.py", line 448, in importSymbols
    'No symbol %s::%s at %s' % (modName, symName, self)
pysnmp.smi.error.SmiError: No symbol SNMPv2-SMI::ObjectSyntax at <pysnmp.smi.builder.MibBuilder object at 0x7f1c9e864ba8>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/mus3/.local/lib/python3.7/site-packages/pysnmp/smi/builder.py", line 362, in loadModule
    exec(codeObj, g)
  File "/home/mus3/.pysnmp/mibs/WLSX-SYSTEMEXT-MIB.py", line 9, in <module>
    ArubaSwitchRole, ArubaCardType, ArubaActiveState = mibBuilder.importSymbols("ARUBA-TC", "ArubaSwitchRole", "ArubaCardType", "ArubaActiveState")
  File "/home/mus3/.local/lib/python3.7/site-packages/pysnmp/smi/builder.py", line 441, in importSymbols
    self.loadModules(modName, **userCtx)
  File "/home/mus3/.local/lib/python3.7/site-packages/pysnmp/smi/builder.py", line 401, in loadModules
    self.loadModule(modName, **userCtx)
  File "/home/mus3/.local/lib/python3.7/site-packages/pysnmp/smi/builder.py", line 367, in loadModule
    'MIB module \'%s\' load error: %s' % (modPath, traceback.format_exception(*sys.exc_info()))
pysnmp.smi.error.MibLoadError: MIB module '/home/mus3/.pysnmp/mibs/ARUBA-TC/home/mus3/.pysnmp/mibs/ARUBA-TC.py' load error: ['Traceback (most recent call last):\n', '  File "/home/mus3/.local/lib/python3.7/site-packages/pysnmp/smi/builder.py", line 362, in loadModule\n    exec(codeObj, g)\n', '  File "/home/mus3/.pysnmp/mibs/ARUBA-TC.py", line 12, in <module>\n    NotificationType, Integer32, MibIdentifier, IpAddress, Counter64, ModuleIdentity, Gauge32, Bits, MibScalar, MibTable, MibTableRow, MibTableColumn, ObjectSyntax, ObjectIdentity, Counter32, TimeTicks, Unsigned32, iso = mibBuilder.importSymbols("SNMPv2-SMI", "NotificationType", "Integer32", "MibIdentifier", "IpAddress", "Counter64", "ModuleIdentity", "Gauge32", "Bits", "MibScalar", "MibTable", "MibTableRow", "MibTableColumn", "ObjectSyntax", "ObjectIdentity", "Counter32", "TimeTicks", "Unsigned32", "iso")\n', '  File "/home/mus3/.local/lib/python3.7/site-packages/pysnmp/smi/builder.py", line 448, in importSymbols\n    \'No symbol %s::%s at %s\' % (modName, symName, self)\n', 'pysnmp.smi.error.SmiError: No symbol SNMPv2-SMI::ObjectSyntax at <pysnmp.smi.builder.MibBuilder object at 0x7f1c9e864ba8>\n']caused by <class 'pysnmp.smi.error.SmiError'>: No symbol SNMPv2-SMI::ObjectSyntax at <pysnmp.smi.builder.MibBuilder object at 0x7f1c9e864ba8>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "getstats.py", line 14, in <module>
    errorIndication, errorStatus, errorIndex, varBinds = next(iterator)
  File "/home/mus3/.local/lib/python3.7/site-packages/pysnmp/hlapi/asyncore/sync/cmdgen.py", line 111, in getCmd
    lookupMib=options.get('lookupMib', True)))
  File "/home/mus3/.local/lib/python3.7/site-packages/pysnmp/hlapi/asyncore/cmdgen.py", line 130, in getCmd
    vbProcessor.makeVarBinds(snmpEngine, varBinds), __cbFun,
  File "/home/mus3/.local/lib/python3.7/site-packages/pysnmp/hlapi/varbinds.py", line 39, in makeVarBinds
    __varBinds.append(varBind.resolveWithMib(mibViewController, ignoreErrors=False))
  File "/home/mus3/.local/lib/python3.7/site-packages/pysnmp/smi/rfc1902.py", line 853, in resolveWithMib
    self.__args[0].resolveWithMib(mibViewController)
  File "/home/mus3/.local/lib/python3.7/site-packages/pysnmp/smi/rfc1902.py", line 481, in resolveWithMib
    self.__modName, self.__symName
  File "/home/mus3/.local/lib/python3.7/site-packages/pysnmp/smi/builder.py", line 441, in importSymbols
    self.loadModules(modName, **userCtx)
  File "/home/mus3/.local/lib/python3.7/site-packages/pysnmp/smi/builder.py", line 401, in loadModules
    self.loadModule(modName, **userCtx)
  File "/home/mus3/.local/lib/python3.7/site-packages/pysnmp/smi/builder.py", line 367, in loadModule
    'MIB module \'%s\' load error: %s' % (modPath, traceback.format_exception(*sys.exc_info()))
pysnmp.smi.error.MibLoadError: MIB module '/home/mus3/.pysnmp/mibs/WLSX-SYSTEMEXT-MIB/home/mus3/.pysnmp/mibs/WLSX-SYSTEMEXT-MIB.py' load error: ['Traceback (most recent call last):\n', '  File "/home/mus3/.local/lib/python3.7/site-packages/pysnmp/smi/builder.py", line 362, in loadModule\n    exec(codeObj, g)\n', '  File "/home/mus3/.pysnmp/mibs/ARUBA-TC.py", line 12, in <module>\n    NotificationType, Integer32, MibIdentifier, IpAddress, Counter64, ModuleIdentity, Gauge32, Bits, MibScalar, MibTable, MibTableRow, MibTableColumn, ObjectSyntax, ObjectIdentity, Counter32, TimeTicks, Unsigned32, iso = mibBuilder.importSymbols("SNMPv2-SMI", "NotificationType", "Integer32", "MibIdentifier", "IpAddress", "Counter64", "ModuleIdentity", "Gauge32", "Bits", "MibScalar", "MibTable", "MibTableRow", "MibTableColumn", "ObjectSyntax", "ObjectIdentity", "Counter32", "TimeTicks", "Unsigned32", "iso")\n', '  File "/home/mus3/.local/lib/python3.7/site-packages/pysnmp/smi/builder.py", line 448, in importSymbols\n    \'No symbol %s::%s at %s\' % (modName, symName, self)\n', 'pysnmp.smi.error.SmiError: No symbol SNMPv2-SMI::ObjectSyntax at <pysnmp.smi.builder.MibBuilder object at 0x7f1c9e864ba8>\n', '\nDuring handling of the above exception, another exception occurred:\n\n', 'Traceback (most recent call last):\n', '  File "/home/mus3/.local/lib/python3.7/site-packages/pysnmp/smi/builder.py", line 362, in loadModule\n    exec(codeObj, g)\n', '  File "/home/mus3/.pysnmp/mibs/WLSX-SYSTEMEXT-MIB.py", line 9, in <module>\n    ArubaSwitchRole, ArubaCardType, ArubaActiveState = mibBuilder.importSymbols("ARUBA-TC", "ArubaSwitchRole", "ArubaCardType", "ArubaActiveState")\n', '  File "/home/mus3/.local/lib/python3.7/site-packages/pysnmp/smi/builder.py", line 441, in importSymbols\n    self.loadModules(modName, **userCtx)\n', '  File "/home/mus3/.local/lib/python3.7/site-packages/pysnmp/smi/builder.py", line 401, in loadModules\n    self.loadModule(modName, **userCtx)\n', '  File "/home/mus3/.local/lib/python3.7/site-packages/pysnmp/smi/builder.py", line 367, in loadModule\n    \'MIB module \\\'%s\\\' load error: %s\' % (modPath, traceback.format_exception(*sys.exc_info()))\n', 'pysnmp.smi.error.MibLoadError: MIB module \'/home/mus3/.pysnmp/mibs/ARUBA-TC/home/mus3/.pysnmp/mibs/ARUBA-TC.py\' load error: [\'Traceback (most recent call last):\\n\', \'  File "/home/mus3/.local/lib/python3.7/site-packages/pysnmp/smi/builder.py", line 362, in loadModule\\n    exec(codeObj, g)\\n\', \'  File "/home/mus3/.pysnmp/mibs/ARUBA-TC.py", line 12, in <module>\\n    NotificationType, Integer32, MibIdentifier, IpAddress, Counter64, ModuleIdentity, Gauge32, Bits, MibScalar, MibTable, MibTableRow, MibTableColumn, ObjectSyntax, ObjectIdentity, Counter32, TimeTicks, Unsigned32, iso = mibBuilder.importSymbols("SNMPv2-SMI", "NotificationType", "Integer32", "MibIdentifier", "IpAddress", "Counter64", "ModuleIdentity", "Gauge32", "Bits", "MibScalar", "MibTable", "MibTableRow", "MibTableColumn", "ObjectSyntax", "ObjectIdentity", "Counter32", "TimeTicks", "Unsigned32", "iso")\\n\', \'  File "/home/mus3/.local/lib/python3.7/site-packages/pysnmp/smi/builder.py", line 448, in importSymbols\\n    \\\'No symbol %s::%s at %s\\\' % (modName, symName, self)\\n\', \'pysnmp.smi.error.SmiError: No symbol SNMPv2-SMI::ObjectSyntax at <pysnmp.smi.builder.MibBuilder object at 0x7f1c9e864ba8>\\n\']caused by <class \'pysnmp.smi.error.SmiError\'>: No symbol SNMPv2-SMI::ObjectSyntax at <pysnmp.smi.builder.MibBuilder object at 0x7f1c9e864ba8>\n']caused by <class 'pysnmp.smi.error.MibLoadError'>: MIB module '/home/mus3/.pysnmp/mibs/ARUBA-TC/home/mus3/.pysnmp/mibs/ARUBA-TC.py' load error: ['Traceback (most recent call last):\n', '  File "/home/mus3/.local/lib/python3.7/site-packages/pysnmp/smi/builder.py", line 362, in loadModule\n    exec(codeObj, g)\n', '  File "/home/mus3/.pysnmp/mibs/ARUBA-TC.py", line 12, in <module>\n    NotificationType, Integer32, MibIdentifier, IpAddress, Counter64, ModuleIdentity, Gauge32, Bits, MibScalar, MibTable, MibTableRow, MibTableColumn, ObjectSyntax, ObjectIdentity, Counter32, TimeTicks, Unsigned32, iso = mibBuilder.importSymbols("SNMPv2-SMI", "NotificationType", "Integer32", "MibIdentifier", "IpAddress", "Counter64", "ModuleIdentity", "Gauge32", "Bits", "MibScalar", "MibTable", "MibTableRow", "MibTableColumn", "ObjectSyntax", "ObjectIdentity", "Counter32", "TimeTicks", "Unsigned32", "iso")\n', '  File "/home/mus3/.local/lib/python3.7/site-packages/pysnmp/smi/builder.py", line 448, in importSymbols\n    \'No symbol %s::%s at %s\' % (modName, symName, self)\n', 'pysnmp.smi.error.SmiError: No symbol SNMPv2-SMI::ObjectSyntax at <pysnmp.smi.builder.MibBuilder object at 0x7f1c9e864ba8>\n']caused by <class 'pysnmp.smi.error.SmiError'>: No symbol SNMPv2-SMI::ObjectSyntax at <pysnmp.smi.builder.MibBuilder object at 0x7f1c9e864ba8>

My best understanding of the problems is the SNMPv2-SMI.py doesn't have an "ObjectSyntax" definition which might mean it's a v1 MIB not a v2? I've tried using smidump to convert to v2, but I get error unspecified errors and when I try to use the mibdump command like so:

mibdump --debug writer --mib-source="file:///home/mroe1234/mibs" --generate-mib-texts --destination-directory "/home/mroe1234/.pysnmp/mibs" --destination-format pysnmp SNMPv2-SMI

The output includes:

MIBs excluded from code generation: INET-ADDRESS-MIB, PYSNMP-USM-MIB, RFC-1212, RFC-1215, RFC1065-SMI, RFC1155-SMI, RFC1158-MIB, RFC1213-MIB, SNMP-FRAMEWORK-MIB, SNMP-TARGET-MIB, SNMPv2-CONF, SNMPv2-SMI, SNMPv2-TC, SNMPv2-TM, TRANSPORT-ADDRESS-MIB

Which seems to say it is ignoring the SNMPv2-SMI because it is supplied by pysnmp and it exists in ~/.local/lib/python3.7/site-packages/pysnmp/smi/mibs/ , Any advice would be helpful. Thanks.

lextm commented 1 year ago

While you realized that "SNMPv2-SMI.py doesn't have an "ObjectSyntax" definition", you neglected the fact that ARUBA-TC itself was written in a bad way. Since it does not make use of ObjectSyntax anywhere inside, this import should be removed. Thus, you can manually modify the ARUBA-TC MIB document and compile again.

Similarly you will hit any issue in WLSX-SYSTEMEXT-MIB where it mistakenly tries to import TEXTUAL-CONVENTION from SNMPv2-SMI.