diff options
Diffstat (limited to 'examples/v3arch/asyncore/manager/ntfrcv/regexp-community-name.py')
-rw-r--r-- | examples/v3arch/asyncore/manager/ntfrcv/regexp-community-name.py | 15 |
1 files changed, 8 insertions, 7 deletions
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: |