summaryrefslogtreecommitdiff
path: root/pysnmp/entity/rfc3413/oneliner/sync/compat/ntforg.py
blob: 7a9291c0d716da320e0cf462025586a8b0093c22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from pysnmp.entity.rfc3413.oneliner.ntforg import *

if version_info[:2] < (2, 6):
    def next(iter):
        return iter.next()

#
# Synchronous one-liner SNMP Notification Originator application
#

def sendNotification(snmpEngine, authData, transportTarget, contextData,
                     notifyType, varBinds, **options):

    def cbFun(snmpEngine, sendRequestHandle,
              errorIndication, errorStatus, errorIndex,
              varBinds, cbCtx):
        cbCtx['errorIndication'] = errorIndication
        cbCtx['errorStatus'] = errorStatus
        cbCtx['errorIndex'] = errorIndex
        cbCtx['varBinds'] = varBinds

    cbCtx = {}

    ntfOrg = AsyncNotificationOriginator()

    if varBinds:
        ntfOrg.sendNotification(
            snmpEngine,
            authData,
            transportTarget,
            contextData,
            notifyType,
            varBinds,
            (cbFun, cbCtx),
            options.get('lookupMib', True)
        )

        snmpEngine.transportDispatcher.runDispatcher()

        errorIndication = cbCtx.get('errorIndication')
        errorStatus = cbCtx.get('errorStatus')
        errorIndex = cbCtx.get('errorIndex')
        varBinds = cbCtx.get('varBinds', [])
    else:
        errorIndication = errorStatus = errorIndex = None
        varBinds = []

    yield errorIndication, errorStatus, errorIndex, varBinds