summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorelie <elie>2005-10-12 19:52:50 +0000
committerelie <elie>2005-10-12 19:52:50 +0000
commitcc47cb366fca2786437ba287ab3f16b4aa61d04d (patch)
treeeedc213f1acb40e6ae49c927305b3bda9adea296
parent1130f496129bbb5b67f7df50a46a088293118d11 (diff)
downloadpysnmp-cc47cb366fca2786437ba287ab3f16b4aa61d04d.tar.gz
NotificationOriginator now supports cbFun (used for Informs)
-rw-r--r--examples/v3arch/agent/ntforg.py15
-rw-r--r--pysnmp/entity/rfc3413/ntforg.py20
-rw-r--r--pysnmp/entity/rfc3413/oneliner/ntforg.py15
3 files changed, 36 insertions, 14 deletions
diff --git a/examples/v3arch/agent/ntforg.py b/examples/v3arch/agent/ntforg.py
index 97442fd..508e665 100644
--- a/examples/v3arch/agent/ntforg.py
+++ b/examples/v3arch/agent/ntforg.py
@@ -46,10 +46,19 @@ config.addTrapUser(snmpEngine, 3, 'test-user', 'authPriv', (1,3,6)) # v3
# SNMP context
snmpContext = context.SnmpContext(snmpEngine)
-
-ntforg.NotificationOriginator(snmpContext).sendNotification(
+
+def cbFun(snmpEngine, errorIndication):
+ if errorIndication:
+ print errorIndication
+
+errorIndication = ntforg.NotificationOriginator(snmpContext).sendNotification(
snmpEngine, 'myNotifyName', ('SNMPv2-MIB', 'coldStart'),
- (((1,3,6,1,2,1,1,5), v2c.OctetString('Example Notificator')),), ''
+ (((1,3,6,1,2,1,1,5), v2c.OctetString('Example Notificator')),),
+ cbFun
)
+if errorIndication:
+ print errorIndication
+ return
+
snmpEngine.transportDispatcher.runDispatcher()
diff --git a/pysnmp/entity/rfc3413/ntforg.py b/pysnmp/entity/rfc3413/ntforg.py
index c1225fa..f31cd55 100644
--- a/pysnmp/entity/rfc3413/ntforg.py
+++ b/pysnmp/entity/rfc3413/ntforg.py
@@ -25,7 +25,7 @@ class NotificationOriginator:
PDU,
statusInformation,
sendPduHandle,
- cbData
+ (cbFun, cbCtx)
):
# 3.3.6d
( origTransportDomain,
@@ -47,7 +47,13 @@ class NotificationOriginator:
snmpEngine.transportDispatcher.jobFinished(id(self))
- if statusInformation and origRetries != origRetryCount:
+ if statusInformation:
+ if origRetries == origRetryCount:
+ cbFun(origSendRequestHandle,
+ statusInformation['errorIndication'],
+ cbCtx)
+ return
+
# 3.3.6a
sendPduHandle = snmpEngine.msgAndPduDsp.sendPdu(
snmpEngine,
@@ -61,7 +67,8 @@ class NotificationOriginator:
origContextName,
origPduVersion,
origPdu,
- (self.processResponsePdu, origTimeout/1000 + time.time(), None)
+ (self.processResponsePdu, origTimeout/1000 + time.time(),
+ (cbFun, cbCtx))
)
snmpEngine.transportDispatcher.jobStarted(id(self))
@@ -86,7 +93,7 @@ class NotificationOriginator:
return
# 3.3.6c
- pass
+ cbFun(origSendRequestHandle, None, cbCtx)
def sendNotification(
self,
@@ -94,6 +101,8 @@ class NotificationOriginator:
notificationTarget,
notificationName,
additionalVarBinds=None,
+ cbFun=None,
+ cbCtx=None,
contextName=''
):
# 3.3
@@ -209,7 +218,8 @@ class NotificationOriginator:
contextName,
pduVersion,
pdu,
- (self.processResponsePdu, timeout/1000 + time.time(), None)
+ (self.processResponsePdu, timeout/1000 + time.time(),
+ (cbFun, cbCtx))
)
# 3.3.6b
diff --git a/pysnmp/entity/rfc3413/oneliner/ntforg.py b/pysnmp/entity/rfc3413/oneliner/ntforg.py
index a99d439..f49fa20 100644
--- a/pysnmp/entity/rfc3413/oneliner/ntforg.py
+++ b/pysnmp/entity/rfc3413/oneliner/ntforg.py
@@ -26,7 +26,7 @@ class AsynNotificationOriginator(cmdgen.AsynCommandGenerator):
def asyncSendNotification(
self, authData, transportTarget, notifyType,
- notificationType, varBinds=None
+ notificationType, varBinds=None, cbFun=None, cbCtx=None
):
tagList = 'notify-list'
addrName, paramsName = cmdgen.AsynCommandGenerator._configure(
@@ -66,19 +66,22 @@ class AsynNotificationOriginator(cmdgen.AsynCommandGenerator):
else:
__varBinds = None
- return ntforg.NotificationOriginator(self.snmpContext).sendNotification(
- self.snmpEngine, notifyName, notificationType, __varBinds
- )
+ return ntforg.NotificationOriginator(self.snmpContext).sendNotification(self.snmpEngine, notifyName, notificationType, __varBinds, cbFun, cbCtx)
class NotificationOriginator(AsynNotificationOriginator):
def sendNotification(
self, authData, transportTarget, notifyType,
notificationType, varBinds=None
):
+ def __cbFun(sendRequestHandle, errorIndication, appReturn):
+ appReturn['errorIndication'] = errorIndication
+
+ appReturn = {}
errorIndication = self.asyncSendNotification(
- authData, transportTarget, notifyType, notificationType, varBinds
+ authData, transportTarget, notifyType, notificationType, varBinds,
+ __cbFun, appReturn
)
if errorIndication:
return errorIndication
self.snmpEngine.transportDispatcher.runDispatcher()
-
+ return appReturn.get('errorIndication')