我似乎无法让这个脚本工作。任何帮助是极大的赞赏。
这是我不断收到的错误:
./snmptester.py
Traceback (most recent call last):
File "./snmptester.py", line 35, in <module>
cmdgen.MibVariable(mib, oid),
File "/usr/lib/python2.6/site-packages/pysnmp/entity/rfc3413/oneliner/cmdgen.py", line 370, in getCmd
kwargs.get('contextName', null)
File "/usr/lib/python2.6/site-packages/pysnmp/entity/rfc3413/oneliner/cmdgen.py", line 207, in getCmd
self.makeReadVarBinds(varNames),
File "/usr/lib/python2.6/site-packages/pysnmp/entity/rfc3413/oneliner/cmdgen.py", line 150, in makeReadVarBinds
self.mibViewController, oidOnly=True
File "/usr/lib/python2.6/site-packages/pysnmp/entity/rfc3413/oneliner/mibvar.py", line 160, in resolveWithMib
self.__modName, self.__symName
File "/usr/lib/python2.6/site-packages/pysnmp/smi/builder.py", line 298, in importSymbols
'No symbol %s::%s at %s' % (modName, symName, self)
pysnmp.smi.error.SmiError: No symbol CISCO-REMOTE-ACCESS-MONITOR-MIB::ciscoRasMonitorMIBObjects.crasActivity.crasSessionTable.crasSessionEntry.crasLocalAddress at <pysnmp.smi.builder.MibBuilder instance at 0x7f5e50d51170>
这是我正在运行的脚本:
ip='192.168.1.1'
community='public'
mib = "CISCO-REMOTE-ACCESS-MONITOR-MIB"
oid = 'ciscoRasMonitorMIBObjects.crasActivity.crasSessionTable.crasSessionEntry.crasLocalAddress'
cmdGen = cmdgen.CommandGenerator()
errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
cmdgen.CommunityData(community),
cmdgen.UdpTransportTarget((ip, 161)),
cmdgen.MibVariable(mib, oid),
lookupNames=True, lookupValues=True
)
# Check for errors and print out results
if errorIndication:
print(errorIndication)
elif errorStatus:
print(errorStatus)
else:
for string, val in varBinds:
print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
我对 python 还是很陌生,所以我很难破译这个错误。
进行这些更改后,我现在收到此错误:
Traceback (most recent call last):
File "./snmptester.py", line 32, in <module>
lookupNames=True, lookupValues=True
File "/usr/lib/python2.6/site-packages/pysnmp/entity/rfc3413/oneliner/cmdgen.py", line 475, in nextCmd
varBindHead = [ univ.ObjectIdentifier(x[0]) for x in self.__asynCmdGen.makeReadVarBinds(varNames) ]
File "/usr/lib/python2.6/site-packages/pysnmp/entity/rfc3413/oneliner/cmdgen.py", line 150, in makeReadVarBinds
self.mibViewController, oidOnly=True
File "/usr/lib/python2.6/site-packages/pysnmp/entity/rfc3413/oneliner/mibvar.py", line 80, in resolveWithMib
mibViewController.mibBuilder.loadModules(*self.__modNamesToLoad)
File "/usr/lib/python2.6/site-packages/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 "/usr/lib/python2.6/site-packages/pysnmp/smi/mibs/instances/__TRS-MIB.pyc" load error: No module TRS-MIB loaded at <pysnmp.smi.builder.MibBuilder instance at 0x7f18dbc36d88>
我尝试触摸 TRS-MIB 文件,但它仍然抱怨。有没有办法我需要构建 TRS-MIB 文件?