[pysnmp-users] pysnmp: oneliners
Brought to you by:
elie
From: Ashirvaad R. <ax...@gm...> - 2008-04-15 12:30:19
|
Hello I am new to python and SNMP. I am experiencing a little difficulty with pysnmp, and trawling through the documentation, source code, and mailing lists has not been able to help me. I hope someone can point me in the right direction with the information below: I am trying to use pysnmp to asynchronously poll a number of devices. It seemed easiest to do this using pysnmp.entity.rfc3413.oneliner: handle = cmdgen.AsynCommandGenerator().asyncGetCmd( authData, transportTarget, varNames, (handle_asyn_snmp_response, (self, context_id))) authData, transportTarget, varNames are correctly initialised before the call to asyncGetCmd(). handle_asyn_snmp_response is the name of the callback function. as the context data, i'm passing a reference to the calling object, and a custom specified id (a string which is used to identify the request sender). after the call to asyncGetCmd(), I store some data in a dictionary, using "handle" as the key, based on the assumption that every request/response is generated with a unique handle number. That is not exactly how it turns out. I send an SNMP NEXT request to each device: handle = cmdgen.AsynCommandGenerator().asyncNextCmd( authData, transportTarget, varNames, (handle_asyn_snmp_response, (self, context_id))) When a response is received (if it is not timed out and no error has occurred), I then send the same device an SNMP GET request, using an almost identical call: handle = cmdgen.AsynCommandGenerator().asyncGetCmd( authData, transportTarget, varNames, (handle_asyn_snmp_response, (self, context_id))) The problem is that this method always returns a handle ID of 1. Looking at the source has revealed that a new instance of the command generator is created for each call, and this is why the handle number is never incremented. One obvious way I managed to solve this problem was to extend the cmdgen.AsynCommandGenerator class and change things a little in there, that is by creating and reusing a single command generator object. That worked for the case where I send out only SNMP NEXT or only SNMP GET requests. But I am, within the same session, sending out both GET and NEXT requests, and the handles generated are not unique. Looking at the class hierarchy, I see that GetCommandGenerator, SetCommandGenerator, NextCommandGenerator, and BulkCommandGenerator all inherit from CommandGeneratorBase. This means I have no way of getting them to obtain handles from a shared source. Any suggestions? I don't want to have to hack this whole project by rewriting most of Ilya's code. And I don't want to use a global counter that all instances of the command generators read. And the oneliner module so closely almost does exactly what I need it to do! Is there something I can do to take advantage of its elegance, eloquence, and simplicity? Thanks for your time and patience! Ashir -- all is chaos. seek harmony, not control. axdk |