summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorelie <elie>2015-07-06 21:30:04 +0000
committerelie <elie>2015-07-06 21:30:04 +0000
commitf308702c7867aa3cfb778a4ed6bd0b15c118073d (patch)
tree0087c2861fe78fbb7b52042310b7bd1c61785886 /examples
parent51841e9cba10f8d1dbaf2d1a7e8ecef0df3ce366 (diff)
downloadpysnmp-git-f308702c7867aa3cfb778a4ed6bd0b15c118073d.tar.gz
synchronous oneliner apps redesigned to offer Python generator-based
API along with more comprehensive set of accepted parameters
Diffstat (limited to 'examples')
-rw-r--r--examples/hlapi/asyncore/manager/cmdgen/multiple-concurrent-queries.py20
-rw-r--r--examples/hlapi/asyncore/manager/cmdgen/pull-mibs-from-multiple-agents-at-once.py15
-rw-r--r--examples/hlapi/asyncore/manager/cmdgen/query-multiple-snmp-engines.py12
-rw-r--r--examples/hlapi/asyncore/sync/agent/ntforg/custom-contextengineid.py51
-rw-r--r--examples/hlapi/asyncore/sync/agent/ntforg/custom-contextname.py47
-rw-r--r--examples/hlapi/asyncore/sync/agent/ntforg/custom-v1-trap.py41
-rw-r--r--examples/hlapi/asyncore/sync/agent/ntforg/default-v1-trap.py34
-rw-r--r--examples/hlapi/asyncore/sync/agent/ntforg/send-notification-with-additional-varbinds.py53
-rw-r--r--examples/hlapi/asyncore/sync/agent/ntforg/v2c-trap-via-notification-type.py26
-rw-r--r--examples/hlapi/asyncore/sync/agent/ntforg/v3-inform.py50
-rw-r--r--examples/hlapi/asyncore/sync/agent/ntforg/v3-trap.py42
-rw-r--r--examples/hlapi/asyncore/sync/manager/cmdgen/coerce-set-value-to-mib-spec.py48
-rw-r--r--examples/hlapi/asyncore/sync/manager/cmdgen/custom-asn1-mib-search-path.py46
-rw-r--r--examples/hlapi/asyncore/sync/manager/cmdgen/custom-contextengineid-and-contextname.py53
-rw-r--r--examples/hlapi/asyncore/sync/manager/cmdgen/custom-contextengineid.py58
-rw-r--r--examples/hlapi/asyncore/sync/manager/cmdgen/custom-pysnmp-mibs-search-path.py51
-rw-r--r--examples/hlapi/asyncore/sync/manager/cmdgen/custom-timeout-and-retries.py44
-rw-r--r--examples/hlapi/asyncore/sync/manager/cmdgen/custom-v3-security-name.py43
-rw-r--r--examples/hlapi/asyncore/sync/manager/cmdgen/fetch-variables-over-ipv6.py46
-rw-r--r--examples/hlapi/asyncore/sync/manager/cmdgen/get-table-object-by-index.py44
-rw-r--r--examples/hlapi/asyncore/sync/manager/cmdgen/get-table-object-by-multiple-indices.py51
-rw-r--r--examples/hlapi/asyncore/sync/manager/cmdgen/getbulk-fetch-scalar-and-table-variables.py52
-rw-r--r--examples/hlapi/asyncore/sync/manager/cmdgen/getnext-limit-number-of-variables.py51
-rw-r--r--examples/hlapi/asyncore/sync/manager/cmdgen/getnext-multiple-oids-to-eom.py45
-rw-r--r--examples/hlapi/asyncore/sync/manager/cmdgen/preload-pysnmp-mibs.py45
-rw-r--r--examples/hlapi/asyncore/sync/manager/cmdgen/pull-whole-mib.py47
-rw-r--r--examples/hlapi/asyncore/sync/manager/cmdgen/pull-whole-snmp-table.py54
-rw-r--r--examples/hlapi/asyncore/sync/manager/cmdgen/set-multiple-scalar-values.py46
-rw-r--r--examples/hlapi/asyncore/sync/manager/cmdgen/specific-v3-engine-id.py30
-rw-r--r--examples/hlapi/asyncore/sync/manager/cmdgen/usm-md5-none.py42
-rw-r--r--examples/hlapi/asyncore/sync/manager/cmdgen/v1-get.py45
-rw-r--r--examples/hlapi/asyncore/sync/manager/cmdgen/v2c-get.py44
-rw-r--r--examples/hlapi/asyncore/sync/manager/cmdgen/v2c-getbulk.py47
-rw-r--r--examples/hlapi/asyncore/sync/manager/cmdgen/waive-mib-lookup.py45
34 files changed, 750 insertions, 718 deletions
diff --git a/examples/hlapi/asyncore/manager/cmdgen/multiple-concurrent-queries.py b/examples/hlapi/asyncore/manager/cmdgen/multiple-concurrent-queries.py
index d169377e..e50a54b4 100644
--- a/examples/hlapi/asyncore/manager/cmdgen/multiple-concurrent-queries.py
+++ b/examples/hlapi/asyncore/manager/cmdgen/multiple-concurrent-queries.py
@@ -22,29 +22,29 @@ targets = (
# 1-st target (SNMPv1 over IPv4/UDP)
( cmdgen.CommunityData('public', mpModel=0),
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
- ( cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0),
- cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0) ) ),
+ ( cmdgen.ObjectType(cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)),
+ cmdgen.ObjectType(cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0) )) ),
# 2-nd target (SNMPv2c over IPv4/UDP)
( cmdgen.CommunityData('public'),
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
- ( cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0),
- cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0) ) ),
+ ( cmdgen.ObjectType(cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)),
+ cmdgen.ObjectType(cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0) )) ),
# 3-nd target (SNMPv2c over IPv4/UDP) - same community and
# different transport address.
( cmdgen.CommunityData('public'),
cmdgen.UdpTransportTarget(('localhost', 161)),
- ( cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysContact', 0),
- cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysName', 0) ) ),
+ ( cmdgen.ObjectType(cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysContact', 0)),
+ cmdgen.ObjectType(cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysName', 0))) ),
# 4-nd target (SNMPv3 over IPv4/UDP)
( cmdgen.UsmUserData('usr-md5-des', 'authkey1', 'privkey1'),
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
- ( cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0),
- cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0) ) ),
+ ( cmdgen.ObjectType(cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)),
+ cmdgen.ObjectType(cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0) )) ),
# 5-th target (SNMPv3 over IPv6/UDP)
( cmdgen.UsmUserData('usr-md5-none', 'authkey1'),
cmdgen.Udp6TransportTarget(('::1', 161)),
- ( cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0),
- cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0) ) ),
+ ( cmdgen.ObjectType(cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)),
+ cmdgen.ObjectType(cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0) )) ),
# N-th target
# ...
)
diff --git a/examples/hlapi/asyncore/manager/cmdgen/pull-mibs-from-multiple-agents-at-once.py b/examples/hlapi/asyncore/manager/cmdgen/pull-mibs-from-multiple-agents-at-once.py
index 80ff0fe1..b1304aec 100644
--- a/examples/hlapi/asyncore/manager/cmdgen/pull-mibs-from-multiple-agents-at-once.py
+++ b/examples/hlapi/asyncore/manager/cmdgen/pull-mibs-from-multiple-agents-at-once.py
@@ -21,19 +21,20 @@ targets = (
# 1-st target (SNMPv1 over IPv4/UDP)
( cmdgen.CommunityData('public', mpModel=0),
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
- ( '1.3.6.1.2.1', '1.3.6.1.3.1') ),
+ ( cmdgen.ObjectType(cmdgen.ObjectIdentity('1.3.6.1.2.1')),
+ cmdgen.ObjectType(cmdgen.ObjectIdentity('1.3.6.1.3.1')) ) ),
# 2-nd target (SNMPv2c over IPv4/UDP)
( cmdgen.CommunityData('public'),
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
- ( '1.3.6.1.4.1', ) ),
+ ( cmdgen.ObjectType(cmdgen.ObjectIdentity('1.3.6.1.4.1')), ) ),
# 3-nd target (SNMPv3 over IPv4/UDP)
( cmdgen.UsmUserData('usr-md5-des', 'authkey1', 'privkey1'),
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
- ( cmdgen.ObjectIdentity('SNMPv2-MIB', 'system'), ) ),
+ ( cmdgen.ObjectType(cmdgen.ObjectIdentity('SNMPv2-MIB', 'system')), ) ),
# 4-th target (SNMPv3 over IPv6/UDP)
( cmdgen.UsmUserData('usr-md5-none', 'authkey1'),
cmdgen.Udp6TransportTarget(('::1', 161)),
- ( cmdgen.ObjectIdentity('IF-MIB', 'ifTable'), ) )
+ ( cmdgen.ObjectType(cmdgen.ObjectIdentity('IF-MIB', 'ifTable')), ) )
# N-th target
# ...
)
@@ -77,10 +78,10 @@ snmpEngine = engine.SnmpEngine()
cmdGen = cmdgen.AsyncCommandGenerator()
# Submit initial GETNEXT requests and wait for responses
-for authData, transportTarget, varNames in targets:
- varBindHead = cmdGen.makeVarBindsHead(snmpEngine, varNames)
+for authData, transportTarget, varBinds in targets:
+ varBindHead = [ x[0] for x in cmdGen.makeVarBinds(snmpEngine, varBinds ) ]
cmdGen.nextCmd(
- snmpEngine, authData, transportTarget, cmdgen.ContextData(), varNames,
+ snmpEngine, authData, transportTarget, cmdgen.ContextData(), varBinds,
# User-space callback function and its context
(cbFun, (varBindHead, authData, transportTarget)),
lookupNames=True, lookupValues=True
diff --git a/examples/hlapi/asyncore/manager/cmdgen/query-multiple-snmp-engines.py b/examples/hlapi/asyncore/manager/cmdgen/query-multiple-snmp-engines.py
index 45ae42b0..85586ed5 100644
--- a/examples/hlapi/asyncore/manager/cmdgen/query-multiple-snmp-engines.py
+++ b/examples/hlapi/asyncore/manager/cmdgen/query-multiple-snmp-engines.py
@@ -35,18 +35,18 @@ targets = (
# 1-st target (SNMPv1 over IPv4/UDP)
( cmdgen.CommunityData('public', mpModel=0),
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
- ( cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0),
- cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0) ) ),
+ ( cmdgen.ObjectType(cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)),
+ cmdgen.ObjectType(cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0) )) ),
# 2-nd target (SNMPv2c over IPv4/UDP)
( cmdgen.CommunityData('public'),
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 1161)),
- ( cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0),
- cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0) ) ),
+ ( cmdgen.ObjectType(cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)),
+ cmdgen.ObjectType(cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0) )) ),
# 3-nd target (SNMPv3 over IPv4/UDP)
( cmdgen.UsmUserData('usr-md5-des', 'authkey1', 'privkey1'),
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 2161)),
- ( cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0),
- cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0) ) )
+ ( cmdgen.ObjectType(cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)),
+ cmdgen.ObjectType(cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0) )) )
# N-th target
# ...
)
diff --git a/examples/hlapi/asyncore/sync/agent/ntforg/custom-contextengineid.py b/examples/hlapi/asyncore/sync/agent/ntforg/custom-contextengineid.py
index 5e8c0535..071c3362 100644
--- a/examples/hlapi/asyncore/sync/agent/ntforg/custom-contextengineid.py
+++ b/examples/hlapi/asyncore/sync/agent/ntforg/custom-contextengineid.py
@@ -14,28 +14,33 @@
# requires having a collection of Managed Objects registered under
# the ContextEngineId being used.
#
-from pysnmp.entity import engine
-from pysnmp.entity.rfc3413 import context
-from pysnmp.entity.rfc3413.oneliner import ntforg
+from pysnmp.entity.rfc3413.oneliner.ntforg import *
from pysnmp.proto import rfc1902
-snmpEngine = engine.SnmpEngine()
-
-ntfOrg = ntforg.NotificationOriginator(snmpEngine)
-
-errorIndication, errorStatus, errorIndex, varBinds = ntfOrg.sendNotification(
- ntforg.UsmUserData('usr-md5-none', 'authkey1'),
- ntforg.UdpTransportTarget(('localhost', 162)),
- 'inform',
- ntforg.NotificationType(ntforg.ObjectIdentity('1.3.6.1.6.3.1.1.5.2')),
- contextEngineId=rfc1902.OctetString(hexValue='8000000004030201')
-)
-
-if errorIndication:
- print('Notification not sent: %s' % errorIndication)
-elif errorStatus:
- print('Notification Receiver returned error: %s @%s' %
- (errorStatus, errorIndex))
-else:
- for name, val in varBinds:
- print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
+for errorIndication, \
+ errorStatus, errorIndex, \
+ varBinds in \
+ sendNotification(SnmpEngine(),
+ UsmUserData('usr-md5-none', 'authkey1'),
+ UdpTransportTarget(('localhost', 162)),
+ ContextData(
+ rfc1902.OctetString(hexValue='8000000004030201')
+ ),
+ 'inform',
+ NotificationType(
+ ObjectIdentity('1.3.6.1.6.3.1.1.5.2')
+ ),
+ lookupNames=True, lookupValues=True):
+ # Check for errors and print out results
+ if errorIndication:
+ print(errorIndication)
+ else:
+ if 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/asyncore/sync/agent/ntforg/custom-contextname.py b/examples/hlapi/asyncore/sync/agent/ntforg/custom-contextname.py
index dfe0ad04..ed87fdc8 100644
--- a/examples/hlapi/asyncore/sync/agent/ntforg/custom-contextname.py
+++ b/examples/hlapi/asyncore/sync/agent/ntforg/custom-contextname.py
@@ -14,25 +14,30 @@
# requires having a collection of Managed Objects registered under
# the ContextName being used.
#
-from pysnmp.entity import engine
-from pysnmp.entity.rfc3413.oneliner import ntforg
+from pysnmp.entity.rfc3413.oneliner.ntforg import *
-snmpEngine = engine.SnmpEngine()
-
-ntfOrg = ntforg.NotificationOriginator(snmpEngine)
-
-errorIndication, errorStatus, errorIndex, varBinds = ntfOrg.sendNotification(
- ntforg.UsmUserData('usr-md5-none', 'authkey1'),
- ntforg.UdpTransportTarget(('localhost', 162)),
- 'inform',
- ntforg.NotificationType(ntforg.ObjectIdentity('1.3.6.1.6.3.1.1.5.2')),
- contextName='my-context'
-)
-
-if errorIndication:
- print('Notification not sent: %s' % errorIndication)
-elif errorStatus:
- print('Notification Receiver returned error: %s @%s' % (errorStatus, errorIndex))
-else:
- for name, val in varBinds:
- print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
+for errorIndication, \
+ errorStatus, errorIndex, \
+ varBinds in \
+ sendNotification(SnmpEngine(),
+ UsmUserData('usr-md5-none', 'authkey1'),
+ UdpTransportTarget(('localhost', 162)),
+ ContextData(contextName='my-context'),
+ 'inform',
+ NotificationType(
+ ObjectIdentity('1.3.6.1.6.3.1.1.5.2')
+ ),
+ lookupNames=True, lookupValues=True):
+ # Check for errors and print out results
+ if errorIndication:
+ print(errorIndication)
+ else:
+ if 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/asyncore/sync/agent/ntforg/custom-v1-trap.py b/examples/hlapi/asyncore/sync/agent/ntforg/custom-v1-trap.py
index 7db778e3..1d2b825e 100644
--- a/examples/hlapi/asyncore/sync/agent/ntforg/custom-v1-trap.py
+++ b/examples/hlapi/asyncore/sync/agent/ntforg/custom-v1-trap.py
@@ -13,27 +13,24 @@
# * overriding Enterprise OID with 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'
#
-from pysnmp.entity.rfc3413.oneliner import ntforg
+from pysnmp.entity.rfc3413.oneliner.ntforg import *
from pysnmp.proto import rfc1902
-#from pysnmp import debug
-#debug.setLogger(debug.Debug('mibview'))
-
-ntfOrg = ntforg.NotificationOriginator()
-
-errorIndication = ntfOrg.sendNotification(
- ntforg.CommunityData('public', mpModel=0),
- ntforg.UdpTransportTarget(('localhost', 162)),
- 'trap',
- ntforg.NotificationType(
- ntforg.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', rfc1902.OctetString('my system'))
- )
-)
-
-if errorIndication:
- print('Notification not sent: %s' % errorIndication)
+for errorIndication, \
+ errorStatus, errorIndex, \
+ varBinds in \
+ sendNotification(SnmpEngine(),
+ CommunityData('public', mpModel=0),
+ UdpTransportTarget(('localhost', 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', rfc1902.OctetString('my system'))
+ )):
+ if errorIndication:
+ print(errorIndication)
diff --git a/examples/hlapi/asyncore/sync/agent/ntforg/default-v1-trap.py b/examples/hlapi/asyncore/sync/agent/ntforg/default-v1-trap.py
index beab6e7c..a7041462 100644
--- a/examples/hlapi/asyncore/sync/agent/ntforg/default-v1-trap.py
+++ b/examples/hlapi/asyncore/sync/agent/ntforg/default-v1-trap.py
@@ -13,22 +13,22 @@
# * 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'
#
-from pysnmp.entity.rfc3413.oneliner import ntforg
+from pysnmp.entity.rfc3413.oneliner.ntforg import *
from pysnmp.proto import rfc1902
-ntfOrg = ntforg.NotificationOriginator()
-
-errorIndication = ntfOrg.sendNotification(
- ntforg.CommunityData('public', mpModel=0),
- ntforg.UdpTransportTarget(('localhost', 162)),
- 'trap',
- ntforg.NotificationType(
- ntforg.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'))
- )
-)
-
-if errorIndication:
- print('Notification not sent: %s' % errorIndication)
+for errorIndication, \
+ errorStatus, errorIndex, \
+ varBinds in \
+ sendNotification(SnmpEngine(),
+ CommunityData('public', mpModel=0),
+ UdpTransportTarget(('localhost', 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', rfc1902.OctetString('my system'))
+ )):
+ if errorIndication:
+ print(errorIndication)
diff --git a/examples/hlapi/asyncore/sync/agent/ntforg/send-notification-with-additional-varbinds.py b/examples/hlapi/asyncore/sync/agent/ntforg/send-notification-with-additional-varbinds.py
index 330b6b24..6eebaa93 100644
--- a/examples/hlapi/asyncore/sync/agent/ntforg/send-notification-with-additional-varbinds.py
+++ b/examples/hlapi/asyncore/sync/agent/ntforg/send-notification-with-additional-varbinds.py
@@ -11,29 +11,32 @@
# * include managed object information specified as a MIB symbol
# * perform response OIDs and values resolution at MIB
#
-from pysnmp.entity.rfc3413.oneliner import ntforg
-
-ntfOrg = ntforg.NotificationOriginator()
-
-errorIndication, errorStatus, errorIndex, varBinds = ntfOrg.sendNotification(
- ntforg.CommunityData('public'),
- ntforg.UdpTransportTarget(('localhost', 162)),
- 'inform',
- ntforg.NotificationType(
- ntforg.ObjectIdentity('SNMPv2-MIB', 'coldStart')
- ).addVarBinds(
- ( ntforg.ObjectIdentity('SNMPv2-MIB', 'sysName', 0), 'my system' )
- ),
- lookupNames=True, lookupValues=True
-)
-
-if errorIndication:
- print('Notification not sent: %s' % errorIndication)
-elif errorStatus:
- print('Notification Receiver returned error: %s @%s' %
- (errorStatus, errorIndex))
-else:
- for name, val in varBinds:
- print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
-
+from pysnmp.entity.rfc3413.oneliner.ntforg import *
+for errorIndication, \
+ errorStatus, errorIndex, \
+ varBinds in \
+ sendNotification(SnmpEngine(),
+ CommunityData('public'),
+ UdpTransportTarget(('localhost', 162)),
+ ContextData(),
+ 'inform',
+ NotificationType(
+ ObjectIdentity('SNMPv2-MIB', 'coldStart')
+ ).addVarBinds(
+ ( ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysName', 0), 'my system') )
+ ),
+ lookupNames=True, lookupValues=True):
+ # Check for errors and print out results
+ if errorIndication:
+ print(errorIndication)
+ else:
+ if 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/asyncore/sync/agent/ntforg/v2c-trap-via-notification-type.py b/examples/hlapi/asyncore/sync/agent/ntforg/v2c-trap-via-notification-type.py
index 502b3a0e..b243f438 100644
--- a/examples/hlapi/asyncore/sync/agent/ntforg/v2c-trap-via-notification-type.py
+++ b/examples/hlapi/asyncore/sync/agent/ntforg/v2c-trap-via-notification-type.py
@@ -10,16 +10,18 @@
# * with TRAP ID 'coldStart' specified as a MIB symbol
# * include managed object information specified as a MIB symbol
#
-from pysnmp.entity.rfc3413.oneliner import ntforg
+from pysnmp.entity.rfc3413.oneliner.ntforg import *
-ntfOrg = ntforg.NotificationOriginator()
-
-errorIndication = ntfOrg.sendNotification(
- ntforg.CommunityData('public'),
- ntforg.UdpTransportTarget(('localhost', 162)),
- 'trap',
- ntforg.NotificationType(ntforg.ObjectIdentity('SNMPv2-MIB', 'coldStart'))
-)
-
-if errorIndication:
- print('Notification not sent: %s' % errorIndication)
+for errorIndication, \
+ errorStatus, errorIndex, \
+ varBinds in \
+ sendNotification(SnmpEngine(),
+ CommunityData('public'),
+ UdpTransportTarget(('localhost', 162)),
+ ContextData(),
+ 'trap',
+ NotificationType(
+ ObjectIdentity('SNMPv2-MIB', 'coldStart')
+ )):
+ if errorIndication:
+ print(errorIndication)
diff --git a/examples/hlapi/asyncore/sync/agent/ntforg/v3-inform.py b/examples/hlapi/asyncore/sync/agent/ntforg/v3-inform.py
index f9abe916..2996eb51 100644
--- a/examples/hlapi/asyncore/sync/agent/ntforg/v3-inform.py
+++ b/examples/hlapi/asyncore/sync/agent/ntforg/v3-inform.py
@@ -10,27 +10,35 @@
# * with TRAP ID 'warmStart' specified as a string OID
# * include managed object information 1.3.6.1.2.1.1.5.0 = 'system name'
#
-from pysnmp.entity.rfc3413.oneliner import ntforg
+from pysnmp.entity.rfc3413.oneliner.ntforg import *
from pysnmp.proto import rfc1902
-ntfOrg = ntforg.NotificationOriginator()
+for errorIndication, \
+ errorStatus, errorIndex, \
+ varBinds in \
+ sendNotification(SnmpEngine(),
+ UsmUserData('usr-md5-des', 'authkey1', 'privkey1'),
+ UdpTransportTarget(('localhost', 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'),
+ rfc1902.OctetString('system name')) )
+ ),
+ lookupNames=True, lookupValues=True):
+ # Check for errors and print out results
+ if errorIndication:
+ print(errorIndication)
+ else:
+ if 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 ]))
-errorIndication, errorStatus, errorIndex, varBinds = ntfOrg.sendNotification(
- ntforg.UsmUserData('usr-md5-des', 'authkey1', 'privkey1'),
- ntforg.UdpTransportTarget(('localhost', 162)),
- 'inform',
- ntforg.NotificationType(
- ntforg.ObjectIdentity('1.3.6.1.6.3.1.1.5.2')
- ).addVarBinds(
- ('1.3.6.1.2.1.1.5.0', rfc1902.OctetString('system name'))
- )
-)
-
-if errorIndication:
- print('Notification not sent: %s' % errorIndication)
-elif errorStatus:
- print('Notification Receiver returned error: %s @%s' %
- (errorStatus, errorIndex))
-else:
- for name, val in varBinds:
- print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
diff --git a/examples/hlapi/asyncore/sync/agent/ntforg/v3-trap.py b/examples/hlapi/asyncore/sync/agent/ntforg/v3-trap.py
index 60cb0a6c..bbc91940 100644
--- a/examples/hlapi/asyncore/sync/agent/ntforg/v3-trap.py
+++ b/examples/hlapi/asyncore/sync/agent/ntforg/v3-trap.py
@@ -4,7 +4,7 @@
# Send SNMP notification using the following options:
#
# * SNMPv3
-# * with local snmpEngineId = 0x8000000001020304
+# * with local snmpEngineId = 0x8000000001020304 (must configure at Receiver)
# * with user 'usr-sha-aes128', auth: SHA, priv: AES128
# * over IPv4/UDP
# * send TRAP notification
@@ -15,25 +15,23 @@
# value of SnmpEngineId with Notification Receiver. To facilitate that
# we will use static (e.g. not autogenerated) version of snmpEngineId.
#
-from pysnmp.entity import engine
-from pysnmp.entity.rfc3413.oneliner import ntforg
-from pysnmp.proto import rfc1902
+from pysnmp.entity.rfc3413.oneliner.ntforg import *
+from pysnmp.proto.rfc1902 import OctetString
-# This SNMP Engine ID value should also be configured to TRAP receiver.
-snmpEngineId = rfc1902.OctetString(hexValue='8000000001020304')
-
-ntfOrg = ntforg.NotificationOriginator(engine.SnmpEngine(snmpEngineId))
-
-errorIndication = ntfOrg.sendNotification(
- ntforg.UsmUserData('usr-sha-aes128', 'authkey1', 'privkey1',
- authProtocol=ntforg.usmHMACSHAAuthProtocol,
- privProtocol=ntforg.usmAesCfb128Protocol),
- ntforg.UdpTransportTarget(('127.0.0.1', 162)),
- 'trap',
- ntforg.NotificationType(
- ntforg.ObjectIdentity('SNMPv2-MIB', 'authenticationFailure')
- )
-)
-
-if errorIndication:
- print('Notification not sent: %s' % errorIndication)
+for errorIndication, \
+ errorStatus, errorIndex, \
+ varBinds in \
+ sendNotification(SnmpEngine(
+ OctetString(hexValue='8000000001020304')
+ ),
+ UsmUserData('usr-sha-aes128', 'authkey1', 'privkey1',
+ authProtocol=usmHMACSHAAuthProtocol,
+ privProtocol=usmAesCfb128Protocol),
+ UdpTransportTarget(('localhost', 162)),
+ ContextData(),
+ 'trap',
+ NotificationType(
+ ObjectIdentity('SNMPv2-MIB', 'authenticationFailure')
+ )):
+ if errorIndication:
+ print(errorIndication)
diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/coerce-set-value-to-mib-spec.py b/examples/hlapi/asyncore/sync/manager/cmdgen/coerce-set-value-to-mib-spec.py
index 6732ec29..46d4c5ec 100644
--- a/examples/hlapi/asyncore/sync/manager/cmdgen/coerce-set-value-to-mib-spec.py
+++ b/examples/hlapi/asyncore/sync/manager/cmdgen/coerce-set-value-to-mib-spec.py
@@ -8,29 +8,29 @@
# * to an Agent at demo.snmplabs.com:161
# * setting SNMPv2-MIB::sysName.0 to new value (type taken from MIB)
#
-from pysnmp.entity.rfc3413.oneliner import cmdgen
+from pysnmp.entity.rfc3413.oneliner.cmdgen import *
-cmdGen = cmdgen.CommandGenerator()
-
-errorIndication, errorStatus, errorIndex, varBinds = cmdGen.setCmd(
- cmdgen.CommunityData('public'),
- cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
- cmdgen.ObjectType(
- cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysORDescr', 1),
- 'new system name'
- )
-)
-
-# Check for errors and print out results
-if errorIndication:
- print(errorIndication)
-else:
- if errorStatus:
- print('%s at %s' % (
- errorStatus.prettyPrint(),
- errorIndex and varBinds[int(errorIndex)-1][0] or '?'
- )
- )
+for errorIndication, \
+ errorStatus, errorIndex, \
+ varBinds in setCmd(SnmpEngine(),
+ CommunityData('public'),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ ContextData(),
+ ObjectType(
+ ObjectIdentity('SNMPv2-MIB', 'sysORDescr', 1),
+ 'new system name'
+ )):
+ # Check for errors and print out results
+ if errorIndication:
+ print(errorIndication)
else:
- for name, val in varBinds:
- print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
+ if 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 ]))
+ break
diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/custom-asn1-mib-search-path.py b/examples/hlapi/asyncore/sync/manager/cmdgen/custom-asn1-mib-search-path.py
index 9c2db805..fba316f5 100644
--- a/examples/hlapi/asyncore/sync/manager/cmdgen/custom-asn1-mib-search-path.py
+++ b/examples/hlapi/asyncore/sync/manager/cmdgen/custom-asn1-mib-search-path.py
@@ -9,27 +9,29 @@
# * for IF-MIB::ifInOctets.1 MIB object
# * Pass attached MIB compiler non-default ASN.1 MIB source
#
-from pysnmp.entity.rfc3413.oneliner import cmdgen
+from pysnmp.entity.rfc3413.oneliner.cmdgen import *
-cmdGen = cmdgen.CommandGenerator()
-
-errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
- cmdgen.CommunityData('public'),
- cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
- cmdgen.ObjectIdentity('IF-MIB', 'ifInOctets', 1).addAsn1MibSource('file:///usr/share/snmp', 'http://mibs.snmplabs.com/asn1/@mib@'),
- lookupNames=True, lookupValues=True
-)
-
-# Check for errors and print out results
-if errorIndication:
- print(errorIndication)
-else:
- if errorStatus:
- print('%s at %s' % (
- errorStatus.prettyPrint(),
- errorIndex and varBinds[int(errorIndex)-1][0] or '?'
- )
- )
+for errorIndication, \
+ errorStatus, errorIndex, \
+ varBinds in 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@')
+ ),
+ lookupNames=True, lookupValues=True):
+ # Check for errors and print out results
+ if errorIndication:
+ print(errorIndication)
else:
- for oid, val in varBinds:
- print('%s = %s' % (oid.prettyPrint(), val.prettyPrint()))
+ if 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 ]))
+ break
diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/custom-contextengineid-and-contextname.py b/examples/hlapi/asyncore/sync/manager/cmdgen/custom-contextengineid-and-contextname.py
index f28063b1..9c5b20f1 100644
--- a/examples/hlapi/asyncore/sync/manager/cmdgen/custom-contextengineid-and-contextname.py
+++ b/examples/hlapi/asyncore/sync/manager/cmdgen/custom-contextengineid-and-contextname.py
@@ -11,32 +11,33 @@
# * contextName 'a172334d7d97871b72241397f713fa12'
# * setting SNMPv2-MIB::sysName.0 to new value (type taken from MIB)
#
-from pysnmp.entity.rfc3413.oneliner import cmdgen
+from pysnmp.entity.rfc3413.oneliner.cmdgen import *
from pysnmp.proto import rfc1902
-cmdGen = cmdgen.CommandGenerator()
-
-errorIndication, errorStatus, errorIndex, varBinds = cmdGen.setCmd(
- cmdgen.UsmUserData('usr-md5-none', 'authkey1'),
- cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
- cmdgen.ObjectType(
- cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysORDescr', 1),
- 'new system name'
- ),
- contextEngineId=rfc1902.OctetString(hexValue='80004fb805636c6f75644dab22cc'),
- contextName='da761cfc8c94d3aceef4f60f049105ba'
-)
-
-# Check for errors and print out results
-if errorIndication:
- print(errorIndication)
-else:
- if errorStatus:
- print('%s at %s' % (
- errorStatus.prettyPrint(),
- errorIndex and varBinds[int(errorIndex)-1][0] or '?'
- )
- )
+for errorIndication, \
+ errorStatus, errorIndex, \
+ varBinds in setCmd(SnmpEngine(),
+ UsmUserData('usr-md5-none', 'authkey1'),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ ContextData(
+ contextEngineId=rfc1902.OctetString(hexValue='80004fb805636c6f75644dab22cc'),
+ contextName='da761cfc8c94d3aceef4f60f049105ba'
+ ),
+ ObjectType(
+ ObjectIdentity('SNMPv2-MIB', 'sysORDescr', 1),
+ 'new system name'
+ )):
+ # Check for errors and print out results
+ if errorIndication:
+ print(errorIndication)
else:
- for name, val in varBinds:
- print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
+ if 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 ]))
+ break
diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/custom-contextengineid.py b/examples/hlapi/asyncore/sync/manager/cmdgen/custom-contextengineid.py
index 124a26fa..22d165df 100644
--- a/examples/hlapi/asyncore/sync/manager/cmdgen/custom-contextengineid.py
+++ b/examples/hlapi/asyncore/sync/manager/cmdgen/custom-contextengineid.py
@@ -10,35 +10,35 @@
# * to an Agent at demo.snmplabs.com:161
# * setting SNMPv2-MIB::sysName.0 to new value (type taken from MIB)
#
-from pysnmp.entity.rfc3413.oneliner import cmdgen
+from pysnmp.entity.rfc3413.oneliner.cmdgen import *
from pysnmp.proto import rfc1902
-cmdGen = cmdgen.CommandGenerator()
-
-errorIndication, errorStatus, errorIndex, varBinds = cmdGen.setCmd(
- cmdgen.UsmUserData(
- 'usr-md5-des', 'authkey1', 'privkey1',
- securityEngineId=rfc1902.OctetString(
- hexValue='80004fb805636c6f75644dab22cc'
- )
- ),
- cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
- cmdgen.ObjectType(
- cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysORDescr', 1),
- 'new system name'
- )
-)
-
-# Check for errors and print out results
-if errorIndication:
- print(errorIndication)
-else:
- if errorStatus:
- print('%s at %s' % (
- errorStatus.prettyPrint(),
- errorIndex and varBinds[int(errorIndex)-1][0] or '?'
- )
- )
+for errorIndication, \
+ errorStatus, errorIndex, \
+ varBinds in setCmd(SnmpEngine(),
+ UsmUserData(
+ 'usr-md5-des', 'authkey1', 'privkey1',
+ securityEngineId=rfc1902.OctetString(
+ hexValue='80004fb805636c6f75644dab22cc'
+ )
+ ),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ ContextData(),
+ ObjectType(
+ ObjectIdentity('SNMPv2-MIB', 'sysORDescr', 1),
+ 'new system name'
+ )):
+ # Check for errors and print out results
+ if errorIndication:
+ print(errorIndication)
else:
- for name, val in varBinds:
- print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
+ if 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 ]))
+ break
diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/custom-pysnmp-mibs-search-path.py b/examples/hlapi/asyncore/sync/manager/cmdgen/custom-pysnmp-mibs-search-path.py
index 4ca6b6e9..5d1eb815 100644
--- a/examples/hlapi/asyncore/sync/manager/cmdgen/custom-pysnmp-mibs-search-path.py
+++ b/examples/hlapi/asyncore/sync/manager/cmdgen/custom-pysnmp-mibs-search-path.py
@@ -12,30 +12,31 @@
# maxCalls == 10 request-response interactions occur
# * ignoring non-increasing OIDs whenever reported by Agent
#
-# make sure IF-MIB.py is search path
-#
-from pysnmp.entity.rfc3413.oneliner import cmdgen
-
-cmdGen = cmdgen.CommandGenerator()
-
-errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.bulkCmd(
- cmdgen.UsmUserData('usr-none-none'),
- cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
- 0, 50,
- cmdgen.ObjectIdentity('TCP-MIB', 'tcpConnTable').addMibSource('/tmp/mibs'),
- lexicographicMode=True, maxRows=100, maxCalls=10,ignoreNonIncreasingOid=True
-)
+from pysnmp.entity.rfc3413.oneliner.cmdgen import *
-if errorIndication:
- print(errorIndication)
-else:
- if errorStatus:
- print('%s at %s' % (
- errorStatus.prettyPrint(),
- errorIndex and varBindTable[-1][int(errorIndex)-1][0] or '?'
- )
- )
+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('/tmp/mibs')),
+ maxRows=100, maxCalls=10,
+ lexicographicMode=True,
+ ignoreNonIncreasingOid=True):
+ # Check for errors and print out results
+ if errorIndication:
+ print(errorIndication)
+ break
else:
- for varBindTableRow in varBindTable:
- for name, val in varBindTableRow:
- print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
+ if 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/asyncore/sync/manager/cmdgen/custom-timeout-and-retries.py b/examples/hlapi/asyncore/sync/manager/cmdgen/custom-timeout-and-retries.py
index 35f575d5..d9fc4919 100644
--- a/examples/hlapi/asyncore/sync/manager/cmdgen/custom-timeout-and-retries.py
+++ b/examples/hlapi/asyncore/sync/manager/cmdgen/custom-timeout-and-retries.py
@@ -22,26 +22,28 @@
# if no response arrives, there will be no retry. Likewise, retries=1
# means one initial request plus one retry.
#
-from pysnmp.entity.rfc3413.oneliner import cmdgen
+from pysnmp.entity.rfc3413.oneliner.cmdgen import *
-cmdGen = cmdgen.CommandGenerator()
-
-errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
- cmdgen.CommunityData('public'),
- cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161),timeout=1.5,retries=0),
- '1.3.6.1.2.1.1.1.0',
-)
-
-# Check for errors and print out results
-if errorIndication:
- print(errorIndication)
-else:
- if errorStatus:
- print('%s at %s' % (
- errorStatus.prettyPrint(),
- errorIndex and varBinds[int(errorIndex)-1][0] or '?'
- )
- )
+for errorIndication, \
+ errorStatus, errorIndex, \
+ varBinds in getCmd(SnmpEngine(),
+ CommunityData('public'),
+ UdpTransportTarget(
+ ('demo.snmplabs.com', 161), timeout=1.5, retries=0
+ ),
+ ContextData(),
+ ObjectType(ObjectIdentity('1.3.6.1.2.1.1.1.0'))):
+ # Check for errors and print out results
+ if errorIndication:
+ print(errorIndication)
else:
- for name, val in varBinds:
- print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
+ if 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 ]))
+ break
diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/custom-v3-security-name.py b/examples/hlapi/asyncore/sync/manager/cmdgen/custom-v3-security-name.py
index c17e49b9..4770c5d3 100644
--- a/examples/hlapi/asyncore/sync/manager/cmdgen/custom-v3-security-name.py
+++ b/examples/hlapi/asyncore/sync/manager/cmdgen/custom-v3-security-name.py
@@ -14,26 +14,27 @@
# securityName can be made human-readable, also it is not an index in
# usmUserTable, thus duplicate securityName parameters are possible.
#
-from pysnmp.entity.rfc3413.oneliner import cmdgen
+from pysnmp.entity.rfc3413.oneliner.cmdgen import *
-cmdGen = cmdgen.CommandGenerator()
-
-errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
- cmdgen.UsmUserData('usr-md5-none', 'authkey1', securityName='myuser'),
- cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
- '1.3.6.1.2.1.1.1.0'
-)
-
-# Check for errors and print out results
-if errorIndication:
- print(errorIndication)
-else:
- if errorStatus:
- print('%s at %s' % (
- errorStatus.prettyPrint(),
- errorIndex and varBinds[int(errorIndex)-1][0] or '?'
- )
- )
+for errorIndication, \
+ errorStatus, errorIndex, \
+ varBinds in 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'))):
+ # Check for errors and print out results
+ if errorIndication:
+ print(errorIndication)
else:
- for name, val in varBinds:
- print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
+ if 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 ]))
+ break
diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/fetch-variables-over-ipv6.py b/examples/hlapi/asyncore/sync/manager/cmdgen/fetch-variables-over-ipv6.py
index b766fad9..716d1e9b 100644
--- a/examples/hlapi/asyncore/sync/manager/cmdgen/fetch-variables-over-ipv6.py
+++ b/examples/hlapi/asyncore/sync/manager/cmdgen/fetch-variables-over-ipv6.py
@@ -9,28 +9,28 @@
# * for three OIDs: one passed as a ObjectIdentity object while others are
# * in string form
#
-from pysnmp.entity.rfc3413.oneliner import cmdgen
+from pysnmp.entity.rfc3413.oneliner.cmdgen import *
-cmdGen = cmdgen.CommandGenerator()
-
-errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
- cmdgen.UsmUserData('usr-md5-des', 'authkey1', 'privkey1'),
- cmdgen.Udp6TransportTarget(('::1', 161)),
- cmdgen.ObjectIdentity('1.3.6.1.2.1.1.1.0'),
- '1.3.6.1.2.1.1.2.0',
- '1.3.6.1.2.1.1.3.0'
-)
-
-# Check for errors and print out results
-if errorIndication:
- print(errorIndication)
-else:
- if errorStatus:
- print('%s at %s' % (
- errorStatus.prettyPrint(),
- errorIndex and varBinds[int(errorIndex)-1][0] or '?'
- )
- )
+for errorIndication, \
+ errorStatus, errorIndex, \
+ varBinds in 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'))):
+ # Check for errors and print out results
+ if errorIndication:
+ print(errorIndication)
else:
- for name, val in varBinds:
- print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
+ if 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 ]))
+ break
diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/get-table-object-by-index.py b/examples/hlapi/asyncore/sync/manager/cmdgen/get-table-object-by-index.py
index c6419934..e83e0d2a 100644
--- a/examples/hlapi/asyncore/sync/manager/cmdgen/get-table-object-by-index.py
+++ b/examples/hlapi/asyncore/sync/manager/cmdgen/get-table-object-by-index.py
@@ -9,27 +9,27 @@
# * for IF-MIB::ifInOctets.1 MIB object
# * perform response OIDs and values resolution at MIB
#
-from pysnmp.entity.rfc3413.oneliner import cmdgen
+from pysnmp.entity.rfc3413.oneliner.cmdgen import *
-cmdGen = cmdgen.CommandGenerator()
-
-errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
- cmdgen.UsmUserData('usr-none-none'),
- cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
- cmdgen.ObjectIdentity('IF-MIB', 'ifInOctets', 1),
- lookupNames=True, lookupValues=True
-)
-
-# Check for errors and print out results
-if errorIndication:
- print(errorIndication)
-else:
- if errorStatus:
- print('%s at %s' % (
- errorStatus.prettyPrint(),
- errorIndex and varBinds[int(errorIndex)-1][0] or '?'
- )
- )
+for errorIndication, \
+ errorStatus, errorIndex, \
+ varBinds in getCmd(SnmpEngine(),
+ UsmUserData('usr-none-none'),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ ContextData(),
+ ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets', 1)),
+ lookupNames=True, lookupValues=True):
+ # Check for errors and print out results
+ if errorIndication:
+ print(errorIndication)
else:
- for name, val in varBinds:
- print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
+ if 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 ]))
+ break
diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/get-table-object-by-multiple-indices.py b/examples/hlapi/asyncore/sync/manager/cmdgen/get-table-object-by-multiple-indices.py
index 8bc4562b..7b78a356 100644
--- a/examples/hlapi/asyncore/sync/manager/cmdgen/get-table-object-by-multiple-indices.py
+++ b/examples/hlapi/asyncore/sync/manager/cmdgen/get-table-object-by-multiple-indices.py
@@ -8,28 +8,33 @@
# * to an Agent at demo.snmplabs.com:161
# * for TCP-MIB::tcpConnLocalAddress."0.0.0.0".22."0.0.0.0".0 MIB object
#
-from pysnmp.entity.rfc3413.oneliner import cmdgen
+from pysnmp.entity.rfc3413.oneliner.cmdgen import *
-cmdGen = cmdgen.CommandGenerator()
-
-errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
- cmdgen.UsmUserData('usr-sha-aes128', 'authkey1', 'privkey1',
- authProtocol=cmdgen.usmHMACSHAAuthProtocol,
- privProtocol=cmdgen.usmAesCfb128Protocol ),
- cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
- cmdgen.ObjectIdentity('TCP-MIB', 'tcpConnLocalAddress', '0.0.0.0', 22, '0.0.0.0', 0)
-)
-
-# Check for errors and print out results
-if errorIndication:
- print(errorIndication)
-else:
- if errorStatus:
- print('%s at %s' % (
- errorStatus.prettyPrint(),
- errorIndex and varBinds[int(errorIndex)-1][0] or '?'
- )
- )
+for errorIndication, \
+ errorStatus, errorIndex, \
+ varBinds in getCmd(SnmpEngine(),
+ UsmUserData('usr-sha-aes128', 'authkey1', 'privkey1',
+ authProtocol=usmHMACSHAAuthProtocol,
+ privProtocol=usmAesCfb128Protocol ),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ ContextData(),
+ ObjectType(
+ ObjectIdentity('TCP-MIB',
+ 'tcpConnLocalAddress',
+ '0.0.0.0', 22,
+ '0.0.0.0', 0)
+ )):
+ # Check for errors and print out results
+ if errorIndication:
+ print(errorIndication)
else:
- for name, val in varBinds:
- print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
+ if 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 ]))
+ break
diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/getbulk-fetch-scalar-and-table-variables.py b/examples/hlapi/asyncore/sync/manager/cmdgen/getbulk-fetch-scalar-and-table-variables.py
index 99df3c11..9b255f35 100644
--- a/examples/hlapi/asyncore/sync/manager/cmdgen/getbulk-fetch-scalar-and-table-variables.py
+++ b/examples/hlapi/asyncore/sync/manager/cmdgen/getbulk-fetch-scalar-and-table-variables.py
@@ -11,32 +11,30 @@
# * stop when response OIDs leave the scopes of the table OR maxRows == 20
# * perform response OIDs and values resolution at MIB
#
-from pysnmp.entity.rfc3413.oneliner import cmdgen
+from pysnmp.entity.rfc3413.oneliner.cmdgen import *
-cmdGen = cmdgen.CommandGenerator()
-
-# Send a series of SNMP GETBULK requests
-# make sure IF-MIB.py and IP-MIB.py are in search path
-
-errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.bulkCmd(
- cmdgen.UsmUserData('usr-md5-des', 'authkey1', 'privkey1'),
- cmdgen.Udp6TransportTarget(('::1', 161)),
- 1, 25,
- cmdgen.ObjectIdentity('IP-MIB', 'ipAdEntAddr'),
- cmdgen.ObjectIdentity('IF-MIB', 'ifEntry'),
- lookupNames=True, lookupValues=True, maxRows=20
-)
-
-if errorIndication:
- print(errorIndication)
-else:
- if errorStatus:
- print('%s at %s' % (
- errorStatus.prettyPrint(),
- errorIndex and varBindTable[-1][int(errorIndex)-1][0] or '?'
- )
- )
+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')),
+ lookupNames=True, lookupValues=True, maxRows=20):
+ # Check for errors and print out results
+ if errorIndication:
+ print(errorIndication)
+ break
else:
- for varBindTableRow in varBindTable:
- for name, val in varBindTableRow:
- print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
+ if 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/asyncore/sync/manager/cmdgen/getnext-limit-number-of-variables.py b/examples/hlapi/asyncore/sync/manager/cmdgen/getnext-limit-number-of-variables.py
index bdeda853..99eba513 100644
--- a/examples/hlapi/asyncore/sync/manager/cmdgen/getnext-limit-number-of-variables.py
+++ b/examples/hlapi/asyncore/sync/manager/cmdgen/getnext-limit-number-of-variables.py
@@ -12,30 +12,31 @@
#
# make sure IF-MIB.py is search path
#
-from pysnmp.entity.rfc3413.oneliner import cmdgen
+from pysnmp.entity.rfc3413.oneliner.cmdgen import *
-cmdGen = cmdgen.CommandGenerator()
-
-errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.nextCmd(
- cmdgen.UsmUserData('usr-sha-aes128', 'authkey1', 'privkey1',
- authProtocol=cmdgen.usmHMACSHAAuthProtocol,
- privProtocol=cmdgen.usmAesCfb128Protocol),
- cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
- cmdgen.ObjectIdentity('IF-MIB', '').loadMibs(),
- lexicographicMode=True, maxRows=100,
- ignoreNonIncreasingOid=True
-)
-
-if errorIndication:
- print(errorIndication)
-else:
- if errorStatus:
- print('%s at %s' % (
- errorStatus.prettyPrint(),
- errorIndex and varBindTable[-1][int(errorIndex)-1][0] or '?'
- )
- )
+for errorIndication, \
+ errorStatus, errorIndex, \
+ varBinds in nextCmd(SnmpEngine(),
+ UsmUserData('usr-sha-aes128', 'authkey1', 'privkey1',
+ authProtocol=usmHMACSHAAuthProtocol,
+ privProtocol=usmAesCfb128Protocol),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ ContextData(),
+ ObjectType(ObjectIdentity('IF-MIB', '').loadMibs()),
+ lexicographicMode=True, maxRows=100,
+ ignoreNonIncreasingOid=True):
+ # Check for errors and print out results
+ if errorIndication:
+ print(errorIndication)
+ break
else:
- for varBindTableRow in varBindTable:
- for name, val in varBindTableRow:
- print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
+ if 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/asyncore/sync/manager/cmdgen/getnext-multiple-oids-to-eom.py b/examples/hlapi/asyncore/sync/manager/cmdgen/getnext-multiple-oids-to-eom.py
index c5181ca3..178cd09e 100644
--- a/examples/hlapi/asyncore/sync/manager/cmdgen/getnext-multiple-oids-to-eom.py
+++ b/examples/hlapi/asyncore/sync/manager/cmdgen/getnext-multiple-oids-to-eom.py
@@ -9,27 +9,28 @@
# * for two OIDs in string form
# * stop when response OIDs leave the scopes of initial OIDs
#
-from pysnmp.entity.rfc3413.oneliner import cmdgen
+from pysnmp.entity.rfc3413.oneliner.cmdgen import *
-cmdGen = cmdgen.CommandGenerator()
-
-errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.nextCmd(
- cmdgen.CommunityData('public'),
- cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
- '1.3.6.1.2.1.2.2.1.2',
- '1.3.6.1.2.1.2.2.1.3'
-)
-
-if errorIndication:
- print(errorIndication)
-else:
- if errorStatus:
- print('%s at %s' % (
- errorStatus.prettyPrint(),
- errorIndex and varBindTable[-1][int(errorIndex)-1][0] or '?'
- )
- )
+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'))):
+ # Check for errors and print out results
+ if errorIndication:
+ print(errorIndication)
+ break
else:
- for varBindTableRow in varBindTable:
- for name, val in varBindTableRow:
- print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
+ if 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/asyncore/sync/manager/cmdgen/preload-pysnmp-mibs.py b/examples/hlapi/asyncore/sync/manager/cmdgen/preload-pysnmp-mibs.py
index 847ba252..01c74be0 100644
--- a/examples/hlapi/asyncore/sync/manager/cmdgen/preload-pysnmp-mibs.py
+++ b/examples/hlapi/asyncore/sync/manager/cmdgen/preload-pysnmp-mibs.py
@@ -12,27 +12,28 @@
#
# make sure IF-MIB.py is in search path
#
-from pysnmp.entity.rfc3413.oneliner import cmdgen
+from pysnmp.entity.rfc3413.oneliner.cmdgen import *
-cmdGen = cmdgen.CommandGenerator()
-
-errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.nextCmd(
- cmdgen.UsmUserData('usr-md5-des', 'authkey1', 'privkey1'),
- cmdgen.Udp6TransportTarget(('::1', 161)),
- cmdgen.ObjectIdentity('IF-MIB', 'ifEntry'),
- lookupNames=True, lookupValues=True
-)
-
-if errorIndication:
- print(errorIndication)
-else:
- if errorStatus:
- print('%s at %s' % (
- errorStatus.prettyPrint(),
- errorIndex and varBindTable[-1][int(errorIndex)-1][0] or '?'
- )
- )
+for errorIndication, \
+ errorStatus, errorIndex, \
+ varBinds in nextCmd(SnmpEngine(),
+ UsmUserData('usr-md5-des', 'authkey1', 'privkey1'),
+ Udp6TransportTarget(('::1', 161)),
+ ContextData(),
+ ObjectType(ObjectIdentity('IF-MIB', 'ifEntry')),
+ lookupNames=True, lookupValues=True):
+ # Check for errors and print out results
+ if errorIndication:
+ print(errorIndication)
+ break
else:
- for varBindTableRow in varBindTable:
- for name, val in varBindTableRow:
- print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
+ if 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/asyncore/sync/manager/cmdgen/pull-whole-mib.py b/examples/hlapi/asyncore/sync/manager/cmdgen/pull-whole-mib.py
index 2d62e85c..658f6fc5 100644
--- a/examples/hlapi/asyncore/sync/manager/cmdgen/pull-whole-mib.py
+++ b/examples/hlapi/asyncore/sync/manager/cmdgen/pull-whole-mib.py
@@ -10,29 +10,28 @@
# * stop when response OIDs leave the scopes of the table
# * perform response values resolution at MIB
#
-# make sure IF-MIB.py is in search path
-#
-from pysnmp.entity.rfc3413.oneliner import cmdgen
-
-cmdGen = cmdgen.CommandGenerator()
-
-errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.nextCmd(
- cmdgen.UsmUserData('usr-md5-none', 'authkey1'),
- cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
- cmdgen.ObjectIdentity('IF-MIB', ''),
- lookupValues=True
-)
+from pysnmp.entity.rfc3413.oneliner.cmdgen import *
-if errorIndication:
- print(errorIndication)
-else:
- if errorStatus:
- print('%s at %s' % (
- errorStatus.prettyPrint(),
- errorIndex and varBindTable[-1][int(errorIndex)-1][0] or '?'
- )
- )
+for errorIndication, \
+ errorStatus, errorIndex, \
+ varBinds in nextCmd(SnmpEngine(),
+ UsmUserData('usr-md5-none', 'authkey1'),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ ContextData(),
+ ObjectType(ObjectIdentity('IF-MIB', '')),
+ lookupValues=True):
+ # Check for errors and print out results
+ if errorIndication:
+ print(errorIndication)
+ break
else:
- for varBindTableRow in varBindTable:
- for name, val in varBindTableRow:
- print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
+ if 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/asyncore/sync/manager/cmdgen/pull-whole-snmp-table.py b/examples/hlapi/asyncore/sync/manager/cmdgen/pull-whole-snmp-table.py
index 7be99e22..1c3a998e 100644
--- a/examples/hlapi/asyncore/sync/manager/cmdgen/pull-whole-snmp-table.py
+++ b/examples/hlapi/asyncore/sync/manager/cmdgen/pull-whole-snmp-table.py
@@ -9,32 +9,32 @@
# * for some columns of the IF-MIB::ifEntry table
# * stop when response OIDs leave the scopes of initial OIDs
#
-# make sure IF-MIB.py is in search path
-#
-from pysnmp.entity.rfc3413.oneliner import cmdgen
-
-cmdGen = cmdgen.CommandGenerator()
-
-errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.nextCmd(
- cmdgen.CommunityData('public', mpModel=0),
- cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
- cmdgen.ObjectIdentity('IF-MIB', 'ifDescr'),
- cmdgen.ObjectIdentity('IF-MIB', 'ifType'),
- cmdgen.ObjectIdentity('IF-MIB', 'ifMtu'),
- cmdgen.ObjectIdentity('IF-MIB', 'ifSpeed'),
- cmdgen.ObjectIdentity('IF-MIB', 'ifPhysAddress')
-)
+from pysnmp.entity.rfc3413.oneliner.cmdgen import *
-if errorIndication:
- print(errorIndication)
-else:
- if errorStatus:
- print('%s at %s' % (
- errorStatus.prettyPrint(),
- errorIndex and varBindTable[-1][int(errorIndex)-1][0] or '?'
- )
- )
+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'))):
+ # Check for errors and print out results
+ if errorIndication:
+ print(errorIndication)
+ break
else:
- for varBindTableRow in varBindTable:
- for name, val in varBindTableRow:
- print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
+ if 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/asyncore/sync/manager/cmdgen/set-multiple-scalar-values.py b/examples/hlapi/asyncore/sync/manager/cmdgen/set-multiple-scalar-values.py
index b225b71f..bba4a84d 100644
--- a/examples/hlapi/asyncore/sync/manager/cmdgen/set-multiple-scalar-values.py
+++ b/examples/hlapi/asyncore/sync/manager/cmdgen/set-multiple-scalar-values.py
@@ -8,29 +8,29 @@
# * to an Agent at demo.snmplabs.com:161
# * setting two OIDs to new values (types explicitly specified)
#
-from pysnmp.entity.rfc3413.oneliner import cmdgen
+from pysnmp.entity.rfc3413.oneliner.cmdgen import *
from pysnmp.proto import rfc1902
-cmdGen = cmdgen.CommandGenerator()
-
-errorIndication, errorStatus, errorIndex, varBinds = cmdGen.setCmd(
- cmdgen.CommunityData('public', mpModel=0),
- cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
- ('1.3.6.1.2.1.1.9.1.2.1', rfc1902.ObjectName('1.3.6.1.4.1.20408.1.1')),
- ('1.3.6.1.2.1.1.9.1.2.1', '1.3.6.1.4.1.20408.1.1'),
- ('1.3.6.1.2.1.1.9.1.3.1', rfc1902.OctetString('new system name'))
-)
-
-# Check for errors and print out results
-if errorIndication:
- print(errorIndication)
-else:
- if errorStatus:
- print('%s at %s' % (
- errorStatus.prettyPrint(),
- errorIndex and varBinds[int(errorIndex)-1][0] or '?'
- )
- )
+for errorIndication, \
+ errorStatus, errorIndex, \
+ varBinds in setCmd(SnmpEngine(),
+ CommunityData('public', mpModel=0),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ ContextData(),
+ ('1.3.6.1.2.1.1.9.1.2.1', rfc1902.ObjectName('1.3.6.1.4.1.20408.1.1')),
+ ('1.3.6.1.2.1.1.9.1.2.1', '1.3.6.1.4.1.20408.1.1'),
+ ('1.3.6.1.2.1.1.9.1.3.1', rfc1902.OctetString('new system name'))):
+ # Check for errors and print out results
+ if errorIndication:
+ print(errorIndication)
else:
- for name, val in varBinds:
- print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
+ if 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 ]))
+ break
diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/specific-v3-engine-id.py b/examples/hlapi/asyncore/sync/manager/cmdgen/specific-v3-engine-id.py
index efdcbc8e..ca1d1fef 100644
--- a/examples/hlapi/asyncore/sync/manager/cmdgen/specific-v3-engine-id.py
+++ b/examples/hlapi/asyncore/sync/manager/cmdgen/specific-v3-engine-id.py
@@ -13,14 +13,11 @@
# ** to the same SNMP Engine ID
# ** for an OID in text form
#
-from pysnmp.entity import engine
-from pysnmp.entity.rfc3413.oneliner import cmdgen
+from pysnmp.entity.rfc3413.oneliner.cmdgen import *
-snmpEngine = engine.SnmpEngine()
+snmpEngine = SnmpEngine()
-cmdGen = cmdgen.CommandGenerator(snmpEngine)
-
-transportTarget = cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161))
+transportTarget = UdpTransportTarget(('demo.snmplabs.com', 161))
#
# To discover remote SNMP EngineID we will tap on SNMP engine inner workings
@@ -39,11 +36,12 @@ snmpEngine.observer.registerObserver(
# Send probe SNMP request with invalid credentials
-authData = cmdgen.UsmUserData('non-existing-user')
+authData = UsmUserData('non-existing-user')
-errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
- authData, transportTarget
-)
+for errorIndication, errorStatus, errorIndex, \
+ varBinds in getCmd(snmpEngine, authData,
+ transportTarget, ContextData()):
+ break
# See if our SNMP engine received REPORT PDU containing securityEngineId
@@ -59,12 +57,14 @@ print('Remote securityEngineId = %s' % securityEngineId.prettyPrint())
# Query remote SNMP Engine using usmUserTable entry configured for it
#
-authData = cmdgen.UsmUserData('usr-md5-none', 'authkey1',
- securityEngineId=securityEngineId)
+authData = UsmUserData('usr-md5-none', 'authkey1',
+ securityEngineId=securityEngineId)
-errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
- authData, transportTarget, '1.3.6.1.2.1.1.1.0'
-)
+for errorIndication, errorStatus, errorIndex, \
+ varBinds in getCmd(snmpEngine, authData, \
+ transportTarget, ContextData(), \
+ ObjectType(ObjectIdentity('1.3.6.1.2.1.1.1.0'))):
+ break
# Check for errors and print out results
if errorIndication:
diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/usm-md5-none.py b/examples/hlapi/asyncore/sync/manager/cmdgen/usm-md5-none.py
index 47f025f1..c01a61d0 100644
--- a/examples/hlapi/asyncore/sync/manager/cmdgen/usm-md5-none.py
+++ b/examples/hlapi/asyncore/sync/manager/cmdgen/usm-md5-none.py
@@ -8,26 +8,26 @@
# * to an Agent at demo.snmplabs.com:161
# * for IF-MIB::ifInOctets.1 MIB object
#
-from pysnmp.entity.rfc3413.oneliner import cmdgen
+from pysnmp.entity.rfc3413.oneliner.cmdgen import *
-cmdGen = cmdgen.CommandGenerator()
-
-errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
- cmdgen.UsmUserData('usr-md5-none', 'authkey1'),
- cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
- cmdgen.ObjectIdentity('IF-MIB', 'ifInOctets', 1)
-)
-
-# Check for errors and print out results
-if errorIndication:
- print(errorIndication)
-else:
- if errorStatus:
- print('%s at %s' % (
- errorStatus.prettyPrint(),
- errorIndex and varBinds[int(errorIndex)-1][0] or '?'
- )
- )
+for errorIndication, \
+ errorStatus, errorIndex, \
+ varBinds in getCmd(SnmpEngine(),
+ UsmUserData('usr-md5-none', 'authkey1'),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ ContextData(),
+ ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets', 1))):
+ # Check for errors and print out results
+ if errorIndication:
+ print(errorIndication)
else:
- for name, val in varBinds:
- print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
+ if 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 ]))
+ break
diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/v1-get.py b/examples/hlapi/asyncore/sync/manager/cmdgen/v1-get.py
index 664df9dd..aca41293 100644
--- a/examples/hlapi/asyncore/sync/manager/cmdgen/v1-get.py
+++ b/examples/hlapi/asyncore/sync/manager/cmdgen/v1-get.py
@@ -9,28 +9,27 @@
# * for two instances of SNMPv2-MIB::sysDescr.0 MIB object,
# * one in label and another in MIB symbol form
#
-from pysnmp.entity.rfc3413.oneliner import cmdgen
+from pysnmp.entity.rfc3413.oneliner.cmdgen import *
-cmdGen = cmdgen.CommandGenerator()
-
-errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
- cmdgen.CommunityData('public', mpModel=0),
- cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
- cmdgen.ObjectIdentity('iso.org.dod.internet.mgmt.mib-2.system.sysDescr.0'),
- cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)
-)
-
-# Check for errors and print out results
-if errorIndication:
- print(errorIndication)
-else:
- if errorStatus:
- print('%s at %s' % (
- errorStatus.prettyPrint(),
- errorIndex and varBinds[int(errorIndex)-1][0] or '?'
- )
- )
+for errorIndication, \
+ errorStatus, errorIndex, \
+ varBinds in getCmd(SnmpEngine(),
+ CommunityData('public', mpModel=0),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ ContextData(),
+ ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)),
+ lookupNames=True, lookupValues=True):
+ # Check for errors and print out results
+ if errorIndication:
+ print(errorIndication)
else:
- for name, val in varBinds:
- print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
-
+ if 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 ]))
+ break
diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/v2c-get.py b/examples/hlapi/asyncore/sync/manager/cmdgen/v2c-get.py
index de39b6ce..5fe5bfe9 100644
--- a/examples/hlapi/asyncore/sync/manager/cmdgen/v2c-get.py
+++ b/examples/hlapi/asyncore/sync/manager/cmdgen/v2c-get.py
@@ -8,27 +8,27 @@
# * to an Agent at demo.snmplabs.com:161
# * for two OIDs in string form
#
-from pysnmp.entity.rfc3413.oneliner import cmdgen
+from pysnmp.entity.rfc3413.oneliner.cmdgen import *
-cmdGen = cmdgen.CommandGenerator()
-
-errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
- cmdgen.CommunityData('public'),
- cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
- '1.3.6.1.2.1.1.1.0',
- '1.3.6.1.2.1.1.6.0'
-)
-
-# Check for errors and print out results
-if errorIndication:
- print(errorIndication)
-else:
- if errorStatus:
- print('%s at %s' % (
- errorStatus.prettyPrint(),
- errorIndex and varBinds[int(errorIndex)-1][0] or '?'
- )
- )
+for errorIndication, \
+ errorStatus, errorIndex, \
+ varBinds in 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'))):
+ # Check for errors and print out results
+ if errorIndication:
+ print(errorIndication)
else:
- for name, val in varBinds:
- print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
+ if 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 ]))
+ break
diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/v2c-getbulk.py b/examples/hlapi/asyncore/sync/manager/cmdgen/v2c-getbulk.py
index 1aa138b1..0bed0f08 100644
--- a/examples/hlapi/asyncore/sync/manager/cmdgen/v2c-getbulk.py
+++ b/examples/hlapi/asyncore/sync/manager/cmdgen/v2c-getbulk.py
@@ -10,28 +10,29 @@
# * for two OIDs in string form
# * stop when response OIDs leave the scopes of initial OIDs
#
-from pysnmp.entity.rfc3413.oneliner import cmdgen
+from pysnmp.entity.rfc3413.oneliner.cmdgen import *
-cmdGen = cmdgen.CommandGenerator()
-
-errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.bulkCmd(
- cmdgen.CommunityData('public'),
- cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
- 0, 25,
- '1.3.6.1.2.1.2.2',
- '1.3.6.1.2.1.2.3',
-)
-
-if errorIndication:
- print(errorIndication)
-else:
- if errorStatus:
- print('%s at %s' % (
- errorStatus.prettyPrint(),
- errorIndex and varBindTable[-1][int(errorIndex)-1][0] or '?'
- )
- )
+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'))):
+ # Check for errors and print out results
+ if errorIndication:
+ print(errorIndication)
+ break
else:
- for varBindTableRow in varBindTable:
- for name, val in varBindTableRow:
- print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
+ if 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/asyncore/sync/manager/cmdgen/waive-mib-lookup.py b/examples/hlapi/asyncore/sync/manager/cmdgen/waive-mib-lookup.py
index c7f08970..e59b07bd 100644
--- a/examples/hlapi/asyncore/sync/manager/cmdgen/waive-mib-lookup.py
+++ b/examples/hlapi/asyncore/sync/manager/cmdgen/waive-mib-lookup.py
@@ -20,27 +20,28 @@
# currently loaded MIBs, unresolved OIDs and values will still be
# returned.
#
-from pysnmp.entity.rfc3413.oneliner import cmdgen
+from pysnmp.entity.rfc3413.oneliner.cmdgen import *
-cmdGen = cmdgen.CommandGenerator()
-
-errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.nextCmd(
- cmdgen.CommunityData('public'),
- cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
- '1.3.6.1.2.1.1',
- lookupNames=True, lookupValues=True
-)
-
-if errorIndication:
- print(errorIndication)
-else:
- if errorStatus:
- print('%s at %s' % (
- errorStatus.prettyPrint(),
- errorIndex and varBindTable[-1][int(errorIndex)-1] or '?'
- )
- )
+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')),
+ lookupNames=True, lookupValues=True):
+ # Check for errors and print out results
+ if errorIndication:
+ print(errorIndication)
+ break
else:
- for varBindTableRow in varBindTable:
- for name, val in varBindTableRow:
- print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
+ if 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 ]))