PYSNMP陷阱/通知接收器与PYSNMP 4.3.4和4.3.3发生冲突

时间:2017-03-16 20:46:17

标签: python-2.7 snmp pysnmp

Pysnmp陷阱接收器与PYSNMP-4.3.4相同,与4.3.3相同 4.3.2它工作得很好.Iusse每次都可以重现。 当代理同时发出多个陷阱消息时发生。

与此类似,您将看不到错误:

snmptrap -v3 -u user_auth1 -l noAuthNoPriv -e 80000F150000000000000000 127.0.0.1:1036 123 1.3.6.1.6.3.1.1.5.1

当代理HW正在发送多个陷阱消息时,此问题正在复制。

请参阅下面用于重现问题的代码,

    from pysnmp.entity import engine, config
    from pysnmp.carrier.asyncore.dgram import udp
    from pysnmp.entity.rfc3413 import ntfrcv
    from pysnmp.proto.api import v2c
    from pysnmp.smi import builder, view, compiler, rfc1902, error
    from pysnmp import debug 
    debug.setLogger(debug.Debug('all'))
    snmpEngine = engine.SnmpEngine()
    config.addTransport(
        snmpEngine,
        udp.domainName,
        udp.UdpTransport().openServerMode(('0.0.0.0', 1036))
    )

    config.addV3User(
        snmpEngine, 'user_snmp1234',
        config.usmHMACMD5AuthProtocol, 'authkey1',
        config.usmDESPrivProtocol, 'privkey1',
        securityEngineId=v2c.OctetString(hexValue='80000F150000000000000000')
    )

config.addV3User(
    snmpEngine, 'user_auth1',
    securityEngineId=v2c.OctetString(hexValue='80000F150000000000000000')
)

    mibBuilder = builder.MibBuilder()
    custom_mib_path= <provide the MIB Path>
    compiler.addMibCompiler(mibBuilder, sources=custom_mib_path.split(","))
    mibViewController = view.MibViewController(mibBuilder)
    load_mib_module = <PROVIDE the MIB Modules>
    for mibs in load_mib_module.split(","):
        mibBuilder.loadModules(mibs)

    def cbFun(snmpEngine, stateReference, contextEngineId, contextName,
              varBinds, cbCtx):
        print "#######################Recived Notification from {} #######################".format(snmpEngine.msgAndPduDsp.getTransportInfo(stateReference)[-1][0])
        execContext = snmpEngine.observer.getExecutionContext(
            'rfc3412.receiveMessage:request'
        )
        #print "########### execContext {}".format(execContext) 
        print('Notification from %s, ContextEngineId "%s", ContextName "%s " SNMPVER "%s" securityName "%s"' % ('@'.join([str(x) for x in execContext['transportAddress']]),contextEngineId.prettyPrint(),contextName.prettyPrint(), execContext['securityModel'], execContext['securityName']))
        for oid, val in varBinds:
            output = rfc1902.ObjectType(rfc1902.ObjectIdentity(oid),val).resolveWithMib(mibViewController).prettyPrint()
            print output

    ntfrcv.NotificationReceiver(snmpEngine, cbFun)
    snmpEngine.transportDispatcher.jobStarted(1) 
    try:
        snmpEngine.transportDispatcher.runDispatcher()
    except:
        snmpEngine.transportDispatcher.closeDispatcher()
        raise

