summaryrefslogtreecommitdiff
path: root/examples
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
parentc5f7842c430ad3431bee793362ef11cff9f1e0de (diff)
downloadpysnmp-git-b9a7b9c955df98b1e5eec250f418c3df3b7d0199.tar.gz
Reformat example scripts for easier reading (#241)
Diffstat (limited to 'examples')
-rw-r--r--examples/hlapi/v1arch/asyncore/manager/cmdgen/multiple-concurrent-queries-over-ipv4-and-ipv6.py10
-rw-r--r--examples/hlapi/v1arch/asyncore/manager/cmdgen/pull-mibs-from-multiple-agents-at-once-over-ipv4-and-ipv6.py10
-rw-r--r--examples/hlapi/v1arch/asyncore/manager/cmdgen/pull-whole-mib.py1
-rw-r--r--examples/hlapi/v1arch/asyncore/manager/cmdgen/v1-getnext.py1
-rw-r--r--examples/hlapi/v1arch/asyncore/sync/agent/ntforg/generic-v1-trap.py38
-rw-r--r--examples/hlapi/v1arch/asyncore/sync/agent/ntforg/generic-v2c-trap.py26
-rw-r--r--examples/hlapi/v1arch/asyncore/sync/agent/ntforg/v2c-inform.py26
-rw-r--r--examples/hlapi/v1arch/asyncore/sync/agent/ntforg/v2c-trap-with-notification-objects.py28
-rw-r--r--examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/coerce-set-value-to-mib-spec.py15
-rw-r--r--examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/custom-asn1-mib-search-path.py19
-rw-r--r--examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/custom-pysnmp-mibs-search-path.py29
-rw-r--r--examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/custom-timeout-and-retries.py16
-rw-r--r--examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/enable-mib-lookup.py17
-rw-r--r--examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/fetch-variables-over-ipv6.py16
-rw-r--r--examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/get-table-object-by-index.py16
-rw-r--r--examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/get-table-object-by-multiple-indices.py25
-rw-r--r--examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/getbulk-fetch-scalar-and-table-variables-over-ipv6.py23
-rw-r--r--examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/getbulk-limit-number-of-packets.py21
-rw-r--r--examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/multiple-get-calls.py11
-rw-r--r--examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/preload-pysnmp-mibs.py17
-rw-r--r--examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/pull-whole-mib.py15
-rw-r--r--examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/pull-whole-snmp-table.py29
-rw-r--r--examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/query-agents-from-multuple-threads-over-ipv4-and-ipv6.py13
-rw-r--r--examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/set-multiple-scalar-values.py31
-rw-r--r--examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/v1-get.py14
-rw-r--r--examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/v2c-get.py14
-rw-r--r--examples/hlapi/v3arch/asyncio/agent/ntforg/default-v1-trap.py6
-rw-r--r--examples/hlapi/v3arch/asyncio/agent/ntforg/multiple-notifications-at-once.py16
-rw-r--r--examples/hlapi/v3arch/asyncio/manager/cmdgen/getbulk-to-eom.py13
-rw-r--r--examples/hlapi/v3arch/asyncio/manager/cmdgen/multiple-concurrent-queries-over-ipv4-and-ipv6.py14
-rw-r--r--examples/hlapi/v3arch/asyncio/manager/cmdgen/multiple-sequential-queries.py19
-rw-r--r--examples/hlapi/v3arch/asyncio/manager/cmdgen/v1-get.py6
-rw-r--r--examples/hlapi/v3arch/asyncore/agent/ntforg/multiple-informs-at-once.py5
-rw-r--r--examples/hlapi/v3arch/asyncore/agent/ntforg/multiple-traps-at-once.py5
-rw-r--r--examples/hlapi/v3arch/asyncore/agent/ntforg/running-multiple-snmp-engines-at-once.py27
-rw-r--r--examples/hlapi/v3arch/asyncore/manager/cmdgen/multiple-concurrent-queries-over-ipv4-and-ipv6.py15
-rw-r--r--examples/hlapi/v3arch/asyncore/manager/cmdgen/pull-mibs-from-multiple-agents-at-once-over-ipv4-and-ipv6.py11
-rw-r--r--examples/hlapi/v3arch/asyncore/manager/cmdgen/pull-whole-mib.py3
-rw-r--r--examples/hlapi/v3arch/asyncore/manager/cmdgen/query-multiple-snmp-engines-over-ipv4-and-ipv6.py20
-rw-r--r--examples/hlapi/v3arch/asyncore/manager/cmdgen/v2c-get.py3
-rw-r--r--examples/hlapi/v3arch/asyncore/sync/agent/ntforg/custom-contextengineid.py23
-rw-r--r--examples/hlapi/v3arch/asyncore/sync/agent/ntforg/custom-contextname.py18
-rw-r--r--examples/hlapi/v3arch/asyncore/sync/agent/ntforg/custom-v1-trap.py35
-rw-r--r--examples/hlapi/v3arch/asyncore/sync/agent/ntforg/default-v1-trap.py30
-rw-r--r--examples/hlapi/v3arch/asyncore/sync/agent/ntforg/send-notification-with-additional-varbinds.py26
-rw-r--r--examples/hlapi/v3arch/asyncore/sync/agent/ntforg/v2c-trap-with-notification-objects.py30
-rw-r--r--examples/hlapi/v3arch/asyncore/sync/agent/ntforg/v3-inform.py30
-rw-r--r--examples/hlapi/v3arch/asyncore/sync/agent/ntforg/v3-trap.py22
-rw-r--r--examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/coerce-set-value-to-mib-spec.py20
-rw-r--r--examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-asn1-mib-search-path.py24
-rw-r--r--examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-contextengineid-and-contextname.py20
-rw-r--r--examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-contextengineid.py18
-rw-r--r--examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-pysnmp-mibs-search-path.py33
-rw-r--r--examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-timeout-and-retries.py18
-rw-r--r--examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-v3-security-name.py16
-rw-r--r--examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/fetch-variables-over-ipv6.py20
-rw-r--r--examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/get-table-object-by-index.py18
-rw-r--r--examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/get-table-object-by-multiple-indices.py32
-rw-r--r--examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getbulk-fetch-scalar-and-table-variables-over-ipv6.py25
-rw-r--r--examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getbulk-limit-number-of-packets.py23
-rw-r--r--examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getbulk-limit-number-of-variables.py25
-rw-r--r--examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getnext-limit-number-of-variables.py27
-rw-r--r--examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getnext-multiple-oids-to-eom.py23
-rw-r--r--examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/multiple-get-calls.py13
-rw-r--r--examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/preload-pysnmp-mibs.py19
-rw-r--r--examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/pull-whole-mib.py19
-rw-r--r--examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/pull-whole-snmp-table.py31
-rw-r--r--examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/query-agents-from-multuple-threads-over-ipv4-and-ipv6.py21
-rw-r--r--examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/set-multiple-scalar-values.py32
-rw-r--r--examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/specific-v3-engine-id.py16
-rw-r--r--examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-md5-des.py16
-rw-r--r--examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-md5-none.py16
-rw-r--r--examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-none-none.py16
-rw-r--r--examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-sha-aes128.py20
-rw-r--r--examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/v1-get.py16
-rw-r--r--examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/v2c-get.py18
-rw-r--r--examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/v2c-getbulk.py25
-rw-r--r--examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/waive-mib-lookup.py21
-rw-r--r--examples/hlapi/v3arch/trollius/agent/ntforg/default-v1-trap.py37
-rw-r--r--examples/hlapi/v3arch/trollius/manager/cmdgen/getbulk-to-eom.py26
-rw-r--r--examples/hlapi/v3arch/trollius/manager/cmdgen/v1-get.py22
-rw-r--r--examples/hlapi/v3arch/twisted/agent/ntforg/default-v1-trap.py12
-rw-r--r--examples/hlapi/v3arch/twisted/agent/ntforg/multiple-notifications-at-once.py12
-rw-r--r--examples/hlapi/v3arch/twisted/agent/ntforg/v2c-trap-inline-callbacks.py6
-rw-r--r--examples/hlapi/v3arch/twisted/manager/cmdgen/custom-timeout-and-retries.py20
-rw-r--r--examples/hlapi/v3arch/twisted/manager/cmdgen/getbulk-to-eom.py23
-rw-r--r--examples/hlapi/v3arch/twisted/manager/cmdgen/multiple-concurrent-queries.py19
-rw-r--r--examples/hlapi/v3arch/twisted/manager/cmdgen/pull-mibs-from-multiple-agents-at-once.py24
-rw-r--r--examples/hlapi/v3arch/twisted/manager/cmdgen/pull-whole-mib.py19
-rw-r--r--examples/hlapi/v3arch/twisted/manager/cmdgen/v1-get.py19
-rw-r--r--examples/smi/agent/custom-managed-object.py5
-rw-r--r--examples/smi/agent/operations-on-managed-objects.py6
-rw-r--r--examples/smi/manager/configure-mib-viewer-and-resolve-pdu-varbinds.py3
-rw-r--r--examples/smi/manager/mib-tree-inspection.py12
-rw-r--r--examples/v1arch/asyncore/agent/cmdrsp/implementing-scalar-mib-objects-over-ipv4-and-ipv6.py22
-rw-r--r--examples/v1arch/asyncore/agent/ntforg/send-inform-over-ipv4-and-ipv6.py7
-rw-r--r--examples/v1arch/asyncore/agent/ntforg/send-trap-over-ipv4-and-ipv6.py2
-rw-r--r--examples/v1arch/asyncore/manager/cmdgen/broadcast-agent-discovery.py11
-rw-r--r--examples/v1arch/asyncore/manager/cmdgen/fetch-scalar-value.py5
-rw-r--r--examples/v1arch/asyncore/manager/cmdgen/getbulk-pull-whole-mib.py14
-rw-r--r--examples/v1arch/asyncore/manager/cmdgen/getnext-pull-whole-mib.py20
-rw-r--r--examples/v1arch/asyncore/manager/cmdgen/spoof-source-address.py11
-rw-r--r--examples/v1arch/asyncore/manager/cmdgen/v2c-set.py6
-rw-r--r--examples/v1arch/asyncore/manager/ntfrcv/listen-on-ipv4-and-ipv6-interfaces.py19
-rw-r--r--examples/v3arch/asyncio/agent/cmdrsp/multiple-usm-users.py11
-rw-r--r--examples/v3arch/asyncio/manager/ntfrcv/multiple-interfaces.py16
-rw-r--r--examples/v3arch/asyncore/agent/cmdrsp/alternative-mib-tree.py7
-rw-r--r--examples/v3arch/asyncore/agent/cmdrsp/custom-mib-controller.py5
-rw-r--r--examples/v3arch/asyncore/agent/cmdrsp/custom-snmp-engine-id.py4
-rw-r--r--examples/v3arch/asyncore/agent/cmdrsp/implementing-scalar-mib-objects.py4
-rw-r--r--examples/v3arch/asyncore/agent/cmdrsp/implementing-snmp-table.py29
-rw-r--r--examples/v3arch/asyncore/agent/cmdrsp/listen-on-ipv4-and-ipv6-interfaces.py5
-rw-r--r--examples/v3arch/asyncore/agent/cmdrsp/listen-on-multiple-interfaces.py5
-rw-r--r--examples/v3arch/asyncore/agent/cmdrsp/listening-on-virtual-network-interface.py4
-rw-r--r--examples/v3arch/asyncore/agent/cmdrsp/multiple-snmp-communities.py4
-rw-r--r--examples/v3arch/asyncore/agent/cmdrsp/multiple-snmp-engines.py4
-rw-r--r--examples/v3arch/asyncore/agent/cmdrsp/multiple-usm-users.py6
-rw-r--r--examples/v3arch/asyncore/agent/cmdrsp/observe-request-processing.py11
-rw-r--r--examples/v3arch/asyncore/agent/ntforg/multiple-different-notifications-at-once.py3
-rw-r--r--examples/v3arch/asyncore/agent/ntforg/send-inform-to-multiple-managers.py3
-rw-r--r--examples/v3arch/asyncore/agent/ntforg/send-notification-over-ipv4-and-ipv6.py2
-rw-r--r--examples/v3arch/asyncore/agent/ntforg/send-packet-from-specific-address.py1
-rw-r--r--examples/v3arch/asyncore/agent/ntforg/send-trap-to-multiple-managers.py3
-rw-r--r--examples/v3arch/asyncore/agent/ntforg/usm-md5-none.py6
-rw-r--r--examples/v3arch/asyncore/agent/ntforg/v1-trap.py1
-rw-r--r--examples/v3arch/asyncore/agent/ntforg/v2c-inform.py5
-rw-r--r--examples/v3arch/asyncore/agent/ntforg/v2c-trap-with-notification-objects.py2
-rw-r--r--examples/v3arch/asyncore/agent/ntforg/v2c-trap.py5
-rw-r--r--examples/v3arch/asyncore/agent/ntforg/v3-trap.py2
-rw-r--r--examples/v3arch/asyncore/manager/cmdgen/custom-contextengineid-and-contextname.py4
-rw-r--r--examples/v3arch/asyncore/manager/cmdgen/custom-timeout-and-retries.py3
-rw-r--r--examples/v3arch/asyncore/manager/cmdgen/fetch-variables-over-ipv6.py5
-rw-r--r--examples/v3arch/asyncore/manager/cmdgen/getbulk-fetch-scalar-and-table-variables.py4
-rw-r--r--examples/v3arch/asyncore/manager/cmdgen/getbulk-multiple-oids-to-eom.py4
-rw-r--r--examples/v3arch/asyncore/manager/cmdgen/getnext-multiple-oids-and-resolve-with-mib.py6
-rw-r--r--examples/v3arch/asyncore/manager/cmdgen/getnext-multiple-oids-to-eom.py6
-rw-r--r--examples/v3arch/asyncore/manager/cmdgen/observe-request-processing.py4
-rw-r--r--examples/v3arch/asyncore/manager/cmdgen/pull-subtree.py8
-rw-r--r--examples/v3arch/asyncore/manager/cmdgen/send-packets-from-specific-interface.py8
-rw-r--r--examples/v3arch/asyncore/manager/cmdgen/set-multiple-scalar-values.py3
-rw-r--r--examples/v3arch/asyncore/manager/cmdgen/spoof-source-address.py2
-rw-r--r--examples/v3arch/asyncore/manager/cmdgen/usm-sha-aes128.py4
-rw-r--r--examples/v3arch/asyncore/manager/cmdgen/usm-sha-none.py3
-rw-r--r--examples/v3arch/asyncore/manager/cmdgen/v1-get.py3
-rw-r--r--examples/v3arch/asyncore/manager/cmdgen/v2c-set.py3
-rw-r--r--examples/v3arch/asyncore/manager/ntfrcv/determine-peer-network-address.py11
-rw-r--r--examples/v3arch/asyncore/manager/ntfrcv/multiple-network-interfaces.py4
-rw-r--r--examples/v3arch/asyncore/manager/ntfrcv/multiple-network-transports-incl-ipv4-and-ipv6.py4
-rw-r--r--examples/v3arch/asyncore/manager/ntfrcv/multiple-usm-users.py4
-rw-r--r--examples/v3arch/asyncore/manager/ntfrcv/observe-request-processing-over-ipv4-and-ipv6.py4
-rw-r--r--examples/v3arch/asyncore/manager/ntfrcv/regexp-community-name.py10
-rw-r--r--examples/v3arch/asyncore/proxy/command/ipv6-to-ipv4-conversion.py12
-rw-r--r--examples/v3arch/asyncore/proxy/command/v2c-to-v1-conversion.py11
-rw-r--r--examples/v3arch/asyncore/proxy/command/v2c-to-v3-conversion.py13
-rw-r--r--examples/v3arch/asyncore/proxy/command/v3-to-v2c-conversion.py12
-rw-r--r--examples/v3arch/twisted/manager/ntfrcv/multiple-interfaces.py5
-rw-r--r--examples/v3arch/twisted/manager/ntfrcv/multiple-usm-users.py5
157 files changed, 1371 insertions, 823 deletions
diff --git a/examples/hlapi/v1arch/asyncore/manager/cmdgen/multiple-concurrent-queries-over-ipv4-and-ipv6.py b/examples/hlapi/v1arch/asyncore/manager/cmdgen/multiple-concurrent-queries-over-ipv4-and-ipv6.py
index beeb1785..b40c5c09 100644
--- a/examples/hlapi/v1arch/asyncore/manager/cmdgen/multiple-concurrent-queries-over-ipv4-and-ipv6.py
+++ b/examples/hlapi/v1arch/asyncore/manager/cmdgen/multiple-concurrent-queries-over-ipv4-and-ipv6.py
@@ -19,23 +19,26 @@ from pysnmp.hlapi.v1arch.asyncore import *
# List of targets in the following format:
# ((authData, transportTarget, varNames), ...)
-targets = (
+TARGETS = (
# 1-st target (SNMPv1 over IPv4/UDP)
(CommunityData('public', mpModel=0),
UdpTransportTarget(('demo.snmplabs.com', 161)),
(ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)),
ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0)))),
+
# 2-nd target (SNMPv2c over IPv4/UDP)
(CommunityData('public'),
UdpTransportTarget(('demo.snmplabs.com', 161)),
(ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)),
ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0)))),
- # 3-nd target (SNMPv2c over IPv4/UDP) - same community and
+
+ # 3-nd target (SNMPv2c over IPv4/UDP) - same community and
# different transport address.
(CommunityData('public'),
Udp6TransportTarget(('::1', 161)),
(ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysContact', 0)),
ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysName', 0)))),
+
# N-th target
# ...
)
@@ -53,10 +56,11 @@ def cbFun(errorIndication, errorStatus, errorIndex, varBinds, **context):
for varBind in varBinds:
print(' = '.join([x.prettyPrint() for x in varBind]))
+
snmpDispatcher = SnmpDispatcher()
# Submit a bunch of initial GET requests
-for authData, transportTarget, varBinds in targets:
+for authData, transportTarget, varBinds in TARGETS:
getCmd(snmpDispatcher, authData, transportTarget, *varBinds,
cbFun=cbFun, lookupMib=True)
diff --git a/examples/hlapi/v1arch/asyncore/manager/cmdgen/pull-mibs-from-multiple-agents-at-once-over-ipv4-and-ipv6.py b/examples/hlapi/v1arch/asyncore/manager/cmdgen/pull-mibs-from-multiple-agents-at-once-over-ipv4-and-ipv6.py
index b3af60a4..32c92ff8 100644
--- a/examples/hlapi/v1arch/asyncore/manager/cmdgen/pull-mibs-from-multiple-agents-at-once-over-ipv4-and-ipv6.py
+++ b/examples/hlapi/v1arch/asyncore/manager/cmdgen/pull-mibs-from-multiple-agents-at-once-over-ipv4-and-ipv6.py
@@ -19,20 +19,23 @@ from pysnmp.hlapi.v1arch.asyncore import *
# List of targets in the following format:
# ((authData, transportTarget, varNames), ...)
-targets = (
+TARGETS = (
# 1-st target (SNMPv1 over IPv4/UDP)
(CommunityData('public', mpModel=0),
UdpTransportTarget(('demo.snmplabs.com', 161)),
(ObjectType(ObjectIdentity('1.3.6.1.2.1')),
ObjectType(ObjectIdentity('1.3.6.1.3.1')))),
+
# 2-nd target (SNMPv2c over IPv4/UDP)
(CommunityData('public'),
UdpTransportTarget(('demo.snmplabs.com', 161)),
(ObjectType(ObjectIdentity('1.3.6.1.4.1')),)),
+
# 3-th target (SNMPv3 over IPv6/UDP)
(CommunityData('public'),
Udp6TransportTarget(('::1', 161)),
(ObjectType(ObjectIdentity('IF-MIB', 'ifTable')),))
+
# N-th target
# ...
)
@@ -53,11 +56,12 @@ def cbFun(errorIndication, errorStatus, errorIndex, varBindTable, **context):
return context.get('nextVarBinds')
+
snmpDispatcher = SnmpDispatcher()
# Submit a bunch of initial GETNEXT requests
-for authData, transportTarget, varBinds in targets:
+for authData, transportTarget, varBinds in TARGETS:
nextCmd(snmpDispatcher, authData, transportTarget, *varBinds,
- cbFun=cbFun, lookupMib=True)
+ cbFun=cbFun, lookupMib=True)
snmpDispatcher.transportDispatcher.runDispatcher()
diff --git a/examples/hlapi/v1arch/asyncore/manager/cmdgen/pull-whole-mib.py b/examples/hlapi/v1arch/asyncore/manager/cmdgen/pull-whole-mib.py
index 09113fd1..4af0138f 100644
--- a/examples/hlapi/v1arch/asyncore/manager/cmdgen/pull-whole-mib.py
+++ b/examples/hlapi/v1arch/asyncore/manager/cmdgen/pull-whole-mib.py
@@ -31,6 +31,7 @@ def cbFun(errorIndication, errorStatus, errorIndex, varBindTable, **context):
return context.get('nextVarBinds')
+
snmpDispatcher = SnmpDispatcher()
# Submit initial GETBULK request
diff --git a/examples/hlapi/v1arch/asyncore/manager/cmdgen/v1-getnext.py b/examples/hlapi/v1arch/asyncore/manager/cmdgen/v1-getnext.py
index 385e869c..d59f1ba0 100644
--- a/examples/hlapi/v1arch/asyncore/manager/cmdgen/v1-getnext.py
+++ b/examples/hlapi/v1arch/asyncore/manager/cmdgen/v1-getnext.py
@@ -35,6 +35,7 @@ def cbFun(errorIndication, errorStatus, errorIndex, varBindTable, **context):
return context.get('nextVarBinds')
+
snmpDispatcher = SnmpDispatcher()
stateHandle = nextCmd(
diff --git a/examples/hlapi/v1arch/asyncore/sync/agent/ntforg/generic-v1-trap.py b/examples/hlapi/v1arch/asyncore/sync/agent/ntforg/generic-v1-trap.py
index 2f1fa0fd..2d83da5f 100644
--- a/examples/hlapi/v1arch/asyncore/sync/agent/ntforg/generic-v1-trap.py
+++ b/examples/hlapi/v1arch/asyncore/sync/agent/ntforg/generic-v1-trap.py
@@ -21,26 +21,26 @@ Functionally similar to:
"""#
from pysnmp.hlapi.v1arch import *
-errorIndication, errorStatus, errorIndex, varBinds = next(
- sendNotification(
- SnmpDispatcher(),
- CommunityData('public', mpModel=0),
- UdpTransportTarget(('demo.snmplabs.com', 162)),
- 'trap',
- # SNMPv2-MIB::sysUpTime.0 = 12345
- ('1.3.6.1.2.1.1.3.0', TimeTicks(12345)),
- # SNMPv2-SMI::snmpTrapOID.0 = SNMPv2-MIB::warmStart
- ('1.3.6.1.6.3.1.1.4.1.0', ObjectIdentifier('1.3.6.1.6.3.1.1.5.2')),
- # SNMP-COMMUNITY-MIB::snmpTrapAddress.0 = 127.0.0.1
- ('1.3.6.1.6.3.18.1.3.0', IpAddress('127.0.0.1')),
- # SNMP-COMMUNITY-MIB::snmpTrapCommunity.0 = public
- ('1.3.6.1.6.3.18.1.4.0', OctetString('public')),
- # SNMP-COMMUNITY-MIB::snmpTrapEnterprise.0 = 1.3.6.1.4.1.20408.4.1.1.2
- ('1.3.6.1.6.3.1.1.4.3.0', ObjectIdentifier('1.3.6.1.4.1.20408.4.1.1.2')),
- # SNMPv2-MIB::sysName.0
- ('1.3.6.1.2.1.1.1.0', OctetString('my system'))
- )
+iterator = sendNotification(
+ SnmpDispatcher(),
+ CommunityData('public', mpModel=0),
+ UdpTransportTarget(('demo.snmplabs.com', 162)),
+ 'trap',
+ # SNMPv2-MIB::sysUpTime.0 = 12345
+ ('1.3.6.1.2.1.1.3.0', TimeTicks(12345)),
+ # SNMPv2-SMI::snmpTrapOID.0 = SNMPv2-MIB::warmStart
+ ('1.3.6.1.6.3.1.1.4.1.0', ObjectIdentifier('1.3.6.1.6.3.1.1.5.2')),
+ # SNMP-COMMUNITY-MIB::snmpTrapAddress.0 = 127.0.0.1
+ ('1.3.6.1.6.3.18.1.3.0', IpAddress('127.0.0.1')),
+ # SNMP-COMMUNITY-MIB::snmpTrapCommunity.0 = public
+ ('1.3.6.1.6.3.18.1.4.0', OctetString('public')),
+ # SNMP-COMMUNITY-MIB::snmpTrapEnterprise.0 = 1.3.6.1.4.1.20408.4.1.1.2
+ ('1.3.6.1.6.3.1.1.4.3.0', ObjectIdentifier('1.3.6.1.4.1.20408.4.1.1.2')),
+ # SNMPv2-MIB::sysName.0
+ ('1.3.6.1.2.1.1.1.0', OctetString('my system'))
)
+errorIndication, errorStatus, errorIndex, varBinds = next(iterator)
+
if errorIndication:
print(errorIndication)
diff --git a/examples/hlapi/v1arch/asyncore/sync/agent/ntforg/generic-v2c-trap.py b/examples/hlapi/v1arch/asyncore/sync/agent/ntforg/generic-v2c-trap.py
index 10a04ed4..639b7b6b 100644
--- a/examples/hlapi/v1arch/asyncore/sync/agent/ntforg/generic-v2c-trap.py
+++ b/examples/hlapi/v1arch/asyncore/sync/agent/ntforg/generic-v2c-trap.py
@@ -19,20 +19,20 @@ Functionally similar to:
"""#
from pysnmp.hlapi.v1arch import *
-errorIndication, errorStatus, errorIndex, varBinds = next(
- sendNotification(
- SnmpDispatcher(),
- CommunityData('public'),
- UdpTransportTarget(('demo.snmplabs.com', 162)),
- 'trap',
- # SNMPv2-MIB::sysUpTime.0 = 12345
- ('1.3.6.1.2.1.1.3.0', TimeTicks(12345)),
- # SNMPv2-SMI::snmpTrapOID.0 = SNMPv2-MIB::warmStart
- ('1.3.6.1.6.3.1.1.4.1.0', ObjectIdentifier('1.3.6.1.6.3.1.1.5.2')),
- # SNMPv2-MIB::sysName.0
- ('1.3.6.1.2.1.1.1.0', OctetString('my system'))
- )
+iterator = sendNotification(
+ SnmpDispatcher(),
+ CommunityData('public'),
+ UdpTransportTarget(('demo.snmplabs.com', 162)),
+ 'trap',
+ # SNMPv2-MIB::sysUpTime.0 = 12345
+ ('1.3.6.1.2.1.1.3.0', TimeTicks(12345)),
+ # SNMPv2-SMI::snmpTrapOID.0 = SNMPv2-MIB::warmStart
+ ('1.3.6.1.6.3.1.1.4.1.0', ObjectIdentifier('1.3.6.1.6.3.1.1.5.2')),
+ # SNMPv2-MIB::sysName.0
+ ('1.3.6.1.2.1.1.1.0', OctetString('my system'))
)
+errorIndication, errorStatus, errorIndex, varBinds = next(iterator)
+
if errorIndication:
print(errorIndication)
diff --git a/examples/hlapi/v1arch/asyncore/sync/agent/ntforg/v2c-inform.py b/examples/hlapi/v1arch/asyncore/sync/agent/ntforg/v2c-inform.py
index c1799993..9210d45a 100644
--- a/examples/hlapi/v1arch/asyncore/sync/agent/ntforg/v2c-inform.py
+++ b/examples/hlapi/v1arch/asyncore/sync/agent/ntforg/v2c-inform.py
@@ -18,21 +18,21 @@ Functionally similar to:
"""#
from pysnmp.hlapi.v1arch import *
-errorIndication, errorStatus, errorIndex, varBinds = next(
- sendNotification(
- SnmpDispatcher(),
- CommunityData('public'),
- UdpTransportTarget(('demo.snmplabs.com', 162)),
- 'inform',
- # SNMPv2-MIB::sysUpTime.0 = 12345
- ('1.3.6.1.2.1.1.3.0', TimeTicks(12345)),
- # SNMPv2-SMI::snmpTrapOID.0 = SNMPv2-MIB::warmStart
- ('1.3.6.1.6.3.1.1.4.1.0', ObjectIdentifier('1.3.6.1.6.3.1.1.5.2')),
- # SNMPv2-MIB::sysName.0
- ('1.3.6.1.2.1.1.1.0', OctetString('my system'))
- )
+iterator = sendNotification(
+ SnmpDispatcher(),
+ CommunityData('public'),
+ UdpTransportTarget(('demo.snmplabs.com', 162)),
+ 'inform',
+ # SNMPv2-MIB::sysUpTime.0 = 12345
+ ('1.3.6.1.2.1.1.3.0', TimeTicks(12345)),
+ # SNMPv2-SMI::snmpTrapOID.0 = SNMPv2-MIB::warmStart
+ ('1.3.6.1.6.3.1.1.4.1.0', ObjectIdentifier('1.3.6.1.6.3.1.1.5.2')),
+ # SNMPv2-MIB::sysName.0
+ ('1.3.6.1.2.1.1.1.0', OctetString('my system'))
)
+errorIndication, errorStatus, errorIndex, varBinds = next(iterator)
+
if errorIndication:
print(errorIndication)
diff --git a/examples/hlapi/v1arch/asyncore/sync/agent/ntforg/v2c-trap-with-notification-objects.py b/examples/hlapi/v1arch/asyncore/sync/agent/ntforg/v2c-trap-with-notification-objects.py
index 052946bc..0bf6c354 100644
--- a/examples/hlapi/v1arch/asyncore/sync/agent/ntforg/v2c-trap-with-notification-objects.py
+++ b/examples/hlapi/v1arch/asyncore/sync/agent/ntforg/v2c-trap-with-notification-objects.py
@@ -19,21 +19,21 @@ Functionally similar to:
"""#
from pysnmp.hlapi.v1arch import *
-errorIndication, errorStatus, errorIndex, varBinds = next(
- sendNotification(
- SnmpDispatcher(),
- CommunityData('public'),
- UdpTransportTarget(('demo.snmplabs.com', 162)),
- 'trap',
- # SNMPv2-MIB::sysUpTime.0 = 12345
- ('1.3.6.1.2.1.1.3.0', TimeTicks(12345)),
- # SNMPv2-SMI::snmpTrapOID.0 = SNMPv2-MIB::warmStart
- NotificationType(ObjectIdentity('SNMPv2-MIB', 'warmStart')),
- # SNMPv2-MIB::sysName.0
- ('1.3.6.1.2.1.1.1.0', OctetString('my system')),
- lookupMib=True
- )
+iterator = sendNotification(
+ SnmpDispatcher(),
+ CommunityData('public'),
+ UdpTransportTarget(('demo.snmplabs.com', 162)),
+ 'trap',
+ # SNMPv2-MIB::sysUpTime.0 = 12345
+ ('1.3.6.1.2.1.1.3.0', TimeTicks(12345)),
+ # SNMPv2-SMI::snmpTrapOID.0 = SNMPv2-MIB::warmStart
+ NotificationType(ObjectIdentity('SNMPv2-MIB', 'warmStart')),
+ # SNMPv2-MIB::sysName.0
+ ('1.3.6.1.2.1.1.1.0', OctetString('my system')),
+ lookupMib=True
)
+errorIndication, errorStatus, errorIndex, varBinds = next(iterator)
+
if errorIndication:
print(errorIndication)
diff --git a/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/coerce-set-value-to-mib-spec.py b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/coerce-set-value-to-mib-spec.py
index a6789f7f..a22e6e93 100644
--- a/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/coerce-set-value-to-mib-spec.py
+++ b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/coerce-set-value-to-mib-spec.py
@@ -17,15 +17,16 @@ Functionally similar to:
"""#
from pysnmp.hlapi.v1arch import *
-errorIndication, errorStatus, errorIndex, varBinds = next(
- setCmd(SnmpDispatcher(),
- CommunityData('public'),
- UdpTransportTarget(('demo.snmplabs.com', 161)),
- ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysORDescr', 1),
- 'new description'),
- lookupMib=True)
+iterator = setCmd(
+ SnmpDispatcher(),
+ CommunityData('public'),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysORDescr', 1), 'new description'),
+ lookupMib=True
)
+errorIndication, errorStatus, errorIndex, varBinds = next(iterator)
+
if errorIndication:
print(errorIndication)
diff --git a/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/custom-asn1-mib-search-path.py b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/custom-asn1-mib-search-path.py
index 759171c1..20767556 100644
--- a/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/custom-asn1-mib-search-path.py
+++ b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/custom-asn1-mib-search-path.py
@@ -18,16 +18,19 @@ Functionally similar to:
"""#
from pysnmp.hlapi.v1arch import *
-errorIndication, errorStatus, errorIndex, varBinds = next(
- getCmd(SnmpDispatcher(),
- CommunityData('public'),
- UdpTransportTarget(('demo.snmplabs.com', 161)),
- ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets', 1).addAsn1MibSource(
- 'file:///usr/share/snmp',
- 'http://mibs.snmplabs.com/asn1/@mib@')),
- lookupMib=True)
+iterator = getCmd(
+ SnmpDispatcher(),
+ CommunityData('public'),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets', 1).addAsn1MibSource(
+ 'file:///usr/share/snmp',
+ 'http://mibs.snmplabs.com/asn1/@mib@')
+ ),
+ lookupMib=True
)
+errorIndication, errorStatus, errorIndex, varBinds = next(iterator)
+
if errorIndication:
print(errorIndication)
diff --git a/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/custom-pysnmp-mibs-search-path.py b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/custom-pysnmp-mibs-search-path.py
index a3686d69..7f1f8d2c 100644
--- a/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/custom-pysnmp-mibs-search-path.py
+++ b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/custom-pysnmp-mibs-search-path.py
@@ -20,20 +20,21 @@ Functionally similar to:
"""#
from pysnmp.hlapi.v1arch import *
-for (errorIndication,
- errorStatus,
- errorIndex,
- varBinds) in bulkCmd(SnmpDispatcher(),
- CommunityData('public'),
- UdpTransportTarget(('demo.snmplabs.com', 161)),
- 0, 50,
- ObjectType(
- ObjectIdentity('TCP-MIB', 'tcpConnTable').addMibSource(
- '/opt/mibs/pysnmp').addMibSource(
- 'python_packaged_mibs')
- ),
- lookupMib=True,
- lexicographicMode=False):
+iterator = bulkCmd(
+ SnmpDispatcher(),
+ CommunityData('public'),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ 0, 50,
+ ObjectType(
+ ObjectIdentity('TCP-MIB', 'tcpConnTable').addMibSource(
+ '/opt/mibs/pysnmp').addMibSource(
+ 'python_packaged_mibs')
+ ),
+ lookupMib=True,
+ lexicographicMode=False
+)
+
+for errorIndication, errorStatus, errorIndex, varBinds in iterator:
if errorIndication:
print(errorIndication)
diff --git a/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/custom-timeout-and-retries.py b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/custom-timeout-and-retries.py
index 7a4253cf..f56d6511 100644
--- a/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/custom-timeout-and-retries.py
+++ b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/custom-timeout-and-retries.py
@@ -30,15 +30,17 @@ Functionally similar to:
"""#
from pysnmp.hlapi.v1arch import *
-errorIndication, errorStatus, errorIndex, varBinds = next(
- getCmd(SnmpDispatcher(),
- CommunityData('public'),
- UdpTransportTarget(
- ('demo.snmplabs.com', 161), timeout=2.0, retries=0
- ),
- (('1.3.6.1.2.1.1.1.0', None)))
+iterator = getCmd(
+ SnmpDispatcher(),
+ CommunityData('public'),
+ UdpTransportTarget(
+ ('demo.snmplabs.com', 161), timeout=2.0, retries=0
+ ),
+ ('1.3.6.1.2.1.1.1.0', None)
)
+errorIndication, errorStatus, errorIndex, varBinds = next(iterator)
+
if errorIndication:
print(errorIndication)
diff --git a/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/enable-mib-lookup.py b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/enable-mib-lookup.py
index 2f4f8edb..1072c71c 100644
--- a/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/enable-mib-lookup.py
+++ b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/enable-mib-lookup.py
@@ -20,14 +20,15 @@ Functionally similar to:
"""#
from pysnmp.hlapi.v1arch import *
-for (errorIndication,
- errorStatus,
- errorIndex,
- varBinds) in nextCmd(SnmpDispatcher(),
- CommunityData('public'),
- UdpTransportTarget(('demo.snmplabs.com', 161)),
- ObjectType(ObjectIdentity('1.3.6.1.2.1.1')),
- lookupMib=True):
+iterator = nextCmd(
+ SnmpDispatcher(),
+ CommunityData('public'),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ ObjectType(ObjectIdentity('1.3.6.1.2.1.1')),
+ lookupMib=True
+)
+
+for errorIndication, errorStatus, errorIndex, varBinds in iterator:
if errorIndication:
print(errorIndication)
diff --git a/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/fetch-variables-over-ipv6.py b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/fetch-variables-over-ipv6.py
index bd8d9ca2..dc9db8a5 100644
--- a/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/fetch-variables-over-ipv6.py
+++ b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/fetch-variables-over-ipv6.py
@@ -15,15 +15,17 @@ Functionally similar to:
"""#
from pysnmp.hlapi.v1arch import *
-errorIndication, errorStatus, errorIndex, varBinds = next(
- getCmd(SnmpDispatcher(),
- CommunityData('public'),
- Udp6TransportTarget(('::1', 161)),
- ('1.3.6.1.2.1.1.1.0', None),
- ('1.3.6.1.2.1.1.2.0', None),
- ('1.3.6.1.2.1.1.3.0', None))
+iterator = getCmd(
+ SnmpDispatcher(),
+ CommunityData('public'),
+ Udp6TransportTarget(('::1', 161)),
+ ('1.3.6.1.2.1.1.1.0', None),
+ ('1.3.6.1.2.1.1.2.0', None),
+ ('1.3.6.1.2.1.1.3.0', None)
)
+errorIndication, errorStatus, errorIndex, varBinds = next(iterator)
+
if errorIndication:
print(errorIndication)
diff --git a/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/get-table-object-by-index.py b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/get-table-object-by-index.py
index b7fccdcb..38d248c2 100644
--- a/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/get-table-object-by-index.py
+++ b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/get-table-object-by-index.py
@@ -17,15 +17,17 @@ Functionally similar to:
"""#
from pysnmp.hlapi.v1arch import *
-errorIndication, errorStatus, errorIndex, varBinds = next(
- getCmd(SnmpDispatcher(),
- CommunityData('public'),
- UdpTransportTarget(('demo.snmplabs.com', 161)),
- ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets', 1)),
- ObjectType(ObjectIdentity('IF-MIB', 'ifOutOctets', 1)),
- lookupMib=True)
+iterator = getCmd(
+ SnmpDispatcher(),
+ CommunityData('public'),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets', 1)),
+ ObjectType(ObjectIdentity('IF-MIB', 'ifOutOctets', 1)),
+ lookupMib=True
)
+errorIndication, errorStatus, errorIndex, varBinds = next(iterator)
+
if errorIndication:
print(errorIndication)
diff --git a/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/get-table-object-by-multiple-indices.py b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/get-table-object-by-multiple-indices.py
index cec5ad25..ae888ae3 100644
--- a/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/get-table-object-by-multiple-indices.py
+++ b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/get-table-object-by-multiple-indices.py
@@ -17,17 +17,24 @@ Functionally similar to:
"""#
from pysnmp.hlapi.v1arch import *
-errorIndication, errorStatus, errorIndex, varBinds = next(
- getCmd(SnmpDispatcher(),
- CommunityData('public'),
- UdpTransportTarget(('demo.snmplabs.com', 161)),
- ObjectType(ObjectIdentity('TCP-MIB',
- 'tcpConnLocalAddress',
- '0.0.0.0', 22,
- '0.0.0.0', 0)),
- lookupMib=True)
+iterator = getCmd(
+ SnmpDispatcher(),
+ CommunityData('public'),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ ObjectType(
+ ObjectIdentity(
+ 'TCP-MIB',
+ 'tcpConnLocalAddress',
+ '0.0.0.0', 22,
+ '0.0.0.0', 0
+ )
+ ),
+ lookupMib=True
)
+
+errorIndication, errorStatus, errorIndex, varBinds = next(iterator)
+
if errorIndication:
print(errorIndication)
diff --git a/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/getbulk-fetch-scalar-and-table-variables-over-ipv6.py b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/getbulk-fetch-scalar-and-table-variables-over-ipv6.py
index 49257a1c..1bdcf87a 100644
--- a/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/getbulk-fetch-scalar-and-table-variables-over-ipv6.py
+++ b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/getbulk-fetch-scalar-and-table-variables-over-ipv6.py
@@ -19,17 +19,18 @@ Functionally similar to:
"""#
from pysnmp.hlapi.v1arch import *
-for (errorIndication,
- errorStatus,
- errorIndex,
- varBinds) in bulkCmd(SnmpDispatcher(),
- CommunityData('public'),
- UdpTransportTarget(('demo.snmplabs.com', 161)),
- 1, 25,
- ObjectType(ObjectIdentity('IP-MIB', 'ipAdEntAddr')),
- ObjectType(ObjectIdentity('IP-MIB', 'ipAddrEntry')),
- lookupMib=True,
- lexicographicMode=False):
+iterator = bulkCmd(
+ SnmpDispatcher(),
+ CommunityData('public'),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ 1, 25,
+ ObjectType(ObjectIdentity('IP-MIB', 'ipAdEntAddr')),
+ ObjectType(ObjectIdentity('IP-MIB', 'ipAddrEntry')),
+ lookupMib=True,
+ lexicographicMode=False
+)
+
+for errorIndication, errorStatus, errorIndex, varBinds in iterator:
if errorIndication:
print(errorIndication)
diff --git a/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/getbulk-limit-number-of-packets.py b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/getbulk-limit-number-of-packets.py
index 22d52589..519c1bf2 100644
--- a/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/getbulk-limit-number-of-packets.py
+++ b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/getbulk-limit-number-of-packets.py
@@ -19,16 +19,17 @@ Functionally similar to:
"""#
from pysnmp.hlapi.v1arch import *
-for (errorIndication,
- errorStatus,
- errorIndex,
- varBinds) in bulkCmd(SnmpDispatcher(),
- CommunityData('public'),
- UdpTransportTarget(('demo.snmplabs.com', 161)),
- 0, 50,
- ObjectType(ObjectIdentity('SNMPv2-MIB', 'system')),
- lookupMib=True,
- maxCalls=10):
+iterator = bulkCmd(
+ SnmpDispatcher(),
+ CommunityData('public'),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ 0, 50,
+ ObjectType(ObjectIdentity('SNMPv2-MIB', 'system')),
+ lookupMib=True,
+ maxCalls=10
+)
+
+for errorIndication, errorStatus, errorIndex, varBinds in iterator:
if errorIndication:
print(errorIndication)
diff --git a/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/multiple-get-calls.py b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/multiple-get-calls.py
index 57a1132b..e1478085 100644
--- a/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/multiple-get-calls.py
+++ b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/multiple-get-calls.py
@@ -27,15 +27,18 @@ queue = [
[ObjectType(ObjectIdentity('IF-MIB', 'ifOutOctets', 1))]
]
-iterator = getCmd(SnmpDispatcher(),
- CommunityData('public'),
- UdpTransportTarget(('demo.snmplabs.com', 161)),
- lookupMib=True)
+iterator = getCmd(
+ SnmpDispatcher(),
+ CommunityData('public'),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ lookupMib=True
+)
next(iterator)
while queue:
errorIndication, errorStatus, errorIndex, varBinds = iterator.send(queue.pop())
+
if errorIndication:
print(errorIndication)
diff --git a/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/preload-pysnmp-mibs.py b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/preload-pysnmp-mibs.py
index 39d1e7dd..0df556c4 100644
--- a/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/preload-pysnmp-mibs.py
+++ b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/preload-pysnmp-mibs.py
@@ -18,14 +18,15 @@ Functionally similar to:
"""#
from pysnmp.hlapi.v1arch import *
-for (errorIndication,
- errorStatus,
- errorIndex,
- varBinds) in nextCmd(SnmpDispatcher(),
- CommunityData('public'),
- UdpTransportTarget(('demo.snmplabs.com', 161)),
- ObjectType(ObjectIdentity('1.3.6').loadMibs()),
- lookupMib=True):
+iterator = nextCmd(
+ SnmpDispatcher(),
+ CommunityData('public'),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ ObjectType(ObjectIdentity('1.3.6').loadMibs()),
+ lookupMib=True
+)
+
+for errorIndication, errorStatus, errorIndex, varBinds in iterator:
if errorIndication:
print(errorIndication)
diff --git a/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/pull-whole-mib.py b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/pull-whole-mib.py
index 69e943d9..71cf6a70 100644
--- a/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/pull-whole-mib.py
+++ b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/pull-whole-mib.py
@@ -17,13 +17,14 @@ Functionally similar to:
"""#
from pysnmp.hlapi.v1arch import *
-for (errorIndication,
- errorStatus,
- errorIndex,
- varBinds) in nextCmd(SnmpDispatcher(),
- CommunityData('public'),
- UdpTransportTarget(('demo.snmplabs.com', 161)),
- ObjectType(ObjectIdentity('IF-MIB'))):
+iterator = nextCmd(
+ SnmpDispatcher(),
+ CommunityData('public'),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ ObjectType(ObjectIdentity('IF-MIB'))
+)
+
+for errorIndication, errorStatus, errorIndex, varBinds in interator:
if errorIndication:
print(errorIndication)
diff --git a/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/pull-whole-snmp-table.py b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/pull-whole-snmp-table.py
index 8d81b1e5..d605c2da 100644
--- a/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/pull-whole-snmp-table.py
+++ b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/pull-whole-snmp-table.py
@@ -18,20 +18,21 @@ Functionally similar to:
"""#
from pysnmp.hlapi.v1arch import *
-for (errorIndication,
- errorStatus,
- errorIndex,
- varBinds) in nextCmd(SnmpDispatcher(),
- CommunityData('public', mpModel=0),
- UdpTransportTarget(('demo.snmplabs.com', 161)),
- ObjectType(ObjectIdentity('IF-MIB', 'ifDescr')),
- ObjectType(ObjectIdentity('IF-MIB', 'ifType')),
- ObjectType(ObjectIdentity('IF-MIB', 'ifMtu')),
- ObjectType(ObjectIdentity('IF-MIB', 'ifSpeed')),
- ObjectType(ObjectIdentity('IF-MIB', 'ifPhysAddress')),
- ObjectType(ObjectIdentity('IF-MIB', 'ifType')),
- lookupMib=True,
- lexicographicMode=False):
+iterator = nextCmd(
+ SnmpDispatcher(),
+ CommunityData('public', mpModel=0),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ ObjectType(ObjectIdentity('IF-MIB', 'ifDescr')),
+ ObjectType(ObjectIdentity('IF-MIB', 'ifType')),
+ ObjectType(ObjectIdentity('IF-MIB', 'ifMtu')),
+ ObjectType(ObjectIdentity('IF-MIB', 'ifSpeed')),
+ ObjectType(ObjectIdentity('IF-MIB', 'ifPhysAddress')),
+ ObjectType(ObjectIdentity('IF-MIB', 'ifType')),
+ lookupMib=True,
+ lexicographicMode=False
+)
+
+for errorIndication, errorStatus, errorIndex, varBinds in iterator:
if errorIndication:
print(errorIndication)
diff --git a/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/query-agents-from-multuple-threads-over-ipv4-and-ipv6.py b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/query-agents-from-multuple-threads-over-ipv4-and-ipv6.py
index 29ec78b6..98e235f3 100644
--- a/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/query-agents-from-multuple-threads-over-ipv4-and-ipv6.py
+++ b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/query-agents-from-multuple-threads-over-ipv4-and-ipv6.py
@@ -35,29 +35,33 @@ else:
# List of targets in the following format:
# ( ( authData, transportTarget, varNames ), ... )
-targets = (
+TARGETS = (
# 1-st target (SNMPv1 over IPv4/UDP)
(CommunityData('public', mpModel=0),
UdpTransportTarget(('demo.snmplabs.com', 161)),
(ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)),
ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0)))),
+
# 2-nd target (SNMPv2c over IPv4/UDP)
(CommunityData('public'),
UdpTransportTarget(('demo.snmplabs.com', 161)),
(ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)),
ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0)))),
- # 3-nd target (SNMPv2c over IPv4/UDP) - same community and
+
+ # 3-nd target (SNMPv2c over IPv4/UDP) - same community and
# different transport address.
(CommunityData('public'),
Udp6TransportTarget(('localhost', 161)),
(ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysContact', 0)),
ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysName', 0)))),
+
# 4-th target (SNMPv2c over IPv4/UDP) - same community and
# different transport port.
(CommunityData('public'),
UdpTransportTarget(('demo.snmplabs.com', 1161)),
(ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)),
ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0)))),
+
# N-th target
# ...
)
@@ -112,7 +116,7 @@ class ThreadPool(object):
pool = ThreadPool(3)
# Submit GET requests
-for authData, transportTarget, varBinds in targets:
+for authData, transportTarget, varBinds in TARGETS:
pool.addRequest(authData, transportTarget, varBinds)
# Wait for responses or errors
@@ -120,11 +124,14 @@ pool.waitCompletion()
# Walk through responses
for errorIndication, errorStatus, errorIndex, varBinds in pool.getResponses():
+
if errorIndication:
print(errorIndication)
+
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
+
else:
for varBind in varBinds:
print(' = '.join([x.prettyPrint() for x in varBind]))
diff --git a/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/set-multiple-scalar-values.py b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/set-multiple-scalar-values.py
index b5498003..39edb0cb 100644
--- a/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/set-multiple-scalar-values.py
+++ b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/set-multiple-scalar-values.py
@@ -21,19 +21,28 @@ Functionally similar to:
"""#
from pysnmp.hlapi.v1arch import *
-errorIndication, errorStatus, errorIndex, varBinds = next(
- setCmd(SnmpDispatcher(),
- CommunityData('public', mpModel=0),
- UdpTransportTarget(('demo.snmplabs.com', 161)),
- ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysORID', 1),
- ObjectIdentifier('1.3.6.1.4.1.20408.1.1')),
- ObjectType(ObjectIdentity('1.3.6.1.2.1.1.9.1.2.1'),
- '1.3.6.1.4.1.20408.1.1'),
- ObjectType(ObjectIdentity('1.3.6.1.2.1.1.9.1.3.1'),
- OctetString('new system name')),
- lookupMib=True)
+iterator = setCmd(
+ SnmpDispatcher(),
+ CommunityData('public', mpModel=0),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ ObjectType(
+ ObjectIdentity('SNMPv2-MIB', 'sysORID', 1),
+ ObjectIdentifier('1.3.6.1.4.1.20408.1.1')
+ ),
+ ObjectType(
+ ObjectIdentity('1.3.6.1.2.1.1.9.1.2.1'),
+ '1.3.6.1.4.1.20408.1.1'
+ ),
+ ObjectType(
+ ObjectIdentity('1.3.6.1.2.1.1.9.1.3.1'),
+ OctetString('new system name')
+ ),
+ lookupMib=True
)
+
+errorIndication, errorStatus, errorIndex, varBinds = next(iterator)
+
if errorIndication:
print(errorIndication)
diff --git a/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/v1-get.py b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/v1-get.py
index b54802af..a07208e7 100644
--- a/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/v1-get.py
+++ b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/v1-get.py
@@ -17,11 +17,15 @@ Functionally similar to:
"""#
from pysnmp.hlapi.v1arch import *
-for response in getCmd(SnmpDispatcher(),
- CommunityData('public', mpModel=0),
- UdpTransportTarget(('demo.snmplabs.com', 161)),
- ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)),
- lookupMib=True):
+iterator = getCmd(
+ SnmpDispatcher(),
+ CommunityData('public', mpModel=0),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)),
+ lookupMib=True
+)
+
+for response in iterator:
errorIndication, errorStatus, errorIndex, varBinds = response
diff --git a/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/v2c-get.py b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/v2c-get.py
index e2ec5815..25e1c626 100644
--- a/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/v2c-get.py
+++ b/examples/hlapi/v1arch/asyncore/sync/manager/cmdgen/v2c-get.py
@@ -16,11 +16,15 @@ Functionally similar to:
"""#
from pysnmp.hlapi.v1arch import *
-for response in getCmd(SnmpDispatcher(),
- CommunityData('public'),
- UdpTransportTarget(('demo.snmplabs.com', 161)),
- ('1.3.6.1.2.1.1.1.0', None),
- ('1.3.6.1.2.1.1.6.0', None)):
+iterator = getCmd(
+ SnmpDispatcher(),
+ CommunityData('public'),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ ('1.3.6.1.2.1.1.1.0', None),
+ ('1.3.6.1.2.1.1.6.0', None)
+)
+
+for response in iterator:
errorIndication, errorStatus, errorIndex, varBinds = response
diff --git a/examples/hlapi/v3arch/asyncio/agent/ntforg/default-v1-trap.py b/examples/hlapi/v3arch/asyncio/agent/ntforg/default-v1-trap.py
index 6a0fefda..41032e9b 100644
--- a/examples/hlapi/v3arch/asyncio/agent/ntforg/default-v1-trap.py
+++ b/examples/hlapi/v3arch/asyncio/agent/ntforg/default-v1-trap.py
@@ -26,8 +26,10 @@ from pysnmp.hlapi.v3arch.asyncio import *
@asyncio.coroutine
def run():
+
snmpEngine = SnmpEngine()
- errorIndication, errorStatus, errorIndex, varBinds = yield from sendNotification(
+
+ iterator = sendNotification(
snmpEngine,
CommunityData('public', mpModel=0),
UdpTransportTarget(('demo.snmplabs.com', 162)),
@@ -43,6 +45,8 @@ def run():
)
)
+ errorIndication, errorStatus, errorIndex, varBinds = yield from iterator
+
if errorIndication:
print(errorIndication)
diff --git a/examples/hlapi/v3arch/asyncio/agent/ntforg/multiple-notifications-at-once.py b/examples/hlapi/v3arch/asyncio/agent/ntforg/multiple-notifications-at-once.py
index f1cae2b8..fbdb568c 100644
--- a/examples/hlapi/v3arch/asyncio/agent/ntforg/multiple-notifications-at-once.py
+++ b/examples/hlapi/v3arch/asyncio/agent/ntforg/multiple-notifications-at-once.py
@@ -29,10 +29,8 @@ from pysnmp.hlapi.v3arch.asyncio import *
@asyncio.coroutine
def sendone(snmpEngine, hostname, notifyType):
- (errorIndication,
- errorStatus,
- errorIndex,
- varBinds) = yield from sendNotification(
+
+ iterator = sendNotification(
snmpEngine,
CommunityData('public', tag=hostname),
UdpTransportTarget((hostname, 162), tagList=hostname),
@@ -48,10 +46,14 @@ def sendone(snmpEngine, hostname, notifyType):
)
)
+ errorIndication, errorStatus, errorIndex, varBinds = yield from iterator
+
if errorIndication:
print(errorIndication)
+
elif errorStatus:
print('%s: at %s' % (errorStatus.prettyPrint(), errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
+
else:
for varBind in varBinds:
print(' = '.join([x.prettyPrint() for x in varBind]))
@@ -61,6 +63,8 @@ snmpEngine = SnmpEngine()
loop = asyncio.get_event_loop()
loop.run_until_complete(
- asyncio.wait([sendone(snmpEngine, 'demo.snmplabs.com', 'trap'),
- sendone(snmpEngine, 'demo.snmplabs.com', 'inform')])
+ asyncio.wait(
+ [sendone(snmpEngine, 'demo.snmplabs.com', 'trap'),
+ sendone(snmpEngine, 'demo.snmplabs.com', 'inform')]
+ )
)
diff --git a/examples/hlapi/v3arch/asyncio/manager/cmdgen/getbulk-to-eom.py b/examples/hlapi/v3arch/asyncio/manager/cmdgen/getbulk-to-eom.py
index c60d6e12..aa6bf441 100644
--- a/examples/hlapi/v3arch/asyncio/manager/cmdgen/getbulk-to-eom.py
+++ b/examples/hlapi/v3arch/asyncio/manager/cmdgen/getbulk-to-eom.py
@@ -23,22 +23,25 @@ from pysnmp.hlapi.v3arch.asyncio import *
@asyncio.coroutine
def run(varBinds):
+
snmpEngine = SnmpEngine()
+
while True:
- (errorIndication,
- errorStatus,
- errorIndex,
- varBindTable) = yield from bulkCmd(
+ iterator = bulkCmd(
snmpEngine,
UsmUserData('usr-none-none'),
UdpTransportTarget(('demo.snmplabs.com', 161)),
ContextData(),
0, 50,
- *varBinds)
+ *varBinds
+ )
+
+ errorIndication, errorStatus, errorIndex, varBindTable = yield from iterator
if errorIndication:
print(errorIndication)
break
+
elif errorStatus:
print('%s at %s' % (
errorStatus.prettyPrint(),
diff --git a/examples/hlapi/v3arch/asyncio/manager/cmdgen/multiple-concurrent-queries-over-ipv4-and-ipv6.py b/examples/hlapi/v3arch/asyncio/manager/cmdgen/multiple-concurrent-queries-over-ipv4-and-ipv6.py
index a1b5d9a0..5f3c78e7 100644
--- a/examples/hlapi/v3arch/asyncio/manager/cmdgen/multiple-concurrent-queries-over-ipv4-and-ipv6.py
+++ b/examples/hlapi/v3arch/asyncio/manager/cmdgen/multiple-concurrent-queries-over-ipv4-and-ipv6.py
@@ -23,7 +23,8 @@ from pysnmp.hlapi.v3arch.asyncio import *
@asyncio.coroutine
def getone(snmpEngine, hostname):
- errorIndication, errorStatus, errorIndex, varBinds = yield from getCmd(
+
+ iterator = getCmd(
snmpEngine,
CommunityData('public'),
UdpTransportTarget(hostname),
@@ -31,8 +32,11 @@ def getone(snmpEngine, hostname):
ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0))
)
+ errorIndication, errorStatus, errorIndex, varBinds = yield from iterator
+
if errorIndication:
print(errorIndication)
+
elif errorStatus:
print('%s at %s' % (
errorStatus.prettyPrint(),
@@ -48,7 +52,9 @@ snmpEngine = SnmpEngine()
loop = asyncio.get_event_loop()
loop.run_until_complete(
- asyncio.wait([getone(snmpEngine, ('demo.snmplabs.com', 1161)),
- getone(snmpEngine, ('demo.snmplabs.com', 2161)),
- getone(snmpEngine, ('demo.snmplabs.com', 3161))])
+ asyncio.wait(
+ [getone(snmpEngine, ('demo.snmplabs.com', 1161)),
+ getone(snmpEngine, ('demo.snmplabs.com', 2161)),
+ getone(snmpEngine, ('demo.snmplabs.com', 3161))]
+ )
)
diff --git a/examples/hlapi/v3arch/asyncio/manager/cmdgen/multiple-sequential-queries.py b/examples/hlapi/v3arch/asyncio/manager/cmdgen/multiple-sequential-queries.py
index d546870d..626661d0 100644
--- a/examples/hlapi/v3arch/asyncio/manager/cmdgen/multiple-sequential-queries.py
+++ b/examples/hlapi/v3arch/asyncio/manager/cmdgen/multiple-sequential-queries.py
@@ -23,7 +23,8 @@ from pysnmp.hlapi.v3arch.asyncio import *
@asyncio.coroutine
def getone(snmpEngine, hostname):
- errorIndication, errorStatus, errorIndex, varBinds = yield from getCmd(
+
+ iterator = getCmd(
snmpEngine,
CommunityData('public'),
UdpTransportTarget(hostname),
@@ -31,8 +32,11 @@ def getone(snmpEngine, hostname):
ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0))
)
+ errorIndication, errorStatus, errorIndex, varBinds = yield from iterator
+
if errorIndication:
print(errorIndication)
+
elif errorStatus:
print('%s at %s' % (
errorStatus.prettyPrint(),
@@ -53,6 +57,13 @@ def getall(snmpEngine, hostnames):
snmpEngine = SnmpEngine()
loop = asyncio.get_event_loop()
-loop.run_until_complete(getall(snmpEngine, [('demo.snmplabs.com', 1161),
- ('demo.snmplabs.com', 2161),
- ('demo.snmplabs.com', 3161)]))
+
+loop.run_until_complete(
+ getall(
+ snmpEngine, [
+ ('demo.snmplabs.com', 1161),
+ ('demo.snmplabs.com', 2161),
+ ('demo.snmplabs.com', 3161)
+ ]
+ )
+)
diff --git a/examples/hlapi/v3arch/asyncio/manager/cmdgen/v1-get.py b/examples/hlapi/v3arch/asyncio/manager/cmdgen/v1-get.py
index f14a9f63..a7bf585a 100644
--- a/examples/hlapi/v3arch/asyncio/manager/cmdgen/v1-get.py
+++ b/examples/hlapi/v3arch/asyncio/manager/cmdgen/v1-get.py
@@ -22,7 +22,8 @@ from pysnmp.hlapi.v3arch.asyncio import *
@asyncio.coroutine
def run():
snmpEngine = SnmpEngine()
- errorIndication, errorStatus, errorIndex, varBinds = yield from getCmd(
+
+ iterator = getCmd(
snmpEngine,
CommunityData('public', mpModel=0),
UdpTransportTarget(('demo.snmplabs.com', 161)),
@@ -30,8 +31,11 @@ def run():
ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0))
)
+ errorIndication, errorStatus, errorIndex, varBinds = yield from iterator
+
if errorIndication:
print(errorIndication)
+
elif errorStatus:
print('%s at %s' % (
errorStatus.prettyPrint(),
diff --git a/examples/hlapi/v3arch/asyncore/agent/ntforg/multiple-informs-at-once.py b/examples/hlapi/v3arch/asyncore/agent/ntforg/multiple-informs-at-once.py
index 9690c2e4..a1c73886 100644
--- a/examples/hlapi/v3arch/asyncore/agent/ntforg/multiple-informs-at-once.py
+++ b/examples/hlapi/v3arch/asyncore/agent/ntforg/multiple-informs-at-once.py
@@ -20,11 +20,12 @@ from pysnmp.hlapi.v3arch.asyncore import *
# List of targets in the followin format:
# ( ( authData, transportTarget ), ... )
-targets = (
+TARGETS = (
# 1-st target (SNMPv2c over IPv4/UDP)
(CommunityData('public'),
UdpTransportTarget(('demo.snmplabs.com', 162)),
ContextData()),
+
# 2-nd target (SNMPv3 over IPv4/UDP)
(UsmUserData('usr-md5-des', 'authkey1', 'privkey1'),
UdpTransportTarget(('demo.snmplabs.com', 162)),
@@ -48,7 +49,7 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication,
snmpEngine = SnmpEngine()
-for authData, transportTarget, contextData in targets:
+for authData, transportTarget, contextData in TARGETS:
sendPduHandle = sendNotification(
snmpEngine,
authData,
diff --git a/examples/hlapi/v3arch/asyncore/agent/ntforg/multiple-traps-at-once.py b/examples/hlapi/v3arch/asyncore/agent/ntforg/multiple-traps-at-once.py
index ad873868..83d9cfc4 100644
--- a/examples/hlapi/v3arch/asyncore/agent/ntforg/multiple-traps-at-once.py
+++ b/examples/hlapi/v3arch/asyncore/agent/ntforg/multiple-traps-at-once.py
@@ -21,11 +21,12 @@ from pysnmp.hlapi.v3arch.asyncore import *
# List of targets in the followin format:
# ( ( authData, transportTarget ), ... )
-targets = (
+TARGETS = (
# 1-st target (SNMPv1 over IPv4/UDP)
(CommunityData('public', mpModel=0),
UdpTransportTarget(('demo.snmplabs.com', 162)),
ContextData()),
+
# 2-nd target (SNMPv2c over IPv4/UDP)
(CommunityData('public'),
UdpTransportTarget(('demo.snmplabs.com', 162)),
@@ -34,7 +35,7 @@ targets = (
snmpEngine = SnmpEngine()
-for authData, transportTarget, contextData in targets:
+for authData, transportTarget, contextData in TARGETS:
sendNotification(
snmpEngine,
authData,
diff --git a/examples/hlapi/v3arch/asyncore/agent/ntforg/running-multiple-snmp-engines-at-once.py b/examples/hlapi/v3arch/asyncore/agent/ntforg/running-multiple-snmp-engines-at-once.py
index 10a96756..c60ea839 100644
--- a/examples/hlapi/v3arch/asyncore/agent/ntforg/running-multiple-snmp-engines-at-once.py
+++ b/examples/hlapi/v3arch/asyncore/agent/ntforg/running-multiple-snmp-engines-at-once.py
@@ -34,11 +34,12 @@ from pysnmp.carrier.asyncore.dispatch import AsyncoreDispatcher
# List of targets in the following format:
# ( ( authData, transportTarget ), ... )
-targets = (
+TARGETS = (
# 1-st target (SNMPv2c over IPv4/UDP)
(CommunityData('public'),
UdpTransportTarget(('demo.snmplabs.com', 1162)),
ContextData()),
+
# 2-nd target (SNMPv3 over IPv4/UDP)
(UsmUserData('usr-md5-des', 'authkey1', 'privkey1'),
UdpTransportTarget(('demo.snmplabs.com', 162)),
@@ -49,13 +50,22 @@ targets = (
# noinspection PyUnusedLocal
def cbFun(snmpEngine, sendRequestHandle, errorIndication,
errorStatus, errorIndex, varBinds, cbCtx):
- snmpEngine = cbCtx
+
if errorIndication:
- print('Notification %s for %s not sent: %s' % (sendRequestHandle, snmpEngine.snmpEngineID.prettyPrint(), errorIndication))
+ print('Notification %s for %s not sent: %s' % (
+ sendRequestHandle, snmpEngine.snmpEngineID.prettyPrint(),
+ errorIndication))
+
elif errorStatus:
- print('Notification Receiver returned error for request %s, SNMP Engine %s: %s @%s' % (sendRequestHandle, snmpEngine.snmpEngineID.prettyPrint(), errorStatus, errorIndex))
+ print('Notification Receiver returned error for request %s, '
+ 'SNMP Engine %s: %s @%s' % (sendRequestHandle,
+ snmpEngine.snmpEngineID.prettyPrint(),
+ errorStatus, errorIndex))
+
else:
- print('Notification %s for SNMP Engine %s delivered:' % (sendRequestHandle, snmpEngine.snmpEngineID.prettyPrint()))
+ print('Notification %s for SNMP Engine %s delivered: ' % (
+ sendRequestHandle, snmpEngine.snmpEngineID.prettyPrint()))
+
for name, val in varBinds:
print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
@@ -74,9 +84,12 @@ snmpEngineA.registerTransportDispatcher(transportDispatcher, 'A')
snmpEngineB = SnmpEngine()
snmpEngineB.registerTransportDispatcher(transportDispatcher, 'B')
-for authData, transportTarget, contextData in targets:
+for authData, transportTarget, contextData in TARGETS:
+
+ # Pick one of the two SNMP engines
snmpEngine = (transportTarget.getTransportInfo()[1][1] % 3 and
snmpEngineA or snmpEngineB)
+
sendPduHandle = sendNotification(
snmpEngine,
authData,
@@ -86,7 +99,7 @@ for authData, transportTarget, contextData in targets:
NotificationType(
ObjectIdentity('SNMPv2-MIB', 'coldStart')
).addVarBinds(('1.3.6.1.2.1.1.1.0', 'my name')),
- cbFun=cbFun, cbCtx=snmpEngine
+ cbFun=cbFun
)
transportDispatcher.runDispatcher()
diff --git a/examples/hlapi/v3arch/asyncore/manager/cmdgen/multiple-concurrent-queries-over-ipv4-and-ipv6.py b/examples/hlapi/v3arch/asyncore/manager/cmdgen/multiple-concurrent-queries-over-ipv4-and-ipv6.py
index ba9ffed3..1422fe3e 100644
--- a/examples/hlapi/v3arch/asyncore/manager/cmdgen/multiple-concurrent-queries-over-ipv4-and-ipv6.py
+++ b/examples/hlapi/v3arch/asyncore/manager/cmdgen/multiple-concurrent-queries-over-ipv4-and-ipv6.py
@@ -20,28 +20,32 @@ from pysnmp.hlapi.v3arch.asyncore import *
# List of targets in the followin format:
# ( ( authData, transportTarget, varNames ), ... )
-targets = (
+TARGETS = (
# 1-st target (SNMPv1 over IPv4/UDP)
(CommunityData('public', mpModel=0),
UdpTransportTarget(('demo.snmplabs.com', 161)),
(ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)),
ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0)))),
+
# 2-nd target (SNMPv2c over IPv4/UDP)
(CommunityData('public'),
UdpTransportTarget(('demo.snmplabs.com', 161)),
(ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)),
ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0)))),
- # 3-nd target (SNMPv2c over IPv4/UDP) - same community and
+
+ # 3-nd target (SNMPv2c over IPv4/UDP) - same community and
# different transport address.
(CommunityData('public'),
UdpTransportTarget(('localhost', 161)),
(ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysContact', 0)),
ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysName', 0)))),
+
# 4-nd target (SNMPv3 over IPv4/UDP)
(UsmUserData('usr-md5-des', 'authkey1', 'privkey1'),
UdpTransportTarget(('demo.snmplabs.com', 161)),
(ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)),
ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0)))),
+
# 5-th target (SNMPv3 over IPv6/UDP)
(UsmUserData('usr-md5-none', 'authkey1'),
Udp6TransportTarget(('::1', 161)),
@@ -56,15 +60,20 @@ targets = (
# noinspection PyUnusedLocal,PyUnusedLocal
def cbFun(snmpEngine, sendRequestHandle, errorIndication,
errorStatus, errorIndex, varBinds, cbCtx):
+
authData, transportTarget = cbCtx
+
print('%s via %s' % (authData, transportTarget))
+
if errorIndication:
print(errorIndication)
return True
+
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
return True
+
else:
for varBind in varBinds:
print(' = '.join([x.prettyPrint() for x in varBind]))
@@ -73,7 +82,7 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication,
snmpEngine = SnmpEngine()
# Submit GET requests
-for authData, transportTarget, varNames in targets:
+for authData, transportTarget, varNames in TARGETS:
getCmd(snmpEngine, authData, transportTarget, ContextData(), *varNames,
cbFun=cbFun, cbCtx=(authData, transportTarget))
diff --git a/examples/hlapi/v3arch/asyncore/manager/cmdgen/pull-mibs-from-multiple-agents-at-once-over-ipv4-and-ipv6.py b/examples/hlapi/v3arch/asyncore/manager/cmdgen/pull-mibs-from-multiple-agents-at-once-over-ipv4-and-ipv6.py
index 38e96f45..44247b9a 100644
--- a/examples/hlapi/v3arch/asyncore/manager/cmdgen/pull-mibs-from-multiple-agents-at-once-over-ipv4-and-ipv6.py
+++ b/examples/hlapi/v3arch/asyncore/manager/cmdgen/pull-mibs-from-multiple-agents-at-once-over-ipv4-and-ipv6.py
@@ -25,18 +25,22 @@ targets = (
UdpTransportTarget(('demo.snmplabs.com', 161)),
(ObjectType(ObjectIdentity('1.3.6.1.2.1')),
ObjectType(ObjectIdentity('1.3.6.1.3.1')))),
+
# 2-nd target (SNMPv2c over IPv4/UDP)
(CommunityData('public'),
UdpTransportTarget(('demo.snmplabs.com', 161)),
(ObjectType(ObjectIdentity('1.3.6.1.4.1')),)),
+
# 3-nd target (SNMPv3 over IPv4/UDP)
(UsmUserData('usr-md5-des', 'authkey1', 'privkey1'),
UdpTransportTarget(('demo.snmplabs.com', 161)),
(ObjectType(ObjectIdentity('SNMPv2-MIB', 'system')),)),
+
# 4-th target (SNMPv3 over IPv6/UDP)
(UsmUserData('usr-md5-none', 'authkey1'),
Udp6TransportTarget(('::1', 161)),
(ObjectType(ObjectIdentity('IF-MIB', 'ifTable')),))
+
# N-th target
# ...
)
@@ -46,15 +50,20 @@ targets = (
# noinspection PyUnusedLocal,PyUnusedLocal
def cbFun(snmpEngine, sendRequestHandle, errorIndication,
errorStatus, errorIndex, varBindTable, cbCtx):
- (authData, transportTarget) = cbCtx
+
+ authData, transportTarget = cbCtx
+
print('%s via %s' % (authData, transportTarget))
+
if errorIndication:
print(errorIndication)
return
+
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBindTable[-1][int(errorIndex) - 1][0] or '?'))
return
+
else:
for varBindRow in varBindTable:
for varBind in varBindRow:
diff --git a/examples/hlapi/v3arch/asyncore/manager/cmdgen/pull-whole-mib.py b/examples/hlapi/v3arch/asyncore/manager/cmdgen/pull-whole-mib.py
index a0aa02b9..e6fe324a 100644
--- a/examples/hlapi/v3arch/asyncore/manager/cmdgen/pull-whole-mib.py
+++ b/examples/hlapi/v3arch/asyncore/manager/cmdgen/pull-whole-mib.py
@@ -21,13 +21,16 @@ from pysnmp.hlapi.v3arch.asyncore import *
# noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal
def cbFun(snmpEngine, sendRequestHandle, errorIndication,
errorStatus, errorIndex, varBindTable, cbCtx):
+
if errorIndication:
print(errorIndication)
return
+
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBindTable[-1][int(errorIndex) - 1][0] or '?'))
return
+
else:
for varBindRow in varBindTable:
for varBind in varBindRow:
diff --git a/examples/hlapi/v3arch/asyncore/manager/cmdgen/query-multiple-snmp-engines-over-ipv4-and-ipv6.py b/examples/hlapi/v3arch/asyncore/manager/cmdgen/query-multiple-snmp-engines-over-ipv4-and-ipv6.py
index ad6e838f..fc2143d4 100644
--- a/examples/hlapi/v3arch/asyncore/manager/cmdgen/query-multiple-snmp-engines-over-ipv4-and-ipv6.py
+++ b/examples/hlapi/v3arch/asyncore/manager/cmdgen/query-multiple-snmp-engines-over-ipv4-and-ipv6.py
@@ -33,22 +33,25 @@ from pysnmp.carrier.asyncore.dispatch import AsyncoreDispatcher
# List of targets in the following format:
# ( ( authData, transportTarget, varNames ), ... )
-targets = (
+TARGETS = (
# 1-st target (SNMPv1 over IPv4/UDP)
(CommunityData('public', mpModel=0),
UdpTransportTarget(('demo.snmplabs.com', 161)),
(ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)),
ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0)))),
+
# 2-nd target (SNMPv2c over IPv4/UDP)
(CommunityData('public'),
UdpTransportTarget(('demo.snmplabs.com', 1161)),
(ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)),
ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0)))),
+
# 3-nd target (SNMPv3 over IPv4/UDP)
(UsmUserData('usr-md5-des', 'authkey1', 'privkey1'),
UdpTransportTarget(('demo.snmplabs.com', 2161)),
(ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)),
ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0))))
+
# N-th target
# ...
)
@@ -58,15 +61,19 @@ targets = (
# noinspection PyUnusedLocal,PyUnusedLocal
def cbFun(snmpEngine, sendRequestHandle, errorIndication,
errorStatus, errorIndex, varBinds, cbCtx):
- (snmpEngine, authData, transportTarget) = cbCtx
+ authData, transportTarget = cbCtx
+
print('snmpEngine %s: %s via %s' % (snmpEngine.snmpEngineID.prettyPrint(), authData, transportTarget))
+
if errorIndication:
print(errorIndication)
return True
+
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
return True
+
else:
for varBind in varBinds:
print(' = '.join([x.prettyPrint() for x in varBind]))
@@ -86,10 +93,11 @@ snmpEngineA.registerTransportDispatcher(transportDispatcher, 'A')
snmpEngineB = SnmpEngine()
snmpEngineB.registerTransportDispatcher(transportDispatcher, 'B')
-for authData, transportTarget, varBinds in targets:
- snmpEngine = transportTarget.getTransportInfo()[1][1] % 3 and \
- snmpEngineA or snmpEngineB
+for authData, transportTarget, varBinds in TARGETS:
+ snmpEngine = (transportTarget.getTransportInfo()[1][1] % 3 and
+ snmpEngineA or snmpEngineB)
+
getCmd(snmpEngine, authData, transportTarget, ContextData(), *varBinds,
- cbFun=cbFun, cbCtx=(snmpEngine, authData, transportTarget))
+ cbFun=cbFun, cbCtx=(authData, transportTarget))
transportDispatcher.runDispatcher()
diff --git a/examples/hlapi/v3arch/asyncore/manager/cmdgen/v2c-get.py b/examples/hlapi/v3arch/asyncore/manager/cmdgen/v2c-get.py
index ae8f8262..da2e7b34 100644
--- a/examples/hlapi/v3arch/asyncore/manager/cmdgen/v2c-get.py
+++ b/examples/hlapi/v3arch/asyncore/manager/cmdgen/v2c-get.py
@@ -20,13 +20,16 @@ from pysnmp.hlapi.v3arch.asyncore import *
# noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal
def cbFun(snmpEngine, sendRequestHandle, errorIndication,
errorStatus, errorIndex, varBinds, cbCtx):
+
if errorIndication:
print(errorIndication)
return
+
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBindTable[-1][int(errorIndex) - 1][0] or '?'))
return
+
else:
for varBind in varBinds:
print(' = '.join([x.prettyPrint() for x in varBind]))
diff --git a/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/custom-contextengineid.py b/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/custom-contextengineid.py
index 1b9e12d5..18da255f 100644
--- a/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/custom-contextengineid.py
+++ b/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/custom-contextengineid.py
@@ -22,23 +22,26 @@ Functionally similar to:
"""#
from pysnmp.hlapi import *
-errorIndication, errorStatus, errorIndex, varBinds = next(
- sendNotification(SnmpEngine(),
- UsmUserData('usr-md5-none', 'authkey1'),
- UdpTransportTarget(('demo.snmplabs.com', 162)),
- ContextData(OctetString(hexValue='8000000004030201')),
- 'inform',
- NotificationType(
- ObjectIdentity('1.3.6.1.6.3.1.1.5.2')
- ).loadMibs('SNMPv2-MIB')
- )
+iterator = sendNotification(
+ SnmpEngine(),
+ UsmUserData('usr-md5-none', 'authkey1'),
+ UdpTransportTarget(('demo.snmplabs.com', 162)),
+ ContextData(OctetString(hexValue='8000000004030201')),
+ 'inform',
+ NotificationType(
+ ObjectIdentity('1.3.6.1.6.3.1.1.5.2')
+ ).loadMibs('SNMPv2-MIB')
)
+errorIndication, errorStatus, errorIndex, varBinds = next(iterator)
+
if errorIndication:
print(errorIndication)
+
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
+
else:
for varBind in varBinds:
print(' = '.join([x.prettyPrint() for x in varBind]))
diff --git a/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/custom-contextname.py b/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/custom-contextname.py
index 96abba48..2c232cb6 100644
--- a/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/custom-contextname.py
+++ b/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/custom-contextname.py
@@ -22,20 +22,24 @@ Functionally similar to:
"""#
from pysnmp.hlapi import *
-errorIndication, errorStatus, errorIndex, varBinds = next(
- sendNotification(SnmpEngine(),
- UsmUserData('usr-md5-none', 'authkey1'),
- UdpTransportTarget(('demo.snmplabs.com', 162)),
- ContextData(contextName='my-context'),
- 'inform',
- NotificationType(ObjectIdentity('1.3.6.1.6.3.1.1.5.2')).loadMibs('SNMPv2-MIB'))
+iterator = sendNotification(
+ SnmpEngine(),
+ UsmUserData('usr-md5-none', 'authkey1'),
+ UdpTransportTarget(('demo.snmplabs.com', 162)),
+ ContextData(contextName='my-context'),
+ 'inform',
+ NotificationType(ObjectIdentity('1.3.6.1.6.3.1.1.5.2')).loadMibs('SNMPv2-MIB')
)
+errorIndication, errorStatus, errorIndex, varBinds = next(iterator)
+
if errorIndication:
print(errorIndication)
+
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
+
else:
for varBind in varBinds:
print(' = '.join([x.prettyPrint() for x in varBind]))
diff --git a/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/custom-v1-trap.py b/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/custom-v1-trap.py
index c6d84303..017fc8b8 100644
--- a/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/custom-v1-trap.py
+++ b/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/custom-v1-trap.py
@@ -24,24 +24,25 @@ Functionally similar to:
"""#
from pysnmp.hlapi import *
-errorIndication, errorStatus, errorIndex, varBinds = next(
- sendNotification(
- SnmpEngine(),
- CommunityData('public', mpModel=0),
- UdpTransportTarget(('demo.snmplabs.com', 162)),
- ContextData(),
- 'trap',
- NotificationType(
- ObjectIdentity('1.3.6.1.4.1.20408.4.1.1.2.0.432'),
- ).addVarBinds(
- ('1.3.6.1.2.1.1.3.0', 12345),
- ('1.3.6.1.6.3.18.1.3.0', '127.0.0.1'),
- ('1.3.6.1.6.3.1.1.4.3.0', '1.3.6.1.4.1.20408.4.1.1.2'),
- ('1.3.6.1.2.1.1.1.0', OctetString('my system'))
- ).loadMibs(
- 'SNMPv2-MIB', 'SNMP-COMMUNITY-MIB'
- )
+iterator = sendNotification(
+ SnmpEngine(),
+ CommunityData('public', mpModel=0),
+ UdpTransportTarget(('demo.snmplabs.com', 162)),
+ ContextData(),
+ 'trap',
+ NotificationType(
+ ObjectIdentity('1.3.6.1.4.1.20408.4.1.1.2.0.432'),
+ ).addVarBinds(
+ ('1.3.6.1.2.1.1.3.0', 12345),
+ ('1.3.6.1.6.3.18.1.3.0', '127.0.0.1'),
+ ('1.3.6.1.6.3.1.1.4.3.0', '1.3.6.1.4.1.20408.4.1.1.2'),
+ ('1.3.6.1.2.1.1.1.0', OctetString('my system'))
+ ).loadMibs(
+ 'SNMPv2-MIB', 'SNMP-COMMUNITY-MIB'
)
)
+
+errorIndication, errorStatus, errorIndex, varBinds = next(iterator)
+
if errorIndication:
print(errorIndication)
diff --git a/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/default-v1-trap.py b/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/default-v1-trap.py
index 552ad877..4846f9da 100644
--- a/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/default-v1-trap.py
+++ b/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/default-v1-trap.py
@@ -22,23 +22,23 @@ Functionally similar to:
"""#
from pysnmp.hlapi import *
-errorIndication, errorStatus, errorIndex, varBinds = next(
- sendNotification(
- SnmpEngine(),
- CommunityData('public', mpModel=0),
- UdpTransportTarget(('demo.snmplabs.com', 162)),
- ContextData(),
- 'trap',
- NotificationType(
- ObjectIdentity('1.3.6.1.6.3.1.1.5.2')
- ).addVarBinds(
- ('1.3.6.1.6.3.1.1.4.3.0', '1.3.6.1.4.1.20408.4.1.1.2'),
- ('1.3.6.1.2.1.1.1.0', OctetString('my system'))
- ).loadMibs(
- 'SNMPv2-MIB'
- )
+iterator = sendNotification(
+ SnmpEngine(),
+ CommunityData('public', mpModel=0),
+ UdpTransportTarget(('demo.snmplabs.com', 162)),
+ ContextData(),
+ 'trap',
+ NotificationType(
+ ObjectIdentity('1.3.6.1.6.3.1.1.5.2')
+ ).addVarBinds(
+ ('1.3.6.1.6.3.1.1.4.3.0', '1.3.6.1.4.1.20408.4.1.1.2'),
+ ('1.3.6.1.2.1.1.1.0', OctetString('my system'))
+ ).loadMibs(
+ 'SNMPv2-MIB'
)
)
+errorIndication, errorStatus, errorIndex, varBinds = next(iterator)
+
if errorIndication:
print(errorIndication)
diff --git a/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/send-notification-with-additional-varbinds.py b/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/send-notification-with-additional-varbinds.py
index 46f3c5c1..1fd44398 100644
--- a/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/send-notification-with-additional-varbinds.py
+++ b/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/send-notification-with-additional-varbinds.py
@@ -18,26 +18,28 @@ Functionally similar to:
"""#
from pysnmp.hlapi import *
-errorIndication, errorStatus, errorIndex, varBinds = next(
- sendNotification(
- SnmpEngine(),
- CommunityData('public'),
- UdpTransportTarget(('demo.snmplabs.com', 162)),
- ContextData(),
- 'inform',
- NotificationType(
- ObjectIdentity('SNMPv2-MIB', 'coldStart')
- ).addVarBinds(
- ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysName', 0), 'my system')
- )
+iterator = sendNotification(
+ SnmpEngine(),
+ CommunityData('public'),
+ UdpTransportTarget(('demo.snmplabs.com', 162)),
+ ContextData(),
+ 'inform',
+ NotificationType(
+ ObjectIdentity('SNMPv2-MIB', 'coldStart')
+ ).addVarBinds(
+ ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysName', 0), 'my system')
)
)
+errorIndication, errorStatus, errorIndex, varBinds = next(iterator)
+
if errorIndication:
print(errorIndication)
+
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
+
else:
for varBind in varBinds:
print(' = '.join([x.prettyPrint() for x in varBind]))
diff --git a/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/v2c-trap-with-notification-objects.py b/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/v2c-trap-with-notification-objects.py
index 5681d28c..c53f09e6 100644
--- a/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/v2c-trap-with-notification-objects.py
+++ b/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/v2c-trap-with-notification-objects.py
@@ -20,22 +20,24 @@ Functionally similar to:
"""#
from pysnmp.hlapi import *
-errorIndication, errorStatus, errorIndex, varBinds = next(
- sendNotification(
- SnmpEngine(),
- CommunityData('public'),
- UdpTransportTarget(('demo.snmplabs.com', 162)),
- ContextData(),
- 'trap',
- NotificationType(
- ObjectIdentity('IF-MIB', 'linkUp'),
- instanceIndex=(123,),
- objects={('IF-MIB', 'ifIndex'): 123,
- ('IF-MIB', 'ifAdminStatus'): 'up',
- ('IF-MIB', 'ifOperStatus'): 'up'}
- )
+iterator = sendNotification(
+ SnmpEngine(),
+ CommunityData('public'),
+ UdpTransportTarget(('demo.snmplabs.com', 162)),
+ ContextData(),
+ 'trap',
+ NotificationType(
+ ObjectIdentity('IF-MIB', 'linkUp'),
+ instanceIndex=(123,),
+ objects={
+ ('IF-MIB', 'ifIndex'): 123,
+ ('IF-MIB', 'ifAdminStatus'): 'up',
+ ('IF-MIB', 'ifOperStatus'): 'up'
+ }
)
)
+errorIndication, errorStatus, errorIndex, varBinds = next(iterator)
+
if errorIndication:
print(errorIndication)
diff --git a/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/v3-inform.py b/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/v3-inform.py
index 6f02024f..fb9df891 100644
--- a/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/v3-inform.py
+++ b/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/v3-inform.py
@@ -18,28 +18,30 @@ Functionally similar to:
"""#
from pysnmp.hlapi import *
-errorIndication, errorStatus, errorIndex, varBinds = next(
- sendNotification(
- SnmpEngine(),
- UsmUserData('usr-md5-des', 'authkey1', 'privkey1'),
- UdpTransportTarget(('demo.snmplabs.com', 162)),
- ContextData(),
- 'inform',
- NotificationType(
- ObjectIdentity('1.3.6.1.6.3.1.1.5.2')
- ).addVarBinds(
- ObjectType(ObjectIdentity('1.3.6.1.2.1.1.5.0'), 'system name')
- ).loadMibs(
- 'SNMPv2-MIB'
- )
+iterator = sendNotification(
+ SnmpEngine(),
+ UsmUserData('usr-md5-des', 'authkey1', 'privkey1'),
+ UdpTransportTarget(('demo.snmplabs.com', 162)),
+ ContextData(),
+ 'inform',
+ NotificationType(
+ ObjectIdentity('1.3.6.1.6.3.1.1.5.2')
+ ).addVarBinds(
+ ObjectType(ObjectIdentity('1.3.6.1.2.1.1.5.0'), 'system name')
+ ).loadMibs(
+ 'SNMPv2-MIB'
)
)
+errorIndication, errorStatus, errorIndex, varBinds = next(iterator)
+
if errorIndication:
print(errorIndication)
+
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
+
else:
for varBind in varBinds:
print(' = '.join([x.prettyPrint() for x in varBind]))
diff --git a/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/v3-trap.py b/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/v3-trap.py
index 14501fb9..87a53fd6 100644
--- a/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/v3-trap.py
+++ b/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/v3-trap.py
@@ -24,18 +24,18 @@ Functionally similar to:
"""#
from pysnmp.hlapi import *
-errorIndication, errorStatus, errorIndex, varBinds = next(
- sendNotification(
- SnmpEngine(OctetString(hexValue='8000000001020304')),
- UsmUserData('usr-sha-aes128', 'authkey1', 'privkey1',
- authProtocol=USM_AUTH_HMAC96_SHA,
- privProtocol=USM_PRIV_CFB128_AES),
- UdpTransportTarget(('demo.snmplabs.com', 162)),
- ContextData(),
- 'trap',
- NotificationType(ObjectIdentity('SNMPv2-MIB', 'authenticationFailure'))
- )
+iterator = sendNotification(
+ SnmpEngine(OctetString(hexValue='8000000001020304')),
+ UsmUserData('usr-sha-aes128', 'authkey1', 'privkey1',
+ authProtocol=USM_AUTH_HMAC96_SHA,
+ privProtocol=USM_PRIV_CFB128_AES),
+ UdpTransportTarget(('demo.snmplabs.com', 162)),
+ ContextData(),
+ 'trap',
+ NotificationType(ObjectIdentity('SNMPv2-MIB', 'authenticationFailure'))
)
+errorIndication, errorStatus, errorIndex, varBinds = next(iterator)
+
if errorIndication:
print(errorIndication)
diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/coerce-set-value-to-mib-spec.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/coerce-set-value-to-mib-spec.py
index b6fb879e..93ba8fff 100644
--- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/coerce-set-value-to-mib-spec.py
+++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/coerce-set-value-to-mib-spec.py
@@ -16,20 +16,26 @@ Functionally similar to:
"""#
from pysnmp.hlapi import *
-errorIndication, errorStatus, errorIndex, varBinds = next(
- setCmd(SnmpEngine(),
- CommunityData('public'),
- UdpTransportTarget(('demo.snmplabs.com', 161)),
- ContextData(),
- ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysORDescr', 1),
- 'new system name'))
+iterator = setCmd(
+ SnmpEngine(),
+ CommunityData('public'),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ ContextData(),
+ ObjectType(
+ ObjectIdentity('SNMPv2-MIB', 'sysORDescr', 1),
+ 'new system name'
+ )
)
+errorIndication, errorStatus, errorIndex, varBinds = next(iterator)
+
if errorIndication:
print(errorIndication)
+
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
+
else:
for varBind in varBinds:
print(' = '.join([x.prettyPrint() for x in varBind]))
diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-asn1-mib-search-path.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-asn1-mib-search-path.py
index f25fafe4..3c279437 100644
--- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-asn1-mib-search-path.py
+++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-asn1-mib-search-path.py
@@ -17,20 +17,30 @@ Functionally similar to:
"""#
from pysnmp.hlapi import *
-errorIndication, errorStatus, errorIndex, varBinds = next(
- getCmd(SnmpEngine(),
- CommunityData('public'),
- UdpTransportTarget(('demo.snmplabs.com', 161)),
- ContextData(),
- ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets', 1).addAsn1MibSource('file:///usr/share/snmp',
- 'http://mibs.snmplabs.com/asn1/@mib@')))
+iterator = getCmd(
+ SnmpEngine(),
+ CommunityData('public'),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ ContextData(),
+ ObjectType(
+ ObjectIdentity(
+ 'IF-MIB', 'ifInOctets', 1
+ ).addAsn1MibSource(
+ 'file:///usr/share/snmp',
+ 'http://mibs.snmplabs.com/asn1/@mib@'
+ )
+ )
)
+errorIndication, errorStatus, errorIndex, varBinds = next(iterator)
+
if errorIndication:
print(errorIndication)
+
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
+
else:
for varBind in varBinds:
print(' = '.join([x.prettyPrint() for x in varBind]))
diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-contextengineid-and-contextname.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-contextengineid-and-contextname.py
index 497af602..38871cd8 100644
--- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-contextengineid-and-contextname.py
+++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-contextengineid-and-contextname.py
@@ -19,20 +19,26 @@ Functionally similar to:
"""#
from pysnmp.hlapi import *
-errorIndication, errorStatus, errorIndex, varBinds = next(
- setCmd(SnmpEngine(),
- UsmUserData('usr-md5-none', 'authkey1'),
- UdpTransportTarget(('demo.snmplabs.com', 161)),
- ContextData(contextEngineId=OctetString(hexValue='80004fb805636c6f75644dab22cc'),
- contextName='da761cfc8c94d3aceef4f60f049105ba'),
- ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysORDescr', 1), 'new system name'))
+iterator = setCmd(
+ SnmpEngine(),
+ UsmUserData('usr-md5-none', 'authkey1'),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ ContextData(
+ contextEngineId=OctetString(hexValue='80004fb805636c6f75644dab22cc'),
+ contextName='da761cfc8c94d3aceef4f60f049105ba'
+ ),
+ ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysORDescr', 1), 'new system name')
)
+errorIndication, errorStatus, errorIndex, varBinds = next(iterator)
+
if errorIndication:
print(errorIndication)
+
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
+
else:
for varBind in varBinds:
print(' = '.join([x.prettyPrint() for x in varBind]))
diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-contextengineid.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-contextengineid.py
index 6435a5d5..3f50481d 100644
--- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-contextengineid.py
+++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-contextengineid.py
@@ -18,20 +18,24 @@ Functionally similar to:
"""#
from pysnmp.hlapi import *
-errorIndication, errorStatus, errorIndex, varBinds = next(
- setCmd(SnmpEngine(),
- UsmUserData('usr-md5-des', 'authkey1', 'privkey1',
- securityEngineId=OctetString(hexValue='80004fb805636c6f75644dab22cc')),
- UdpTransportTarget(('demo.snmplabs.com', 161)),
- ContextData(),
- ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysName', 0), 'new system name'))
+iterator = setCmd(
+ SnmpEngine(),
+ UsmUserData('usr-md5-des', 'authkey1', 'privkey1',
+ securityEngineId=OctetString(hexValue='80004fb805636c6f75644dab22cc')),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ ContextData(),
+ ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysName', 0), 'new system name')
)
+errorIndication, errorStatus, errorIndex, varBinds = next(iterator)
+
if errorIndication:
print(errorIndication)
+
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
+
else:
for varBind in varBinds:
print(' = '.join([x.prettyPrint() for x in varBind]))
diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-pysnmp-mibs-search-path.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-pysnmp-mibs-search-path.py
index 26b8954a..33d72f1f 100644
--- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-pysnmp-mibs-search-path.py
+++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-pysnmp-mibs-search-path.py
@@ -19,26 +19,35 @@ Functionally similar to:
"""#
from pysnmp.hlapi import *
-for (errorIndication,
- errorStatus,
- errorIndex,
- varBinds) in bulkCmd(SnmpEngine(),
- UsmUserData('usr-none-none'),
- UdpTransportTarget(('demo.snmplabs.com', 161)),
- ContextData(),
- 0, 50,
- ObjectType(
- ObjectIdentity('TCP-MIB', 'tcpConnTable').addMibSource('/opt/mibs/pysnmp').addMibSource('python_packaged_mibs')
- ),
- lexicographicMode=False):
+iterator = bulkCmd(
+ SnmpEngine(),
+ UsmUserData('usr-none-none'),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ ContextData(),
+ 0, 50,
+ ObjectType(
+ ObjectIdentity(
+ 'TCP-MIB', 'tcpConnTable'
+ ).addMibSource(
+ '/opt/mibs/pysnmp'
+ ).addMibSource(
+ 'python_packaged_mibs'
+ )
+ ),
+ lexicographicMode=False
+)
+
+for errorIndication, errorStatus, errorIndex, varBinds in iterator:
if errorIndication:
print(errorIndication)
break
+
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
break
+
else:
for varBind in varBinds:
print(' = '.join([x.prettyPrint() for x in varBind]))
diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-timeout-and-retries.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-timeout-and-retries.py
index d70a322f..9b99693a 100644
--- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-timeout-and-retries.py
+++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-timeout-and-retries.py
@@ -30,21 +30,23 @@ Functionally similar to:
"""#
from pysnmp.hlapi import *
-errorIndication, errorStatus, errorIndex, varBinds = next(
- getCmd(SnmpEngine(),
- CommunityData('public'),
- UdpTransportTarget(
- ('demo.snmplabs.com', 161), timeout=2.0, retries=0
- ),
- ContextData(),
- ObjectType(ObjectIdentity('1.3.6.1.2.1.1.1.0')))
+iterator = getCmd(
+ SnmpEngine(),
+ CommunityData('public'),
+ UdpTransportTarget(('demo.snmplabs.com', 161), timeout=2.0, retries=0),
+ ContextData(),
+ ObjectType(ObjectIdentity('1.3.6.1.2.1.1.1.0'))
)
+errorIndication, errorStatus, errorIndex, varBinds = next(iterator)
+
if errorIndication:
print(errorIndication)
+
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
+
else:
for varBind in varBinds:
print(' = '.join([x.prettyPrint() for x in varBind]))
diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-v3-security-name.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-v3-security-name.py
index 8e541f7b..cadc2c3c 100644
--- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-v3-security-name.py
+++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-v3-security-name.py
@@ -17,19 +17,23 @@ usmUserTable, thus duplicate securityName parameters are possible.
"""#
from pysnmp.hlapi import *
-errorIndication, errorStatus, errorIndex, varBinds = next(
- getCmd(SnmpEngine(),
- UsmUserData('usr-md5-none', 'authkey1', securityName='myuser'),
- UdpTransportTarget(('demo.snmplabs.com', 161)),
- ContextData(),
- ObjectType(ObjectIdentity('1.3.6.1.2.1.1.1.0')))
+iterator = getCmd(
+ SnmpEngine(),
+ UsmUserData('usr-md5-none', 'authkey1', securityName='myuser'),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ ContextData(),
+ ObjectType(ObjectIdentity('1.3.6.1.2.1.1.1.0'))
)
+errorIndication, errorStatus, errorIndex, varBinds = next(iterator)
+
if errorIndication:
print(errorIndication)
+
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
+
else:
for varBind in varBinds:
print(' = '.join([x.prettyPrint() for x in varBind]))
diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/fetch-variables-over-ipv6.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/fetch-variables-over-ipv6.py
index 9bc76446..9b8f3382 100644
--- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/fetch-variables-over-ipv6.py
+++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/fetch-variables-over-ipv6.py
@@ -15,21 +15,25 @@ Functionally similar to:
"""#
from pysnmp.hlapi import *
-errorIndication, errorStatus, errorIndex, varBinds = next(
- getCmd(SnmpEngine(),
- UsmUserData('usr-md5-des', 'authkey1', 'privkey1'),
- Udp6TransportTarget(('::1', 161)),
- ContextData(),
- ObjectType(ObjectIdentity('1.3.6.1.2.1.1.1.0')),
- ObjectType(ObjectIdentity('1.3.6.1.2.1.1.2.0')),
- ObjectType(ObjectIdentity('1.3.6.1.2.1.1.3.0')))
+iterator = getCmd(
+ SnmpEngine(),
+ UsmUserData('usr-md5-des', 'authkey1', 'privkey1'),
+ Udp6TransportTarget(('::1', 161)),
+ ContextData(),
+ ObjectType(ObjectIdentity('1.3.6.1.2.1.1.1.0')),
+ ObjectType(ObjectIdentity('1.3.6.1.2.1.1.2.0')),
+ ObjectType(ObjectIdentity('1.3.6.1.2.1.1.3.0'))
)
+errorIndication, errorStatus, errorIndex, varBinds = next(iterator)
+
if errorIndication:
print(errorIndication)
+
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
+
else:
for varBind in varBinds:
print(' = '.join([x.prettyPrint() for x in varBind]))
diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/get-table-object-by-index.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/get-table-object-by-index.py
index ed5d8351..253b9224 100644
--- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/get-table-object-by-index.py
+++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/get-table-object-by-index.py
@@ -17,20 +17,24 @@ Functionally similar to:
"""#
from pysnmp.hlapi import *
-errorIndication, errorStatus, errorIndex, varBinds = next(
- getCmd(SnmpEngine(),
- UsmUserData('usr-none-none'),
- UdpTransportTarget(('demo.snmplabs.com', 161)),
- ContextData(),
- ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets', 1)),
- ObjectType(ObjectIdentity('IF-MIB', 'ifOutOctets', 1)))
+iterator = getCmd(
+ SnmpEngine(),
+ UsmUserData('usr-none-none'),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ ContextData(),
+ ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets', 1)),
+ ObjectType(ObjectIdentity('IF-MIB', 'ifOutOctets', 1))
)
+errorIndication, errorStatus, errorIndex, varBinds = next(iterator)
+
if errorIndication:
print(errorIndication)
+
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
+
else:
for varBind in varBinds:
print(' = '.join([x.prettyPrint() for x in varBind]))
diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/get-table-object-by-multiple-indices.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/get-table-object-by-multiple-indices.py
index 06302525..733bd9cb 100644
--- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/get-table-object-by-multiple-indices.py
+++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/get-table-object-by-multiple-indices.py
@@ -16,24 +16,34 @@ Functionally similar to:
"""#
from pysnmp.hlapi import *
-errorIndication, errorStatus, errorIndex, varBinds = next(
- getCmd(SnmpEngine(),
- UsmUserData('usr-sha-aes128', 'authkey1', 'privkey1',
- authProtocol=USM_AUTH_HMAC96_SHA,
- privProtocol=USM_PRIV_CFB128_AES),
- UdpTransportTarget(('demo.snmplabs.com', 161)),
- ContextData(),
- ObjectType(ObjectIdentity('TCP-MIB',
- 'tcpConnLocalAddress',
- '0.0.0.0', 22,
- '0.0.0.0', 0)))
+iterator = getCmd(
+ SnmpEngine(),
+ UsmUserData(
+ 'usr-sha-aes128', 'authkey1', 'privkey1',
+ authProtocol=USM_AUTH_HMAC96_SHA,
+ privProtocol=USM_PRIV_CFB128_AES
+ ),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ ContextData(),
+ ObjectType(
+ ObjectIdentity(
+ 'TCP-MIB',
+ 'tcpConnLocalAddress',
+ '0.0.0.0', 22,
+ '0.0.0.0', 0
+ )
+ )
)
+errorIndication, errorStatus, errorIndex, varBinds = next(iterator)
+
if errorIndication:
print(errorIndication)
+
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
+
else:
for varBind in varBinds:
print(' = '.join([x.prettyPrint() for x in varBind]))
diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getbulk-fetch-scalar-and-table-variables-over-ipv6.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getbulk-fetch-scalar-and-table-variables-over-ipv6.py
index 499c9b02..261e46f9 100644
--- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getbulk-fetch-scalar-and-table-variables-over-ipv6.py
+++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getbulk-fetch-scalar-and-table-variables-over-ipv6.py
@@ -18,25 +18,28 @@ Functionally similar to:
"""#
from pysnmp.hlapi import *
-for (errorIndication,
- errorStatus,
- errorIndex,
- varBinds) in bulkCmd(SnmpEngine(),
- UsmUserData('usr-md5-des', 'authkey1', 'privkey1'),
- Udp6TransportTarget(('::1', 161)),
- ContextData(),
- 1, 25,
- ObjectType(ObjectIdentity('IP-MIB', 'ipAdEntAddr')),
- ObjectType(ObjectIdentity('IP-MIB', 'ipAddrEntry')),
- lexicographicMode=False):
+iterator = bulkCmd(
+ SnmpEngine(),
+ UsmUserData('usr-md5-des', 'authkey1', 'privkey1'),
+ Udp6TransportTarget(('::1', 161)),
+ ContextData(),
+ 1, 25,
+ ObjectType(ObjectIdentity('IP-MIB', 'ipAdEntAddr')),
+ ObjectType(ObjectIdentity('IP-MIB', 'ipAddrEntry')),
+ lexicographicMode=False
+)
+
+for errorIndication, errorStatus, errorIndex, varBinds in iterator:
if errorIndication:
print(errorIndication)
break
+
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
break
+
else:
for varBind in varBinds:
print(' = '.join([x.prettyPrint() for x in varBind]))
diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getbulk-limit-number-of-packets.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getbulk-limit-number-of-packets.py
index dd94650c..ce114002 100644
--- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getbulk-limit-number-of-packets.py
+++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getbulk-limit-number-of-packets.py
@@ -18,24 +18,27 @@ Functionally similar to:
"""#
from pysnmp.hlapi import *
-for (errorIndication,
- errorStatus,
- errorIndex,
- varBinds) in bulkCmd(SnmpEngine(),
- UsmUserData('usr-none-none'),
- UdpTransportTarget(('demo.snmplabs.com', 161)),
- ContextData(),
- 0, 50,
- ObjectType(ObjectIdentity('SNMPv2-MIB', 'system')),
- maxCalls=10):
+iterator = bulkCmd(
+ SnmpEngine(),
+ UsmUserData('usr-none-none'),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ ContextData(),
+ 0, 50,
+ ObjectType(ObjectIdentity('SNMPv2-MIB', 'system')),
+ maxCalls=10
+)
+
+for errorIndication, errorStatus, errorIndex, varBinds in iterator:
if errorIndication:
print(errorIndication)
break
+
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
break
+
else:
for varBind in varBinds:
print(' = '.join([x.prettyPrint() for x in varBind]))
diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getbulk-limit-number-of-variables.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getbulk-limit-number-of-variables.py
index fa39086b..c0c355c5 100644
--- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getbulk-limit-number-of-variables.py
+++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getbulk-limit-number-of-variables.py
@@ -19,25 +19,28 @@ Functionally similar to:
"""#
from pysnmp.hlapi import *
-for (errorIndication,
- errorStatus,
- errorIndex,
- varBinds) in bulkCmd(SnmpEngine(),
- CommunityData('public'),
- UdpTransportTarget(('demo.snmplabs.com', 161)),
- ContextData(),
- 0, 25,
- ObjectType(ObjectIdentity('1.3.6.1.2.1.2.2')),
- ObjectType(ObjectIdentity('1.3.6.1.2.1.2.3')),
- lexicographicMode=False, maxRows=20):
+iterator = bulkCmd(
+ SnmpEngine(),
+ CommunityData('public'),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ ContextData(),
+ 0, 25,
+ ObjectType(ObjectIdentity('1.3.6.1.2.1.2.2')),
+ ObjectType(ObjectIdentity('1.3.6.1.2.1.2.3')),
+ lexicographicMode=False, maxRows=20
+)
+
+for errorIndication, errorStatus, errorIndex, varBinds in iterator:
if errorIndication:
print(errorIndication)
break
+
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex)-1][0] or '?'))
break
+
else:
for varBind in varBinds:
print(' = '.join([ x.prettyPrint() for x in varBind ]))
diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getnext-limit-number-of-variables.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getnext-limit-number-of-variables.py
index d8a2b935..950e9db6 100644
--- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getnext-limit-number-of-variables.py
+++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getnext-limit-number-of-variables.py
@@ -18,25 +18,30 @@ Functionally similar to:
"""#
from pysnmp.hlapi import *
-for (errorIndication,
- errorStatus,
- errorIndex,
- varBinds) in nextCmd(SnmpEngine(),
- UsmUserData('usr-sha-aes128', 'authkey1', 'privkey1',
- authProtocol=USM_AUTH_HMAC96_SHA,
- privProtocol=USM_PRIV_CFB128_AES),
- UdpTransportTarget(('demo.snmplabs.com', 161)),
- ContextData(),
- ObjectType(ObjectIdentity('SNMPv2-MIB')),
- maxRows=100, ignoreNonIncreasingOid=True):
+iterator = nextCmd(
+ SnmpEngine(),
+ UsmUserData(
+ 'usr-sha-aes128', 'authkey1', 'privkey1',
+ authProtocol=USM_AUTH_HMAC96_SHA,
+ privProtocol=USM_PRIV_CFB128_AES
+ ),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ ContextData(),
+ ObjectType(ObjectIdentity('SNMPv2-MIB')),
+ maxRows=100, ignoreNonIncreasingOid=True
+)
+
+for errorIndication, errorStatus, errorIndex, varBinds in iterator:
if errorIndication:
print(errorIndication)
break
+
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
break
+
else:
for varBind in varBinds:
print(' = '.join([x.prettyPrint() for x in varBind]))
diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getnext-multiple-oids-to-eom.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getnext-multiple-oids-to-eom.py
index 863ceb6f..0008f4bc 100644
--- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getnext-multiple-oids-to-eom.py
+++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getnext-multiple-oids-to-eom.py
@@ -17,24 +17,27 @@ Functionally similar to:
"""#
from pysnmp.hlapi import *
-for (errorIndication,
- errorStatus,
- errorIndex,
- varBinds) in nextCmd(SnmpEngine(),
- CommunityData('public'),
- UdpTransportTarget(('demo.snmplabs.com', 161)),
- ContextData(),
- ObjectType(ObjectIdentity('1.3.6.1.2.1.2.2.1.2')),
- ObjectType(ObjectIdentity('1.3.6.1.2.1.2.2.1.3')),
- lexicographicMode=False):
+iterator = nextCmd(
+ SnmpEngine(),
+ CommunityData('public'),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ ContextData(),
+ ObjectType(ObjectIdentity('1.3.6.1.2.1.2.2.1.2')),
+ ObjectType(ObjectIdentity('1.3.6.1.2.1.2.2.1.3')),
+ lexicographicMode=False
+)
+
+for errorIndication, errorStatus, errorIndex, varBinds in iterator:
if errorIndication:
print(errorIndication)
break
+
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex)-1][0] or '?'))
break
+
else:
for varBind in varBinds:
print(' = '.join([ x.prettyPrint() for x in varBind ]))
diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/multiple-get-calls.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/multiple-get-calls.py
index d883d16a..b69f1c6b 100644
--- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/multiple-get-calls.py
+++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/multiple-get-calls.py
@@ -25,20 +25,25 @@ from pysnmp.hlapi import *
queue = [[ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets', 1))],
[ObjectType(ObjectIdentity('IF-MIB', 'ifOutOctets', 1))]]
-iterator = getCmd(SnmpEngine(),
- UsmUserData('usr-md5-none', 'authkey1'),
- UdpTransportTarget(('demo.snmplabs.com', 161)),
- ContextData())
+iterator = getCmd(
+ SnmpEngine(),
+ UsmUserData('usr-md5-none', 'authkey1'),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ ContextData()
+)
next(iterator)
while queue:
errorIndication, errorStatus, errorIndex, varBinds = iterator.send(queue.pop())
+
if errorIndication:
print(errorIndication)
+
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
+
else:
for varBind in varBinds:
print(' = '.join([x.prettyPrint() for x in varBind]))
diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/preload-pysnmp-mibs.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/preload-pysnmp-mibs.py
index a9bb2bb3..ed752999 100644
--- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/preload-pysnmp-mibs.py
+++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/preload-pysnmp-mibs.py
@@ -17,22 +17,25 @@ Functionally similar to:
"""#
from pysnmp.hlapi import *
-for (errorIndication,
- errorStatus,
- errorIndex,
- varBinds) in nextCmd(SnmpEngine(),
- UsmUserData('usr-md5-des', 'authkey1', 'privkey1'),
- UdpTransportTarget(('demo.snmplabs.com', 161)),
- ContextData(),
- ObjectType(ObjectIdentity('1.3.6').loadMibs())):
+iterator = nextCmd(
+ SnmpEngine(),
+ UsmUserData('usr-md5-des', 'authkey1', 'privkey1'),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ ContextData(),
+ ObjectType(ObjectIdentity('1.3.6').loadMibs())
+)
+
+for errorIndication, errorStatus, errorIndex, varBinds in iterator:
if errorIndication:
print(errorIndication)
break
+
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
break
+
else:
for varBind in varBinds:
print(' = '.join([x.prettyPrint() for x in varBind]))
diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/pull-whole-mib.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/pull-whole-mib.py
index b9103de3..2ac2b318 100644
--- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/pull-whole-mib.py
+++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/pull-whole-mib.py
@@ -16,22 +16,25 @@ Functionally similar to:
"""#
from pysnmp.hlapi import *
-for (errorIndication,
- errorStatus,
- errorIndex,
- varBinds) in nextCmd(SnmpEngine(),
- UsmUserData('usr-md5-none', 'authkey1'),
- UdpTransportTarget(('demo.snmplabs.com', 161)),
- ContextData(),
- ObjectType(ObjectIdentity('IF-MIB'))):
+iterator = nextCmd(
+ SnmpEngine(),
+ UsmUserData('usr-md5-none', 'authkey1'),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ ContextData(),
+ ObjectType(ObjectIdentity('IF-MIB'))
+)
+
+for errorIndication, errorStatus, errorIndex, varBinds in iterator:
if errorIndication:
print(errorIndication)
break
+
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
break
+
else:
for varBind in varBinds:
print(' = '.join([x.prettyPrint() for x in varBind]))
diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/pull-whole-snmp-table.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/pull-whole-snmp-table.py
index 91a71a61..260102a5 100644
--- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/pull-whole-snmp-table.py
+++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/pull-whole-snmp-table.py
@@ -17,28 +17,31 @@ Functionally similar to:
"""#
from pysnmp.hlapi import *
-for (errorIndication,
- errorStatus,
- errorIndex,
- varBinds) in nextCmd(SnmpEngine(),
- CommunityData('public', mpModel=0),
- UdpTransportTarget(('demo.snmplabs.com', 161)),
- ContextData(),
- ObjectType(ObjectIdentity('IF-MIB', 'ifDescr')),
- ObjectType(ObjectIdentity('IF-MIB', 'ifType')),
- ObjectType(ObjectIdentity('IF-MIB', 'ifMtu')),
- ObjectType(ObjectIdentity('IF-MIB', 'ifSpeed')),
- ObjectType(ObjectIdentity('IF-MIB', 'ifPhysAddress')),
- ObjectType(ObjectIdentity('IF-MIB', 'ifType')),
- lexicographicMode=False):
+iterator = nextCmd(
+ SnmpEngine(),
+ CommunityData('public', mpModel=0),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ ContextData(),
+ ObjectType(ObjectIdentity('IF-MIB', 'ifDescr')),
+ ObjectType(ObjectIdentity('IF-MIB', 'ifType')),
+ ObjectType(ObjectIdentity('IF-MIB', 'ifMtu')),
+ ObjectType(ObjectIdentity('IF-MIB', 'ifSpeed')),
+ ObjectType(ObjectIdentity('IF-MIB', 'ifPhysAddress')),
+ ObjectType(ObjectIdentity('IF-MIB', 'ifType')),
+ lexicographicMode=False
+)
+
+for errorIndication, errorStatus, errorIndex, varBinds in iterator:
if errorIndication:
print(errorIndication)
break
+
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex)-1][0] or '?'))
break
+
else:
for varBind in varBinds:
print(' = '.join([x.prettyPrint() for x in varBind]))
diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/query-agents-from-multuple-threads-over-ipv4-and-ipv6.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/query-agents-from-multuple-threads-over-ipv4-and-ipv6.py
index 16995ed8..049e1be1 100644
--- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/query-agents-from-multuple-threads-over-ipv4-and-ipv6.py
+++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/query-agents-from-multuple-threads-over-ipv4-and-ipv6.py
@@ -27,39 +27,45 @@ else:
# List of targets in the following format:
# ( ( authData, transportTarget, varNames ), ... )
-targets = (
+TARGETS = (
# 1-st target (SNMPv1 over IPv4/UDP)
(CommunityData('public', mpModel=0),
UdpTransportTarget(('demo.snmplabs.com', 161)),
(ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)),
ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0)))),
+
# 2-nd target (SNMPv2c over IPv4/UDP)
(CommunityData('public'),
UdpTransportTarget(('demo.snmplabs.com', 161)),
(ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)),
ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0)))),
- # 3-nd target (SNMPv2c over IPv4/UDP) - same community and
+
+ # 3-nd target (SNMPv2c over IPv4/UDP) - same community and
# different transport address.
(CommunityData('public'),
UdpTransportTarget(('localhost', 161)),
(ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysContact', 0)),
ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysName', 0)))),
+
# 4-nd target (SNMPv3 over IPv4/UDP)
(UsmUserData('usr-md5-des', 'authkey1', 'privkey1'),
UdpTransportTarget(('demo.snmplabs.com', 161)),
(ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)),
ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0)))),
+
# 5-th target (SNMPv3 over IPv6/UDP)
(UsmUserData('usr-md5-none', 'authkey1'),
Udp6TransportTarget(('::1', 161)),
(ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)),
ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0)))),
+
# N-th target
# ...
)
class Worker(Thread):
+
def __init__(self, requests, responses):
Thread.__init__(self)
self.snmpEngine = SnmpEngine()
@@ -71,15 +77,17 @@ class Worker(Thread):
def run(self):
while True:
authData, transportTarget, varBinds = self.requests.get()
+
self.responses.append(
next(getCmd(self.snmpEngine,
authData, transportTarget, ContextData(), *varBinds))
)
- if hasattr(self.requests, 'task_done'): # 2.5+
- self.requests.task_done()
+
+ self.requests.task_done()
class ThreadPool(object):
+
def __init__(self, num_threads):
self.requests = Queue(num_threads)
self.responses = []
@@ -106,7 +114,7 @@ class ThreadPool(object):
pool = ThreadPool(3)
# Submit GET requests
-for authData, transportTarget, varBinds in targets:
+for authData, transportTarget, varBinds in TARGETS:
pool.addRequest(authData, transportTarget, varBinds)
# Wait for responses or errors
@@ -114,11 +122,14 @@ pool.waitCompletion()
# Walk through responses
for errorIndication, errorStatus, errorIndex, varBinds in pool.getResponses():
+
if errorIndication:
print(errorIndication)
+
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
+
else:
for varBind in varBinds:
print(' = '.join([x.prettyPrint() for x in varBind]))
diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/set-multiple-scalar-values.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/set-multiple-scalar-values.py
index be4ffeab..a5eeb1a3 100644
--- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/set-multiple-scalar-values.py
+++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/set-multiple-scalar-values.py
@@ -20,24 +20,34 @@ Functionally similar to:
"""#
from pysnmp.hlapi import *
-errorIndication, errorStatus, errorIndex, varBinds = next(
- setCmd(SnmpEngine(),
- CommunityData('public', mpModel=0),
- UdpTransportTarget(('demo.snmplabs.com', 161)),
- ContextData(),
- ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysORID', 1),
- ObjectIdentifier('1.3.6.1.4.1.20408.1.1')),
- ObjectType(ObjectIdentity('1.3.6.1.2.1.1.9.1.2.1'),
- '1.3.6.1.4.1.20408.1.1'),
- ObjectType(ObjectIdentity('1.3.6.1.2.1.1.9.1.3.1'),
- OctetString('new system name')))
+iterator = setCmd(
+ SnmpEngine(),
+ CommunityData('public', mpModel=0),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ ContextData(),
+ ObjectType(
+ ObjectIdentity('SNMPv2-MIB', 'sysORID', 1),
+ ObjectIdentifier('1.3.6.1.4.1.20408.1.1')
+ ),
+ ObjectType(
+ ObjectIdentity('1.3.6.1.2.1.1.9.1.2.1'),
+ '1.3.6.1.4.1.20408.1.1'
+ ),
+ ObjectType(
+ ObjectIdentity('1.3.6.1.2.1.1.9.1.3.1'),
+ OctetString('new system name')
+ )
)
+errorIndication, errorStatus, errorIndex, varBinds = next(iterator)
+
if errorIndication:
print(errorIndication)
+
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
+
else:
for varBind in varBinds:
print(' = '.join([x.prettyPrint() for x in varBind]))
diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/specific-v3-engine-id.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/specific-v3-engine-id.py
index 94f591c4..36cfc050 100644
--- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/specific-v3-engine-id.py
+++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/specific-v3-engine-id.py
@@ -65,19 +65,23 @@ print('Remote securityEngineId = %s' % securityEngineId.prettyPrint())
authData = UsmUserData('usr-md5-none', 'authkey1',
securityEngineId=securityEngineId)
-errorIndication, errorStatus, errorIndex, varBinds = next(
- getCmd(snmpEngine,
- authData,
- transportTarget,
- ContextData(),
- ObjectType(ObjectIdentity('1.3.6.1.2.1.1.1.0')))
+iterator = getCmd(
+ snmpEngine,
+ authData,
+ transportTarget,
+ ContextData(),
+ ObjectType(ObjectIdentity('1.3.6.1.2.1.1.1.0'))
)
+errorIndication, errorStatus, errorIndex, varBinds = next(iterator)
+
if errorIndication:
print(errorIndication)
+
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
+
else:
for name, val in varBinds:
print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-md5-des.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-md5-des.py
index 27c0e7fb..6254418c 100644
--- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-md5-des.py
+++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-md5-des.py
@@ -16,19 +16,23 @@ Functionally similar to:
"""#
from pysnmp.hlapi import *
-errorIndication, errorStatus, errorIndex, varBinds = next(
- getCmd(SnmpEngine(),
- UsmUserData('usr-md5-des', 'authkey1', 'privkey1'),
- UdpTransportTarget(('demo.snmplabs.com', 161)),
- ContextData(),
- ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets', 1)))
+iterator = getCmd(
+ SnmpEngine(),
+ UsmUserData('usr-md5-des', 'authkey1', 'privkey1'),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ ContextData(),
+ ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets', 1))
)
+errorIndication, errorStatus, errorIndex, varBinds = next(iterator)
+
if errorIndication:
print(errorIndication)
+
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
+
else:
for varBind in varBinds:
print(' = '.join([x.prettyPrint() for x in varBind]))
diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-md5-none.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-md5-none.py
index f06964e2..724910b5 100644
--- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-md5-none.py
+++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-md5-none.py
@@ -16,19 +16,23 @@ Functionally similar to:
"""#
from pysnmp.hlapi import *
-errorIndication, errorStatus, errorIndex, varBinds = next(
- getCmd(SnmpEngine(),
- UsmUserData('usr-md5-none', 'authkey1'),
- UdpTransportTarget(('demo.snmplabs.com', 161)),
- ContextData(),
- ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets', 1)))
+iterator = getCmd(
+ SnmpEngine(),
+ UsmUserData('usr-md5-none', 'authkey1'),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ ContextData(),
+ ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets', 1))
)
+errorIndication, errorStatus, errorIndex, varBinds = next(iterator)
+
if errorIndication:
print(errorIndication)
+
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
+
else:
for varBind in varBinds:
print(' = '.join([x.prettyPrint() for x in varBind]))
diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-none-none.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-none-none.py
index 940d8817..8a558920 100644
--- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-none-none.py
+++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-none-none.py
@@ -16,18 +16,22 @@ Functionally similar to:
"""#
from pysnmp.hlapi import *
-errorIndication, errorStatus, errorIndex, varBinds = next(
- getCmd(SnmpEngine(),
- UsmUserData('usr-none-none'),
- UdpTransportTarget(('demo.snmplabs.com', 161)),
- ContextData(),
- ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets', 1)))
+iterator = getCmd(
+ SnmpEngine(),
+ UsmUserData('usr-none-none'),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ ContextData(),
+ ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets', 1))
)
+errorIndication, errorStatus, errorIndex, varBinds = next(iterator)
+
if errorIndication:
print(errorIndication)
+
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(), errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
+
else:
for varBind in varBinds:
print(' = '.join([x.prettyPrint() for x in varBind]))
diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-sha-aes128.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-sha-aes128.py
index 69262086..e30e8239 100644
--- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-sha-aes128.py
+++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-sha-aes128.py
@@ -35,21 +35,25 @@ Functionally similar to:
"""#
from pysnmp.hlapi import *
-errorIndication, errorStatus, errorIndex, varBinds = next(
- getCmd(SnmpEngine(),
- UsmUserData('usr-sha-aes', 'authkey1', 'privkey1',
- authProtocol=USM_AUTH_HMAC96_SHA,
- privProtocol=USM_PRIV_CFB128_AES),
- UdpTransportTarget(('demo.snmplabs.com', 161)),
- ContextData(),
- ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)))
+iterator = getCmd(
+ SnmpEngine(),
+ UsmUserData('usr-sha-aes', 'authkey1', 'privkey1',
+ authProtocol=USM_AUTH_HMAC96_SHA,
+ privProtocol=USM_PRIV_CFB128_AES),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ ContextData(),
+ ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0))
)
+errorIndication, errorStatus, errorIndex, varBinds = next(iterator)
+
if errorIndication:
print(errorIndication)
+
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
+
else:
for varBind in varBinds:
print(' = '.join([x.prettyPrint() for x in varBind]))
diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/v1-get.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/v1-get.py
index 1b272967..55c49735 100644
--- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/v1-get.py
+++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/v1-get.py
@@ -16,19 +16,23 @@ Functionally similar to:
"""#
from pysnmp.hlapi import *
-errorIndication, errorStatus, errorIndex, varBinds = next(
- getCmd(SnmpEngine(),
- CommunityData('public', mpModel=0),
- UdpTransportTarget(('demo.snmplabs.com', 161)),
- ContextData(),
- ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)))
+iterator = getCmd(
+ SnmpEngine(),
+ CommunityData('public', mpModel=0),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ ContextData(),
+ ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0))
)
+errorIndication, errorStatus, errorIndex, varBinds = next(iterator)
+
if errorIndication:
print(errorIndication)
+
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
+
else:
for varBind in varBinds:
print(' = '.join([x.prettyPrint() for x in varBind]))
diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/v2c-get.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/v2c-get.py
index 606bab5b..d7676e32 100644
--- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/v2c-get.py
+++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/v2c-get.py
@@ -16,20 +16,24 @@ Functionally similar to:
"""#
from pysnmp.hlapi import *
-errorIndication, errorStatus, errorIndex, varBinds = next(
- getCmd(SnmpEngine(),
- CommunityData('public'),
- UdpTransportTarget(('demo.snmplabs.com', 161)),
- ContextData(),
- ObjectType(ObjectIdentity('1.3.6.1.2.1.1.1.0')),
- ObjectType(ObjectIdentity('1.3.6.1.2.1.1.6.0')))
+iterator = getCmd(
+ SnmpEngine(),
+ CommunityData('public'),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ ContextData(),
+ ObjectType(ObjectIdentity('1.3.6.1.2.1.1.1.0')),
+ ObjectType(ObjectIdentity('1.3.6.1.2.1.1.6.0'))
)
+errorIndication, errorStatus, errorIndex, varBinds = next(iterator)
+
if errorIndication:
print(errorIndication)
+
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
+
else:
for varBind in varBinds:
print(' = '.join([x.prettyPrint() for x in varBind]))
diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/v2c-getbulk.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/v2c-getbulk.py
index 47715195..15f684f5 100644
--- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/v2c-getbulk.py
+++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/v2c-getbulk.py
@@ -18,25 +18,28 @@ Functionally similar to:
"""#
from pysnmp.hlapi import *
-for (errorIndication,
- errorStatus,
- errorIndex,
- varBinds) in bulkCmd(SnmpEngine(),
- CommunityData('public'),
- UdpTransportTarget(('demo.snmplabs.com', 161)),
- ContextData(),
- 0, 25,
- ObjectType(ObjectIdentity('1.3.6.1.2.1.2.2')),
- ObjectType(ObjectIdentity('1.3.6.1.2.1.2.3')),
- lexicographicMode=False):
+iterator = bulkCmd(
+ SnmpEngine(),
+ CommunityData('public'),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ ContextData(),
+ 0, 25,
+ ObjectType(ObjectIdentity('1.3.6.1.2.1.2.2')),
+ ObjectType(ObjectIdentity('1.3.6.1.2.1.2.3')),
+ lexicographicMode=False
+)
+
+for errorIndication, errorStatus, errorIndex, varBinds in iterator:
if errorIndication:
print(errorIndication)
break
+
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
break
+
else:
for varBind in varBinds:
print(' = '.join([x.prettyPrint() for x in varBind]))
diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/waive-mib-lookup.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/waive-mib-lookup.py
index f44d160b..c22d7b19 100644
--- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/waive-mib-lookup.py
+++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/waive-mib-lookup.py
@@ -20,23 +20,26 @@ Functionally similar to:
"""#
from pysnmp.hlapi import *
-for (errorIndication,
- errorStatus,
- errorIndex,
- varBinds) in nextCmd(SnmpEngine(),
- CommunityData('public'),
- UdpTransportTarget(('demo.snmplabs.com', 161)),
- ContextData(),
- ObjectType(ObjectIdentity('1.3.6.1.2.1.1')),
- lookupMib=False):
+iterator = nextCmd(
+ SnmpEngine(),
+ CommunityData('public'),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ ContextData(),
+ ObjectType(ObjectIdentity('1.3.6.1.2.1.1')),
+ lookupMib=False
+)
+
+for errorIndication, errorStatus, errorIndex, varBinds in iterator:
if errorIndication:
print(errorIndication)
break
+
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
break
+
else:
for varBind in varBinds:
print(' = '.join([x.prettyPrint() for x in varBind]))
diff --git a/examples/hlapi/v3arch/trollius/agent/ntforg/default-v1-trap.py b/examples/hlapi/v3arch/trollius/agent/ntforg/default-v1-trap.py
index 64e61b1d..1e74aa55 100644
--- a/examples/hlapi/v3arch/trollius/agent/ntforg/default-v1-trap.py
+++ b/examples/hlapi/v3arch/trollius/agent/ntforg/default-v1-trap.py
@@ -28,32 +28,33 @@ from pysnmp.hlapi.v3arch.asyncio import *
@trollius.coroutine
def run():
snmpEngine = SnmpEngine()
- (errorIndication,
- errorStatus,
- errorIndex,
- varBinds) = yield trollius.From(
- sendNotification(
- snmpEngine,
- CommunityData('public'), # mpModel=0),
- UdpTransportTarget(('demo.snmplabs.com', 162)),
- ContextData(),
- 'inform',
- NotificationType(
- ObjectIdentity('1.3.6.1.6.3.1.1.5.2')
- ).loadMibs(
- 'SNMPv2-MIB'
- ).addVarBinds(
- ('1.3.6.1.6.3.1.1.4.3.0', '1.3.6.1.4.1.20408.4.1.1.2'),
- ('1.3.6.1.2.1.1.1.0', OctetString('my system'))
- )
+
+ iterator = sendNotification(
+ snmpEngine,
+ CommunityData('public'), # mpModel=0),
+ UdpTransportTarget(('demo.snmplabs.com', 162)),
+ ContextData(),
+ 'inform',
+ NotificationType(
+ ObjectIdentity('1.3.6.1.6.3.1.1.5.2')
+ ).loadMibs(
+ 'SNMPv2-MIB'
+ ).addVarBinds(
+ ('1.3.6.1.6.3.1.1.4.3.0', '1.3.6.1.4.1.20408.4.1.1.2'),
+ ('1.3.6.1.2.1.1.1.0', OctetString('my system'))
)
)
+ (errorIndication, errorStatus,
+ errorIndex, varBinds) = yield trollius.From(iterator)
+
if errorIndication:
print(errorIndication)
+
elif errorStatus:
print('%s: at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
+
else:
for varBind in varBinds:
print(' = '.join([x.prettyPrint() for x in varBind]))
diff --git a/examples/hlapi/v3arch/trollius/manager/cmdgen/getbulk-to-eom.py b/examples/hlapi/v3arch/trollius/manager/cmdgen/getbulk-to-eom.py
index f084e398..50a77395 100644
--- a/examples/hlapi/v3arch/trollius/manager/cmdgen/getbulk-to-eom.py
+++ b/examples/hlapi/v3arch/trollius/manager/cmdgen/getbulk-to-eom.py
@@ -22,32 +22,38 @@ from pysnmp.hlapi.v3arch.asyncio import *
@trollius.coroutine
def run(varBinds):
+
snmpEngine = SnmpEngine()
+
while True:
- (errorIndication,
- errorStatus,
- errorIndex,
- varBindTable) = yield trollius.From(
- bulkCmd(snmpEngine,
- UsmUserData('usr-none-none'),
- UdpTransportTarget(('demo.snmplabs.com', 161)),
- ContextData(),
- 0, 50,
- *varBinds)
+
+ iterator = bulkCmd(
+ snmpEngine,
+ UsmUserData('usr-none-none'),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ ContextData(),
+ 0, 50,
+ *varBinds
)
+ (errorIndication, errorStatus,
+ errorIndex, varBindTable) = yield trollius.From(iterator)
+
if errorIndication:
print(errorIndication)
break
+
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
+
else:
for varBindRow in varBindTable:
for varBind in varBindRow:
print(' = '.join([x.prettyPrint() for x in varBind]))
varBinds = varBindTable[-1]
+
if isEndOfMib(varBinds):
break
diff --git a/examples/hlapi/v3arch/trollius/manager/cmdgen/v1-get.py b/examples/hlapi/v3arch/trollius/manager/cmdgen/v1-get.py
index 771e48c6..1e17f34e 100644
--- a/examples/hlapi/v3arch/trollius/manager/cmdgen/v1-get.py
+++ b/examples/hlapi/v3arch/trollius/manager/cmdgen/v1-get.py
@@ -21,23 +21,27 @@ from pysnmp.hlapi.v3arch.asyncio import *
@trollius.coroutine
def run():
+
snmpEngine = SnmpEngine()
- (errorIndication,
- errorStatus,
- errorIndex,
- varBinds) = yield trollius.From(
- getCmd(snmpEngine,
- CommunityData('public', mpModel=0),
- UdpTransportTarget(('demo.snmplabs.com', 161)),
- ContextData(),
- ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)))
+
+ iterator = getCmd(
+ snmpEngine,
+ CommunityData('public', mpModel=0),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ ContextData(),
+ ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0))
)
+ (errorIndication, errorStatus,
+ errorIndex, varBinds) = yield trollius.From(iterator)
+
if errorIndication:
print(errorIndication)
+
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
+
else:
for varBind in varBinds:
print(' = '.join([x.prettyPrint() for x in varBind]))
diff --git a/examples/hlapi/v3arch/twisted/agent/ntforg/default-v1-trap.py b/examples/hlapi/v3arch/twisted/agent/ntforg/default-v1-trap.py
index 756ce58d..bf409536 100644
--- a/examples/hlapi/v3arch/twisted/agent/ntforg/default-v1-trap.py
+++ b/examples/hlapi/v3arch/twisted/agent/ntforg/default-v1-trap.py
@@ -25,7 +25,7 @@ from pysnmp.hlapi.v3arch.twisted import *
def success(args, hostname):
- (errorStatus, errorIndex, varBinds) = args
+ errorStatus, errorIndex, varBinds = args
if errorStatus:
print('%s: %s at %s' % (
@@ -34,6 +34,7 @@ def success(args, hostname):
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'
)
)
+
else:
for varBind in varBinds:
print(' = '.join([x.prettyPrint() for x in varBind]))
@@ -45,7 +46,8 @@ def failure(errorIndication, hostname):
# noinspection PyUnusedLocal
def run(reactor, hostname):
- d = sendNotification(
+
+ deferred = sendNotification(
SnmpEngine(),
CommunityData('public', mpModel=0),
UdpTransportTarget((hostname, 162)),
@@ -60,8 +62,10 @@ def run(reactor, hostname):
('1.3.6.1.2.1.1.1.0', OctetString('my system'))
)
)
- d.addCallback(success, hostname).addErrback(failure, hostname)
- return d
+
+ deferred.addCallback(success, hostname).addErrback(failure, hostname)
+
+ return deferred
react(run, ['demo.snmplabs.com'])
diff --git a/examples/hlapi/v3arch/twisted/agent/ntforg/multiple-notifications-at-once.py b/examples/hlapi/v3arch/twisted/agent/ntforg/multiple-notifications-at-once.py
index c234a827..29f474a5 100644
--- a/examples/hlapi/v3arch/twisted/agent/ntforg/multiple-notifications-at-once.py
+++ b/examples/hlapi/v3arch/twisted/agent/ntforg/multiple-notifications-at-once.py
@@ -28,12 +28,13 @@ from pysnmp.hlapi.v3arch.twisted import *
def success(args, hostname):
- (errorStatus, errorIndex, varBinds) = args
+ errorStatus, errorIndex, varBinds = args
if errorStatus:
print('%s: %s at %s' % (hostname,
errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
+
else:
for varBind in varBinds:
print(' = '.join([x.prettyPrint() for x in varBind]))
@@ -45,7 +46,8 @@ def failure(errorIndication, hostname):
# noinspection PyUnusedLocal
def sendone(reactor, snmpEngine, hostname, notifyType):
- d = sendNotification(
+
+ deferred = sendNotification(
snmpEngine,
CommunityData('public', tag=hostname),
UdpTransportTarget((hostname, 162), tagList=hostname),
@@ -60,8 +62,10 @@ def sendone(reactor, snmpEngine, hostname, notifyType):
('1.3.6.1.2.1.1.1.0', OctetString('my system'))
)
)
- d.addCallback(success, hostname).addErrback(failure, hostname)
- return d
+
+ deferred.addCallback(success, hostname).addErrback(failure, hostname)
+
+ return deferred
def sendall(reactor, destinations):
diff --git a/examples/hlapi/v3arch/twisted/agent/ntforg/v2c-trap-inline-callbacks.py b/examples/hlapi/v3arch/twisted/agent/ntforg/v2c-trap-inline-callbacks.py
index 39b15c57..6e831582 100644
--- a/examples/hlapi/v3arch/twisted/agent/ntforg/v2c-trap-inline-callbacks.py
+++ b/examples/hlapi/v3arch/twisted/agent/ntforg/v2c-trap-inline-callbacks.py
@@ -24,7 +24,7 @@ from pysnmp.hlapi.v3arch.twisted import *
@defer.inlineCallbacks
def sendtrap(reactor, snmpEngine, hostname):
- yield sendNotification(
+ deferred = sendNotification(
snmpEngine,
CommunityData('public', mpModel=0),
UdpTransportTarget((hostname, 162)),
@@ -39,8 +39,10 @@ def sendtrap(reactor, snmpEngine, hostname):
)
)
+ yield deferred
+
+
# Preserve SnmpEngine instance across [potentially] multiple calls to safe on initialization
snmpEngine = SnmpEngine()
react(sendtrap, [snmpEngine, 'demo.snmplabs.com'])
-
diff --git a/examples/hlapi/v3arch/twisted/manager/cmdgen/custom-timeout-and-retries.py b/examples/hlapi/v3arch/twisted/manager/cmdgen/custom-timeout-and-retries.py
index 9c8c6eb9..96a93749 100644
--- a/examples/hlapi/v3arch/twisted/manager/cmdgen/custom-timeout-and-retries.py
+++ b/examples/hlapi/v3arch/twisted/manager/cmdgen/custom-timeout-and-retries.py
@@ -20,12 +20,13 @@ from pysnmp.hlapi.v3arch.twisted import *
def success(args, hostname):
- (errorStatus, errorIndex, varBinds) = args
+ errorStatus, errorIndex, varBinds = args
if errorStatus:
print('%s: %s at %s' % (hostname,
errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
+
else:
for varBind in varBinds:
print(' = '.join([x.prettyPrint() for x in varBind]))
@@ -37,17 +38,20 @@ def failure(errorIndication, hostname):
# noinspection PyUnusedLocal
def getSysDescr(reactor, hostname):
+
snmpEngine = SnmpEngine()
- d = getCmd(snmpEngine,
- CommunityData('public'),
- UdpTransportTarget((hostname, 161), timeout=2.0, retries=0),
- ContextData(),
- ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)))
+ deferred = getCmd(
+ snmpEngine,
+ CommunityData('public'),
+ UdpTransportTarget((hostname, 161), timeout=2.0, retries=0),
+ ContextData(),
+ ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0))
+ )
- d.addCallback(success, hostname).addErrback(failure, hostname)
+ deferred.addCallback(success, hostname).addErrback(failure, hostname)
- return d
+ return deferred
react(getSysDescr, ['demo.snmplabs.com'])
diff --git a/examples/hlapi/v3arch/twisted/manager/cmdgen/getbulk-to-eom.py b/examples/hlapi/v3arch/twisted/manager/cmdgen/getbulk-to-eom.py
index 89542793..e558fe89 100644
--- a/examples/hlapi/v3arch/twisted/manager/cmdgen/getbulk-to-eom.py
+++ b/examples/hlapi/v3arch/twisted/manager/cmdgen/getbulk-to-eom.py
@@ -21,12 +21,13 @@ from pysnmp.hlapi.v3arch.twisted import *
def success(args, reactor, snmpEngine):
- (errorStatus, errorIndex, varBindTable) = args
+ errorStatus, errorIndex, varBindTable = args
if errorStatus:
print('%s: %s at %s' % (hostname,
errorStatus.prettyPrint(),
errorIndex and varBindTable[0][int(errorIndex) - 1][0] or '?'))
+
else:
for varBindRow in varBindTable:
for varBind in varBindRow:
@@ -41,14 +42,18 @@ def failure(errorIndication):
def getbulk(reactor, snmpEngine, varBinds):
- d = bulkCmd(snmpEngine,
- UsmUserData('usr-none-none'),
- UdpTransportTarget(('demo.snmplabs.com', 161)),
- ContextData(),
- 0, 50,
- varBinds)
- d.addCallback(success, reactor, snmpEngine).addErrback(failure)
- return d
+ deferred = bulkCmd(
+ snmpEngine,
+ UsmUserData('usr-none-none'),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ ContextData(),
+ 0, 50,
+ varBinds
+ )
+
+ deferred.addCallback(success, reactor, snmpEngine).addErrback(failure)
+
+ return deferred
react(getbulk, [SnmpEngine(), ObjectType(ObjectIdentity('SNMPv2-MIB', 'system'))])
diff --git a/examples/hlapi/v3arch/twisted/manager/cmdgen/multiple-concurrent-queries.py b/examples/hlapi/v3arch/twisted/manager/cmdgen/multiple-concurrent-queries.py
index 90561015..4e1b3754 100644
--- a/examples/hlapi/v3arch/twisted/manager/cmdgen/multiple-concurrent-queries.py
+++ b/examples/hlapi/v3arch/twisted/manager/cmdgen/multiple-concurrent-queries.py
@@ -29,6 +29,7 @@ def success(args, hostname):
print('%s: %s at %s' % (hostname,
errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
+
else:
for varBind in varBinds:
print(' = '.join([x.prettyPrint() for x in varBind]))
@@ -43,13 +44,17 @@ def getSystem(reactor, hostname):
snmpEngine = SnmpEngine()
def getScalar(objectType):
- d = getCmd(snmpEngine,
- CommunityData('public', mpModel=0),
- UdpTransportTarget((hostname, 161)),
- ContextData(),
- objectType)
- d.addCallback(success, hostname).addErrback(failure, hostname)
- return d
+ deferred = getCmd(
+ snmpEngine,
+ CommunityData('public', mpModel=0),
+ UdpTransportTarget((hostname, 161)),
+ ContextData(),
+ objectType
+ )
+
+ deferred.addCallback(success, hostname).addErrback(failure, hostname)
+
+ return deferred
return DeferredList(
[getScalar(ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0))),
diff --git a/examples/hlapi/v3arch/twisted/manager/cmdgen/pull-mibs-from-multiple-agents-at-once.py b/examples/hlapi/v3arch/twisted/manager/cmdgen/pull-mibs-from-multiple-agents-at-once.py
index 2e501262..e7776a34 100644
--- a/examples/hlapi/v3arch/twisted/manager/cmdgen/pull-mibs-from-multiple-agents-at-once.py
+++ b/examples/hlapi/v3arch/twisted/manager/cmdgen/pull-mibs-from-multiple-agents-at-once.py
@@ -21,12 +21,13 @@ from pysnmp.hlapi.v3arch.twisted import *
def success(args, reactor, snmpEngine, hostname):
- (errorStatus, errorIndex, varBindTable) = args
+ errorStatus, errorIndex, varBindTable = args
if errorStatus:
print('%s: %s at %s' % (hostname,
errorStatus.prettyPrint(),
errorIndex and varBindTable[0][int(errorIndex) - 1][0] or '?'))
+
else:
for varBindRow in varBindTable:
for varBind in varBindRow:
@@ -41,17 +42,22 @@ def failure(errorIndication):
def getbulk(reactor, snmpEngine, hostname, varBinds):
- d = bulkCmd(snmpEngine,
- UsmUserData('usr-md5-none', 'authkey1'),
- UdpTransportTarget(hostname),
- ContextData(),
- 0, 25,
- varBinds)
- d.addCallback(success, reactor, snmpEngine, hostname).addErrback(failure)
- return d
+ deferred = bulkCmd(
+ snmpEngine,
+ UsmUserData('usr-md5-none', 'authkey1'),
+ UdpTransportTarget(hostname),
+ ContextData(),
+ 0, 25,
+ varBinds
+ )
+
+ deferred.addCallback(success, reactor, snmpEngine, hostname).addErrback(failure)
+
+ return deferred
def getall(reactor, hostnames):
+
snmpEngine = SnmpEngine()
return DeferredList(
diff --git a/examples/hlapi/v3arch/twisted/manager/cmdgen/pull-whole-mib.py b/examples/hlapi/v3arch/twisted/manager/cmdgen/pull-whole-mib.py
index 9e3f1791..ee1f376f 100644
--- a/examples/hlapi/v3arch/twisted/manager/cmdgen/pull-whole-mib.py
+++ b/examples/hlapi/v3arch/twisted/manager/cmdgen/pull-whole-mib.py
@@ -26,6 +26,7 @@ def success(args, reactor, snmpEngine):
print('%s: %s at %s' % (hostname,
errorStatus.prettyPrint(),
errorIndex and varBindTable[0][int(errorIndex) - 1][0] or '?'))
+
else:
for varBindRow in varBindTable:
for varBind in varBindRow:
@@ -40,13 +41,17 @@ def failure(errorIndication):
def getnext(reactor, snmpEngine, varBinds):
- d = nextCmd(snmpEngine,
- UsmUserData('usr-md5-none', 'authkey1'),
- UdpTransportTarget(('demo.snmplabs.com', 161)),
- ContextData(),
- varBinds)
- d.addCallback(success, reactor, snmpEngine).addErrback(failure)
- return d
+ deferred = nextCmd(
+ snmpEngine,
+ UsmUserData('usr-md5-none', 'authkey1'),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ ContextData(),
+ varBinds
+ )
+
+ deferred.addCallback(success, reactor, snmpEngine).addErrback(failure)
+
+ return deferred
react(getnext, [SnmpEngine(), ObjectType(ObjectIdentity('SNMPv2-MIB', 'system'))])
diff --git a/examples/hlapi/v3arch/twisted/manager/cmdgen/v1-get.py b/examples/hlapi/v3arch/twisted/manager/cmdgen/v1-get.py
index e483354d..735e146f 100644
--- a/examples/hlapi/v3arch/twisted/manager/cmdgen/v1-get.py
+++ b/examples/hlapi/v3arch/twisted/manager/cmdgen/v1-get.py
@@ -20,12 +20,13 @@ from pysnmp.hlapi.v3arch.twisted import *
def success(args, hostname):
- (errorStatus, errorIndex, varBinds) = args
+ errorStatus, errorIndex, varBinds = args
if errorStatus:
print('%s: %s at %s' % (hostname,
errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
+
else:
for varBind in varBinds:
print(' = '.join([x.prettyPrint() for x in varBind]))
@@ -37,15 +38,17 @@ def failure(errorIndication, hostname):
# noinspection PyUnusedLocal
def getSysDescr(reactor, hostname):
- d = getCmd(SnmpEngine(),
- CommunityData('public', mpModel=0),
- UdpTransportTarget((hostname, 161)),
- ContextData(),
- ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)))
+ deferred = getCmd(
+ SnmpEngine(),
+ CommunityData('public', mpModel=0),
+ UdpTransportTarget((hostname, 161)),
+ ContextData(),
+ ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0))
+ )
- d.addCallback(success, hostname).addErrback(failure, hostname)
+ deferred.addCallback(success, hostname).addErrback(failure, hostname)
- return d
+ return deferred
react(getSysDescr, ['demo.snmplabs.com'])
diff --git a/examples/smi/agent/custom-managed-object.py b/examples/smi/agent/custom-managed-object.py
index 50aee947..a6c3137b 100644
--- a/examples/smi/agent/custom-managed-object.py
+++ b/examples/smi/agent/custom-managed-object.py
@@ -55,9 +55,12 @@ if __name__ == '__main__':
def cbFun(varBinds, **context):
+
for oid, val in varBinds:
+
if exval.endOfMib.isSameTypeWith(val):
context['app']['stop'] = True
+
print('%s = %s' % ('.'.join([str(x) for x in oid]), not val.isValue and 'N/A' or val.prettyPrint()))
context['app']['varBinds'] = varBinds
@@ -69,6 +72,8 @@ if __name__ == '__main__':
}
print('Remote manager read access to MIB instrumentation (table walk)')
+
while not app_context['stop']:
mibInstrum.readNextMibObjects(*app_context['varBinds'], cbFun=cbFun, app=app_context)
+
print('done')
diff --git a/examples/smi/agent/operations-on-managed-objects.py b/examples/smi/agent/operations-on-managed-objects.py
index 75b9a765..704a6be5 100644
--- a/examples/smi/agent/operations-on-managed-objects.py
+++ b/examples/smi/agent/operations-on-managed-objects.py
@@ -10,12 +10,10 @@ from pysnmp.smi import builder
from pysnmp.smi import instrum
from pysnmp.smi import exval
from pysnmp.smi import error
-from pysnmp import debug
-
-#debug.setLogger(debug.Debug('all'))
def walkMib():
+
def cbFun(varBinds, **context):
err = context.get('error')
if err:
@@ -38,6 +36,7 @@ def walkMib():
}
print('Read whole MIB (table walk)')
+
while not app_context['stop']:
mibInstrum.readNextMibObjects(*app_context['varBinds'], cbFun=cbFun, app=app_context)
@@ -103,6 +102,7 @@ def cbFun(varBinds, **context):
err = context.get('errors', None)
if err:
print(err)
+
for oid, val in varBinds:
print('%s = %s' % ('.'.join([str(x) for x in oid]), not val.isValue and 'N/A' or val.prettyPrint()))
diff --git a/examples/smi/manager/configure-mib-viewer-and-resolve-pdu-varbinds.py b/examples/smi/manager/configure-mib-viewer-and-resolve-pdu-varbinds.py
index 82957fb3..2f2e83e0 100644
--- a/examples/smi/manager/configure-mib-viewer-and-resolve-pdu-varbinds.py
+++ b/examples/smi/manager/configure-mib-viewer-and-resolve-pdu-varbinds.py
@@ -31,7 +31,8 @@ varBinds = [
# Run var-binds through MIB resolver
# You may want to catch and ignore resolution errors here
-varBinds = [rfc1902.ObjectType(rfc1902.ObjectIdentity(x[0]), x[1]).resolveWithMib(mibViewController) for x in varBinds]
+varBinds = [rfc1902.ObjectType(rfc1902.ObjectIdentity(x[0]), x[1]).resolveWithMib(mibViewController)
+ for x in varBinds]
for varBind in varBinds:
print(varBind.prettyPrint())
diff --git a/examples/smi/manager/mib-tree-inspection.py b/examples/smi/manager/mib-tree-inspection.py
index 58b110a6..899ef36b 100644
--- a/examples/smi/manager/mib-tree-inspection.py
+++ b/examples/smi/manager/mib-tree-inspection.py
@@ -66,19 +66,25 @@ print(rowNode.getIndicesFromInstId(oid))
print('MIB tree traversal')
oid, label, suffix = mibView.getFirstNodeName()
-while 1:
+
+while True:
try:
modName, nodeDesc, suffix = mibView.getNodeLocation(oid)
print('%s::%s == %s' % (modName, nodeDesc, oid))
oid, label, suffix = mibView.getNextNodeName(oid)
+
except error.NoSuchObjectError:
break
print('Modules traversal')
modName = mibView.getFirstModuleName()
-while 1:
- if modName: print(modName)
+
+while True:
+ if modName:
+ print(modName)
+
try:
modName = mibView.getNextModuleName(modName)
+
except error.SmiError:
break
diff --git a/examples/v1arch/asyncore/agent/cmdrsp/implementing-scalar-mib-objects-over-ipv4-and-ipv6.py b/examples/v1arch/asyncore/agent/cmdrsp/implementing-scalar-mib-objects-over-ipv4-and-ipv6.py
index b6a20e86..1728d772 100644
--- a/examples/v1arch/asyncore/agent/cmdrsp/implementing-scalar-mib-objects-over-ipv4-and-ipv6.py
+++ b/examples/v1arch/asyncore/agent/cmdrsp/implementing-scalar-mib-objects-over-ipv4-and-ipv6.py
@@ -80,26 +80,35 @@ for mibVar in mibInstr:
def cbFun(transportDispatcher, transportDomain, transportAddress, wholeMsg):
while wholeMsg:
+
msgVer = 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(),
)
+
rspMsg = pMod.apiMessage.getResponse(reqMsg)
rspPDU = pMod.apiMessage.getPDU(rspMsg)
reqPDU = pMod.apiMessage.getPDU(reqMsg)
+
varBinds = []
pendingErrors = []
errorIndex = 0
+
# GETNEXT PDU
if reqPDU.isSameTypeWith(pMod.GetNextRequestPDU()):
+
# Produce response var-binds
for oid, val in pMod.apiPDU.getVarBinds(reqPDU):
errorIndex = errorIndex + 1
+
# Search next OID to report
nextIdx = bisect.bisect(mibInstr, oid)
if nextIdx == len(mibInstr):
@@ -108,15 +117,20 @@ def cbFun(transportDispatcher, transportDomain, transportAddress, wholeMsg):
pendingErrors.append(
(pMod.apiPDU.setEndOfMibError, errorIndex)
)
+
else:
# Report value if OID is found
varBinds.append(
(mibInstr[nextIdx].name, mibInstr[nextIdx](msgVer))
)
+
elif reqPDU.isSameTypeWith(pMod.GetRequestPDU()):
+
for oid, val in pMod.apiPDU.getVarBinds(reqPDU):
+
if oid in mibInstrIdx:
varBinds.append((oid, mibInstrIdx[oid](msgVer)))
+
else:
# No such instance
varBinds.append((oid, val))
@@ -124,16 +138,21 @@ def cbFun(transportDispatcher, transportDomain, transportAddress, wholeMsg):
(pMod.apiPDU.setNoSuchInstanceError, errorIndex)
)
break
+
else:
# Report unsupported request type
pMod.apiPDU.setErrorStatus(rspPDU, 'genErr')
+
pMod.apiPDU.setVarBinds(rspPDU, varBinds)
+
# Commit possible error indices to response PDU
for f, i in pendingErrors:
f(rspPDU, i)
+
transportDispatcher.sendMessage(
encoder.encode(rspMsg), transportDomain, transportAddress
)
+
return wholeMsg
@@ -155,6 +174,7 @@ transportDispatcher.jobStarted(1)
try:
# Dispatcher will never finish as job#1 never reaches zero
transportDispatcher.runDispatcher()
-except:
+
+except Exception:
transportDispatcher.closeDispatcher()
raise
diff --git a/examples/v1arch/asyncore/agent/ntforg/send-inform-over-ipv4-and-ipv6.py b/examples/v1arch/asyncore/agent/ntforg/send-inform-over-ipv4-and-ipv6.py
index bbf40fa0..20056466 100644
--- a/examples/v1arch/asyncore/agent/ntforg/send-inform-over-ipv4-and-ipv6.py
+++ b/examples/v1arch/asyncore/agent/ntforg/send-inform-over-ipv4-and-ipv6.py
@@ -43,20 +43,27 @@ def cbTimerFun(timeNow):
def cbRecvFun(transportDispatcher, transportDomain, transportAddress,
wholeMsg, reqPDU=reqPDU):
+
while wholeMsg:
rspMsg, wholeMsg = decoder.decode(wholeMsg, asn1Spec=pMod.Message())
rspPDU = pMod.apiMessage.getPDU(rspMsg)
+
# Match response to request
if pMod.apiPDU.getRequestID(reqPDU) == pMod.apiPDU.getRequestID(rspPDU):
+
# Check for SNMP errors reported
errorStatus = pMod.apiPDU.getErrorStatus(rspPDU)
if errorStatus:
print(errorStatus.prettyPrint())
+
else:
print('INFORM message delivered, response var-binds follow')
+
for oid, val in pMod.apiPDU.getVarBinds(rspPDU):
print('%s = %s' % (oid.prettyPrint(), val.prettyPrint()))
+
transportDispatcher.jobFinished(1)
+
return wholeMsg
diff --git a/examples/v1arch/asyncore/agent/ntforg/send-trap-over-ipv4-and-ipv6.py b/examples/v1arch/asyncore/agent/ntforg/send-trap-over-ipv4-and-ipv6.py
index 110c6701..9a689fb3 100644
--- a/examples/v1arch/asyncore/agent/ntforg/send-trap-over-ipv4-and-ipv6.py
+++ b/examples/v1arch/asyncore/agent/ntforg/send-trap-over-ipv4-and-ipv6.py
@@ -52,6 +52,7 @@ transportDispatcher = AsyncoreDispatcher()
transportDispatcher.registerTransport(
udp.DOMAIN_NAME, udp.UdpSocketTransport().openClientMode()
)
+
transportDispatcher.sendMessage(
encoder.encode(trapMsg), udp.DOMAIN_NAME, ('demo.snmplabs.com', 162)
)
@@ -60,6 +61,7 @@ transportDispatcher.sendMessage(
transportDispatcher.registerTransport(
udp6.DOMAIN_NAME, udp6.Udp6SocketTransport().openClientMode()
)
+
transportDispatcher.sendMessage(
encoder.encode(trapMsg), udp6.DOMAIN_NAME, ('::1', 162)
)
diff --git a/examples/v1arch/asyncore/manager/cmdgen/broadcast-agent-discovery.py b/examples/v1arch/asyncore/manager/cmdgen/broadcast-agent-discovery.py
index 40eb0698..2fe5db4b 100644
--- a/examples/v1arch/asyncore/manager/cmdgen/broadcast-agent-discovery.py
+++ b/examples/v1arch/asyncore/manager/cmdgen/broadcast-agent-discovery.py
@@ -62,19 +62,25 @@ def cbTimerFun(timeNow):
# noinspection PyUnusedLocal,PyUnusedLocal
def cbRecvFun(transportDispatcher, transportDomain, transportAddress,
wholeMsg, reqPDU=reqPDU):
+
while wholeMsg:
rspMsg, wholeMsg = decoder.decode(wholeMsg, asn1Spec=pMod.Message())
rspPDU = pMod.apiMessage.getPDU(rspMsg)
+
# Match response to request
if pMod.apiPDU.getRequestID(reqPDU) == pMod.apiPDU.getRequestID(rspPDU):
+
# Check for SNMP errors reported
errorStatus = pMod.apiPDU.getErrorStatus(rspPDU)
if errorStatus:
print(errorStatus.prettyPrint())
+
else:
for oid, val in pMod.apiPDU.getVarBinds(rspPDU):
print('%s = %s' % (oid.prettyPrint(), val.prettyPrint()))
+
transportDispatcher.jobFinished(1)
+
return wholeMsg
@@ -98,7 +104,6 @@ transportDispatcher.jobStarted(1, maxNumberResponses)
# Dispatcher will finish as all jobs counter reaches zero
try:
transportDispatcher.runDispatcher()
-except StopWaiting:
+
+finally:
transportDispatcher.closeDispatcher()
-else:
- raise
diff --git a/examples/v1arch/asyncore/manager/cmdgen/fetch-scalar-value.py b/examples/v1arch/asyncore/manager/cmdgen/fetch-scalar-value.py
index 014ca7d2..f0b51373 100644
--- a/examples/v1arch/asyncore/manager/cmdgen/fetch-scalar-value.py
+++ b/examples/v1arch/asyncore/manager/cmdgen/fetch-scalar-value.py
@@ -52,16 +52,21 @@ def cbRecvFun(transportDispatcher, transportDomain, transportAddress,
while wholeMsg:
rspMsg, wholeMsg = decoder.decode(wholeMsg, asn1Spec=pMod.Message())
rspPDU = pMod.apiMessage.getPDU(rspMsg)
+
# Match response to request
if pMod.apiPDU.getRequestID(reqPDU) == pMod.apiPDU.getRequestID(rspPDU):
+
# Check for SNMP errors reported
errorStatus = pMod.apiPDU.getErrorStatus(rspPDU)
if errorStatus:
print(errorStatus.prettyPrint())
+
else:
for oid, val in pMod.apiPDU.getVarBinds(rspPDU):
print('%s = %s' % (oid.prettyPrint(), val.prettyPrint()))
+
transportDispatcher.jobFinished(1)
+
return wholeMsg
diff --git a/examples/v1arch/asyncore/manager/cmdgen/getbulk-pull-whole-mib.py b/examples/v1arch/asyncore/manager/cmdgen/getbulk-pull-whole-mib.py
index 0c45a18f..031193c4 100644
--- a/examples/v1arch/asyncore/manager/cmdgen/getbulk-pull-whole-mib.py
+++ b/examples/v1arch/asyncore/manager/cmdgen/getbulk-pull-whole-mib.py
@@ -71,15 +71,15 @@ def cbRecvFun(transportDispatcher, transportDomain, transportAddress,
# Report SNMP table
for tableRow in varBindTable:
for name, val in tableRow:
- print('from: %s, %s = %s' % (
- transportAddress, name.prettyPrint(), val.prettyPrint()
- )
- )
+ print('from: %s, %s = %s' % (transportAddress,
+ name.prettyPrint(),
+ val.prettyPrint()))
# Stop on EOM
for oid, val in varBindTable[-1]:
if not isinstance(val, v2c.Null):
break
+
else:
transportDispatcher.jobFinished(1)
continue
@@ -88,13 +88,17 @@ def cbRecvFun(transportDispatcher, transportDomain, transportAddress,
v2c.apiBulkPDU.setVarBinds(
reqPDU, [(x, v2c.null) for x, y in varBindTable[-1]]
)
+
v2c.apiBulkPDU.setRequestID(reqPDU, v2c.getNextRequestID())
+
transportDispatcher.sendMessage(
encoder.encode(reqMsg), transportDomain, transportAddress
)
+
global startedAt
if time() - startedAt > 3:
raise Exception('Request timed out')
+
startedAt = time()
return wholeMsg
@@ -108,9 +112,11 @@ transportDispatcher.registerTimerCbFun(cbTimerFun)
transportDispatcher.registerTransport(
udp.DOMAIN_NAME, udp.UdpSocketTransport().openClientMode()
)
+
transportDispatcher.sendMessage(
encoder.encode(reqMsg), udp.DOMAIN_NAME, ('demo.snmplabs.com', 161)
)
+
transportDispatcher.jobStarted(1)
# Dispatcher will finish as job#1 counter reaches zero
diff --git a/examples/v1arch/asyncore/manager/cmdgen/getnext-pull-whole-mib.py b/examples/v1arch/asyncore/manager/cmdgen/getnext-pull-whole-mib.py
index a81dd9b0..3a543900 100644
--- a/examples/v1arch/asyncore/manager/cmdgen/getnext-pull-whole-mib.py
+++ b/examples/v1arch/asyncore/manager/cmdgen/getnext-pull-whole-mib.py
@@ -53,25 +53,30 @@ def cbRecvFun(transportDispatcher, transportDomain, transportAddress,
while wholeMsg:
rspMsg, wholeMsg = decoder.decode(wholeMsg, asn1Spec=pMod.Message())
rspPDU = pMod.apiMessage.getPDU(rspMsg)
+
# Match response to request
if pMod.apiPDU.getRequestID(reqPDU) == pMod.apiPDU.getRequestID(rspPDU):
+
# Check for SNMP errors reported
errorStatus = pMod.apiPDU.getErrorStatus(rspPDU)
if errorStatus and errorStatus != 2:
raise Exception(errorStatus)
+
# Format var-binds table
varBindTable = pMod.apiPDU.getVarBindTable(reqPDU, rspPDU)
+
# Report SNMP table
for tableRow in varBindTable:
for name, val in tableRow:
- print('from: %s, %s = %s' % (
- transportAddress, name.prettyPrint(), val.prettyPrint()
- )
- )
+ print('from: %s, %s = %s' % (transportAddress,
+ name.prettyPrint(),
+ val.prettyPrint()))
+
# Stop on EOM
for oid, val in varBindTable[-1]:
if not isinstance(val, pMod.Null):
break
+
else:
transportDispatcher.jobFinished(1)
continue
@@ -80,13 +85,18 @@ def cbRecvFun(transportDispatcher, transportDomain, transportAddress,
pMod.apiPDU.setVarBinds(
reqPDU, [(x, pMod.null) for x, y in varBindTable[-1]]
)
+
pMod.apiPDU.setRequestID(reqPDU, pMod.getNextRequestID())
+
transportDispatcher.sendMessage(
encoder.encode(reqMsg), transportDomain, transportAddress
)
+
global startedAt
+
if time() - startedAt > 3:
raise Exception('Request timed out')
+
startedAt = time()
return wholeMsg
@@ -100,9 +110,11 @@ transportDispatcher.registerTimerCbFun(cbTimerFun)
transportDispatcher.registerTransport(
udp.DOMAIN_NAME, udp.UdpSocketTransport().openClientMode()
)
+
transportDispatcher.sendMessage(
encoder.encode(reqMsg), udp.DOMAIN_NAME, ('demo.snmplabs.com', 161)
)
+
transportDispatcher.jobStarted(1)
transportDispatcher.runDispatcher()
diff --git a/examples/v1arch/asyncore/manager/cmdgen/spoof-source-address.py b/examples/v1arch/asyncore/manager/cmdgen/spoof-source-address.py
index 72e87736..24d7a3eb 100644
--- a/examples/v1arch/asyncore/manager/cmdgen/spoof-source-address.py
+++ b/examples/v1arch/asyncore/manager/cmdgen/spoof-source-address.py
@@ -72,19 +72,25 @@ def cbTimerFun(timeNow):
# noinspection PyUnusedLocal,PyUnusedLocal
def cbRecvFun(transportDispatcher, transportDomain, transportAddress,
wholeMsg, reqPDU=reqPDU):
+
while wholeMsg:
rspMsg, wholeMsg = decoder.decode(wholeMsg, asn1Spec=pMod.Message())
rspPDU = pMod.apiMessage.getPDU(rspMsg)
+
# Match response to request
if pMod.apiPDU.getRequestID(reqPDU) == pMod.apiPDU.getRequestID(rspPDU):
+
# Check for SNMP errors reported
errorStatus = pMod.apiPDU.getErrorStatus(rspPDU)
if errorStatus:
print(errorStatus.prettyPrint())
+
else:
for oid, val in pMod.apiPDU.getVarBinds(rspPDU):
print('%s = %s' % (oid.prettyPrint(), val.prettyPrint()))
+
transportDispatcher.jobFinished(1)
+
return wholeMsg
@@ -116,7 +122,6 @@ transportDispatcher.jobStarted(1)
# Dispatcher will finish as all jobs counter reaches zero
try:
transportDispatcher.runDispatcher()
-except StopWaiting:
+
+finally:
transportDispatcher.closeDispatcher()
-else:
- raise
diff --git a/examples/v1arch/asyncore/manager/cmdgen/v2c-set.py b/examples/v1arch/asyncore/manager/cmdgen/v2c-set.py
index 88be5508..60fb2518 100644
--- a/examples/v1arch/asyncore/manager/cmdgen/v2c-set.py
+++ b/examples/v1arch/asyncore/manager/cmdgen/v2c-set.py
@@ -54,16 +54,21 @@ def cbRecvFun(transportDispatcher, transportDomain, transportAddress,
while wholeMsg:
rspMsg, wholeMsg = decoder.decode(wholeMsg, asn1Spec=pMod.Message())
rspPDU = pMod.apiMessage.getPDU(rspMsg)
+
# Match response to request
if pMod.apiPDU.getRequestID(reqPDU) == pMod.apiPDU.getRequestID(rspPDU):
+
# Check for SNMP errors reported
errorStatus = pMod.apiPDU.getErrorStatus(rspPDU)
if errorStatus:
print(errorStatus.prettyPrint())
+
else:
for oid, val in pMod.apiPDU.getVarBinds(rspPDU):
print('%s = %s' % (oid.prettyPrint(), val.prettyPrint()))
+
transportDispatcher.jobFinished(1)
+
return wholeMsg
@@ -81,6 +86,7 @@ transportDispatcher.registerTransport(
transportDispatcher.sendMessage(
encoder.encode(reqMsg), udp.DOMAIN_NAME, ('demo.snmplabs.com', 161)
)
+
transportDispatcher.jobStarted(1)
# Dispatcher will finish as job#1 counter reaches zero
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
diff --git a/examples/v3arch/asyncio/agent/cmdrsp/multiple-usm-users.py b/examples/v3arch/asyncio/agent/cmdrsp/multiple-usm-users.py
index 2b420185..7a99405b 100644
--- a/examples/v3arch/asyncio/agent/cmdrsp/multiple-usm-users.py
+++ b/examples/v3arch/asyncio/agent/cmdrsp/multiple-usm-users.py
@@ -52,11 +52,13 @@ config.addV3User(
config.USM_AUTH_HMAC96_MD5, 'authkey1',
config.USM_PRIV_CBC56_DES, 'privkey1'
)
+
# user: usr-sha-none, auth: SHA, priv NONE
config.addV3User(
snmpEngine, 'usr-sha-none',
config.USM_AUTH_HMAC96_SHA, 'authkey1'
)
+
# user: usr-sha-none, auth: SHA, priv AES
config.addV3User(
snmpEngine, 'usr-sha-aes128',
@@ -65,9 +67,12 @@ config.addV3User(
)
# Allow full MIB access for each user at VACM
-config.addVacmUser(snmpEngine, 3, 'usr-md5-des', 'authPriv', (1, 3, 6, 1, 2, 1), (1, 3, 6, 1, 2, 1))
-config.addVacmUser(snmpEngine, 3, 'usr-sha-none', 'authNoPriv', (1, 3, 6, 1, 2, 1), (1, 3, 6, 1, 2, 1))
-config.addVacmUser(snmpEngine, 3, 'usr-sha-aes128', 'authPriv', (1, 3, 6, 1, 2, 1), (1, 3, 6, 1, 2, 1))
+config.addVacmUser(snmpEngine, 3, 'usr-md5-des', 'authPriv',
+ (1, 3, 6, 1, 2, 1), (1, 3, 6, 1, 2, 1))
+config.addVacmUser(snmpEngine, 3, 'usr-sha-none', 'authNoPriv',
+ (1, 3, 6, 1, 2, 1), (1, 3, 6, 1, 2, 1))
+config.addVacmUser(snmpEngine, 3, 'usr-sha-aes128', 'authPriv',
+ (1, 3, 6, 1, 2, 1), (1, 3, 6, 1, 2, 1))
# Get default SNMP context this SNMP engine serves
snmpContext = context.SnmpContext(snmpEngine)
diff --git a/examples/v3arch/asyncio/manager/ntfrcv/multiple-interfaces.py b/examples/v3arch/asyncio/manager/ntfrcv/multiple-interfaces.py
index b5bdea9f..dc29a054 100644
--- a/examples/v3arch/asyncio/manager/ntfrcv/multiple-interfaces.py
+++ b/examples/v3arch/asyncio/manager/ntfrcv/multiple-interfaces.py
@@ -56,15 +56,15 @@ config.addV1System(snmpEngine, 'my-area', 'public')
# Callback function for receiving notifications
# noinspection PyUnusedLocal
-def cbFun(snmpEngine,
- stateReference,
- contextEngineId, contextName,
- varBinds,
- cbCtx):
+def cbFun(snmpEngine, stateReference, contextEngineId,
+ contextName, varBinds, cbCtx):
+
transportDomain, transportAddress = snmpEngine.msgAndPduDsp.getTransportInfo(stateReference)
- print('Notification from %s, SNMP Engine %s, Context %s' % (transportAddress,
- contextEngineId.prettyPrint(),
- contextName.prettyPrint()))
+
+ print('Notification from %s, SNMP Engine %s, '
+ 'Context %s' % (transportAddress, contextEngineId.prettyPrint(),
+ contextName.prettyPrint()))
+
for name, val in varBinds:
print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
diff --git a/examples/v3arch/asyncore/agent/cmdrsp/alternative-mib-tree.py b/examples/v3arch/asyncore/agent/cmdrsp/alternative-mib-tree.py
index 257f9676..42d19cf7 100644
--- a/examples/v3arch/asyncore/agent/cmdrsp/alternative-mib-tree.py
+++ b/examples/v3arch/asyncore/agent/cmdrsp/alternative-mib-tree.py
@@ -45,7 +45,8 @@ config.addV3User(
)
# Allow full MIB access for each user at VACM
-config.addVacmUser(snmpEngine, 3, 'usr-md5-none', 'authNoPriv', (1, 3, 6, 1, 2, 1), (1, 3, 6, 1, 2, 1))
+config.addVacmUser(snmpEngine, 3, 'usr-md5-none', 'authNoPriv',
+ (1, 3, 6, 1, 2, 1), (1, 3, 6, 1, 2, 1))
# Create an SNMP context with ContextEngineId = 8000000001020304
snmpContext = context.SnmpContext(
@@ -72,6 +73,6 @@ snmpEngine.transportDispatcher.jobStarted(1)
# Run I/O dispatcher which would receive queries and send responses
try:
snmpEngine.transportDispatcher.runDispatcher()
-except:
+
+finally:
snmpEngine.transportDispatcher.closeDispatcher()
- raise
diff --git a/examples/v3arch/asyncore/agent/cmdrsp/custom-mib-controller.py b/examples/v3arch/asyncore/agent/cmdrsp/custom-mib-controller.py
index 65637f3e..0368882a 100644
--- a/examples/v3arch/asyncore/agent/cmdrsp/custom-mib-controller.py
+++ b/examples/v3arch/asyncore/agent/cmdrsp/custom-mib-controller.py
@@ -53,6 +53,7 @@ snmpContext = context.SnmpContext(snmpEngine)
# any Managed Objects attached. It supports only GET's and
# always echos request var-binds in response.
class EchoMibInstrumController(instrum.AbstractMibInstrumController):
+
def readMibObjects(self, *varBinds, **context):
cbFun = context.get('cbFun')
if cbFun:
@@ -76,6 +77,6 @@ snmpEngine.transportDispatcher.jobStarted(1)
# Run I/O dispatcher which would receive queries and send responses
try:
snmpEngine.transportDispatcher.runDispatcher()
-except:
+
+finally:
snmpEngine.transportDispatcher.closeDispatcher()
- raise
diff --git a/examples/v3arch/asyncore/agent/cmdrsp/custom-snmp-engine-id.py b/examples/v3arch/asyncore/agent/cmdrsp/custom-snmp-engine-id.py
index bd54caed..fd51542f 100644
--- a/examples/v3arch/asyncore/agent/cmdrsp/custom-snmp-engine-id.py
+++ b/examples/v3arch/asyncore/agent/cmdrsp/custom-snmp-engine-id.py
@@ -60,6 +60,6 @@ snmpEngine.transportDispatcher.jobStarted(1)
# Run I/O dispatcher which would receive queries and send responses
try:
snmpEngine.transportDispatcher.runDispatcher()
-except:
+
+finally:
snmpEngine.transportDispatcher.closeDispatcher()
- raise
diff --git a/examples/v3arch/asyncore/agent/cmdrsp/implementing-scalar-mib-objects.py b/examples/v3arch/asyncore/agent/cmdrsp/implementing-scalar-mib-objects.py
index 74e8c5db..73641d70 100644
--- a/examples/v3arch/asyncore/agent/cmdrsp/implementing-scalar-mib-objects.py
+++ b/examples/v3arch/asyncore/agent/cmdrsp/implementing-scalar-mib-objects.py
@@ -80,6 +80,6 @@ snmpEngine.transportDispatcher.jobStarted(1)
# Run I/O dispatcher which would receive queries and send responses
try:
snmpEngine.transportDispatcher.runDispatcher()
-except:
+
+finally:
snmpEngine.transportDispatcher.closeDispatcher()
- raise
diff --git a/examples/v3arch/asyncore/agent/cmdrsp/implementing-snmp-table.py b/examples/v3arch/asyncore/agent/cmdrsp/implementing-snmp-table.py
index bf15aedf..cedcc15e 100644
--- a/examples/v3arch/asyncore/agent/cmdrsp/implementing-snmp-table.py
+++ b/examples/v3arch/asyncore/agent/cmdrsp/implementing-snmp-table.py
@@ -47,7 +47,8 @@ config.addTransport(
config.addV1System(snmpEngine, 'my-area', 'public')
# Allow read MIB access for this user / securityModels at VACM
-config.addVacmUser(snmpEngine, 2, 'my-area', 'noAuthNoPriv', (1, 3, 6, 6), (1, 3, 6, 6))
+config.addVacmUser(snmpEngine, 2, 'my-area', 'noAuthNoPriv',
+ (1, 3, 6, 6), (1, 3, 6, 6))
# Create an SNMP context
snmpContext = context.SnmpContext(snmpEngine)
@@ -72,17 +73,24 @@ RowStatus, = mibBuilder.importSymbols('SNMPv2-TC', 'RowStatus')
mibBuilder.exportSymbols(
'__EXAMPLE-MIB',
# table object
- exampleTable=MibTable((1, 3, 6, 6, 1)).setMaxAccess('readcreate'),
+ exampleTable=MibTable((1, 3, 6, 6, 1))
+ .setMaxAccess('readcreate'),
# table row object, also carries references to table indices
- exampleTableEntry=MibTableRow((1, 3, 6, 6, 1, 5)).setMaxAccess('readcreate').setIndexNames((0, '__EXAMPLE-MIB', 'exampleTableColumn1')),
+ exampleTableEntry=MibTableRow((1, 3, 6, 6, 1, 5))
+ .setMaxAccess('readcreate')
+ .setIndexNames((0, '__EXAMPLE-MIB', 'exampleTableColumn1')),
# table column: string index
- exampleTableColumn1=MibTableColumn((1, 3, 6, 6, 1, 5, 1), v2c.OctetString()).setMaxAccess('readcreate'),
+ exampleTableColumn1=MibTableColumn((1, 3, 6, 6, 1, 5, 1), v2c.OctetString())
+ .setMaxAccess('readcreate'),
# table column: string value
- exampleTableColumn2=MibTableColumn((1, 3, 6, 6, 1, 5, 2), v2c.OctetString()).setMaxAccess('readcreate'),
+ exampleTableColumn2=MibTableColumn((1, 3, 6, 6, 1, 5, 2), v2c.OctetString())
+ .setMaxAccess('readcreate'),
# table column: integer value with default
- exampleTableColumn3=MibTableColumn((1, 3, 6, 6, 1, 5, 3), v2c.Integer32(123)).setMaxAccess('readcreate'),
+ exampleTableColumn3=MibTableColumn((1, 3, 6, 6, 1, 5, 3), v2c.Integer32(123))
+ .setMaxAccess('readcreate'),
# table column: row status
- exampleTableStatus=MibTableColumn((1, 3, 6, 6, 1, 5, 4), RowStatus('notExists')).setMaxAccess('readcreate')
+ exampleTableStatus=MibTableColumn((1, 3, 6, 6, 1, 5, 4), RowStatus('notExists'))
+ .setMaxAccess('readcreate')
)
# --- end of custom SNMP table definition, empty table now exists ---
@@ -99,8 +107,11 @@ mibBuilder.exportSymbols(
'exampleTableColumn3',
'exampleTableStatus'
)
+
rowInstanceId = exampleTableEntry.getInstIdFromIndices('example record one')
+
mibInstrumentation = snmpContext.getMibInstrum()
+
mibInstrumentation.writeMibObjects(
(exampleTableColumn2.name + rowInstanceId, 'my string value'),
(exampleTableColumn3.name + rowInstanceId, 123456),
@@ -121,6 +132,6 @@ snmpEngine.transportDispatcher.jobStarted(1)
# Run I/O dispatcher which would receive queries and send responses
try:
snmpEngine.transportDispatcher.runDispatcher()
-except:
+
+finally:
snmpEngine.transportDispatcher.closeDispatcher()
- raise
diff --git a/examples/v3arch/asyncore/agent/cmdrsp/listen-on-ipv4-and-ipv6-interfaces.py b/examples/v3arch/asyncore/agent/cmdrsp/listen-on-ipv4-and-ipv6-interfaces.py
index 1334fd8d..a1a4e853 100644
--- a/examples/v3arch/asyncore/agent/cmdrsp/listen-on-ipv4-and-ipv6-interfaces.py
+++ b/examples/v3arch/asyncore/agent/cmdrsp/listen-on-ipv4-and-ipv6-interfaces.py
@@ -33,6 +33,7 @@ config.addTransport(
udp.DOMAIN_NAME,
udp.UdpTransport().openServerMode(('127.0.0.1', 161))
)
+
# UDP over IPv6 at [::1]:161
config.addTransport(
snmpEngine,
@@ -63,6 +64,6 @@ snmpEngine.transportDispatcher.jobStarted(1)
# Run I/O dispatcher which would receive queries and send responses
try:
snmpEngine.transportDispatcher.runDispatcher()
-except:
+
+finally:
snmpEngine.transportDispatcher.closeDispatcher()
- raise
diff --git a/examples/v3arch/asyncore/agent/cmdrsp/listen-on-multiple-interfaces.py b/examples/v3arch/asyncore/agent/cmdrsp/listen-on-multiple-interfaces.py
index c8088ed0..bfb0b4ef 100644
--- a/examples/v3arch/asyncore/agent/cmdrsp/listen-on-multiple-interfaces.py
+++ b/examples/v3arch/asyncore/agent/cmdrsp/listen-on-multiple-interfaces.py
@@ -32,6 +32,7 @@ config.addTransport(
udp.DOMAIN_NAME + (1,),
udp.UdpTransport().openServerMode(('127.0.0.1', 161))
)
+
# UDP over IPv4 at 127.0.0.2:161
config.addTransport(
snmpEngine,
@@ -62,6 +63,6 @@ snmpEngine.transportDispatcher.jobStarted(1)
# Run I/O dispatcher which would receive queries and send responses
try:
snmpEngine.transportDispatcher.runDispatcher()
-except:
+
+finally:
snmpEngine.transportDispatcher.closeDispatcher()
- raise
diff --git a/examples/v3arch/asyncore/agent/cmdrsp/listening-on-virtual-network-interface.py b/examples/v3arch/asyncore/agent/cmdrsp/listening-on-virtual-network-interface.py
index a501aec3..c6bfc33f 100644
--- a/examples/v3arch/asyncore/agent/cmdrsp/listening-on-virtual-network-interface.py
+++ b/examples/v3arch/asyncore/agent/cmdrsp/listening-on-virtual-network-interface.py
@@ -85,7 +85,7 @@ snmpEngine.transportDispatcher.jobStarted(1)
# Run I/O dispatcher which would receive queries and send responses
try:
snmpEngine.transportDispatcher.runDispatcher()
-except:
+
+finally:
snmpEngine.observer.unregisterObserver()
snmpEngine.transportDispatcher.closeDispatcher()
- raise
diff --git a/examples/v3arch/asyncore/agent/cmdrsp/multiple-snmp-communities.py b/examples/v3arch/asyncore/agent/cmdrsp/multiple-snmp-communities.py
index c2180ade..8aef067d 100644
--- a/examples/v3arch/asyncore/agent/cmdrsp/multiple-snmp-communities.py
+++ b/examples/v3arch/asyncore/agent/cmdrsp/multiple-snmp-communities.py
@@ -60,6 +60,6 @@ snmpEngine.transportDispatcher.jobStarted(1)
# Run I/O dispatcher which would receive queries and send responses
try:
snmpEngine.transportDispatcher.runDispatcher()
-except:
+
+finally:
snmpEngine.transportDispatcher.closeDispatcher()
- raise
diff --git a/examples/v3arch/asyncore/agent/cmdrsp/multiple-snmp-engines.py b/examples/v3arch/asyncore/agent/cmdrsp/multiple-snmp-engines.py
index b65cd63f..00e241c2 100644
--- a/examples/v3arch/asyncore/agent/cmdrsp/multiple-snmp-engines.py
+++ b/examples/v3arch/asyncore/agent/cmdrsp/multiple-snmp-engines.py
@@ -88,6 +88,6 @@ transportDispatcher.jobStarted(1)
# Run I/O dispatcher which would receive queries and send responses
try:
transportDispatcher.runDispatcher()
-except:
+
+finally:
transportDispatcher.closeDispatcher()
- raise
diff --git a/examples/v3arch/asyncore/agent/cmdrsp/multiple-usm-users.py b/examples/v3arch/asyncore/agent/cmdrsp/multiple-usm-users.py
index 4a9f5162..45b4d113 100644
--- a/examples/v3arch/asyncore/agent/cmdrsp/multiple-usm-users.py
+++ b/examples/v3arch/asyncore/agent/cmdrsp/multiple-usm-users.py
@@ -43,11 +43,13 @@ config.addV3User(
config.USM_AUTH_HMAC96_MD5, 'authkey1',
config.USM_PRIV_CBC56_DES, 'privkey1'
)
+
# user: usr-sha-none, auth: SHA, priv NONE
config.addV3User(
snmpEngine, 'usr-sha-none',
config.USM_AUTH_HMAC96_SHA, 'authkey1'
)
+
# user: usr-sha-none, auth: SHA, priv AES
config.addV3User(
snmpEngine, 'usr-sha-aes128',
@@ -75,6 +77,6 @@ snmpEngine.transportDispatcher.jobStarted(1)
# Run I/O dispatcher which would receive queries and send responses
try:
snmpEngine.transportDispatcher.runDispatcher()
-except:
+
+finally:
snmpEngine.transportDispatcher.closeDispatcher()
- raise
diff --git a/examples/v3arch/asyncore/agent/cmdrsp/observe-request-processing.py b/examples/v3arch/asyncore/agent/cmdrsp/observe-request-processing.py
index a7c1acae..44c9a92e 100644
--- a/examples/v3arch/asyncore/agent/cmdrsp/observe-request-processing.py
+++ b/examples/v3arch/asyncore/agent/cmdrsp/observe-request-processing.py
@@ -36,7 +36,9 @@ snmpEngine = engine.SnmpEngine()
def requestObserver(snmpEngine, execpoint, variables, cbCtx):
print('Execution point: %s' % execpoint)
print('* transportDomain: %s' % '.'.join([str(x) for x in variables['transportDomain']]))
- print('* transportAddress: %s (local %s)' % ('@'.join([str(x) for x in variables['transportAddress']]), '@'.join([str(x) for x in variables['transportAddress'].getLocalAddress()])))
+ print('* transportAddress: %s (local %s)' % (
+ '@'.join([str(x) for x in variables['transportAddress']]), '@'.join(
+ [str(x) for x in variables['transportAddress'].getLocalAddress()])))
print('* securityModel: %s' % variables['securityModel'])
print('* securityName: %s' % variables['securityName'])
print('* securityLevel: %s' % variables['securityLevel'])
@@ -70,7 +72,8 @@ config.addV3User(
)
# Allow full MIB access for each user at VACM
-config.addVacmUser(snmpEngine, 3, 'usr-md5-des', 'authPriv', (1, 3, 6, 1, 2, 1), (1, 3, 6, 1, 2, 1))
+config.addVacmUser(snmpEngine, 3, 'usr-md5-des', 'authPriv',
+ (1, 3, 6, 1, 2, 1), (1, 3, 6, 1, 2, 1))
# Get default SNMP context this SNMP engine serves
snmpContext = context.SnmpContext(snmpEngine)
@@ -87,7 +90,7 @@ snmpEngine.transportDispatcher.jobStarted(1)
# Run I/O dispatcher which would receive queries and send responses
try:
snmpEngine.transportDispatcher.runDispatcher()
-except:
+
+finally:
snmpEngine.observer.unregisterObserver()
snmpEngine.transportDispatcher.closeDispatcher()
- raise
diff --git a/examples/v3arch/asyncore/agent/ntforg/multiple-different-notifications-at-once.py b/examples/v3arch/asyncore/agent/ntforg/multiple-different-notifications-at-once.py
index e1781416..8fb7c483 100644
--- a/examples/v3arch/asyncore/agent/ntforg/multiple-different-notifications-at-once.py
+++ b/examples/v3arch/asyncore/agent/ntforg/multiple-different-notifications-at-once.py
@@ -45,6 +45,7 @@ config.addV3User(
snmpEngine, 'usr-md5-none',
config.USM_AUTH_HMAC96_MD5, 'authkey1'
)
+
config.addTargetParams(snmpEngine, 'my-creds-2', 'usr-md5-none', 'authNoPriv')
# Setup transport endpoint and bind it with security settings yielding
@@ -54,6 +55,7 @@ config.addTransport(
udp.DOMAIN_NAME,
udp.UdpSocketTransport().openClientMode()
)
+
# First target
config.addTargetAddr(
snmpEngine, 'my-nms-1',
@@ -61,6 +63,7 @@ config.addTargetAddr(
'my-creds-1',
tagList='all-my-managers'
)
+
# Second target
config.addTargetAddr(
snmpEngine, 'my-nms-2',
diff --git a/examples/v3arch/asyncore/agent/ntforg/send-inform-to-multiple-managers.py b/examples/v3arch/asyncore/agent/ntforg/send-inform-to-multiple-managers.py
index ee1692cb..3349f4c2 100644
--- a/examples/v3arch/asyncore/agent/ntforg/send-inform-to-multiple-managers.py
+++ b/examples/v3arch/asyncore/agent/ntforg/send-inform-to-multiple-managers.py
@@ -43,6 +43,7 @@ config.addTransport(
udp.DOMAIN_NAME,
udp.UdpSocketTransport().openClientMode()
)
+
# First target
config.addTargetAddr(
snmpEngine, 'my-nms-1',
@@ -50,6 +51,7 @@ config.addTargetAddr(
'my-creds',
tagList='all-my-managers'
)
+
# Second target
config.addTargetAddr(
snmpEngine, 'my-nms-2',
@@ -57,6 +59,7 @@ config.addTargetAddr(
'my-creds',
tagList='all-my-managers'
)
+
# Third target
config.addTargetAddr(
snmpEngine, 'my-nms-3',
diff --git a/examples/v3arch/asyncore/agent/ntforg/send-notification-over-ipv4-and-ipv6.py b/examples/v3arch/asyncore/agent/ntforg/send-notification-over-ipv4-and-ipv6.py
index 7985d848..c2031bfa 100644
--- a/examples/v3arch/asyncore/agent/ntforg/send-notification-over-ipv4-and-ipv6.py
+++ b/examples/v3arch/asyncore/agent/ntforg/send-notification-over-ipv4-and-ipv6.py
@@ -44,6 +44,7 @@ config.addTransport(
udp.DOMAIN_NAME,
udp.UdpSocketTransport().openClientMode()
)
+
config.addTargetAddr(
snmpEngine, 'my-nms-1',
udp.DOMAIN_NAME, ('104.236.166.95', 162),
@@ -57,6 +58,7 @@ config.addTransport(
udp6.DOMAIN_NAME,
udp6.Udp6SocketTransport().openClientMode()
)
+
config.addTargetAddr(
snmpEngine, 'my-nms-2',
udp6.DOMAIN_NAME, ('::1', 162),
diff --git a/examples/v3arch/asyncore/agent/ntforg/send-packet-from-specific-address.py b/examples/v3arch/asyncore/agent/ntforg/send-packet-from-specific-address.py
index 5ce65da5..8552c4d9 100644
--- a/examples/v3arch/asyncore/agent/ntforg/send-packet-from-specific-address.py
+++ b/examples/v3arch/asyncore/agent/ntforg/send-packet-from-specific-address.py
@@ -40,6 +40,7 @@ config.addTransport(
udp.DOMAIN_NAME,
udp.UdpSocketTransport().openClientMode(iface=('0.0.0.0', 61024))
)
+
config.addTargetAddr(
snmpEngine, 'my-nms',
udp.DOMAIN_NAME, ('104.236.166.95', 162),
diff --git a/examples/v3arch/asyncore/agent/ntforg/send-trap-to-multiple-managers.py b/examples/v3arch/asyncore/agent/ntforg/send-trap-to-multiple-managers.py
index 59065c17..4ea058f1 100644
--- a/examples/v3arch/asyncore/agent/ntforg/send-trap-to-multiple-managers.py
+++ b/examples/v3arch/asyncore/agent/ntforg/send-trap-to-multiple-managers.py
@@ -43,6 +43,7 @@ config.addTransport(
udp.DOMAIN_NAME,
udp.UdpSocketTransport().openClientMode()
)
+
# First target
config.addTargetAddr(
snmpEngine, 'my-nms-1',
@@ -50,6 +51,7 @@ config.addTargetAddr(
'my-creds',
tagList='all-my-managers'
)
+
# Second target
config.addTargetAddr(
snmpEngine, 'my-nms-2',
@@ -57,6 +59,7 @@ config.addTargetAddr(
'my-creds',
tagList='all-my-managers'
)
+
# Third target
config.addTargetAddr(
snmpEngine, 'my-nms-3',
diff --git a/examples/v3arch/asyncore/agent/ntforg/usm-md5-none.py b/examples/v3arch/asyncore/agent/ntforg/usm-md5-none.py
index 4e95455b..732c567a 100644
--- a/examples/v3arch/asyncore/agent/ntforg/usm-md5-none.py
+++ b/examples/v3arch/asyncore/agent/ntforg/usm-md5-none.py
@@ -30,6 +30,7 @@ config.addV3User(
snmpEngine, 'usr-md5-none',
config.USM_AUTH_HMAC96_MD5, 'authkey1'
)
+
config.addTargetParams(snmpEngine, 'my-creds', 'usr-md5-none', 'authNoPriv')
# Setup transport endpoint and bind it with security settings yielding
@@ -39,6 +40,7 @@ config.addTransport(
udp.DOMAIN_NAME,
udp.UdpSocketTransport().openClientMode()
)
+
config.addTargetAddr(
snmpEngine, 'my-nms',
udp.DOMAIN_NAME, ('104.236.166.95', 162),
@@ -69,9 +71,7 @@ ntfOrg = ntforg.NotificationOriginator()
def cbFun(snmpEngine, sendRequestHandle, errorIndication,
errorStatus, errorIndex, varBinds, cbCtx):
print('Notification %s, status - %s' % (
- sendRequestHandle, errorIndication and errorIndication or 'delivered'
- )
- )
+ sendRequestHandle, errorIndication and errorIndication or 'delivered'))
# Build and submit notification message to dispatcher
diff --git a/examples/v3arch/asyncore/agent/ntforg/v1-trap.py b/examples/v3arch/asyncore/agent/ntforg/v1-trap.py
index 9c0ba17e..24df282f 100644
--- a/examples/v3arch/asyncore/agent/ntforg/v1-trap.py
+++ b/examples/v3arch/asyncore/agent/ntforg/v1-trap.py
@@ -42,6 +42,7 @@ config.addTransport(
udp.DOMAIN_NAME,
udp.UdpSocketTransport().openClientMode()
)
+
config.addTargetAddr(
snmpEngine, 'my-nms',
udp.DOMAIN_NAME, ('104.236.166.95', 162),
diff --git a/examples/v3arch/asyncore/agent/ntforg/v2c-inform.py b/examples/v3arch/asyncore/agent/ntforg/v2c-inform.py
index 240f1426..752af9bf 100644
--- a/examples/v3arch/asyncore/agent/ntforg/v2c-inform.py
+++ b/examples/v3arch/asyncore/agent/ntforg/v2c-inform.py
@@ -41,6 +41,7 @@ config.addTransport(
udp.DOMAIN_NAME,
udp.UdpSocketTransport().openClientMode()
)
+
config.addTargetAddr(
snmpEngine, 'my-nms',
udp.DOMAIN_NAME, ('104.236.166.95', 162),
@@ -71,9 +72,7 @@ ntfOrg = ntforg.NotificationOriginator()
def cbFun(snmpEngine, sendRequestHandle, errorIndication,
errorStatus, errorIndex, varBinds, cbCtx):
print('Notification %s, status - %s' % (
- sendRequestHandle, errorIndication and errorIndication or 'delivered'
- )
- )
+ sendRequestHandle, errorIndication and errorIndication or 'delivered'))
# Build and submit notification message to dispatcher
diff --git a/examples/v3arch/asyncore/agent/ntforg/v2c-trap-with-notification-objects.py b/examples/v3arch/asyncore/agent/ntforg/v2c-trap-with-notification-objects.py
index f985786e..e8460490 100644
--- a/examples/v3arch/asyncore/agent/ntforg/v2c-trap-with-notification-objects.py
+++ b/examples/v3arch/asyncore/agent/ntforg/v2c-trap-with-notification-objects.py
@@ -38,6 +38,7 @@ from pysnmp.smi import rfc1902, view
# Agent runtime.
#
instanceIndex = (1,)
+
objects = {
('IF-MIB', 'ifIndex'): instanceIndex[0],
('IF-MIB', 'ifAdminStatus'): 'up',
@@ -66,6 +67,7 @@ config.addTransport(
udp.DOMAIN_NAME,
udp.UdpSocketTransport().openClientMode()
)
+
config.addTargetAddr(
snmpEngine, 'my-nms-1',
udp.DOMAIN_NAME, ('104.236.166.95', 162),
diff --git a/examples/v3arch/asyncore/agent/ntforg/v2c-trap.py b/examples/v3arch/asyncore/agent/ntforg/v2c-trap.py
index 8850e7d0..c3ebd2b5 100644
--- a/examples/v3arch/asyncore/agent/ntforg/v2c-trap.py
+++ b/examples/v3arch/asyncore/agent/ntforg/v2c-trap.py
@@ -40,6 +40,7 @@ config.addTransport(
udp.DOMAIN_NAME,
udp.UdpSocketTransport().openClientMode()
)
+
config.addTargetAddr(
snmpEngine, 'my-nms',
udp.DOMAIN_NAME, ('104.236.166.95', 162),
@@ -70,9 +71,7 @@ ntfOrg = ntforg.NotificationOriginator()
def cbFun(snmpEngine, sendRequestHandle, errorIndication,
errorStatus, errorIndex, varBinds, cbCtx):
print('Notification %s, status - %s' % (
- sendRequestHandle, errorIndication and errorIndication or 'delivered'
- )
- )
+ sendRequestHandle, errorIndication and errorIndication or 'delivered'))
# Build and submit notification message to dispatcher
diff --git a/examples/v3arch/asyncore/agent/ntforg/v3-trap.py b/examples/v3arch/asyncore/agent/ntforg/v3-trap.py
index 0502a153..0acc4a75 100644
--- a/examples/v3arch/asyncore/agent/ntforg/v3-trap.py
+++ b/examples/v3arch/asyncore/agent/ntforg/v3-trap.py
@@ -35,6 +35,7 @@ config.addV3User(
config.USM_AUTH_HMAC96_MD5, 'authkey1',
config.USM_PRIV_CBC56_DES, 'privkey1'
)
+
config.addTargetParams(snmpEngine, 'my-creds', 'usr-md5-des', 'authPriv')
# Setup transport endpoint and bind it with security settings yielding
@@ -44,6 +45,7 @@ config.addTransport(
udp.DOMAIN_NAME,
udp.UdpSocketTransport().openClientMode()
)
+
config.addTargetAddr(
snmpEngine, 'my-nms',
udp.DOMAIN_NAME, ('104.236.166.95', 162),
diff --git a/examples/v3arch/asyncore/manager/cmdgen/custom-contextengineid-and-contextname.py b/examples/v3arch/asyncore/manager/cmdgen/custom-contextengineid-and-contextname.py
index 2dc2ee8b..4ea68110 100644
--- a/examples/v3arch/asyncore/manager/cmdgen/custom-contextengineid-and-contextname.py
+++ b/examples/v3arch/asyncore/manager/cmdgen/custom-contextengineid-and-contextname.py
@@ -34,6 +34,7 @@ config.addV3User(
snmpEngine, 'usr-md5-none',
config.USM_AUTH_HMAC96_MD5, 'authkey1'
)
+
config.addTargetParams(snmpEngine, 'my-creds', 'usr-md5-none', 'authNoPriv')
#
@@ -47,6 +48,7 @@ config.addTransport(
udp.DOMAIN_NAME,
udp.UdpSocketTransport().openClientMode()
)
+
config.addTargetAddr(
snmpEngine, 'my-router',
udp.DOMAIN_NAME, ('104.236.166.95', 161),
@@ -60,9 +62,11 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication,
errorStatus, errorIndex, varBinds, cbCtx):
if errorIndication:
print(errorIndication)
+
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
+
else:
for oid, val in varBinds:
print('%s = %s' % (oid.prettyPrint(), val.prettyPrint()))
diff --git a/examples/v3arch/asyncore/manager/cmdgen/custom-timeout-and-retries.py b/examples/v3arch/asyncore/manager/cmdgen/custom-timeout-and-retries.py
index 45b8c7a6..b7e137b3 100644
--- a/examples/v3arch/asyncore/manager/cmdgen/custom-timeout-and-retries.py
+++ b/examples/v3arch/asyncore/manager/cmdgen/custom-timeout-and-retries.py
@@ -43,6 +43,7 @@ config.addTransport(
udp.DOMAIN_NAME,
udp.UdpSocketTransport().openClientMode()
)
+
config.addTargetAddr(
snmpEngine, 'my-router',
udp.DOMAIN_NAME, ('104.236.166.95', 161),
@@ -58,9 +59,11 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication,
errorStatus, errorIndex, varBinds, cbCtx):
if errorIndication:
print(errorIndication)
+
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
+
else:
for oid, val in varBinds:
print('%s = %s' % (oid.prettyPrint(), val.prettyPrint()))
diff --git a/examples/v3arch/asyncore/manager/cmdgen/fetch-variables-over-ipv6.py b/examples/v3arch/asyncore/manager/cmdgen/fetch-variables-over-ipv6.py
index 0a156d0f..de85e3db 100644
--- a/examples/v3arch/asyncore/manager/cmdgen/fetch-variables-over-ipv6.py
+++ b/examples/v3arch/asyncore/manager/cmdgen/fetch-variables-over-ipv6.py
@@ -44,6 +44,7 @@ config.addTransport(
udp6.DOMAIN_NAME,
udp6.Udp6SocketTransport().openClientMode()
)
+
config.addTargetAddr(
snmpEngine, 'my-router',
udp6.DOMAIN_NAME, ('::1', 161),
@@ -58,13 +59,17 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication,
if errorIndication:
print(errorIndication)
return
+
if errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBindTable[-1][int(errorIndex) - 1][0] or '?'))
return # stop on error
+
for varBindRow in varBindTable:
+
for oid, val in varBindRow:
print('%s = %s' % (oid.prettyPrint(), val.prettyPrint()))
+
return True # signal dispatcher to continue
diff --git a/examples/v3arch/asyncore/manager/cmdgen/getbulk-fetch-scalar-and-table-variables.py b/examples/v3arch/asyncore/manager/cmdgen/getbulk-fetch-scalar-and-table-variables.py
index 82e42879..499514f3 100644
--- a/examples/v3arch/asyncore/manager/cmdgen/getbulk-fetch-scalar-and-table-variables.py
+++ b/examples/v3arch/asyncore/manager/cmdgen/getbulk-fetch-scalar-and-table-variables.py
@@ -46,6 +46,7 @@ config.addTransport(
udp.DOMAIN_NAME,
udp.UdpSocketTransport().openClientMode()
)
+
config.addTargetAddr(
snmpEngine, 'my-router',
udp.DOMAIN_NAME, ('104.236.166.95', 161),
@@ -60,13 +61,16 @@ def cbFun(snmpEngine, sendRequesthandle, errorIndication,
if errorIndication:
print(errorIndication)
return # stop on error
+
if errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBindTable[-1][int(errorIndex) - 1][0] or '?'))
return # stop on error
+
for varBindRow in varBindTable:
for oid, val in varBindRow:
print('%s = %s' % (oid.prettyPrint(), val.prettyPrint()))
+
return True # signal dispatcher to continue walking
diff --git a/examples/v3arch/asyncore/manager/cmdgen/getbulk-multiple-oids-to-eom.py b/examples/v3arch/asyncore/manager/cmdgen/getbulk-multiple-oids-to-eom.py
index 125e3a72..98a4c42b 100644
--- a/examples/v3arch/asyncore/manager/cmdgen/getbulk-multiple-oids-to-eom.py
+++ b/examples/v3arch/asyncore/manager/cmdgen/getbulk-multiple-oids-to-eom.py
@@ -43,6 +43,7 @@ config.addTransport(
udp.DOMAIN_NAME,
udp.UdpSocketTransport().openClientMode()
)
+
config.addTargetAddr(
snmpEngine, 'my-router',
udp.DOMAIN_NAME, ('104.236.166.95', 161),
@@ -57,13 +58,16 @@ def cbFun(snmpEngine, sendRequesthandle, errorIndication,
if errorIndication:
print(errorIndication)
return # stop on error
+
if errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBindTable[-1][int(errorIndex) - 1][0] or '?'))
return # stop on error
+
for varBindRow in varBindTable:
for oid, val in varBindRow:
print('%s = %s' % (oid.prettyPrint(), val.prettyPrint()))
+
return True # signal dispatcher to continue walking
diff --git a/examples/v3arch/asyncore/manager/cmdgen/getnext-multiple-oids-and-resolve-with-mib.py b/examples/v3arch/asyncore/manager/cmdgen/getnext-multiple-oids-and-resolve-with-mib.py
index f01efec7..8fed28c1 100644
--- a/examples/v3arch/asyncore/manager/cmdgen/getnext-multiple-oids-and-resolve-with-mib.py
+++ b/examples/v3arch/asyncore/manager/cmdgen/getnext-multiple-oids-and-resolve-with-mib.py
@@ -54,6 +54,7 @@ config.addTransport(
udp.DOMAIN_NAME,
udp.UdpSocketTransport().openClientMode()
)
+
config.addTargetAddr(
snmpEngine, 'my-router',
udp.DOMAIN_NAME, ('104.236.166.95', 161),
@@ -68,17 +69,20 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication,
if errorIndication:
print(errorIndication)
return
+
# SNMPv1 response may contain noSuchName error *and* SNMPv2c exception,
# so we ignore noSuchName error here
if errorStatus and errorStatus != 2:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBindTable[-1][int(errorIndex) - 1][0] or '?'))
return # stop on error
+
for varBindRow in varBindTable:
for varBind in varBindRow:
print(rfc1902.ObjectType(rfc1902.ObjectIdentity(varBind[0]),
varBind[1]).resolveWithMib(mibViewController).prettyPrint())
- return 1 # signal dispatcher to continue
+
+ return True # signal dispatcher to continue
# Prepare initial request to be sent
diff --git a/examples/v3arch/asyncore/manager/cmdgen/getnext-multiple-oids-to-eom.py b/examples/v3arch/asyncore/manager/cmdgen/getnext-multiple-oids-to-eom.py
index c984a899..64e4e19f 100644
--- a/examples/v3arch/asyncore/manager/cmdgen/getnext-multiple-oids-to-eom.py
+++ b/examples/v3arch/asyncore/manager/cmdgen/getnext-multiple-oids-to-eom.py
@@ -43,6 +43,7 @@ config.addTransport(
udp.DOMAIN_NAME,
udp.UdpSocketTransport().openClientMode()
)
+
config.addTargetAddr(
snmpEngine, 'my-router',
udp.DOMAIN_NAME, ('104.236.166.95', 161),
@@ -57,16 +58,19 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication,
if errorIndication:
print(errorIndication)
return
+
# SNMPv1 response may contain noSuchName error *and* SNMPv2c exception,
# so we ignore noSuchName error here
if errorStatus and errorStatus != 2:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBindTable[-1][int(errorIndex) - 1][0] or '?'))
return # stop on error
+
for varBindRow in varBindTable:
for oid, val in varBindRow:
print('%s = %s' % (oid.prettyPrint(), val.prettyPrint()))
- return 1 # signal dispatcher to continue
+
+ return True # signal dispatcher to continue
# Prepare initial request to be sent
diff --git a/examples/v3arch/asyncore/manager/cmdgen/observe-request-processing.py b/examples/v3arch/asyncore/manager/cmdgen/observe-request-processing.py
index fccb1483..3a8b4f5a 100644
--- a/examples/v3arch/asyncore/manager/cmdgen/observe-request-processing.py
+++ b/examples/v3arch/asyncore/manager/cmdgen/observe-request-processing.py
@@ -59,6 +59,7 @@ config.addV3User(
config.USM_AUTH_HMAC96_SHA, 'authkey1',
config.USM_PRIV_CFB128_AES, 'privkey1'
)
+
config.addTargetParams(snmpEngine, 'my-creds', 'usr-sha-aes', 'authPriv')
#
@@ -72,6 +73,7 @@ config.addTransport(
udp.DOMAIN_NAME,
udp.UdpSocketTransport().openClientMode()
)
+
config.addTargetAddr(
snmpEngine, 'my-router',
udp.DOMAIN_NAME, ('104.236.166.95', 161),
@@ -85,9 +87,11 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication,
errorStatus, errorIndex, varBinds, cbCtx):
if errorIndication:
print(errorIndication)
+
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
+
else:
for oid, val in varBinds:
print('%s = %s' % (oid.prettyPrint(), val.prettyPrint()))
diff --git a/examples/v3arch/asyncore/manager/cmdgen/pull-subtree.py b/examples/v3arch/asyncore/manager/cmdgen/pull-subtree.py
index b1eb9ace..4233356b 100644
--- a/examples/v3arch/asyncore/manager/cmdgen/pull-subtree.py
+++ b/examples/v3arch/asyncore/manager/cmdgen/pull-subtree.py
@@ -33,6 +33,7 @@ snmpEngine = engine.SnmpEngine()
config.addV3User(
snmpEngine, 'usr-none-none',
)
+
config.addTargetParams(snmpEngine, 'my-creds', 'usr-none-none', 'noAuthNoPriv')
#
@@ -46,6 +47,7 @@ config.addTransport(
udp.DOMAIN_NAME,
udp.UdpSocketTransport().openClientMode()
)
+
config.addTargetAddr(
snmpEngine, 'my-router',
udp.DOMAIN_NAME, ('104.236.166.95', 161),
@@ -60,16 +62,20 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication,
if errorIndication:
print(errorIndication)
return
+
if errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBindTable[-1][int(errorIndex) - 1][0] or '?'))
- return # stop on error
+ return False # stop on error
+
for varBindRow in varBindTable:
for oid, val in varBindRow:
if initialOID.isPrefixOf(oid):
print('%s = %s' % (oid.prettyPrint(), val.prettyPrint()))
+
else:
return False # signal dispatcher to stop
+
return True # signal dispatcher to continue
diff --git a/examples/v3arch/asyncore/manager/cmdgen/send-packets-from-specific-interface.py b/examples/v3arch/asyncore/manager/cmdgen/send-packets-from-specific-interface.py
index ed5ec19f..9342df3e 100644
--- a/examples/v3arch/asyncore/manager/cmdgen/send-packets-from-specific-interface.py
+++ b/examples/v3arch/asyncore/manager/cmdgen/send-packets-from-specific-interface.py
@@ -44,6 +44,7 @@ config.addTransport(
udp.DOMAIN_NAME,
udp.UdpSocketTransport().openClientMode(('0.0.0.0', 61024))
)
+
config.addTargetAddr(
snmpEngine, 'my-router',
udp.DOMAIN_NAME, ('104.236.166.95', 161),
@@ -57,15 +58,18 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication,
errorStatus, errorIndex, varBindTable, cbCtx):
if errorIndication:
print(errorIndication)
- return
+ return False
+
if errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBindTable[-1][int(errorIndex) - 1][0] or '?'))
return # stop on error
+
for varBindRow in varBindTable:
for oid, val in varBindRow:
print('%s = %s' % (oid.prettyPrint(), val.prettyPrint()))
- return 1 # signal dispatcher to continue
+
+ return True # signal dispatcher to continue
# Prepare initial request to be sent
diff --git a/examples/v3arch/asyncore/manager/cmdgen/set-multiple-scalar-values.py b/examples/v3arch/asyncore/manager/cmdgen/set-multiple-scalar-values.py
index 173bdd91..c93e142b 100644
--- a/examples/v3arch/asyncore/manager/cmdgen/set-multiple-scalar-values.py
+++ b/examples/v3arch/asyncore/manager/cmdgen/set-multiple-scalar-values.py
@@ -43,6 +43,7 @@ config.addTransport(
udp.DOMAIN_NAME,
udp.UdpSocketTransport().openClientMode()
)
+
config.addTargetAddr(
snmpEngine, 'my-router',
udp.DOMAIN_NAME, ('104.236.166.95', 161),
@@ -56,11 +57,13 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication,
errorStatus, errorIndex, varBinds, cbCtx):
if errorIndication:
print(errorIndication)
+
# SNMPv1 response may contain noSuchName error *and* SNMPv2c exception,
# so we ignore noSuchName error here
elif errorStatus and errorStatus != 2:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
+
else:
for oid, val in varBinds:
print('%s = %s' % (oid.prettyPrint(), val.prettyPrint()))
diff --git a/examples/v3arch/asyncore/manager/cmdgen/spoof-source-address.py b/examples/v3arch/asyncore/manager/cmdgen/spoof-source-address.py
index 10050e3f..da7878f2 100644
--- a/examples/v3arch/asyncore/manager/cmdgen/spoof-source-address.py
+++ b/examples/v3arch/asyncore/manager/cmdgen/spoof-source-address.py
@@ -77,11 +77,13 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication,
errorStatus, errorIndex, varBinds, cbCtx):
if errorIndication:
print(errorIndication)
+
# SNMPv1 response may contain noSuchName error *and* SNMPv2c exception,
# so we ignore noSuchName error here
elif errorStatus and errorStatus != 2:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
+
else:
for oid, val in varBinds:
print('%s = %s' % (oid.prettyPrint(), val.prettyPrint()))
diff --git a/examples/v3arch/asyncore/manager/cmdgen/usm-sha-aes128.py b/examples/v3arch/asyncore/manager/cmdgen/usm-sha-aes128.py
index d65a018f..7fb95ead 100644
--- a/examples/v3arch/asyncore/manager/cmdgen/usm-sha-aes128.py
+++ b/examples/v3arch/asyncore/manager/cmdgen/usm-sha-aes128.py
@@ -30,6 +30,7 @@ config.addV3User(
config.USM_AUTH_HMAC96_SHA, 'authkey1',
config.USM_PRIV_CFB128_AES, 'privkey1'
)
+
config.addTargetParams(snmpEngine, 'my-creds', 'usr-sha-aes', 'authPriv')
#
@@ -43,6 +44,7 @@ config.addTransport(
udp.DOMAIN_NAME,
udp.UdpSocketTransport().openClientMode()
)
+
config.addTargetAddr(
snmpEngine, 'my-router',
udp.DOMAIN_NAME, ('104.236.166.95', 161),
@@ -56,9 +58,11 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication,
errorStatus, errorIndex, varBinds, cbCtx):
if errorIndication:
print(errorIndication)
+
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
+
else:
for oid, val in varBinds:
print('%s = %s' % (oid.prettyPrint(), val.prettyPrint()))
diff --git a/examples/v3arch/asyncore/manager/cmdgen/usm-sha-none.py b/examples/v3arch/asyncore/manager/cmdgen/usm-sha-none.py
index 43c5dade..2eba8949 100644
--- a/examples/v3arch/asyncore/manager/cmdgen/usm-sha-none.py
+++ b/examples/v3arch/asyncore/manager/cmdgen/usm-sha-none.py
@@ -44,6 +44,7 @@ config.addTransport(
udp.DOMAIN_NAME,
udp.UdpSocketTransport().openClientMode()
)
+
config.addTargetAddr(
snmpEngine, 'my-router',
udp.DOMAIN_NAME, ('104.236.166.95', 161),
@@ -57,9 +58,11 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication,
errorStatus, errorIndex, varBinds, cbCtx):
if errorIndication:
print(errorIndication)
+
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
+
else:
for oid, val in varBinds:
print('%s = %s' % (oid.prettyPrint(), val.prettyPrint()))
diff --git a/examples/v3arch/asyncore/manager/cmdgen/v1-get.py b/examples/v3arch/asyncore/manager/cmdgen/v1-get.py
index 60d25f5e..20eab6c7 100644
--- a/examples/v3arch/asyncore/manager/cmdgen/v1-get.py
+++ b/examples/v3arch/asyncore/manager/cmdgen/v1-get.py
@@ -40,6 +40,7 @@ config.addTransport(
udp.DOMAIN_NAME,
udp.UdpSocketTransport().openClientMode()
)
+
config.addTargetAddr(
snmpEngine, 'my-router',
udp.DOMAIN_NAME, ('104.236.166.95', 161),
@@ -53,11 +54,13 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication,
errorStatus, errorIndex, varBinds, cbCtx):
if errorIndication:
print(errorIndication)
+
# SNMPv1 response may contain noSuchName error *and* SNMPv2c exception,
# so we ignore noSuchName error here
elif errorStatus and errorStatus != 2:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
+
else:
for oid, val in varBinds:
print('%s = %s' % (oid.prettyPrint(), val.prettyPrint()))
diff --git a/examples/v3arch/asyncore/manager/cmdgen/v2c-set.py b/examples/v3arch/asyncore/manager/cmdgen/v2c-set.py
index 61657677..8e6a1168 100644
--- a/examples/v3arch/asyncore/manager/cmdgen/v2c-set.py
+++ b/examples/v3arch/asyncore/manager/cmdgen/v2c-set.py
@@ -42,6 +42,7 @@ config.addTransport(
udp.DOMAIN_NAME,
udp.UdpSocketTransport().openClientMode()
)
+
config.addTargetAddr(
snmpEngine, 'my-router',
udp.DOMAIN_NAME, ('104.236.166.95', 161),
@@ -55,9 +56,11 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication,
errorStatus, errorIndex, varBinds, cbCtx):
if errorIndication:
print(errorIndication)
+
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
+
else:
for oid, val in varBinds:
print('%s = %s' % (oid.prettyPrint(), val.prettyPrint()))
diff --git a/examples/v3arch/asyncore/manager/ntfrcv/determine-peer-network-address.py b/examples/v3arch/asyncore/manager/ntfrcv/determine-peer-network-address.py
index 3d3052a7..877d84df 100644
--- a/examples/v3arch/asyncore/manager/ntfrcv/determine-peer-network-address.py
+++ b/examples/v3arch/asyncore/manager/ntfrcv/determine-peer-network-address.py
@@ -49,9 +49,10 @@ def cbFun(snmpEngine, stateReference, contextEngineId, contextName,
)
# ... and use inner SNMP engine data to figure out peer address
- print('Notification from %s, ContextEngineId "%s", ContextName "%s"' % ('@'.join([str(x) for x in execContext['transportAddress']]),
- contextEngineId.prettyPrint(),
- contextName.prettyPrint()))
+ print('Notification from %s, ContextEngineId "%s", '
+ 'ContextName "%s"' % ('@'.join([str(x) for x in execContext['transportAddress']]),
+ contextEngineId.prettyPrint(),
+ contextName.prettyPrint()))
for name, val in varBinds:
print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
@@ -64,6 +65,6 @@ snmpEngine.transportDispatcher.jobStarted(1) # this job would never finish
# Run I/O dispatcher which would receive queries and send confirmations
try:
snmpEngine.transportDispatcher.runDispatcher()
-except:
+
+finally:
snmpEngine.transportDispatcher.closeDispatcher()
- raise
diff --git a/examples/v3arch/asyncore/manager/ntfrcv/multiple-network-interfaces.py b/examples/v3arch/asyncore/manager/ntfrcv/multiple-network-interfaces.py
index 4aae9b66..74ebba45 100644
--- a/examples/v3arch/asyncore/manager/ntfrcv/multiple-network-interfaces.py
+++ b/examples/v3arch/asyncore/manager/ntfrcv/multiple-network-interfaces.py
@@ -65,6 +65,6 @@ snmpEngine.transportDispatcher.jobStarted(1) # this job would never finish
# Run I/O dispatcher which would receive queries and send confirmations
try:
snmpEngine.transportDispatcher.runDispatcher()
-except:
+
+finally:
snmpEngine.transportDispatcher.closeDispatcher()
- raise
diff --git a/examples/v3arch/asyncore/manager/ntfrcv/multiple-network-transports-incl-ipv4-and-ipv6.py b/examples/v3arch/asyncore/manager/ntfrcv/multiple-network-transports-incl-ipv4-and-ipv6.py
index 98f8ebd4..83dbad56 100644
--- a/examples/v3arch/asyncore/manager/ntfrcv/multiple-network-transports-incl-ipv4-and-ipv6.py
+++ b/examples/v3arch/asyncore/manager/ntfrcv/multiple-network-transports-incl-ipv4-and-ipv6.py
@@ -66,6 +66,6 @@ snmpEngine.transportDispatcher.jobStarted(1) # this job would never finish
# Run I/O dispatcher which would receive queries and send confirmations
try:
snmpEngine.transportDispatcher.runDispatcher()
-except:
+
+finally:
snmpEngine.transportDispatcher.closeDispatcher()
- raise
diff --git a/examples/v3arch/asyncore/manager/ntfrcv/multiple-usm-users.py b/examples/v3arch/asyncore/manager/ntfrcv/multiple-usm-users.py
index fd40aaf3..459ae3d7 100644
--- a/examples/v3arch/asyncore/manager/ntfrcv/multiple-usm-users.py
+++ b/examples/v3arch/asyncore/manager/ntfrcv/multiple-usm-users.py
@@ -87,6 +87,6 @@ snmpEngine.transportDispatcher.jobStarted(1) # this job would never finish
# Run I/O dispatcher which would receive queries and send confirmations
try:
snmpEngine.transportDispatcher.runDispatcher()
-except:
+
+finally:
snmpEngine.transportDispatcher.closeDispatcher()
- raise
diff --git a/examples/v3arch/asyncore/manager/ntfrcv/observe-request-processing-over-ipv4-and-ipv6.py b/examples/v3arch/asyncore/manager/ntfrcv/observe-request-processing-over-ipv4-and-ipv6.py
index a8d84813..53658f86 100644
--- a/examples/v3arch/asyncore/manager/ntfrcv/observe-request-processing-over-ipv4-and-ipv6.py
+++ b/examples/v3arch/asyncore/manager/ntfrcv/observe-request-processing-over-ipv4-and-ipv6.py
@@ -91,7 +91,7 @@ snmpEngine.transportDispatcher.jobStarted(1) # this job would never finish
# Run I/O dispatcher which would receive queries and send confirmations
try:
snmpEngine.transportDispatcher.runDispatcher()
-except:
+
+finally:
snmpEngine.observer.unregisterObserver()
snmpEngine.transportDispatcher.closeDispatcher()
- raise
diff --git a/examples/v3arch/asyncore/manager/ntfrcv/regexp-community-name.py b/examples/v3arch/asyncore/manager/ntfrcv/regexp-community-name.py
index b4a6fa0c..5ef940cc 100644
--- a/examples/v3arch/asyncore/manager/ntfrcv/regexp-community-name.py
+++ b/examples/v3arch/asyncore/manager/ntfrcv/regexp-community-name.py
@@ -71,8 +71,10 @@ config.addV1System(snmpEngine, 'my-area', 'public')
# noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal
def cbFun(snmpEngine, stateReference, contextEngineId, contextName,
varBinds, cbCtx):
- print('Notification from ContextEngineId "%s", ContextName "%s"' % (contextEngineId.prettyPrint(),
- contextName.prettyPrint()))
+ print('Notification from ContextEngineId "%s", '
+ 'ContextName "%s"' % (contextEngineId.prettyPrint(),
+ contextName.prettyPrint()))
+
for name, val in varBinds:
print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
@@ -85,6 +87,6 @@ snmpEngine.transportDispatcher.jobStarted(1) # this job would never finish
# Run I/O dispatcher which would receive queries and send confirmations
try:
snmpEngine.transportDispatcher.runDispatcher()
-except:
+
+finally:
snmpEngine.transportDispatcher.closeDispatcher()
- raise
diff --git a/examples/v3arch/asyncore/proxy/command/ipv6-to-ipv4-conversion.py b/examples/v3arch/asyncore/proxy/command/ipv6-to-ipv4-conversion.py
index 2d7e0b3b..2abb1c51 100644
--- a/examples/v3arch/asyncore/proxy/command/ipv6-to-ipv4-conversion.py
+++ b/examples/v3arch/asyncore/proxy/command/ipv6-to-ipv4-conversion.py
@@ -79,6 +79,7 @@ config.addV1System(snmpEngine, '0-distant-area', 'public', transportTag='remote'
config.addTargetParams(
snmpEngine, 'distant-agent-auth', '0-distant-area', 'noAuthNoPriv', 1
)
+
config.addTargetAddr(
snmpEngine, 'distant-agent',
udp.DOMAIN_NAME, ('104.236.166.95', 161),
@@ -90,13 +91,13 @@ config.addContext(snmpEngine, '')
class CommandResponder(cmdrsp.CommandResponderBase):
- cmdGenMap = {
+ CMDGEN_MAP = {
v2c.GetRequestPDU.tagSet: cmdgen.GetCommandGenerator(),
v2c.SetRequestPDU.tagSet: cmdgen.SetCommandGenerator(),
v2c.GetNextRequestPDU.tagSet: cmdgen.NextCommandGeneratorSingleRun(),
v2c.GetBulkRequestPDU.tagSet: cmdgen.BulkCommandGeneratorSingleRun()
}
- SUPPORTED_PDU_TYPES = cmdGenMap.keys() # This app will handle these PDUs
+ SUPPORTED_PDU_TYPES = tuple(CMDGEN_MAP) # This app will handle these PDUs
# SNMP request relay
def handleMgmtOperation(self, snmpEngine, stateReference, contextName,
@@ -104,12 +105,13 @@ class CommandResponder(cmdrsp.CommandResponderBase):
cbCtx = stateReference, PDU
contextEngineId = None # address authoritative SNMP Engine
try:
- self.cmdGenMap[PDU.tagSet].sendPdu(
+ self.CMDGEN_MAP[PDU.tagSet].sendPdu(
snmpEngine, 'distant-agent',
contextEngineId, contextName,
PDU,
self.handleResponsePdu, cbCtx
)
+
except error.PySnmpError:
self.handleResponsePdu(
snmpEngine, stateReference, 'error', None, cbCtx
@@ -139,6 +141,6 @@ snmpEngine.transportDispatcher.jobStarted(1) # this job would never finish
# Run I/O dispatcher which would receive queries and send responses
try:
snmpEngine.transportDispatcher.runDispatcher()
-except:
+
+finally:
snmpEngine.transportDispatcher.closeDispatcher()
- raise
diff --git a/examples/v3arch/asyncore/proxy/command/v2c-to-v1-conversion.py b/examples/v3arch/asyncore/proxy/command/v2c-to-v1-conversion.py
index 69916cb0..b56e7734 100644
--- a/examples/v3arch/asyncore/proxy/command/v2c-to-v1-conversion.py
+++ b/examples/v3arch/asyncore/proxy/command/v2c-to-v1-conversion.py
@@ -89,13 +89,13 @@ config.addContext(snmpEngine, '')
class CommandResponder(cmdrsp.CommandResponderBase):
- cmdGenMap = {
+ CMDGEN_MAP = {
v2c.GetRequestPDU.tagSet: cmdgen.GetCommandGenerator(),
v2c.SetRequestPDU.tagSet: cmdgen.SetCommandGenerator(),
v2c.GetNextRequestPDU.tagSet: cmdgen.NextCommandGeneratorSingleRun(),
v2c.GetBulkRequestPDU.tagSet: cmdgen.BulkCommandGeneratorSingleRun()
}
- SUPPORTED_PDU_TYPES = cmdGenMap.keys() # This app will handle these PDUs
+ SUPPORTED_PDU_TYPES = tuple(CMDGEN_MAP) # This app will handle these PDUs
# SNMP request relay
def handleMgmtOperation(self, snmpEngine, stateReference, contextName,
@@ -103,12 +103,13 @@ class CommandResponder(cmdrsp.CommandResponderBase):
cbCtx = stateReference, PDU
contextEngineId = None # address authoritative SNMP Engine
try:
- self.cmdGenMap[PDU.tagSet].sendPdu(
+ self.CMDGEN_MAP[PDU.tagSet].sendPdu(
snmpEngine, 'distant-agent',
contextEngineId, contextName,
PDU,
self.handleResponsePdu, cbCtx
)
+
except error.PySnmpError:
self.handleResponsePdu(
snmpEngine, stateReference, 'error', None, cbCtx
@@ -138,6 +139,6 @@ snmpEngine.transportDispatcher.jobStarted(1) # this job would never finish
# Run I/O dispatcher which would receive queries and send responses
try:
snmpEngine.transportDispatcher.runDispatcher()
-except:
+
+finally:
snmpEngine.transportDispatcher.closeDispatcher()
- raise
diff --git a/examples/v3arch/asyncore/proxy/command/v2c-to-v3-conversion.py b/examples/v3arch/asyncore/proxy/command/v2c-to-v3-conversion.py
index 3e370e3c..46e3738f 100644
--- a/examples/v3arch/asyncore/proxy/command/v2c-to-v3-conversion.py
+++ b/examples/v3arch/asyncore/proxy/command/v2c-to-v3-conversion.py
@@ -78,6 +78,7 @@ config.addV3User(
config.addTargetParams(
snmpEngine, 'distant-agent-auth', 'usr-md5-none', 'authNoPriv'
)
+
config.addTargetAddr(
snmpEngine, 'distant-agent',
udp.DOMAIN_NAME + (2,), ('104.236.166.95', 161),
@@ -89,26 +90,28 @@ config.addContext(snmpEngine, '')
class CommandResponder(cmdrsp.CommandResponderBase):
- cmdGenMap = {
+ CMDGEN_MAP = {
v2c.GetRequestPDU.tagSet: cmdgen.GetCommandGenerator(),
v2c.SetRequestPDU.tagSet: cmdgen.SetCommandGenerator(),
v2c.GetNextRequestPDU.tagSet: cmdgen.NextCommandGeneratorSingleRun(),
v2c.GetBulkRequestPDU.tagSet: cmdgen.BulkCommandGeneratorSingleRun()
}
- SUPPORTED_PDU_TYPES = cmdGenMap.keys() # This app will handle these PDUs
+ SUPPORTED_PDU_TYPES = tuple(CMDGEN_MAP) # This app will handle these PDUs
# SNMP request relay
def handleMgmtOperation(self, snmpEngine, stateReference, contextName,
PDU, acInfo):
cbCtx = stateReference, PDU
contextEngineId = None # address authoritative SNMP Engine
+
try:
- self.cmdGenMap[PDU.tagSet].sendPdu(
+ self.CMDGEN_MAP[PDU.tagSet].sendPdu(
snmpEngine, 'distant-agent',
contextEngineId, contextName,
PDU,
self.handleResponsePdu, cbCtx
)
+
except error.PySnmpError:
self.handleResponsePdu(
snmpEngine, stateReference, 'error', None, cbCtx
@@ -138,6 +141,6 @@ snmpEngine.transportDispatcher.jobStarted(1) # this job would never finish
# Run I/O dispatcher which would receive queries and send responses
try:
snmpEngine.transportDispatcher.runDispatcher()
-except:
+
+finally:
snmpEngine.transportDispatcher.closeDispatcher()
- raise
diff --git a/examples/v3arch/asyncore/proxy/command/v3-to-v2c-conversion.py b/examples/v3arch/asyncore/proxy/command/v3-to-v2c-conversion.py
index 4794f49c..5a2443f3 100644
--- a/examples/v3arch/asyncore/proxy/command/v3-to-v2c-conversion.py
+++ b/examples/v3arch/asyncore/proxy/command/v3-to-v2c-conversion.py
@@ -92,13 +92,14 @@ config.addContext(snmpEngine, '')
class CommandResponder(cmdrsp.CommandResponderBase):
- cmdGenMap = {
+ CMDGEN_MAP = {
v2c.GetRequestPDU.tagSet: cmdgen.GetCommandGenerator(),
v2c.SetRequestPDU.tagSet: cmdgen.SetCommandGenerator(),
v2c.GetNextRequestPDU.tagSet: cmdgen.NextCommandGeneratorSingleRun(),
v2c.GetBulkRequestPDU.tagSet: cmdgen.BulkCommandGeneratorSingleRun()
}
- SUPPORTED_PDU_TYPES = cmdGenMap.keys() # This app will handle these PDUs
+
+ SUPPORTED_PDU_TYPES = tuple(CMDGEN_MAP) # This app will handle these PDUs
# SNMP request relay
def handleMgmtOperation(self, snmpEngine, stateReference, contextName,
@@ -106,12 +107,13 @@ class CommandResponder(cmdrsp.CommandResponderBase):
cbCtx = stateReference, PDU
contextEngineId = None # address authoritative SNMP Engine
try:
- self.cmdGenMap[PDU.tagSet].sendPdu(
+ self.CMDGEN_MAP[PDU.tagSet].sendPdu(
snmpEngine, 'distant-agent',
contextEngineId, contextName,
PDU,
self.handleResponsePdu, cbCtx
)
+
except error.PySnmpError:
self.handleResponsePdu(
snmpEngine, stateReference, 'error', None, cbCtx
@@ -139,6 +141,6 @@ snmpEngine.transportDispatcher.jobStarted(1) # this job would never finish
# Run I/O dispatcher which would receive queries and send responses
try:
snmpEngine.transportDispatcher.runDispatcher()
-except:
+
+finally:
snmpEngine.transportDispatcher.closeDispatcher()
- raise
diff --git a/examples/v3arch/twisted/manager/ntfrcv/multiple-interfaces.py b/examples/v3arch/twisted/manager/ntfrcv/multiple-interfaces.py
index f5839302..76eacbe3 100644
--- a/examples/v3arch/twisted/manager/ntfrcv/multiple-interfaces.py
+++ b/examples/v3arch/twisted/manager/ntfrcv/multiple-interfaces.py
@@ -54,8 +54,9 @@ config.addV1System(snmpEngine, 'my-area', 'public')
# noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal
def cbFun(snmpEngine, stateReference, contextEngineId, contextName,
varBinds, cbCtx):
- print('Notification from ContextEngineId "%s", Context "%s"' % (contextEngineId.prettyPrint(),
- contextName.prettyPrint()))
+ print('Notification from ContextEngineId "%s", '
+ 'Context "%s"' % (contextEngineId.prettyPrint(),
+ contextName.prettyPrint()))
for name, val in varBinds:
print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
diff --git a/examples/v3arch/twisted/manager/ntfrcv/multiple-usm-users.py b/examples/v3arch/twisted/manager/ntfrcv/multiple-usm-users.py
index eef2f014..a9ec8cb4 100644
--- a/examples/v3arch/twisted/manager/ntfrcv/multiple-usm-users.py
+++ b/examples/v3arch/twisted/manager/ntfrcv/multiple-usm-users.py
@@ -95,8 +95,9 @@ config.addV3User(
# noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal
def cbFun(snmpEngine, stateReference, contextEngineId, contextName,
varBinds, cbCtx):
- print('Notification from ContextEngineId "%s", ContextName "%s"' % (contextEngineId.prettyPrint(),
- contextName.prettyPrint()))
+ print('Notification from ContextEngineId "%s", '
+ 'ContextName "%s"' % (contextEngineId.prettyPrint(),
+ contextName.prettyPrint()))
for name, val in varBinds:
print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))