diff options
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 ])) |