Re: [Pysnmp-dev] Need information on SNMP Agent implementation usingPYSNMP
Brought to you by:
elie
From: Ilya E. <il...@gl...> - 2010-11-06 15:19:44
|
Mohammed, > With reference to your example given in the following link: > http://pysnmp.sourceforge.net/examples/4.x/v3arch/agent/cmdrsp.html > > I want to know two facts, once you start your engine, which API in that > example is kind of a blocking call or the API which just listens for > GET/other requests from other devices ? and will get invoked only when > there is request (GET/SET) received ? In current implementation, everything revolves around the main loop which is invoked by: snmpEngine.transportDispatcher.runDispatcher() call and terminates only on SNMP engine shutdown. All other API functions/methods are either explicitly invoked before starting the main loop (mostly configuration settings) or called back from the mail loop on message arrival (MIB objects, in my example). Listening and processing incoming messages is hidden behind the API we are talking about here. > Once we have our own mapping with the real life objects and we have > fetched the real value after getting GET request, Which API of cmd > responder is preparing to send the response? (I can see the registration > but I don't see any mechanism there which prepares the response and send > it to the ip/device which has sent the request). With pysnmp's built-in SMI subsystem, you can intercept individual MIB object access using this code: # Override readGet method and return file content class MyFileReadingMibObject(MibScalarInstance): def readGet(self, name, *args): return name, rfc1902.OctetString(open('/etc/passwd').read()) # attach new object to MIB tree (you must also export its parent object) mibBuilder.exportSymbols( "__MYFILEREADING-MIB", MyFileReadingMibObject( (1, 3, 6, 1, 2, 1, 1, 2, 1), (0,), rfc1902.OctetString() ) ) Now when you do: snmpget -v2c -c public localhost 1.3.6.1.2.1.1.2.1.0 the return would be your /etc/passwd file content. Message preparing and sending is done automatically my SNMP engine -- you only have to return a value from your object's readGet() method. Keep in mind, that the readGet() method is currently synchronous -- you can't block in there or the whole SNMP engine would block. If fetching a value is going to take time, an asynchronous implementation is also possible. -ilya > -----Original Message----- > From: Ilya Etingof [mailto:il...@gl...] > Sent: Monday, November 01, 2010 9:56 PM > To: Mohammed Ahad (mdaahad) > Cc: Pys...@li... > Subject: RE: [Pysnmp-dev] Need information on SNMP Agent implementation > usingPYSNMP > > >> 1. once we start our engine, how can we listen (continuously) to the >> GET/SET requests received from other devices(may be a manager) ? > > Yes, sure you can. Here's a working example of an Agent: > > http://pysnmp.sourceforge.net/examples/4.x/v3arch/agent/cmdrsp.html > >> 2. I could not understand the mapping of the instances to real life >> objects, can you explain it briefly. > > What is your real-life setup? Knowing this would help me advise you the > best possible solution. > > Conceptually, pysnmp Agent talks to a SMI (MIB) subsystem through a very > > simple API (pysnmp.smi.MibInstrumController methods) to either fetch or > modify/create OID-value pairs. > > You can implement your own MIB backend and plug it into stock pysnmp > Agent. By way of example, this approach is used in the SNMP Simulator > software: > > http://sourceforge.net/projects/snmpsim/ > > Or you could use stock pysnmp SMI subsystem by > > 1) subclassing MibScalarInstance class and overloading its > read*/write* methods > > or > > 2) subclassing SNMP data type classes (Integer, OctetString, IpAddress > etc.), overloading their clone() method and attaching these > customized > objects to MibScalarInstance.syntax attribute. > > Here's a more in-depth discussion on the topic: > > http://sourceforge.net/mailarchive/forum.php?thread_name=4C00CD1E.609060 > 0%40akimeka.com&forum_name=pysnmp-users > >> 3. My implementation is about to add a support for SNMP agent where I >> have few MIBS. I want to add the SNMP agent support first then SNMP >> Manager support using PYSNMP. I have MIBs which are in xxx-MIB.py > form. > > With pysnmp you could implement Manager, Agent or Manager+Agent > kinds of applications. All scenarious support MIB backend (Agent > role) and MIB resolution (Manager role). > > If you have more specific questions, please, let me know. > > -ilya > >> -----Original Message----- >> From: Ilya Etingof [mailto:il...@gl...] >> Sent: Friday, October 29, 2010 2:56 AM >> To: Mohammed Ahad (mdaahad) >> Cc: Pys...@li... >> Subject: Re: [Pysnmp-dev] Need information on SNMP Agent > implementation >> usingPYSNMP >> >> >> There is a brief tutorial on Agent-side MIB support: >> >> http://pysnmp.sourceforge.net/docs/4.x/index.html#MIB-SERVICES >> >> All the low-level SNMP operations (like loading MIB backend, decoding >> SNMP >> queries etc) are hidden inside the CommandResponder application: >> >> http://pysnmp.sourceforge.net/examples/4.x/v3arch/agent/cmdrsp.html >> >> which is already a fully functional SNMP Agent. >> >> What might take most of your efforts is bridging your Managed >> Objects (this is what you are going to manage though SNMP) with >> pysnmp's MIB API. >> >> One approach is explained in the Agent application above, which >> is hooking on MibScalarInstance's "syntax" component. Though, there >> are a few others. >> >> If you explain your goal in more details, I'd be able to advise. >> >> -ilya >> >>> Moreover I need info on the requirements and infrastructure component >>> details that are essential to respond to SNMP Query, for example, how >>> can we start SNMP engine and how the MIB file (XXX-MIB.py) exports > the >>> symbols and how can it decode the SNMP Get Query and how can we > listen >>> to the queries. >>> >>> I need some good documentation on SNMP agent side >>> implementation using PYSNMP, or if someone guide me with a good >> example >>> (along with explanation) will be appreciable. >> >> > > |