2017-02-24 172 views
0

PSNMP Socket实际上正在接收陷阱,但回调函数没有被调用。我已启用调试日志记录。使用Pysnmp 4.3.3Pysnmp Trap Receiver.for SNMPv3问题

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 

我可以看到它的reciving v3的陷阱:

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 

但最后我选通的一些错误是这样的:

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 

回答

0

SNMPv3 TRAP mandate您将TRAP发送应用程序的SNMP引擎ID配置为TRAP接收用于每个USM用户应用:

config.addV3User(
    snmpEngine, 'user_snmp1234', 
    securityEngineId=v2c.OctetString(hexValue='8000000001020304') 
) 

所以,你应该要么配置(或在设备配置弄清楚)你的TRAP发送的应用或设备的权威SNMP引擎ID,然后将它们配置到您的TRAP接收机。

如果您正在努力确定设备的SNMP引擎ID,请尝试this tool - 它会与您的设备通信并报告其SNMP引擎ID。

这是怎么了,你可以发送带有的Net-SNMP SNMPTRAP工具TRAP其SNMP引擎ID设置为特定值:

$ snmptrap -v3 -u user_snmp1234 -l noAuthNoPriv -e 8000000001020304 127.0.0.1 123 1.3.6.1.6.3.1.1.5.1 

随着第一环节,所有的并发症是由于这样的事实解释(否则自动)SNMP引擎ID发现不会超过单向消息,如TRAP。

+0

@Ilyly Etingof谢谢伊利亚指出,现在它的作品很好。在实际的硬件中,像roadm或开关似乎这个值在我配置的所有用户中都是相同的。你有任何想法如何从硬件获取这个值或以某种方式派生它? – sbhatta

+0

@ user3502325更新我的答案,希望给你更多的提示。 ;-) –