From cc47cb366fca2786437ba287ab3f16b4aa61d04d Mon Sep 17 00:00:00 2001 From: elie Date: Wed, 12 Oct 2005 19:52:50 +0000 Subject: NotificationOriginator now supports cbFun (used for Informs) --- examples/v3arch/agent/ntforg.py | 15 ++++++++++++--- pysnmp/entity/rfc3413/ntforg.py | 20 +++++++++++++++----- pysnmp/entity/rfc3413/oneliner/ntforg.py | 15 +++++++++------ 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') -- cgit v1.2.1