diff options
Diffstat (limited to 'examples/v3arch/asyncore/manager')
22 files changed, 142 insertions, 157 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 eb1900c2..1f3fdaf2 100644 --- a/examples/v3arch/asyncore/manager/cmdgen/custom-contextengineid-and-contextname.py +++ b/examples/v3arch/asyncore/manager/cmdgen/custom-contextengineid-and-contextname.py @@ -53,6 +53,7 @@ config.addTargetAddr( 'my-creds' ) + # Error/response receiver # noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal def cbFun(snmpEngine, sendRequestHandle, errorIndication, @@ -60,15 +61,13 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication, 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 oid, val in varBinds: print('%s = %s' % (oid.prettyPrint(), val.prettyPrint())) + # Prepare and send a request message, pass custom ContextEngineId & ContextName cmdgen.GetCommandGenerator().sendVarBinds( snmpEngine, @@ -77,7 +76,7 @@ cmdgen.GetCommandGenerator().sendVarBinds( rfc1902.OctetString(hexValue='80004fb805636c6f75644dab22cc'), # contextName rfc1902.OctetString('da761cfc8c94d3aceef4f60f049105ba'), - [ ((1,3,6,1,2,1,1,1,0), None) ], + [((1, 3, 6, 1, 2, 1, 1, 1, 0), None)], cbFun ) 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 1e49ffef..c30ff4c1 100644 --- a/examples/v3arch/asyncore/manager/cmdgen/custom-timeout-and-retries.py +++ b/examples/v3arch/asyncore/manager/cmdgen/custom-timeout-and-retries.py @@ -51,6 +51,7 @@ config.addTargetAddr( retryCount=5 ) + # Error/response receiver # noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal def cbFun(snmpEngine, sendRequestHandle, errorIndication, @@ -58,21 +59,19 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication, 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 oid, val in varBinds: print('%s = %s' % (oid.prettyPrint(), val.prettyPrint())) + # Prepare and send a request message cmdgen.GetCommandGenerator().sendVarBinds( snmpEngine, 'my-router', - None, '', # contextEngineId, contextName - [ ((1,3,6,1,2,1,1,1,0), None) ], + None, '', # contextEngineId, contextName + [((1, 3, 6, 1, 2, 1, 1, 1, 0), None)], cbFun ) 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 916537da..45460c92 100644 --- a/examples/v3arch/asyncore/manager/cmdgen/fetch-variables-over-ipv6.py +++ b/examples/v3arch/asyncore/manager/cmdgen/fetch-variables-over-ipv6.py @@ -50,6 +50,7 @@ config.addTargetAddr( 'my-creds' ) + # Error/response receiver # noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal def cbFun(snmpEngine, sendRequestHandle, errorIndication, @@ -58,24 +59,22 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication, print(errorIndication) return if errorStatus: - print('%s at %s' % ( - errorStatus.prettyPrint(), - errorIndex and varBindTable[-1][int(errorIndex)-1][0] or '?' - ) - ) + 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 + return True # signal dispatcher to continue + # Prepare initial request to be sent cmdgen.NextCommandGenerator().sendVarBinds( snmpEngine, 'my-router', None, '', # contextEngineId, contextName - [ ((1,3,6,1,2,1,1), None), - ((1,3,6,1,4,1,1), None) ], + [((1, 3, 6, 1, 2, 1, 1), None), + ((1, 3, 6, 1, 4, 1, 1), None)], cbFun ) 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 516951f8..8c4bf3dd 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 @@ -52,6 +52,7 @@ config.addTargetAddr( 'my-creds' ) + # Error/response receiver # noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal def cbFun(snmpEngine, sendRequesthandle, errorIndication, @@ -60,25 +61,23 @@ def cbFun(snmpEngine, sendRequesthandle, errorIndication, print(errorIndication) return # stop on error if errorStatus: - print('%s at %s' % ( - errorStatus.prettyPrint(), - errorIndex and varBindTable[-1][int(errorIndex)-1][0] or '?' - ) - ) + 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 + return True # signal dispatcher to continue walking + # Prepare initial request to be sent cmdgen.BulkCommandGenerator().sendVarBinds( snmpEngine, 'my-router', None, '', # contextEngineId, contextName - 0, 25, # non-repeaters, max-repetitions - ( ((1,3,6,1,2,1,1), None), - ((1,3,6,1,4,1,1), None) ), + 0, 25, # non-repeaters, max-repetitions + (((1, 3, 6, 1, 2, 1, 1), None), + ((1, 3, 6, 1, 4, 1, 1), None)), cbFun ) 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 2cd37cda..29c480c1 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 @@ -49,6 +49,7 @@ config.addTargetAddr( 'my-creds' ) + # Error/response receiver # noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal def cbFun(snmpEngine, sendRequesthandle, errorIndication, @@ -57,25 +58,23 @@ def cbFun(snmpEngine, sendRequesthandle, errorIndication, print(errorIndication) return # stop on error if errorStatus: - print('%s at %s' % ( - errorStatus.prettyPrint(), - errorIndex and varBindTable[-1][int(errorIndex)-1][0] or '?' - ) - ) + 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 + return True # signal dispatcher to continue walking + # Prepare initial request to be sent cmdgen.BulkCommandGenerator().sendVarBinds( snmpEngine, 'my-router', None, '', # contextEngineId, contextName - 0, 25, # non-repeaters, max-repetitions - [ ((1,3,6,1,2,1,1), None), - ((1,3,6,1,4,1,1), None) ], + 0, 25, # non-repeaters, max-repetitions + [((1, 3, 6, 1, 2, 1, 1), None), + ((1, 3, 6, 1, 4, 1, 1), None)], cbFun ) 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 f4667bef..9caf6a89 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 @@ -27,7 +27,7 @@ snmpEngine = engine.SnmpEngine() # This call will fail if PySMI is not present on the system compiler.addMibCompiler(snmpEngine.getMibBuilder()) # ... alternatively, this call will not complain on missing PySMI -#compiler.addMibCompiler(snmpEngine.getMibBuilder(), ifAvailable=True) +# compiler.addMibCompiler(snmpEngine.getMibBuilder(), ifAvailable=True) # Used for MIB objects resolution mibViewController = view.MibViewController(snmpEngine.getMibBuilder()) @@ -60,6 +60,7 @@ config.addTargetAddr( 'my-creds' ) + # Error/response receiver # noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal def cbFun(snmpEngine, sendRequestHandle, errorIndication, @@ -70,24 +71,23 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication, # 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 '?' - ) - ) + 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 + print(rfc1902.ObjectType(rfc1902.ObjectIdentity(varBind[0]), + varBind[1]).resolveWithMib(mibViewController).prettyPrint()) + return 1 # signal dispatcher to continue + # Prepare initial request to be sent cmdgen.NextCommandGenerator().sendVarBinds( snmpEngine, 'my-router', None, '', # contextEngineId, contextName - [ rfc1902.ObjectType(rfc1902.ObjectIdentity('iso.org.dod')).resolveWithMib(mibViewController), - rfc1902.ObjectType(rfc1902.ObjectIdentity('IF-MIB', 'ifMIB')).resolveWithMib(mibViewController) ], + [rfc1902.ObjectType(rfc1902.ObjectIdentity('iso.org.dod')).resolveWithMib(mibViewController), + rfc1902.ObjectType(rfc1902.ObjectIdentity('IF-MIB', 'ifMIB')).resolveWithMib(mibViewController)], cbFun ) 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 f2bcc43e..d90c35bb 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 @@ -49,6 +49,7 @@ config.addTargetAddr( 'my-creds' ) + # Error/response receiver # noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal def cbFun(snmpEngine, sendRequestHandle, errorIndication, @@ -59,24 +60,22 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication, # 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 '?' - ) - ) + 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 1 # signal dispatcher to continue + # Prepare initial request to be sent cmdgen.NextCommandGenerator().sendVarBinds( snmpEngine, 'my-router', None, '', # contextEngineId, contextName - [ ((1,3,6,1,2,1,1), None), - ((1,3,6,1,4,1,1), None) ], + [((1, 3, 6, 1, 2, 1, 1), None), + ((1, 3, 6, 1, 4, 1, 1), None)], cbFun ) diff --git a/examples/v3arch/asyncore/manager/cmdgen/observe-request-processing.py b/examples/v3arch/asyncore/manager/cmdgen/observe-request-processing.py index 86187923..6034624c 100644 --- a/examples/v3arch/asyncore/manager/cmdgen/observe-request-processing.py +++ b/examples/v3arch/asyncore/manager/cmdgen/observe-request-processing.py @@ -25,6 +25,7 @@ from pysnmp.entity.rfc3413 import cmdgen # Create SNMP engine instance snmpEngine = engine.SnmpEngine() + # Execution point observer setup # Register a callback to be invoked at specified execution point of @@ -41,8 +42,9 @@ def requestObserver(snmpEngine, execpoint, variables, cbCtx): print('* contextName: %s' % variables['contextName'].prettyPrint()) print('* PDU: %s' % variables['pdu'].prettyPrint()) + snmpEngine.observer.registerObserver( - requestObserver, + requestObserver, 'rfc3412.sendPdu', 'rfc3412.receiveMessage:response' ) @@ -76,6 +78,7 @@ config.addTargetAddr( 'my-creds' ) + # Error/response receiver # noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal def cbFun(snmpEngine, sendRequestHandle, errorIndication, @@ -83,21 +86,19 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication, 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 oid, val in varBinds: print('%s = %s' % (oid.prettyPrint(), val.prettyPrint())) + # Prepare and send a request message cmdgen.GetCommandGenerator().sendVarBinds( snmpEngine, 'my-router', None, '', # contextEngineId, contextName - [ ((1,3,6,1,2,1,1,1,0), None) ], + [((1, 3, 6, 1, 2, 1, 1, 1, 0), None)], cbFun ) diff --git a/examples/v3arch/asyncore/manager/cmdgen/pull-subtree.py b/examples/v3arch/asyncore/manager/cmdgen/pull-subtree.py index 36e461fb..cbaa1d0b 100644 --- a/examples/v3arch/asyncore/manager/cmdgen/pull-subtree.py +++ b/examples/v3arch/asyncore/manager/cmdgen/pull-subtree.py @@ -52,6 +52,7 @@ config.addTargetAddr( 'my-creds' ) + # Error/response receiver # noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal def cbFun(snmpEngine, sendRequestHandle, errorIndication, @@ -60,26 +61,24 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication, print(errorIndication) return if errorStatus: - print('%s at %s' % ( - errorStatus.prettyPrint(), - errorIndex and varBindTable[-1][int(errorIndex)-1][0] or '?' - ) - ) + 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: if initialOID.isPrefixOf(oid): print('%s = %s' % (oid.prettyPrint(), val.prettyPrint())) else: - return False # signal dispatcher to stop - return True # signal dispatcher to continue + return False # signal dispatcher to stop + return True # signal dispatcher to continue + # Prepare initial request to be sent cmdgen.NextCommandGenerator().sendVarBinds( snmpEngine, 'my-router', None, '', # contextEngineId, contextName - [ (initialOID, None) ], + [(initialOID, None)], cbFun ) 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 27acf769..2d6805fa 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 @@ -50,6 +50,7 @@ config.addTargetAddr( 'my-creds' ) + # Error/response receiver # noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal def cbFun(snmpEngine, sendRequestHandle, errorIndication, @@ -58,24 +59,22 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication, print(errorIndication) return if errorStatus: - print('%s at %s' % ( - errorStatus.prettyPrint(), - errorIndex and varBindTable[-1][int(errorIndex)-1][0] or '?' - ) - ) + 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 1 # signal dispatcher to continue + # Prepare initial request to be sent cmdgen.NextCommandGenerator().sendVarBinds( snmpEngine, 'my-router', None, '', # contextEngineId, contextName - [ ((1,3,6,1,2,1,1), None), - ((1,3,6,1,2,1,11), None) ], + [((1, 3, 6, 1, 2, 1, 1), None), + ((1, 3, 6, 1, 2, 1, 11), None)], cbFun ) 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 28095a76..25a33fd0 100644 --- a/examples/v3arch/asyncore/manager/cmdgen/set-multiple-scalar-values.py +++ b/examples/v3arch/asyncore/manager/cmdgen/set-multiple-scalar-values.py @@ -49,6 +49,7 @@ config.addTargetAddr( 'my-creds' ) + # Error/response receiver # noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal def cbFun(snmpEngine, sendRequestHandle, errorIndication, @@ -58,22 +59,20 @@ def cbFun(snmpEngine, sendRequestHandle, 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 '?' - ) - ) + 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())) + # Prepare and send a request message cmdgen.SetCommandGenerator().sendVarBinds( snmpEngine, 'my-router', None, '', # contextEngineId, contextName - [ ((1,3,6,1,2,1,1,9,1,3,1), rfc1902.OctetString('my value')), - ((1,3,6,1,2,1,1,9,1,4,1), rfc1902.TimeTicks(123)) ], + [((1, 3, 6, 1, 2, 1, 1, 9, 1, 3, 1), rfc1902.OctetString('my value')), + ((1, 3, 6, 1, 2, 1, 1, 9, 1, 4, 1), rfc1902.TimeTicks(123))], cbFun ) diff --git a/examples/v3arch/asyncore/manager/cmdgen/spoof-source-address.py b/examples/v3arch/asyncore/manager/cmdgen/spoof-source-address.py index 953f80e6..229ffdab 100644 --- a/examples/v3arch/asyncore/manager/cmdgen/spoof-source-address.py +++ b/examples/v3arch/asyncore/manager/cmdgen/spoof-source-address.py @@ -70,6 +70,7 @@ config.addTargetAddr( sourceAddress=('1.2.3.4', 0) ) + # Error/response receiver # noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal def cbFun(snmpEngine, sendRequestHandle, errorIndication, @@ -79,21 +80,19 @@ def cbFun(snmpEngine, sendRequestHandle, 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 '?' - ) - ) + 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())) + # Prepare and send a request message cmdgen.GetCommandGenerator().sendVarBinds( snmpEngine, 'my-router', None, '', # contextEngineId, contextName - [ ((1,3,6,1,2,1,1,1,0), None) ], + [((1, 3, 6, 1, 2, 1, 1, 1, 0), None)], cbFun ) diff --git a/examples/v3arch/asyncore/manager/cmdgen/usm-sha-aes128.py b/examples/v3arch/asyncore/manager/cmdgen/usm-sha-aes128.py index 58154ba1..49b20831 100644 --- a/examples/v3arch/asyncore/manager/cmdgen/usm-sha-aes128.py +++ b/examples/v3arch/asyncore/manager/cmdgen/usm-sha-aes128.py @@ -49,6 +49,7 @@ config.addTargetAddr( 'my-creds' ) + # Error/response receiver # noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal def cbFun(snmpEngine, sendRequestHandle, errorIndication, @@ -56,21 +57,19 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication, 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 oid, val in varBinds: print('%s = %s' % (oid.prettyPrint(), val.prettyPrint())) + # Prepare and send a request message cmdgen.GetCommandGenerator().sendVarBinds( snmpEngine, 'my-router', None, '', # contextEngineId, contextName - [ ((1,3,6,1,2,1,1,1,0), None) ], + [((1, 3, 6, 1, 2, 1, 1, 1, 0), None)], cbFun ) diff --git a/examples/v3arch/asyncore/manager/cmdgen/usm-sha-none.py b/examples/v3arch/asyncore/manager/cmdgen/usm-sha-none.py index 45692e4c..807822bf 100644 --- a/examples/v3arch/asyncore/manager/cmdgen/usm-sha-none.py +++ b/examples/v3arch/asyncore/manager/cmdgen/usm-sha-none.py @@ -50,6 +50,7 @@ config.addTargetAddr( 'my-creds' ) + # Error/response receiver # noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal def cbFun(snmpEngine, sendRequestHandle, errorIndication, @@ -57,21 +58,19 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication, 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 oid, val in varBinds: print('%s = %s' % (oid.prettyPrint(), val.prettyPrint())) + # Prepare and send a request message cmdgen.SetCommandGenerator().sendVarBinds( snmpEngine, 'my-router', None, '', # contextEngineId, contextName - [ ((1,3,6,1,2,1,1,9,1,3,1), rfc1902.OctetString('my new value')) ], + [((1, 3, 6, 1, 2, 1, 1, 9, 1, 3, 1), rfc1902.OctetString('my new value'))], cbFun ) diff --git a/examples/v3arch/asyncore/manager/cmdgen/v1-get.py b/examples/v3arch/asyncore/manager/cmdgen/v1-get.py index 9e9019cd..88078331 100644 --- a/examples/v3arch/asyncore/manager/cmdgen/v1-get.py +++ b/examples/v3arch/asyncore/manager/cmdgen/v1-get.py @@ -46,6 +46,7 @@ config.addTargetAddr( 'my-creds' ) + # Error/response receiver # noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal def cbFun(snmpEngine, sendRequestHandle, errorIndication, @@ -55,21 +56,19 @@ def cbFun(snmpEngine, sendRequestHandle, 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 '?' - ) - ) + 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())) + # Prepare and send a request message cmdgen.GetCommandGenerator().sendVarBinds( snmpEngine, 'my-router', None, '', # contextEngineId, contextName - [ ((1,3,6,1,2,1,1,1,0), None) ], + [((1, 3, 6, 1, 2, 1, 1, 1, 0), None)], cbFun ) diff --git a/examples/v3arch/asyncore/manager/cmdgen/v2c-set.py b/examples/v3arch/asyncore/manager/cmdgen/v2c-set.py index 7936f174..8a084b20 100644 --- a/examples/v3arch/asyncore/manager/cmdgen/v2c-set.py +++ b/examples/v3arch/asyncore/manager/cmdgen/v2c-set.py @@ -48,6 +48,7 @@ config.addTargetAddr( 'my-creds' ) + # Error/response receiver # noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal def cbFun(snmpEngine, sendRequestHandle, errorIndication, @@ -55,21 +56,19 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication, 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 oid, val in varBinds: print('%s = %s' % (oid.prettyPrint(), val.prettyPrint())) + # Prepare and send a request message cmdgen.SetCommandGenerator().sendVarBinds( snmpEngine, 'my-router', None, '', # contextEngineId, contextName - [ ((1,3,6,1,2,1,1,9,1,4,1), rfc1902.TimeTicks(123)) ], + [((1, 3, 6, 1, 2, 1, 1, 9, 1, 4, 1), rfc1902.TimeTicks(123))], cbFun ) diff --git a/examples/v3arch/asyncore/manager/ntfrcv/determine-peer-network-address.py b/examples/v3arch/asyncore/manager/ntfrcv/determine-peer-network-address.py index 87880e41..d7d9b6d3 100644 --- a/examples/v3arch/asyncore/manager/ntfrcv/determine-peer-network-address.py +++ b/examples/v3arch/asyncore/manager/ntfrcv/determine-peer-network-address.py @@ -38,6 +38,7 @@ config.addTransport( # SecurityName <-> CommunityName mapping config.addV1System(snmpEngine, 'my-area', 'public') + # Callback function for receiving notifications # noinspection PyUnusedLocal,PyUnusedLocal def cbFun(snmpEngine, stateReference, contextEngineId, contextName, @@ -48,19 +49,17 @@ def cbFun(snmpEngine, stateReference, contextEngineId, contextName, ) # ... and use inner SNMP engine data to figure out peer address - print('Notification from %s, ContextEngineId "%s", ContextName "%s"' % ( - '@'.join([str(x) for x in execContext['transportAddress']]), - contextEngineId.prettyPrint(), - contextName.prettyPrint() - ) - ) + print('Notification from %s, ContextEngineId "%s", ContextName "%s"' % ('@'.join([str(x) for x in execContext['transportAddress']]), + contextEngineId.prettyPrint(), + contextName.prettyPrint())) for name, val in varBinds: print('%s = %s' % (name.prettyPrint(), val.prettyPrint())) + # Register SNMP Application at the SNMP engine ntfrcv.NotificationReceiver(snmpEngine, cbFun) -snmpEngine.transportDispatcher.jobStarted(1) # this job would never finish +snmpEngine.transportDispatcher.jobStarted(1) # this job would never finish # Run I/O dispatcher which would receive queries and send confirmations try: diff --git a/examples/v3arch/asyncore/manager/ntfrcv/multiple-network-interfaces.py b/examples/v3arch/asyncore/manager/ntfrcv/multiple-network-interfaces.py index 63c86926..30b41706 100644 --- a/examples/v3arch/asyncore/manager/ntfrcv/multiple-network-interfaces.py +++ b/examples/v3arch/asyncore/manager/ntfrcv/multiple-network-interfaces.py @@ -46,22 +46,21 @@ config.addTransport( # SecurityName <-> CommunityName mapping config.addV1System(snmpEngine, 'my-area', 'public') + # Callback function for receiving notifications # noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal def cbFun(snmpEngine, stateReference, contextEngineId, contextName, varBinds, cbCtx): - print('Notification from ContextEngineId "%s", ContextName "%s"' % ( - contextEngineId.prettyPrint(), - contextName.prettyPrint() - ) - ) + print('Notification from ContextEngineId "%s", ContextName "%s"' % (contextEngineId.prettyPrint(), + contextName.prettyPrint())) for name, val in varBinds: print('%s = %s' % (name.prettyPrint(), val.prettyPrint())) + # Register SNMP Application at the SNMP engine ntfrcv.NotificationReceiver(snmpEngine, cbFun) -snmpEngine.transportDispatcher.jobStarted(1) # this job would never finish +snmpEngine.transportDispatcher.jobStarted(1) # this job would never finish # Run I/O dispatcher which would receive queries and send confirmations try: diff --git a/examples/v3arch/asyncore/manager/ntfrcv/multiple-network-transports.py b/examples/v3arch/asyncore/manager/ntfrcv/multiple-network-transports.py index c0e2eeae..994c73dd 100644 --- a/examples/v3arch/asyncore/manager/ntfrcv/multiple-network-transports.py +++ b/examples/v3arch/asyncore/manager/ntfrcv/multiple-network-transports.py @@ -40,29 +40,28 @@ config.addTransport( snmpEngine, udp6.domainName, udp6.Udp6Transport().openServerMode(('::1', 162)) - ) +) # SNMPv1/2c setup # SecurityName <-> CommunityName mapping config.addV1System(snmpEngine, 'my-area', 'public') + # Callback function for receiving notifications # noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal def cbFun(snmpEngine, stateReference, contextEngineId, contextName, varBinds, cbCtx): - print('Notification from ContextEngineId "%s", ContextName "%s"' % ( - contextEngineId.prettyPrint(), - contextName.prettyPrint() - ) - ) + print('Notification from ContextEngineId "%s", ContextName "%s"' % (contextEngineId.prettyPrint(), + contextName.prettyPrint())) for name, val in varBinds: print('%s = %s' % (name.prettyPrint(), val.prettyPrint())) + # Register SNMP Application at the SNMP engine ntfrcv.NotificationReceiver(snmpEngine, cbFun) -snmpEngine.transportDispatcher.jobStarted(1) # this job would never finish +snmpEngine.transportDispatcher.jobStarted(1) # this job would never finish # Run I/O dispatcher which would receive queries and send confirmations try: diff --git a/examples/v3arch/asyncore/manager/ntfrcv/multiple-usm-users.py b/examples/v3arch/asyncore/manager/ntfrcv/multiple-usm-users.py index 1a0ae8bd..50aaee26 100644 --- a/examples/v3arch/asyncore/manager/ntfrcv/multiple-usm-users.py +++ b/examples/v3arch/asyncore/manager/ntfrcv/multiple-usm-users.py @@ -87,22 +87,21 @@ config.addV3User( securityEngineId=v2c.OctetString(hexValue='8000000001020304') ) + # Callback function for receiving notifications # noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal def cbFun(snmpEngine, stateReference, contextEngineId, contextName, varBinds, cbCtx): - print('Notification from ContextEngineId "%s", ContextName "%s"' % ( - contextEngineId.prettyPrint(), - contextName.prettyPrint() - ) - ) + print('Notification from ContextEngineId "%s", ContextName "%s"' % (contextEngineId.prettyPrint(), + contextName.prettyPrint())) for name, val in varBinds: print('%s = %s' % (name.prettyPrint(), val.prettyPrint())) + # Register SNMP Application at the SNMP engine ntfrcv.NotificationReceiver(snmpEngine, cbFun) -snmpEngine.transportDispatcher.jobStarted(1) # this job would never finish +snmpEngine.transportDispatcher.jobStarted(1) # this job would never finish # Run I/O dispatcher which would receive queries and send confirmations try: diff --git a/examples/v3arch/asyncore/manager/ntfrcv/observe-request-processing.py b/examples/v3arch/asyncore/manager/ntfrcv/observe-request-processing.py index 6dd9b305..9f3a2c40 100644 --- a/examples/v3arch/asyncore/manager/ntfrcv/observe-request-processing.py +++ b/examples/v3arch/asyncore/manager/ntfrcv/observe-request-processing.py @@ -27,6 +27,7 @@ from pysnmp.entity.rfc3413 import ntfrcv # to socket transport dispatcher snmpEngine = engine.SnmpEngine() + # Execution point observer setup # Register a callback to be invoked at specified execution point of @@ -43,6 +44,7 @@ def requestObserver(snmpEngine, execpoint, variables, cbCtx): print('* contextName: %s' % variables['contextName'].prettyPrint()) print('* PDU: %s' % variables['pdu'].prettyPrint()) + snmpEngine.observer.registerObserver( requestObserver, 'rfc3412.receiveMessage:request', @@ -63,29 +65,28 @@ config.addTransport( snmpEngine, udp6.domainName, udp6.Udp6Transport().openServerMode(('::1', 162)) - ) +) # SNMPv1/2c setup # SecurityName <-> CommunityName mapping config.addV1System(snmpEngine, 'my-area', 'public') + # Callback function for receiving notifications # noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal def cbFun(snmpEngine, stateReference, contextEngineId, contextName, varBinds, cbCtx): - print('Notification from ContextEngineId "%s", ContextName "%s"' % ( - contextEngineId.prettyPrint(), - contextName.prettyPrint() - ) - ) + print('Notification from ContextEngineId "%s", ContextName "%s"' % (contextEngineId.prettyPrint(), + contextName.prettyPrint())) for name, val in varBinds: print('%s = %s' % (name.prettyPrint(), val.prettyPrint())) + # Register SNMP Application at the SNMP engine ntfrcv.NotificationReceiver(snmpEngine, cbFun) -snmpEngine.transportDispatcher.jobStarted(1) # this job would never finish +snmpEngine.transportDispatcher.jobStarted(1) # this job would never finish # Run I/O dispatcher which would receive queries and send confirmations try: diff --git a/examples/v3arch/asyncore/manager/ntfrcv/regexp-community-name.py b/examples/v3arch/asyncore/manager/ntfrcv/regexp-community-name.py index 0e808ec9..769aa2f5 100644 --- a/examples/v3arch/asyncore/manager/ntfrcv/regexp-community-name.py +++ b/examples/v3arch/asyncore/manager/ntfrcv/regexp-community-name.py @@ -35,7 +35,8 @@ import re # to socket transport dispatcher snmpEngine = engine.SnmpEngine() -# Register a callback to be invoked at specified execution point of + +# Register a callback to be invoked at specified execution point of # SNMP Engine and passed local variables at execution point's local scope. # If at this execution point passed variables are modified, their new # values will be propagated back and used by SNMP Engine for securityName @@ -46,6 +47,7 @@ def requestObserver(snmpEngine, execpoint, variables, cbCtx): print('Rewriting communityName \'%s\' from %s into \'public\'' % (variables['communityName'], ':'.join([str(x) for x in variables['transportInformation'][1]]))) variables['communityName'] = variables['communityName'].clone('public') + snmpEngine.observer.registerObserver( requestObserver, 'rfc2576.processIncomingMsg:writable' @@ -65,22 +67,21 @@ config.addTransport( # SecurityName <-> CommunityName mapping config.addV1System(snmpEngine, 'my-area', 'public') + # Callback function for receiving notifications # noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal def cbFun(snmpEngine, stateReference, contextEngineId, contextName, varBinds, cbCtx): - print('Notification from ContextEngineId "%s", ContextName "%s"' % ( - contextEngineId.prettyPrint(), - contextName.prettyPrint() - ) - ) + print('Notification from ContextEngineId "%s", ContextName "%s"' % (contextEngineId.prettyPrint(), + contextName.prettyPrint())) for name, val in varBinds: print('%s = %s' % (name.prettyPrint(), val.prettyPrint())) + # Register SNMP Application at the SNMP engine ntfrcv.NotificationReceiver(snmpEngine, cbFun) -snmpEngine.transportDispatcher.jobStarted(1) # this job would never finish +snmpEngine.transportDispatcher.jobStarted(1) # this job would never finish # Run I/O dispatcher which would receive queries and send confirmations try: |