Reputation: 49
PSNMP Socket is actually receiving traps but the call back function is not getting called. I have enabled the debug logging. Using Pysnmp 4.3.3
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'
)
def cbFun(snmpEngine, stateReference, contextEngineId, contextName,
varBinds, cbCtx):
print "#######################Recived Notification from {} #######################".format(snmpEngine.msgAndPduDsp.getTransportInfo(stateReference)[-1][0])
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
I can see its reciving the v3 traps:
2017-02-24 00:46:02,853 pysnmp: prepareDataElements: SNMPv3Message:
msgVersion=3
msgGlobalData=HeaderData:
msgID=16259
msgMaxSize=65535
msgFlags=0x00
msgSecurityModel=3
msgSecurityParameters=0x3027040c80000f150000000000000000020100020100040d757365725f736e6d703132333404000400
msgData=ScopedPduData:
plaintext=ScopedPDU:
contextEngineId=0x80000f150000000000000000
contextName=
data=PDUs:
snmpV2-trap=SNMPv2TrapPDU:
request-id=775985686
error-status='noError'
error-index=0
variable-bindings=VarBindList:
VarBind:
name=1.3.6.1.2.1.1.3.0
=_BindValue:
value=ObjectSyntax:
application-wide=ApplicationSyntax:
timeticks-value=10000
But at the end I am gating some error like this :
2017-02-24 00:46:02,853 pysnmp: prepareDataElements: msg data msgVersion 3 msgID 16259 securityModel 3
2017-02-24 00:46:02,854 pysnmp: processIncomingMsg: securityParameters
00000: 30 27 04 0C 80 00 0F 15 00 00 00 00 00 00 00 00
00016: 02 01 00 02 01 00 04 0D 75 73 65 72 5F 73 6E 6D
00032: 70 31 32 33 34 04 00 04 00
2017-02-24 00:46:02,854 pysnmp: processIncomingMsg: UsmSecurityParameters:
msgAuthoritativeEngineId=0x80000f150000000000000000
msgAuthoritativeEngineBoots=0
msgAuthoritativeEngineTime=0
msgUserName=user_snmp1234
msgAuthenticationParameters=
msgPrivacyParameters=
2017-02-24 00:46:02,855 pysnmp: processIncomingMsg: cache write securityStateReference 6156330 by msgUserName user_snmp1234
2017-02-24 00:46:02,855 pysnmp: processIncomingMsg: unsynchronized securityEngineID OctetString(hexValue='80000f150000000000000000')
2017-02-24 00:46:02,855 pysnmp: processIncomingMsg: read from securityParams msgAuthoritativeEngineId OctetString(hexValue='80000f150000000000000000') msgUserName OctetString('user_snmp1234', subtypeSpec=ConstraintsIntersection(ConstraintsIntersection(), ValueSizeConstraint(0, 32)))
2017-02-24 00:46:02,855 pysnmp: processIncomingMsg: unknown securityEngineID OctetString(hexValue='80000f150000000000000000') msgUserName OctetString('user_snmp1234', subtypeSpec=ConstraintsIntersection(ConstraintsIntersection(), ValueSizeConstraint(0, 32)))
2017-02-24 00:46:02,855 pysnmp: StatusInformation: {'securityLevel': 1, 'contextName': '', 'val': Counter32(3), 'contextEngineId': SnmpEngineID(), 'oid': (1, 3, 6, 1, 6, 3, 15, 1, 1, 3, 0), 'maxSizeResponseScopedPDU': 65446, 'securityStateReference': 6156330, 'errorIndication': <pysnmp.proto.errind.UnknownSecurityName object at 0x7f1c3d7cf910>}
2017-02-24 00:46:02,855 pysnmp: prepareDataElements: SM failed, statusInformation {'securityLevel': 1, 'contextName': '', 'val': Counter32(3), 'contextEngineId': SnmpEngineID(), 'oid': (1, 3, 6, 1, 6, 3, 15, 1, 1, 3, 0), 'maxSizeResponseScopedPDU': 65446, 'securityStateReference': 6156330, 'errorIndication': <pysnmp.proto.errind.UnknownSecurityName object at 0x7f1c3d7cf910>}
2017-02-24 00:46:02,855 pysnmp: returnResponsePdu: PDU <empty>
2017-02-24 00:46:02,855 pysnmp: prepareResponseMessage: stateReference 9434948
2017-02-24 00:46:02,856 pysnmp: StatusInformation: {'errorIndication': <pysnmp.proto.errind.LoopTerminated object at 0x7f1c3d7cf290>}
2017-02-24 00:46:02,856 pysnmp: prepareDataElements: error reported
Upvotes: 0
Views: 2053
Reputation: 5555
SNMPv3 TRAPs mandate you configuring SNMP Engine ID of the TRAP sending application to USM users table of TRAP receiving application for each USM user:
config.addV3User(
snmpEngine, 'user_snmp1234',
securityEngineId=v2c.OctetString(hexValue='8000000001020304')
)
So you should either configure (or figure out in device configuration) authoritative SNMP engine ID of your TRAP sending apps or devices, then configure them into your TRAP receiver.
If you are struggling figuring out SNMP engine ID of your devices, try this tool -- it will talk to your device and report its SNMP engine ID.
This is how you could send TRAP with Net-SNMP snmptrap tool setting its SNMP engine ID to specific value:
$ snmptrap -v3 -u user_snmp1234 -l noAuthNoPriv -e 8000000001020304 127.0.0.1 123 1.3.6.1.6.3.1.1.5.1
As explained by the first link, all that complications are due to the fact that (otherwise automatic) SNMP engine ID discovery does not over unidirectional messaging such as TRAPs.
Upvotes: 1