1
嘗試運行基於MIB的SNMP腳本,並遇到問題。雖然我知道包含該功能的模塊已安裝,但無法運行Counter64功能。 MIB模塊會自動生成,因此我一旦安裝了缺少的模塊就試圖重新生成它,但它不能解決問題。嘗試訪問函數Counter64時,PySNMP MIB模塊失敗
的代碼如下:
#!/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
我知道環境的變量是正確的,因爲我可以用男人ually分配的OID沒有任何問題詢問他們。我收到的回溯是:
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 any have suggestions? Counter64是pycopia-SMI Python模塊的一部分,我已確認它已安裝。但我不確定如何解決這個問題。