diff options
Diffstat (limited to 'examples/hlapi/v3arch/asyncore/sync')
38 files changed, 507 insertions, 348 deletions
diff --git a/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/custom-contextengineid.py b/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/custom-contextengineid.py index 1b9e12d5..18da255f 100644 --- a/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/custom-contextengineid.py +++ b/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/custom-contextengineid.py @@ -22,23 +22,26 @@ Functionally similar to: """# from pysnmp.hlapi import * -errorIndication, errorStatus, errorIndex, varBinds = next( - sendNotification(SnmpEngine(), - UsmUserData('usr-md5-none', 'authkey1'), - UdpTransportTarget(('demo.snmplabs.com', 162)), - ContextData(OctetString(hexValue='8000000004030201')), - 'inform', - NotificationType( - ObjectIdentity('1.3.6.1.6.3.1.1.5.2') - ).loadMibs('SNMPv2-MIB') - ) +iterator = sendNotification( + SnmpEngine(), + UsmUserData('usr-md5-none', 'authkey1'), + UdpTransportTarget(('demo.snmplabs.com', 162)), + ContextData(OctetString(hexValue='8000000004030201')), + 'inform', + NotificationType( + ObjectIdentity('1.3.6.1.6.3.1.1.5.2') + ).loadMibs('SNMPv2-MIB') ) +errorIndication, errorStatus, errorIndex, varBinds = next(iterator) + if errorIndication: print(errorIndication) + elif 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])) diff --git a/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/custom-contextname.py b/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/custom-contextname.py index 96abba48..2c232cb6 100644 --- a/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/custom-contextname.py +++ b/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/custom-contextname.py @@ -22,20 +22,24 @@ Functionally similar to: """# from pysnmp.hlapi import * -errorIndication, errorStatus, errorIndex, varBinds = next( - sendNotification(SnmpEngine(), - UsmUserData('usr-md5-none', 'authkey1'), - UdpTransportTarget(('demo.snmplabs.com', 162)), - ContextData(contextName='my-context'), - 'inform', - NotificationType(ObjectIdentity('1.3.6.1.6.3.1.1.5.2')).loadMibs('SNMPv2-MIB')) +iterator = sendNotification( + SnmpEngine(), + UsmUserData('usr-md5-none', 'authkey1'), + UdpTransportTarget(('demo.snmplabs.com', 162)), + ContextData(contextName='my-context'), + 'inform', + NotificationType(ObjectIdentity('1.3.6.1.6.3.1.1.5.2')).loadMibs('SNMPv2-MIB') ) +errorIndication, errorStatus, errorIndex, varBinds = next(iterator) + if errorIndication: print(errorIndication) + elif 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])) diff --git a/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/custom-v1-trap.py b/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/custom-v1-trap.py index c6d84303..017fc8b8 100644 --- a/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/custom-v1-trap.py +++ b/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/custom-v1-trap.py @@ -24,24 +24,25 @@ 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')) - ).loadMibs( - 'SNMPv2-MIB', 'SNMP-COMMUNITY-MIB' - ) +iterator = 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')) + ).loadMibs( + 'SNMPv2-MIB', 'SNMP-COMMUNITY-MIB' ) ) + +errorIndication, errorStatus, errorIndex, varBinds = next(iterator) + if errorIndication: print(errorIndication) diff --git a/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/default-v1-trap.py b/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/default-v1-trap.py index 552ad877..4846f9da 100644 --- a/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/default-v1-trap.py +++ b/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/default-v1-trap.py @@ -22,23 +22,23 @@ 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')) - ).loadMibs( - 'SNMPv2-MIB' - ) +iterator = 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')) + ).loadMibs( + 'SNMPv2-MIB' ) ) +errorIndication, errorStatus, errorIndex, varBinds = next(iterator) + if errorIndication: print(errorIndication) diff --git a/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/send-notification-with-additional-varbinds.py b/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/send-notification-with-additional-varbinds.py index 46f3c5c1..1fd44398 100644 --- a/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/send-notification-with-additional-varbinds.py +++ b/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/send-notification-with-additional-varbinds.py @@ -18,26 +18,28 @@ 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') - ) +iterator = 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') ) ) +errorIndication, errorStatus, errorIndex, varBinds = next(iterator) + if errorIndication: print(errorIndication) + elif 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])) diff --git a/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/v2c-trap-with-notification-objects.py b/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/v2c-trap-with-notification-objects.py index 5681d28c..c53f09e6 100644 --- a/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/v2c-trap-with-notification-objects.py +++ b/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/v2c-trap-with-notification-objects.py @@ -20,22 +20,24 @@ 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'} - ) +iterator = 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' + } ) ) +errorIndication, errorStatus, errorIndex, varBinds = next(iterator) + if errorIndication: print(errorIndication) diff --git a/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/v3-inform.py b/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/v3-inform.py index 6f02024f..fb9df891 100644 --- a/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/v3-inform.py +++ b/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/v3-inform.py @@ -18,28 +18,30 @@ 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') - ).loadMibs( - 'SNMPv2-MIB' - ) +iterator = 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') + ).loadMibs( + 'SNMPv2-MIB' ) ) +errorIndication, errorStatus, errorIndex, varBinds = next(iterator) + if errorIndication: print(errorIndication) + elif 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])) diff --git a/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/v3-trap.py b/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/v3-trap.py index 14501fb9..87a53fd6 100644 --- a/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/v3-trap.py +++ b/examples/hlapi/v3arch/asyncore/sync/agent/ntforg/v3-trap.py @@ -24,18 +24,18 @@ Functionally similar to: """# from pysnmp.hlapi import * -errorIndication, errorStatus, errorIndex, varBinds = next( - sendNotification( - SnmpEngine(OctetString(hexValue='8000000001020304')), - UsmUserData('usr-sha-aes128', 'authkey1', 'privkey1', - authProtocol=USM_AUTH_HMAC96_SHA, - privProtocol=USM_PRIV_CFB128_AES), - UdpTransportTarget(('demo.snmplabs.com', 162)), - ContextData(), - 'trap', - NotificationType(ObjectIdentity('SNMPv2-MIB', 'authenticationFailure')) - ) +iterator = sendNotification( + SnmpEngine(OctetString(hexValue='8000000001020304')), + UsmUserData('usr-sha-aes128', 'authkey1', 'privkey1', + authProtocol=USM_AUTH_HMAC96_SHA, + privProtocol=USM_PRIV_CFB128_AES), + UdpTransportTarget(('demo.snmplabs.com', 162)), + ContextData(), + 'trap', + NotificationType(ObjectIdentity('SNMPv2-MIB', 'authenticationFailure')) ) +errorIndication, errorStatus, errorIndex, varBinds = next(iterator) + if errorIndication: print(errorIndication) diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/coerce-set-value-to-mib-spec.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/coerce-set-value-to-mib-spec.py index b6fb879e..93ba8fff 100644 --- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/coerce-set-value-to-mib-spec.py +++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/coerce-set-value-to-mib-spec.py @@ -16,20 +16,26 @@ Functionally similar to: """# from pysnmp.hlapi import * -errorIndication, errorStatus, errorIndex, varBinds = next( - setCmd(SnmpEngine(), - CommunityData('public'), - UdpTransportTarget(('demo.snmplabs.com', 161)), - ContextData(), - ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysORDescr', 1), - 'new system name')) +iterator = setCmd( + SnmpEngine(), + CommunityData('public'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ContextData(), + ObjectType( + ObjectIdentity('SNMPv2-MIB', 'sysORDescr', 1), + 'new system name' + ) ) +errorIndication, errorStatus, errorIndex, varBinds = next(iterator) + if errorIndication: print(errorIndication) + elif 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])) diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-asn1-mib-search-path.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-asn1-mib-search-path.py index f25fafe4..3c279437 100644 --- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-asn1-mib-search-path.py +++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-asn1-mib-search-path.py @@ -17,20 +17,30 @@ Functionally similar to: """# from pysnmp.hlapi import * -errorIndication, errorStatus, errorIndex, varBinds = next( - getCmd(SnmpEngine(), - 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@'))) +iterator = getCmd( + SnmpEngine(), + 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@' + ) + ) ) +errorIndication, errorStatus, errorIndex, varBinds = next(iterator) + if errorIndication: print(errorIndication) + elif 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])) diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-contextengineid-and-contextname.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-contextengineid-and-contextname.py index 497af602..38871cd8 100644 --- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-contextengineid-and-contextname.py +++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-contextengineid-and-contextname.py @@ -19,20 +19,26 @@ Functionally similar to: """# from pysnmp.hlapi import * -errorIndication, errorStatus, errorIndex, varBinds = next( - setCmd(SnmpEngine(), - UsmUserData('usr-md5-none', 'authkey1'), - UdpTransportTarget(('demo.snmplabs.com', 161)), - ContextData(contextEngineId=OctetString(hexValue='80004fb805636c6f75644dab22cc'), - contextName='da761cfc8c94d3aceef4f60f049105ba'), - ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysORDescr', 1), 'new system name')) +iterator = setCmd( + SnmpEngine(), + UsmUserData('usr-md5-none', 'authkey1'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ContextData( + contextEngineId=OctetString(hexValue='80004fb805636c6f75644dab22cc'), + contextName='da761cfc8c94d3aceef4f60f049105ba' + ), + ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysORDescr', 1), 'new system name') ) +errorIndication, errorStatus, errorIndex, varBinds = next(iterator) + if errorIndication: print(errorIndication) + elif 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])) diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-contextengineid.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-contextengineid.py index 6435a5d5..3f50481d 100644 --- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-contextengineid.py +++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-contextengineid.py @@ -18,20 +18,24 @@ Functionally similar to: """# from pysnmp.hlapi import * -errorIndication, errorStatus, errorIndex, varBinds = next( - setCmd(SnmpEngine(), - UsmUserData('usr-md5-des', 'authkey1', 'privkey1', - securityEngineId=OctetString(hexValue='80004fb805636c6f75644dab22cc')), - UdpTransportTarget(('demo.snmplabs.com', 161)), - ContextData(), - ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysName', 0), 'new system name')) +iterator = setCmd( + SnmpEngine(), + UsmUserData('usr-md5-des', 'authkey1', 'privkey1', + securityEngineId=OctetString(hexValue='80004fb805636c6f75644dab22cc')), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ContextData(), + ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysName', 0), 'new system name') ) +errorIndication, errorStatus, errorIndex, varBinds = next(iterator) + if errorIndication: print(errorIndication) + elif 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])) diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-pysnmp-mibs-search-path.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-pysnmp-mibs-search-path.py index 26b8954a..33d72f1f 100644 --- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-pysnmp-mibs-search-path.py +++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-pysnmp-mibs-search-path.py @@ -19,26 +19,35 @@ Functionally similar to: """# 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): +iterator = 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 iterator: if errorIndication: print(errorIndication) break + elif 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])) diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-timeout-and-retries.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-timeout-and-retries.py index d70a322f..9b99693a 100644 --- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-timeout-and-retries.py +++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-timeout-and-retries.py @@ -30,21 +30,23 @@ Functionally similar to: """# from pysnmp.hlapi import * -errorIndication, errorStatus, errorIndex, varBinds = next( - getCmd(SnmpEngine(), - CommunityData('public'), - UdpTransportTarget( - ('demo.snmplabs.com', 161), timeout=2.0, retries=0 - ), - ContextData(), - ObjectType(ObjectIdentity('1.3.6.1.2.1.1.1.0'))) +iterator = getCmd( + SnmpEngine(), + CommunityData('public'), + UdpTransportTarget(('demo.snmplabs.com', 161), timeout=2.0, retries=0), + ContextData(), + ObjectType(ObjectIdentity('1.3.6.1.2.1.1.1.0')) ) +errorIndication, errorStatus, errorIndex, varBinds = next(iterator) + if errorIndication: print(errorIndication) + elif 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])) diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-v3-security-name.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-v3-security-name.py index 8e541f7b..cadc2c3c 100644 --- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-v3-security-name.py +++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/custom-v3-security-name.py @@ -17,19 +17,23 @@ usmUserTable, thus duplicate securityName parameters are possible. """# from pysnmp.hlapi import * -errorIndication, errorStatus, errorIndex, varBinds = next( - getCmd(SnmpEngine(), - UsmUserData('usr-md5-none', 'authkey1', securityName='myuser'), - UdpTransportTarget(('demo.snmplabs.com', 161)), - ContextData(), - ObjectType(ObjectIdentity('1.3.6.1.2.1.1.1.0'))) +iterator = getCmd( + SnmpEngine(), + UsmUserData('usr-md5-none', 'authkey1', securityName='myuser'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ContextData(), + ObjectType(ObjectIdentity('1.3.6.1.2.1.1.1.0')) ) +errorIndication, errorStatus, errorIndex, varBinds = next(iterator) + if errorIndication: print(errorIndication) + elif 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])) diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/fetch-variables-over-ipv6.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/fetch-variables-over-ipv6.py index 9bc76446..9b8f3382 100644 --- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/fetch-variables-over-ipv6.py +++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/fetch-variables-over-ipv6.py @@ -15,21 +15,25 @@ Functionally similar to: """# from pysnmp.hlapi import * -errorIndication, errorStatus, errorIndex, varBinds = next( - getCmd(SnmpEngine(), - UsmUserData('usr-md5-des', 'authkey1', 'privkey1'), - Udp6TransportTarget(('::1', 161)), - ContextData(), - ObjectType(ObjectIdentity('1.3.6.1.2.1.1.1.0')), - ObjectType(ObjectIdentity('1.3.6.1.2.1.1.2.0')), - ObjectType(ObjectIdentity('1.3.6.1.2.1.1.3.0'))) +iterator = getCmd( + SnmpEngine(), + UsmUserData('usr-md5-des', 'authkey1', 'privkey1'), + Udp6TransportTarget(('::1', 161)), + ContextData(), + ObjectType(ObjectIdentity('1.3.6.1.2.1.1.1.0')), + ObjectType(ObjectIdentity('1.3.6.1.2.1.1.2.0')), + ObjectType(ObjectIdentity('1.3.6.1.2.1.1.3.0')) ) +errorIndication, errorStatus, errorIndex, varBinds = next(iterator) + if errorIndication: print(errorIndication) + elif 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])) diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/get-table-object-by-index.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/get-table-object-by-index.py index ed5d8351..253b9224 100644 --- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/get-table-object-by-index.py +++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/get-table-object-by-index.py @@ -17,20 +17,24 @@ Functionally similar to: """# 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)), - ObjectType(ObjectIdentity('IF-MIB', 'ifOutOctets', 1))) +iterator = getCmd( + SnmpEngine(), + UsmUserData('usr-none-none'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ContextData(), + ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets', 1)), + ObjectType(ObjectIdentity('IF-MIB', 'ifOutOctets', 1)) ) +errorIndication, errorStatus, errorIndex, varBinds = next(iterator) + if errorIndication: print(errorIndication) + elif 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])) diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/get-table-object-by-multiple-indices.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/get-table-object-by-multiple-indices.py index 06302525..733bd9cb 100644 --- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/get-table-object-by-multiple-indices.py +++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/get-table-object-by-multiple-indices.py @@ -16,24 +16,34 @@ Functionally similar to: """# from pysnmp.hlapi import * -errorIndication, errorStatus, errorIndex, varBinds = next( - getCmd(SnmpEngine(), - UsmUserData('usr-sha-aes128', 'authkey1', 'privkey1', - authProtocol=USM_AUTH_HMAC96_SHA, - privProtocol=USM_PRIV_CFB128_AES), - UdpTransportTarget(('demo.snmplabs.com', 161)), - ContextData(), - ObjectType(ObjectIdentity('TCP-MIB', - 'tcpConnLocalAddress', - '0.0.0.0', 22, - '0.0.0.0', 0))) +iterator = getCmd( + SnmpEngine(), + UsmUserData( + 'usr-sha-aes128', 'authkey1', 'privkey1', + authProtocol=USM_AUTH_HMAC96_SHA, + privProtocol=USM_PRIV_CFB128_AES + ), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ContextData(), + ObjectType( + ObjectIdentity( + 'TCP-MIB', + 'tcpConnLocalAddress', + '0.0.0.0', 22, + '0.0.0.0', 0 + ) + ) ) +errorIndication, errorStatus, errorIndex, varBinds = next(iterator) + if errorIndication: print(errorIndication) + elif 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])) diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getbulk-fetch-scalar-and-table-variables-over-ipv6.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getbulk-fetch-scalar-and-table-variables-over-ipv6.py index 499c9b02..261e46f9 100644 --- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getbulk-fetch-scalar-and-table-variables-over-ipv6.py +++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getbulk-fetch-scalar-and-table-variables-over-ipv6.py @@ -18,25 +18,28 @@ Functionally similar to: """# 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): +iterator = 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 iterator: if errorIndication: print(errorIndication) break + elif 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])) diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getbulk-limit-number-of-packets.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getbulk-limit-number-of-packets.py index dd94650c..ce114002 100644 --- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getbulk-limit-number-of-packets.py +++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getbulk-limit-number-of-packets.py @@ -18,24 +18,27 @@ Functionally similar to: """# 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): +iterator = 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 iterator: if errorIndication: print(errorIndication) break + elif 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])) diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getbulk-limit-number-of-variables.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getbulk-limit-number-of-variables.py index fa39086b..c0c355c5 100644 --- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getbulk-limit-number-of-variables.py +++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getbulk-limit-number-of-variables.py @@ -19,25 +19,28 @@ Functionally similar to: """# 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): +iterator = 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 iterator: if errorIndication: print(errorIndication) break + elif 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 ])) diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getnext-limit-number-of-variables.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getnext-limit-number-of-variables.py index d8a2b935..950e9db6 100644 --- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getnext-limit-number-of-variables.py +++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getnext-limit-number-of-variables.py @@ -18,25 +18,30 @@ Functionally similar to: """# from pysnmp.hlapi import * -for (errorIndication, - errorStatus, - errorIndex, - varBinds) in nextCmd(SnmpEngine(), - UsmUserData('usr-sha-aes128', 'authkey1', 'privkey1', - authProtocol=USM_AUTH_HMAC96_SHA, - privProtocol=USM_PRIV_CFB128_AES), - UdpTransportTarget(('demo.snmplabs.com', 161)), - ContextData(), - ObjectType(ObjectIdentity('SNMPv2-MIB')), - maxRows=100, ignoreNonIncreasingOid=True): +iterator = nextCmd( + SnmpEngine(), + UsmUserData( + 'usr-sha-aes128', 'authkey1', 'privkey1', + authProtocol=USM_AUTH_HMAC96_SHA, + privProtocol=USM_PRIV_CFB128_AES + ), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ContextData(), + ObjectType(ObjectIdentity('SNMPv2-MIB')), + maxRows=100, ignoreNonIncreasingOid=True +) + +for errorIndication, errorStatus, errorIndex, varBinds in iterator: if errorIndication: print(errorIndication) break + elif 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])) diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getnext-multiple-oids-to-eom.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getnext-multiple-oids-to-eom.py index 863ceb6f..0008f4bc 100644 --- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getnext-multiple-oids-to-eom.py +++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/getnext-multiple-oids-to-eom.py @@ -17,24 +17,27 @@ 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.2.2.1.2')), - ObjectType(ObjectIdentity('1.3.6.1.2.1.2.2.1.3')), - lexicographicMode=False): +iterator = 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 iterator: if errorIndication: print(errorIndication) break + elif 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 ])) diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/multiple-get-calls.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/multiple-get-calls.py index d883d16a..b69f1c6b 100644 --- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/multiple-get-calls.py +++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/multiple-get-calls.py @@ -25,20 +25,25 @@ from pysnmp.hlapi import * queue = [[ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets', 1))], [ObjectType(ObjectIdentity('IF-MIB', 'ifOutOctets', 1))]] -iterator = getCmd(SnmpEngine(), - UsmUserData('usr-md5-none', 'authkey1'), - UdpTransportTarget(('demo.snmplabs.com', 161)), - ContextData()) +iterator = getCmd( + SnmpEngine(), + UsmUserData('usr-md5-none', 'authkey1'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ContextData() +) next(iterator) while queue: errorIndication, errorStatus, errorIndex, varBinds = iterator.send(queue.pop()) + if errorIndication: print(errorIndication) + elif 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])) diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/preload-pysnmp-mibs.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/preload-pysnmp-mibs.py index a9bb2bb3..ed752999 100644 --- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/preload-pysnmp-mibs.py +++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/preload-pysnmp-mibs.py @@ -17,22 +17,25 @@ Functionally similar to: """# from pysnmp.hlapi import * -for (errorIndication, - errorStatus, - errorIndex, - varBinds) in nextCmd(SnmpEngine(), - UsmUserData('usr-md5-des', 'authkey1', 'privkey1'), - UdpTransportTarget(('demo.snmplabs.com', 161)), - ContextData(), - ObjectType(ObjectIdentity('1.3.6').loadMibs())): +iterator = nextCmd( + SnmpEngine(), + UsmUserData('usr-md5-des', 'authkey1', 'privkey1'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ContextData(), + ObjectType(ObjectIdentity('1.3.6').loadMibs()) +) + +for errorIndication, errorStatus, errorIndex, varBinds in iterator: if errorIndication: print(errorIndication) break + elif 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])) diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/pull-whole-mib.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/pull-whole-mib.py index b9103de3..2ac2b318 100644 --- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/pull-whole-mib.py +++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/pull-whole-mib.py @@ -16,22 +16,25 @@ Functionally similar to: """# 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'))): +iterator = nextCmd( + SnmpEngine(), + UsmUserData('usr-md5-none', 'authkey1'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ContextData(), + ObjectType(ObjectIdentity('IF-MIB')) +) + +for errorIndication, errorStatus, errorIndex, varBinds in iterator: if errorIndication: print(errorIndication) break + elif 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])) diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/pull-whole-snmp-table.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/pull-whole-snmp-table.py index 91a71a61..260102a5 100644 --- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/pull-whole-snmp-table.py +++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/pull-whole-snmp-table.py @@ -17,28 +17,31 @@ Functionally similar to: """# 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): +iterator = 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 iterator: if errorIndication: print(errorIndication) break + elif 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])) diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/query-agents-from-multuple-threads-over-ipv4-and-ipv6.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/query-agents-from-multuple-threads-over-ipv4-and-ipv6.py index 16995ed8..049e1be1 100644 --- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/query-agents-from-multuple-threads-over-ipv4-and-ipv6.py +++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/query-agents-from-multuple-threads-over-ipv4-and-ipv6.py @@ -27,39 +27,45 @@ else: # List of targets in the following format: # ( ( authData, transportTarget, varNames ), ... ) -targets = ( +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)))), + # 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)))), - # 3-nd target (SNMPv2c over IPv4/UDP) - same community and + + # 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)))), + # 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)))), + # 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)))), + # N-th target # ... ) class Worker(Thread): + def __init__(self, requests, responses): Thread.__init__(self) self.snmpEngine = SnmpEngine() @@ -71,15 +77,17 @@ class Worker(Thread): def run(self): while True: authData, transportTarget, varBinds = self.requests.get() + self.responses.append( next(getCmd(self.snmpEngine, authData, transportTarget, ContextData(), *varBinds)) ) - if hasattr(self.requests, 'task_done'): # 2.5+ - self.requests.task_done() + + self.requests.task_done() class ThreadPool(object): + def __init__(self, num_threads): self.requests = Queue(num_threads) self.responses = [] @@ -106,7 +114,7 @@ class ThreadPool(object): pool = ThreadPool(3) # Submit GET requests -for authData, transportTarget, varBinds in targets: +for authData, transportTarget, varBinds in TARGETS: pool.addRequest(authData, transportTarget, varBinds) # Wait for responses or errors @@ -114,11 +122,14 @@ pool.waitCompletion() # Walk through responses for errorIndication, errorStatus, errorIndex, varBinds in pool.getResponses(): + if errorIndication: print(errorIndication) + elif 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])) diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/set-multiple-scalar-values.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/set-multiple-scalar-values.py index be4ffeab..a5eeb1a3 100644 --- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/set-multiple-scalar-values.py +++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/set-multiple-scalar-values.py @@ -20,24 +20,34 @@ Functionally similar to: """# from pysnmp.hlapi import * -errorIndication, errorStatus, errorIndex, varBinds = next( - setCmd(SnmpEngine(), - CommunityData('public', mpModel=0), - UdpTransportTarget(('demo.snmplabs.com', 161)), - ContextData(), - ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysORID', 1), - ObjectIdentifier('1.3.6.1.4.1.20408.1.1')), - ObjectType(ObjectIdentity('1.3.6.1.2.1.1.9.1.2.1'), - '1.3.6.1.4.1.20408.1.1'), - ObjectType(ObjectIdentity('1.3.6.1.2.1.1.9.1.3.1'), - OctetString('new system name'))) +iterator = setCmd( + SnmpEngine(), + CommunityData('public', mpModel=0), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ContextData(), + ObjectType( + ObjectIdentity('SNMPv2-MIB', 'sysORID', 1), + ObjectIdentifier('1.3.6.1.4.1.20408.1.1') + ), + ObjectType( + ObjectIdentity('1.3.6.1.2.1.1.9.1.2.1'), + '1.3.6.1.4.1.20408.1.1' + ), + ObjectType( + ObjectIdentity('1.3.6.1.2.1.1.9.1.3.1'), + OctetString('new system name') + ) ) +errorIndication, errorStatus, errorIndex, varBinds = next(iterator) + if errorIndication: print(errorIndication) + elif 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])) diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/specific-v3-engine-id.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/specific-v3-engine-id.py index 94f591c4..36cfc050 100644 --- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/specific-v3-engine-id.py +++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/specific-v3-engine-id.py @@ -65,19 +65,23 @@ print('Remote securityEngineId = %s' % securityEngineId.prettyPrint()) authData = UsmUserData('usr-md5-none', 'authkey1', securityEngineId=securityEngineId) -errorIndication, errorStatus, errorIndex, varBinds = next( - getCmd(snmpEngine, - authData, - transportTarget, - ContextData(), - ObjectType(ObjectIdentity('1.3.6.1.2.1.1.1.0'))) +iterator = getCmd( + snmpEngine, + authData, + transportTarget, + ContextData(), + ObjectType(ObjectIdentity('1.3.6.1.2.1.1.1.0')) ) +errorIndication, errorStatus, errorIndex, varBinds = next(iterator) + if errorIndication: print(errorIndication) + elif errorStatus: 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/v3arch/asyncore/sync/manager/cmdgen/usm-md5-des.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-md5-des.py index 27c0e7fb..6254418c 100644 --- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-md5-des.py +++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-md5-des.py @@ -16,19 +16,23 @@ Functionally similar to: """# 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))) +iterator = getCmd( + SnmpEngine(), + UsmUserData('usr-md5-des', 'authkey1', 'privkey1'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ContextData(), + ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets', 1)) ) +errorIndication, errorStatus, errorIndex, varBinds = next(iterator) + if errorIndication: print(errorIndication) + elif 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])) diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-md5-none.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-md5-none.py index f06964e2..724910b5 100644 --- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-md5-none.py +++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-md5-none.py @@ -16,19 +16,23 @@ Functionally similar to: """# 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))) +iterator = getCmd( + SnmpEngine(), + UsmUserData('usr-md5-none', 'authkey1'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ContextData(), + ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets', 1)) ) +errorIndication, errorStatus, errorIndex, varBinds = next(iterator) + if errorIndication: print(errorIndication) + elif 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])) diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-none-none.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-none-none.py index 940d8817..8a558920 100644 --- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-none-none.py +++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-none-none.py @@ -16,18 +16,22 @@ Functionally similar to: """# 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))) +iterator = getCmd( + SnmpEngine(), + UsmUserData('usr-none-none'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ContextData(), + ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets', 1)) ) +errorIndication, errorStatus, errorIndex, varBinds = next(iterator) + if errorIndication: print(errorIndication) + elif 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])) diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-sha-aes128.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-sha-aes128.py index 69262086..e30e8239 100644 --- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-sha-aes128.py +++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/usm-sha-aes128.py @@ -35,21 +35,25 @@ Functionally similar to: """# from pysnmp.hlapi import * -errorIndication, errorStatus, errorIndex, varBinds = next( - getCmd(SnmpEngine(), - UsmUserData('usr-sha-aes', 'authkey1', 'privkey1', - authProtocol=USM_AUTH_HMAC96_SHA, - privProtocol=USM_PRIV_CFB128_AES), - UdpTransportTarget(('demo.snmplabs.com', 161)), - ContextData(), - ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0))) +iterator = getCmd( + SnmpEngine(), + UsmUserData('usr-sha-aes', 'authkey1', 'privkey1', + authProtocol=USM_AUTH_HMAC96_SHA, + privProtocol=USM_PRIV_CFB128_AES), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ContextData(), + ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)) ) +errorIndication, errorStatus, errorIndex, varBinds = next(iterator) + if errorIndication: print(errorIndication) + elif 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])) diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/v1-get.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/v1-get.py index 1b272967..55c49735 100644 --- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/v1-get.py +++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/v1-get.py @@ -16,19 +16,23 @@ Functionally similar to: """# from pysnmp.hlapi import * -errorIndication, errorStatus, errorIndex, varBinds = next( - getCmd(SnmpEngine(), - CommunityData('public', mpModel=0), - UdpTransportTarget(('demo.snmplabs.com', 161)), - ContextData(), - ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0))) +iterator = getCmd( + SnmpEngine(), + CommunityData('public', mpModel=0), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ContextData(), + ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)) ) +errorIndication, errorStatus, errorIndex, varBinds = next(iterator) + if errorIndication: print(errorIndication) + elif 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])) diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/v2c-get.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/v2c-get.py index 606bab5b..d7676e32 100644 --- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/v2c-get.py +++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/v2c-get.py @@ -16,20 +16,24 @@ Functionally similar to: """# from pysnmp.hlapi import * -errorIndication, errorStatus, errorIndex, varBinds = next( - 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'))) +iterator = 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')) ) +errorIndication, errorStatus, errorIndex, varBinds = next(iterator) + if errorIndication: print(errorIndication) + elif 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])) diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/v2c-getbulk.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/v2c-getbulk.py index 47715195..15f684f5 100644 --- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/v2c-getbulk.py +++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/v2c-getbulk.py @@ -18,25 +18,28 @@ Functionally similar to: """# 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): +iterator = 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 iterator: if errorIndication: print(errorIndication) break + elif 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])) diff --git a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/waive-mib-lookup.py b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/waive-mib-lookup.py index f44d160b..c22d7b19 100644 --- a/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/waive-mib-lookup.py +++ b/examples/hlapi/v3arch/asyncore/sync/manager/cmdgen/waive-mib-lookup.py @@ -20,23 +20,26 @@ 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): +iterator = 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 iterator: if errorIndication: print(errorIndication) break + elif 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])) |