pysnmp-users Mailing List for SNMP library for Python (Page 8)
Brought to you by:
elie
You can subscribe to this list here.
2002 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(2) |
Jul
|
Aug
(2) |
Sep
(3) |
Oct
(2) |
Nov
(4) |
Dec
(4) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2003 |
Jan
|
Feb
(3) |
Mar
(16) |
Apr
(3) |
May
(6) |
Jun
|
Jul
(7) |
Aug
(12) |
Sep
(4) |
Oct
(2) |
Nov
(11) |
Dec
(6) |
2004 |
Jan
(1) |
Feb
(41) |
Mar
(4) |
Apr
(1) |
May
(6) |
Jun
|
Jul
(8) |
Aug
(5) |
Sep
(8) |
Oct
(10) |
Nov
(3) |
Dec
(1) |
2005 |
Jan
|
Feb
(4) |
Mar
(8) |
Apr
(4) |
May
(10) |
Jun
(5) |
Jul
(10) |
Aug
(6) |
Sep
(6) |
Oct
(39) |
Nov
(20) |
Dec
(21) |
2006 |
Jan
(14) |
Feb
(6) |
Mar
(15) |
Apr
|
May
(5) |
Jun
(16) |
Jul
(16) |
Aug
(18) |
Sep
(35) |
Oct
(12) |
Nov
(3) |
Dec
(3) |
2007 |
Jan
(12) |
Feb
(19) |
Mar
(27) |
Apr
(14) |
May
(32) |
Jun
|
Jul
(35) |
Aug
(11) |
Sep
(11) |
Oct
(6) |
Nov
(13) |
Dec
(4) |
2008 |
Jan
(7) |
Feb
(4) |
Mar
(2) |
Apr
(3) |
May
(3) |
Jun
(5) |
Jul
(5) |
Aug
(1) |
Sep
(2) |
Oct
(3) |
Nov
(19) |
Dec
(7) |
2009 |
Jan
(2) |
Feb
(2) |
Mar
(12) |
Apr
(16) |
May
(16) |
Jun
(23) |
Jul
(7) |
Aug
(2) |
Sep
(17) |
Oct
(20) |
Nov
(20) |
Dec
(5) |
2010 |
Jan
(11) |
Feb
(17) |
Mar
(20) |
Apr
(7) |
May
(6) |
Jun
(14) |
Jul
(5) |
Aug
(10) |
Sep
(23) |
Oct
(16) |
Nov
(32) |
Dec
(21) |
2011 |
Jan
(6) |
Feb
(11) |
Mar
(3) |
Apr
(1) |
May
(4) |
Jun
(1) |
Jul
(4) |
Aug
(8) |
Sep
(20) |
Oct
(9) |
Nov
(29) |
Dec
(25) |
2012 |
Jan
(2) |
Feb
(5) |
Mar
(2) |
Apr
(22) |
May
(21) |
Jun
(7) |
Jul
(6) |
Aug
(2) |
Sep
(12) |
Oct
(20) |
Nov
(17) |
Dec
(17) |
2013 |
Jan
(4) |
Feb
(4) |
Mar
(8) |
Apr
(8) |
May
(10) |
Jun
(2) |
Jul
(23) |
Aug
(12) |
Sep
(14) |
Oct
(12) |
Nov
(4) |
Dec
(18) |
2014 |
Jan
(2) |
Feb
(7) |
Mar
(3) |
Apr
(8) |
May
(7) |
Jun
(1) |
Jul
(5) |
Aug
(2) |
Sep
(8) |
Oct
|
Nov
(2) |
Dec
(1) |
2015 |
Jan
(3) |
Feb
(15) |
Mar
(14) |
Apr
(4) |
May
(6) |
Jun
(3) |
Jul
(1) |
Aug
(6) |
Sep
(5) |
Oct
(21) |
Nov
(43) |
Dec
(10) |
2016 |
Jan
|
Feb
(2) |
Mar
(6) |
Apr
(4) |
May
(6) |
Jun
(2) |
Jul
(6) |
Aug
(5) |
Sep
(4) |
Oct
|
Nov
(3) |
Dec
(11) |
2017 |
Jan
(1) |
Feb
(8) |
Mar
|
Apr
(7) |
May
|
Jun
|
Jul
(5) |
Aug
|
Sep
(9) |
Oct
(8) |
Nov
|
Dec
|
2018 |
Jan
|
Feb
|
Mar
(2) |
Apr
(2) |
May
(1) |
Jun
(2) |
Jul
(2) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2019 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
|
2020 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
|
From: Diego P. <dpa...@gm...> - 2015-09-25 03:32:09
|
I have an aplication that runs (something like) the following code every five minutes. ----------------8<------------------ cmd_gen = cmdgen.AsynCommandGenerator(engine.SnmpEngine()) # every t['transport'] is an instance of "cmdgen.UdpTransportTarget" # every t['cbCtx'] is a "config" for the async callback for t in self.getTransport().values(): cmd_gen.getCmd( public , t['transport'] , oids , (self._parse, t['cbCtx']) ) cmd_gen.snmpEngine.transportDispatcher.runDispatcher() ----------------8<------------------ I though I could run the 'for' statement just once and then run every five minutes only the Dispatcher (last command), but it seems that getCmd command generates a list of jobs for the Dispatcher and, once the jobs are complete, this list is empty, making me run the 'for' to fill it in again. My question is, is there a better way to do this? Can I somehow tell runDispatcher to run the sabe jobs again? Thank you very much :) |
From: Vincent B. <be...@lu...> - 2015-09-14 06:27:28
|
❦ 1 juillet 2015 11:56 +0200, Vincent Bernat <be...@lu...> : >> To prevent leaks keep snmpEngine as a singleton. It will maintain and >> expire its cache. Everything else could be recreated cheaply. I do not >> expect major leaks with such arrangement. > > OK, now, I am all the more confused. :) Maybe it's snmpEngine that > should be a singleton but I should use a new AsyncCommandGenerator for > each manager that I need? In this case, this should work with the > current version too? [...] I am still confused by all this. Moreover, I just discovered that snmpEngine cannot be a singleton because it doesn't handle multiple threads. Therefore, I am still looking for a way to not have a singleton but to push MIB-related high-cost initialization of snmpEngine outside it. -- Choose variable names that won't be confused. - The Elements of Programming Style (Kernighan & Plauger) |
From: Ilya E. <il...@gl...> - 2015-08-24 05:09:58
|
Hi Robert, To verify your guess try to add .setLocalAddress() call like this: > cmdgen.UdpTransportTarget(('192.168.56.2', 161)).setLocalAddress((‘0.0.0.0’, 0)), what will make pysnmp binding its UDP socket to all local interfaces and randomly chosen local port. Please let me know if that helps. -ilya > On 18 Aug 2015, at 20:39, Robert Welbourn <ad...@we...> wrote: > > On further investigation, I suspect that prior to calling socket.sendto(), there was no bind() operation to a local interface. See Appendix C: WinSock Error Reference (continued) <http://www.sockets.com/err_lst1.htm>, in particular: > > > <http://www.sockets.com/err_lst1.htm> > > > > > > Appendix C: WinSock Error Reference (continued) > <http://www.sockets.com/err_lst1.htm>Appendix C: Error Reference [Go to Top] Detailed Error Descriptions Errorless Functions Functionless Errors Error Description List > View on www.sockets.com <http://www.sockets.com/err_lst1.htm> > Preview by Yahoo > > > "send() <http://www.sockets.com/winsock.htm#Send> & sendto() <http://www.sockets.com/winsock.htm#SendTo>: socket not bound (for Dgram) or not yet connected (for Stream)" > R. > > From: Robert Welbourn <ro...@we...> > To: "pys...@li..." <pys...@li...> > Sent: Tuesday, August 18, 2015 12:06 PM > Subject: [pysnmp-users] WinError 10022 when calling CommandGenerator.getCmd() > > I'm running PySNMP 4.2.5 under Windows 7 with Python 3.4.3. When I run the following snippet of code I get a Windows socket error: > > from pysnmp.entity.rfc3413.oneliner import cmdgen > cmdGen = cmdgen.CommandGenerator() > errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd( > cmdgen.CommunityData('CONV'), > cmdgen.UdpTransportTarget(('192.168.56.2', 161)), > '1.3.6.1.4.1.7569.1.2.1.9') > > Traceback (most recent call last): > File "c:\python34\lib\site-packages\pysnmp-4.2.5-py3.4.egg\pysnmp\carrier\asynsock\dgram\base.py", line 66, in handle_write > OSError: [WinError 10022] An invalid argument was supplied > > This appears to happen in the handle_write() method of the DgramSocketTransport class, on the socket.sendto() line: > > def handle_write(self): > outgoingMessage, transportAddress = self.__outQueue.pop(0) > debug.logger & debug.flagIO and debug.logger('handle_write: transportAddress %r -> %r outgoingMessage (%d octets) %s' % (self.__getsockname(), transportAddress, len(outgoingMessage), debug.hexdump(outgoingMessage))) > if not transportAddress: > debug.logger & debug.flagIO and debug.logger('handle_write: missing dst address, loosing outgoing msg') > return > try: > self.socket.sendto(outgoingMessage, transportAddress) > except socket.error: > if sys.exc_info()[1].args[0] in sockErrors: > debug.logger & debug.flagIO and debug.logger('handle_write: ignoring socket error %s' % (sys.exc_info()[1],)) > else: > raise error.CarrierError('sendto() failed for %s: %s' % (transportAddress, sys.exc_info()[1])) > > Microsoft's description of this error is not very helpful: > > Some invalid argument was supplied (for example, specifying an invalid level to the setsockopt <https://msdn.microsoft.com/en-us/library/ms740476%28v=vs.85%29.aspx> function). In some instances, it also refers to the current state of the socket—for instance, calling accept <https://msdn.microsoft.com/en-us/library/ms737526%28v=vs.85%29.aspx> on a socket that is not listening. > > Anyone got any ideas? > > Thanks, > > Rob |
From: Robert W. <ad...@we...> - 2015-08-18 18:52:17
|
On further investigation, I suspect that prior to calling socket.sendto(), there was no bind() operation to a local interface. See Appendix C: WinSock Error Reference (continued), in particular: | | | | | | | | | | | Appendix C: WinSock Error Reference (continued)Appendix C: Error Reference [Go to Top] Detailed Error Descriptions Errorless Functions Functionless Errors Error Description List | | | | View on www.sockets.com | Preview by Yahoo | | | | | "send() & sendto(): socket not bound (for Dgram) or not yetconnected (for Stream)" R. From: Robert Welbourn <ro...@we...> To: "pys...@li..." <pys...@li...> Sent: Tuesday, August 18, 2015 12:06 PM Subject: [pysnmp-users] WinError 10022 when calling CommandGenerator.getCmd() I'm running PySNMP 4.2.5 under Windows 7 with Python 3.4.3. When I run the following snippet of code I get a Windows socket error: from pysnmp.entity.rfc3413.oneliner import cmdgen cmdGen = cmdgen.CommandGenerator() errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd( cmdgen.CommunityData('CONV'), cmdgen.UdpTransportTarget(('192.168.56.2', 161)), '1.3.6.1.4.1.7569.1.2.1.9') Traceback (most recent call last): File "c:\python34\lib\site-packages\pysnmp-4.2.5-py3.4.egg\pysnmp\carrier\asynsock\dgram\base.py", line 66, in handle_write OSError: [WinError 10022] An invalid argument was supplied This appears to happen in the handle_write() method of the DgramSocketTransport class, on the socket.sendto() line: def handle_write(self): outgoingMessage, transportAddress = self.__outQueue.pop(0) debug.logger & debug.flagIO and debug.logger('handle_write: transportAddress %r -> %r outgoingMessage (%d octets) %s' % (self.__getsockname(), transportAddress, len(outgoingMessage), debug.hexdump(outgoingMessage))) if not transportAddress: debug.logger & debug.flagIO and debug.logger('handle_write: missing dst address, loosing outgoing msg') return try: self.socket.sendto(outgoingMessage, transportAddress) except socket.error: if sys.exc_info()[1].args[0] in sockErrors: debug.logger & debug.flagIO and debug.logger('handle_write: ignoring socket error %s' % (sys.exc_info()[1],)) else: raise error.CarrierError('sendto() failed for %s: %s' % (transportAddress, sys.exc_info()[1])) Microsoft's description of this error is not very helpful: Some invalid argument was supplied (for example, specifying an invalid level to the setsockopt function). In some instances, it also refers to the current state of the socket—for instance, calling accept on a socket that is not listening. Anyone got any ideas? Thanks, Rob ------------------------------------------------------------------------------ _______________________________________________ pysnmp-users mailing list pys...@li... https://lists.sourceforge.net/lists/listinfo/pysnmp-users |
From: Robert W. <ro...@we...> - 2015-08-18 16:06:50
|
I'm running PySNMP 4.2.5 under Windows 7 with Python 3.4.3. When I run the following snippet of code I get a Windows socket error: from pysnmp.entity.rfc3413.oneliner import cmdgen cmdGen = cmdgen.CommandGenerator() errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd( cmdgen.CommunityData('CONV'), cmdgen.UdpTransportTarget(('192.168.56.2', 161)), '1.3.6.1.4.1.7569.1.2.1.9') Traceback (most recent call last): File "c:\python34\lib\site-packages\pysnmp-4.2.5-py3.4.egg\pysnmp\carrier\asynsock\dgram\base.py", line 66, in handle_write OSError: [WinError 10022] An invalid argument was supplied This appears to happen in the handle_write() method of the DgramSocketTransport class, on the socket.sendto() line: def handle_write(self): outgoingMessage, transportAddress = self.__outQueue.pop(0) debug.logger & debug.flagIO and debug.logger('handle_write: transportAddress %r -> %r outgoingMessage (%d octets) %s' % (self.__getsockname(), transportAddress, len(outgoingMessage), debug.hexdump(outgoingMessage))) if not transportAddress: debug.logger & debug.flagIO and debug.logger('handle_write: missing dst address, loosing outgoing msg') return try: self.socket.sendto(outgoingMessage, transportAddress) except socket.error: if sys.exc_info()[1].args[0] in sockErrors: debug.logger & debug.flagIO and debug.logger('handle_write: ignoring socket error %s' % (sys.exc_info()[1],)) else: raise error.CarrierError('sendto() failed for %s: %s' % (transportAddress, sys.exc_info()[1])) Microsoft's description of this error is not very helpful: Some invalid argument was supplied (for example, specifying an invalid level to the setsockopt function). In some instances, it also refers to the current state of the socket—for instance, calling accept on a socket that is not listening. Anyone got any ideas? Thanks, Rob |
From: Robert W. <ad...@we...> - 2015-08-18 15:47:37
|
I'm running PySNMP 4.2.5 under Windows 7 with Python 3.4.3. When I run the following snippet of code I get a Windows socket error: from pysnmp.entity.rfc3413.oneliner import cmdgen cmdGen = cmdgen.CommandGenerator() errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd( cmdgen.CommunityData('CONV'), cmdgen.UdpTransportTarget(('192.168.56.2', 161)), '1.3.6.1.4.1.7569.1.2.1.9') Traceback (most recent call last): File "c:\python34\lib\site-packages\pysnmp-4.2.5-py3.4.egg\pysnmp\carrier\asynsock\dgram\base.py", line 66, in handle_write OSError: [WinError 10022] An invalid argument was supplied This appears to happen in the handle_write() method of the DgramSocketTransport class, on the socket.sendto() line: def handle_write(self): outgoingMessage, transportAddress = self.__outQueue.pop(0) debug.logger & debug.flagIO and debug.logger('handle_write: transportAddress %r -> %r outgoingMessage (%d octets) %s' % (self.__getsockname(), transportAddress, len(outgoingMessage), debug.hexdump(outgoingMessage))) if not transportAddress: debug.logger & debug.flagIO and debug.logger('handle_write: missing dst address, loosing outgoing msg') return try: self.socket.sendto(outgoingMessage, transportAddress) except socket.error: if sys.exc_info()[1].args[0] in sockErrors: debug.logger & debug.flagIO and debug.logger('handle_write: ignoring socket error %s' % (sys.exc_info()[1],)) else: raise error.CarrierError('sendto() failed for %s: %s' % (transportAddress, sys.exc_info()[1])) Microsoft's description of this error is not very helpful: Some invalid argument was supplied (for example, specifying an invalid level to the setsockopt function). In some instances, it also refers to the current state of the socket—for instance, calling accept on a socket that is not listening. Anyone got any ideas? Thanks, Rob |
From: Ilya E. <il...@gl...> - 2015-08-17 14:26:58
|
Hi Antonio, The prettyPrintType() method comes from pyasn1 package which is a foundation for pysnmp. Perhaps you should upgrade your pysnmp installation on Debian to get that method or you could just implement something similar in your app based on: print(val.__class__.__name__) -ilya On 08/17/2015 04:01 PM, Antonio Piepoli (apiepoli) wrote: > Hello everybody, > > I am afraid this is a trivial question but I can’t really come to a > solution. > > I am running Debian testing and version 4.2.5 of the pysnmp library. > > If a I run a simple query I don’t find the method prettyPrintType() in > val : > > BASE_OID = '1.3.6.1.2.1.2.2.1' > > errorIndication, errorStatus, errorIndex, varBindTable = > cmdGen.nextCmd(cmdgen.CommunityData(‘public’),cmdgen.UdpTransportTarget(('demo.snmplabs.com', > 161)),'%s' %BASE_OID) > > for varBindTableRow in varBindTable: > > for name, val in varBindTableRow: > > dir(val) > > Running the exact same code on a windows machine with the same version > of pysnmp the method is there. > > I don’t really need that specific method, I only need a way to get the > type of the OID from a query. > > Thanks |
From: Antonio P. (apiepoli) <api...@ci...> - 2015-08-17 14:01:22
|
Hello everybody, I am afraid this is a trivial question but I can't really come to a solution. I am running Debian testing and version 4.2.5 of the pysnmp library. If a I run a simple query I don't find the method prettyPrintType() in val : BASE_OID = '1.3.6.1.2.1.2.2.1' errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.nextCmd(cmdgen.CommunityData('public'),cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),'%s' %BASE_OID) for varBindTableRow in varBindTable: for name, val in varBindTableRow: dir(val) Running the exact same code on a windows machine with the same version of pysnmp the method is there. I don't really need that specific method, I only need a way to get the type of the OID from a query. Thanks Antonio Piepoli NCE - Network Consulting Engineer. api...@ci... Phone: +39 06 5164 5047 Cisco Systems Limited [http://www.cisco.com/web/europe/images/email/signature/logo05.jpg] |
From: Vincent B. <be...@lu...> - 2015-07-01 09:56:26
|
❦ 30 juin 2015 23:46 +0200, Ilya Etingof <il...@gl...> : > In the latest (almost released) pysnmp AsyncCommandGenerator API > reworked to become stateless. It is AsyncCommandGenerator class that > does most of work. CommandGenerator is a thin wrapper creating and > hiding SnmpEngine instance aimed at simple use cases. > > All state (a lot of it) is bound to snmpEngine object. Any > AsyncCommandGenerator call must be done with snmpEngine object > reference. > > Here’s example code: > > http://pysnmp.cvs.sourceforge.net/viewvc/pysnmp/pysnmp/examples/v3arch/oneliner/manager/cmdgen/get-async-multiple-snmp-engines.py?view=markup > > I’d be very interested knowing if that new API works for you before it’s too late (pysnmp is released). ;-) > > Here’s the latest pysnmp: > > http://pysnmp.cvs.sourceforge.net/viewvc/pysnmp/pysnmp/?view=tar > > As for wrongDigest error: take a look at how > SNMP-USER-BASED-SM-MIB::usmUserTable is organised. Its entries are > indexed by two keys: usmUserEngineID and usmUserSecurityName. For > CommandGenerator role, usmUserSecurityName can be used to distinguish > multiple usmUserName entries in usmUserTable. So try adding distinct > securityName parameters to UsmUserData constructor. I am a bit confused. >From my point of view, the usmUserTable is a local configuration table. However, currently, PySNMP seems to use it as a cache accross different hosts. If I have two hosts A and B using the same security name, I shouldn't use the cached entry for one for the other one, right? What you say is that when querying two different hosts, I should use a different snmpEngine for each host. To be able to do that, I must use AsyncCommandGenerator which is stateless and provides the appropriate snmpEngine to getCmd and friends, right? In my case, I can just keep AsyncCommandGenerator a singleton but use "engine.SnmpEngine()" each time I need a new manager? Wouldn't I get the same memory and CPU leak than previously, due to repeated call to view.MibViewController(self.snmpEngine.msgAndPduDsp.mibInstrumController.mibBuilder)? Or will this go away as long as I implement some cache on my side to reuse snmpEngine? If yes, OK, that would solve my problem with the yet-to-be released version of PySNMP. I'll test that pretty soon. With the current version, I think there is no easy way to get the same effect? > To prevent leaks keep snmpEngine as a singleton. It will maintain and > expire its cache. Everything else could be recreated cheaply. I do not > expect major leaks with such arrangement. OK, now, I am all the more confused. :) Maybe it's snmpEngine that should be a singleton but I should use a new AsyncCommandGenerator for each manager that I need? In this case, this should work with the current version too? > As a side note, the above pysnmp code can do MIB > download/compilation/lookup without libsmi/smidump. It relies upon our > latest creature — PySMI (http://pysmi.sf.net) which can be pip’ed down > right away. > > I’d also be very interested to know your experience in this respect. Oh, that's pretty interesting! I'll have a look at that and tell you if it fits my need. Just when I got a sense on how CFFI worked. ;-) -- In the Spring, I have counted 136 different kinds of weather inside of 24 hours. -- Mark Twain, on New England weather |
From: Ilya E. <il...@gl...> - 2015-06-30 21:46:43
|
Hi Vincent, In the latest (almost released) pysnmp AsyncCommandGenerator API reworked to become stateless. It is AsyncCommandGenerator class that does most of work. CommandGenerator is a thin wrapper creating and hiding SnmpEngine instance aimed at simple use cases. All state (a lot of it) is bound to snmpEngine object. Any AsyncCommandGenerator call must be done with snmpEngine object reference. Here’s example code: http://pysnmp.cvs.sourceforge.net/viewvc/pysnmp/pysnmp/examples/v3arch/oneliner/manager/cmdgen/get-async-multiple-snmp-engines.py?view=markup I’d be very interested knowing if that new API works for you before it’s too late (pysnmp is released). ;-) Here’s the latest pysnmp: http://pysnmp.cvs.sourceforge.net/viewvc/pysnmp/pysnmp/?view=tar As for wrongDigest error: take a look at how SNMP-USER-BASED-SM-MIB::usmUserTable is organised. Its entries are indexed by two keys: usmUserEngineID and usmUserSecurityName. For CommandGenerator role, usmUserSecurityName can be used to distinguish multiple usmUserName entries in usmUserTable. So try adding distinct securityName parameters to UsmUserData constructor. I hope to get some time for figuring that out for sure. Meanwhile, in case of further troubles, I suggest you enabling pysnmp debugging (secmod category) and watch what usmUserTable entry gets chosen for each Agent communication. To prevent leaks keep snmpEngine as a singleton. It will maintain and expire its cache. Everything else could be recreated cheaply. I do not expect major leaks with such arrangement. As a side note, the above pysnmp code can do MIB download/compilation/lookup without libsmi/smidump. It relies upon our latest creature — PySMI (http://pysmi.sf.net) which can be pip’ed down right away. I’d also be very interested to know your experience in this respect. Thanks, Ilya > On 26 Jun 2015, at 21:00, Vincent Bernat <be...@lu...> wrote: > > Hi! > >> From the interface of cmdgen.CommandGenerator, it seems to me that I can > use a single instance of this class for the whole life of the > application. Unfortunately, with SNMPv3, it seems that the class keeps > some state. > > I see in cmdgen.py: > > #v+ > authDataKey = authData.userName, authData.securityEngineId > if authDataKey not in self.__knownAuths: > #v- > > I didn't understand how security engine ID is computed, but using the > same CommandGenerator() instance to query two hosts with the same > security name but different passwords lead to the reuse of the auth data > and leads to a "wrong digest" error. > > I get this bug in Snimpy: > https://github.com/vincentbernat/snimpy/issues/35 > > I did turn cmdgen.CmdGenerator() into a singleton because when called in > a loop, it leaks a lot of memory: > https://github.com/vincentbernat/snimpy/issues/33 > > (and a lot of CPU is used too) > > What would be the appropriate steps to keep the singleton but ensuring > the data not to be cached? I tried some manual security engine ID but I > didn't understand the rules to build one (RFC 5343 ?) and I get "Unknown > SNMP security name encountered" error. > -- > Follow each decision as closely as possible with its associated action. > - The Elements of Programming Style (Kernighan & Plauger) > > ------------------------------------------------------------------------------ > Monitor 25 network devices or servers for free with OpManager! > OpManager is web-based network management software that monitors > network devices and physical & virtual servers, alerts via email & sms > for fault. Monitor 25 devices for free with no restriction. Download now > http://ad.doubleclick.net/ddm/clk/292181274;119417398;o > _______________________________________________ > pysnmp-users mailing list > pys...@li... > https://lists.sourceforge.net/lists/listinfo/pysnmp-users |
From: Vincent B. <be...@lu...> - 2015-06-30 20:37:25
|
❦ 26 juin 2015 21:00 +0200, Vincent Bernat <be...@lu...> : > From the interface of cmdgen.CommandGenerator, it seems to me that I can > use a single instance of this class for the whole life of the > application. Unfortunately, with SNMPv3, it seems that the class keeps > some state. Any insight on this? -- Every cloud engenders not a storm. -- William Shakespeare, "Henry VI" |
From: Vincent B. <be...@lu...> - 2015-06-26 19:00:54
|
Hi! >From the interface of cmdgen.CommandGenerator, it seems to me that I can use a single instance of this class for the whole life of the application. Unfortunately, with SNMPv3, it seems that the class keeps some state. I see in cmdgen.py: #v+ authDataKey = authData.userName, authData.securityEngineId if authDataKey not in self.__knownAuths: #v- I didn't understand how security engine ID is computed, but using the same CommandGenerator() instance to query two hosts with the same security name but different passwords lead to the reuse of the auth data and leads to a "wrong digest" error. I get this bug in Snimpy: https://github.com/vincentbernat/snimpy/issues/35 I did turn cmdgen.CmdGenerator() into a singleton because when called in a loop, it leaks a lot of memory: https://github.com/vincentbernat/snimpy/issues/33 (and a lot of CPU is used too) What would be the appropriate steps to keep the singleton but ensuring the data not to be cached? I tried some manual security engine ID but I didn't understand the rules to build one (RFC 5343 ?) and I get "Unknown SNMP security name encountered" error. -- Follow each decision as closely as possible with its associated action. - The Elements of Programming Style (Kernighan & Plauger) |
From: Ilya E. <il...@gl...> - 2015-05-21 06:39:29
|
Hi Johan, You are supposed to pass a sequence of OIDs, not just one: > cmdGen.getCmd( > cmdgen.UsmUserData('user', 'authpassword', 'privpassword', > authProtocol=cmdgen.usmHMACSHAAuthProtocol, > privProtocol=cmdgen.usmAesCfb128Protocol), > transportTarget, > ( ('1.3.6.1.2.1.1.5.0’), ), > (cbFun, None), > ) -ilya > On 21 May 2015, at 05:26, Johan Geldenhuys <joh...@gm...> wrote: > > Hi all, > > I would appreciate some help with the getcmd in the following code. I get a serialization error. > Eventually i will have multiple targets and would like to keep that in a loop. The OID will also be a custom OID without loading the MIB. > > Thank you > J > > > > > from pysnmp.entity.rfc3413.oneliner import cmdgen > > def cbFun(sendRequestHandle, errorIndication, \ > errorStatus, errorIndex, varBindTable, cbCtx): > if errorIndication: > print(errorIndication) > return > if errorStatus: > print('%s at %s' % \ > (errorStatus.prettyPrint(), > errorIndex and varBindTable[-1][int(errorIndex)-1] or '?') > ) > return > > for varBindRow in varBindTable: > for oid, val in varBindRow: > if val is None: > return # stop table retrieval > else: > print('%s = %s' % (oid.prettyPrint(), val.prettyPrint())) > > return True # continue table retrieval > > cmdGen = cmdgen.AsynCommandGenerator() > > for transportTarget in ( cmdgen.UdpTransportTarget(('192.168.10.107', 161)), > ): > > cmdGen.getCmd( > cmdgen.UsmUserData('user', 'authpassword', 'privpassword', > authProtocol=cmdgen.usmHMACSHAAuthProtocol, > privProtocol=cmdgen.usmAesCfb128Protocol), > transportTarget, > ('1.3.6.1.2.1.1.5.0'), > (cbFun, None), > lookupNames=False, lookupValues=False > ) > > cmdGen.snmpEngine.transportDispatcher.runDispatcher() > |
From: Johan G. <joh...@gm...> - 2015-05-21 02:26:47
|
Hi all, I would appreciate some help with the getcmd in the following code. I get a serialization error. Eventually i will have multiple targets and would like to keep that in a loop. The OID will also be a custom OID without loading the MIB. Thank you J from pysnmp.entity.rfc3413.oneliner import cmdgen def cbFun(sendRequestHandle, errorIndication, \ errorStatus, errorIndex, varBindTable, cbCtx): if errorIndication: print(errorIndication) return if errorStatus: print('%s at %s' % \ (errorStatus.prettyPrint(), errorIndex and varBindTable[-1][int(errorIndex)-1] or '?') ) return for varBindRow in varBindTable: for oid, val in varBindRow: if val is None: return # stop table retrieval else: print('%s = %s' % (oid.prettyPrint(), val.prettyPrint())) return True # continue table retrieval cmdGen = cmdgen.AsynCommandGenerator() for transportTarget in ( cmdgen.UdpTransportTarget(('192.168.10.107', 161)), ): cmdGen.getCmd( cmdgen.UsmUserData('user', 'authpassword', 'privpassword', authProtocol=cmdgen.usmHMACSHAAuthProtocol, privProtocol=cmdgen.usmAesCfb128Protocol), transportTarget, ('1.3.6.1.2.1.1.5.0'), (cbFun, None), lookupNames=False, lookupValues=False ) cmdGen.snmpEngine.transportDispatcher.runDispatcher() |
From: Ilya E. <il...@gl...> - 2015-05-20 06:16:25
|
Hi Christopher, 1. Here you go: http://sourceforge.net/projects/pyasn1/files/pyasn1/0.1.8/ <http://sourceforge.net/projects/pyasn1/files/pyasn1/0.1.8/> 2. Just pass plain OID (as a string to a tuple) instead of MibVariable instance: http://pysnmp.sourceforge.net/examples/current/v3arch/oneliner/manager/cmdgen/get-v2c.html The lookupNames and lookupValues keyword parameters enable MIB resolution for the response OID/value pairs. -ilya > On 20 May 2015, at 03:41, Christopher Young <chr...@me...> wrote: > > Thanks Ilya! > > Cross posting from Stack-Overflow > > Thanks for the answer! > > Two more quick questions > > > 1) I tried to grab the latest pysnmp 4.2.6.2 but I'm getting blocked on install with the following error "Could not find a version that satisfies the requirement pyasn1>=0.1.8 (from pysnmp) (from versions: 0.0.9a0, 0.0.10a0, 0.0.11a0, 0.0.12a0, 0.0.13a0, 0.0.13b0, 0.0.13, 0.1.1, 0.1.2, 0.1.3, 0.1.4, 0.1.5, 0.1.6, 0.1.7) No matching distribution found for pyasn1>=0.1.8 (from pysnmp)" > > I couldn’t find an updated version of the PYASN1 library around. Latest I can find is 0.1.7. Pointers? > > Question 2 - Am I misunderstanding the lookupValues=False & lookupNames=False kwargs above? I thought that should have allowed me to access the OID directly without having to import the MIB. I wanted to avoid any dependencies if possible. The 1.3.6.1.2.1.31.1.1.1.18.1 definitely corresponds to a MIB object as I was able to use an SNMP browser tool ( iReasoning’s free tool ) to access and SET this exact OID to a value using a octetString input. > > Really appreciate the help! ( and the library!!!) > > > Chris > >> On May 19, 2015, at 6:11 PM, Ilya Etingof <il...@gl... <mailto:il...@gl...>> wrote: >> >> Hi Christopher, >> >> Cross-posting from StackOverflow: >> >> That looks like a bug in pysnmp -- latest CVS version might not throw that way. >> >> However, the root cause of that error is that pysnmp could not find a MIB object corresponding the 1.3.6.1.2.1.31.1.1.1.18.1 OID. That may happen either because MIB that defines that OID is not loaded or OID in question does not correspond to any MIB object. >> >> To load IF-MIB you may either do it explicitly: >> >> cmdgen.MibVariable('1.3.6.1.2.1.31.1.1.1.18.1').loadMibs('IF-MIB') >> or use MIB::object.index syntax: >> >> cmdgen.MibVariable('IF-MIB', 'ifAlias', 1) >> You could grab the IF-MIB.py from pysnmp-mibs package available on pypi or compile it from ASN.1 MIB by [experimental] pysmi compiler (http://sf.net/projects/pysmi/ <http://sf.net/projects/pysmi/>) >> >> -ilya >> >>> On 18 May 2015, at 19:44, Christopher Young <chr...@me... <mailto:chr...@me...>> wrote: >>> >>> Hi All, >>> >>> Using Python 3.4. Made sure I’m using latest version of pysnmp by pip3 install pysnmp —update >>> >>> >>> 1) This function to set the SYSCONTACT value of a switch works exactly as intended. >>> >>> >>> def SNMP_SET_SYSCONTACT(syscontact): >>> errorIndication, errorStatus, errorIndex, varBinds = cmdGen.setCmd(cmdgen.CommunityData('private'),cmdgen.UdpTransportTarget(('10.101.0.221', 161)),(cmdgen.MibVariable('.1.3.6.1.2.1.1.4.0'), syscontact), lookupNames=False, lookupValues=True) >>> >>> >>> >>> 2) Substituted in the OID for the 1st ifAlias occurrence in the switch. This throws the exception noted below. No idea why I would be thrown this error for what is essentially the same function. >>> >>> I have verified that this OID is writable using a standard MIB browser ( iReasoning ) >>> >>> >>> >>> def SNMP_SET_IFALIAS(ifAlias): >>> errorIndication, errorStatus, errorIndex, varBinds = cmdGen.setCmd(cmdgen.CommunityData('private'),cmdgen.UdpTransportTarget(('10.101.0.221', 161)),(cmdgen.MibVariable('1.3.6.1.2.1.31.1.1.1.18.1'), ifAlias),lookupValues=False, lookupNames=False) >>> >>> Traceback (most recent call last): >>> File "<pyshell#632>", line 1, in <module> >>> SNMP_SET_IFALIAS('Check this out') >>> File "<pyshell#629>", line 2, in SNMP_SET_IFALIAS >>> errorIndication, errorStatus, errorIndex, varBinds = cmdGen.setCmd(cmdgen.CommunityData('private'),cmdgen.UdpTransportTarget(('10.101.0.221', 161)),(cmdgen.MibVariable('1.3.6.1.2.1.31.1.1.1.18.1'), ifAlias),lookupValues=False, lookupNames=False) >>> File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pysnmp/entity/rfc3413/oneliner/cmdgen.py", line 452, in setCmd >>> kwargs.get('contextName', null) >>> File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pysnmp/entity/rfc3413/oneliner/cmdgen.py", line 314, in setCmd >>> self.makeVarBinds(varBinds), >>> File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pysnmp/entity/rfc3413/oneliner/cmdgen.py", line 212, in makeVarBinds >>> varVal = varName.getMibNode().getSyntax().clone(varVal) >>> AttributeError: 'MibIdentifier' object has no attribute ‘getSyntax' >> |
From: Christopher Y. <chr...@me...> - 2015-05-20 00:42:32
|
Thanks Ilya! Cross posting from Stack-Overflow Thanks for the answer! Two more quick questions 1) I tried to grab the latest pysnmp 4.2.6.2 but I'm getting blocked on install with the following error "Could not find a version that satisfies the requirement pyasn1>=0.1.8 (from pysnmp) (from versions: 0.0.9a0, 0.0.10a0, 0.0.11a0, 0.0.12a0, 0.0.13a0, 0.0.13b0, 0.0.13, 0.1.1, 0.1.2, 0.1.3, 0.1.4, 0.1.5, 0.1.6, 0.1.7) No matching distribution found for pyasn1>=0.1.8 (from pysnmp)" I couldn’t find an updated version of the PYASN1 library around. Latest I can find is 0.1.7. Pointers? Question 2 - Am I misunderstanding the lookupValues=False & lookupNames=False kwargs above? I thought that should have allowed me to access the OID directly without having to import the MIB. I wanted to avoid any dependencies if possible. The 1.3.6.1.2.1.31.1.1.1.18.1 definitely corresponds to a MIB object as I was able to use an SNMP browser tool ( iReasoning’s free tool ) to access and SET this exact OID to a value using a octetString input. Really appreciate the help! ( and the library!!!) Chris > On May 19, 2015, at 6:11 PM, Ilya Etingof <il...@gl...> wrote: > > Hi Christopher, > > Cross-posting from StackOverflow: > > That looks like a bug in pysnmp -- latest CVS version might not throw that way. > > However, the root cause of that error is that pysnmp could not find a MIB object corresponding the 1.3.6.1.2.1.31.1.1.1.18.1 OID. That may happen either because MIB that defines that OID is not loaded or OID in question does not correspond to any MIB object. > > To load IF-MIB you may either do it explicitly: > > cmdgen.MibVariable('1.3.6.1.2.1.31.1.1.1.18.1').loadMibs('IF-MIB') > or use MIB::object.index syntax: > > cmdgen.MibVariable('IF-MIB', 'ifAlias', 1) > You could grab the IF-MIB.py from pysnmp-mibs package available on pypi or compile it from ASN.1 MIB by [experimental] pysmi compiler (http://sf.net/projects/pysmi/ <http://sf.net/projects/pysmi/>) > > -ilya > >> On 18 May 2015, at 19:44, Christopher Young <chr...@me... <mailto:chr...@me...>> wrote: >> >> Hi All, >> >> Using Python 3.4. Made sure I’m using latest version of pysnmp by pip3 install pysnmp —update >> >> >> 1) This function to set the SYSCONTACT value of a switch works exactly as intended. >> >> >>> def SNMP_SET_SYSCONTACT(syscontact): >> errorIndication, errorStatus, errorIndex, varBinds = cmdGen.setCmd(cmdgen.CommunityData('private'),cmdgen.UdpTransportTarget(('10.101.0.221', 161)),(cmdgen.MibVariable('.1.3.6.1.2.1.1.4.0'), syscontact), lookupNames=False, lookupValues=True) >> >> >> >> 2) Substituted in the OID for the 1st ifAlias occurrence in the switch. This throws the exception noted below. No idea why I would be thrown this error for what is essentially the same function. >> >> I have verified that this OID is writable using a standard MIB browser ( iReasoning ) >> >> >> >>> def SNMP_SET_IFALIAS(ifAlias): >> errorIndication, errorStatus, errorIndex, varBinds = cmdGen.setCmd(cmdgen.CommunityData('private'),cmdgen.UdpTransportTarget(('10.101.0.221', 161)),(cmdgen.MibVariable('1.3.6.1.2.1.31.1.1.1.18.1'), ifAlias),lookupValues=False, lookupNames=False) >> >> Traceback (most recent call last): >> File "<pyshell#632>", line 1, in <module> >> SNMP_SET_IFALIAS('Check this out') >> File "<pyshell#629>", line 2, in SNMP_SET_IFALIAS >> errorIndication, errorStatus, errorIndex, varBinds = cmdGen.setCmd(cmdgen.CommunityData('private'),cmdgen.UdpTransportTarget(('10.101.0.221', 161)),(cmdgen.MibVariable('1.3.6.1.2.1.31.1.1.1.18.1'), ifAlias),lookupValues=False, lookupNames=False) >> File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pysnmp/entity/rfc3413/oneliner/cmdgen.py", line 452, in setCmd >> kwargs.get('contextName', null) >> File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pysnmp/entity/rfc3413/oneliner/cmdgen.py", line 314, in setCmd >> self.makeVarBinds(varBinds), >> File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pysnmp/entity/rfc3413/oneliner/cmdgen.py", line 212, in makeVarBinds >> varVal = varName.getMibNode().getSyntax().clone(varVal) >> AttributeError: 'MibIdentifier' object has no attribute ‘getSyntax' > |
From: Ilya E. <il...@gl...> - 2015-05-19 22:11:26
|
Hi Christopher, Cross-posting from StackOverflow: That looks like a bug in pysnmp -- latest CVS version might not throw that way. However, the root cause of that error is that pysnmp could not find a MIB object corresponding the 1.3.6.1.2.1.31.1.1.1.18.1 OID. That may happen either because MIB that defines that OID is not loaded or OID in question does not correspond to any MIB object. To load IF-MIB you may either do it explicitly: cmdgen.MibVariable('1.3.6.1.2.1.31.1.1.1.18.1').loadMibs('IF-MIB') or use MIB::object.index syntax: cmdgen.MibVariable('IF-MIB', 'ifAlias', 1) You could grab the IF-MIB.py from pysnmp-mibs package available on pypi or compile it from ASN.1 MIB by [experimental] pysmi compiler (http://sf.net/projects/pysmi/ <http://sf.net/projects/pysmi/>) -ilya > On 18 May 2015, at 19:44, Christopher Young <chr...@me...> wrote: > > Hi All, > > Using Python 3.4. Made sure I’m using latest version of pysnmp by pip3 install pysnmp —update > > > 1) This function to set the SYSCONTACT value of a switch works exactly as intended. > > >>> def SNMP_SET_SYSCONTACT(syscontact): > errorIndication, errorStatus, errorIndex, varBinds = cmdGen.setCmd(cmdgen.CommunityData('private'),cmdgen.UdpTransportTarget(('10.101.0.221', 161)),(cmdgen.MibVariable('.1.3.6.1.2.1.1.4.0'), syscontact), lookupNames=False, lookupValues=True) > > > > 2) Substituted in the OID for the 1st ifAlias occurrence in the switch. This throws the exception noted below. No idea why I would be thrown this error for what is essentially the same function. > > I have verified that this OID is writable using a standard MIB browser ( iReasoning ) > > > >>> def SNMP_SET_IFALIAS(ifAlias): > errorIndication, errorStatus, errorIndex, varBinds = cmdGen.setCmd(cmdgen.CommunityData('private'),cmdgen.UdpTransportTarget(('10.101.0.221', 161)),(cmdgen.MibVariable('1.3.6.1.2.1.31.1.1.1.18.1'), ifAlias),lookupValues=False, lookupNames=False) > > Traceback (most recent call last): > File "<pyshell#632>", line 1, in <module> > SNMP_SET_IFALIAS('Check this out') > File "<pyshell#629>", line 2, in SNMP_SET_IFALIAS > errorIndication, errorStatus, errorIndex, varBinds = cmdGen.setCmd(cmdgen.CommunityData('private'),cmdgen.UdpTransportTarget(('10.101.0.221', 161)),(cmdgen.MibVariable('1.3.6.1.2.1.31.1.1.1.18.1'), ifAlias),lookupValues=False, lookupNames=False) > File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pysnmp/entity/rfc3413/oneliner/cmdgen.py", line 452, in setCmd > kwargs.get('contextName', null) > File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pysnmp/entity/rfc3413/oneliner/cmdgen.py", line 314, in setCmd > self.makeVarBinds(varBinds), > File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pysnmp/entity/rfc3413/oneliner/cmdgen.py", line 212, in makeVarBinds > varVal = varName.getMibNode().getSyntax().clone(varVal) > AttributeError: 'MibIdentifier' object has no attribute ‘getSyntax' |
From: Christopher Y. <chr...@me...> - 2015-05-18 16:44:56
|
Hi All, Using Python 3.4. Made sure I’m using latest version of pysnmp by pip3 install pysnmp —update 1) This function to set the SYSCONTACT value of a switch works exactly as intended. >>> def SNMP_SET_SYSCONTACT(syscontact): errorIndication, errorStatus, errorIndex, varBinds = cmdGen.setCmd(cmdgen.CommunityData('private'),cmdgen.UdpTransportTarget(('10.101.0.221', 161)),(cmdgen.MibVariable('.1.3.6.1.2.1.1.4.0'), syscontact), lookupNames=False, lookupValues=True) 2) Substituted in the OID for the 1st ifAlias occurrence in the switch. This throws the exception noted below. No idea why I would be thrown this error for what is essentially the same function. I have verified that this OID is writable using a standard MIB browser ( iReasoning ) >>> def SNMP_SET_IFALIAS(ifAlias): errorIndication, errorStatus, errorIndex, varBinds = cmdGen.setCmd(cmdgen.CommunityData('private'),cmdgen.UdpTransportTarget(('10.101.0.221', 161)),(cmdgen.MibVariable('1.3.6.1.2.1.31.1.1.1.18.1'), ifAlias),lookupValues=False, lookupNames=False) Traceback (most recent call last): File "<pyshell#632>", line 1, in <module> SNMP_SET_IFALIAS('Check this out') File "<pyshell#629>", line 2, in SNMP_SET_IFALIAS errorIndication, errorStatus, errorIndex, varBinds = cmdGen.setCmd(cmdgen.CommunityData('private'),cmdgen.UdpTransportTarget(('10.101.0.221', 161)),(cmdgen.MibVariable('1.3.6.1.2.1.31.1.1.1.18.1'), ifAlias),lookupValues=False, lookupNames=False) File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pysnmp/entity/rfc3413/oneliner/cmdgen.py", line 452, in setCmd kwargs.get('contextName', null) File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pysnmp/entity/rfc3413/oneliner/cmdgen.py", line 314, in setCmd self.makeVarBinds(varBinds), File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pysnmp/entity/rfc3413/oneliner/cmdgen.py", line 212, in makeVarBinds varVal = varName.getMibNode().getSyntax().clone(varVal) AttributeError: 'MibIdentifier' object has no attribute ‘getSyntax' |
From: chetan S. <che...@sy...> - 2015-04-30 14:49:21
|
Hi I tried to populate Table data by taking a reference from this link http://pysnmp.sourceforge.net/examples/current/v3arch/agent/cmdrsp/v2c-custom-tabular-mib-objects.html But i am not able to update table data in agent, so that it will send respond to incoming requests. Can anyone give a any working reference code to get a reference to populate data. Hopefully i will hear soon. -- Regards Chetan Sharma -- This message (and any associated files) is intended only for the use of the individual or entity to which it is addressed and may contain information that is confidential, subject to copyright or constitutes a trade secret. If you are not the intended recipient you are hereby notified that any dissemination, copying or distribution of this message, or files associated with this message, is strictly prohibited. If you have received this message in error, please notify Symstream Technology Group immediately by replying to the message and deleting it from your computer. Messages sent to and from us may be monitored. Internet communications cannot be guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. Therefore, we do not accept responsibility for any errors or omissions that are present in this message, or any attachment, that have arisen as a result of e-mail transmission. If verification is required, please request a hard-copy version. Any views or opinions presented are solely those of the author and do not necessarily represent those of the company. ------------------------------ |
From: Adam B. <Ada...@ji...> - 2015-04-30 01:33:17
|
On 29 Apr 2015, at 20:44, Ilya Etingof <il...@gl...> wrote: > I can't reproduce the .closeTransport() error as well as "exception > ignored" thing. Could you please update your pysnmp sources from CVS and > try again? I've cleaned my environment and reinstalled from CVS and I can't reproduce it. I must have ended up with a broken installation while switching between stable/rc/cvs. Apologies for the confusion. > For MibVariable to work you need to invoke .resolveWithMib() before use > like this: Works perfectly, thanks for the pointer. I'll probably switch to creating a separate MibBuilder as you suggested so I can re-use it between engines. > Hope this helps, It does, thank you again. Regards, Adam Bishop gpg: 0x6609D460 jisc.ac.uk Jisc is a registered charity (number 1149740) and a company limited by guarantee which is registered in England under Company No. 5747339, VAT No. GB 197 0632 86. Jisc’s registered office is: One Castlepark, Tower Hill, Bristol, BS2 0JA. T 0203 697 5800. Jisc Services Limited is a wholly owned Jisc subsidiary and a company limited by guarantee which is registered in England under company number 2881024, VAT number GB 197 0632 86. The registered office is: One Castle Park, Tower Hill, Bristol BS2 0JA. T 0203 697 5800. |
From: Ilya E. <il...@gl...> - 2015-04-29 19:44:49
|
Hi Adam, Thanks for your report! I can't reproduce the .closeTransport() error as well as "exception ignored" thing. Could you please update your pysnmp sources from CVS and try again? For MibVariable to work you need to invoke .resolveWithMib() before use like this: from pysnmp.entity.rfc3413.oneliner.mibvar import MibVariable from pysnmp.smi.view import MibViewController from pysnmp.smi.builder import MibBuilder # this is optional # grab MIB Builder object from running snmpEngine mibBuilder = self._conn.msgAndPduDsp.mibInstrumController.mibBuilder # ... or create a separate one # mibBuilder = MibBuilder() # ... and create MIB view controller on top of it mibViewController = MibViewController(mibBuilder) oid = MibVariable('SNMPv2-MIB', 'sysDescr', 0) # here's a shortcut for adding MIB path to each mibVariable # or you could mibBuilder.get/setMibSources() to configure # it permanently for all mibVariables oid.addMibSource('/path/to/additional/pysnmp/mibs') oid.resolveWithMib(mibViewController) # at this point oid takes shape of a sequence of integers # so that str(oid) or tuple(oid) will return an OID # ... so we can use it for querying snmpOperation(..., oid, ...) Hope this helps, ilya On 04/29/2015 02:03 PM, Adam Bishop wrote: > Hi, > > I've been playing with the new asyncio API; I understand it's not been properly released yet, so "it doesn't do that yet" is an acceptable answer. :) > > First thing I've noticed is the examples don't work out of the box as of a recent CVS change: > > Traceback (most recent call last): > File "get-v2c-custom-timeout.py", line 95, in <module> > ( ('1.3.6.1.2.1.1.1.0', None), ) > File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/asyncio/base_events.py", line 316, in run_until_complete > return future.result() > File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/asyncio/futures.py", line 275, in result > raise self._exception > File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/asyncio/tasks.py", line 236, in _step > result = coro.send(value) > File "get-v2c-custom-timeout.py", line 87, in snmpOperation > udp.domainName > AttributeError: 'NoneType' object has no attribute 'closeTransport' > > Removing closeTransport() fixes that problem though, so that's fine. > > All of the examples currently print "Exception ignored in: %" at the end; this is just an annoyance though. > > The issue I've not been able to work around is how to do MibLookups. > > I've tried combining the MIB lookup example from the onset API and the asyncio get-v2c-custom-timeout.py example, but this earns me "MibVariable object not properly initialized". > > ... > builder = self._conn.msgAndPduDsp.mibInstrumController.mibBuilder > builder.setMibSources(*(builder.getMibSources() + > (pysnmp.smi.builder.DirMibSource(''.join([os.path.dirname(__file__), '/mib'])), ) > ) > ) > ... > oid = pysnmp.entity.rfc3413.oneliner.cmdgen.MibVariable(mib_name, sym_name) > > loop.run_until_complete( > snmpOperation( > snmpEngine, > 'my-router', > None, '', # contextEngineId, contextName > ( (oid, None), ) > ) > ) > ... > > Are MibLookups supported currently using the asyncio API, or am I just going about it in completely the wrong way. > > > Regards, > > Adam Bishop > gpg: 0x6609D460 > |
From: Adam B. <Ada...@ji...> - 2015-04-29 11:03:38
|
Hi, I've been playing with the new asyncio API; I understand it's not been properly released yet, so "it doesn't do that yet" is an acceptable answer. :) First thing I've noticed is the examples don't work out of the box as of a recent CVS change: Traceback (most recent call last): File "get-v2c-custom-timeout.py", line 95, in <module> ( ('1.3.6.1.2.1.1.1.0', None), ) File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/asyncio/base_events.py", line 316, in run_until_complete return future.result() File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/asyncio/futures.py", line 275, in result raise self._exception File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/asyncio/tasks.py", line 236, in _step result = coro.send(value) File "get-v2c-custom-timeout.py", line 87, in snmpOperation udp.domainName AttributeError: 'NoneType' object has no attribute 'closeTransport' Removing closeTransport() fixes that problem though, so that's fine. All of the examples currently print "Exception ignored in: %" at the end; this is just an annoyance though. The issue I've not been able to work around is how to do MibLookups. I've tried combining the MIB lookup example from the onset API and the asyncio get-v2c-custom-timeout.py example, but this earns me "MibVariable object not properly initialized". ... builder = self._conn.msgAndPduDsp.mibInstrumController.mibBuilder builder.setMibSources(*(builder.getMibSources() + (pysnmp.smi.builder.DirMibSource(''.join([os.path.dirname(__file__), '/mib'])), ) ) ) ... oid = pysnmp.entity.rfc3413.oneliner.cmdgen.MibVariable(mib_name, sym_name) loop.run_until_complete( snmpOperation( snmpEngine, 'my-router', None, '', # contextEngineId, contextName ( (oid, None), ) ) ) ... Are MibLookups supported currently using the asyncio API, or am I just going about it in completely the wrong way. Regards, Adam Bishop gpg: 0x6609D460 jisc.ac.uk Jisc is a registered charity (number 1149740) and a company limited by guarantee which is registered in England under Company No. 5747339, VAT No. GB 197 0632 86. Jisc’s registered office is: One Castlepark, Tower Hill, Bristol, BS2 0JA. T 0203 697 5800. Jisc Services Limited is a wholly owned Jisc subsidiary and a company limited by guarantee which is registered in England under company number 2881024, VAT number GB 197 0632 86. The registered office is: One Castle Park, Tower Hill, Bristol BS2 0JA. T 0203 697 5800. |
From: Jeremy A. <ja...@ar...> - 2015-03-28 19:53:50
|
I’m searching for the Cisco Wireless MIB AIRESPACE-WIRELESS-MIB converted to a pysnmp MIB. I’ve attempted to build-pysnmp-mib it but the output appears to be incomplete. Hoping that others have attempted and been successful in the same. |
From: Ilya E. <il...@gl...> - 2015-03-18 07:26:31
|
Hi Tom, Your app could call .getVarBinds()/.getVarBindsList() multiple times in any combination. To give you better understanding, the .getVarBinds() call works like this (pysnmp.proto.api.v1): def getVarBinds(pdu): varBinds = [] for varBind in getVarBindList(pdu): varBinds.append(getOIDVal(varBind)) return varBinds -ilya > On 16 Mar 2015, at 19:09, Tom Kr. <to...@we...> wrote: > > With my test script everything works fine now. > Thank you very much for your support! > > But now I have a new challenge. > > To implement the solution into the production I have a last short question to you. > Is it possible to use the .getVarBinds() method after another script has used the getVarBindsList() method? > > I have the situation that the first script use the getVarBindsList() method. > Unfortunately I couldn't change it to getVarBinds(). So is there any way to convert the data in the same way as it getVarBinds() it does? > > -Tom > > > > >> Am 16.03.2015 um 11:33 schrieb Ilya Etingof <il...@gl...>: >> >> >> Hi Tom, >> >> You can check it like this: >> >> from pyasn1.type.univ import OctetString >> >> if isinstance(val, OctetString): >> val = str(val) >> ... >> >> The str() part is important because you are getting pyasn1 objects in response while "re" expects strings. >> >> -ilya >> >>> On 03/16/2015 01:15 PM, Tom Kr. wrote: >>> Some good news to the beginning of the new week. >>> After I changed the method from .getVarBindsList() to .getVarBinds(), I can read the data with the stupid line feed. >>> Now I tried to search and replace the line feed with this lines >>> for oid, val in varBinds: >>> print("DEBUG_oid: %s" % oid) >>> print("DEUBG_val: %s" % val) >>> new_val = "".join(val) >>> val = re.sub(r"[\r|\s]", "", new_val) >>> print("DEBUG_oid_2: %s" % oid) >>> print("DEBUG_val_2: %s" % val) >>> Each time there is a trap with this characters I get this error message. >>> return _compile(pattern, flags).sub(repl, string, count) >>> ;TypeError: expected string or buffer >>> How can I find out which type the val variable have? >>> And how can I change this to string? >>> Tom >>> >>> >>> >>>> Am 12.03.2015 um 16:18 schrieb Ilya Etingof <il...@gl...>: >>>> >>>> >>>> Right, in 'val' you are getting the whole SNMP PDU value structure, not just a leaf scalar. That's the reason it does not match OctetString class instance check. >>>> >>>> Use .getVarBinds() method instead of .getVarBindsList(). The former returns a list of tuples of terminal values, while the latter returns original var-bindings list from SNMP PDU which always holds a record-like structure for value. >>>> >>>> -ilya >>>> >>>>> On 03/12/2015 05:29 PM, Tom Kr. wrote: >>>>> Hmm, I'm confused. >>>>> With this changes I also get hex values back and I still enter the else part for each value. >>>>> import sys,os >>>>> sys.path.append('/usr/share/pyshared/') >>>>> from pysnmp.carrier.asynsock.dispatch import AsynsockDispatcher >>>>> from pysnmp.carrier.asynsock.dgram import udp, udp6 >>>>> from pyasn1.codec.ber import decoder >>>>> from pysnmp.proto import api >>>>> #from pysnmp.proto.rfc1902 import OctetString >>>>> from pyasn1.type.univ import OctetString >>>>> def pySnmpCheck(oval): >>>>> if isinstance(oval, OctetString): >>>>> print("DEBUG: OctetString") >>>>> val = oval.asOctets() >>>>> else: >>>>> print("DEBUG: else") >>>>> val = oval >>>>> return val >>>>> If this information are useful, this is the header I've got. >>>>> # python snmp-transports.py >>>>> Notification message from (1, 3, 6, 1, 6, 1, 1):('xxx.xxx.xxx.xxx', 52032): >>>>> Enterprise: 1.3.6.1.4.1.18494.2 >>>>> Agent Address: xxx.xxx.xxx.xxx >>>>> Generic Trap: 'enterpriseSpecific' >>>>> Specific Trap: 1 >>>>> Uptime: 1 >>>>> Var-binds: >>>>> DEBUG: else >>>>> 1.3.6.1.4.1.18494.2.1.9 = ObjectSyntax: >>>>> simple=SimpleSyntax: >>>>> string=0x4f70657261746f722058585858585858585858203a20585858585858585858582c2058585858585858202c204c6f63616c6c792061757468656e74696361746564202d207375636365737366756c6c79207369676e6564206f6e20746f20746865207465726d696e616c20275858582e5858582e582e584058272061742031343a3238207573696e672027585858585858585820585858205858585858585858272e0a4f70657261746f722050726f66696c65733a2058585858585858585858585858 >>>>> Tom >>>>> >>>>> >>>>>> Am 12.03.2015 um 14:39 schrieb Ilya Etingof <il...@gl...>: >>>>>> >>>>>> >>>>>> Oh, if you are using SNMPv1 you should check against the base class: >>>>>> >>>>>> from pyasn1.type.univ import OctetString >>>>>> >>>>>> if isinstance(oval, OctetString): >>>>>> ... >>>>>> >>>>>> Perhaps this should be improved in pysnmp. >>>>>> >>>>>> -ilya >>>>>> >>>>>>> On 03/12/2015 04:29 PM, Tom Kr. wrote: >>>>>>> I made the following changes to the script. >>>>>>> ... >>>>>>> from pysnmp.proto.rfc1902 import OctetString >>>>>>> def pySnmpCheck(oval): >>>>>>> if isinstance(oval, OctetString): >>>>>>> print("DEBUG: OctetString") >>>>>>> val = oval.asOctets() >>>>>>> else: >>>>>>> print("DEBUG: else") >>>>>>> val = oval >>>>>>> return val >>>>>>> ... >>>>>>> for oid, val in varBinds: >>>>>>> val = pySnmpCheck(val) >>>>>>> print('%s = %s' % (oid.prettyPrint(), val.prettyPrint())) >>>>>>> ... >>>>>>> Then I start grabbing the snmp messages again. >>>>>>> Unfortunately every value of the message go through the else part. >>>>>>> But how could this happen? >>>>>>> Is there a possibility to check which type of string the values have? >>>>>>> Tom >>>>>>> >>>>>>> >>>>>>> >>>>>>>> Am 11.03.2015 um 14:17 schrieb Ilya Etingof <il...@gl...>: >>>>>>>> >>>>>>>> >>>>>>>> That's right, .asOctets() is only defined for OctetString type and its >>>>>>>> subclasses. Therefore, to deal with octets of OctetString() you should >>>>>>>> do additional check: >>>>>>>> >>>>>>>> from pysnmp.proto.rfc1902 import OctetString >>>>>>>> >>>>>>>> ... >>>>>>>> >>>>>>>> if isinstance(val, OctetString): >>>>>>>> val = val.asOctets() >>>>>>>> >>>>>>>> Keep in mind that octet string is not always the same as printable >>>>>>>> string. The former is not immune to your terminal potentially eating >>>>>>>> non-printable characters or garbling output in a funny way. Also, text >>>>>>>> encoding is not defined by OctetString. To be on a safe side default >>>>>>>> OctetString printout is done in hex whenever a non-printable is seen in >>>>>>>> its contents. >>>>>>>> >>>>>>>> -ilya >>>>>>>> >>>>>>>>>> On 03/11/2015 03:18 PM, Craig Small wrote: >>>>>>>>>> On Wed, Mar 11, 2015 at 07:02:44AM +0100, Tom wrote: >>>>>>>>>> ;AttributeError: ObjectSyntax instance has no attribute 'asOctets' >>>>>>>>> Are you sure each row is returning something asOctets makes sense for? >>>>>>>>> An Integer doesn't make sense. >>>>>>>>> >>>>>>>>>> Does it only works if a hex value is send by snmp? >>>>>>>>> I believe it works for certain types of values, such as an OctetString >>>>>>>>> >>>>>>>>>> How can I check if the value is hex or not? >>>>>>>>> Not sure, but the types are found in pyasn1.type.univ so you could >>>>>>>>> compare it to, say, univ.OctetString >>>>>>>>> >>>>>>>>> ObjectSyntax seems to be the superset of all types, from what I can tell >>>>>>>>> it means pysnmp wasn't sure what the type should be. >>>>>>>>> >>>>>>>>> It's been an interesting and educational discussion anyhow. >>>>>>>>> >>>>>>>>> - Craig >> > > ------------------------------------------------------------------------------ > Dive into the World of Parallel Programming The Go Parallel Website, sponsored > by Intel and developed in partnership with Slashdot Media, is your hub for all > things parallel software development, from weekly thought leadership blogs to > news, videos, case studies, tutorials and more. Take a look and join the > conversation now. http://goparallel.sourceforge.net/ > _______________________________________________ > pysnmp-users mailing list > pys...@li... > https://lists.sourceforge.net/lists/listinfo/pysnmp-users |
From: Tom Kr. <to...@we...> - 2015-03-16 16:09:16
|
With my test script everything works fine now. Thank you very much for your support! But now I have a new challenge. To implement the solution into the production I have a last short question to you. Is it possible to use the .getVarBinds() method after another script has used the getVarBindsList() method? I have the situation that the first script use the getVarBindsList() method. Unfortunately I couldn't change it to getVarBinds(). So is there any way to convert the data in the same way as it getVarBinds() it does? -Tom > Am 16.03.2015 um 11:33 schrieb Ilya Etingof <il...@gl...>: > > > Hi Tom, > > You can check it like this: > > from pyasn1.type.univ import OctetString > > if isinstance(val, OctetString): > val = str(val) > ... > > The str() part is important because you are getting pyasn1 objects in response while "re" expects strings. > > -ilya > >> On 03/16/2015 01:15 PM, Tom Kr. wrote: >> Some good news to the beginning of the new week. >> After I changed the method from .getVarBindsList() to .getVarBinds(), I can read the data with the stupid line feed. >> Now I tried to search and replace the line feed with this lines >> for oid, val in varBinds: >> print("DEBUG_oid: %s" % oid) >> print("DEUBG_val: %s" % val) >> new_val = "".join(val) >> val = re.sub(r"[\r|\s]", "", new_val) >> print("DEBUG_oid_2: %s" % oid) >> print("DEBUG_val_2: %s" % val) >> Each time there is a trap with this characters I get this error message. >> return _compile(pattern, flags).sub(repl, string, count) >> ;TypeError: expected string or buffer >> How can I find out which type the val variable have? >> And how can I change this to string? >> Tom >> >> >> >>> Am 12.03.2015 um 16:18 schrieb Ilya Etingof <il...@gl...>: >>> >>> >>> Right, in 'val' you are getting the whole SNMP PDU value structure, not just a leaf scalar. That's the reason it does not match OctetString class instance check. >>> >>> Use .getVarBinds() method instead of .getVarBindsList(). The former returns a list of tuples of terminal values, while the latter returns original var-bindings list from SNMP PDU which always holds a record-like structure for value. >>> >>> -ilya >>> >>>> On 03/12/2015 05:29 PM, Tom Kr. wrote: >>>> Hmm, I'm confused. >>>> With this changes I also get hex values back and I still enter the else part for each value. >>>> import sys,os >>>> sys.path.append('/usr/share/pyshared/') >>>> from pysnmp.carrier.asynsock.dispatch import AsynsockDispatcher >>>> from pysnmp.carrier.asynsock.dgram import udp, udp6 >>>> from pyasn1.codec.ber import decoder >>>> from pysnmp.proto import api >>>> #from pysnmp.proto.rfc1902 import OctetString >>>> from pyasn1.type.univ import OctetString >>>> def pySnmpCheck(oval): >>>> if isinstance(oval, OctetString): >>>> print("DEBUG: OctetString") >>>> val = oval.asOctets() >>>> else: >>>> print("DEBUG: else") >>>> val = oval >>>> return val >>>> If this information are useful, this is the header I've got. >>>> # python snmp-transports.py >>>> Notification message from (1, 3, 6, 1, 6, 1, 1):('xxx.xxx.xxx.xxx', 52032): >>>> Enterprise: 1.3.6.1.4.1.18494.2 >>>> Agent Address: xxx.xxx.xxx.xxx >>>> Generic Trap: 'enterpriseSpecific' >>>> Specific Trap: 1 >>>> Uptime: 1 >>>> Var-binds: >>>> DEBUG: else >>>> 1.3.6.1.4.1.18494.2.1.9 = ObjectSyntax: >>>> simple=SimpleSyntax: >>>> string=0x4f70657261746f722058585858585858585858203a20585858585858585858582c2058585858585858202c204c6f63616c6c792061757468656e74696361746564202d207375636365737366756c6c79207369676e6564206f6e20746f20746865207465726d696e616c20275858582e5858582e582e584058272061742031343a3238207573696e672027585858585858585820585858205858585858585858272e0a4f70657261746f722050726f66696c65733a2058585858585858585858585858 >>>> Tom >>>> >>>> >>>>> Am 12.03.2015 um 14:39 schrieb Ilya Etingof <il...@gl...>: >>>>> >>>>> >>>>> Oh, if you are using SNMPv1 you should check against the base class: >>>>> >>>>> from pyasn1.type.univ import OctetString >>>>> >>>>> if isinstance(oval, OctetString): >>>>> ... >>>>> >>>>> Perhaps this should be improved in pysnmp. >>>>> >>>>> -ilya >>>>> >>>>>> On 03/12/2015 04:29 PM, Tom Kr. wrote: >>>>>> I made the following changes to the script. >>>>>> ... >>>>>> from pysnmp.proto.rfc1902 import OctetString >>>>>> def pySnmpCheck(oval): >>>>>> if isinstance(oval, OctetString): >>>>>> print("DEBUG: OctetString") >>>>>> val = oval.asOctets() >>>>>> else: >>>>>> print("DEBUG: else") >>>>>> val = oval >>>>>> return val >>>>>> ... >>>>>> for oid, val in varBinds: >>>>>> val = pySnmpCheck(val) >>>>>> print('%s = %s' % (oid.prettyPrint(), val.prettyPrint())) >>>>>> ... >>>>>> Then I start grabbing the snmp messages again. >>>>>> Unfortunately every value of the message go through the else part. >>>>>> But how could this happen? >>>>>> Is there a possibility to check which type of string the values have? >>>>>> Tom >>>>>> >>>>>> >>>>>> >>>>>>> Am 11.03.2015 um 14:17 schrieb Ilya Etingof <il...@gl...>: >>>>>>> >>>>>>> >>>>>>> That's right, .asOctets() is only defined for OctetString type and its >>>>>>> subclasses. Therefore, to deal with octets of OctetString() you should >>>>>>> do additional check: >>>>>>> >>>>>>> from pysnmp.proto.rfc1902 import OctetString >>>>>>> >>>>>>> ... >>>>>>> >>>>>>> if isinstance(val, OctetString): >>>>>>> val = val.asOctets() >>>>>>> >>>>>>> Keep in mind that octet string is not always the same as printable >>>>>>> string. The former is not immune to your terminal potentially eating >>>>>>> non-printable characters or garbling output in a funny way. Also, text >>>>>>> encoding is not defined by OctetString. To be on a safe side default >>>>>>> OctetString printout is done in hex whenever a non-printable is seen in >>>>>>> its contents. >>>>>>> >>>>>>> -ilya >>>>>>> >>>>>>>>> On 03/11/2015 03:18 PM, Craig Small wrote: >>>>>>>>> On Wed, Mar 11, 2015 at 07:02:44AM +0100, Tom wrote: >>>>>>>>> ;AttributeError: ObjectSyntax instance has no attribute 'asOctets' >>>>>>>> Are you sure each row is returning something asOctets makes sense for? >>>>>>>> An Integer doesn't make sense. >>>>>>>> >>>>>>>>> Does it only works if a hex value is send by snmp? >>>>>>>> I believe it works for certain types of values, such as an OctetString >>>>>>>> >>>>>>>>> How can I check if the value is hex or not? >>>>>>>> Not sure, but the types are found in pyasn1.type.univ so you could >>>>>>>> compare it to, say, univ.OctetString >>>>>>>> >>>>>>>> ObjectSyntax seems to be the superset of all types, from what I can tell >>>>>>>> it means pysnmp wasn't sure what the type should be. >>>>>>>> >>>>>>>> It's been an interesting and educational discussion anyhow. >>>>>>>> >>>>>>>> - Craig > |