NotificationReceiver reports SNMPv1 TRAP community string
parent
305c94fdb1
commit
eada4862d6
|
@ -9,6 +9,8 @@ Revision 4.3.10, released 2017-10-XX
|
|||
it propagates to the return value. Before this fix
|
||||
ObjectIdentity.prettyPrint() may crash when rendering malformed SNMP
|
||||
table indices.
|
||||
- Fixed NotificationReceiver to include SNMPv1 TRAP Message community
|
||||
string into SNMPv2c/v3 TRAP PDU
|
||||
- Fixed multiple bugs in SNMP table indices rendering, especially
|
||||
the InetAddressIPv6 type which was severely broken.
|
||||
- Fixed crashing Bits.prettyPrint() implementation
|
||||
|
|
|
@ -28,7 +28,6 @@ CommunityName's, not explicitly configured to local SNMP Engine.
|
|||
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
|
||||
import re
|
||||
|
||||
# Create SNMP engine with autogenernated engineID and pre-bound
|
||||
|
|
|
@ -21,10 +21,17 @@ class NotificationReceiver(object):
|
|||
snmpEngine.msgAndPduDsp.registerContextEngineId(
|
||||
null, self.pduTypes, self.processPdu # '' is a wildcard
|
||||
)
|
||||
|
||||
self.__snmpTrapCommunity = ''
|
||||
self.__cbFunVer = 0
|
||||
self.__cbFun = cbFun
|
||||
self.__cbCtx = cbCtx
|
||||
|
||||
def storeSnmpTrapCommunity(snmpEngine, execpoint, variables, cbCtx):
|
||||
self.__snmpTrapCommunity = variables.get('communityName', '')
|
||||
|
||||
snmpEngine.observer.registerObserver(storeSnmpTrapCommunity, 'rfc2576.processIncomingMsg')
|
||||
|
||||
def close(self, snmpEngine):
|
||||
snmpEngine.msgAndPduDsp.unregisterContextEngineId(
|
||||
null, self.pduTypes
|
||||
|
@ -39,7 +46,7 @@ class NotificationReceiver(object):
|
|||
# Agent-side API complies with SMIv2
|
||||
if messageProcessingModel == 0:
|
||||
origPdu = PDU
|
||||
PDU = rfc2576.v1ToV2(PDU)
|
||||
PDU = rfc2576.v1ToV2(PDU, snmpTrapCommunity=self.__snmpTrapCommunity)
|
||||
else:
|
||||
origPdu = None
|
||||
|
||||
|
|
|
@ -97,7 +97,7 @@ __v2ToV1ErrorMap = {
|
|||
__zeroInt = v1.Integer(0)
|
||||
|
||||
|
||||
def v1ToV2(v1Pdu, origV2Pdu=None):
|
||||
def v1ToV2(v1Pdu, origV2Pdu=None, snmpTrapCommunity=''):
|
||||
pduType = v1Pdu.tagSet
|
||||
v2Pdu = __v1ToV2PduMap[pduType].clone()
|
||||
|
||||
|
@ -119,13 +119,13 @@ def v1ToV2(v1Pdu, origV2Pdu=None):
|
|||
else:
|
||||
snmpTrapOIDParam = v2c.ObjectIdentifier(__v1ToV2TrapMap[genericTrap])
|
||||
|
||||
# 3.1.4 (XXX snmpTrapCommunity.0 is missing here)
|
||||
# 3.1.4
|
||||
v2VarBinds.append((v2c.apiTrapPDU.sysUpTime, sysUpTime))
|
||||
v2VarBinds.append((v2c.apiTrapPDU.snmpTrapOID, snmpTrapOIDParam))
|
||||
v2VarBinds.append(
|
||||
(v2c.apiTrapPDU.snmpTrapAddress, v1.apiTrapPDU.getAgentAddr(v1Pdu))
|
||||
)
|
||||
v2VarBinds.append((v2c.apiTrapPDU.snmpTrapCommunity, v2c.OctetString("")))
|
||||
v2VarBinds.append((v2c.apiTrapPDU.snmpTrapCommunity, v2c.OctetString(snmpTrapCommunity)))
|
||||
v2VarBinds.append((v2c.apiTrapPDU.snmpTrapEnterprise,
|
||||
v1.apiTrapPDU.getEnterprise(v1Pdu)))
|
||||
|
||||
|
|
Loading…
Reference in New Issue