PySNMP exceptions

随声附和 提交于 2020-01-03 05:27:11

问题


I am trying to make an SNMP agent following this tutorial: http://www.nealc.com/blog/blog/2013/02/23/writing-an-snmp-agent-with-a-custom-mib-using-pysnmp/

I am using the exact code in the tutorial, but when I run the code it ends in this:

DBG: [19:13:54.964]: file SNMPv2-SMI.pyc mtime 1379957443
DBG: [19:13:54.964]: file SNMPv2-SMI.py mtime 1402947591
DBG: [19:13:54.965]: loadModules: evaluating /usr/local/lib/python2.7/dist-packages/pysnmp/smi/mibs/SNMPv2-SMI.py
Traceback (most recent call last):
  File "snmpAgentTest.py", line 163, in <module>
    agent = SNMPAgent(objects)
  File "snmpAgentTest.py", line 59, in __init__
    self._snmpEngine = engine.SnmpEngine()
  File "/usr/local/lib/python2.7/dist-packages/pysnmp/entity/engine.py", line 18, in     __init__
    self.msgAndPduDsp = MsgAndPduDispatcher()
  File "/usr/local/lib/python2.7/dist-packages/pysnmp/proto/rfc3412.py", line 24, in __init__
    'SNMP-TARGET-MIB', 'SNMP-USER-BASED-SM-MIB'
  File "/usr/local/lib/python2.7/dist-packages/pysnmp/smi/builder.py", line 259, in loadModules
    'MIB module \"%s\" load error: %s' % (modPath, traceback.format_exception(*sys.exc_info()))
pysnmp.smi.error.SmiError: MIB module "/usr/local/lib/python2.7/dist-packages/pysnmp/smi/mibs/SNMPv2
-MIB.pyc" load error: ['Traceback (most recent call last):\n', '  File "/usr/local/lib/python2.7/dist-packages/pysnmp/smi/builder.py", line 255, in loadModules\n    exec(modData, g)\n', '  File "/usr/local/lib/python2.7/dist-packages/pysnmp/smi/mibs/SNMPv2-MIB.py", line 10, in <module>\n    ( Module
Compliance, NotificationGroup, ObjectGroup, ) = mibBuilder.importSymbols("SNMPv2-CONF", "ModuleCompliance", "NotificationGroup", "ObjectGroup")\n', '  File "/usr/local/lib/python2.7/dist-packages/pysnmp/smi/builder.py", line 299, in importSymbols\n    self.loadModules(modName, **userCtx)\n', '  File
 "/usr/local/lib/python2.7/dist-packages/pysnmp/smi/builder.py", line 259, in loadModules\n    \'MIB module \\"%s\\" load error: %s\' % (modPath, traceback.format_exception(*sys.exc_info()))\n', 'SmiError: MIB module "/usr/local/lib/python2.7/dist-packages/pysnmp/smi/mibs/SNMPv2-CONF.pyc" load error: [\'Traceback (most recent call last):\\n\', \'  File "/usr/local/lib/python2.7/dist-packages/pysnmp/smi/builder.py", line 255, in loadModules\\n    exec(modData, g)\\n\', \'  File "/usr/local/lib/python2.7/dist-packages/pysnmp/smi/mibs/SNMPv2-CONF.py", line 2, in <module>\\n    MibNode, = mibBuilder.importSymbols(\\\'SNMPv2-SMI\\\', \\\'MibNode\\\')\\n\', \'  File "/usr/local/lib/python2.7/dist-packages/pysnmp/smi/builder.py", line 299, in importSymbols\\n    self.loadModules(modName, **userCtx)\\n\', \'  File "/usr/local/lib/python2.7/dist-packages/pysnmp/smi/builder.py", line 259, in loadModules\\n    \\\'MIB module \\\\"%s\\\\" load error: %s\\\' % (modPath, traceback.format_exception(*sys.exc_info()))\\n\', \'SmiError: MIB module "/usr/local/lib/python2.7/dist-packages/pysnmp/smi/mibs/SNMPv2-SMI.py" load error: [\\\'Traceback (most recent call last):\\\\n\\\', \\\'  File "/usr/local/lib/python2.7/dist-packages/pysnmp/smi/builder.py", line 255, in loadModules\\\\n    exec(modData, g)\\\\n\\\', \\\'  File "<string>", line 2\\\\n\\\', \\\'    -- WinAgents MIB Extraction Wizard\\\\n\\\', \\\'                   ^\\\\n\\\', \\\'SyntaxError: invalid syntax\\\\n\\\']\\n\']\n']

The MY-MIB.py that gets generated by build-pysnmp-mib looks like this:

# PySNMP SMI module. Autogenerated from smidump -f python MY-MIB
# by libsmi2pysnmp-0.1.3 at Thu Jun 26 19:03:31 2014,
# Python version sys.version_info(major=2, minor=7, micro=3, releaselevel='final', serial=0)

# Imports

( Integer, ObjectIdentifier, OctetString, ) = mibBuilder.importSymbols("ASN1", "Integer", "ObjectIdentifier", "OctetString")
( NamedValues, ) = mibBuilder.importSymbols("ASN1-ENUMERATION", "NamedValues")
( ConstraintsIntersection, ConstraintsUnion, SingleValueConstraint, ValueRangeConstraint, ValueSizeConstraint, ) = mibBuilder.importSymbols("ASN1-REFINEMENT", "ConstraintsIntersection", "ConstraintsUnion", "SingleValueConstraint", "ValueRangeConstraint", "ValueSizeConstraint")
( Bits, Integer32, Integer32, MibIdentifier, NotificationType, MibScalar, MibTable, MibTableRow, MibTableColumn, TimeTicks, enterprises, ) = mibBuilder.importSymbols("SNMPv2-SMI", "Bits", "Integer32", "Integer32", "MibIdentifier", "NotificationType", "MibScalar", "MibTable", "MibTableRow", "MibTableColumn", "TimeTicks", "enterprises")

