Pysnmp Trap Receiver.for SNMPv3 的问题 [英] Issue with Pysnmp Trap Receiver.for SNMPv3

查看:211
本文介绍了Pysnmp Trap Receiver.for SNMPv3 的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PSNMP 套接字实际上正在接收陷阱,但没有调用回调函数.我已启用调试日志记录.使用 Pysnmp 4.3.3

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

我可以看到它收到了 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

推荐答案

SNMPv3 TRAPs 要求您将 TRAP 发送应用程序的 SNMP 引擎 ID 配置为 USM 用户表:

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')
)

因此,您应该配置(或在设备配置中找出)TRAP 发送应用程序或设备的权威 SNMP 引擎 ID,然后将它们配置到您的 TRAP 接收器中.

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.

如果您正在努力找出设备的 SNMP 引擎 ID,请尝试 这个工具 - 它会与您的设备对话并报告其 SNMP 引擎 ID.

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.

这是您如何使用 Net-SNMP snmptrap 工具将其 SNMP 引擎 ID 设置为特定值来发送 TRAP:

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

正如第一个链接所解释的,所有这些复杂性都是由于(否则是自动的)SNMP 引擎 ID 发现不通过单向消息传递(例如 TRAP)这一事实.

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.

这篇关于Pysnmp Trap Receiver.for SNMPv3 的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