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
@Ilyly Etingof谢谢伊利亚指出,现在它的作品很好。在实际的硬件中,像roadm或开关似乎这个值在我配置的所有用户中都是相同的。你有任何想法如何从硬件获取这个值或以某种方式派生它? – sbhatta
@ user3502325更新我的答案,希望给你更多的提示。 ;-) –