# Objects

myCompany = MibIdentifier((1, 3, 6, 1, 4, 1, 42))
testCount = MibScalar((1, 3, 6, 1, 4, 1, 42, 1), Integer32()).setMaxAccess("readonly")
if mibBuilder.loadTexts: testCount.setDescription("A sample count of something.")
testDescription = MibScalar((1, 3, 6, 1, 4, 1, 42, 2), OctetString()).setMaxAccess("readonly")
if mibBuilder.loadTexts: testDescription.setDescription("A description of something")

# Augmentions

# Notifications

testTrap = NotificationType((1, 3, 6, 1, 4, 1, 42, 3)).setObjects(*() )
if mibBuilder.loadTexts: testTrap.setDescription("Test notification")

# Exports

# Objects
mibBuilder.exportSymbols("MY-MIB", myCompany=myCompany, testCount=testCount, testDescription=testDescription)

# Notifications
mibBuilder.exportSymbols("MY-MIB", testTrap=testTrap)

Does anyone have an idea what could have caused that exception? I've been on Google for the last few hours searching but didn't find anything valuable.

Edit: Also when using the code from http://pysnmp.sourceforge.net/examples/current/v3arch/agent/cmdrsp/v2c-custom-scalar-mib-objects.html I get a similar error:

Traceback (most recent call last):
  File "agentTest2.py", line 8, in <module>
    snmpEngine = engine.SnmpEngine()
  File "/usr/local/lib/python2.7/dist-packages/pysnmp/entity/engine.py", line 18, in __init__
    self.msgAndPduDsp = MsgAndPduDispatcher()
  File "/usr/local/lib/python2.7/dist-packages/pysnmp/proto/rfc3412.py", line 24, in __init__
    'SNMP-TARGET-MIB', 'SNMP-USER-BASED-SM-MIB'
  File "/usr/local/lib/python2.7/dist-packages/pysnmp/smi/builder.py", line 259, in loadModules
    'MIB module \"%s\" load error: %s' % (modPath, traceback.format_exception(*sys.exc_info()))
pysnmp.smi.error.SmiError: MIB module "/usr/local/lib/python2.7/dist-packages/pysnmp/smi/mibs/SNMPv2-MIB.pyc" load error: ['Traceback (most recent call last):\n', '  File "/usr/local/lib/python2.7/dist-packages/pysnmp/smi/builder.py", line 255, in loadModules\n    exec(modData, g)\n', '  File "/usr/local/lib/python2.7/dist-packages/pysnmp/smi/mibs/SNMPv2-MIB.py", line 10, in <module>\n    ( ModuleCompliance, NotificationGroup, ObjectGroup, ) = mibBuilder.importSymbols("SNMPv2-CONF", "ModuleCompliance", "NotificationGroup", "ObjectGroup")\n', '  File "/usr/local/lib/python2.7/dist-packages/pysnmp/smi/builder.py", line 299, in importSymbols\n    self.loadModules(modName, **userCtx)\n', '  File "/usr/local/lib/python2.7/dist-packages/pysnmp/smi/builder.py", line 259, in loadModules\n    \'MIB module \\"%s\\" load error: %s\' % (modPath, traceback.format_exception(*sys.exc_info()))\n', 'SmiError: MIB module "/usr/local/lib/python2.7/dist-packages/pysnmp/smi/mibs/SNMPv2-CONF.pyc" load error: [\'Traceback (most recent call last):\\n\', \'  File "/usr/local/lib/python2.7/dist-packages/pysnmp/smi/builder.py", line 255, in loadModules\\n    exec(modData, g)\\n\', \'  File "/usr/local/lib/python2.7/dist-packages/pysnmp/smi/mibs/SNMPv2-CONF.py", line 2, in <module>\\n    MibNode, = mibBuilder.importSymbols(\\\'SNMPv2-SMI\\\', \\\'MibNode\\\')\\n\', \'  File "/usr/local/lib/python2.7/dist-packages/pysnmp/smi/builder.py", line 299, in importSymbols\\n    self.loadModules(modName, **userCtx)\\n\', \'  File "/usr/local/lib/python2.7/dist-packages/pysnmp/smi/builder.py", line 259, in loadModules\\n    \\\'MIB module \\\\"%s\\\\" load error: %s\\\' % (modPath, traceback.format_exception(*sys.exc_info()))\\n\', \'SmiError: MIB module "/usr/local/lib/python2.7/dist-packages/pysnmp/smi/mibs/SNMPv2-SMI.py" load error: [\\\'Traceback (most recent call last):\\\\n\\\', \\\'  File "/usr/local/lib/python2.7/dist-packages/pysnmp/smi/builder.py", line 255, in loadModules\\\\n    exec(modData, g)\\\\n\\\', \\\'  File "<string>", line 2\\\\n\\\', \\\'    -- WinAgents MIB Extraction Wizard\\\\n\\\', \\\'                   ^\\\\n\\\', \\\'SyntaxError: invalid syntax\\\\n\\\']\\n\']\n']

来源:https://stackoverflow.com/questions/24429161/pysnmp-exceptions

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!