I am trying to do a GET command on a few specific OIDs for my application. I have a custom MIB file in .txt format. I converted the file to .py format via http://www.ibr.cs.tu-bs.de/projects/libsmi/tools/
I get this error. I save the output as X-MIB.py and continue:
smidump: module `mibs/AGILINK-MIB' contains errors, expect flawed output.
I saved my X-MIB.py file in C:\Python27\Lib\site-packages\pysnmp\smi\mibs. I understand that this is bad practice but I just wanted to test to see if it works.
Here is my script to get a few OID back:
from pysnmp.entity.rfc3413.oneliner import cmdgen
cmdGen = cmdgen.CommandGenerator()
errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
cmdgen.CommunityData('public'),
cmdgen.UdpTransportTarget(('169.254.0.1', 161)),
cmdgen.MibVariable('X-MIB', 'aglGwDesc', '0'),
cmdgen.MibVariable('SNMPv2-MIB', 'sysUpTime', '0'),
lookupNames = True,
lookupValues = True
)
# Check for errors and print out results
if errorIndication:
print(errorIndication)
elif errorStatus:
print(errorStatus)
else:
print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
for name, val in varBinds:
Here is the error:
Traceback (most recent call last):
File "getting_started.py", line 11, in <module>
lookupValues = True
File "C:\Python27\lib\site-packages\pysnmp\entity\rfc3413\oneliner\cmdgen.py", line 424, in getCmd
kwargs.get('contextName', null)
File "C:\Python27\lib\site-packages\pysnmp\entity\rfc3413\oneliner\cmdgen.py", line 277, in getCmd
self.makeReadVarBinds(varNames),
File "C:\Python27\lib\site-packages\pysnmp\entity\rfc3413\oneliner\cmdgen.py", line 201, in makeReadVarBinds
[ (x, self._null) for x in varNames ], oidOnly=True
File "C:\Python27\lib\site-packages\pysnmp\entity\rfc3413\oneliner\cmdgen.py", line 209, in makeVarBinds
varName.resolveWithMib(self.mibViewController, oidOnly=True)
File "C:\Python27\lib\site-packages\pysnmp\entity\rfc3413\oneliner\mibvar.py", line 159, in resolveWithMib
self.__modName, self.__symName
File "C:\Python27\lib\site-packages\pysnmp\smi\builder.py", line 302, in importSymbols
'No module %s loaded at %s' % (modName, self)
pysnmp.smi.error.SmiError: No module X-MIB loaded at <pysnmp.smi.builder.MibBuilder instance at 0x02D6B8F0>
My question is how do I solve this error? Is it because of the previous error in the making of the X-MIB.py file?
I know that it is able to see my X-MIB.py file, because the error is not say "Unable to find X-MIB in path" or something similar. I read the PySNMP docs but I am unable to follow it.
As mentioned in this post, you have to convert smidump output into pysnmp-compatible format by passing it through libsmi2pysnmp tool.
But I'd advise you to resolve smidump errors/warnings first, otherwise your *.py MIB may be faulty. Those errors seems to be specific to your MIB syntax.
You could point pysnmp to use your own path to your own pysnmp-compatible MIB directory by using addMibSource() method:
cmdgen.MibVariable('X-MIB', 'aglGwDesc', '0').addMibSource('/tmp/mymibs'),
Finally, you don't really need a MIB to query your SNMP Agent - just pass Command Generator a plain-text OID instead of MibVariable instance:
errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
cmdgen.CommunityData('public'),
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
'1.3.6.1.2.1.1.1.0',
'1.3.6.1.2.1.1.6.0'
)