diff options
Diffstat (limited to 'examples')
13 files changed, 143 insertions, 201 deletions
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 10538f22..b9103de3 100644 --- a/examples/hlapi/asyncore/sync/manager/cmdgen/pull-whole-mib.py +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/pull-whole-mib.py @@ -11,30 +11,27 @@ Send a series of SNMP GETNEXT requests using the following options: Functionally similar to: -| $ snmpwalk -v3 -lauthPriv -u usr-md5-none -A authkey1 -X privkey1 \ -| demo.snmplabs.com IF-MIB:: +| $ snmpwalk -v3 -lauthPriv -u usr-md5-none -A authkey1 -X privkey1 demo.snmplabs.com IF-MIB:: """# from pysnmp.hlapi import * -for errorIndication, \ - errorStatus, errorIndex, \ - varBinds in nextCmd(SnmpEngine(), - UsmUserData('usr-md5-none', 'authkey1'), - UdpTransportTarget(('demo.snmplabs.com', 161)), - ContextData(), - ObjectType(ObjectIdentity('IF-MIB'))): +for (errorIndication, + errorStatus, + errorIndex, + varBinds) in nextCmd(SnmpEngine(), + UsmUserData('usr-md5-none', 'authkey1'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ContextData(), + ObjectType(ObjectIdentity('IF-MIB'))): if errorIndication: print(errorIndication) break elif errorStatus: - print('%s at %s' % ( - errorStatus.prettyPrint(), - errorIndex and varBinds[int(errorIndex)-1][0] or '?' - ) - ) + 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 ])) + 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 5b8d2219..91a71a61 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 @@ -12,42 +12,33 @@ Send a series of SNMP GETNEXT requests using the following options: Functionally similar to: -| $ snmpwalk -v1 -c public demo.snmplabs.com \ -| IF-MIB::ifDescr \ -| IF-MIB::ifType \ -| IF-MIB::ifMtu \ -| IF-MIB::ifSpeed \ -| IF-MIB::ifPhysAddress \ -| IF-MIB::ifType \ +| $ snmpwalk -v1 -c public demo.snmplabs.com IF-MIB::ifDescr IF-MIB::ifType IF-MIB::ifMtu IF-MIB::ifSpeed IF-MIB::ifPhysAddress IF-MIB::ifType """# from pysnmp.hlapi import * -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')), - lexicographicMode=False): +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')), + lexicographicMode=False): if errorIndication: print(errorIndication) break elif errorStatus: - print('%s at %s' % ( - errorStatus.prettyPrint(), - errorIndex and varBinds[int(errorIndex)-1][0] or '?' - ) - ) + 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 ])) + print(' = '.join([x.prettyPrint() for x in varBind])) diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/query-agents-from-multuple-threads.py b/examples/hlapi/asyncore/sync/manager/cmdgen/query-agents-from-multuple-threads.py index 34ead8b5..d289982e 100644 --- a/examples/hlapi/asyncore/sync/manager/cmdgen/query-agents-from-multuple-threads.py +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/query-agents-from-multuple-threads.py @@ -17,46 +17,48 @@ Send a bunch of SNMP GET requests simultaneously using the following options: """# from sys import version_info +from threading import Thread +from pysnmp.hlapi import * + if version_info[0] == 2: from Queue import Queue else: from queue import Queue -from threading import Thread -from pysnmp.hlapi import * # List of targets in the followin format: # ( ( authData, transportTarget, varNames ), ... ) targets = ( # 1-st target (SNMPv1 over IPv4/UDP) - ( CommunityData('public', mpModel=0), - UdpTransportTarget(('demo.snmplabs.com', 161)), - ( ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)), - ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0)))), + (CommunityData('public', mpModel=0), + UdpTransportTarget(('demo.snmplabs.com', 161)), + (ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)), + ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0)))), # 2-nd target (SNMPv2c over IPv4/UDP) - ( CommunityData('public'), - UdpTransportTarget(('demo.snmplabs.com', 161)), - ( ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)), - ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0)))), + (CommunityData('public'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + (ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)), + ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0)))), # 3-nd target (SNMPv2c over IPv4/UDP) - same community and # different transport address. - ( CommunityData('public'), - UdpTransportTarget(('localhost', 161)), - ( ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysContact', 0)), - ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysName', 0)))), + (CommunityData('public'), + UdpTransportTarget(('localhost', 161)), + (ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysContact', 0)), + ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysName', 0)))), # 4-nd target (SNMPv3 over IPv4/UDP) - ( UsmUserData('usr-md5-des', 'authkey1', 'privkey1'), - UdpTransportTarget(('demo.snmplabs.com', 161)), - ( ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)), - ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0) ))), + (UsmUserData('usr-md5-des', 'authkey1', 'privkey1'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + (ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)), + ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0)))), # 5-th target (SNMPv3 over IPv6/UDP) - ( UsmUserData('usr-md5-none', 'authkey1'), - Udp6TransportTarget(('::1', 161)), - ( ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)), - ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0)))), + (UsmUserData('usr-md5-none', 'authkey1'), + Udp6TransportTarget(('::1', 161)), + (ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)), + ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0)))), # N-th target # ... ) + class Worker(Thread): def __init__(self, requests, responses): Thread.__init__(self) @@ -65,21 +67,18 @@ class Worker(Thread): self.responses = responses self.setDaemon(True) self.start() - + def run(self): while True: authData, transportTarget, varBinds = self.requests.get() self.responses.append( - next( - getCmd( - self.snmpEngine, - authData, transportTarget, ContextData(), *varBinds - ) - ) + next(getCmd(self.snmpEngine, + authData, transportTarget, ContextData(), *varBinds)) ) if hasattr(self.requests, 'task_done'): # 2.5+ self.requests.task_done() + class ThreadPool: def __init__(self, num_threads): self.requests = Queue(num_threads) @@ -90,7 +89,8 @@ class ThreadPool: def addRequest(self, authData, transportTarget, varBinds): self.requests.put((authData, transportTarget, varBinds)) - def getResponses(self): return self.responses + def getResponses(self): + return self.responses def waitCompletion(self): if hasattr(self.requests, 'join'): @@ -99,29 +99,26 @@ class ThreadPool: from time import sleep # this is a lame substitute for missing .join() # adding an explicit synchronization might be a better solution - while not self.requests.empty(): - sleep(1) + while not self.requests.empty(): + sleep(1) + pool = ThreadPool(3) # Submit GET requests for authData, transportTarget, varBinds in targets: pool.addRequest(authData, transportTarget, varBinds) - + # Wait for responses or errors pool.waitCompletion() # Walk through responses for errorIndication, errorStatus, errorIndex, varBinds in pool.getResponses(): - print('Response for %s from %s:' % (authData, transportTarget)) if errorIndication: print(errorIndication) elif errorStatus: - print('%s at %s' % ( - errorStatus.prettyPrint(), - errorIndex and varBinds[int(errorIndex)-1][0] or '?' - ) - ) + 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 ])) + 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 c3d3c5c5..b5fc1912 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 @@ -15,10 +15,7 @@ inferred from passed objects. Functionally similar to: -| $ snmpset -v1 -c public demo.snmplabs.com \ -| 1.3.6.1.2.1.1.9.1.2.1 o 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 s "new system name" +| $ snmpset -v1 -c public demo.snmplabs.com 1.3.6.1.2.1.1.9.1.2.1 o 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 s "new system name" """# from pysnmp.hlapi import * @@ -39,11 +36,8 @@ errorIndication, errorStatus, errorIndex, varBinds = next( if errorIndication: print(errorIndication) elif errorStatus: - print('%s at %s' % ( - errorStatus.prettyPrint(), - errorIndex and varBinds[int(errorIndex)-1][0] or '?' - ) - ) + 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 ])) + print(' = '.join([x.prettyPrint() for x in varBind])) 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 72263bee..94f591c4 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 @@ -34,7 +34,7 @@ observerContext = {} # Register a callback to be invoked at specified execution point of # SNMP Engine and passed local variables at execution point's local scope snmpEngine.observer.registerObserver( - lambda e,p,v,c: c.update(securityEngineId=v['securityEngineId']), + lambda e, p, v, c: c.update(securityEngineId=v['securityEngineId']), 'rfc3412.prepareDataElements:internal', cbCtx=observerContext ) @@ -62,7 +62,7 @@ print('Remote securityEngineId = %s' % securityEngineId.prettyPrint()) # Query remote SNMP Engine using usmUserTable entry configured for it # -authData = UsmUserData('usr-md5-none', 'authkey1', +authData = UsmUserData('usr-md5-none', 'authkey1', securityEngineId=securityEngineId) errorIndication, errorStatus, errorIndex, varBinds = next( @@ -76,11 +76,8 @@ errorIndication, errorStatus, errorIndex, varBinds = next( if errorIndication: print(errorIndication) elif errorStatus: - print('%s at %s' % ( - errorStatus.prettyPrint(), - errorIndex and varBinds[int(errorIndex)-1][0] or '?' - ) - ) + print('%s at %s' % (errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex) - 1][0] or '?')) else: for name, val in varBinds: print('%s = %s' % (name.prettyPrint(), val.prettyPrint())) diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/usm-md5-des.py b/examples/hlapi/asyncore/sync/manager/cmdgen/usm-md5-des.py index 1d8030da..f7e102c1 100644 --- a/examples/hlapi/asyncore/sync/manager/cmdgen/usm-md5-des.py +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/usm-md5-des.py @@ -11,29 +11,24 @@ Send SNMP GET request using the following options: Functionally similar to: -| $ snmpget -v3 -l authPriv -u usr-md5-des -A authkey1 -X privkey1 \ -| demo.snmplabs.com \ -| IF-MIB::ifInOctets.1 +| $ snmpget -v3 -l authPriv -u usr-md5-des -A authkey1 -X privkey1 demo.snmplabs.com IF-MIB::ifInOctets.1 -"""# +""" # from pysnmp.hlapi import * errorIndication, errorStatus, errorIndex, varBinds = next( getCmd(SnmpEngine(), - UsmUserData('usr-md5-des', 'authkey1', 'privkey1'), - UdpTransportTarget(('demo.snmplabs.com', 161)), - ContextData(), - ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets', 1))) + UsmUserData('usr-md5-des', 'authkey1', 'privkey1'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ContextData(), + ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets', 1))) ) if errorIndication: print(errorIndication) elif errorStatus: - print('%s at %s' % ( - errorStatus.prettyPrint(), - errorIndex and varBinds[int(errorIndex)-1][0] or '?' - ) - ) + 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 ])) + print(' = '.join([x.prettyPrint() for x in varBind])) 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 c38d2f32..f06964e2 100644 --- a/examples/hlapi/asyncore/sync/manager/cmdgen/usm-md5-none.py +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/usm-md5-none.py @@ -11,28 +11,24 @@ Send SNMP GET request using the following options: Functionally similar to: -| $ snmpget -v3 -l authNoPriv -u usr-md5-none -A authkey1 demo.snmplabs.com \ -| IF-MIB::ifInOctets.1 +| $ snmpget -v3 -l authNoPriv -u usr-md5-none -A authkey1 demo.snmplabs.com IF-MIB::ifInOctets.1 """# from pysnmp.hlapi import * errorIndication, errorStatus, errorIndex, varBinds = next( getCmd(SnmpEngine(), - UsmUserData('usr-md5-none', 'authkey1'), - UdpTransportTarget(('demo.snmplabs.com', 161)), - ContextData(), - ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets', 1))) + UsmUserData('usr-md5-none', 'authkey1'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ContextData(), + ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets', 1))) ) if errorIndication: print(errorIndication) elif errorStatus: - print('%s at %s' % ( - errorStatus.prettyPrint(), - errorIndex and varBinds[int(errorIndex)-1][0] or '?' - ) - ) + 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 ])) + print(' = '.join([x.prettyPrint() for x in varBind])) diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/usm-none-none.py b/examples/hlapi/asyncore/sync/manager/cmdgen/usm-none-none.py index 15f570a1..940d8817 100644 --- a/examples/hlapi/asyncore/sync/manager/cmdgen/usm-none-none.py +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/usm-none-none.py @@ -11,29 +11,23 @@ Send SNMP GET request using the following options: Functionally similar to: -| $ snmpget -v3 -l noAuthNoPriv -u usr-none-none -| demo.snmplabs.com \ -| IF-MIB::ifInOctets.1 +| $ snmpget -v3 -l noAuthNoPriv -u usr-none-none demo.snmplabs.com IF-MIB::ifInOctets.1 """# from pysnmp.hlapi import * errorIndication, errorStatus, errorIndex, varBinds = next( getCmd(SnmpEngine(), - UsmUserData('usr-none-none'), - UdpTransportTarget(('demo.snmplabs.com', 161)), - ContextData(), - ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets', 1))) + UsmUserData('usr-none-none'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ContextData(), + ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets', 1))) ) if errorIndication: print(errorIndication) elif errorStatus: - print('%s at %s' % ( - errorStatus.prettyPrint(), - errorIndex and varBinds[int(errorIndex)-1][0] or '?' - ) - ) + 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 ])) + print(' = '.join([x.prettyPrint() for x in varBind])) diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/usm-sha-aes128.py b/examples/hlapi/asyncore/sync/manager/cmdgen/usm-sha-aes128.py index 1e985f5a..4d7692cf 100644 --- a/examples/hlapi/asyncore/sync/manager/cmdgen/usm-sha-aes128.py +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/usm-sha-aes128.py @@ -26,32 +26,26 @@ Available privacy protocols: Functionally similar to: -| $ snmpget -v3 -l authPriv -u usr-sha-aes -A authkey1 -X privkey1 \ -| -a SHA -x AES \ -| demo.snmplabs.com \ -| SNMPv2-MIB::sysDescr.0 +| $ snmpget -v3 -l authPriv -u usr-sha-aes -A authkey1 -X privkey1 -a SHA -x AES demo.snmplabs.com SNMPv2-MIB::sysDescr.0 """# from pysnmp.hlapi import * errorIndication, errorStatus, errorIndex, varBinds = next( getCmd(SnmpEngine(), - UsmUserData('usr-sha-aes', 'authkey1', 'privkey1', - authProtocol=usmHMACSHAAuthProtocol, - privProtocol=usmAesCfb128Protocol), - UdpTransportTarget(('demo.snmplabs.com', 161)), - ContextData(), - ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0))) + UsmUserData('usr-sha-aes', 'authkey1', 'privkey1', + authProtocol=usmHMACSHAAuthProtocol, + privProtocol=usmAesCfb128Protocol), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ContextData(), + ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0))) ) if errorIndication: print(errorIndication) elif errorStatus: - print('%s at %s' % ( - errorStatus.prettyPrint(), - errorIndex and varBinds[int(errorIndex)-1][0] or '?' - ) - ) + 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 ])) + print(' = '.join([x.prettyPrint() for x in varBind])) diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/v1-get.py b/examples/hlapi/asyncore/sync/manager/cmdgen/v1-get.py index 3f03c7cd..1b272967 100644 --- a/examples/hlapi/asyncore/sync/manager/cmdgen/v1-get.py +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/v1-get.py @@ -27,11 +27,8 @@ errorIndication, errorStatus, errorIndex, varBinds = next( if errorIndication: print(errorIndication) elif errorStatus: - print('%s at %s' % ( - errorStatus.prettyPrint(), - errorIndex and varBinds[int(errorIndex)-1][0] or '?' - ) - ) + 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 ])) + print(' = '.join([x.prettyPrint() for x in varBind])) diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/v2c-get.py b/examples/hlapi/asyncore/sync/manager/cmdgen/v2c-get.py index 169b6a61..606bab5b 100644 --- a/examples/hlapi/asyncore/sync/manager/cmdgen/v2c-get.py +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/v2c-get.py @@ -11,8 +11,7 @@ Send SNMP GET request using the following options: Functionally similar to: -| $ snmpget -v2c -c public demo.snmplabs.com 1.3.6.1.2.1.1.1.0 \ -| 1.3.6.1.2.1.1.6.0 +| $ snmpget -v2c -c public demo.snmplabs.com 1.3.6.1.2.1.1.1.0 1.3.6.1.2.1.1.6.0 """# from pysnmp.hlapi import * @@ -29,11 +28,8 @@ errorIndication, errorStatus, errorIndex, varBinds = next( if errorIndication: print(errorIndication) elif errorStatus: - print('%s at %s' % ( - errorStatus.prettyPrint(), - errorIndex and varBinds[int(errorIndex)-1][0] or '?' - ) - ) + 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 ])) + print(' = '.join([x.prettyPrint() for x in varBind])) diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/v2c-getbulk.py b/examples/hlapi/asyncore/sync/manager/cmdgen/v2c-getbulk.py index a65bb352..47715195 100644 --- a/examples/hlapi/asyncore/sync/manager/cmdgen/v2c-getbulk.py +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/v2c-getbulk.py @@ -13,34 +13,30 @@ Send a series of SNMP GETBULK requests using the following options: Functionally similar to: -| $ snmpbulkwalk -v2c -c public demo.snmplabs.com \ -| -Cn0 -Cr25 \ -| 1.3.6.1.2.1.2.2 1.3.6.1.2.1.2.3 +| $ snmpbulkwalk -v2c -c public demo.snmplabs.com -Cn0 -Cr25 1.3.6.1.2.1.2.2 1.3.6.1.2.1.2.3 """# from pysnmp.hlapi import * -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')), - lexicographicMode=False): +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')), + lexicographicMode=False): if errorIndication: print(errorIndication) break elif errorStatus: - print('%s at %s' % ( - errorStatus.prettyPrint(), - errorIndex and varBinds[int(errorIndex)-1][0] or '?' - ) - ) + 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 ])) + 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 7038d961..17194552 100644 --- a/examples/hlapi/asyncore/sync/manager/cmdgen/waive-mib-lookup.py +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/waive-mib-lookup.py @@ -21,25 +21,23 @@ Functionally similar to: """# from pysnmp.hlapi import * -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')), - lookupMib=False): +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')), + lookupMib=False): if errorIndication: print(errorIndication) break elif errorStatus: - print('%s at %s' % ( - errorStatus.prettyPrint(), - errorIndex and varBinds[int(errorIndex)-1][0] or '?' - ) - ) + 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 ])) + print(' = '.join([x.prettyPrint() for x in varBind])) |