summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorelie <elie>2015-09-27 10:26:25 +0000
committerelie <elie>2015-09-27 10:26:25 +0000
commit627d9ff4a3715477e56fe397f099ad0db0d5c1b9 (patch)
tree60cdd6f446e892194122abad0dfa4c6413eb4374 /examples
parentbdfbce73382678e0288d8bc8d3093c827b05e1d1 (diff)
downloadpysnmp-627d9ff4a3715477e56fe397f099ad0db0d5c1b9.tar.gz
* Asyncore and asyncio-based APIs reworked to become functions.
* Asyncio and Twisted API moved entirely into high-level domain to be aligned with other high-level APIs. This WILL BREAK backward compatibility for those apps that use Twisted API.
Diffstat (limited to 'examples')
-rw-r--r--examples/hlapi/asyncio/agent/ntforg/default-v1-trap.py54
-rw-r--r--examples/hlapi/asyncio/agent/ntforg/multiple-notifications-at-once.py55
-rw-r--r--examples/hlapi/asyncio/manager/cmdgen/getbulk-to-eom.py59
-rw-r--r--examples/hlapi/asyncio/manager/cmdgen/multiple-concurrent-async-queries.py52
-rw-r--r--examples/hlapi/asyncio/manager/cmdgen/multiple-sequential-async-queries.py55
-rw-r--r--examples/hlapi/asyncio/manager/cmdgen/v1-get.py46
-rw-r--r--examples/hlapi/asyncore/agent/ntforg/async-multiple-informs-at-once.py6
-rw-r--r--examples/hlapi/asyncore/agent/ntforg/async-multiple-traps-at-once.py6
-rw-r--r--examples/hlapi/asyncore/agent/ntforg/async-running-multiple-snmp-engines-at-once.py6
-rw-r--r--examples/hlapi/asyncore/agent/ntforg/custom-contextengineid.py6
-rw-r--r--examples/hlapi/asyncore/agent/ntforg/custom-contextname.py2
-rw-r--r--examples/hlapi/asyncore/agent/ntforg/custom-v1-trap.py4
-rw-r--r--examples/hlapi/asyncore/agent/ntforg/default-v1-trap.py4
-rw-r--r--examples/hlapi/asyncore/agent/ntforg/send-notification-with-additional-varbinds.py2
-rw-r--r--examples/hlapi/asyncore/agent/ntforg/v2c-trap-via-notification-type.py4
-rw-r--r--examples/hlapi/asyncore/agent/ntforg/v3-inform.py2
-rw-r--r--examples/hlapi/asyncore/agent/ntforg/v3-trap.py2
-rw-r--r--examples/hlapi/asyncore/manager/cmdgen/async-pull-mibs-from-multiple-agents-at-once.py21
-rw-r--r--examples/hlapi/asyncore/manager/cmdgen/async-query-multiple-snmp-engines.py8
-rw-r--r--examples/hlapi/asyncore/manager/cmdgen/coerce-set-value-to-mib-spec.py2
-rw-r--r--examples/hlapi/asyncore/manager/cmdgen/custom-asn1-mib-search-path.py2
-rw-r--r--examples/hlapi/asyncore/manager/cmdgen/custom-contextengineid-and-contextname.py2
-rw-r--r--examples/hlapi/asyncore/manager/cmdgen/custom-contextengineid.py2
-rw-r--r--examples/hlapi/asyncore/manager/cmdgen/custom-pysnmp-mibs-search-path.py2
-rw-r--r--examples/hlapi/asyncore/manager/cmdgen/custom-timeout-and-retries.py6
-rw-r--r--examples/hlapi/asyncore/manager/cmdgen/custom-v3-security-name.py2
-rw-r--r--examples/hlapi/asyncore/manager/cmdgen/fetch-variables-over-ipv6.py2
-rw-r--r--examples/hlapi/asyncore/manager/cmdgen/get-table-object-by-index.py2
-rw-r--r--examples/hlapi/asyncore/manager/cmdgen/get-table-object-by-multiple-indices.py2
-rw-r--r--examples/hlapi/asyncore/manager/cmdgen/getbulk-fetch-scalar-and-table-variables.py2
-rw-r--r--examples/hlapi/asyncore/manager/cmdgen/getbulk-limit-number-of-packets.py2
-rw-r--r--examples/hlapi/asyncore/manager/cmdgen/getbulk-limit-number-of-variables.py2
-rw-r--r--examples/hlapi/asyncore/manager/cmdgen/getnext-limit-number-of-variables.py2
-rw-r--r--examples/hlapi/asyncore/manager/cmdgen/getnext-multiple-oids-to-eom.py2
-rw-r--r--examples/hlapi/asyncore/manager/cmdgen/multiple-concurrent-async-queries.py9
-rw-r--r--examples/hlapi/asyncore/manager/cmdgen/multiple-get-calls.py2
-rw-r--r--examples/hlapi/asyncore/manager/cmdgen/preload-pysnmp-mibs.py2
-rw-r--r--examples/hlapi/asyncore/manager/cmdgen/pull-whole-mib.py6
-rw-r--r--examples/hlapi/asyncore/manager/cmdgen/pull-whole-snmp-table.py2
-rw-r--r--examples/hlapi/asyncore/manager/cmdgen/query-agents-from-multuple-threads.py2
-rw-r--r--examples/hlapi/asyncore/manager/cmdgen/set-multiple-scalar-values.py2
-rw-r--r--examples/hlapi/asyncore/manager/cmdgen/specific-v3-engine-id.py2
-rw-r--r--examples/hlapi/asyncore/manager/cmdgen/usm-md5-des.py2
-rw-r--r--examples/hlapi/asyncore/manager/cmdgen/usm-md5-none.py2
-rw-r--r--examples/hlapi/asyncore/manager/cmdgen/usm-none-none.py2
-rw-r--r--examples/hlapi/asyncore/manager/cmdgen/usm-sha-aes128.py2
-rw-r--r--examples/hlapi/asyncore/manager/cmdgen/v1-get.py2
-rw-r--r--examples/hlapi/asyncore/manager/cmdgen/v2c-get.py2
-rw-r--r--examples/hlapi/asyncore/manager/cmdgen/v2c-getbulk.py2
-rw-r--r--examples/hlapi/asyncore/manager/cmdgen/waive-mib-lookup.py2
-rw-r--r--examples/hlapi/trollius/agent/ntforg/default-v1-trap.py58
-rw-r--r--examples/hlapi/trollius/manager/cmdgen/getbulk-to-eom.py60
-rw-r--r--examples/hlapi/trollius/manager/cmdgen/v1-get.py47
-rw-r--r--examples/hlapi/twisted/agent/ntforg/default-v1-trap.py64
-rw-r--r--examples/hlapi/twisted/agent/ntforg/multiple-notifications-at-once.py73
-rw-r--r--examples/hlapi/twisted/manager/cmdgen/custom-timeout-and-retries.py49
-rw-r--r--examples/hlapi/twisted/manager/cmdgen/getbulk-to-eom.py52
-rw-r--r--examples/hlapi/twisted/manager/cmdgen/multiple-concurrent-async-queries.py56
-rw-r--r--examples/hlapi/twisted/manager/cmdgen/pull-mibs-from-multiple-agents-at-once.py61
-rw-r--r--examples/hlapi/twisted/manager/cmdgen/pull-whole-mib.py50
-rw-r--r--examples/hlapi/twisted/manager/cmdgen/v1-get.py47
61 files changed, 997 insertions, 91 deletions
diff --git a/examples/hlapi/asyncio/agent/ntforg/default-v1-trap.py b/examples/hlapi/asyncio/agent/ntforg/default-v1-trap.py
new file mode 100644
index 0000000..20cee83
--- /dev/null
+++ b/examples/hlapi/asyncio/agent/ntforg/default-v1-trap.py
@@ -0,0 +1,54 @@
+"""
+SNMPv1 TRAP with defaults
++++++++++++++++++++++++++
+
+Send SNMPv1 TRAP through unified SNMPv3 message processing framework
+using the following options:
+
+* SNMPv1
+* with community name 'public'
+* over IPv4/UDP
+* send TRAP notification
+* with Generic Trap #1 (warmStart) and Specific Trap 0
+* with default Uptime
+* with default Agent Address
+* with Enterprise OID 1.3.6.1.4.1.20408.4.1.1.2
+* include managed object information '1.3.6.1.2.1.1.1.0' = 'my system'
+
+Functionally similar to:
+
+| $ snmptrap -v1 -c public demo.snmplabs.com \
+| 1.3.6.1.4.1.20408.4.1.1.2 \
+| 0.0.0.0 \
+| 1 \
+| 0 \
+| 0
+| '1.3.6.1.2.1.1.1.0' s 'my system'
+
+"""#
+import asyncio
+from pysnmp.hlapi.asyncio import *
+
+@asyncio.coroutine
+def run():
+ snmpEngine = SnmpEngine()
+ errorIndication, errorStatus, errorIndex, varBinds = yield from sendNotification(
+ snmpEngine,
+ CommunityData('public'), # mpModel=0),
+ UdpTransportTarget(('localhost', 162)),
+ ContextData(),
+ 'inform',
+ 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'))
+ )
+ )
+
+ if errorIndication:
+ print(errorIndication)
+
+ snmpEngine.transportDispatcher.closeDispatcher()
+
+asyncio.get_event_loop().run_until_complete(run())
diff --git a/examples/hlapi/asyncio/agent/ntforg/multiple-notifications-at-once.py b/examples/hlapi/asyncio/agent/ntforg/multiple-notifications-at-once.py
new file mode 100644
index 0000000..a67e374
--- /dev/null
+++ b/examples/hlapi/asyncio/agent/ntforg/multiple-notifications-at-once.py
@@ -0,0 +1,55 @@
+"""
+Multiple concurrent notifications
++++++++++++++++++++++++++++++++++
+
+Send multiple SNMP notifications at once using the following options:
+
+* SNMPv2c and SNMPv3
+* with community name 'public'
+* over IPv4/UDP
+* send INFORM notification
+* to multiple Managers
+* with TRAP ID 'coldStart' specified as a MIB symbol
+* include managed object information specified as var-bind objects pair
+
+Here we tag each SNMP-COMMUNITY-MIB::snmpCommunityTable row
+with the same tag as SNMP-TARGET-MIB::snmpTargetAddrTable row
+what leads to excessive tables information.
+
+Functionally similar to:
+
+| $ snmptrap -v2c -c public demo.snmplabs.com 12345 1.3.6.1.6.3.1.1.5.2
+| $ snmpinform -v2c -c public localhost 12345 1.3.6.1.6.3.1.1.5.2
+| $ snmptrap -v2c -c public demo.snmplabs.com 12345 1.3.6.1.6.3.1.1.5.2
+
+"""#
+import asyncio
+from pysnmp.hlapi.asyncio import *
+
+@asyncio.coroutine
+def sendone(snmpEngine, hostname, notifyType):
+ errorIndication, errorStatus, \
+ errorIndex, varBinds = yield from sendNotification(
+ snmpEngine,
+ CommunityData('public', tag=hostname),
+ UdpTransportTarget((hostname, 162), tagList=hostname),
+ ContextData(),
+ notifyType,
+ 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'))
+ )
+ )
+
+ if errorIndication:
+ print(errorIndication)
+
+snmpEngine = SnmpEngine()
+
+loop = asyncio.get_event_loop()
+loop.run_until_complete(
+ asyncio.wait([sendone(snmpEngine, 'demo.snmplabs.com', 'trap'),
+ sendone(snmpEngine, 'localhost', 'inform')])
+)
diff --git a/examples/hlapi/asyncio/manager/cmdgen/getbulk-to-eom.py b/examples/hlapi/asyncio/manager/cmdgen/getbulk-to-eom.py
new file mode 100644
index 0000000..c555683
--- /dev/null
+++ b/examples/hlapi/asyncio/manager/cmdgen/getbulk-to-eom.py
@@ -0,0 +1,59 @@
+"""
+Bulk walk MIB
++++++++++++++
+
+Send a series of SNMP GETBULK requests using the following options:
+
+* with SNMPv3, user 'usr-none-none', no authentication, no privacy
+* over IPv4/UDP
+* to an Agent at demo.snmplabs.com:161
+* for all OIDs past SNMPv2-MIB::system
+* run till end-of-mib condition is reported by Agent
+* based on asyncio I/O framework
+
+Functionally similar to:
+
+| $ snmpbulkwalk -v3 -lnoAuthNoPriv -u usr-none-none -Cn0 -Cr50 \
+| demo.snmplabs.com SNMPv2-MIB::system
+
+"""#
+import asyncio
+from pysnmp.hlapi.asyncio import *
+
+@asyncio.coroutine
+def run(varBinds):
+ snmpEngine = SnmpEngine()
+ while True:
+ errorIndication, errorStatus, errorIndex, \
+ varBindTable = yield from bulkCmd(
+ snmpEngine,
+ UsmUserData('usr-none-none'),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ ContextData(),
+ 0, 50,
+ *varBinds)
+
+ 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
+
+ snmpEngine.transportDispatcher.closeDispatcher()
+
+loop = asyncio.get_event_loop()
+loop.run_until_complete(
+ run([ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr'))])
+)
diff --git a/examples/hlapi/asyncio/manager/cmdgen/multiple-concurrent-async-queries.py b/examples/hlapi/asyncio/manager/cmdgen/multiple-concurrent-async-queries.py
new file mode 100644
index 0000000..81de80a
--- /dev/null
+++ b/examples/hlapi/asyncio/manager/cmdgen/multiple-concurrent-async-queries.py
@@ -0,0 +1,52 @@
+"""
+Concurrent queries
+++++++++++++++++++
+
+Send multiple SNMP GET requests at once using the following options:
+
+* with SNMPv2c, community 'public'
+* over IPv4/UDP
+* to multiple Agents at demo.snmplabs.com
+* for instance of SNMPv2-MIB::sysDescr.0 MIB object
+* based on asyncio I/O framework
+
+Functionally similar to:
+
+| $ snmpget -v2c -c public demo.snmplabs.com:1161 SNMPv2-MIB::sysDescr.0
+| $ snmpget -v2c -c public demo.snmplabs.com:2161 SNMPv2-MIB::sysDescr.0
+| $ snmpget -v2c -c public demo.snmplabs.com:3161 SNMPv2-MIB::sysDescr.0
+
+"""#
+import asyncio
+from pysnmp.hlapi.asyncio import *
+
+@asyncio.coroutine
+def getone(snmpEngine, hostname):
+ errorIndication, errorStatus, errorIndex, varBinds = yield from getCmd(
+ snmpEngine,
+ CommunityData('public'),
+ UdpTransportTarget(hostname),
+ ContextData(),
+ ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0))
+ )
+
+ 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 ]))
+
+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))])
+)
diff --git a/examples/hlapi/asyncio/manager/cmdgen/multiple-sequential-async-queries.py b/examples/hlapi/asyncio/manager/cmdgen/multiple-sequential-async-queries.py
new file mode 100644
index 0000000..1867d5b
--- /dev/null
+++ b/examples/hlapi/asyncio/manager/cmdgen/multiple-sequential-async-queries.py
@@ -0,0 +1,55 @@
+"""
+Concurrent queries
+++++++++++++++++++
+
+Send multiple SNMP GET requests one by one using the following options:
+
+* with SNMPv2c, community 'public'
+* over IPv4/UDP
+* to multiple Agents at demo.snmplabs.com
+* for instance of SNMPv2-MIB::sysDescr.0 MIB object
+* based on asyncio I/O framework
+
+Functionally similar to:
+
+| $ snmpget -v2c -c public demo.snmplabs.com:1161 SNMPv2-MIB::sysDescr.0
+| $ snmpget -v2c -c public demo.snmplabs.com:2161 SNMPv2-MIB::sysDescr.0
+| $ snmpget -v2c -c public demo.snmplabs.com:3161 SNMPv2-MIB::sysDescr.0
+
+"""#
+import asyncio
+from pysnmp.hlapi.asyncio import *
+
+@asyncio.coroutine
+def getone(snmpEngine, hostname):
+ errorIndication, errorStatus, errorIndex, varBinds = yield from getCmd(
+ snmpEngine,
+ CommunityData('public'),
+ UdpTransportTarget(hostname),
+ ContextData(),
+ ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0))
+ )
+
+ 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 ]))
+
+@asyncio.coroutine
+def getall(snmpEngine, hostnames):
+ for hostname in hostnames:
+ yield from getone(snmpEngine, hostname)
+
+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)]))
diff --git a/examples/hlapi/asyncio/manager/cmdgen/v1-get.py b/examples/hlapi/asyncio/manager/cmdgen/v1-get.py
new file mode 100644
index 0000000..7757dec
--- /dev/null
+++ b/examples/hlapi/asyncio/manager/cmdgen/v1-get.py
@@ -0,0 +1,46 @@
+"""
+SNMPv1
+++++++
+
+Send SNMP GET request using the following options:
+
+ * with SNMPv1, community 'public'
+ * over IPv4/UDP
+ * to an Agent at demo.snmplabs.com:161
+ * for an instance of SNMPv2-MIB::sysDescr.0 MIB object
+ * Based on asyncio I/O framework
+
+Functionally similar to:
+
+| $ snmpget -v1 -c public demo.snmplabs.com SNMPv2-MIB::sysDescr.0
+
+"""#
+import asyncio
+from pysnmp.hlapi.asyncio import *
+
+@asyncio.coroutine
+def run():
+ snmpEngine = SnmpEngine()
+ errorIndication, errorStatus, errorIndex, varBinds = yield from getCmd(
+ snmpEngine,
+ CommunityData('public', mpModel=0),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ ContextData(),
+ ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0))
+ )
+
+ 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 ]))
+
+ snmpEngine.transportDispatcher.closeDispatcher()
+
+asyncio.get_event_loop().run_until_complete(run())
diff --git a/examples/hlapi/asyncore/agent/ntforg/async-multiple-informs-at-once.py b/examples/hlapi/asyncore/agent/ntforg/async-multiple-informs-at-once.py
index e2cacbe..c0ae96b 100644
--- a/examples/hlapi/asyncore/agent/ntforg/async-multiple-informs-at-once.py
+++ b/examples/hlapi/asyncore/agent/ntforg/async-multiple-informs-at-once.py
@@ -42,10 +42,8 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication,
snmpEngine = SnmpEngine()
-ntfOrg = AsyncNotificationOriginator()
-
for authData, transportTarget, contextData in targets:
- sendPduHandle = ntfOrg.sendNotification(
+ sendPduHandle = sendNotification(
snmpEngine,
authData,
transportTarget,
@@ -54,7 +52,7 @@ for authData, transportTarget, contextData in targets:
NotificationType(
ObjectIdentity('SNMPv2-MIB', 'coldStart')
).addVarBinds( ( '1.3.6.1.2.1.1.1.0', 'my name' ) ),
- cbInfo=(cbFun, None)
+ cbFun=cbFun
)
snmpEngine.transportDispatcher.runDispatcher()
diff --git a/examples/hlapi/asyncore/agent/ntforg/async-multiple-traps-at-once.py b/examples/hlapi/asyncore/agent/ntforg/async-multiple-traps-at-once.py
index 3d4d4b6..729f2e5 100644
--- a/examples/hlapi/asyncore/agent/ntforg/async-multiple-traps-at-once.py
+++ b/examples/hlapi/asyncore/agent/ntforg/async-multiple-traps-at-once.py
@@ -31,10 +31,8 @@ targets = (
snmpEngine = SnmpEngine()
-ntfOrg = AsyncNotificationOriginator()
-
for authData, transportTarget, contextData in targets:
- ntfOrg.sendNotification(
+ sendNotification(
snmpEngine,
authData,
transportTarget,
@@ -43,7 +41,7 @@ for authData, transportTarget, contextData in targets:
NotificationType(
ObjectIdentity('SNMPv2-MIB', 'coldStart')
).addVarBinds(
- ( ObjectName('1.3.6.1.2.1.1.1.0'),
+ ( ObjectIdentifier('1.3.6.1.2.1.1.1.0'),
OctetString('my name') )
)
)
diff --git a/examples/hlapi/asyncore/agent/ntforg/async-running-multiple-snmp-engines-at-once.py b/examples/hlapi/asyncore/agent/ntforg/async-running-multiple-snmp-engines-at-once.py
index 9df9daf..ce9db15 100644
--- a/examples/hlapi/asyncore/agent/ntforg/async-running-multiple-snmp-engines-at-once.py
+++ b/examples/hlapi/asyncore/agent/ntforg/async-running-multiple-snmp-engines-at-once.py
@@ -68,12 +68,10 @@ snmpEngineA.registerTransportDispatcher(transportDispatcher, 'A')
snmpEngineB = SnmpEngine()
snmpEngineB.registerTransportDispatcher(transportDispatcher, 'B')
-ntfOrg = AsyncNotificationOriginator()
-
for authData, transportTarget, contextData in targets:
snmpEngine = transportTarget.getTransportInfo()[1][1] % 3 and \
snmpEngineA or snmpEngineB
- sendPduHandle = ntfOrg.sendNotification(
+ sendPduHandle = sendNotification(
snmpEngine,
authData,
transportTarget,
@@ -82,7 +80,7 @@ for authData, transportTarget, contextData in targets:
NotificationType(
ObjectIdentity('SNMPv2-MIB', 'coldStart')
).addVarBinds( ( '1.3.6.1.2.1.1.1.0', 'my name' ) ),
- cbInfo=(cbFun, snmpEngine)
+ cbFun=cbFun, cbCtx=snmpEngine
)
transportDispatcher.runDispatcher()
diff --git a/examples/hlapi/asyncore/agent/ntforg/custom-contextengineid.py b/examples/hlapi/asyncore/agent/ntforg/custom-contextengineid.py
index 1a65a61..2ccdafe 100644
--- a/examples/hlapi/asyncore/agent/ntforg/custom-contextengineid.py
+++ b/examples/hlapi/asyncore/agent/ntforg/custom-contextengineid.py
@@ -24,15 +24,13 @@ Functionally similar to:
| 1.3.6.1.6.3.1.1.5.2
"""#
-from pysnmp.hlapi.asyncore import *
+from pysnmp.hlapi import *
errorIndication, errorStatus, errorIndex, varBinds = next(
sendNotification(SnmpEngine(),
UsmUserData('usr-md5-none', 'authkey1'),
UdpTransportTarget(('localhost', 162)),
- ContextData(
- rfc1902.OctetString(hexValue='8000000004030201')
- ),
+ ContextData(OctetString(hexValue='8000000004030201')),
'inform',
NotificationType(ObjectIdentity('1.3.6.1.6.3.1.1.5.2')))
)
diff --git a/examples/hlapi/asyncore/agent/ntforg/custom-contextname.py b/examples/hlapi/asyncore/agent/ntforg/custom-contextname.py
index c322d55..a087c7e 100644
--- a/examples/hlapi/asyncore/agent/ntforg/custom-contextname.py
+++ b/examples/hlapi/asyncore/agent/ntforg/custom-contextname.py
@@ -24,7 +24,7 @@ Functionally similar to:
| 1.3.6.1.6.3.1.1.5.2
"""#
-from pysnmp.hlapi.asyncore import *
+from pysnmp.hlapi import *
errorIndication, errorStatus, errorIndex, varBinds = next(
sendNotification(SnmpEngine(),
diff --git a/examples/hlapi/asyncore/agent/ntforg/custom-v1-trap.py b/examples/hlapi/asyncore/agent/ntforg/custom-v1-trap.py
index 51bf05a..768ad26 100644
--- a/examples/hlapi/asyncore/agent/ntforg/custom-v1-trap.py
+++ b/examples/hlapi/asyncore/agent/ntforg/custom-v1-trap.py
@@ -28,7 +28,7 @@ Functionally similar to:
| '1.3.6.1.2.1.1.1.0' s 'my system'
"""#
-from pysnmp.hlapi.asyncore import *
+from pysnmp.hlapi import *
errorIndication, errorStatus, errorIndex, varBinds = next(
sendNotification(SnmpEngine(),
@@ -42,7 +42,7 @@ errorIndication, errorStatus, errorIndex, varBinds = next(
('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', rfc1902.OctetString('my system'))
+ ('1.3.6.1.2.1.1.1.0', OctetString('my system'))
)
)
)
diff --git a/examples/hlapi/asyncore/agent/ntforg/default-v1-trap.py b/examples/hlapi/asyncore/agent/ntforg/default-v1-trap.py
index 75542ba..7d4a9d0 100644
--- a/examples/hlapi/asyncore/agent/ntforg/default-v1-trap.py
+++ b/examples/hlapi/asyncore/agent/ntforg/default-v1-trap.py
@@ -26,7 +26,7 @@ Functionally similar to:
| '1.3.6.1.2.1.1.1.0' s 'my system'
"""#
-from pysnmp.hlapi.asyncore import *
+from pysnmp.hlapi import *
errorIndication, errorStatus, errorIndex, varBinds = next(
sendNotification(SnmpEngine(),
@@ -38,7 +38,7 @@ errorIndication, errorStatus, errorIndex, varBinds = next(
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', rfc1902.OctetString('my system'))
+ ('1.3.6.1.2.1.1.1.0', OctetString('my system'))
)
)
)
diff --git a/examples/hlapi/asyncore/agent/ntforg/send-notification-with-additional-varbinds.py b/examples/hlapi/asyncore/agent/ntforg/send-notification-with-additional-varbinds.py
index 096eb34..17cf899 100644
--- a/examples/hlapi/asyncore/agent/ntforg/send-notification-with-additional-varbinds.py
+++ b/examples/hlapi/asyncore/agent/ntforg/send-notification-with-additional-varbinds.py
@@ -20,7 +20,7 @@ Functionally similar to:
| 1.3.6.1.2.1.1.1.0 s 'my system'
"""#
-from pysnmp.hlapi.asyncore import *
+from pysnmp.hlapi import *
errorIndication, errorStatus, errorIndex, varBinds = next(
sendNotification(SnmpEngine(),
diff --git a/examples/hlapi/asyncore/agent/ntforg/v2c-trap-via-notification-type.py b/examples/hlapi/asyncore/agent/ntforg/v2c-trap-via-notification-type.py
index 296aebc..e5121b2 100644
--- a/examples/hlapi/asyncore/agent/ntforg/v2c-trap-via-notification-type.py
+++ b/examples/hlapi/asyncore/agent/ntforg/v2c-trap-via-notification-type.py
@@ -16,10 +16,10 @@ Functionally similar to:
| $ snmptrap -v2c -c public demo.snmplabs.com \
| 12345
-| 1.3.6.1.4.1.20408.4.1.1.2 \
+| 1.3.6.1.4.1.20408.4.1.1.2
"""#
-from pysnmp.hlapi.asyncore import *
+from pysnmp.hlapi import *
errorIndication, errorStatus, errorIndex, varBinds = next(
sendNotification(SnmpEngine(),
diff --git a/examples/hlapi/asyncore/agent/ntforg/v3-inform.py b/examples/hlapi/asyncore/agent/ntforg/v3-inform.py
index ebf2fdf..39f5127 100644
--- a/examples/hlapi/asyncore/agent/ntforg/v3-inform.py
+++ b/examples/hlapi/asyncore/agent/ntforg/v3-inform.py
@@ -20,7 +20,7 @@ Functionally similar to:
| '1.3.6.1.2.1.1.1.0' s 'my system'
"""#
-from pysnmp.hlapi.asyncore import *
+from pysnmp.hlapi import *
errorIndication, errorStatus, errorIndex, varBinds = next(
sendNotification(SnmpEngine(),
diff --git a/examples/hlapi/asyncore/agent/ntforg/v3-trap.py b/examples/hlapi/asyncore/agent/ntforg/v3-trap.py
index 27d081d..ba62b39 100644
--- a/examples/hlapi/asyncore/agent/ntforg/v3-trap.py
+++ b/examples/hlapi/asyncore/agent/ntforg/v3-trap.py
@@ -26,7 +26,7 @@ Functionally similar to:
| '1.3.6.1.2.1.1.1.0' s 'my system'
"""#
-from pysnmp.hlapi.asyncore import *
+from pysnmp.hlapi import *
errorIndication, errorStatus, errorIndex, varBinds = next(
sendNotification(SnmpEngine(OctetString(hexValue='8000000001020304')),
diff --git a/examples/hlapi/asyncore/manager/cmdgen/async-pull-mibs-from-multiple-agents-at-once.py b/examples/hlapi/asyncore/manager/cmdgen/async-pull-mibs-from-multiple-agents-at-once.py
index ecb35ee..b671f19 100644
--- a/examples/hlapi/asyncore/manager/cmdgen/async-pull-mibs-from-multiple-agents-at-once.py
+++ b/examples/hlapi/asyncore/manager/cmdgen/async-pull-mibs-from-multiple-agents-at-once.py
@@ -12,7 +12,7 @@ following options:
over IPv6/UDP
* to an Agent at demo.snmplabs.com:161 and
to an Agent at [::1]:161
-* for multiple MIB subtrees and tables
+* pull variables till EOM
"""#
from pysnmp.hlapi.asyncore import *
@@ -44,7 +44,7 @@ targets = (
# Wait for responses or errors, submit GETNEXT requests for further OIDs
def cbFun(snmpEngine, sendRequestHandle, errorIndication,
errorStatus, errorIndex, varBindTable, cbCtx):
- (varBindHead, authData, transportTarget) = cbCtx
+ (authData, transportTarget) = cbCtx
print('%s via %s' % (authData, transportTarget))
if errorIndication:
print(errorIndication)
@@ -57,13 +57,6 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication,
)
return
else:
- for idx, varBind in enumerate(varBindTable[-1]):
- if varBind[1] is not None and varBindHead[idx] <= varBind[0]:
- break # still in table
- else:
- print('went out of table at %s' % (name, ))
- return
-
for varBindRow in varBindTable:
for varBind in varBindRow:
print(' = '.join([ x.prettyPrint() for x in varBind ]))
@@ -72,15 +65,9 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication,
snmpEngine = SnmpEngine()
-cmdGen = AsyncCommandGenerator()
-
# Submit initial GETNEXT requests and wait for responses
for authData, transportTarget, varBinds in targets:
- varBindHead = [ x[0] for x in cmdGen.makeVarBinds(snmpEngine, varBinds ) ]
- cmdGen.nextCmd(
- snmpEngine, authData, transportTarget, ContextData(), varBinds,
- # User-space callback function and its context
- (cbFun, (varBindHead, authData, transportTarget))
- )
+ nextCmd(snmpEngine, authData, transportTarget, ContextData(), varBinds,
+ cbFun=cbFun, cbCtx=(authData, transportTarget))
snmpEngine.transportDispatcher.runDispatcher()
diff --git a/examples/hlapi/asyncore/manager/cmdgen/async-query-multiple-snmp-engines.py b/examples/hlapi/asyncore/manager/cmdgen/async-query-multiple-snmp-engines.py
index 1ce32ae..d0a5c62 100644
--- a/examples/hlapi/asyncore/manager/cmdgen/async-query-multiple-snmp-engines.py
+++ b/examples/hlapi/asyncore/manager/cmdgen/async-query-multiple-snmp-engines.py
@@ -88,14 +88,10 @@ snmpEngineA.registerTransportDispatcher(transportDispatcher, 'A')
snmpEngineB = SnmpEngine()
snmpEngineB.registerTransportDispatcher(transportDispatcher, 'B')
-cmdGen = AsyncCommandGenerator()
-
for authData, transportTarget, varBinds in targets:
snmpEngine = transportTarget.getTransportInfo()[1][1] % 3 and \
snmpEngineA or snmpEngineB
- cmdGen.getCmd(
- snmpEngine, authData, transportTarget, ContextData(), varBinds,
- (cbFun, (snmpEngine, authData, transportTarget))
- )
+ getCmd(snmpEngine, authData, transportTarget, ContextData(), varBinds,
+ cbFun=cbFun, cbCtx=(snmpEngine, authData, transportTarget))
transportDispatcher.runDispatcher()
diff --git a/examples/hlapi/asyncore/manager/cmdgen/coerce-set-value-to-mib-spec.py b/examples/hlapi/asyncore/manager/cmdgen/coerce-set-value-to-mib-spec.py
index bbcac86..ab2df92 100644
--- a/examples/hlapi/asyncore/manager/cmdgen/coerce-set-value-to-mib-spec.py
+++ b/examples/hlapi/asyncore/manager/cmdgen/coerce-set-value-to-mib-spec.py
@@ -15,7 +15,7 @@ Functionally similar to:
| = "new system name"
"""#
-from pysnmp.hlapi.asyncore import *
+from pysnmp.hlapi import *
errorIndication, errorStatus, errorIndex, varBinds = next(
setCmd(SnmpEngine(),
diff --git a/examples/hlapi/asyncore/manager/cmdgen/custom-asn1-mib-search-path.py b/examples/hlapi/asyncore/manager/cmdgen/custom-asn1-mib-search-path.py
index 445d665..22fbe6d 100644
--- a/examples/hlapi/asyncore/manager/cmdgen/custom-asn1-mib-search-path.py
+++ b/examples/hlapi/asyncore/manager/cmdgen/custom-asn1-mib-search-path.py
@@ -16,7 +16,7 @@ Functionally similar to:
| IF-MIB::ifInOctets.1
"""#
-from pysnmp.hlapi.asyncore import *
+from pysnmp.hlapi import *
errorIndication, errorStatus, errorIndex, varBinds = next(
getCmd(SnmpEngine(),
diff --git a/examples/hlapi/asyncore/manager/cmdgen/custom-contextengineid-and-contextname.py b/examples/hlapi/asyncore/manager/cmdgen/custom-contextengineid-and-contextname.py
index 2e84bba..1244583 100644
--- a/examples/hlapi/asyncore/manager/cmdgen/custom-contextengineid-and-contextname.py
+++ b/examples/hlapi/asyncore/manager/cmdgen/custom-contextengineid-and-contextname.py
@@ -20,7 +20,7 @@ Functionally similar to:
| SNMPv2-MIB::sysORDescr.1 = "new system name"
"""#
-from pysnmp.hlapi.asyncore import *
+from pysnmp.hlapi import *
errorIndication, errorStatus, errorIndex, varBinds = next(
setCmd(SnmpEngine(),
diff --git a/examples/hlapi/asyncore/manager/cmdgen/custom-contextengineid.py b/examples/hlapi/asyncore/manager/cmdgen/custom-contextengineid.py
index d8e19ab..ea97c59 100644
--- a/examples/hlapi/asyncore/manager/cmdgen/custom-contextengineid.py
+++ b/examples/hlapi/asyncore/manager/cmdgen/custom-contextengineid.py
@@ -18,7 +18,7 @@ Functionally similar to:
| SNMPv2-MIB::sysORDescr.1 = "new system name"
"""#
-from pysnmp.hlapi.asyncore import *
+from pysnmp.hlapi import *
errorIndication, errorStatus, errorIndex, varBinds = next(
setCmd(SnmpEngine(),
diff --git a/examples/hlapi/asyncore/manager/cmdgen/custom-pysnmp-mibs-search-path.py b/examples/hlapi/asyncore/manager/cmdgen/custom-pysnmp-mibs-search-path.py
index e49ef4b..42b1df6 100644
--- a/examples/hlapi/asyncore/manager/cmdgen/custom-pysnmp-mibs-search-path.py
+++ b/examples/hlapi/asyncore/manager/cmdgen/custom-pysnmp-mibs-search-path.py
@@ -18,7 +18,7 @@ Functionally similar to:
| demo.snmplabs.com TCP-MIB::tcpConnTable
"""#
-from pysnmp.hlapi.asyncore import *
+from pysnmp.hlapi import *
for errorIndication, \
errorStatus, errorIndex, \
diff --git a/examples/hlapi/asyncore/manager/cmdgen/custom-timeout-and-retries.py b/examples/hlapi/asyncore/manager/cmdgen/custom-timeout-and-retries.py
index a6965fe..cfa274f 100644
--- a/examples/hlapi/asyncore/manager/cmdgen/custom-timeout-and-retries.py
+++ b/examples/hlapi/asyncore/manager/cmdgen/custom-timeout-and-retries.py
@@ -25,16 +25,16 @@ means one initial request plus one retry.
Functionally similar to:
-| $ snmpget -v1 -c public demo.snmplabs.com 1.3.6.1.2.1.1.1.0
+| $ snmpget -v1 -c public -t 2 -r 0 demo.snmplabs.com 1.3.6.1.2.1.1.1.0
"""#
-from pysnmp.hlapi.asyncore import *
+from pysnmp.hlapi import *
errorIndication, errorStatus, errorIndex, varBinds = next(
getCmd(SnmpEngine(),
CommunityData('public'),
UdpTransportTarget(
- ('demo.snmplabs.com', 161), timeout=1.5, retries=0
+ ('demo.snmplabs.com', 161), timeout=2.0, retries=0
),
ContextData(),
ObjectType(ObjectIdentity('1.3.6.1.2.1.1.1.0')))
diff --git a/examples/hlapi/asyncore/manager/cmdgen/custom-v3-security-name.py b/examples/hlapi/asyncore/manager/cmdgen/custom-v3-security-name.py
index 77c4cf6..4346b26 100644
--- a/examples/hlapi/asyncore/manager/cmdgen/custom-v3-security-name.py
+++ b/examples/hlapi/asyncore/manager/cmdgen/custom-v3-security-name.py
@@ -15,7 +15,7 @@ allows you to address a USM Table row just as userName does. However
securityName can be made human-readable, also it is not an index in
usmUserTable, thus duplicate securityName parameters are possible.
"""#
-from pysnmp.hlapi.asyncore import *
+from pysnmp.hlapi import *
errorIndication, errorStatus, errorIndex, varBinds = next(
getCmd(SnmpEngine(),
diff --git a/examples/hlapi/asyncore/manager/cmdgen/fetch-variables-over-ipv6.py b/examples/hlapi/asyncore/manager/cmdgen/fetch-variables-over-ipv6.py
index 3967ab6..d431659 100644
--- a/examples/hlapi/asyncore/manager/cmdgen/fetch-variables-over-ipv6.py
+++ b/examples/hlapi/asyncore/manager/cmdgen/fetch-variables-over-ipv6.py
@@ -17,7 +17,7 @@ Functionally similar to:
| 1.3.6.1.2.1.1.2.0 \
| 1.3.6.1.2.1.1.3.0
"""#
-from pysnmp.hlapi.asyncore import *
+from pysnmp.hlapi import *
errorIndication, errorStatus, errorIndex, varBinds = next(
getCmd(SnmpEngine(),
diff --git a/examples/hlapi/asyncore/manager/cmdgen/get-table-object-by-index.py b/examples/hlapi/asyncore/manager/cmdgen/get-table-object-by-index.py
index 6b382ea..fc8a882 100644
--- a/examples/hlapi/asyncore/manager/cmdgen/get-table-object-by-index.py
+++ b/examples/hlapi/asyncore/manager/cmdgen/get-table-object-by-index.py
@@ -17,7 +17,7 @@ Functionally similar to:
| IF-MIB::ifInOctets.1 IF-MIB::ifOutOctets.1
"""#
-from pysnmp.hlapi.asyncore import *
+from pysnmp.hlapi import *
errorIndication, errorStatus, errorIndex, varBinds = next(
getCmd(SnmpEngine(),
diff --git a/examples/hlapi/asyncore/manager/cmdgen/get-table-object-by-multiple-indices.py b/examples/hlapi/asyncore/manager/cmdgen/get-table-object-by-multiple-indices.py
index e344dc0..5d0621d 100644
--- a/examples/hlapi/asyncore/manager/cmdgen/get-table-object-by-multiple-indices.py
+++ b/examples/hlapi/asyncore/manager/cmdgen/get-table-object-by-multiple-indices.py
@@ -17,7 +17,7 @@ Functionally similar to:
| TCP-MIB::tcpConnLocalAddress."0.0.0.0".22."0.0.0.0".0
"""#
-from pysnmp.hlapi.asyncore import *
+from pysnmp.hlapi import *
errorIndication, errorStatus, errorIndex, varBinds = next(
getCmd(SnmpEngine(),
diff --git a/examples/hlapi/asyncore/manager/cmdgen/getbulk-fetch-scalar-and-table-variables.py b/examples/hlapi/asyncore/manager/cmdgen/getbulk-fetch-scalar-and-table-variables.py
index f30ae1e..6b18d42 100644
--- a/examples/hlapi/asyncore/manager/cmdgen/getbulk-fetch-scalar-and-table-variables.py
+++ b/examples/hlapi/asyncore/manager/cmdgen/getbulk-fetch-scalar-and-table-variables.py
@@ -20,7 +20,7 @@ Functionally similar to:
| IP-MIB::ipAddrEntry
"""#
-from pysnmp.hlapi.asyncore import *
+from pysnmp.hlapi import *
for errorIndication, \
errorStatus, errorIndex, \
diff --git a/examples/hlapi/asyncore/manager/cmdgen/getbulk-limit-number-of-packets.py b/examples/hlapi/asyncore/manager/cmdgen/getbulk-limit-number-of-packets.py
index 0cf9e0f..5146808 100644
--- a/examples/hlapi/asyncore/manager/cmdgen/getbulk-limit-number-of-packets.py
+++ b/examples/hlapi/asyncore/manager/cmdgen/getbulk-limit-number-of-packets.py
@@ -17,7 +17,7 @@ Functionally similar to:
| demo.snmplabs.com SNMPv2-MIB::system
"""#
-from pysnmp.hlapi.asyncore import *
+from pysnmp.hlapi import *
for errorIndication, \
errorStatus, errorIndex, \
diff --git a/examples/hlapi/asyncore/manager/cmdgen/getbulk-limit-number-of-variables.py b/examples/hlapi/asyncore/manager/cmdgen/getbulk-limit-number-of-variables.py
index ec2abdd..ef95f5a 100644
--- a/examples/hlapi/asyncore/manager/cmdgen/getbulk-limit-number-of-variables.py
+++ b/examples/hlapi/asyncore/manager/cmdgen/getbulk-limit-number-of-variables.py
@@ -19,7 +19,7 @@ Functionally similar to:
| 1.3.6.1.2.1.2.2 1.3.6.1.2.1.2.3
"""#
-from pysnmp.hlapi.asyncore import *
+from pysnmp.hlapi import *
for errorIndication, \
errorStatus, errorIndex, \
diff --git a/examples/hlapi/asyncore/manager/cmdgen/getnext-limit-number-of-variables.py b/examples/hlapi/asyncore/manager/cmdgen/getnext-limit-number-of-variables.py
index 2844bfa..9536ebb 100644
--- a/examples/hlapi/asyncore/manager/cmdgen/getnext-limit-number-of-variables.py
+++ b/examples/hlapi/asyncore/manager/cmdgen/getnext-limit-number-of-variables.py
@@ -18,7 +18,7 @@ Functionally similar to:
| SNMPv2-MIB::system
"""#
-from pysnmp.hlapi.asyncore import *
+from pysnmp.hlapi import *
for errorIndication, \
errorStatus, errorIndex, \
diff --git a/examples/hlapi/asyncore/manager/cmdgen/getnext-multiple-oids-to-eom.py b/examples/hlapi/asyncore/manager/cmdgen/getnext-multiple-oids-to-eom.py
index ac66388..c2858a7 100644
--- a/examples/hlapi/asyncore/manager/cmdgen/getnext-multiple-oids-to-eom.py
+++ b/examples/hlapi/asyncore/manager/cmdgen/getnext-multiple-oids-to-eom.py
@@ -16,7 +16,7 @@ Functionally similar to:
| 1.3.6.1.2.1.2.2.1.2 1.3.6.1.2.1.2.2.1.3
"""#
-from pysnmp.hlapi.asyncore import *
+from pysnmp.hlapi import *
for errorIndication, \
errorStatus, errorIndex, \
diff --git a/examples/hlapi/asyncore/manager/cmdgen/multiple-concurrent-async-queries.py b/examples/hlapi/asyncore/manager/cmdgen/multiple-concurrent-async-queries.py
index 0c6e9bf..6222c3e 100644
--- a/examples/hlapi/asyncore/manager/cmdgen/multiple-concurrent-async-queries.py
+++ b/examples/hlapi/asyncore/manager/cmdgen/multiple-concurrent-async-queries.py
@@ -72,14 +72,9 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication,
snmpEngine = SnmpEngine()
-cmdGen = AsyncCommandGenerator()
-
# Submit GET requests
for authData, transportTarget, varNames in targets:
- cmdGen.getCmd(
- snmpEngine, authData, transportTarget, ContextData(), varNames,
- # User-space callback function and its context
- (cbFun, (authData, transportTarget))
- )
+ getCmd(snmpEngine, authData, transportTarget, ContextData(), varNames,
+ cbFun=cbFun, cbCtx=(authData, transportTarget))
snmpEngine.transportDispatcher.runDispatcher()
diff --git a/examples/hlapi/asyncore/manager/cmdgen/multiple-get-calls.py b/examples/hlapi/asyncore/manager/cmdgen/multiple-get-calls.py
index b17da65..d8c63ef 100644
--- a/examples/hlapi/asyncore/manager/cmdgen/multiple-get-calls.py
+++ b/examples/hlapi/asyncore/manager/cmdgen/multiple-get-calls.py
@@ -20,7 +20,7 @@ Functionally similar to:
| IF-MIB::ifInOctets.1
"""#
-from pysnmp.hlapi.asyncore import *
+from pysnmp.hlapi import *
queue = [ [ ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets', 1)) ],
[ ObjectType(ObjectIdentity('IF-MIB', 'ifOutOctets', 1)) ] ]
diff --git a/examples/hlapi/asyncore/manager/cmdgen/preload-pysnmp-mibs.py b/examples/hlapi/asyncore/manager/cmdgen/preload-pysnmp-mibs.py
index 080b5d1..885dbdf 100644
--- a/examples/hlapi/asyncore/manager/cmdgen/preload-pysnmp-mibs.py
+++ b/examples/hlapi/asyncore/manager/cmdgen/preload-pysnmp-mibs.py
@@ -18,7 +18,7 @@ Functionally similar to:
| 1.3.6
"""#
-from pysnmp.hlapi.asyncore import *
+from pysnmp.hlapi import *
for errorIndication, \
errorStatus, errorIndex, \
diff --git a/examples/hlapi/asyncore/manager/cmdgen/pull-whole-mib.py b/examples/hlapi/asyncore/manager/cmdgen/pull-whole-mib.py
index 479c504..10538f2 100644
--- a/examples/hlapi/asyncore/manager/cmdgen/pull-whole-mib.py
+++ b/examples/hlapi/asyncore/manager/cmdgen/pull-whole-mib.py
@@ -8,7 +8,6 @@ Send a series of SNMP GETNEXT requests using the following options:
* over IPv4/UDP
* to an Agent at demo.snmplabs.com:161
* for all OIDs in IF-MIB
-* stop when response OIDs leave the scopes of the table
Functionally similar to:
@@ -16,7 +15,7 @@ Functionally similar to:
| demo.snmplabs.com IF-MIB::
"""#
-from pysnmp.hlapi.asyncore import *
+from pysnmp.hlapi import *
for errorIndication, \
errorStatus, errorIndex, \
@@ -24,8 +23,7 @@ for errorIndication, \
UsmUserData('usr-md5-none', 'authkey1'),
UdpTransportTarget(('demo.snmplabs.com', 161)),
ContextData(),
- ObjectType(ObjectIdentity('IF-MIB')),
- lexicographicMode=False):
+ ObjectType(ObjectIdentity('IF-MIB'))):
if errorIndication:
print(errorIndication)
diff --git a/examples/hlapi/asyncore/manager/cmdgen/pull-whole-snmp-table.py b/examples/hlapi/asyncore/manager/cmdgen/pull-whole-snmp-table.py
index 3c3f40b..5b8d221 100644
--- a/examples/hlapi/asyncore/manager/cmdgen/pull-whole-snmp-table.py
+++ b/examples/hlapi/asyncore/manager/cmdgen/pull-whole-snmp-table.py
@@ -21,7 +21,7 @@ Functionally similar to:
| IF-MIB::ifType \
"""#
-from pysnmp.hlapi.asyncore import *
+from pysnmp.hlapi import *
for errorIndication, \
errorStatus, \
diff --git a/examples/hlapi/asyncore/manager/cmdgen/query-agents-from-multuple-threads.py b/examples/hlapi/asyncore/manager/cmdgen/query-agents-from-multuple-threads.py
index 442855a..34ead8b 100644
--- a/examples/hlapi/asyncore/manager/cmdgen/query-agents-from-multuple-threads.py
+++ b/examples/hlapi/asyncore/manager/cmdgen/query-agents-from-multuple-threads.py
@@ -22,7 +22,7 @@ if version_info[0] == 2:
else:
from queue import Queue
from threading import Thread
-from pysnmp.hlapi.asyncore import *
+from pysnmp.hlapi import *
# List of targets in the followin format:
# ( ( authData, transportTarget, varNames ), ... )
diff --git a/examples/hlapi/asyncore/manager/cmdgen/set-multiple-scalar-values.py b/examples/hlapi/asyncore/manager/cmdgen/set-multiple-scalar-values.py
index b2b67eb..c3d3c5c 100644
--- a/examples/hlapi/asyncore/manager/cmdgen/set-multiple-scalar-values.py
+++ b/examples/hlapi/asyncore/manager/cmdgen/set-multiple-scalar-values.py
@@ -21,7 +21,7 @@ Functionally similar to:
| 1.3.6.1.2.1.1.9.1.3.1 s "new system name"
"""#
-from pysnmp.hlapi.asyncore import *
+from pysnmp.hlapi import *
errorIndication, errorStatus, errorIndex, varBinds = next(
setCmd(SnmpEngine(),
diff --git a/examples/hlapi/asyncore/manager/cmdgen/specific-v3-engine-id.py b/examples/hlapi/asyncore/manager/cmdgen/specific-v3-engine-id.py
index f7db38f..72263be 100644
--- a/examples/hlapi/asyncore/manager/cmdgen/specific-v3-engine-id.py
+++ b/examples/hlapi/asyncore/manager/cmdgen/specific-v3-engine-id.py
@@ -18,7 +18,7 @@ Send SNMP GET request using the following scenario and options:
* for an OID in text form
"""#
-from pysnmp.hlapi.asyncore import *
+from pysnmp.hlapi import *
snmpEngine = SnmpEngine()
diff --git a/examples/hlapi/asyncore/manager/cmdgen/usm-md5-des.py b/examples/hlapi/asyncore/manager/cmdgen/usm-md5-des.py
index cdd6ce3..1d8030d 100644
--- a/examples/hlapi/asyncore/manager/cmdgen/usm-md5-des.py
+++ b/examples/hlapi/asyncore/manager/cmdgen/usm-md5-des.py
@@ -16,7 +16,7 @@ Functionally similar to:
| IF-MIB::ifInOctets.1
"""#
-from pysnmp.hlapi.asyncore import *
+from pysnmp.hlapi import *
errorIndication, errorStatus, errorIndex, varBinds = next(
getCmd(SnmpEngine(),
diff --git a/examples/hlapi/asyncore/manager/cmdgen/usm-md5-none.py b/examples/hlapi/asyncore/manager/cmdgen/usm-md5-none.py
index 363bddb..c38d2f3 100644
--- a/examples/hlapi/asyncore/manager/cmdgen/usm-md5-none.py
+++ b/examples/hlapi/asyncore/manager/cmdgen/usm-md5-none.py
@@ -15,7 +15,7 @@ Functionally similar to:
| IF-MIB::ifInOctets.1
"""#
-from pysnmp.hlapi.asyncore import *
+from pysnmp.hlapi import *
errorIndication, errorStatus, errorIndex, varBinds = next(
getCmd(SnmpEngine(),
diff --git a/examples/hlapi/asyncore/manager/cmdgen/usm-none-none.py b/examples/hlapi/asyncore/manager/cmdgen/usm-none-none.py
index 5049a7c..15f570a 100644
--- a/examples/hlapi/asyncore/manager/cmdgen/usm-none-none.py
+++ b/examples/hlapi/asyncore/manager/cmdgen/usm-none-none.py
@@ -16,7 +16,7 @@ Functionally similar to:
| IF-MIB::ifInOctets.1
"""#
-from pysnmp.hlapi.asyncore import *
+from pysnmp.hlapi import *
errorIndication, errorStatus, errorIndex, varBinds = next(
getCmd(SnmpEngine(),
diff --git a/examples/hlapi/asyncore/manager/cmdgen/usm-sha-aes128.py b/examples/hlapi/asyncore/manager/cmdgen/usm-sha-aes128.py
index 1a1c0cb..1e985f5 100644
--- a/examples/hlapi/asyncore/manager/cmdgen/usm-sha-aes128.py
+++ b/examples/hlapi/asyncore/manager/cmdgen/usm-sha-aes128.py
@@ -32,7 +32,7 @@ Functionally similar to:
| SNMPv2-MIB::sysDescr.0
"""#
-from pysnmp.hlapi.asyncore import *
+from pysnmp.hlapi import *
errorIndication, errorStatus, errorIndex, varBinds = next(
getCmd(SnmpEngine(),
diff --git a/examples/hlapi/asyncore/manager/cmdgen/v1-get.py b/examples/hlapi/asyncore/manager/cmdgen/v1-get.py
index 7d417ef..3f03c7c 100644
--- a/examples/hlapi/asyncore/manager/cmdgen/v1-get.py
+++ b/examples/hlapi/asyncore/manager/cmdgen/v1-get.py
@@ -14,7 +14,7 @@ Functionally similar to:
| $ snmpget -v1 -c public demo.snmplabs.com SNMPv2-MIB::sysDescr.0
"""#
-from pysnmp.hlapi.asyncore import *
+from pysnmp.hlapi import *
errorIndication, errorStatus, errorIndex, varBinds = next(
getCmd(SnmpEngine(),
diff --git a/examples/hlapi/asyncore/manager/cmdgen/v2c-get.py b/examples/hlapi/asyncore/manager/cmdgen/v2c-get.py
index a11c48c..169b6a6 100644
--- a/examples/hlapi/asyncore/manager/cmdgen/v2c-get.py
+++ b/examples/hlapi/asyncore/manager/cmdgen/v2c-get.py
@@ -15,7 +15,7 @@ Functionally similar to:
| 1.3.6.1.2.1.1.6.0
"""#
-from pysnmp.hlapi.asyncore import *
+from pysnmp.hlapi import *
errorIndication, errorStatus, errorIndex, varBinds = next(
getCmd(SnmpEngine(),
diff --git a/examples/hlapi/asyncore/manager/cmdgen/v2c-getbulk.py b/examples/hlapi/asyncore/manager/cmdgen/v2c-getbulk.py
index ff82017..a65bb35 100644
--- a/examples/hlapi/asyncore/manager/cmdgen/v2c-getbulk.py
+++ b/examples/hlapi/asyncore/manager/cmdgen/v2c-getbulk.py
@@ -18,7 +18,7 @@ Functionally similar to:
| 1.3.6.1.2.1.2.2 1.3.6.1.2.1.2.3
"""#
-from pysnmp.hlapi.asyncore import *
+from pysnmp.hlapi import *
for errorIndication, \
errorStatus, errorIndex, \
diff --git a/examples/hlapi/asyncore/manager/cmdgen/waive-mib-lookup.py b/examples/hlapi/asyncore/manager/cmdgen/waive-mib-lookup.py
index 595d7ad..7038d96 100644
--- a/examples/hlapi/asyncore/manager/cmdgen/waive-mib-lookup.py
+++ b/examples/hlapi/asyncore/manager/cmdgen/waive-mib-lookup.py
@@ -19,7 +19,7 @@ Functionally similar to:
| $ snmpwalk -v2c -c public -ObentU demo.snmplabs.com 1.3.6.1.2.1
"""#
-from pysnmp.hlapi.asyncore import *
+from pysnmp.hlapi import *
for errorIndication, \
errorStatus, errorIndex, \
diff --git a/examples/hlapi/trollius/agent/ntforg/default-v1-trap.py b/examples/hlapi/trollius/agent/ntforg/default-v1-trap.py
new file mode 100644
index 0000000..dbfb63e
--- /dev/null
+++ b/examples/hlapi/trollius/agent/ntforg/default-v1-trap.py
@@ -0,0 +1,58 @@
+"""
+SNMPv1 TRAP with defaults
++++++++++++++++++++++++++
+
+Send SNMPv1 TRAP through unified SNMPv3 message processing framework
+using the following options:
+
+* SNMPv1
+* with community name 'public'
+* over IPv4/UDP
+* send TRAP notification
+* with Generic Trap #1 (warmStart) and Specific Trap 0
+* with default Uptime
+* with default Agent Address
+* with Enterprise OID 1.3.6.1.4.1.20408.4.1.1.2
+* include managed object information '1.3.6.1.2.1.1.1.0' = 'my system'
+* use trollius I/O framework
+
+Functionally similar to:
+
+| $ snmptrap -v1 -c public demo.snmplabs.com \
+| 1.3.6.1.4.1.20408.4.1.1.2 \
+| 0.0.0.0 \
+| 1 \
+| 0 \
+| 0
+| '1.3.6.1.2.1.1.1.0' s 'my system'
+
+"""#
+import trollius
+from pysnmp.hlapi.asyncio import *
+
+@trollius.coroutine
+def run():
+ snmpEngine = SnmpEngine()
+ errorIndication, errorStatus, \
+ errorIndex, varBinds = yield trollius.From(
+ sendNotification(
+ snmpEngine,
+ CommunityData('public'), # mpModel=0),
+ UdpTransportTarget(('localhost', 162)),
+ ContextData(),
+ 'inform',
+ 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'))
+ )
+ )
+ )
+
+ if errorIndication:
+ print(errorIndication)
+
+ snmpEngine.transportDispatcher.closeDispatcher()
+
+trollius.get_event_loop().run_until_complete(run())
diff --git a/examples/hlapi/trollius/manager/cmdgen/getbulk-to-eom.py b/examples/hlapi/trollius/manager/cmdgen/getbulk-to-eom.py
new file mode 100644
index 0000000..6d4cf71
--- /dev/null
+++ b/examples/hlapi/trollius/manager/cmdgen/getbulk-to-eom.py
@@ -0,0 +1,60 @@
+"""
+Bulk walk MIB
++++++++++++++
+
+Send a series of SNMP GETBULK requests using the following options:
+
+* with SNMPv3, user 'usr-none-none', no authentication, no privacy
+* over IPv4/UDP
+* to an Agent at demo.snmplabs.com:161
+* for all OIDs past SNMPv2-MIB::system
+* run till end-of-mib condition is reported by Agent
+* based on trollius I/O framework
+
+Functionally similar to:
+
+| $ snmpbulkwalk -v3 -lnoAuthNoPriv -u usr-none-none -Cn0 -Cr50 \
+| demo.snmplabs.com SNMPv2-MIB::system
+
+"""#
+import trollius
+from pysnmp.hlapi.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)
+ )
+
+ 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
+
+ snmpEngine.transportDispatcher.closeDispatcher()
+
+loop = trollius.get_event_loop()
+loop.run_until_complete(
+ run([ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr'))])
+)
diff --git a/examples/hlapi/trollius/manager/cmdgen/v1-get.py b/examples/hlapi/trollius/manager/cmdgen/v1-get.py
new file mode 100644
index 0000000..c75be31
--- /dev/null
+++ b/examples/hlapi/trollius/manager/cmdgen/v1-get.py
@@ -0,0 +1,47 @@
+"""
+SNMPv1
+++++++
+
+Send SNMP GET request using the following options:
+
+ * with SNMPv1, community 'public'
+ * over IPv4/UDP
+ * to an Agent at demo.snmplabs.com:161
+ * for an instance of SNMPv2-MIB::sysDescr.0 MIB object
+ * Based on trollius I/O framework
+
+Functionally similar to:
+
+| $ snmpget -v1 -c public demo.snmplabs.com SNMPv2-MIB::sysDescr.0
+
+"""#
+import trollius
+from pysnmp.hlapi.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)))
+ )
+
+ 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 ]))
+
+ snmpEngine.transportDispatcher.closeDispatcher()
+
+trollius.get_event_loop().run_until_complete(run())
diff --git a/examples/hlapi/twisted/agent/ntforg/default-v1-trap.py b/examples/hlapi/twisted/agent/ntforg/default-v1-trap.py
new file mode 100644
index 0000000..c17e3cf
--- /dev/null
+++ b/examples/hlapi/twisted/agent/ntforg/default-v1-trap.py
@@ -0,0 +1,64 @@
+"""
+SNMPv1 TRAP with defaults
++++++++++++++++++++++++++
+
+Send SNMPv1 TRAP through unified SNMPv3 message processing framework
+using the following options:
+
+* SNMPv1
+* with community name 'public'
+* over IPv4/UDP
+* send TRAP notification
+* with Generic Trap #1 (warmStart) and Specific Trap 0
+* with default Uptime
+* with default Agent Address
+* with Enterprise OID 1.3.6.1.4.1.20408.4.1.1.2
+* include managed object information '1.3.6.1.2.1.1.1.0' = 'my system'
+
+Functionally similar to:
+
+| $ snmptrap -v1 -c public demo.snmplabs.com \
+| 1.3.6.1.4.1.20408.4.1.1.2 \
+| 0.0.0.0 \
+| 1 \
+| 0 \
+| 0
+| '1.3.6.1.2.1.1.1.0' s 'my system'
+
+"""#
+from twisted.internet.task import react
+from pysnmp.hlapi.twisted import *
+
+def success((errorStatus, errorIndex, varBinds), hostname):
+ 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 ]))
+
+def failure(errorIndication, hostname):
+ print('%s failure: %s' % (hostname, errorIndication))
+
+def run(reactor, hostname):
+ d = sendNotification(
+ SnmpEngine(),
+ CommunityData('public', mpModel=0),
+ UdpTransportTarget((hostname, 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'))
+ )
+ )
+ d.addCallback(success, hostname).addErrback(failure, hostname)
+ return d
+
+react(run, ['demo.snmplabs.com'])
diff --git a/examples/hlapi/twisted/agent/ntforg/multiple-notifications-at-once.py b/examples/hlapi/twisted/agent/ntforg/multiple-notifications-at-once.py
new file mode 100644
index 0000000..e0839c3
--- /dev/null
+++ b/examples/hlapi/twisted/agent/ntforg/multiple-notifications-at-once.py
@@ -0,0 +1,73 @@
+"""
+Multiple concurrent notifications
++++++++++++++++++++++++++++++++++
+
+Send multiple SNMP notifications at once using the following options:
+
+* SNMPv2c and SNMPv3
+* with community name 'public' or USM username usr-md5-des
+* over IPv4/UDP
+* send INFORM notification
+* to multiple Managers
+* with TRAP ID 'coldStart' specified as a MIB symbol
+* include managed object information specified as var-bind objects pair
+
+Here we tag each SNMP-COMMUNITY-MIB::snmpCommunityTable row
+with the same tag as SNMP-TARGET-MIB::snmpTargetAddrTable row
+what leads to excessive tables information.
+
+Functionally similar to:
+
+| $ snmpinform -v2c -c public demo.snmplabs.com 12345 1.3.6.1.6.3.1.1.5.2
+|
+| $ snmpinform -v3 -l authNoPriv -u usr-md5-none -A authkey1 \
+| demo.snmplabs.com \
+| 12345 \
+| 1.3.6.1.6.3.1.1.5.2
+
+"""#
+from twisted.internet.defer import DeferredList
+from twisted.internet.task import react
+from pysnmp.hlapi.twisted import *
+
+def success((errorStatus, errorIndex, varBinds), hostname):
+ 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 ]))
+
+def failure(errorIndication, hostname):
+ print('%s failure: %s' % (hostname, errorIndication))
+
+def sendone(reactor, snmpEngine, hostname, notifyType):
+ d = sendNotification(
+ snmpEngine,
+ CommunityData('public', tag=hostname),
+ UdpTransportTarget((hostname, 162), tagList=hostname),
+ ContextData(),
+ notifyType,
+ 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'))
+ )
+ )
+ d.addCallback(success, hostname).addErrback(failure, hostname)
+ return d
+
+def sendall(reactor, destinations):
+ snmpEngine = SnmpEngine()
+
+ return DeferredList(
+ [ sendone(reactor, snmpEngine, hostname, notifyType)
+ for hostname, notifyType in destinations ]
+ )
+
+react(sendall, [[('localhost', 'trap'), ('localhost', 'inform')]])
diff --git a/examples/hlapi/twisted/manager/cmdgen/custom-timeout-and-retries.py b/examples/hlapi/twisted/manager/cmdgen/custom-timeout-and-retries.py
new file mode 100644
index 0000000..fefcd68
--- /dev/null
+++ b/examples/hlapi/twisted/manager/cmdgen/custom-timeout-and-retries.py
@@ -0,0 +1,49 @@
+"""
+SNMPv2c
++++++++
+
+Send SNMP GET request using the following options:
+
+ * with SNMPv2c, community 'public'
+ * over IPv4/UDP with non-default timeout and no retries
+ * to an Agent at demo.snmplabs.com:161
+ * for two instances of SNMPv2-MIB::sysDescr.0 MIB object,
+ * based on Twisted I/O framework
+
+Functionally similar to:
+
+| $ snmpget -v2c -c public -r 0 -t 2 demo.snmplabs.com SNMPv2-MIB::sysDescr.0
+
+"""#
+from twisted.internet.task import react
+from pysnmp.hlapi.twisted import *
+
+def success((errorStatus, errorIndex, varBinds), hostname):
+ 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 ]))
+
+def failure(errorIndication, hostname):
+ print('%s failure: %s' % (hostname, errorIndication))
+
+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)))
+
+ d.addCallback(success, hostname).addErrback(failure, hostname)
+
+ return d
+
+react(getSysDescr, ['demo.snmplabs.com'])
diff --git a/examples/hlapi/twisted/manager/cmdgen/getbulk-to-eom.py b/examples/hlapi/twisted/manager/cmdgen/getbulk-to-eom.py
new file mode 100644
index 0000000..47ede70
--- /dev/null
+++ b/examples/hlapi/twisted/manager/cmdgen/getbulk-to-eom.py
@@ -0,0 +1,52 @@
+"""
+Bulk walk MIB
++++++++++++++
+
+Send a series of SNMP GETBULK requests using the following options:
+
+* with SNMPv3, user 'usr-none-none', no authentication, no privacy
+* over IPv4/UDP
+* to an Agent at demo.snmplabs.com:161
+* for all OIDs past SNMPv2-MIB::system
+* run till end-of-mib condition is reported by Agent
+* based on Twisted I/O framework
+
+Functionally similar to:
+
+| $ snmpbulkwalk -v3 -lnoAuthNoPriv -u usr-none-none -Cn0 -Cr50 \
+| demo.snmplabs.com SNMPv2-MIB::system
+
+"""#
+from twisted.internet.task import react
+from pysnmp.hlapi.twisted import *
+
+def success((errorStatus, errorIndex, varBindTable), reactor, snmpEngine):
+ 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:
+ print(' = '.join([ x.prettyPrint() for x in varBind ]))
+
+ if not isEndOfMib(varBindTable[-1]):
+ return getbulk(reactor, snmpEngine, *varBindTable[-1])
+
+def failure(errorIndication):
+ print(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
+
+react(getbulk, [SnmpEngine(), ObjectType(ObjectIdentity('SNMPv2-MIB', 'system'))])
diff --git a/examples/hlapi/twisted/manager/cmdgen/multiple-concurrent-async-queries.py b/examples/hlapi/twisted/manager/cmdgen/multiple-concurrent-async-queries.py
new file mode 100644
index 0000000..5349e97
--- /dev/null
+++ b/examples/hlapi/twisted/manager/cmdgen/multiple-concurrent-async-queries.py
@@ -0,0 +1,56 @@
+"""
+Concurrent queries
+++++++++++++++++++
+
+Send multiple SNMP GET requests at once using the following options:
+
+* with SNMPv2c, community 'public'
+* over IPv4/UDP
+* to an Agent at demo.snmplabs.com:161
+* for two instances of SNMPv2-MIB::sysDescr.0 and SNMPv2-MIB::sysLocation.0
+ MIB object,
+* based on Twisted I/O framework
+
+Functionally similar to:
+
+| $ snmpget -v2c -c public demo.snmplabs.com SNMPv2-MIB::sysDescr.0
+| $ snmpget -v2c -c public demo.snmplabs.com SNMPv2-MIB::sysLocation.0
+
+"""#
+from twisted.internet.defer import DeferredList
+from twisted.internet.task import react
+from pysnmp.hlapi.twisted import *
+
+def success((errorStatus, errorIndex, varBinds), hostname):
+ 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 ]))
+
+def failure(errorIndication, hostname):
+ print('%s failure: %s' % (hostname, errorIndication))
+
+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
+
+ return DeferredList(
+ [getScalar(ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0))),
+ getScalar(ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0)))]
+ )
+
+react(getSystem, ['demo.snmplabs.com'])
diff --git a/examples/hlapi/twisted/manager/cmdgen/pull-mibs-from-multiple-agents-at-once.py b/examples/hlapi/twisted/manager/cmdgen/pull-mibs-from-multiple-agents-at-once.py
new file mode 100644
index 0000000..30d710b
--- /dev/null
+++ b/examples/hlapi/twisted/manager/cmdgen/pull-mibs-from-multiple-agents-at-once.py
@@ -0,0 +1,61 @@
+"""
+Walk multiple Agents at once
+++++++++++++++++++++++++++++
+
+* with SNMPv3 with user 'usr-md5-none', MD5 auth and no privacy protocols
+* over IPv4/UDP
+* to Agents at demo.snmplabs.com:161 and demo.snmplabs.com:1161
+* for multiple MIB subtrees and tables
+* for whole MIB
+* based on Twisted I/O framework
+
+Functionally similar to:
+
+| $ snmpget -v2c -c public demo.snmplabs.com:161 SNMPv2-MIB::system
+| $ snmpget -v2c -c public demo.snmplabs.comL1161 SNMPv2-MIB::system
+
+"""#
+from twisted.internet.defer import DeferredList
+from twisted.internet.task import react
+from pysnmp.hlapi.twisted import *
+
+def success((errorStatus, errorIndex, varBindTable), reactor, snmpEngine, hostname):
+ 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:
+ print(' = '.join([ x.prettyPrint() for x in varBind ]))
+
+ if not isEndOfMib(varBindTable[-1]):
+ return getbulk(reactor, snmpEngine, hostname, *varBindTable[-1])
+
+def failure(errorIndication):
+ print(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
+
+def getall(reactor, hostnames):
+ snmpEngine = SnmpEngine()
+
+ return DeferredList(
+ [ getbulk(reactor, snmpEngine, hostname,
+ ObjectType(ObjectIdentity('SNMPv2-MIB', 'system')))
+ for hostname in hostnames ]
+ )
+
+react(getall, [(('demo.snmplabs.com', 161), ('demo.snmplabs.com', 1161))])
+
diff --git a/examples/hlapi/twisted/manager/cmdgen/pull-whole-mib.py b/examples/hlapi/twisted/manager/cmdgen/pull-whole-mib.py
new file mode 100644
index 0000000..6df1668
--- /dev/null
+++ b/examples/hlapi/twisted/manager/cmdgen/pull-whole-mib.py
@@ -0,0 +1,50 @@
+"""
+Walk whole MIB
+++++++++++++++
+
+Send a series of SNMP GETNEXT requests using the following options:
+
+* with SNMPv3, user 'usr-md5-none', MD5 authentication, no privacy
+* over IPv4/UDP
+* to an Agent at demo.snmplabs.com:161
+* for all OIDs in IF-MIB
+* based on Twisted I/O framework
+
+Functionally similar to:
+
+| $ snmpwalk -v3 -lauthPriv -u usr-md5-none -A authkey1 -X privkey1 \
+| demo.snmplabs.com IF-MIB::
+
+"""#
+from twisted.internet.task import react
+from pysnmp.hlapi.twisted import *
+
+def success((errorStatus, errorIndex, varBindTable), reactor, snmpEngine):
+ 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:
+ print(' = '.join([ x.prettyPrint() for x in varBind ]))
+
+ if not isEndOfMib(varBindTable[-1]):
+ return getnext(reactor, snmpEngine, *varBindTable[-1])
+
+def failure(errorIndication):
+ print(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
+
+react(getnext, [SnmpEngine(), ObjectType(ObjectIdentity('SNMPv2-MIB', 'system'))])
diff --git a/examples/hlapi/twisted/manager/cmdgen/v1-get.py b/examples/hlapi/twisted/manager/cmdgen/v1-get.py
new file mode 100644
index 0000000..02b3690
--- /dev/null
+++ b/examples/hlapi/twisted/manager/cmdgen/v1-get.py
@@ -0,0 +1,47 @@
+"""
+SNMPv1
+++++++
+
+Send SNMP GET request using the following options:
+
+* with SNMPv1, community 'public'
+* over IPv4/UDP
+* to an Agent at demo.snmplabs.com:161
+* for two instances of SNMPv2-MIB::sysDescr.0 MIB object,
+* based on Twisted I/O framework
+
+Functionally similar to:
+
+| $ snmpget -v1 -c public demo.snmplabs.com SNMPv2-MIB::sysDescr.0
+
+"""#
+from twisted.internet.task import react
+from pysnmp.hlapi.twisted import *
+
+def success((errorStatus, errorIndex, varBinds), hostname):
+ 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 ]))
+
+def failure(errorIndication, hostname):
+ print('%s failure: %s' % (hostname, errorIndication))
+
+def getSysDescr(reactor, hostname):
+ d = getCmd(SnmpEngine(),
+ CommunityData('public', mpModel=0),
+ UdpTransportTarget((hostname, 161)),
+ ContextData(),
+ ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)))
+
+ d.addCallback(success, hostname).addErrback(failure, hostname)
+
+ return d
+
+react(getSysDescr, ['demo.snmplabs.com'])