diff options
-rw-r--r-- | CHANGES.txt | 2 | ||||
-rw-r--r-- | examples/v3arch/asyncore/manager/ntfrcv/regexp-community-name.py | 1 | ||||
-rw-r--r-- | pysnmp/entity/rfc3413/ntfrcv.py | 9 | ||||
-rw-r--r-- | pysnmp/proto/proxy/rfc2576.py | 6 |
4 files changed, 13 insertions, 5 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index 04b01820..5fbe9d3e 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -16,6 +16,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 diff --git a/examples/v3arch/asyncore/manager/ntfrcv/regexp-community-name.py b/examples/v3arch/asyncore/manager/ntfrcv/regexp-community-name.py index 769aa2f5..448c682b 100644 --- a/examples/v3arch/asyncore/manager/ntfrcv/regexp-community-name.py +++ b/examples/v3arch/asyncore/manager/ntfrcv/regexp-community-name.py @@ -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 diff --git a/pysnmp/entity/rfc3413/ntfrcv.py b/pysnmp/entity/rfc3413/ntfrcv.py index c3cc2c1c..14f965ea 100644 --- a/pysnmp/entity/rfc3413/ntfrcv.py +++ b/pysnmp/entity/rfc3413/ntfrcv.py @@ -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 diff --git a/pysnmp/proto/proxy/rfc2576.py b/pysnmp/proto/proxy/rfc2576.py index 81390b2c..b576feba 100644 --- a/pysnmp/proto/proxy/rfc2576.py +++ b/pysnmp/proto/proxy/rfc2576.py @@ -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))) |