summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorelie <elie>2009-05-22 07:01:02 +0000
committerelie <elie>2009-05-22 07:01:02 +0000
commit99d320277505a7e746a3576e938de6a54bf45d9a (patch)
tree7e2ad9d089b3f843bd4c123c88cb2dbfa5913bad
parente7e0fee60aa2e188bbf3e43dfdfb23ef645be862 (diff)
downloadpysnmp-99d320277505a7e746a3576e938de6a54bf45d9a.tar.gz
pass stateReference to NotificationReceiver app and let it browse
request details (transport details at the moment) using stateReference
-rw-r--r--examples/v3arch/manager/ntfrcv.py6
-rw-r--r--pysnmp/entity/rfc3413/ntfrcv.py22
-rw-r--r--pysnmp/proto/mpmod/rfc3412.py6
-rw-r--r--pysnmp/proto/rfc3412.py18
4 files changed, 46 insertions, 6 deletions
diff --git a/examples/v3arch/manager/ntfrcv.py b/examples/v3arch/manager/ntfrcv.py
index 81bf25a..0e63982 100644
--- a/examples/v3arch/manager/ntfrcv.py
+++ b/examples/v3arch/manager/ntfrcv.py
@@ -32,11 +32,13 @@ config.addV3User(
# Callback function for receiving notifications
def cbFun(snmpEngine,
+ stateReference,
contextEngineId, contextName,
varBinds,
cbCtx):
- print 'Notification from SNMP Engine \"%s\", Context \"%s\"' % (
- contextEngineId, contextName
+ transportDomain, transportAddress = snmpEngine.msgAndPduDsp.getTransportInfo(stateReference)
+ print 'Notification from %s, SNMP Engine \"%s\", Context \"%s\"' % (
+ transportAddress, contextEngineId, contextName
)
for name, val in varBinds:
print '%s = %s' % (name.prettyPrint(), val.prettyPrint())
diff --git a/pysnmp/entity/rfc3413/ntfrcv.py b/pysnmp/entity/rfc3413/ntfrcv.py
index 308431d..3ff4274 100644
--- a/pysnmp/entity/rfc3413/ntfrcv.py
+++ b/pysnmp/entity/rfc3413/ntfrcv.py
@@ -14,6 +14,7 @@ class NotificationReceiver:
snmpEngine.msgAndPduDsp.registerContextEngineId(
'', self.pduTypes, self.processPdu # '' is a wildcard
)
+ self.__cbFunVer = 0
self.__cbFun = cbFun
self.__cbCtx = cbCtx
@@ -86,6 +87,21 @@ class NotificationReceiver:
else:
raise error.ProtocolError('Unexpected PDU class %s' % PDU.tagSet)
- self.__cbFun(
- snmpEngine, contextEngineId, contextName, varBinds, self.__cbCtx
- )
+ if self.__cbFunVer:
+ self.__cbFun(
+ snmpEngine, stateReference, contextEngineId, contextName,
+ varBinds, self.__cbCtx
+ )
+ else:
+ # Compatibility stub (handle legacy cbFun interface)
+ try:
+ self.__cbFun(
+ snmpEngine, contextEngineId, contextName,
+ varBinds, self.__cbCtx
+ )
+ except TypeError:
+ self.__cbFunVer = 1
+ self.__cbFun(
+ snmpEngine, stateReference, contextEngineId, contextName,
+ varBinds, self.__cbCtx
+ )
diff --git a/pysnmp/proto/mpmod/rfc3412.py b/pysnmp/proto/mpmod/rfc3412.py
index 9aac846..1545c6a 100644
--- a/pysnmp/proto/mpmod/rfc3412.py
+++ b/pysnmp/proto/mpmod/rfc3412.py
@@ -709,8 +709,12 @@ class SnmpV3MessageProcessingModel(AbstractMessageProcessingModel):
# 7.2.14
if rfc3411.unconfirmedClassPDUs.has_key(pduType):
+ # Pass new stateReference to let app browse request details
+ stateReference = self._newStateReference()
+
# This is not specified explicitly in RFC
smHandler.releaseStateInformation(securityStateReference)
+
return ( messageProcessingModel,
securityModel,
securityName,
@@ -723,7 +727,7 @@ class SnmpV3MessageProcessingModel(AbstractMessageProcessingModel):
sendPduHandle,
maxSizeResponseScopedPDU,
statusInformation,
- None )
+ stateReference )
smHandler.releaseStateInformation(securityStateReference)
raise error.StatusInformation(
diff --git a/pysnmp/proto/rfc3412.py b/pysnmp/proto/rfc3412.py
index db97322..2b46229 100644
--- a/pysnmp/proto/rfc3412.py
+++ b/pysnmp/proto/rfc3412.py
@@ -30,6 +30,9 @@ class MsgAndPduDispatcher:
self.__sendPduHandle = 0L
self.__cacheRepository = {}
+ # To pass transport info to app
+ self.__transportInfo = {}
+
# These routines manage cache of management apps
def __newSendPduHandle(self):
@@ -60,6 +63,14 @@ class MsgAndPduDispatcher:
if cbFun(snmpEngine, cachedParams):
del self.__cacheRepository[index]
+ def getTransportInfo(self, stateReference):
+ if self.__transportInfo.has_key(stateReference):
+ return self.__transportInfo[stateReference]
+ else:
+ raise error.ProtocolError(
+ 'No data for stateReference %s' % stateReference
+ )
+
# Application registration with dispatcher
# 4.3.1
@@ -394,6 +405,11 @@ class MsgAndPduDispatcher:
# 4.2.2.1.2.d
return restOfWholeMsg
else:
+ # Pass transport info to app
+ if stateReference is not None:
+ self.__transportInfo[stateReference] = (
+ transportDomain, transportAddress
+ )
# 4.2.2.1.3
processPdu(
snmpEngine,
@@ -408,6 +424,8 @@ class MsgAndPduDispatcher:
maxSizeResponseScopedPDU,
stateReference
)
+ if stateReference is not None:
+ del self.__transportInfo[stateReference]
debug.logger & debug.flagDsp and debug.logger('receiveMessage: processPdu succeeded')
return restOfWholeMsg
else: