summaryrefslogtreecommitdiff
path: root/examples/hlapi/asyncore/sync/manager/cmdgen/pull-whole-snmp-table.py
diff options
context:
space:
mode:
Diffstat (limited to 'examples/hlapi/asyncore/sync/manager/cmdgen/pull-whole-snmp-table.py')
-rw-r--r--examples/hlapi/asyncore/sync/manager/cmdgen/pull-whole-snmp-table.py54
1 files changed, 27 insertions, 27 deletions
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 ]))