[pysnmp-users] Am I doing this right?
Brought to you by:
elie
From: Eric B. <br...@br...> - 2008-11-05 18:40:30
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> </head> <body bgcolor="#ffffff" text="#000000"> In order to get around some performance problems I recently rewrote some code to use an asynchronous trap mechanism rather than the synchronous version of the calls I'd been using. Now my trap recipient is getting two traps each time I try to send one. I don't know if I'm calling the dispatcher when I shouldn't be or what...<br> <br> I'll strip down the code here as much as I can without getting rid of anything important.<br> <br> <blockquote> <pre># Some globals so I don't have to create them over and over destinations = ( ("10.255.20.30", standardtrapport ), ( "10.255.20.60", standardtrapport ) ) transports = [ ntforg.UdpTransportTarget((host, port)) for host, port in destinations ] def sendTrap(trapOID, blah, blah, blah, some varbinds ): global OIDs, transports, timer, notifier, community # OIDs is a dict of OIDs, unimportant # transports is the above tuple of two trap destinations # timer is the last time.time() that I ran the dispatcher # notifier is a global instance of ntforg.NotificationOriginator() # community is duh try: varbinds = (blah, blah, blah, nothing important to the issue) # here I want to queue one trap for each destination for transport in transports: log( 3, 'sending to %s' % transport ) notifier.asyncSendNotification( community, transport, 'trap', (trapOID), varbinds) except: # Deleted exception handling as unimportant, # I log the traceback, then move on pass # This is my question, I queue up traps for 10 seconds, then # run the dispatcher. Is that correct? if time.time() - timer > 10: notifier.snmpEngine.transportDispatcher.runDispatcher() timer = time.time() </pre> </blockquote> The code actually runs great, except for the duplicate traps. If I only have one transport in the transports tuple, then the single transport gets one trap, if there are two transports, they each get two traps.<br> <br> Any advice is greatly appreciated.<br> <br> <br> </body> </html> |