diff options
Diffstat (limited to 'examples/v3arch/asyncore/manager/cmdgen')
16 files changed, 65 insertions, 5 deletions
diff --git a/examples/v3arch/asyncore/manager/cmdgen/custom-contextengineid-and-contextname.py b/examples/v3arch/asyncore/manager/cmdgen/custom-contextengineid-and-contextname.py index 2dc2ee8b..4ea68110 100644 --- a/examples/v3arch/asyncore/manager/cmdgen/custom-contextengineid-and-contextname.py +++ b/examples/v3arch/asyncore/manager/cmdgen/custom-contextengineid-and-contextname.py @@ -34,6 +34,7 @@ config.addV3User( snmpEngine, 'usr-md5-none', config.USM_AUTH_HMAC96_MD5, 'authkey1' ) + config.addTargetParams(snmpEngine, 'my-creds', 'usr-md5-none', 'authNoPriv') # @@ -47,6 +48,7 @@ config.addTransport( udp.DOMAIN_NAME, udp.UdpSocketTransport().openClientMode() ) + config.addTargetAddr( snmpEngine, 'my-router', udp.DOMAIN_NAME, ('104.236.166.95', 161), @@ -60,9 +62,11 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication, errorStatus, errorIndex, varBinds, cbCtx): if errorIndication: print(errorIndication) + elif errorStatus: print('%s at %s' % (errorStatus.prettyPrint(), errorIndex and varBinds[int(errorIndex) - 1][0] or '?')) + else: for oid, val in varBinds: print('%s = %s' % (oid.prettyPrint(), val.prettyPrint())) diff --git a/examples/v3arch/asyncore/manager/cmdgen/custom-timeout-and-retries.py b/examples/v3arch/asyncore/manager/cmdgen/custom-timeout-and-retries.py index 45b8c7a6..b7e137b3 100644 --- a/examples/v3arch/asyncore/manager/cmdgen/custom-timeout-and-retries.py +++ b/examples/v3arch/asyncore/manager/cmdgen/custom-timeout-and-retries.py @@ -43,6 +43,7 @@ config.addTransport( udp.DOMAIN_NAME, udp.UdpSocketTransport().openClientMode() ) + config.addTargetAddr( snmpEngine, 'my-router', udp.DOMAIN_NAME, ('104.236.166.95', 161), @@ -58,9 +59,11 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication, errorStatus, errorIndex, varBinds, cbCtx): if errorIndication: print(errorIndication) + elif errorStatus: print('%s at %s' % (errorStatus.prettyPrint(), errorIndex and varBinds[int(errorIndex) - 1][0] or '?')) + else: for oid, val in varBinds: print('%s = %s' % (oid.prettyPrint(), val.prettyPrint())) diff --git a/examples/v3arch/asyncore/manager/cmdgen/fetch-variables-over-ipv6.py b/examples/v3arch/asyncore/manager/cmdgen/fetch-variables-over-ipv6.py index 0a156d0f..de85e3db 100644 --- a/examples/v3arch/asyncore/manager/cmdgen/fetch-variables-over-ipv6.py +++ b/examples/v3arch/asyncore/manager/cmdgen/fetch-variables-over-ipv6.py @@ -44,6 +44,7 @@ config.addTransport( udp6.DOMAIN_NAME, udp6.Udp6SocketTransport().openClientMode() ) + config.addTargetAddr( snmpEngine, 'my-router', udp6.DOMAIN_NAME, ('::1', 161), @@ -58,13 +59,17 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication, if errorIndication: print(errorIndication) return + if errorStatus: print('%s at %s' % (errorStatus.prettyPrint(), errorIndex and varBindTable[-1][int(errorIndex) - 1][0] or '?')) return # stop on error + for varBindRow in varBindTable: + for oid, val in varBindRow: print('%s = %s' % (oid.prettyPrint(), val.prettyPrint())) + return True # signal dispatcher to continue diff --git a/examples/v3arch/asyncore/manager/cmdgen/getbulk-fetch-scalar-and-table-variables.py b/examples/v3arch/asyncore/manager/cmdgen/getbulk-fetch-scalar-and-table-variables.py index 82e42879..499514f3 100644 --- a/examples/v3arch/asyncore/manager/cmdgen/getbulk-fetch-scalar-and-table-variables.py +++ b/examples/v3arch/asyncore/manager/cmdgen/getbulk-fetch-scalar-and-table-variables.py @@ -46,6 +46,7 @@ config.addTransport( udp.DOMAIN_NAME, udp.UdpSocketTransport().openClientMode() ) + config.addTargetAddr( snmpEngine, 'my-router', udp.DOMAIN_NAME, ('104.236.166.95', 161), @@ -60,13 +61,16 @@ def cbFun(snmpEngine, sendRequesthandle, errorIndication, if errorIndication: print(errorIndication) return # stop on error + if errorStatus: print('%s at %s' % (errorStatus.prettyPrint(), errorIndex and varBindTable[-1][int(errorIndex) - 1][0] or '?')) return # stop on error + for varBindRow in varBindTable: for oid, val in varBindRow: print('%s = %s' % (oid.prettyPrint(), val.prettyPrint())) + return True # signal dispatcher to continue walking diff --git a/examples/v3arch/asyncore/manager/cmdgen/getbulk-multiple-oids-to-eom.py b/examples/v3arch/asyncore/manager/cmdgen/getbulk-multiple-oids-to-eom.py index 125e3a72..98a4c42b 100644 --- a/examples/v3arch/asyncore/manager/cmdgen/getbulk-multiple-oids-to-eom.py +++ b/examples/v3arch/asyncore/manager/cmdgen/getbulk-multiple-oids-to-eom.py @@ -43,6 +43,7 @@ config.addTransport( udp.DOMAIN_NAME, udp.UdpSocketTransport().openClientMode() ) + config.addTargetAddr( snmpEngine, 'my-router', udp.DOMAIN_NAME, ('104.236.166.95', 161), @@ -57,13 +58,16 @@ def cbFun(snmpEngine, sendRequesthandle, errorIndication, if errorIndication: print(errorIndication) return # stop on error + if errorStatus: print('%s at %s' % (errorStatus.prettyPrint(), errorIndex and varBindTable[-1][int(errorIndex) - 1][0] or '?')) return # stop on error + for varBindRow in varBindTable: for oid, val in varBindRow: print('%s = %s' % (oid.prettyPrint(), val.prettyPrint())) + return True # signal dispatcher to continue walking diff --git a/examples/v3arch/asyncore/manager/cmdgen/getnext-multiple-oids-and-resolve-with-mib.py b/examples/v3arch/asyncore/manager/cmdgen/getnext-multiple-oids-and-resolve-with-mib.py index f01efec7..8fed28c1 100644 --- a/examples/v3arch/asyncore/manager/cmdgen/getnext-multiple-oids-and-resolve-with-mib.py +++ b/examples/v3arch/asyncore/manager/cmdgen/getnext-multiple-oids-and-resolve-with-mib.py @@ -54,6 +54,7 @@ config.addTransport( udp.DOMAIN_NAME, udp.UdpSocketTransport().openClientMode() ) + config.addTargetAddr( snmpEngine, 'my-router', udp.DOMAIN_NAME, ('104.236.166.95', 161), @@ -68,17 +69,20 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication, if errorIndication: print(errorIndication) return + # SNMPv1 response may contain noSuchName error *and* SNMPv2c exception, # so we ignore noSuchName error here if errorStatus and errorStatus != 2: print('%s at %s' % (errorStatus.prettyPrint(), errorIndex and varBindTable[-1][int(errorIndex) - 1][0] or '?')) return # stop on error + for varBindRow in varBindTable: for varBind in varBindRow: print(rfc1902.ObjectType(rfc1902.ObjectIdentity(varBind[0]), varBind[1]).resolveWithMib(mibViewController).prettyPrint()) - return 1 # signal dispatcher to continue + + return True # signal dispatcher to continue # Prepare initial request to be sent diff --git a/examples/v3arch/asyncore/manager/cmdgen/getnext-multiple-oids-to-eom.py b/examples/v3arch/asyncore/manager/cmdgen/getnext-multiple-oids-to-eom.py index c984a899..64e4e19f 100644 --- a/examples/v3arch/asyncore/manager/cmdgen/getnext-multiple-oids-to-eom.py +++ b/examples/v3arch/asyncore/manager/cmdgen/getnext-multiple-oids-to-eom.py @@ -43,6 +43,7 @@ config.addTransport( udp.DOMAIN_NAME, udp.UdpSocketTransport().openClientMode() ) + config.addTargetAddr( snmpEngine, 'my-router', udp.DOMAIN_NAME, ('104.236.166.95', 161), @@ -57,16 +58,19 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication, if errorIndication: print(errorIndication) return + # SNMPv1 response may contain noSuchName error *and* SNMPv2c exception, # so we ignore noSuchName error here if errorStatus and errorStatus != 2: print('%s at %s' % (errorStatus.prettyPrint(), errorIndex and varBindTable[-1][int(errorIndex) - 1][0] or '?')) return # stop on error + for varBindRow in varBindTable: for oid, val in varBindRow: print('%s = %s' % (oid.prettyPrint(), val.prettyPrint())) - return 1 # signal dispatcher to continue + + return True # signal dispatcher to continue # Prepare initial request to be sent diff --git a/examples/v3arch/asyncore/manager/cmdgen/observe-request-processing.py b/examples/v3arch/asyncore/manager/cmdgen/observe-request-processing.py index fccb1483..3a8b4f5a 100644 --- a/examples/v3arch/asyncore/manager/cmdgen/observe-request-processing.py +++ b/examples/v3arch/asyncore/manager/cmdgen/observe-request-processing.py @@ -59,6 +59,7 @@ config.addV3User( config.USM_AUTH_HMAC96_SHA, 'authkey1', config.USM_PRIV_CFB128_AES, 'privkey1' ) + config.addTargetParams(snmpEngine, 'my-creds', 'usr-sha-aes', 'authPriv') # @@ -72,6 +73,7 @@ config.addTransport( udp.DOMAIN_NAME, udp.UdpSocketTransport().openClientMode() ) + config.addTargetAddr( snmpEngine, 'my-router', udp.DOMAIN_NAME, ('104.236.166.95', 161), @@ -85,9 +87,11 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication, errorStatus, errorIndex, varBinds, cbCtx): if errorIndication: print(errorIndication) + elif errorStatus: print('%s at %s' % (errorStatus.prettyPrint(), errorIndex and varBinds[int(errorIndex) - 1][0] or '?')) + else: for oid, val in varBinds: print('%s = %s' % (oid.prettyPrint(), val.prettyPrint())) diff --git a/examples/v3arch/asyncore/manager/cmdgen/pull-subtree.py b/examples/v3arch/asyncore/manager/cmdgen/pull-subtree.py index b1eb9ace..4233356b 100644 --- a/examples/v3arch/asyncore/manager/cmdgen/pull-subtree.py +++ b/examples/v3arch/asyncore/manager/cmdgen/pull-subtree.py @@ -33,6 +33,7 @@ snmpEngine = engine.SnmpEngine() config.addV3User( snmpEngine, 'usr-none-none', ) + config.addTargetParams(snmpEngine, 'my-creds', 'usr-none-none', 'noAuthNoPriv') # @@ -46,6 +47,7 @@ config.addTransport( udp.DOMAIN_NAME, udp.UdpSocketTransport().openClientMode() ) + config.addTargetAddr( snmpEngine, 'my-router', udp.DOMAIN_NAME, ('104.236.166.95', 161), @@ -60,16 +62,20 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication, if errorIndication: print(errorIndication) return + if errorStatus: print('%s at %s' % (errorStatus.prettyPrint(), errorIndex and varBindTable[-1][int(errorIndex) - 1][0] or '?')) - return # stop on error + return False # stop on error + for varBindRow in varBindTable: for oid, val in varBindRow: if initialOID.isPrefixOf(oid): print('%s = %s' % (oid.prettyPrint(), val.prettyPrint())) + else: return False # signal dispatcher to stop + return True # signal dispatcher to continue diff --git a/examples/v3arch/asyncore/manager/cmdgen/send-packets-from-specific-interface.py b/examples/v3arch/asyncore/manager/cmdgen/send-packets-from-specific-interface.py index ed5ec19f..9342df3e 100644 --- a/examples/v3arch/asyncore/manager/cmdgen/send-packets-from-specific-interface.py +++ b/examples/v3arch/asyncore/manager/cmdgen/send-packets-from-specific-interface.py @@ -44,6 +44,7 @@ config.addTransport( udp.DOMAIN_NAME, udp.UdpSocketTransport().openClientMode(('0.0.0.0', 61024)) ) + config.addTargetAddr( snmpEngine, 'my-router', udp.DOMAIN_NAME, ('104.236.166.95', 161), @@ -57,15 +58,18 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication, errorStatus, errorIndex, varBindTable, cbCtx): if errorIndication: print(errorIndication) - return + return False + if errorStatus: print('%s at %s' % (errorStatus.prettyPrint(), errorIndex and varBindTable[-1][int(errorIndex) - 1][0] or '?')) return # stop on error + for varBindRow in varBindTable: for oid, val in varBindRow: print('%s = %s' % (oid.prettyPrint(), val.prettyPrint())) - return 1 # signal dispatcher to continue + + return True # signal dispatcher to continue # Prepare initial request to be sent diff --git a/examples/v3arch/asyncore/manager/cmdgen/set-multiple-scalar-values.py b/examples/v3arch/asyncore/manager/cmdgen/set-multiple-scalar-values.py index 173bdd91..c93e142b 100644 --- a/examples/v3arch/asyncore/manager/cmdgen/set-multiple-scalar-values.py +++ b/examples/v3arch/asyncore/manager/cmdgen/set-multiple-scalar-values.py @@ -43,6 +43,7 @@ config.addTransport( udp.DOMAIN_NAME, udp.UdpSocketTransport().openClientMode() ) + config.addTargetAddr( snmpEngine, 'my-router', udp.DOMAIN_NAME, ('104.236.166.95', 161), @@ -56,11 +57,13 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication, errorStatus, errorIndex, varBinds, cbCtx): if errorIndication: print(errorIndication) + # SNMPv1 response may contain noSuchName error *and* SNMPv2c exception, # so we ignore noSuchName error here elif errorStatus and errorStatus != 2: print('%s at %s' % (errorStatus.prettyPrint(), errorIndex and varBinds[int(errorIndex) - 1][0] or '?')) + else: for oid, val in varBinds: print('%s = %s' % (oid.prettyPrint(), val.prettyPrint())) diff --git a/examples/v3arch/asyncore/manager/cmdgen/spoof-source-address.py b/examples/v3arch/asyncore/manager/cmdgen/spoof-source-address.py index 10050e3f..da7878f2 100644 --- a/examples/v3arch/asyncore/manager/cmdgen/spoof-source-address.py +++ b/examples/v3arch/asyncore/manager/cmdgen/spoof-source-address.py @@ -77,11 +77,13 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication, errorStatus, errorIndex, varBinds, cbCtx): if errorIndication: print(errorIndication) + # SNMPv1 response may contain noSuchName error *and* SNMPv2c exception, # so we ignore noSuchName error here elif errorStatus and errorStatus != 2: print('%s at %s' % (errorStatus.prettyPrint(), errorIndex and varBinds[int(errorIndex) - 1][0] or '?')) + else: for oid, val in varBinds: print('%s = %s' % (oid.prettyPrint(), val.prettyPrint())) diff --git a/examples/v3arch/asyncore/manager/cmdgen/usm-sha-aes128.py b/examples/v3arch/asyncore/manager/cmdgen/usm-sha-aes128.py index d65a018f..7fb95ead 100644 --- a/examples/v3arch/asyncore/manager/cmdgen/usm-sha-aes128.py +++ b/examples/v3arch/asyncore/manager/cmdgen/usm-sha-aes128.py @@ -30,6 +30,7 @@ config.addV3User( config.USM_AUTH_HMAC96_SHA, 'authkey1', config.USM_PRIV_CFB128_AES, 'privkey1' ) + config.addTargetParams(snmpEngine, 'my-creds', 'usr-sha-aes', 'authPriv') # @@ -43,6 +44,7 @@ config.addTransport( udp.DOMAIN_NAME, udp.UdpSocketTransport().openClientMode() ) + config.addTargetAddr( snmpEngine, 'my-router', udp.DOMAIN_NAME, ('104.236.166.95', 161), @@ -56,9 +58,11 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication, errorStatus, errorIndex, varBinds, cbCtx): if errorIndication: print(errorIndication) + elif errorStatus: print('%s at %s' % (errorStatus.prettyPrint(), errorIndex and varBinds[int(errorIndex) - 1][0] or '?')) + else: for oid, val in varBinds: print('%s = %s' % (oid.prettyPrint(), val.prettyPrint())) diff --git a/examples/v3arch/asyncore/manager/cmdgen/usm-sha-none.py b/examples/v3arch/asyncore/manager/cmdgen/usm-sha-none.py index 43c5dade..2eba8949 100644 --- a/examples/v3arch/asyncore/manager/cmdgen/usm-sha-none.py +++ b/examples/v3arch/asyncore/manager/cmdgen/usm-sha-none.py @@ -44,6 +44,7 @@ config.addTransport( udp.DOMAIN_NAME, udp.UdpSocketTransport().openClientMode() ) + config.addTargetAddr( snmpEngine, 'my-router', udp.DOMAIN_NAME, ('104.236.166.95', 161), @@ -57,9 +58,11 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication, errorStatus, errorIndex, varBinds, cbCtx): if errorIndication: print(errorIndication) + elif errorStatus: print('%s at %s' % (errorStatus.prettyPrint(), errorIndex and varBinds[int(errorIndex) - 1][0] or '?')) + else: for oid, val in varBinds: print('%s = %s' % (oid.prettyPrint(), val.prettyPrint())) diff --git a/examples/v3arch/asyncore/manager/cmdgen/v1-get.py b/examples/v3arch/asyncore/manager/cmdgen/v1-get.py index 60d25f5e..20eab6c7 100644 --- a/examples/v3arch/asyncore/manager/cmdgen/v1-get.py +++ b/examples/v3arch/asyncore/manager/cmdgen/v1-get.py @@ -40,6 +40,7 @@ config.addTransport( udp.DOMAIN_NAME, udp.UdpSocketTransport().openClientMode() ) + config.addTargetAddr( snmpEngine, 'my-router', udp.DOMAIN_NAME, ('104.236.166.95', 161), @@ -53,11 +54,13 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication, errorStatus, errorIndex, varBinds, cbCtx): if errorIndication: print(errorIndication) + # SNMPv1 response may contain noSuchName error *and* SNMPv2c exception, # so we ignore noSuchName error here elif errorStatus and errorStatus != 2: print('%s at %s' % (errorStatus.prettyPrint(), errorIndex and varBinds[int(errorIndex) - 1][0] or '?')) + else: for oid, val in varBinds: print('%s = %s' % (oid.prettyPrint(), val.prettyPrint())) diff --git a/examples/v3arch/asyncore/manager/cmdgen/v2c-set.py b/examples/v3arch/asyncore/manager/cmdgen/v2c-set.py index 61657677..8e6a1168 100644 --- a/examples/v3arch/asyncore/manager/cmdgen/v2c-set.py +++ b/examples/v3arch/asyncore/manager/cmdgen/v2c-set.py @@ -42,6 +42,7 @@ config.addTransport( udp.DOMAIN_NAME, udp.UdpSocketTransport().openClientMode() ) + config.addTargetAddr( snmpEngine, 'my-router', udp.DOMAIN_NAME, ('104.236.166.95', 161), @@ -55,9 +56,11 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication, errorStatus, errorIndex, varBinds, cbCtx): if errorIndication: print(errorIndication) + elif errorStatus: print('%s at %s' % (errorStatus.prettyPrint(), errorIndex and varBinds[int(errorIndex) - 1][0] or '?')) + else: for oid, val in varBinds: print('%s = %s' % (oid.prettyPrint(), val.prettyPrint())) |