diff options
author | elie <elie> | 2015-07-06 21:30:04 +0000 |
---|---|---|
committer | elie <elie> | 2015-07-06 21:30:04 +0000 |
commit | f308702c7867aa3cfb778a4ed6bd0b15c118073d (patch) | |
tree | 0087c2861fe78fbb7b52042310b7bd1c61785886 /examples/hlapi/asyncore/sync/manager/cmdgen/waive-mib-lookup.py | |
parent | 51841e9cba10f8d1dbaf2d1a7e8ecef0df3ce366 (diff) | |
download | pysnmp-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/hlapi/asyncore/sync/manager/cmdgen/waive-mib-lookup.py')
-rw-r--r-- | examples/hlapi/asyncore/sync/manager/cmdgen/waive-mib-lookup.py | 45 |
1 files changed, 23 insertions, 22 deletions
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 ])) |