Question

Attempting to run a MIB based SNMP script and I running into an issue. It is unable to run the function Counter64 though I know that the module which contains that function is installed. the MIB module is automatically generated so I attempted to regenerate it once the missing module was installed, but it didn't resolve the issue.

The code is as follows:

#!/usr/local/bin/python2.7

from pysnmp.smi import builder, view, error
from pysnmp.entity.rfc3413.oneliner import cmdgen

cmdGen = cmdgen.CommandGenerator()
mibBuilder = builder.MibBuilder()
mibSources = mibBuilder.getMibSources() + ( builder.DirMibSource( '/path/to/command/mibs', ), )
mibBuilder.setMibSources( *mibSources )
print mibBuilder.getMibSources()
mibBuilder.loadModules( 
    'NS-MIB-smiv2',
    )
mibView = view.MibViewController( mibBuilder )
errorIndication, errorStatus, errorIndex, \
                 varBindTable = cmdGen.nextCmd( 
    cmdgen.CommunityData( 'Name', 'Community' ),
    cmdgen.UdpTransportTarget( ( 'IP Address', 161 ) ),
    ( ( '', 'serverName' ), ),
    )

print varBindTable

I know the variables for the environment are correct as I can query them using man ually assigned OIDs without any problem. The Traceback I'm receiving is:

Traceback (most recent call last):

  File "./snmpcollectorexample.py", line 12, in <module>

    'NS-MIB-smiv2',

  File "/usr/lib/python2.7/site-packages/pysnmp-4.2.1-py2.7.egg/pysnmp/smi/builder.py", line 221, in loadModules

pysnmp.smi.error.SmiError: MIB module "/path/to/command/mibs/NS-MIB-smiv2.py" load error: name 'Counter64' is not defined

Doesn anyone have recommendations? Counter64 is a part of the pycopia-SMI Python module and I've confirmed that it is installed. But I'm unsure how to go about resolving this issue.

Was it helpful?

Solution

Located the issue. For some reason the build-pysnmp-mib wrapper when running my MIB through all the conversion commands was not adding the Counter64 entries into the mibBuilder.importSymbols(). Manually added it and it moved right along.

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