Question

I keep getting this error in the PySNMP builder when trying to load CISCO-RTTMON-MIB. The code below works with all other mibs I've tried so far, but this one is getting stuck. This is also the first time I'm trying to walk an entire table (rttMonStats), so I might just be doing it wrong. Here's what I've done:

I downloaded all of the files under the Version 2 column here: http://tools.cisco.com/Support/SNMP/do/BrowseMIB.do?local=en&mibName=CISCO-RTTMON-MIB

The ones marked as "Non-Cisco MIB", I found elsewhere online with a search for "download MIB_NAME. I ran each one of these through build-pysnmp-mib like:

build-pysnmp-mib MIB_NAME.my > MIB_NAME.py.

I then copied all *.py files into /opt/appname/mibs/

Here is the pertinent def in snmpcommands.py:

def walk(community, ipaddress, mib, oid, index):
    cmdGen = cmdgen.CommandGenerator()
    mibBuilder = cmdGen.snmpEngine.msgAndPduDsp.mibInstrumController.mibBuilder
    mibSources = mibBuilder.getMibSources() + (
            builder.DirMibSource('/opt/appname/mibs'),
            )
    mibBuilder.setMibSources(*mibSources)
    mibBuilder.loadModules()
    errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.nextCmd(
            cmdgen.CommunityData(community, mpModel=0),
            cmdgen.UdpTransportTarget((ipaddress, 161)),
            cmdgen.MibVariable(mib, oid, index),
            lookupValues=True, lookupNames=True
    )

    if errorIndication:
            print(errorIndication)
    else:
            if errorStatus:
                    print('%s at %s' % (
                            errorStatus.prettyPrint(),
                            errorIndex and varBinds[int(errorIndex)-1] or '?'
                            )
                    )
            else:
                    result = {}
                    for tableRow in varBindTable:
                            for oid, val in tableRow:
                                    result[oid.prettyPrint()] = val.prettyPrint()

                    return json.dumps(result)

and I'm calling it like:

>>>import snmpcommands
>>>snmpcommands.walk('community', 'ip.add.ress', 'CISCO-RTTMON-MIB', 'rttMonStats', '0.0.0.0')

However, I get this:

>>> snmpcommands.walk('community', 'ip.add.ress', 'CISCO-RTTMON-MIB', 'rttMonStats', '0.0.0.0')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "snmpcommands.py", line 57, in walk
    mibBuilder.loadModules()
  File "/usr/lib/python2.6/site-packages/pysnmp-4.2.4-py2.6.egg/pysnmp/smi/builder.py", line 251, in loadModules
    'MIB module \"%s\" load error: %s' % (modPath, sys.exc_info()[1])
pysnmp.smi.error.SmiError: MIB module "/opt/appname/mibs/CISCO-RTTMON-MIB.py" load     error:     ConstraintsIntersection(ConstraintsIntersection(ConstraintsIntersection(ConstraintsIntersection(), ValueSizeConstraint(0, 65535)), ValueSizeConstraint(0, 255)), ValueSizeConstraint(1, 64)) failed at: "ValueSizeConstraint(1, 64) failed at: """ at SnmpAdminString

I'm very new to PySNMP so I'm guessing that the issue is it was expecting a value in SnmpAdminString that it pulls from SNMP-FRAMEWORK-MIB and it was empty. I just don't know how to fix it.

Was it helpful?

Solution

It looks like you have an empty string as a SnmpAdminString("") initializer at CISCO-RTTMON-MIB.py. That seems to violate SnmpAdminString constraints what ultimately caused an exception. So I'd grep CISCO-RTTMON-MIB.py for empty SnmpAdminString initializers and either replace them with a compliant value (1-64 octets) or just drop empty initializers (e.g. making it looking like SnmpAdminString()).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top