[Python] pySNMP unable to dispatch SNMPv3 trap: "No callback for 'None' found"

Discussão em 'Python' iniciado por Stack, Outubro 4, 2024.

  1. Stack

    Stack Membro Participativo

    I'm trying to get a SNMPv3 trap listener to work, and have hit a wall.

    The trap packet arrives, but the code errors before the callback function ever gets called. All the available discussions point out to specifying a matching EngineID, which I have — no change.

    The error is

    File "/usr/local/lib/python3.9/site-packages/pysnmp/carrier/base.py", line 146, in _cbFun
    raise error.CarrierError(
    pysnmp.carrier.error.CarrierError: No callback for "None" found - losing incoming event


    My code:

    from pysnmp.hlapi import *
    from pysnmp.carrier.asyncio.dispatch import AsyncioDispatcher
    from pysnmp.carrier.asyncio.dgram import udp
    from pyasn1.codec.ber import decoder
    from pysnmp.proto import api
    from pysnmp.proto import rfc1902
    from pysnmp.entity import config
    from pysnmp.smi import builder
    from pysnmp.entity.rfc3413 import ntfrcv


    snmpEngine = config.SnmpEngine()

    config.addV3User(
    snmpEngine,
    "usertest",
    config.USM_AUTH_NONE,
    None,
    config.USM_PRIV_NONE,
    None,
    securityEngineId = rfc1902.OctetString(hexValue='8000000001020304'),
    )

    # Callback function for handling incoming SNMP traps
    def cbFun(snmpEngine, stateReference, contextEngineId, contextName, varBinds, cbCtx):
    print("Made it to the callback")

    transportDispatcher = AsyncioDispatcher()

    ntfrcv.NotificationReceiver(snmpEngine, cbFun)

    transportDispatcher.registerTransport(
    udp.DOMAIN_NAME, udp.UdpAsyncioTransport().openServerMode(('192.168.120.56', 162))
    )

    transportDispatcher.jobStarted(1)

    try:
    transportDispatcher.runDispatcher()

    except KeyboardInterrupt:
    print("Shutting down...")

    finally:
    transportDispatcher.closeDispatcher()


    And the command to generate the trap:

    sudo snmptrap -v 3 -u usertest -l noAuthNoPriv -e 0x8000000001020304 192.168.120.56 '' .1.3.6.1.4.1


    Python 3.9, pySNMP 7.1.4

    Continue reading...

Compartilhe esta Página