summaryrefslogtreecommitdiff
path: root/examples/v1arch/asyncore/manager/ntfrcv/listen-on-ipv4-and-ipv6-interfaces.py
diff options
context:
space:
mode:
authorIlya Etingof <etingof@gmail.com>2019-02-12 09:16:17 +0100
committerGitHub <noreply@github.com>2019-02-12 09:16:17 +0100
commitb9a7b9c955df98b1e5eec250f418c3df3b7d0199 (patch)
tree3364eb15031352859586e8eb6aa49759a23f9c72 /examples/v1arch/asyncore/manager/ntfrcv/listen-on-ipv4-and-ipv6-interfaces.py
parentc5f7842c430ad3431bee793362ef11cff9f1e0de (diff)
downloadpysnmp-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.py19
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