当收到多个TRAP消息时,它会抛出异常,如:

    Traceback (most recent call last):
      File "<stdin>", line 2, in <module>
      File "/home/user/VIRT/lib/python2.7/site-packages/pysnmp/carrier/asyncore/dispatch.py", line 50, in runDispatcher
        raise PySnmpError('poll error: %s' % ';'.join(format_exception(*exc_info())))
    pysnmp.error.PySnmpError: poll error: Traceback (most recent call last):
    ;  File "/home/user/VIRT/lib/python2.7/site-packages/pysnmp/carrier/asyncore/dispatch.py", line 46, in runDispatcher
        use_poll=True, map=self.__sockMap, count=1)
    ;  File "/local/python/2.7.8/lib/python2.7/asyncore.py", line 220, in loop
        poll_fun(timeout, map)
    ;  File "/local/python/2.7.8/lib/python2.7/asyncore.py", line 201, in poll2
        readwrite(obj, flags)
    ;  File "/local/python/2.7.8/lib/python2.7/asyncore.py", line 123, in readwrite
        obj.handle_error()
    ;  File "/local/python/2.7.8/lib/python2.7/asyncore.py", line 108, in readwrite
        obj.handle_read_event()
    ;  File "/local/python/2.7.8/lib/python2.7/asyncore.py", line 449, in handle_read_event
        self.handle_read()
    ;  File "/home/user/VIRT/lib/python2.7/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 163, in handle_read
        self._cbFun(self, transportAddress, incomingMessage)
    ;  File "/home/user/VIRT/lib/python2.7/site-packages/pysnmp/carrier/base.py", line 70, in _cbFun
        self, transportDomain, transportAddress, incomingMessage
    ;  File "/home/user/VIRT/lib/python2.7/site-packages/pysnmp/entity/engine.py", line 154, in __receiveMessageCbFun
        self, transportDomain, transportAddress, wholeMsg
    ;  File "/home/user/VIRT/lib/python2.7/site-packages/pysnmp/proto/rfc3412.py", line 421, in receiveMessage
        PDU, maxSizeResponseScopedPDU, stateReference)
    ;  File "/home/user/VIRT/lib/python2.7/site-packages/pysnmp/entity/rfc3413/ntfrcv.py", line 99, in processPdu
        contextName, varBinds, self.__cbCtx)
    ;  File "<stdin>", line 10, in cbFun
    ;  File "/home/user/VIRT/lib/python2.7/site-packages/pysnmp/smi/rfc1902.py", line 865, in resolveWithMib
        self.__args[1] = self.__args[0].getMibNode().getSyntax().clone(self.__args[1])
    ;  File "/home/user/VIRT/lib/python2.7/site-packages/pysnmp/proto/rfc1902.py", line 203, in clone
        return univ.OctetString.clone(self, *args, **kwargs).setFixedLength(self.getFixedLength())
    ;  File "/home/user/VIRT/lib/python2.7/site-packages/pyasn1/type/univ.py", line 881, in clone
        value, tagSet, subtypeSpec, encoding, binValue, hexValue
    ;  File "/home/user/VIRT/lib/python2.7/site-packages/pyasn1/type/univ.py", line 833, in __init__
        base.AbstractSimpleAsn1Item.__init__(self, value, tagSet, subtypeSpec)
    ;  File "/home/user/VIRT/lib/python2.7/site-packages/pyasn1/type/base.py", line 176, in __init__
        value = self.prettyIn(value)
    ;  File "/tmp/pip-build-K5McN0/pysnmp/pysnmp/smi/mibs/SNMPv2-TC.py", line 273, in prettyIn

;  File "/home/user/VIRT/lib/python2.7/site-packages/pyasn1/type/base.py", line 107, in isSuperTypeOf
    self._tagSet.isSuperTagSetOf(other.getTagSet())) and \
;  File "/home/user/VIRT/lib/python2.7/site-packages/pyasn1/type/tag.py", line 177, in isSuperTagSetOf
    if self.__superTags[idx] != tagSet[idx]:
;  File "/home/user/VIRT/lib/python2.7/site-packages/pyasn1/type/tag.py", line 142, in __getitem__
    if isinstance(idx, slice):
;RuntimeError: maximum recursion depth exceeded while calling a Python object

1 个答案:

答案 0 :(得分:0)

此问题将在PYSNMP 4.3.5中修复。 https://github.com/etingof/pysnmp/issues/46