pysnmp.smi.error.SmiError:没有符号

时间:2013-07-12 12:22:36

标签: python snmp cisco pysnmp

我似乎无法让这个脚本工作。非常感谢任何帮助。

这是我一直得到的错误:

./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文件?

1 个答案:

答案 0 :(得分:0)

使用pysnmp,MIB具有扁平结构。因此,您可以通过其符号名称来寻址任何MIB对象,如:

CISCO-REMOTE-ACCESS-MONITOR-MIB::ciscoRasMonitorMIBObjects
CISCO-REMOTE-ACCESS-MONITOR-MIB::crasActivity
CISCO-REMOTE-ACCESS-MONITOR-MIB::crasSessionTable
CISCO-REMOTE-ACCESS-MONITOR-MIB::crasSessionEntry
CISCO-REMOTE-ACCESS-MONITOR-MIB::crasLocalAddress

所以我将你的oid作业改为:

oid = 'crasLocalAddress'

另请注意,由于您要查询SNMP表对象,因此必须提供其列实例ID。例如:

cmdgen.MibVariable(mib, oid, (1,2,3,4))

是普通的子OID或

cmdgen.MibVariable(mib, oid, '0.0.0.0')

将由pysnmp解释并根据SMI INDEX子句规则转换为子OID。

或者您可以通过运行nextCmd()方法找出您的Agent实际上具有的实例ID部分,而没有给MibVariable()的实例信息,因此将返回整个列。