diff options
Diffstat (limited to 'examples/hlapi/asyncore/sync')
25 files changed, 231 insertions, 312 deletions
diff --git a/examples/hlapi/asyncore/sync/agent/ntforg/custom-contextengineid.py b/examples/hlapi/asyncore/sync/agent/ntforg/custom-contextengineid.py index 0c02b962..6c4e7adc 100644 --- a/examples/hlapi/asyncore/sync/agent/ntforg/custom-contextengineid.py +++ b/examples/hlapi/asyncore/sync/agent/ntforg/custom-contextengineid.py @@ -34,11 +34,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/agent/ntforg/custom-contextname.py b/examples/hlapi/asyncore/sync/agent/ntforg/custom-contextname.py index 096a83d1..729c9b83 100644 --- a/examples/hlapi/asyncore/sync/agent/ntforg/custom-contextname.py +++ b/examples/hlapi/asyncore/sync/agent/ntforg/custom-contextname.py @@ -34,11 +34,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/agent/ntforg/custom-v1-trap.py b/examples/hlapi/asyncore/sync/agent/ntforg/custom-v1-trap.py index 768ef02a..8693f13f 100644 --- a/examples/hlapi/asyncore/sync/agent/ntforg/custom-v1-trap.py +++ b/examples/hlapi/asyncore/sync/agent/ntforg/custom-v1-trap.py @@ -25,19 +25,20 @@ Functionally similar to: from pysnmp.hlapi import * errorIndication, errorStatus, errorIndex, varBinds = next( - sendNotification(SnmpEngine(), - CommunityData('public', mpModel=0), - UdpTransportTarget(('demo.snmplabs.com', 162)), - ContextData(), - 'trap', - NotificationType( - ObjectIdentity('1.3.6.1.4.1.20408.4.1.1.2.0.432'), - ).addVarBinds( - ('1.3.6.1.2.1.1.3.0', 12345), - ('1.3.6.1.6.3.18.1.3.0', '127.0.0.1'), - ('1.3.6.1.6.3.1.1.4.3.0', '1.3.6.1.4.1.20408.4.1.1.2'), - ('1.3.6.1.2.1.1.1.0', OctetString('my system')) - ) + sendNotification( + SnmpEngine(), + CommunityData('public', mpModel=0), + UdpTransportTarget(('demo.snmplabs.com', 162)), + ContextData(), + 'trap', + NotificationType( + ObjectIdentity('1.3.6.1.4.1.20408.4.1.1.2.0.432'), + ).addVarBinds( + ('1.3.6.1.2.1.1.3.0', 12345), + ('1.3.6.1.6.3.18.1.3.0', '127.0.0.1'), + ('1.3.6.1.6.3.1.1.4.3.0', '1.3.6.1.4.1.20408.4.1.1.2'), + ('1.3.6.1.2.1.1.1.0', OctetString('my system')) + ) ) ) if errorIndication: diff --git a/examples/hlapi/asyncore/sync/agent/ntforg/default-v1-trap.py b/examples/hlapi/asyncore/sync/agent/ntforg/default-v1-trap.py index 9141cc5e..18cc2c77 100644 --- a/examples/hlapi/asyncore/sync/agent/ntforg/default-v1-trap.py +++ b/examples/hlapi/asyncore/sync/agent/ntforg/default-v1-trap.py @@ -23,18 +23,20 @@ Functionally similar to: from pysnmp.hlapi import * errorIndication, errorStatus, errorIndex, varBinds = next( - sendNotification(SnmpEngine(), - CommunityData('public', mpModel=0), - UdpTransportTarget(('demo.snmplabs.com', 162)), - ContextData(), - 'trap', - NotificationType( - ObjectIdentity('1.3.6.1.6.3.1.1.5.2') - ).addVarBinds( - ('1.3.6.1.6.3.1.1.4.3.0', '1.3.6.1.4.1.20408.4.1.1.2'), - ('1.3.6.1.2.1.1.1.0', OctetString('my system')) - ) + sendNotification( + SnmpEngine(), + CommunityData('public', mpModel=0), + UdpTransportTarget(('demo.snmplabs.com', 162)), + ContextData(), + 'trap', + NotificationType( + ObjectIdentity('1.3.6.1.6.3.1.1.5.2') + ).addVarBinds( + ('1.3.6.1.6.3.1.1.4.3.0', '1.3.6.1.4.1.20408.4.1.1.2'), + ('1.3.6.1.2.1.1.1.0', OctetString('my system')) + ) ) ) + if errorIndication: print(errorIndication) diff --git a/examples/hlapi/asyncore/sync/agent/ntforg/send-notification-with-additional-varbinds.py b/examples/hlapi/asyncore/sync/agent/ntforg/send-notification-with-additional-varbinds.py index 8ffa8cec..46f3c5c1 100644 --- a/examples/hlapi/asyncore/sync/agent/ntforg/send-notification-with-additional-varbinds.py +++ b/examples/hlapi/asyncore/sync/agent/ntforg/send-notification-with-additional-varbinds.py @@ -19,27 +19,25 @@ Functionally similar to: from pysnmp.hlapi import * errorIndication, errorStatus, errorIndex, varBinds = next( - sendNotification(SnmpEngine(), - CommunityData('public'), - UdpTransportTarget(('demo.snmplabs.com', 162)), - ContextData(), - 'inform', - NotificationType( - ObjectIdentity('SNMPv2-MIB', 'coldStart') - ).addVarBinds( - ObjectType(ObjectIdentity('SNMPv2-MIB','sysName',0), - 'my system') - )) + sendNotification( + SnmpEngine(), + CommunityData('public'), + UdpTransportTarget(('demo.snmplabs.com', 162)), + ContextData(), + 'inform', + NotificationType( + ObjectIdentity('SNMPv2-MIB', 'coldStart') + ).addVarBinds( + ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysName', 0), 'my system') + ) + ) ) 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/agent/ntforg/v2c-trap-with-notification-objects.py b/examples/hlapi/asyncore/sync/agent/ntforg/v2c-trap-with-notification-objects.py index 5f59738a..5681d28c 100644 --- a/examples/hlapi/asyncore/sync/agent/ntforg/v2c-trap-with-notification-objects.py +++ b/examples/hlapi/asyncore/sync/agent/ntforg/v2c-trap-with-notification-objects.py @@ -21,18 +21,19 @@ Functionally similar to: from pysnmp.hlapi import * errorIndication, errorStatus, errorIndex, varBinds = next( - sendNotification(SnmpEngine(), - CommunityData('public'), - UdpTransportTarget(('demo.snmplabs.com', 162)), - ContextData(), - 'trap', - NotificationType( - ObjectIdentity('IF-MIB', 'linkUp'), - instanceIndex=(123,), - objects={('IF-MIB', 'ifIndex'): 123, - ('IF-MIB', 'ifAdminStatus'): 'up', - ('IF-MIB', 'ifOperStatus'): 'up'} - ) + sendNotification( + SnmpEngine(), + CommunityData('public'), + UdpTransportTarget(('demo.snmplabs.com', 162)), + ContextData(), + 'trap', + NotificationType( + ObjectIdentity('IF-MIB', 'linkUp'), + instanceIndex=(123,), + objects={('IF-MIB', 'ifIndex'): 123, + ('IF-MIB', 'ifAdminStatus'): 'up', + ('IF-MIB', 'ifOperStatus'): 'up'} + ) ) ) diff --git a/examples/hlapi/asyncore/sync/agent/ntforg/v3-inform.py b/examples/hlapi/asyncore/sync/agent/ntforg/v3-inform.py index 638dd242..46153978 100644 --- a/examples/hlapi/asyncore/sync/agent/ntforg/v3-inform.py +++ b/examples/hlapi/asyncore/sync/agent/ntforg/v3-inform.py @@ -19,27 +19,25 @@ Functionally similar to: from pysnmp.hlapi import * errorIndication, errorStatus, errorIndex, varBinds = next( - sendNotification(SnmpEngine(), - UsmUserData('usr-md5-des', 'authkey1', 'privkey1'), - UdpTransportTarget(('demo.snmplabs.com', 162)), - ContextData(), - 'inform', - NotificationType( - ObjectIdentity('1.3.6.1.6.3.1.1.5.2') - ).addVarBinds( - ObjectType(ObjectIdentity('1.3.6.1.2.1.1.5.0'), - 'system name') - )) + sendNotification( + SnmpEngine(), + UsmUserData('usr-md5-des', 'authkey1', 'privkey1'), + UdpTransportTarget(('demo.snmplabs.com', 162)), + ContextData(), + 'inform', + NotificationType( + ObjectIdentity('1.3.6.1.6.3.1.1.5.2') + ).addVarBinds( + ObjectType(ObjectIdentity('1.3.6.1.2.1.1.5.0'), 'system name') + ) + ) ) 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/agent/ntforg/v3-trap.py b/examples/hlapi/asyncore/sync/agent/ntforg/v3-trap.py index 2f402c7e..836e8d50 100644 --- a/examples/hlapi/asyncore/sync/agent/ntforg/v3-trap.py +++ b/examples/hlapi/asyncore/sync/agent/ntforg/v3-trap.py @@ -25,17 +25,17 @@ Functionally similar to: from pysnmp.hlapi import * errorIndication, errorStatus, errorIndex, varBinds = next( - sendNotification(SnmpEngine(OctetString(hexValue='8000000001020304')), - UsmUserData('usr-sha-aes128', 'authkey1', 'privkey1', - authProtocol=usmHMACSHAAuthProtocol, - privProtocol=usmAesCfb128Protocol), - UdpTransportTarget(('demo.snmplabs.com', 162)), - ContextData(), - 'trap', - NotificationType( - ObjectIdentity('SNMPv2-MIB', 'authenticationFailure') - ) + sendNotification( + SnmpEngine(OctetString(hexValue='8000000001020304')), + UsmUserData('usr-sha-aes128', 'authkey1', 'privkey1', + authProtocol=usmHMACSHAAuthProtocol, + privProtocol=usmAesCfb128Protocol), + UdpTransportTarget(('demo.snmplabs.com', 162)), + ContextData(), + 'trap', + NotificationType(ObjectIdentity('SNMPv2-MIB', 'authenticationFailure')) ) ) + if errorIndication: print(errorIndication) diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/coerce-set-value-to-mib-spec.py b/examples/hlapi/asyncore/sync/manager/cmdgen/coerce-set-value-to-mib-spec.py index ab2df92c..b6fb879e 100644 --- a/examples/hlapi/asyncore/sync/manager/cmdgen/coerce-set-value-to-mib-spec.py +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/coerce-set-value-to-mib-spec.py @@ -11,8 +11,7 @@ Send SNMP SET request using the following options: Functionally similar to: -| $ snmpset -v2c -c public demo.snmplabs.com SNMPv2-MIB::sysDescr.0 \ -| = "new system name" +| $ snmpset -v2c -c public demo.snmplabs.com SNMPv2-MIB::sysDescr.0 = "new system name" """# 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/custom-asn1-mib-search-path.py b/examples/hlapi/asyncore/sync/manager/cmdgen/custom-asn1-mib-search-path.py index 22fbe6de..f25fafe4 100644 --- a/examples/hlapi/asyncore/sync/manager/cmdgen/custom-asn1-mib-search-path.py +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/custom-asn1-mib-search-path.py @@ -12,8 +12,7 @@ Send SNMP GET request using the following options: Functionally similar to: -| $ snmpget -v2c -c public -M /usr/share/snmp demo.snmplabs.com \ -| IF-MIB::ifInOctets.1 +| $ snmpget -v2c -c public -M /usr/share/snmp demo.snmplabs.com IF-MIB::ifInOctets.1 """# from pysnmp.hlapi import * @@ -23,17 +22,15 @@ errorIndication, errorStatus, errorIndex, varBinds = next( CommunityData('public'), UdpTransportTarget(('demo.snmplabs.com', 161)), ContextData(), - ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets', 1).addAsn1MibSource('file:///usr/share/snmp', 'http://mibs.snmplabs.com/asn1/@mib@'))) + ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets', 1).addAsn1MibSource('file:///usr/share/snmp', + 'http://mibs.snmplabs.com/asn1/@mib@'))) ) 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/custom-contextengineid-and-contextname.py b/examples/hlapi/asyncore/sync/manager/cmdgen/custom-contextengineid-and-contextname.py index 1244583d..497af602 100644 --- a/examples/hlapi/asyncore/sync/manager/cmdgen/custom-contextengineid-and-contextname.py +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/custom-contextengineid-and-contextname.py @@ -14,10 +14,7 @@ Send SNMP SET request using the following options: Functionally similar to: -| $ snmpset -v3 -u usr-md5-des -l authPriv -A authkey1 -X privkey1 \ -| -E 80004fb805636c6f75644dab22cc -n a172334d7d97871b72241397f713fa12 \ -| demo.snmplabs.com \ -| SNMPv2-MIB::sysORDescr.1 = "new system name" +| $ snmpset -v3 -u usr-md5-des -l authPriv -A authkey1 -X privkey1 -E 80004fb805636c6f75644dab22cc -n a172334d7d97871b72241397f713fa12 demo.snmplabs.com SNMPv2-MIB::sysORDescr.1 = "new system name" """# from pysnmp.hlapi import * @@ -28,18 +25,14 @@ errorIndication, errorStatus, errorIndex, varBinds = next( UdpTransportTarget(('demo.snmplabs.com', 161)), ContextData(contextEngineId=OctetString(hexValue='80004fb805636c6f75644dab22cc'), contextName='da761cfc8c94d3aceef4f60f049105ba'), - ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysORDescr', 1), - 'new system name')) + ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysORDescr', 1), 'new system name')) ) 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/custom-contextengineid.py b/examples/hlapi/asyncore/sync/manager/cmdgen/custom-contextengineid.py index ea97c59d..6435a5d5 100644 --- a/examples/hlapi/asyncore/sync/manager/cmdgen/custom-contextengineid.py +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/custom-contextengineid.py @@ -13,9 +13,7 @@ Send SNMP GET request using the following options: Functionally similar to: -| $ snmpset -v3 -u usr-md5-des -l authPriv -A authkey1 -X privkey1 \ -| -E 80004fb805636c6f75644dab22cc demo.snmplabs.com \ -| SNMPv2-MIB::sysORDescr.1 = "new system name" +| $ snmpset -v3 -u usr-md5-des -l authPriv -A authkey1 -X privkey1 -E 80004fb805636c6f75644dab22cc demo.snmplabs.com SNMPv2-MIB::sysORDescr.1 = "new system name" """# from pysnmp.hlapi import * @@ -26,18 +24,14 @@ errorIndication, errorStatus, errorIndex, varBinds = next( securityEngineId=OctetString(hexValue='80004fb805636c6f75644dab22cc')), UdpTransportTarget(('demo.snmplabs.com', 161)), ContextData(), - ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysName', 0), - 'new system name')) + ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysName', 0), 'new system name')) ) 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/custom-pysnmp-mibs-search-path.py b/examples/hlapi/asyncore/sync/manager/cmdgen/custom-pysnmp-mibs-search-path.py index 42b1df6c..26b8954a 100644 --- a/examples/hlapi/asyncore/sync/manager/cmdgen/custom-pysnmp-mibs-search-path.py +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/custom-pysnmp-mibs-search-path.py @@ -14,32 +14,31 @@ Send a series of SNMP GETBULK requests using the following options: Functionally similar to: -| $ snmpbulkwalk -v3 -lnoAuthNoPriv -u usr-none-none -Cn0 -Cr50 \ -| demo.snmplabs.com TCP-MIB::tcpConnTable +| $ snmpbulkwalk -v3 -lnoAuthNoPriv -u usr-none-none -Cn0 -Cr50 demo.snmplabs.com TCP-MIB::tcpConnTable """# from pysnmp.hlapi import * -for errorIndication, \ - errorStatus, errorIndex, \ - varBinds in bulkCmd(SnmpEngine(), - UsmUserData('usr-none-none'), - UdpTransportTarget(('demo.snmplabs.com', 161)), - ContextData(), - 0, 50, - ObjectType(ObjectIdentity('TCP-MIB', 'tcpConnTable').addMibSource('/opt/mibs/pysnmp').addMibSource('python_packaged_mibs')), - lexicographicMode=False): +for (errorIndication, + errorStatus, + errorIndex, + varBinds) in bulkCmd(SnmpEngine(), + UsmUserData('usr-none-none'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ContextData(), + 0, 50, + ObjectType( + ObjectIdentity('TCP-MIB', 'tcpConnTable').addMibSource('/opt/mibs/pysnmp').addMibSource('python_packaged_mibs') + ), + 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/custom-timeout-and-retries.py b/examples/hlapi/asyncore/sync/manager/cmdgen/custom-timeout-and-retries.py index cfa274fe..d70a322f 100644 --- a/examples/hlapi/asyncore/sync/manager/cmdgen/custom-timeout-and-retries.py +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/custom-timeout-and-retries.py @@ -43,11 +43,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/custom-v3-security-name.py b/examples/hlapi/asyncore/sync/manager/cmdgen/custom-v3-security-name.py index 4346b26d..8e541f7b 100644 --- a/examples/hlapi/asyncore/sync/manager/cmdgen/custom-v3-security-name.py +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/custom-v3-security-name.py @@ -28,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/fetch-variables-over-ipv6.py b/examples/hlapi/asyncore/sync/manager/cmdgen/fetch-variables-over-ipv6.py index d4316594..9bc76446 100644 --- a/examples/hlapi/asyncore/sync/manager/cmdgen/fetch-variables-over-ipv6.py +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/fetch-variables-over-ipv6.py @@ -11,11 +11,7 @@ Send SNMP GET request using the following options: Functionally similar to: -| $ snmpget -v3 -l authPriv -u usr-md5-des -A authkey1 -X privkey1 \ -| udp6:[::1]:161 \ -| 1.3.6.1.2.1.1.1.0 \ -| 1.3.6.1.2.1.1.2.0 \ -| 1.3.6.1.2.1.1.3.0 +| $ snmpget -v3 -l authPriv -u usr-md5-des -A authkey1 -X privkey1 udp6:[::1]:161 1.3.6.1.2.1.1.1.0 1.3.6.1.2.1.1.2.0 1.3.6.1.2.1.1.3.0 """# from pysnmp.hlapi import * @@ -32,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/get-table-object-by-index.py b/examples/hlapi/asyncore/sync/manager/cmdgen/get-table-object-by-index.py index fc8a8822..ed5d8351 100644 --- a/examples/hlapi/asyncore/sync/manager/cmdgen/get-table-object-by-index.py +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/get-table-object-by-index.py @@ -12,9 +12,7 @@ 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 IF-MIB::ifOutOctets.1 +| $ snmpget -v3 -l authPriv -u usr-md5-des -A authkey1 -X privkey1 demo.snmplabs.com IF-MIB::ifInOctets.1 IF-MIB::ifOutOctets.1 """# from pysnmp.hlapi import * @@ -31,11 +29,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/get-table-object-by-multiple-indices.py b/examples/hlapi/asyncore/sync/manager/cmdgen/get-table-object-by-multiple-indices.py index 5d0621db..672aea93 100644 --- a/examples/hlapi/asyncore/sync/manager/cmdgen/get-table-object-by-multiple-indices.py +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/get-table-object-by-multiple-indices.py @@ -11,10 +11,7 @@ Send SNMP GET request using the following options: Functionally similar to: -| $ snmpget -v3 -l authPriv -u usr-md5-des -A authkey1 -X privkey1 \ -| -a SHA -x AES \ -| demo.snmplabs.com \ -| TCP-MIB::tcpConnLocalAddress."0.0.0.0".22."0.0.0.0".0 +| $ snmpget -v3 -l authPriv -u usr-md5-des -A authkey1 -X privkey1 -a SHA -x AES demo.snmplabs.com TCP-MIB::tcpConnLocalAddress."0.0.0.0".22."0.0.0.0".0 """# from pysnmp.hlapi import * @@ -23,24 +20,20 @@ errorIndication, errorStatus, errorIndex, varBinds = next( getCmd(SnmpEngine(), UsmUserData('usr-sha-aes128', 'authkey1', 'privkey1', authProtocol=usmHMACSHAAuthProtocol, - privProtocol=usmAesCfb128Protocol ), + privProtocol=usmAesCfb128Protocol), UdpTransportTarget(('demo.snmplabs.com', 161)), ContextData(), ObjectType(ObjectIdentity('TCP-MIB', 'tcpConnLocalAddress', '0.0.0.0', 22, - '0.0.0.0', 0)) - ) + '0.0.0.0', 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/getbulk-fetch-scalar-and-table-variables.py b/examples/hlapi/asyncore/sync/manager/cmdgen/getbulk-fetch-scalar-and-table-variables.py index 6b18d422..499c9b02 100644 --- a/examples/hlapi/asyncore/sync/manager/cmdgen/getbulk-fetch-scalar-and-table-variables.py +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/getbulk-fetch-scalar-and-table-variables.py @@ -13,36 +13,30 @@ Send a series of SNMP GETBULK requests using the following options: Functionally similar to: -| $ snmpbulkwalk -v3 -lauthPriv -u usr-md5-des -A authkey1 -X privkey1 \ -| -Cn1, -Cr25 \ -| demo.snmplabs.com \ -| IP-MIB::ipAdEntAddr \ -| IP-MIB::ipAddrEntry +| $ snmpbulkwalk -v3 -lauthPriv -u usr-md5-des -A authkey1 -X privkey1 -Cn1, -Cr25 demo.snmplabs.com IP-MIB::ipAdEntAddr IP-MIB::ipAddrEntry """# from pysnmp.hlapi import * -for errorIndication, \ - errorStatus, errorIndex, \ - varBinds in bulkCmd(SnmpEngine(), - UsmUserData('usr-md5-des', 'authkey1', 'privkey1'), - Udp6TransportTarget(('::1', 161)), - ContextData(), - 1, 25, - ObjectType(ObjectIdentity('IP-MIB', 'ipAdEntAddr')), - ObjectType(ObjectIdentity('IP-MIB', 'ipAddrEntry')), - lexicographicMode=False): +for (errorIndication, + errorStatus, + errorIndex, + varBinds) in bulkCmd(SnmpEngine(), + UsmUserData('usr-md5-des', 'authkey1', 'privkey1'), + Udp6TransportTarget(('::1', 161)), + ContextData(), + 1, 25, + ObjectType(ObjectIdentity('IP-MIB', 'ipAdEntAddr')), + ObjectType(ObjectIdentity('IP-MIB', 'ipAddrEntry')), + 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/getbulk-limit-number-of-packets.py b/examples/hlapi/asyncore/sync/manager/cmdgen/getbulk-limit-number-of-packets.py index 51468089..dd94650c 100644 --- a/examples/hlapi/asyncore/sync/manager/cmdgen/getbulk-limit-number-of-packets.py +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/getbulk-limit-number-of-packets.py @@ -13,32 +13,29 @@ Send a series of SNMP GETBULK requests using the following options: Functionally similar to: -| $ snmpbulkwalk -v3 -lnoAuthNoPriv -u usr-none-none -Cn0 -Cr50 \ -| demo.snmplabs.com SNMPv2-MIB::system +| $ snmpbulkwalk -v3 -lnoAuthNoPriv -u usr-none-none -Cn0 -Cr50 demo.snmplabs.com SNMPv2-MIB::system """# from pysnmp.hlapi import * -for errorIndication, \ - errorStatus, errorIndex, \ - varBinds in bulkCmd(SnmpEngine(), - UsmUserData('usr-none-none'), - UdpTransportTarget(('demo.snmplabs.com', 161)), - ContextData(), - 0, 50, - ObjectType(ObjectIdentity('SNMPv2-MIB', 'system')), - maxCalls=10): +for (errorIndication, + errorStatus, + errorIndex, + varBinds) in bulkCmd(SnmpEngine(), + UsmUserData('usr-none-none'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ContextData(), + 0, 50, + ObjectType(ObjectIdentity('SNMPv2-MIB', 'system')), + maxCalls=10): 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/getbulk-limit-number-of-variables.py b/examples/hlapi/asyncore/sync/manager/cmdgen/getbulk-limit-number-of-variables.py index ef95f5a8..fa39086b 100644 --- a/examples/hlapi/asyncore/sync/manager/cmdgen/getbulk-limit-number-of-variables.py +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/getbulk-limit-number-of-variables.py @@ -14,33 +14,29 @@ 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, maxRows=20): +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, maxRows=20): 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: diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/getnext-limit-number-of-variables.py b/examples/hlapi/asyncore/sync/manager/cmdgen/getnext-limit-number-of-variables.py index 9536ebb5..f9fd70c1 100644 --- a/examples/hlapi/asyncore/sync/manager/cmdgen/getnext-limit-number-of-variables.py +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/getnext-limit-number-of-variables.py @@ -13,34 +13,30 @@ Send a series of SNMP GETNEXT requests using the following options: Functionally similar to: -| $ snmpwalk -v3 -lauthPriv -u usr-sha-aes128 -A authkey1 -X privkey1 \ -| -a MD5 -x AES demo.snmplabs.com \ -| SNMPv2-MIB::system +| $ snmpwalk -v3 -lauthPriv -u usr-sha-aes128 -A authkey1 -X privkey1 -a MD5 -x AES demo.snmplabs.com SNMPv2-MIB::system """# from pysnmp.hlapi import * -for errorIndication, \ - errorStatus, errorIndex, \ - varBinds in nextCmd(SnmpEngine(), - UsmUserData('usr-sha-aes128', 'authkey1', 'privkey1', - authProtocol=usmHMACSHAAuthProtocol, - privProtocol=usmAesCfb128Protocol), - UdpTransportTarget(('demo.snmplabs.com', 161)), - ContextData(), - ObjectType(ObjectIdentity('SNMPv2-MIB')), - maxRows=100, ignoreNonIncreasingOid=True): +for (errorIndication, + errorStatus, + errorIndex, + varBinds) in nextCmd(SnmpEngine(), + UsmUserData('usr-sha-aes128', 'authkey1', 'privkey1', + authProtocol=usmHMACSHAAuthProtocol, + privProtocol=usmAesCfb128Protocol), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ContextData(), + ObjectType(ObjectIdentity('SNMPv2-MIB')), + maxRows=100, ignoreNonIncreasingOid=True): 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/getnext-multiple-oids-to-eom.py b/examples/hlapi/asyncore/sync/manager/cmdgen/getnext-multiple-oids-to-eom.py index c2858a77..863ceb6f 100644 --- a/examples/hlapi/asyncore/sync/manager/cmdgen/getnext-multiple-oids-to-eom.py +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/getnext-multiple-oids-to-eom.py @@ -12,31 +12,28 @@ Send a series of SNMP GETNEXT requests using the following options: Functionally similar to: -| $ snmpwalk -v2c -c public demo.snmplabs.com \ -| 1.3.6.1.2.1.2.2.1.2 1.3.6.1.2.1.2.2.1.3 +| $ snmpwalk -v2c -c public demo.snmplabs.com 1.3.6.1.2.1.2.2.1.2 1.3.6.1.2.1.2.2.1.3 """# 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.2.2.1.2')), - ObjectType(ObjectIdentity('1.3.6.1.2.1.2.2.1.3')), - lexicographicMode=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.2.2.1.2')), + ObjectType(ObjectIdentity('1.3.6.1.2.1.2.2.1.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: diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/multiple-get-calls.py b/examples/hlapi/asyncore/sync/manager/cmdgen/multiple-get-calls.py index d8c63ef1..c08b9f47 100644 --- a/examples/hlapi/asyncore/sync/manager/cmdgen/multiple-get-calls.py +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/multiple-get-calls.py @@ -16,14 +16,13 @@ could consume input 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 * -queue = [ [ ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets', 1)) ], - [ ObjectType(ObjectIdentity('IF-MIB', 'ifOutOctets', 1)) ] ] +queue = [[ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets', 1))], + [ObjectType(ObjectIdentity('IF-MIB', 'ifOutOctets', 1))]] iter = getCmd(SnmpEngine(), UsmUserData('usr-md5-none', 'authkey1'), @@ -37,11 +36,8 @@ while queue: 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/preload-pysnmp-mibs.py b/examples/hlapi/asyncore/sync/manager/cmdgen/preload-pysnmp-mibs.py index 885dbdfc..27186431 100644 --- a/examples/hlapi/asyncore/sync/manager/cmdgen/preload-pysnmp-mibs.py +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/preload-pysnmp-mibs.py @@ -12,32 +12,27 @@ Send a series of SNMP GETNEXT requests using the following options: Functionally similar to: -| $ snmpwalk -v3 -l authPriv -u usr-md5-des -A authkey1 -X privkey1 \ -| -m ALL -| udp6:[::1]:161 \ -| 1.3.6 +| $ snmpwalk -v3 -l authPriv -u usr-md5-des -A authkey1 -X privkey1 -m ALL udp6:[::1]:161 1.3.6 """# from pysnmp.hlapi import * -for errorIndication, \ - errorStatus, errorIndex, \ - varBinds in nextCmd(SnmpEngine(), - UsmUserData('usr-md5-des', 'authkey1', 'privkey1'), - Udp6TransportTarget(('::1', 161)), - ContextData(), - ObjectType(ObjectIdentity('1.3.6').loadMibs())): +for (errorIndication, + errorStatus, + errorIndex, + varBinds) in nextCmd(SnmpEngine(), + UsmUserData('usr-md5-des', 'authkey1', 'privkey1'), + Udp6TransportTarget(('::1', 161)), + ContextData(), + ObjectType(ObjectIdentity('1.3.6').loadMibs())): 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])) |