diff options
author | Ilya Etingof <etingof@gmail.com> | 2019-02-12 09:16:17 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-12 09:16:17 +0100 |
commit | b9a7b9c955df98b1e5eec250f418c3df3b7d0199 (patch) | |
tree | 3364eb15031352859586e8eb6aa49759a23f9c72 /examples/v1arch/asyncore/manager/ntfrcv/listen-on-ipv4-and-ipv6-interfaces.py | |
parent | c5f7842c430ad3431bee793362ef11cff9f1e0de (diff) | |
download | pysnmp-git-b9a7b9c955df98b1e5eec250f418c3df3b7d0199.tar.gz |
Reformat example scripts for easier reading (#241)
Diffstat (limited to 'examples/v1arch/asyncore/manager/ntfrcv/listen-on-ipv4-and-ipv6-interfaces.py')
-rw-r--r-- | examples/v1arch/asyncore/manager/ntfrcv/listen-on-ipv4-and-ipv6-interfaces.py | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/examples/v1arch/asyncore/manager/ntfrcv/listen-on-ipv4-and-ipv6-interfaces.py b/examples/v1arch/asyncore/manager/ntfrcv/listen-on-ipv4-and-ipv6-interfaces.py index 36812977..401a29d2 100644 --- a/examples/v1arch/asyncore/manager/ntfrcv/listen-on-ipv4-and-ipv6-interfaces.py +++ b/examples/v1arch/asyncore/manager/ntfrcv/listen-on-ipv4-and-ipv6-interfaces.py @@ -28,20 +28,23 @@ from pysnmp.proto import api # noinspection PyUnusedLocal def cbFun(transportDispatcher, transportDomain, transportAddress, wholeMsg): + while wholeMsg: msgVer = int(api.decodeMessageVersion(wholeMsg)) if msgVer in api.PROTOCOL_MODULES: pMod = api.PROTOCOL_MODULES[msgVer] + else: print('Unsupported SNMP version %s' % msgVer) return + reqMsg, wholeMsg = decoder.decode( wholeMsg, asn1Spec=pMod.Message(), ) - print('Notification message from %s:%s: ' % ( - transportDomain, transportAddress - ) - ) + + print('Notification message from %s:%s: ' % (transportDomain, + transportAddress)) + reqPDU = pMod.apiMessage.getPDU(reqMsg) if reqPDU.isSameTypeWith(pMod.TrapPDU()): if msgVer == api.SNMP_VERSION_1: @@ -51,11 +54,15 @@ def cbFun(transportDispatcher, transportDomain, transportAddress, wholeMsg): print('Specific Trap: %s' % (pMod.apiTrapPDU.getSpecificTrap(reqPDU).prettyPrint())) print('Uptime: %s' % (pMod.apiTrapPDU.getTimeStamp(reqPDU).prettyPrint())) varBinds = pMod.apiTrapPDU.getVarBinds(reqPDU) + else: varBinds = pMod.apiPDU.getVarBinds(reqPDU) + print('Var-binds:') + for oid, val in varBinds: print('%s = %s' % (oid.prettyPrint(), val.prettyPrint())) + return wholeMsg @@ -78,6 +85,6 @@ transportDispatcher.jobStarted(1) try: # Dispatcher will never finish as job#1 never reaches zero transportDispatcher.runDispatcher() -except: + +finally: transportDispatcher.closeDispatcher() - raise |