diff options
Diffstat (limited to 'examples/hlapi/asyncore/sync/manager/cmdgen/v2c-get.py')
-rw-r--r-- | examples/hlapi/asyncore/sync/manager/cmdgen/v2c-get.py | 44 |
1 files changed, 22 insertions, 22 deletions
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 |