pysnmp-users Mailing List for SNMP library for Python (Page 2)
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: Andrew G. <ak...@gm...> - 2017-09-11 21:00:32
|
Thank you so much for the quick reply and suggestion. I'll give it a shot On 9/11/2017 11:42 AM, Ilya Etingof wrote: > Hi Andrew, > > To answer your exact question -- you need to pick up the value at the > callback function and pass it up to the caller (via a global variable or > better mutable stack variable). > > BUT! Do not do that! > > You are using a very old pysnmp API! Better use the modern one -- it's > way better: > > > http://pysnmp.sourceforge.net/examples/hlapi/asyncore/sync/manager/cmdgen/snmp-versions.html#snmpv3-auth-md5-privacy-des > > > On 09/11/2017 05:37 PM, Andrew Gallo wrote: >> Greetings: >> >> Using pysnmp 4.3.9 on python 2.7. I'm following the SNMPv3 example at >> >>> http://pysnmp.sourceforge.net/examples/current/v3arch/manager/cmdgen/get-v3.html >>> >> >> How do I assign the returned value to a variable? >> When I issue a command like: >> rtnval = snmpEngine.transportDispatcher.runDispatcher() >> 1.3.6.1.4.1.10002.2.30.1.1.1.3.16793610.1.1 = -100 >> >> But, rtnval is empty: >>>>> type(rtnval) >> <type 'NoneType'> >> >> Is there anyway to extract the value (in this case -100)? >> >> Thank you. >> >> ------------------------------------------------------------------------------ >> >> Check out the vibrant tech community on one of the world's most >> engaging tech sites, Slashdot.org! http://sdm.link/slashdot >> _______________________________________________ >> pysnmp-users mailing list >> pys...@li... >> https://lists.sourceforge.net/lists/listinfo/pysnmp-users > |
From: Ilya E. <il...@gl...> - 2017-09-11 15:42:52
|
Hi Andrew, To answer your exact question -- you need to pick up the value at the callback function and pass it up to the caller (via a global variable or better mutable stack variable). BUT! Do not do that! You are using a very old pysnmp API! Better use the modern one -- it's way better: http://pysnmp.sourceforge.net/examples/hlapi/asyncore/sync/manager/cmdgen/snmp-versions.html#snmpv3-auth-md5-privacy-des On 09/11/2017 05:37 PM, Andrew Gallo wrote: > Greetings: > > Using pysnmp 4.3.9 on python 2.7. I'm following the SNMPv3 example at > >> http://pysnmp.sourceforge.net/examples/current/v3arch/manager/cmdgen/get-v3.html >> > > > How do I assign the returned value to a variable? > When I issue a command like: > rtnval = snmpEngine.transportDispatcher.runDispatcher() > 1.3.6.1.4.1.10002.2.30.1.1.1.3.16793610.1.1 = -100 > > But, rtnval is empty: > >>> type(rtnval) > <type 'NoneType'> > > Is there anyway to extract the value (in this case -100)? > > Thank you. > > ------------------------------------------------------------------------------ > > Check out the vibrant tech community on one of the world's most > engaging tech sites, Slashdot.org! http://sdm.link/slashdot > _______________________________________________ > pysnmp-users mailing list > pys...@li... > https://lists.sourceforge.net/lists/listinfo/pysnmp-users |
From: Andrew G. <ak...@gm...> - 2017-09-11 15:37:40
|
Greetings: Using pysnmp 4.3.9 on python 2.7. I'm following the SNMPv3 example at > http://pysnmp.sourceforge.net/examples/current/v3arch/manager/cmdgen/get-v3.html How do I assign the returned value to a variable? When I issue a command like: rtnval = snmpEngine.transportDispatcher.runDispatcher() 1.3.6.1.4.1.10002.2.30.1.1.1.3.16793610.1.1 = -100 But, rtnval is empty: >>> type(rtnval) <type 'NoneType'> Is there anyway to extract the value (in this case -100)? Thank you. |
From: Frank T. <in...@ho...> - 2017-07-31 22:03:49
|
Thanks for the response Ilya, I realise that is the issue here, but I’m trying to find out how to catch this exception so I can cater for device not currently reachable. It works fine for devices I can reach, but sometimes devices go down, or are not configured correctly. What I’d like to know is how do I deal with this. There is some error handling in the script - so why are we not catching it? (i.e. the ‘if error_condition’). Thanks, Frank On 16 Jul 2017, at 00:02, Frank <in...@ho...<mailto:in...@ho...>> wrote: Hi All, Another observation is that it seems to work fine first time: Returns: No SNMP response received before timeout But then errors out after. if I wait a decent time (60-120 seconds) then it works again the first time, but bombs out again. Might have to do with networking / caching. Regards, Frank On 14 Jul 2017, at 21:25, Frank <in...@ho...<mailto:in...@ho...>> wrote: Hi, Just FYI, The error is identical using Python 3.5: (Apologies - should have sent 3.5 in the first place!). 10.10.10.10 SNMPv1 community string 'public' on port '161: Traceback (most recent call last): File "/Users/guardian/Sync/Projects/test/lib/python3.5/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 142, in handle_write self.socket, outgoingMessage, transportAddress File "/Users/guardian/Sync/Projects/test/lib/python3.5/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 35, in <lambda> self._sendto = lambda s, b, a: s.sendto(b, a) OSError: [Errno 65] No route to host During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/Users/guardian/Sync/Projects/test/lib/python3.5/site-packages/pysnmp/carrier/asyncore/dispatch.py", line 46, in runDispatcher use_poll=True, map=self.__sockMap, count=1) File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncore.py", line 207, in loop poll_fun(timeout, map) File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncore.py", line 188, in poll2 readwrite(obj, flags) File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncore.py", line 123, in readwrite obj.handle_error() File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncore.py", line 110, in readwrite obj.handle_write_event() File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncore.py", line 442, in handle_write_event self.handle_write() File "/Users/guardian/Sync/Projects/test/lib/python3.5/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 148, in handle_write raise error.CarrierError('sendto() failed for %s: %s' % (transportAddress, sys.exc_info()[1])) pysnmp.carrier.error.CarrierError: sendto() failed for ('10.10.10.10', 161): [Errno 65] No route to host During handling of the above exception, another exception occurred: Traceback (most recent call last): File "./networking.py", line 71, in <module> main() File "./networking.py", line 66, in main snmp_query(['10.10.10.10', '10.10.10.20'], 'v1/public:161', ['1.3.6.1.2.1.1.2.0', '1.3.6.1.2.1.1.1.0']) File "./networking.py", line 28, in snmp_query result = snmp_get(target, snmp_str, snmp_port, oids, int(snmp_ver[1:])) File "./networking.py", line 41, in snmp_get *snmp_oids) File "/Users/guardian/Sync/Projects/test/lib/python3.5/site-packages/pysnmp/entity/rfc3413/oneliner/cmdgen.py", line 183, in getCmd **kwargs): File "/Users/guardian/Sync/Projects/test/lib/python3.5/site-packages/pysnmp/hlapi/asyncore/sync/cmdgen.py", line 113, in getCmd snmpEngine.transportDispatcher.runDispatcher() File "/Users/guardian/Sync/Projects/test/lib/python3.5/site-packages/pysnmp/carrier/asyncore/dispatch.py", line 50, in runDispatcher raise PySnmpError('poll error: %s' % ';'.join(format_exception(*exc_info()))) pysnmp.error.PySnmpError: poll error: Traceback (most recent call last): ; File "/Users/guardian/Sync/Projects/test/lib/python3.5/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 142, in handle_write self.socket, outgoingMessage, transportAddress ; File "/Users/guardian/Sync/Projects/test/lib/python3.5/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 35, in <lambda> self._sendto = lambda s, b, a: s.sendto(b, a) ;OSError: [Errno 65] No route to host ; During handling of the above exception, another exception occurred: ;Traceback (most recent call last): ; File "/Users/guardian/Sync/Projects/test/lib/python3.5/site-packages/pysnmp/carrier/asyncore/dispatch.py", line 46, in runDispatcher use_poll=True, map=self.__sockMap, count=1) ; File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncore.py", line 207, in loop poll_fun(timeout, map) ; File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncore.py", line 188, in poll2 readwrite(obj, flags) ; File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncore.py", line 123, in readwrite obj.handle_error() ; File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncore.py", line 110, in readwrite obj.handle_write_event() ; File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncore.py", line 442, in handle_write_event self.handle_write() ; File "/Users/guardian/Sync/Projects/test/lib/python3.5/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 148, in handle_write raise error.CarrierError('sendto() failed for %s: %s' % (transportAddress, sys.exc_info()[1])) ;pysnmp.carrier.error.CarrierError: sendto() failed for ('10.10.10.10', 161): [Errno 65] No route to host Pretty much identical as in 3.6.1 and no - I didn't just do a search and replace!!! :D Frank On 14 Jul 2017, at 20:45, Frank Tonjes <in...@ho...<mailto:in...@ho...>> wrote: Hi All, I've only been using Python since Dec last year, so please excuse my lack of Knowledge, but I'm trying to write a script which tests polling before adding the devices in our 3rd party tools. One of the tests are SNMP. Currently I'm looking at just the SNMP v1/v2c as most of our devices fall into this category (well most are v2c with some old stuff on v1). I've found some examples online and looked at examples others have used and come up with this 'test' script. It's only to test, so I know it's not following good python practice!!!: #!/usr/bin/env python import re from pysnmp.hlapi import * from pysnmp.entity.rfc3413.oneliner import cmdgen def snmp_query(targets, sequence, oids): # If we get single strings, make it a list with 1 item in it! if isinstance(targets, str): targets = list([targets]) if isinstance(oids, str): oids = list([oids]) for target in targets: print(target) for seq in str.split(sequence, sep=','): info = re.search(r'^(v[123])/(.*):(\d+)$', seq) if info: (snmp_ver, snmp_str, snmp_port) = (info.group(1), info.group(2), info.group(3)) print(" SNMP{0} community string '{1}' on port '{2}:".format(snmp_ver, snmp_str, snmp_port)) if snmp_ver == 'v1' or snmp_ver == 'v2': result = snmp_get(target, snmp_str, snmp_port, oids, int(snmp_ver[1:])) print(result) exit() def snmp_get(host, snmp_community, snmp_port, snmp_oids, snmp_ver): cgen = cmdgen.CommandGenerator() if snmp_ver == 1: error_indication, error_status, error_index, varbinds = cgen.getCmd( cmdgen.CommunityData(snmp_community, mpModel=0), cmdgen.UdpTransportTarget((host, snmp_port)), *snmp_oids) elif snmp_ver == 2: error_indication, error_status, error_index, varbinds = cgen.getCmd( cmdgen.CommunityData(snmp_community), cmdgen.UdpTransportTarget((host, snmp_port)), *snmp_oids) else: print("\n ERROR: Only snmp_ver of '1' or '2' is supported using snmp_get!") exit() if error_indication: return error_indication elif error_status: return '%s at %s' % (error_status.prettyPrint(), error_index and varbinds[int(error_index) - 1][0] or '?') else: result = {} for varbind in varbinds: oid, value = varbind result[str(oid)] = str(value) return result def main(): snmp_query(['10.10.10.10', '10.10.10.20'], 'v1/public:161', ['1.3.6.1.2.1.1.2.0', '1.3.6.1.2.1.1.1.0']) exit() if __name__ == "__main__": main() It seems to be failing with pysnmp somewhere and doesn't return any errors within the error handling I've copied from the example section in PySNMP documentation: The output after running the script is: 10.10.10.10 SNMPv1 community string ‘public' on port '161: Traceback (most recent call last): File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 142, in handle_write self.socket, outgoingMessage, transportAddress File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 35, in <lambda> self._sendto = lambda s, b, a: s.sendto(b, a) OSError: [Errno 64] Host is down During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/carrier/asyncore/dispatch.py", line 46, in runDispatcher use_poll=True, map=self.__sockMap, count=1) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 207, in loop poll_fun(timeout, map) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 188, in poll2 readwrite(obj, flags) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 123, in readwrite obj.handle_error() File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 110, in readwrite obj.handle_write_event() File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 442, in handle_write_event self.handle_write() File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 148, in handle_write raise error.CarrierError('sendto() failed for %s: %s' % (transportAddress, sys.exc_info()[1])) pysnmp.carrier.error.CarrierError: sendto() failed for ('10.10.10.10', 161): [Errno 64] Host is down During handling of the above exception, another exception occurred: Traceback (most recent call last): File "./networking.py", line 71, in <module> main() File "./networking.py", line 66, in main snmp_query(['10.10.10.10', '10.10.10.20'], 'v1/public:161', ['1.3.6.1.2.1.1.2.0', '1.3.6.1.2.1.1.1.0']) File "./networking.py", line 28, in snmp_query result = snmp_get(target, snmp_str, snmp_port, oids, int(snmp_ver[1:])) File "./networking.py", line 41, in snmp_get *snmp_oids) File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/entity/rfc3413/oneliner/cmdgen.py", line 183, in getCmd **kwargs): File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/hlapi/asyncore/sync/cmdgen.py", line 113, in getCmd snmpEngine.transportDispatcher.runDispatcher() File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/carrier/asyncore/dispatch.py", line 50, in runDispatcher raise PySnmpError('poll error: %s' % ';'.join(format_exception(*exc_info()))) pysnmp.error.PySnmpError: poll error: Traceback (most recent call last): ; File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 142, in handle_write self.socket, outgoingMessage, transportAddress ; File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 35, in <lambda> self._sendto = lambda s, b, a: s.sendto(b, a) ;OSError: [Errno 64] Host is down ; During handling of the above exception, another exception occurred: ;Traceback (most recent call last): ; File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/carrier/asyncore/dispatch.py", line 46, in runDispatcher use_poll=True, map=self.__sockMap, count=1) ; File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 207, in loop poll_fun(timeout, map) ; File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 188, in poll2 readwrite(obj, flags) ; File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 123, in readwrite obj.handle_error() ; File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 110, in readwrite obj.handle_write_event() ; File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 442, in handle_write_event self.handle_write() ; File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 148, in handle_write raise error.CarrierError('sendto() failed for %s: %s' % (transportAddress, sys.exc_info()[1])) ;pysnmp.carrier.error.CarrierError: sendto() failed for ('10.10.10.10', 161): [Errno 64] Host is down I'm on Python 3.6.1 and saw you only support 3.5 so set up a virtualenv with 3.5 and get exactly the same error. It obviously sees the 'Errno 64', but seems this error is not making it back to the error handling (error_indication or error_status?). I’m on macOS Sierra 10.12.5 and devices are all on my local LAN - nothing fancy either. Any idea where to look - does this look like a bug - or is there something wrong with my implementation? Is there a better or more propper way to do what I'm trying to do? Idea is to have a pollSequence and use the first one that works e.g. pollSequence of 'v2/public:161,v1/readonly:1961' lets me specific 2 different types of polling with version/community/port no. It seems to work fine if the device is reachable via said polling info - but fails like this when the Host is down or doesn't talk SNMP! Any help would be greatly appreciated. I'm planning to do a lot more complex things with SNMP so need to make sure I'm on the right path early on! Regards, Frank ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org<http://slashdot.org/>! http://sdm.link/slashdot _______________________________________________ pysnmp-users mailing list pys...@li...<mailto:pys...@li...> https://lists.sourceforge.net/lists/listinfo/pysnmp-users |
From: Frank T. <in...@ho...> - 2017-07-15 23:02:23
|
Hi All, Another observation is that it seems to work fine first time: Returns: No SNMP response received before timeout But then errors out after. if I wait a decent time (60-120 seconds) then it works again the first time, but bombs out again. Might have to do with networking / caching. Regards, Frank On 14 Jul 2017, at 21:25, Frank <in...@ho...<mailto:in...@ho...>> wrote: Hi, Just FYI, The error is identical using Python 3.5: (Apologies - should have sent 3.5 in the first place!). 10.10.10.10 SNMPv1 community string 'public' on port '161: Traceback (most recent call last): File "/Users/guardian/Sync/Projects/test/lib/python3.5/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 142, in handle_write self.socket, outgoingMessage, transportAddress File "/Users/guardian/Sync/Projects/test/lib/python3.5/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 35, in <lambda> self._sendto = lambda s, b, a: s.sendto(b, a) OSError: [Errno 65] No route to host During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/Users/guardian/Sync/Projects/test/lib/python3.5/site-packages/pysnmp/carrier/asyncore/dispatch.py", line 46, in runDispatcher use_poll=True, map=self.__sockMap, count=1) File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncore.py", line 207, in loop poll_fun(timeout, map) File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncore.py", line 188, in poll2 readwrite(obj, flags) File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncore.py", line 123, in readwrite obj.handle_error() File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncore.py", line 110, in readwrite obj.handle_write_event() File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncore.py", line 442, in handle_write_event self.handle_write() File "/Users/guardian/Sync/Projects/test/lib/python3.5/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 148, in handle_write raise error.CarrierError('sendto() failed for %s: %s' % (transportAddress, sys.exc_info()[1])) pysnmp.carrier.error.CarrierError: sendto() failed for ('10.10.10.10', 161): [Errno 65] No route to host During handling of the above exception, another exception occurred: Traceback (most recent call last): File "./networking.py", line 71, in <module> main() File "./networking.py", line 66, in main snmp_query(['10.10.10.10', '10.10.10.20'], 'v1/public:161', ['1.3.6.1.2.1.1.2.0', '1.3.6.1.2.1.1.1.0']) File "./networking.py", line 28, in snmp_query result = snmp_get(target, snmp_str, snmp_port, oids, int(snmp_ver[1:])) File "./networking.py", line 41, in snmp_get *snmp_oids) File "/Users/guardian/Sync/Projects/test/lib/python3.5/site-packages/pysnmp/entity/rfc3413/oneliner/cmdgen.py", line 183, in getCmd **kwargs): File "/Users/guardian/Sync/Projects/test/lib/python3.5/site-packages/pysnmp/hlapi/asyncore/sync/cmdgen.py", line 113, in getCmd snmpEngine.transportDispatcher.runDispatcher() File "/Users/guardian/Sync/Projects/test/lib/python3.5/site-packages/pysnmp/carrier/asyncore/dispatch.py", line 50, in runDispatcher raise PySnmpError('poll error: %s' % ';'.join(format_exception(*exc_info()))) pysnmp.error.PySnmpError: poll error: Traceback (most recent call last): ; File "/Users/guardian/Sync/Projects/test/lib/python3.5/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 142, in handle_write self.socket, outgoingMessage, transportAddress ; File "/Users/guardian/Sync/Projects/test/lib/python3.5/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 35, in <lambda> self._sendto = lambda s, b, a: s.sendto(b, a) ;OSError: [Errno 65] No route to host ; During handling of the above exception, another exception occurred: ;Traceback (most recent call last): ; File "/Users/guardian/Sync/Projects/test/lib/python3.5/site-packages/pysnmp/carrier/asyncore/dispatch.py", line 46, in runDispatcher use_poll=True, map=self.__sockMap, count=1) ; File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncore.py", line 207, in loop poll_fun(timeout, map) ; File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncore.py", line 188, in poll2 readwrite(obj, flags) ; File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncore.py", line 123, in readwrite obj.handle_error() ; File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncore.py", line 110, in readwrite obj.handle_write_event() ; File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncore.py", line 442, in handle_write_event self.handle_write() ; File "/Users/guardian/Sync/Projects/test/lib/python3.5/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 148, in handle_write raise error.CarrierError('sendto() failed for %s: %s' % (transportAddress, sys.exc_info()[1])) ;pysnmp.carrier.error.CarrierError: sendto() failed for ('10.10.10.10', 161): [Errno 65] No route to host Pretty much identical as in 3.6.1 and no - I didn't just do a search and replace!!! :D Frank On 14 Jul 2017, at 20:45, Frank Tonjes <in...@ho...<mailto:in...@ho...>> wrote: Hi All, I've only been using Python since Dec last year, so please excuse my lack of Knowledge, but I'm trying to write a script which tests polling before adding the devices in our 3rd party tools. One of the tests are SNMP. Currently I'm looking at just the SNMP v1/v2c as most of our devices fall into this category (well most are v2c with some old stuff on v1). I've found some examples online and looked at examples others have used and come up with this 'test' script. It's only to test, so I know it's not following good python practice!!!: #!/usr/bin/env python import re from pysnmp.hlapi import * from pysnmp.entity.rfc3413.oneliner import cmdgen def snmp_query(targets, sequence, oids): # If we get single strings, make it a list with 1 item in it! if isinstance(targets, str): targets = list([targets]) if isinstance(oids, str): oids = list([oids]) for target in targets: print(target) for seq in str.split(sequence, sep=','): info = re.search(r'^(v[123])/(.*):(\d+)$', seq) if info: (snmp_ver, snmp_str, snmp_port) = (info.group(1), info.group(2), info.group(3)) print(" SNMP{0} community string '{1}' on port '{2}:".format(snmp_ver, snmp_str, snmp_port)) if snmp_ver == 'v1' or snmp_ver == 'v2': result = snmp_get(target, snmp_str, snmp_port, oids, int(snmp_ver[1:])) print(result) exit() def snmp_get(host, snmp_community, snmp_port, snmp_oids, snmp_ver): cgen = cmdgen.CommandGenerator() if snmp_ver == 1: error_indication, error_status, error_index, varbinds = cgen.getCmd( cmdgen.CommunityData(snmp_community, mpModel=0), cmdgen.UdpTransportTarget((host, snmp_port)), *snmp_oids) elif snmp_ver == 2: error_indication, error_status, error_index, varbinds = cgen.getCmd( cmdgen.CommunityData(snmp_community), cmdgen.UdpTransportTarget((host, snmp_port)), *snmp_oids) else: print("\n ERROR: Only snmp_ver of '1' or '2' is supported using snmp_get!") exit() if error_indication: return error_indication elif error_status: return '%s at %s' % (error_status.prettyPrint(), error_index and varbinds[int(error_index) - 1][0] or '?') else: result = {} for varbind in varbinds: oid, value = varbind result[str(oid)] = str(value) return result def main(): snmp_query(['10.10.10.10', '10.10.10.20'], 'v1/public:161', ['1.3.6.1.2.1.1.2.0', '1.3.6.1.2.1.1.1.0']) exit() if __name__ == "__main__": main() It seems to be failing with pysnmp somewhere and doesn't return any errors within the error handling I've copied from the example section in PySNMP documentation: The output after running the script is: 10.10.10.10 SNMPv1 community string ‘public' on port '161: Traceback (most recent call last): File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 142, in handle_write self.socket, outgoingMessage, transportAddress File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 35, in <lambda> self._sendto = lambda s, b, a: s.sendto(b, a) OSError: [Errno 64] Host is down During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/carrier/asyncore/dispatch.py", line 46, in runDispatcher use_poll=True, map=self.__sockMap, count=1) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 207, in loop poll_fun(timeout, map) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 188, in poll2 readwrite(obj, flags) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 123, in readwrite obj.handle_error() File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 110, in readwrite obj.handle_write_event() File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 442, in handle_write_event self.handle_write() File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 148, in handle_write raise error.CarrierError('sendto() failed for %s: %s' % (transportAddress, sys.exc_info()[1])) pysnmp.carrier.error.CarrierError: sendto() failed for ('10.10.10.10', 161): [Errno 64] Host is down During handling of the above exception, another exception occurred: Traceback (most recent call last): File "./networking.py", line 71, in <module> main() File "./networking.py", line 66, in main snmp_query(['10.10.10.10', '10.10.10.20'], 'v1/public:161', ['1.3.6.1.2.1.1.2.0', '1.3.6.1.2.1.1.1.0']) File "./networking.py", line 28, in snmp_query result = snmp_get(target, snmp_str, snmp_port, oids, int(snmp_ver[1:])) File "./networking.py", line 41, in snmp_get *snmp_oids) File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/entity/rfc3413/oneliner/cmdgen.py", line 183, in getCmd **kwargs): File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/hlapi/asyncore/sync/cmdgen.py", line 113, in getCmd snmpEngine.transportDispatcher.runDispatcher() File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/carrier/asyncore/dispatch.py", line 50, in runDispatcher raise PySnmpError('poll error: %s' % ';'.join(format_exception(*exc_info()))) pysnmp.error.PySnmpError: poll error: Traceback (most recent call last): ; File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 142, in handle_write self.socket, outgoingMessage, transportAddress ; File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 35, in <lambda> self._sendto = lambda s, b, a: s.sendto(b, a) ;OSError: [Errno 64] Host is down ; During handling of the above exception, another exception occurred: ;Traceback (most recent call last): ; File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/carrier/asyncore/dispatch.py", line 46, in runDispatcher use_poll=True, map=self.__sockMap, count=1) ; File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 207, in loop poll_fun(timeout, map) ; File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 188, in poll2 readwrite(obj, flags) ; File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 123, in readwrite obj.handle_error() ; File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 110, in readwrite obj.handle_write_event() ; File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 442, in handle_write_event self.handle_write() ; File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 148, in handle_write raise error.CarrierError('sendto() failed for %s: %s' % (transportAddress, sys.exc_info()[1])) ;pysnmp.carrier.error.CarrierError: sendto() failed for ('10.10.10.10', 161): [Errno 64] Host is down I'm on Python 3.6.1 and saw you only support 3.5 so set up a virtualenv with 3.5 and get exactly the same error. It obviously sees the 'Errno 64', but seems this error is not making it back to the error handling (error_indication or error_status?). I’m on macOS Sierra 10.12.5 and devices are all on my local LAN - nothing fancy either. Any idea where to look - does this look like a bug - or is there something wrong with my implementation? Is there a better or more propper way to do what I'm trying to do? Idea is to have a pollSequence and use the first one that works e.g. pollSequence of 'v2/public:161,v1/readonly:1961' lets me specific 2 different types of polling with version/community/port no. It seems to work fine if the device is reachable via said polling info - but fails like this when the Host is down or doesn't talk SNMP! Any help would be greatly appreciated. I'm planning to do a lot more complex things with SNMP so need to make sure I'm on the right path early on! Regards, Frank ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org<http://slashdot.org/>! http://sdm.link/slashdot _______________________________________________ pysnmp-users mailing list pys...@li...<mailto:pys...@li...> https://lists.sourceforge.net/lists/listinfo/pysnmp-users |
From: Ilya E. <il...@gl...> - 2017-07-14 22:10:23
|
Hi Frank, It looks like a routing problem on your network. I guess the “No route to host” error might show up when you are trying to send an IP packet to a host which is neither directly connected to your host nor your host has a default route. I’d first make sure that you can ping the hosts 10.10.10.10, 10.10.10.20. The other idea is to enable pysnmp debugging and read the log to see what pysnmp is doing: from pysnmp import debug debug.setLogger(debug.Debug(‘io’)) > > On 14 Jul 2017, at 22:25, Frank Tonjes <in...@ho...> wrote: > > Hi, > > Just FYI, The error is identical using Python 3.5: (Apologies - should have sent 3.5 in the first place!). > > 10.10.10.10 > SNMPv1 community string 'public' on port '161: > Traceback (most recent call last): > File "/Users/guardian/Sync/Projects/test/lib/python3.5/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 142, in handle_write > self.socket, outgoingMessage, transportAddress > File "/Users/guardian/Sync/Projects/test/lib/python3.5/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 35, in <lambda> > self._sendto = lambda s, b, a: s.sendto(b, a) > OSError: [Errno 65] No route to host > > During handling of the above exception, another exception occurred: > > Traceback (most recent call last): > File "/Users/guardian/Sync/Projects/test/lib/python3.5/site-packages/pysnmp/carrier/asyncore/dispatch.py", line 46, in runDispatcher > use_poll=True, map=self.__sockMap, count=1) > File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncore.py", line 207, in loop > poll_fun(timeout, map) > File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncore.py", line 188, in poll2 > readwrite(obj, flags) > File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncore.py", line 123, in readwrite > obj.handle_error() > File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncore.py", line 110, in readwrite > obj.handle_write_event() > File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncore.py", line 442, in handle_write_event > self.handle_write() > File "/Users/guardian/Sync/Projects/test/lib/python3.5/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 148, in handle_write > raise error.CarrierError('sendto() failed for %s: %s' % (transportAddress, sys.exc_info()[1])) > pysnmp.carrier.error.CarrierError: sendto() failed for ('10.10.10.10', 161): [Errno 65] No route to host > > During handling of the above exception, another exception occurred: > > Traceback (most recent call last): > File "./networking.py", line 71, in <module> > main() > File "./networking.py", line 66, in main > snmp_query(['10.10.10.10', '10.10.10.20'], 'v1/public:161', ['1.3.6.1.2.1.1.2.0', '1.3.6.1.2.1.1.1.0']) > File "./networking.py", line 28, in snmp_query > result = snmp_get(target, snmp_str, snmp_port, oids, int(snmp_ver[1:])) > File "./networking.py", line 41, in snmp_get > *snmp_oids) > File "/Users/guardian/Sync/Projects/test/lib/python3.5/site-packages/pysnmp/entity/rfc3413/oneliner/cmdgen.py", line 183, in getCmd > **kwargs): > File "/Users/guardian/Sync/Projects/test/lib/python3.5/site-packages/pysnmp/hlapi/asyncore/sync/cmdgen.py", line 113, in getCmd > snmpEngine.transportDispatcher.runDispatcher() > File "/Users/guardian/Sync/Projects/test/lib/python3.5/site-packages/pysnmp/carrier/asyncore/dispatch.py", line 50, in runDispatcher > raise PySnmpError('poll error: %s' % ';'.join(format_exception(*exc_info()))) > pysnmp.error.PySnmpError: poll error: Traceback (most recent call last): > ; File "/Users/guardian/Sync/Projects/test/lib/python3.5/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 142, in handle_write > self.socket, outgoingMessage, transportAddress > ; File "/Users/guardian/Sync/Projects/test/lib/python3.5/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 35, in <lambda> > self._sendto = lambda s, b, a: s.sendto(b, a) > ;OSError: [Errno 65] No route to host > ; > During handling of the above exception, another exception occurred: > > ;Traceback (most recent call last): > ; File "/Users/guardian/Sync/Projects/test/lib/python3.5/site-packages/pysnmp/carrier/asyncore/dispatch.py", line 46, in runDispatcher > use_poll=True, map=self.__sockMap, count=1) > ; File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncore.py", line 207, in loop > poll_fun(timeout, map) > ; File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncore.py", line 188, in poll2 > readwrite(obj, flags) > ; File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncore.py", line 123, in readwrite > obj.handle_error() > ; File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncore.py", line 110, in readwrite > obj.handle_write_event() > ; File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncore.py", line 442, in handle_write_event > self.handle_write() > ; File "/Users/guardian/Sync/Projects/test/lib/python3.5/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 148, in handle_write > raise error.CarrierError('sendto() failed for %s: %s' % (transportAddress, sys.exc_info()[1])) > ;pysnmp.carrier.error.CarrierError: sendto() failed for ('10.10.10.10', 161): [Errno 65] No route to host > > Pretty much identical as in 3.6.1 and no - I didn't just do a search and replace!!! :D > > Frank > >> On 14 Jul 2017, at 20:45, Frank Tonjes <in...@ho... <mailto:in...@ho...>> wrote: >> >> Hi All, >> >> I've only been using Python since Dec last year, so please excuse my lack of Knowledge, but I'm trying to write a script which tests polling before adding the devices in our 3rd party tools. One of the tests are SNMP. Currently I'm looking at just the SNMP v1/v2c as most of our devices fall into this category (well most are v2c with some old stuff on v1). >> >> I've found some examples online and looked at examples others have used and come up with this 'test' script. It's only to test, so I know it's not following good python practice!!!: >> >> #!/usr/bin/env python >> >> import re >> from pysnmp.hlapi import * >> from pysnmp.entity.rfc3413.oneliner import cmdgen >> >> >> def snmp_query(targets, sequence, oids): >> >> # If we get single strings, make it a list with 1 item in it! >> if isinstance(targets, str): >> targets = list([targets]) >> >> if isinstance(oids, str): >> oids = list([oids]) >> >> for target in targets: >> print(target) >> >> for seq in str.split(sequence, sep=','): >> >> info = re.search(r'^(v[123])/(.*):(\d+)$', seq) >> if info: >> >> (snmp_ver, snmp_str, snmp_port) = (info.group(1), info.group(2), info.group(3)) >> print(" SNMP{0} community string '{1}' on port '{2}:".format(snmp_ver, snmp_str, snmp_port)) >> >> if snmp_ver == 'v1' or snmp_ver == 'v2': >> result = snmp_get(target, snmp_str, snmp_port, oids, int(snmp_ver[1:])) >> print(result) >> >> exit() >> >> >> def snmp_get(host, snmp_community, snmp_port, snmp_oids, snmp_ver): >> >> cgen = cmdgen.CommandGenerator() >> >> if snmp_ver == 1: >> error_indication, error_status, error_index, varbinds = cgen.getCmd( >> cmdgen.CommunityData(snmp_community, mpModel=0), cmdgen.UdpTransportTarget((host, snmp_port)), >> *snmp_oids) >> elif snmp_ver == 2: >> error_indication, error_status, error_index, varbinds = cgen.getCmd( >> cmdgen.CommunityData(snmp_community), cmdgen.UdpTransportTarget((host, snmp_port)), >> *snmp_oids) >> else: >> print("\n ERROR: Only snmp_ver of '1' or '2' is supported using snmp_get!") >> exit() >> >> if error_indication: >> return error_indication >> elif error_status: >> return '%s at %s' % (error_status.prettyPrint(), error_index and varbinds[int(error_index) - 1][0] or '?') >> else: >> result = {} >> for varbind in varbinds: >> >> oid, value = varbind >> result[str(oid)] = str(value) >> >> return result >> >> >> def main(): >> >> snmp_query(['10.10.10.10', '10.10.10.20'], 'v1/public:161', ['1.3.6.1.2.1.1.2.0', '1.3.6.1.2.1.1.1.0']) >> exit() >> >> >> if __name__ == "__main__": >> main() >> >> >> It seems to be failing with pysnmp somewhere and doesn't return any errors within the error handling I've copied from the example section in PySNMP documentation: >> >> The output after running the script is: >> >> 10.10.10.10 >> SNMPv1 community string ‘public' on port '161: >> Traceback (most recent call last): >> File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 142, in handle_write >> self.socket, outgoingMessage, transportAddress >> File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 35, in <lambda> >> self._sendto = lambda s, b, a: s.sendto(b, a) >> OSError: [Errno 64] Host is down >> >> During handling of the above exception, another exception occurred: >> >> Traceback (most recent call last): >> File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/carrier/asyncore/dispatch.py", line 46, in runDispatcher >> use_poll=True, map=self.__sockMap, count=1) >> File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 207, in loop >> poll_fun(timeout, map) >> File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 188, in poll2 >> readwrite(obj, flags) >> File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 123, in readwrite >> obj.handle_error() >> File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 110, in readwrite >> obj.handle_write_event() >> File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 442, in handle_write_event >> self.handle_write() >> File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 148, in handle_write >> raise error.CarrierError('sendto() failed for %s: %s' % (transportAddress, sys.exc_info()[1])) >> pysnmp.carrier.error.CarrierError: sendto() failed for ('10.10.10.10', 161): [Errno 64] Host is down >> >> During handling of the above exception, another exception occurred: >> >> Traceback (most recent call last): >> File "./networking.py", line 71, in <module> >> main() >> File "./networking.py", line 66, in main >> snmp_query(['10.10.10.10', '10.10.10.20'], 'v1/public:161', ['1.3.6.1.2.1.1.2.0', '1.3.6.1.2.1.1.1.0']) >> File "./networking.py", line 28, in snmp_query >> result = snmp_get(target, snmp_str, snmp_port, oids, int(snmp_ver[1:])) >> File "./networking.py", line 41, in snmp_get >> *snmp_oids) >> File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/entity/rfc3413/oneliner/cmdgen.py", line 183, in getCmd >> **kwargs): >> File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/hlapi/asyncore/sync/cmdgen.py", line 113, in getCmd >> snmpEngine.transportDispatcher.runDispatcher() >> File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/carrier/asyncore/dispatch.py", line 50, in runDispatcher >> raise PySnmpError('poll error: %s' % ';'.join(format_exception(*exc_info()))) >> pysnmp.error.PySnmpError: poll error: Traceback (most recent call last): >> ; File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 142, in handle_write >> self.socket, outgoingMessage, transportAddress >> ; File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 35, in <lambda> >> self._sendto = lambda s, b, a: s.sendto(b, a) >> ;OSError: [Errno 64] Host is down >> ; >> During handling of the above exception, another exception occurred: >> >> ;Traceback (most recent call last): >> ; File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/carrier/asyncore/dispatch.py", line 46, in runDispatcher >> use_poll=True, map=self.__sockMap, count=1) >> ; File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 207, in loop >> poll_fun(timeout, map) >> ; File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 188, in poll2 >> readwrite(obj, flags) >> ; File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 123, in readwrite >> obj.handle_error() >> ; File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 110, in readwrite >> obj.handle_write_event() >> ; File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 442, in handle_write_event >> self.handle_write() >> ; File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 148, in handle_write >> raise error.CarrierError('sendto() failed for %s: %s' % (transportAddress, sys.exc_info()[1])) >> ;pysnmp.carrier.error.CarrierError: sendto() failed for ('10.10.10.10', 161): [Errno 64] Host is down >> >> >> I'm on Python 3.6.1 and saw you only support 3.5 so set up a virtualenv with 3.5 and get exactly the same error. It obviously sees the 'Errno 64', but seems this error is not making it back to the error handling (error_indication or error_status?). >> I’m on macOS Sierra 10.12.5 and devices are all on my local LAN - nothing fancy either. >> >> Any idea where to look - does this look like a bug - or is there something wrong with my implementation? Is there a better or more propper way to do what I'm trying to do? >> Idea is to have a pollSequence and use the first one that works e.g. pollSequence of 'v2/public:161,v1/readonly:1961' lets me specific 2 different types of polling with version/community/port no. >> It seems to work fine if the device is reachable via said polling info - but fails like this when the Host is down or doesn't talk SNMP! >> >> Any help would be greatly appreciated. I'm planning to do a lot more complex things with SNMP so need to make sure I'm on the right path early on! >> >> Regards, >> >> Frank >> ------------------------------- |
From: Frank T. <in...@ho...> - 2017-07-14 20:25:23
|
Hi, Just FYI, The error is identical using Python 3.5: (Apologies - should have sent 3.5 in the first place!). 10.10.10.10 SNMPv1 community string 'public' on port '161: Traceback (most recent call last): File "/Users/guardian/Sync/Projects/test/lib/python3.5/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 142, in handle_write self.socket, outgoingMessage, transportAddress File "/Users/guardian/Sync/Projects/test/lib/python3.5/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 35, in <lambda> self._sendto = lambda s, b, a: s.sendto(b, a) OSError: [Errno 65] No route to host During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/Users/guardian/Sync/Projects/test/lib/python3.5/site-packages/pysnmp/carrier/asyncore/dispatch.py", line 46, in runDispatcher use_poll=True, map=self.__sockMap, count=1) File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncore.py", line 207, in loop poll_fun(timeout, map) File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncore.py", line 188, in poll2 readwrite(obj, flags) File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncore.py", line 123, in readwrite obj.handle_error() File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncore.py", line 110, in readwrite obj.handle_write_event() File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncore.py", line 442, in handle_write_event self.handle_write() File "/Users/guardian/Sync/Projects/test/lib/python3.5/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 148, in handle_write raise error.CarrierError('sendto() failed for %s: %s' % (transportAddress, sys.exc_info()[1])) pysnmp.carrier.error.CarrierError: sendto() failed for ('10.10.10.10', 161): [Errno 65] No route to host During handling of the above exception, another exception occurred: Traceback (most recent call last): File "./networking.py", line 71, in <module> main() File "./networking.py", line 66, in main snmp_query(['10.10.10.10', '10.10.10.20'], 'v1/public:161', ['1.3.6.1.2.1.1.2.0', '1.3.6.1.2.1.1.1.0']) File "./networking.py", line 28, in snmp_query result = snmp_get(target, snmp_str, snmp_port, oids, int(snmp_ver[1:])) File "./networking.py", line 41, in snmp_get *snmp_oids) File "/Users/guardian/Sync/Projects/test/lib/python3.5/site-packages/pysnmp/entity/rfc3413/oneliner/cmdgen.py", line 183, in getCmd **kwargs): File "/Users/guardian/Sync/Projects/test/lib/python3.5/site-packages/pysnmp/hlapi/asyncore/sync/cmdgen.py", line 113, in getCmd snmpEngine.transportDispatcher.runDispatcher() File "/Users/guardian/Sync/Projects/test/lib/python3.5/site-packages/pysnmp/carrier/asyncore/dispatch.py", line 50, in runDispatcher raise PySnmpError('poll error: %s' % ';'.join(format_exception(*exc_info()))) pysnmp.error.PySnmpError: poll error: Traceback (most recent call last): ; File "/Users/guardian/Sync/Projects/test/lib/python3.5/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 142, in handle_write self.socket, outgoingMessage, transportAddress ; File "/Users/guardian/Sync/Projects/test/lib/python3.5/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 35, in <lambda> self._sendto = lambda s, b, a: s.sendto(b, a) ;OSError: [Errno 65] No route to host ; During handling of the above exception, another exception occurred: ;Traceback (most recent call last): ; File "/Users/guardian/Sync/Projects/test/lib/python3.5/site-packages/pysnmp/carrier/asyncore/dispatch.py", line 46, in runDispatcher use_poll=True, map=self.__sockMap, count=1) ; File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncore.py", line 207, in loop poll_fun(timeout, map) ; File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncore.py", line 188, in poll2 readwrite(obj, flags) ; File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncore.py", line 123, in readwrite obj.handle_error() ; File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncore.py", line 110, in readwrite obj.handle_write_event() ; File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncore.py", line 442, in handle_write_event self.handle_write() ; File "/Users/guardian/Sync/Projects/test/lib/python3.5/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 148, in handle_write raise error.CarrierError('sendto() failed for %s: %s' % (transportAddress, sys.exc_info()[1])) ;pysnmp.carrier.error.CarrierError: sendto() failed for ('10.10.10.10', 161): [Errno 65] No route to host Pretty much identical as in 3.6.1 and no - I didn't just do a search and replace!!! :D Frank On 14 Jul 2017, at 20:45, Frank Tonjes <in...@ho...<mailto:in...@ho...>> wrote: Hi All, I've only been using Python since Dec last year, so please excuse my lack of Knowledge, but I'm trying to write a script which tests polling before adding the devices in our 3rd party tools. One of the tests are SNMP. Currently I'm looking at just the SNMP v1/v2c as most of our devices fall into this category (well most are v2c with some old stuff on v1). I've found some examples online and looked at examples others have used and come up with this 'test' script. It's only to test, so I know it's not following good python practice!!!: #!/usr/bin/env python import re from pysnmp.hlapi import * from pysnmp.entity.rfc3413.oneliner import cmdgen def snmp_query(targets, sequence, oids): # If we get single strings, make it a list with 1 item in it! if isinstance(targets, str): targets = list([targets]) if isinstance(oids, str): oids = list([oids]) for target in targets: print(target) for seq in str.split(sequence, sep=','): info = re.search(r'^(v[123])/(.*):(\d+)$', seq) if info: (snmp_ver, snmp_str, snmp_port) = (info.group(1), info.group(2), info.group(3)) print(" SNMP{0} community string '{1}' on port '{2}:".format(snmp_ver, snmp_str, snmp_port)) if snmp_ver == 'v1' or snmp_ver == 'v2': result = snmp_get(target, snmp_str, snmp_port, oids, int(snmp_ver[1:])) print(result) exit() def snmp_get(host, snmp_community, snmp_port, snmp_oids, snmp_ver): cgen = cmdgen.CommandGenerator() if snmp_ver == 1: error_indication, error_status, error_index, varbinds = cgen.getCmd( cmdgen.CommunityData(snmp_community, mpModel=0), cmdgen.UdpTransportTarget((host, snmp_port)), *snmp_oids) elif snmp_ver == 2: error_indication, error_status, error_index, varbinds = cgen.getCmd( cmdgen.CommunityData(snmp_community), cmdgen.UdpTransportTarget((host, snmp_port)), *snmp_oids) else: print("\n ERROR: Only snmp_ver of '1' or '2' is supported using snmp_get!") exit() if error_indication: return error_indication elif error_status: return '%s at %s' % (error_status.prettyPrint(), error_index and varbinds[int(error_index) - 1][0] or '?') else: result = {} for varbind in varbinds: oid, value = varbind result[str(oid)] = str(value) return result def main(): snmp_query(['10.10.10.10', '10.10.10.20'], 'v1/public:161', ['1.3.6.1.2.1.1.2.0', '1.3.6.1.2.1.1.1.0']) exit() if __name__ == "__main__": main() It seems to be failing with pysnmp somewhere and doesn't return any errors within the error handling I've copied from the example section in PySNMP documentation: The output after running the script is: 10.10.10.10 SNMPv1 community string ‘public' on port '161: Traceback (most recent call last): File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 142, in handle_write self.socket, outgoingMessage, transportAddress File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 35, in <lambda> self._sendto = lambda s, b, a: s.sendto(b, a) OSError: [Errno 64] Host is down During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/carrier/asyncore/dispatch.py", line 46, in runDispatcher use_poll=True, map=self.__sockMap, count=1) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 207, in loop poll_fun(timeout, map) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 188, in poll2 readwrite(obj, flags) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 123, in readwrite obj.handle_error() File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 110, in readwrite obj.handle_write_event() File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 442, in handle_write_event self.handle_write() File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 148, in handle_write raise error.CarrierError('sendto() failed for %s: %s' % (transportAddress, sys.exc_info()[1])) pysnmp.carrier.error.CarrierError: sendto() failed for ('10.10.10.10', 161): [Errno 64] Host is down During handling of the above exception, another exception occurred: Traceback (most recent call last): File "./networking.py", line 71, in <module> main() File "./networking.py", line 66, in main snmp_query(['10.10.10.10', '10.10.10.20'], 'v1/public:161', ['1.3.6.1.2.1.1.2.0', '1.3.6.1.2.1.1.1.0']) File "./networking.py", line 28, in snmp_query result = snmp_get(target, snmp_str, snmp_port, oids, int(snmp_ver[1:])) File "./networking.py", line 41, in snmp_get *snmp_oids) File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/entity/rfc3413/oneliner/cmdgen.py", line 183, in getCmd **kwargs): File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/hlapi/asyncore/sync/cmdgen.py", line 113, in getCmd snmpEngine.transportDispatcher.runDispatcher() File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/carrier/asyncore/dispatch.py", line 50, in runDispatcher raise PySnmpError('poll error: %s' % ';'.join(format_exception(*exc_info()))) pysnmp.error.PySnmpError: poll error: Traceback (most recent call last): ; File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 142, in handle_write self.socket, outgoingMessage, transportAddress ; File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 35, in <lambda> self._sendto = lambda s, b, a: s.sendto(b, a) ;OSError: [Errno 64] Host is down ; During handling of the above exception, another exception occurred: ;Traceback (most recent call last): ; File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/carrier/asyncore/dispatch.py", line 46, in runDispatcher use_poll=True, map=self.__sockMap, count=1) ; File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 207, in loop poll_fun(timeout, map) ; File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 188, in poll2 readwrite(obj, flags) ; File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 123, in readwrite obj.handle_error() ; File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 110, in readwrite obj.handle_write_event() ; File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 442, in handle_write_event self.handle_write() ; File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 148, in handle_write raise error.CarrierError('sendto() failed for %s: %s' % (transportAddress, sys.exc_info()[1])) ;pysnmp.carrier.error.CarrierError: sendto() failed for ('10.10.10.10', 161): [Errno 64] Host is down I'm on Python 3.6.1 and saw you only support 3.5 so set up a virtualenv with 3.5 and get exactly the same error. It obviously sees the 'Errno 64', but seems this error is not making it back to the error handling (error_indication or error_status?). I’m on macOS Sierra 10.12.5 and devices are all on my local LAN - nothing fancy either. Any idea where to look - does this look like a bug - or is there something wrong with my implementation? Is there a better or more propper way to do what I'm trying to do? Idea is to have a pollSequence and use the first one that works e.g. pollSequence of 'v2/public:161,v1/readonly:1961' lets me specific 2 different types of polling with version/community/port no. It seems to work fine if the device is reachable via said polling info - but fails like this when the Host is down or doesn't talk SNMP! Any help would be greatly appreciated. I'm planning to do a lot more complex things with SNMP so need to make sure I'm on the right path early on! Regards, Frank ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org<http://Slashdot.org>! http://sdm.link/slashdot _______________________________________________ pysnmp-users mailing list pys...@li...<mailto:pys...@li...> https://lists.sourceforge.net/lists/listinfo/pysnmp-users |
From: Frank T. <in...@ho...> - 2017-07-14 19:46:02
|
Hi All, I've only been using Python since Dec last year, so please excuse my lack of Knowledge, but I'm trying to write a script which tests polling before adding the devices in our 3rd party tools. One of the tests are SNMP. Currently I'm looking at just the SNMP v1/v2c as most of our devices fall into this category (well most are v2c with some old stuff on v1). I've found some examples online and looked at examples others have used and come up with this 'test' script. It's only to test, so I know it's not following good python practice!!!: #!/usr/bin/env python import re from pysnmp.hlapi import * from pysnmp.entity.rfc3413.oneliner import cmdgen def snmp_query(targets, sequence, oids): # If we get single strings, make it a list with 1 item in it! if isinstance(targets, str): targets = list([targets]) if isinstance(oids, str): oids = list([oids]) for target in targets: print(target) for seq in str.split(sequence, sep=','): info = re.search(r'^(v[123])/(.*):(\d+)$', seq) if info: (snmp_ver, snmp_str, snmp_port) = (info.group(1), info.group(2), info.group(3)) print(" SNMP{0} community string '{1}' on port '{2}:".format(snmp_ver, snmp_str, snmp_port)) if snmp_ver == 'v1' or snmp_ver == 'v2': result = snmp_get(target, snmp_str, snmp_port, oids, int(snmp_ver[1:])) print(result) exit() def snmp_get(host, snmp_community, snmp_port, snmp_oids, snmp_ver): cgen = cmdgen.CommandGenerator() if snmp_ver == 1: error_indication, error_status, error_index, varbinds = cgen.getCmd( cmdgen.CommunityData(snmp_community, mpModel=0), cmdgen.UdpTransportTarget((host, snmp_port)), *snmp_oids) elif snmp_ver == 2: error_indication, error_status, error_index, varbinds = cgen.getCmd( cmdgen.CommunityData(snmp_community), cmdgen.UdpTransportTarget((host, snmp_port)), *snmp_oids) else: print("\n ERROR: Only snmp_ver of '1' or '2' is supported using snmp_get!") exit() if error_indication: return error_indication elif error_status: return '%s at %s' % (error_status.prettyPrint(), error_index and varbinds[int(error_index) - 1][0] or '?') else: result = {} for varbind in varbinds: oid, value = varbind result[str(oid)] = str(value) return result def main(): snmp_query(['10.10.10.10', '10.10.10.20'], 'v1/public:161', ['1.3.6.1.2.1.1.2.0', '1.3.6.1.2.1.1.1.0']) exit() if __name__ == "__main__": main() It seems to be failing with pysnmp somewhere and doesn't return any errors within the error handling I've copied from the example section in PySNMP documentation: The output after running the script is: 10.10.10.10 SNMPv1 community string ‘public' on port '161: Traceback (most recent call last): File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 142, in handle_write self.socket, outgoingMessage, transportAddress File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 35, in <lambda> self._sendto = lambda s, b, a: s.sendto(b, a) OSError: [Errno 64] Host is down During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/carrier/asyncore/dispatch.py", line 46, in runDispatcher use_poll=True, map=self.__sockMap, count=1) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 207, in loop poll_fun(timeout, map) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 188, in poll2 readwrite(obj, flags) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 123, in readwrite obj.handle_error() File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 110, in readwrite obj.handle_write_event() File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 442, in handle_write_event self.handle_write() File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 148, in handle_write raise error.CarrierError('sendto() failed for %s: %s' % (transportAddress, sys.exc_info()[1])) pysnmp.carrier.error.CarrierError: sendto() failed for ('10.10.10.10', 161): [Errno 64] Host is down During handling of the above exception, another exception occurred: Traceback (most recent call last): File "./networking.py", line 71, in <module> main() File "./networking.py", line 66, in main snmp_query(['10.10.10.10', '10.10.10.20'], 'v1/public:161', ['1.3.6.1.2.1.1.2.0', '1.3.6.1.2.1.1.1.0']) File "./networking.py", line 28, in snmp_query result = snmp_get(target, snmp_str, snmp_port, oids, int(snmp_ver[1:])) File "./networking.py", line 41, in snmp_get *snmp_oids) File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/entity/rfc3413/oneliner/cmdgen.py", line 183, in getCmd **kwargs): File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/hlapi/asyncore/sync/cmdgen.py", line 113, in getCmd snmpEngine.transportDispatcher.runDispatcher() File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/carrier/asyncore/dispatch.py", line 50, in runDispatcher raise PySnmpError('poll error: %s' % ';'.join(format_exception(*exc_info()))) pysnmp.error.PySnmpError: poll error: Traceback (most recent call last): ; File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 142, in handle_write self.socket, outgoingMessage, transportAddress ; File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 35, in <lambda> self._sendto = lambda s, b, a: s.sendto(b, a) ;OSError: [Errno 64] Host is down ; During handling of the above exception, another exception occurred: ;Traceback (most recent call last): ; File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/carrier/asyncore/dispatch.py", line 46, in runDispatcher use_poll=True, map=self.__sockMap, count=1) ; File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 207, in loop poll_fun(timeout, map) ; File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 188, in poll2 readwrite(obj, flags) ; File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 123, in readwrite obj.handle_error() ; File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 110, in readwrite obj.handle_write_event() ; File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 442, in handle_write_event self.handle_write() ; File "/Users/guardian/Sync/Projects/serenity/lib/python3.6/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 148, in handle_write raise error.CarrierError('sendto() failed for %s: %s' % (transportAddress, sys.exc_info()[1])) ;pysnmp.carrier.error.CarrierError: sendto() failed for ('10.10.10.10', 161): [Errno 64] Host is down I'm on Python 3.6.1 and saw you only support 3.5 so set up a virtualenv with 3.5 and get exactly the same error. It obviously sees the 'Errno 64', but seems this error is not making it back to the error handling (error_indication or error_status?). I’m on macOS Sierra 10.12.5 and devices are all on my local LAN - nothing fancy either. Any idea where to look - does this look like a bug - or is there something wrong with my implementation? Is there a better or more propper way to do what I'm trying to do? Idea is to have a pollSequence and use the first one that works e.g. pollSequence of 'v2/public:161,v1/readonly:1961' lets me specific 2 different types of polling with version/community/port no. It seems to work fine if the device is reachable via said polling info - but fails like this when the Host is down or doesn't talk SNMP! Any help would be greatly appreciated. I'm planning to do a lot more complex things with SNMP so need to make sure I'm on the right path early on! Regards, Frank |
From: William S. <w_...@co...> - 2017-04-08 22:07:01
|
Ah: http://stackoverflow.com/questions/3730925/pysnmp-error-pysnmp-smi-error-smierror pip install pysnmp-mibs Thank You Stack Overflow! > On Apr 8, 2017, at 3:06 PM, William Smith <w_...@co...> wrote: > > I’m trying to upgrade a Raspberry Pi SNMP app from Wheezy to Jessie, and I’m getting the following error: > > Code Snippet: > > IP='192.168.3.210' > > Port = 1 > In_OID = cmdgen.MibVariable('IF-MIB', 'ifInOctets', Port) > Out_OID =cmdgen.MibVariable('IF-MIB', 'ifOutOctets', Port) > # a bunch of integer values (some negative dBm) > AirRxPowerAntennaA = cmdgen.MibVariable('1.3.6.1.4.1.4458.1000.1.5.56.2.0') > AirRxPowerAntennaB = cmdgen.MibVariable('1.3.6.1.4.1.4458.1000.1.5.56.3.0') > AirCurrentFreq = cmdgen.MibVariable('1.3.6.1.4.1.4458.1000.1.5.16.0') > AirLinkDistance = cmdgen.MibVariable('1.3.6.1.4.1.4458.1000.1.5.29.0') > AccumulatedUAS = cmdgen.MibVariable('1.3.6.1.4.1.4458.1000.1.5.61.0') > > #SNMP handle > cmdGen = cmdgen.CommandGenerator() > > # get Heaving Down Dock numbers > HDDerrorIndication, HDDerrorStatus, HDDerrorIndex, HDDvarBinds = cmdGen.getCmd( > cmdgen.CommunityData('public',mpModel=0), > cmdgen.UdpTransportTarget((IP, 161)), > In_OID,Out_OID, > AirRxPowerAntennaA,AirRxPowerAntennaB, > AirCurrentFreq,AirLinkDistance,AccumulatedUAS > ) > > > but when I run it I get: > > File "Airmux.py", line 67, in <module> > AirCurrentFreq,AirLinkDistance,AccumulatedUAS > File "build/bdist.linux-armv7l/egg/pysnmp/entity/rfc3413/oneliner/cmdgen.py", line 183, in getCmd > File "build/bdist.linux-armv7l/egg/pysnmp/hlapi/asyncore/sync/cmdgen.py", line 111, in getCmd > File "build/bdist.linux-armv7l/egg/pysnmp/hlapi/asyncore/cmdgen.py", line 129, in getCmd > File "build/bdist.linux-armv7l/egg/pysnmp/hlapi/varbinds.py", line 39, in makeVarBinds > File "build/bdist.linux-armv7l/egg/pysnmp/smi/rfc1902.py", line 845, in resolveWithMib > File "build/bdist.linux-armv7l/egg/pysnmp/smi/rfc1902.py", line 481, in resolveWithMib > File "build/bdist.linux-armv7l/egg/pysnmp/smi/builder.py", line 400, in importSymbols > File "build/bdist.linux-armv7l/egg/pysnmp/smi/builder.py", line 370, in loadModules > pysnmp.smi.error.MibNotFoundError: IF-MIB compilation error(s): missing > > > But I can’t tell what’s missing, or what I’m doing wrong. > > Any thoughts? > > Thanks! > > William Smith > w_...@co... > |
From: Ilya E. <il...@gl...> - 2017-04-08 20:36:18
|
Hi William, This might mean that the `IF-MIB.py` module can’t be found (missing). There are many ways to fix this: * install pysmi package so it will search for ASN.1 MIBs and convert them into *.py automatically * install pysmi package, compile MIBs you need manually (with the `mibdump.py` tool) and let pysnmp use them * install [depricated] pysnmp-mibs Python package For better understanding of what is happening you may want to enable pysnmp debugging and watch for its attempt to deal with IF-MIB: from pysnmp.debug debug.setLogger(debug.Debug(‘all’)) If you have pysmi package installed, the problem might be that it can’t find ASN.1 MIBs on your system. > On 8 Apr 2017, at 21:06, William Smith <w_...@co...> wrote: > > I’m trying to upgrade a Raspberry Pi SNMP app from Wheezy to Jessie, and I’m getting the following error: > > Code Snippet: > > IP='192.168.3.210' > > Port = 1 > In_OID = cmdgen.MibVariable('IF-MIB', 'ifInOctets', Port) > Out_OID =cmdgen.MibVariable('IF-MIB', 'ifOutOctets', Port) > # a bunch of integer values (some negative dBm) > AirRxPowerAntennaA = cmdgen.MibVariable('1.3.6.1.4.1.4458.1000.1.5.56.2.0') > AirRxPowerAntennaB = cmdgen.MibVariable('1.3.6.1.4.1.4458.1000.1.5.56.3.0') > AirCurrentFreq = cmdgen.MibVariable('1.3.6.1.4.1.4458.1000.1.5.16.0') > AirLinkDistance = cmdgen.MibVariable('1.3.6.1.4.1.4458.1000.1.5.29.0') > AccumulatedUAS = cmdgen.MibVariable('1.3.6.1.4.1.4458.1000.1.5.61.0') > > #SNMP handle > cmdGen = cmdgen.CommandGenerator() > > # get Heaving Down Dock numbers > HDDerrorIndication, HDDerrorStatus, HDDerrorIndex, HDDvarBinds = cmdGen.getCmd( > cmdgen.CommunityData('public',mpModel=0), > cmdgen.UdpTransportTarget((IP, 161)), > In_OID,Out_OID, > AirRxPowerAntennaA,AirRxPowerAntennaB, > AirCurrentFreq,AirLinkDistance,AccumulatedUAS > ) > > > but when I run it I get: > > File "Airmux.py", line 67, in <module> > AirCurrentFreq,AirLinkDistance,AccumulatedUAS > File "build/bdist.linux-armv7l/egg/pysnmp/entity/rfc3413/oneliner/cmdgen.py", line 183, in getCmd > File "build/bdist.linux-armv7l/egg/pysnmp/hlapi/asyncore/sync/cmdgen.py", line 111, in getCmd > File "build/bdist.linux-armv7l/egg/pysnmp/hlapi/asyncore/cmdgen.py", line 129, in getCmd > File "build/bdist.linux-armv7l/egg/pysnmp/hlapi/varbinds.py", line 39, in makeVarBinds > File "build/bdist.linux-armv7l/egg/pysnmp/smi/rfc1902.py", line 845, in resolveWithMib > File "build/bdist.linux-armv7l/egg/pysnmp/smi/rfc1902.py", line 481, in resolveWithMib > File "build/bdist.linux-armv7l/egg/pysnmp/smi/builder.py", line 400, in importSymbols > File "build/bdist.linux-armv7l/egg/pysnmp/smi/builder.py", line 370, in loadModules > pysnmp.smi.error.MibNotFoundError: IF-MIB compilation error(s): missing > > > But I can’t tell what’s missing, or what I’m doing wrong. > > Any thoughts? > > Thanks! > > William Smith > w_...@co... |
From: William S. <w_...@co...> - 2017-04-08 19:32:43
|
I’m trying to upgrade a Raspberry Pi SNMP app from Wheezy to Jessie, and I’m getting the following error: Code Snippet: IP='192.168.3.210' Port = 1 In_OID = cmdgen.MibVariable('IF-MIB', 'ifInOctets', Port) Out_OID =cmdgen.MibVariable('IF-MIB', 'ifOutOctets', Port) # a bunch of integer values (some negative dBm) AirRxPowerAntennaA = cmdgen.MibVariable('1.3.6.1.4.1.4458.1000.1.5.56.2.0') AirRxPowerAntennaB = cmdgen.MibVariable('1.3.6.1.4.1.4458.1000.1.5.56.3.0') AirCurrentFreq = cmdgen.MibVariable('1.3.6.1.4.1.4458.1000.1.5.16.0') AirLinkDistance = cmdgen.MibVariable('1.3.6.1.4.1.4458.1000.1.5.29.0') AccumulatedUAS = cmdgen.MibVariable('1.3.6.1.4.1.4458.1000.1.5.61.0') #SNMP handle cmdGen = cmdgen.CommandGenerator() # get Heaving Down Dock numbers HDDerrorIndication, HDDerrorStatus, HDDerrorIndex, HDDvarBinds = cmdGen.getCmd( cmdgen.CommunityData('public',mpModel=0), cmdgen.UdpTransportTarget((IP, 161)), In_OID,Out_OID, AirRxPowerAntennaA,AirRxPowerAntennaB, AirCurrentFreq,AirLinkDistance,AccumulatedUAS ) but when I run it I get: File "Airmux.py", line 67, in <module> AirCurrentFreq,AirLinkDistance,AccumulatedUAS File "build/bdist.linux-armv7l/egg/pysnmp/entity/rfc3413/oneliner/cmdgen.py", line 183, in getCmd File "build/bdist.linux-armv7l/egg/pysnmp/hlapi/asyncore/sync/cmdgen.py", line 111, in getCmd File "build/bdist.linux-armv7l/egg/pysnmp/hlapi/asyncore/cmdgen.py", line 129, in getCmd File "build/bdist.linux-armv7l/egg/pysnmp/hlapi/varbinds.py", line 39, in makeVarBinds File "build/bdist.linux-armv7l/egg/pysnmp/smi/rfc1902.py", line 845, in resolveWithMib File "build/bdist.linux-armv7l/egg/pysnmp/smi/rfc1902.py", line 481, in resolveWithMib File "build/bdist.linux-armv7l/egg/pysnmp/smi/builder.py", line 400, in importSymbols File "build/bdist.linux-armv7l/egg/pysnmp/smi/builder.py", line 370, in loadModules pysnmp.smi.error.MibNotFoundError: IF-MIB compilation error(s): missing But I can’t tell what’s missing, or what I’m doing wrong. Any thoughts? Thanks! William Smith w_...@co... |
From: RFE <lf...@rf...> - 2017-04-07 20:04:00
|
hello to all, Please can anyone to clarify how i can set an agent on a my system ? It is possibile to create it without use snmpd and only with pysnmp? Can suggest me any link for agent doc? Kindly Regard |
From: Jing S. <Jin...@li...> - 2017-04-07 19:33:51
|
All, I just found the issue. The password has to be at least eight characters long according to RFC3414. The error message is confusing. Regards, Jing -----Original Message----- From: Jing Shao [mailto:Jin...@li...] Sent: Friday, April 07, 2017 2:06 PM To: pys...@li... Subject: [pysnmp-users] Issue with authentication setup All, I am trying to use the pysnmp to test the SNMP v3 get operation from a CLI I wrote the snmpv3_get.py as follows: ================ #!/usr/bin/python from pysnmp.entity.rfc3413.oneliner import cmdgen import argparse SNMP_PORT=161 SNMP_READ_COMMUNITY='public' SNMP_V3_USER='admin' SNMP_V3_AUTH_KEY='admin123' SNMP_V3_AUTH_PROTO='sha' SNMP_V3_PRIV_KEY='admin123' SNMP_V3_PRIV_PROTO='aes' AUTH_PROTOCOLS = { 'md5': cmdgen.usmHMACMD5AuthProtocol, 'sha': cmdgen.usmHMACSHAAuthProtocol } PRIV_PROTOCOLS = { 'des': cmdgen.usmDESPrivProtocol, 'aes': cmdgen.usmAesCfb128Protocol} def snmpv3_get(ip_addr, oid, **kwargs): global SNMP_PORT user = kwargs.get('user', SNMP_V3_USER) authKey = kwargs.get('authKey', SNMP_V3_AUTH_KEY) authProtoStr = kwargs.get('authProtocol', SNMP_V3_AUTH_PROTO) authProto = AUTH_PROTOCOLS[authProtoStr] privKey = kwargs.get('privKey', SNMP_V3_PRIV_KEY) privProtoStr = kwargs.get('privProtocol', SNMP_V3_PRIV_PROTO) privProto = PRIV_PROTOCOLS[privProtoStr] #print '%s %s %s %s %s' %(user, authKey, authProtoStr, privKey, privProtoStr) userData = cmdgen.UsmUserData(user, authKey=authKey, authProtocol=authProto, privKey=privKey, privProtocol=privProto) cmdGen = cmdgen.CommandGenerator() errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd( userData, cmdgen.UdpTransportTarget((ip_addr, SNMP_PORT)), oid) # Check for errors and print out results if errorIndication: print(errorIndication) else: if errorStatus: print('%s at %s' %(errorStatus.prettyPrint(), errorIndex and varBinds[int(errorIndex)-1] or '?')) else: for name, val in varBinds: print('%s = %s' % (name.prettyPrint(), val.prettyPrint())) if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument('--user', '-u', default=SNMP_V3_USER, help='SNMP v3 user') parser.add_argument('--authProto', '-A', default=SNMP_V3_AUTH_PROTO, help='Authentication Protocol: md5 or sha, default to sha') parser.add_argument('--authKey', '-a', default=SNMP_V3_AUTH_KEY, help='Authentication Password') parser.add_argument('--privProto', '-P', default=SNMP_V3_PRIV_PROTO, help='Privacy Protocol: des or aes, default to aes') parser.add_argument('--privKey', '-p', default=SNMP_V3_PRIV_KEY, help='Privacy Password') parser.add_argument('ip_addr') parser.add_argument('oid') args = parser.parse_args() snmpv3_get(args.ip_addr, args.oid, user=args.user, authProtocol=args.authProto, authKey=args.authKey, privProtocol=args.privProto, privKey=args.privKey) ======= I have two users defined on the snmp agent, admin (read/write) and user (read only). I can access the agents with both users using iReasoning MIB browser and Perl successfully. However, with pysnmp, while I can read the sysDesc using admin successfully ====== % snmpv3_get.py -u admin -a admin123 -p admin123 -A sha -P aes 10.200.176.218 .1.3.6.1.2.1.1.1.0 SNMPv2-MIB::sysDescr.0 = Site Monitor Controller ====== But if use the user, I got the following error: ============== % snmpv3_get.py -u user -a user123 -p user123 -A sha -P aes 10.200.176.218 .1.3.6.1.2.1.1.1.0 Traceback (most recent call last): File "./snmpv3_get.py", line 61, in <module> snmpv3_get(args.ip_addr, args.oid, user=args.user, authProtocol=args.authProto, authKey=args.authKey, privProtocol=args.privProto, privKey=args.privKey) File "./snmpv3_get.py", line 36, in snmpv3_get errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd( userData, cmdgen.UdpTransportTarget((ip_addr, SNMP_PORT)), oid) File "/usr/local/lib/python2.7/dist-packages/pysnmp/entity/rfc3413/oneliner/cmdgen.py", line 183, in getCmd **kwargs): File "/usr/local/lib/python2.7/dist-packages/pysnmp/hlapi/asyncore/sync/cmdgen.py", line 111, in getCmd lookupMib=options.get('lookupMib', True))) File "/usr/local/lib/python2.7/dist-packages/pysnmp/hlapi/asyncore/cmdgen.py", line 124, in getCmd addrName, paramsName = lcd.configure(snmpEngine, authData, transportTarget) File "/usr/local/lib/python2.7/dist-packages/pysnmp/hlapi/lcd.py", line 60, in configure securityName=authData.securityName File "/usr/local/lib/python2.7/dist-packages/pysnmp/entity/config.py", line 191, in addV3User (pysnmpUsmSecretEntry.name + (4,) + tblIdx2, 'createAndGo')) File "/usr/local/lib/python2.7/dist-packages/pysnmp/smi/instrum.py", line 256, in writeVars return self.flipFlopFsm(self.fsmWriteVar, varBinds, acInfo) File "/usr/local/lib/python2.7/dist-packages/pysnmp/smi/instrum.py", line 239, in flipFlopFsm raise origExc pysnmp.smi.error.WrongValueError: WrongValueError({'msg': WrongValueError(), 'name': (1, 3, 6, 1, 4, 1, 20408, 3, 1, 1, 1, 2, 1, 2, 117, 115, 101, 114), 'idx': 1}) ============= Looks like I get an exception in instrum.py, but I am not sure why. Your help are greatly appreciated. Jing Shao Senior Software Engineer Lite-On Power System Solutions Confidential Information:This message is sent to the intended recipient and may contain privileged or confidential information. If you received this transmission in error, please notify the sender with a replying e-mail and delete the message and any attachment.Transmission Caveat and Virus Alert: Internet communications cannot be guaranteed to be timely, secure, error or virus-free. The sender does not accept liability for any errors or omissions. ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ pysnmp-users mailing list pys...@li... https://lists.sourceforge.net/lists/listinfo/pysnmp-users Confidential Information:This message is sent to the intended recipient and may contain privileged or confidential information. If you received this transmission in error, please notify the sender with a replying e-mail and delete the message and any attachment.Transmission Caveat and Virus Alert: Internet communications cannot be guaranteed to be timely, secure, error or virus-free. The sender does not accept liability for any errors or omissions. |
From: Jing S. <Jin...@li...> - 2017-04-07 19:18:45
|
All, I am trying to use the pysnmp to test the SNMP v3 get operation from a CLI I wrote the snmpv3_get.py as follows: ================ #!/usr/bin/python from pysnmp.entity.rfc3413.oneliner import cmdgen import argparse SNMP_PORT=161 SNMP_READ_COMMUNITY='public' SNMP_V3_USER='admin' SNMP_V3_AUTH_KEY='admin123' SNMP_V3_AUTH_PROTO='sha' SNMP_V3_PRIV_KEY='admin123' SNMP_V3_PRIV_PROTO='aes' AUTH_PROTOCOLS = { 'md5': cmdgen.usmHMACMD5AuthProtocol, 'sha': cmdgen.usmHMACSHAAuthProtocol } PRIV_PROTOCOLS = { 'des': cmdgen.usmDESPrivProtocol, 'aes': cmdgen.usmAesCfb128Protocol} def snmpv3_get(ip_addr, oid, **kwargs): global SNMP_PORT user = kwargs.get('user', SNMP_V3_USER) authKey = kwargs.get('authKey', SNMP_V3_AUTH_KEY) authProtoStr = kwargs.get('authProtocol', SNMP_V3_AUTH_PROTO) authProto = AUTH_PROTOCOLS[authProtoStr] privKey = kwargs.get('privKey', SNMP_V3_PRIV_KEY) privProtoStr = kwargs.get('privProtocol', SNMP_V3_PRIV_PROTO) privProto = PRIV_PROTOCOLS[privProtoStr] #print '%s %s %s %s %s' %(user, authKey, authProtoStr, privKey, privProtoStr) userData = cmdgen.UsmUserData(user, authKey=authKey, authProtocol=authProto, privKey=privKey, privProtocol=privProto) cmdGen = cmdgen.CommandGenerator() errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd( userData, cmdgen.UdpTransportTarget((ip_addr, SNMP_PORT)), oid) # Check for errors and print out results if errorIndication: print(errorIndication) else: if errorStatus: print('%s at %s' %(errorStatus.prettyPrint(), errorIndex and varBinds[int(errorIndex)-1] or '?')) else: for name, val in varBinds: print('%s = %s' % (name.prettyPrint(), val.prettyPrint())) if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument('--user', '-u', default=SNMP_V3_USER, help='SNMP v3 user') parser.add_argument('--authProto', '-A', default=SNMP_V3_AUTH_PROTO, help='Authentication Protocol: md5 or sha, default to sha') parser.add_argument('--authKey', '-a', default=SNMP_V3_AUTH_KEY, help='Authentication Password') parser.add_argument('--privProto', '-P', default=SNMP_V3_PRIV_PROTO, help='Privacy Protocol: des or aes, default to aes') parser.add_argument('--privKey', '-p', default=SNMP_V3_PRIV_KEY, help='Privacy Password') parser.add_argument('ip_addr') parser.add_argument('oid') args = parser.parse_args() snmpv3_get(args.ip_addr, args.oid, user=args.user, authProtocol=args.authProto, authKey=args.authKey, privProtocol=args.privProto, privKey=args.privKey) ======= I have two users defined on the snmp agent, admin (read/write) and user (read only). I can access the agents with both users using iReasoning MIB browser and Perl successfully. However, with pysnmp, while I can read the sysDesc using admin successfully ====== % snmpv3_get.py -u admin -a admin123 -p admin123 -A sha -P aes 10.200.176.218 .1.3.6.1.2.1.1.1.0 SNMPv2-MIB::sysDescr.0 = Site Monitor Controller ====== But if use the user, I got the following error: ============== % snmpv3_get.py -u user -a user123 -p user123 -A sha -P aes 10.200.176.218 .1.3.6.1.2.1.1.1.0 Traceback (most recent call last): File "./snmpv3_get.py", line 61, in <module> snmpv3_get(args.ip_addr, args.oid, user=args.user, authProtocol=args.authProto, authKey=args.authKey, privProtocol=args.privProto, privKey=args.privKey) File "./snmpv3_get.py", line 36, in snmpv3_get errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd( userData, cmdgen.UdpTransportTarget((ip_addr, SNMP_PORT)), oid) File "/usr/local/lib/python2.7/dist-packages/pysnmp/entity/rfc3413/oneliner/cmdgen.py", line 183, in getCmd **kwargs): File "/usr/local/lib/python2.7/dist-packages/pysnmp/hlapi/asyncore/sync/cmdgen.py", line 111, in getCmd lookupMib=options.get('lookupMib', True))) File "/usr/local/lib/python2.7/dist-packages/pysnmp/hlapi/asyncore/cmdgen.py", line 124, in getCmd addrName, paramsName = lcd.configure(snmpEngine, authData, transportTarget) File "/usr/local/lib/python2.7/dist-packages/pysnmp/hlapi/lcd.py", line 60, in configure securityName=authData.securityName File "/usr/local/lib/python2.7/dist-packages/pysnmp/entity/config.py", line 191, in addV3User (pysnmpUsmSecretEntry.name + (4,) + tblIdx2, 'createAndGo')) File "/usr/local/lib/python2.7/dist-packages/pysnmp/smi/instrum.py", line 256, in writeVars return self.flipFlopFsm(self.fsmWriteVar, varBinds, acInfo) File "/usr/local/lib/python2.7/dist-packages/pysnmp/smi/instrum.py", line 239, in flipFlopFsm raise origExc pysnmp.smi.error.WrongValueError: WrongValueError({'msg': WrongValueError(), 'name': (1, 3, 6, 1, 4, 1, 20408, 3, 1, 1, 1, 2, 1, 2, 117, 115, 101, 114), 'idx': 1}) ============= Looks like I get an exception in instrum.py, but I am not sure why. Your help are greatly appreciated. Jing Shao Senior Software Engineer Lite-On Power System Solutions Confidential Information:This message is sent to the intended recipient and may contain privileged or confidential information. If you received this transmission in error, please notify the sender with a replying e-mail and delete the message and any attachment.Transmission Caveat and Virus Alert: Internet communications cannot be guaranteed to be timely, secure, error or virus-free. The sender does not accept liability for any errors or omissions. |
From: Camilo C. <jua...@im...> - 2017-04-04 09:49:37
|
Hello all, I am having some problems encoding indices instances to OIDs. Here is the outcome when I try to run the example of the documentation resolving the tcpConnectionState instance. In [2]: tcpConnectionState_instance = ObjectIdentity('TCP-MIB', 'tcpConnectionState', 'ipv4', '195.218.254.105', 41511, 'ipv4', '194.67.1.250', 993) In [3]: tcpConnectionState_instance.resolveWithMib(view.MibViewController(mibBuilder)) In [4]: tcpConnectionState_instance.getOid() ObjectName('1.3.6.1.2.1.6.19.1.7.1.15.49.57.53.46.50.49.56.46.50.53.52.46.49.48.53.41511.1.12.49.57.52.46.54.55.46.49.46.50.53.48.993') This is different from the 1.3.6.1.2.1.6.19.1.7.1.4.195.218.254.105.41511.1.4.194.67.1.250.993 (which is given as a result in the documentation). Other examples are actually encoded fine, so I am not sure if this is something local or a general problem. Can this be caused by something on the MIB file? Resolving the “correct” OID throws the next: In [13]: tcpConnectionState_instance = ObjectIdentity('1.3.6.1.2.1.6.19.1.7.1.4.195.218.254.105.41511.1.4.194.67.1.250.993') In [14]: tcpConnectionState_instance.resolveWithMib(view.MibViewController(mibBuilder)) ObjectIdentity('1.3.6.1.2.1.6.19.1.7.1.4.195.218.254.105.41511.1.4.194.67.1.250.993') In [15]: tcpConnectionState_instance.prettyPrint() "TCP-MIB::tcpConnectionState.'ipv4'.0xc3dafe69.41511.'ipv4'.0xc24301fa.993” Thanks, Juan C. |
From: Ilya E. <il...@gl...> - 2017-02-28 21:31:06
|
Version 4.3.4 has been released. That should hopefully fix this issue as well as improve library performance. > On 28 Feb 2017, at 20:47, Ilya Etingof <il...@gl...> wrote: > > Hi Tomas, > > That’s going to be fixed with an upcoming pysnmp release. > > Meanwhile, besides downgrading pyasn1 as you’ve suggested, alternatively, you could take pysnmp from git master (https://github.com/etingof/pysnmp <https://github.com/etingof/pysnmp>). > >> On 28 Feb 2017, at 11:24, Thomas Juberg <tho...@gm... <mailto:tho...@gm...>> wrote: >> >> Hi, >> >> pysnmp 0.2.3 was released on february 25th and seems to break pysnmp. >> Using the quickstart script to test from http://pysnmp.sourceforge.net/quick-start.html#fetch-snmp-variable <http://pysnmp.sourceforge.net/quick-start.html#fetch-snmp-variable> >> Tested on python 3.6 and 2.7.13 with the same error: >> >> Traceback (most recent call last): >> File "v1-get1.py", line 24, in <module> >> ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0))) >> File "/home/tjuberg/.local/lib/python3.6/site-packages/pysnmp/hlapi/asyncore/sync/cmdgen.py", line 111, in getCmd >> lookupMib=options.get('lookupMib', True))) >> File "/home/tjuberg/.local/lib/python3.6/site-packages/pysnmp/hlapi/asyncore/cmdgen.py", line 131, in getCmd >> options.get('cbFun'), options.get('cbCtx')) >> File "/home/tjuberg/.local/lib/python3.6/site-packages/pysnmp/entity/rfc3413/cmdgen.py", line 214, in sendVarBinds >> v2c.apiPDU.setVarBinds(reqPDU, varBinds) >> File "/home/tjuberg/.local/lib/python3.6/site-packages/pysnmp/proto/api/v1.py", line 136, in setVarBinds >> varBindList.getComponentByPosition(idx), varBind >> File "/home/tjuberg/.local/lib/python3.6/site-packages/pysnmp/proto/api/v1.py", line 43, in setOIDVal >> verifyConstraints=False) >> TypeError: setComponentByType() got multiple values for argument 'verifyConstraints' >> >> Downgrading pyasn1 to 0.2.2 resolves the issue. >> >> Regards, >> -Thomas Juberg |
From: Ilya E. <il...@gl...> - 2017-02-28 19:47:45
|
Hi Tomas, That’s going to be fixed with an upcoming pysnmp release. Meanwhile, besides downgrading pyasn1 as you’ve suggested, alternatively, you could take pysnmp from git master (https://github.com/etingof/pysnmp <https://github.com/etingof/pysnmp>). > On 28 Feb 2017, at 11:24, Thomas Juberg <tho...@gm...> wrote: > > Hi, > > pysnmp 0.2.3 was released on february 25th and seems to break pysnmp. > Using the quickstart script to test from http://pysnmp.sourceforge.net/quick-start.html#fetch-snmp-variable <http://pysnmp.sourceforge.net/quick-start.html#fetch-snmp-variable> > Tested on python 3.6 and 2.7.13 with the same error: > > Traceback (most recent call last): > File "v1-get1.py", line 24, in <module> > ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0))) > File "/home/tjuberg/.local/lib/python3.6/site-packages/pysnmp/hlapi/asyncore/sync/cmdgen.py", line 111, in getCmd > lookupMib=options.get('lookupMib', True))) > File "/home/tjuberg/.local/lib/python3.6/site-packages/pysnmp/hlapi/asyncore/cmdgen.py", line 131, in getCmd > options.get('cbFun'), options.get('cbCtx')) > File "/home/tjuberg/.local/lib/python3.6/site-packages/pysnmp/entity/rfc3413/cmdgen.py", line 214, in sendVarBinds > v2c.apiPDU.setVarBinds(reqPDU, varBinds) > File "/home/tjuberg/.local/lib/python3.6/site-packages/pysnmp/proto/api/v1.py", line 136, in setVarBinds > varBindList.getComponentByPosition(idx), varBind > File "/home/tjuberg/.local/lib/python3.6/site-packages/pysnmp/proto/api/v1.py", line 43, in setOIDVal > verifyConstraints=False) > TypeError: setComponentByType() got multiple values for argument 'verifyConstraints' > > Downgrading pyasn1 to 0.2.2 resolves the issue. > > Regards, > -Thomas Juberg |
From: Thomas J. <tho...@gm...> - 2017-02-28 10:24:08
|
Hi, pysnmp 0.2.3 was released on february 25th and seems to break pysnmp. Using the quickstart script to test from http://pysnmp.sourceforge.net/quick-start.html#fetch-snmp-variable Tested on python 3.6 and 2.7.13 with the same error: Traceback (most recent call last): File "v1-get1.py", line 24, in <module> ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0))) File "/home/tjuberg/.local/lib/python3.6/site-packages/pysnmp/hlapi/asyncore/sync/cmdgen.py", line 111, in getCmd lookupMib=options.get('lookupMib', True))) File "/home/tjuberg/.local/lib/python3.6/site-packages/pysnmp/hlapi/asyncore/cmdgen.py", line 131, in getCmd options.get('cbFun'), options.get('cbCtx')) File "/home/tjuberg/.local/lib/python3.6/site-packages/pysnmp/entity/rfc3413/cmdgen.py", line 214, in sendVarBinds v2c.apiPDU.setVarBinds(reqPDU, varBinds) File "/home/tjuberg/.local/lib/python3.6/site-packages/pysnmp/proto/api/v1.py", line 136, in setVarBinds varBindList.getComponentByPosition(idx), varBind File "/home/tjuberg/.local/lib/python3.6/site-packages/pysnmp/proto/api/v1.py", line 43, in setOIDVal verifyConstraints=False) TypeError: setComponentByType() got multiple values for argument 'verifyConstraints' Downgrading pyasn1 to 0.2.2 resolves the issue. Regards, -Thomas Juberg |
From: Ilya E. <il...@gl...> - 2017-02-27 21:11:03
|
The best thing to do here is to figure out which MIBs you are walking (e.g. your SNMP Agent implements), then pass them to the `loadMibs()` function to make pysnmp loading just these MIBs (plus their dependencies). You can of course use `loadMibs()` without parameters, however then pysnmp will load up all MIBs it could reach. That may contribute to excessive memory consumption. > On 27 Feb 2017, at 15:45, Brett Kugler <bre...@gd...> wrote: > > After some more study, I found that if I use the loadMibs() function when I declare the ObjectType(), before I send them through nextCmd(), it works. I was attempting to resolve them after the fact. This doesn’t really explain why it would work at times and not others, but does give me a resolution to my real problem, not getting OIDs resolved properly. > > Thank you, > Brett > > From: Brett Kugler [mailto:bre...@gd... <mailto:bre...@gd...>] > Sent: Thursday, February 23, 2017 10:32 AM > To: Ilya Etingof <il...@gl... <mailto:il...@gl...>> > Cc: pys...@li... <mailto:pys...@li...> > Subject: Re: [pysnmp-users] SNMP MIB resolution issue > > Thank you for the prompt response. I may have provided too much information and confused the issue. I did attempt to use the loadMibs() methods, but I still received the same results. > > Since there are many layers, it is hard for me to produce a minimal reproduction, but I will see if I can spare some time this weekend to find one. Here is a general flow: > > I specify a varbind ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets')) > Without any loading of MIBs, PySNMP converts this to the proper OID (this must mean it’s resolving the MIBs on my system, right?) > I then pull those values from my devices using nextCmd() to walk the table (this is done in a multi-threaded blast using a Threadpool via python’s pool.starmap()) > Once I have all the results collated, I write them out to files based on the IP addresses they were retrieved from, this is where I see issues. > Now is where things get hard to explain, but I will do my best. During different executions of my code (multiple runs), the behavior I see when using pretty print to display the same OIDs from the same device changes. Sometimes, I get the expected output ('IF-MIB', 'ifInOctets', (InterfaceIndex(16875520),)) and other times I get the ‘incorrect’ output ('SNMPv2-SMI', 'mib-2', (ObjectName('2.2.1.10.16875520'),)) – this occurs on a device by device basis. All OIDs for a given device either print correctly, or they don’t. And this occurs even if I do not attempt to load any MIBs from any external sources (and when I do). > There is a wrinkle to all this – as I mentioned, I’m using threading to read multiple devices at once. When I read fewer devices, this behavior does not occur. I have not yet narrowed it down to determine how many devices need to be run concurrently for this to happen. Also – I was having a lot of issues with the asyncio module for PySNMP, so I am using the synchronous PySNMP functions wrapped in my threads. Since each thread gets its own SNMPEngine instance, my understanding was that makes it thread safe – and again, everything appears to work fine, with the exception of this OID to MIB translation issue. > > This is a pretty complex sequence, so I understand that it can be hard to envision – I was hoping this might have been a known issue. I will try to provide a full sample that recreates the issue to help with troubleshooting. > > Brett > > From: Ilya Etingof [mailto:il...@gl... <mailto:il...@gl...>] > Sent: Tuesday, February 21, 2017 6:03 PM > To: Brett Kugler <bre...@gd... <mailto:bre...@gd...>> > Cc: pys...@li... <mailto:pys...@li...> > Subject: Re: [pysnmp-users] SNMP MIB resolution issue > > > Hi Brett, > > I believe there is no randomness here. I’d guess it really depends on whether the MIB (that maps an OID to a human-friendly name) is loaded into pysnmp or not. > > If you know which MIBs your SNMP agent implements, you could load them in advance before you run your SNMP manager app. To load particular MIBs you could use .loadMibs(‘FIRST-MIB’, ’SECOND-MIB’) method: > > http://pysnmp.sourceforge.net/docs/api-reference.html#pysnmp.smi.rfc1902.ObjectIdentity.loadMibs <http://pysnmp.sourceforge.net/docs/api-reference.html#pysnmp.smi.rfc1902.ObjectIdentity.loadMibs> > > There is currently no automatic way in pysnmp to figure out which MIB maps given OID and load it up on demand. However this feature is being developed and should appear in pysnmp sooner rather than later. ;-) > > Let me know if you need further help. > > On 20 Feb 2017, at 23:04, Brett Kugler <bre...@gd... <mailto:bre...@gd...>> wrote: > > I am running the latest version of PySNMP (4.3.3) and am having issues with my OIDs not consistently converting to friendly format. Here is an example of pulling values from the following oids: > oids = [ > ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets')), > ObjectType(ObjectIdentity('IF-MIB', 'ifOutOctets')) > ] > > There are no issues retrieving the values from all my devices using nextCmd. > > When I go to convert the OIDs received back to friendly text, I am getting intermittent results. For simplicity, here is an example of what I’ve tried: > > # results is a list of tuples, [(ip, varbinds),…] > for device in results: > outfile = open(device[0], 'w+') > for varbinds in device[1]: > outfile.write(' = '.join([x.prettyPrint() for x in varbinds])) > outfile.write('\n') > outfile.close() > > This produces a dump of all the bytes in/out for all the interfaces on a device. > > Here’s where things go wrong – when I execute my code, sometimes devices will display the friendly text properly, and sometimes they will not. If the translation fails, it fails for all the varbinds on the device. If it succeeds, they are all correct. Over multiple executions, devices will either be correct or incorrect, seemingly randomly. > > Here is a sample of correct vs. incorrect output. > right - ('IF-MIB', 'ifInOctets', (InterfaceIndex(16875520),)) - wrong - ('SNMPv2-SMI', 'mib-2', (ObjectName('2.2.1.10.16875520'),)) > > Here is a sampling of runs against devices, and their failues: > Nope 10.128.109.11 10.128.109.11 10.128.109.11 Nope 10.128.109.11 > 10.128.109.12 Nope 10.128.109.12 Nope 10.128.109.12 10.128.109.12 > 10.128.11.168 10.128.11.168 10.128.11.168 Nope 10.128.11.168 > Nope 10.128.11.2 Nope 10.128.11.2 10.128.11.2 Nope 10.128.11.2 > 10.128.11.3 10.128.11.3 10.128.11.3 10.128.11.3 > > In all cases the underlying OID is correct – it’s simply the translation that is failing. > > I have tried to assign MIB sources either with addAsn1MibSource() or just addMibSource() as well as playing around with the getMibSymbol() function. I would accept that I am simply doing something wrong, but the intermittent nature of this working/not working has me thinking there’s something else going on. > > Any advice? Thanks in advance! > > Brett > |
From: Brett K. <bre...@gd...> - 2017-02-27 14:45:43
|
After some more study, I found that if I use the loadMibs() function when I declare the ObjectType(), before I send them through nextCmd(), it works. I was attempting to resolve them after the fact. This doesn’t really explain why it would work at times and not others, but does give me a resolution to my real problem, not getting OIDs resolved properly. Thank you, Brett From: Brett Kugler [mailto:bre...@gd...] Sent: Thursday, February 23, 2017 10:32 AM To: Ilya Etingof <il...@gl...> Cc: pys...@li... Subject: Re: [pysnmp-users] SNMP MIB resolution issue Thank you for the prompt response. I may have provided too much information and confused the issue. I did attempt to use the loadMibs() methods, but I still received the same results. Since there are many layers, it is hard for me to produce a minimal reproduction, but I will see if I can spare some time this weekend to find one. Here is a general flow: 1. I specify a varbind ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets')) 2. Without any loading of MIBs, PySNMP converts this to the proper OID (this must mean it’s resolving the MIBs on my system, right?) 3. I then pull those values from my devices using nextCmd() to walk the table (this is done in a multi-threaded blast using a Threadpool via python’s pool.starmap()) 4. Once I have all the results collated, I write them out to files based on the IP addresses they were retrieved from, this is where I see issues. 5. Now is where things get hard to explain, but I will do my best. During different executions of my code (multiple runs), the behavior I see when using pretty print to display the same OIDs from the same device changes. Sometimes, I get the expected output ('IF-MIB', 'ifInOctets', (InterfaceIndex(16875520),)) and other times I get the ‘incorrect’ output ('SNMPv2-SMI', 'mib-2', (ObjectName('2.2.1.10.16875520'),)) – this occurs on a device by device basis. All OIDs for a given device either print correctly, or they don’t. And this occurs even if I do not attempt to load any MIBs from any external sources (and when I do). 6. There is a wrinkle to all this – as I mentioned, I’m using threading to read multiple devices at once. When I read fewer devices, this behavior does not occur. I have not yet narrowed it down to determine how many devices need to be run concurrently for this to happen. Also – I was having a lot of issues with the asyncio module for PySNMP, so I am using the synchronous PySNMP functions wrapped in my threads. Since each thread gets its own SNMPEngine instance, my understanding was that makes it thread safe – and again, everything appears to work fine, with the exception of this OID to MIB translation issue. This is a pretty complex sequence, so I understand that it can be hard to envision – I was hoping this might have been a known issue. I will try to provide a full sample that recreates the issue to help with troubleshooting. Brett From: Ilya Etingof [mailto:il...@gl...] Sent: Tuesday, February 21, 2017 6:03 PM To: Brett Kugler <bre...@gd...<mailto:bre...@gd...>> Cc: pys...@li...<mailto:pys...@li...> Subject: Re: [pysnmp-users] SNMP MIB resolution issue Hi Brett, I believe there is no randomness here. I’d guess it really depends on whether the MIB (that maps an OID to a human-friendly name) is loaded into pysnmp or not. If you know which MIBs your SNMP agent implements, you could load them in advance before you run your SNMP manager app. To load particular MIBs you could use .loadMibs(‘FIRST-MIB’, ’SECOND-MIB’) method: http://pysnmp.sourceforge.net/docs/api-reference.html#pysnmp.smi.rfc1902.ObjectIdentity.loadMibs There is currently no automatic way in pysnmp to figure out which MIB maps given OID and load it up on demand. However this feature is being developed and should appear in pysnmp sooner rather than later. ;-) Let me know if you need further help. On 20 Feb 2017, at 23:04, Brett Kugler <bre...@gd...<mailto:bre...@gd...>> wrote: I am running the latest version of PySNMP (4.3.3) and am having issues with my OIDs not consistently converting to friendly format. Here is an example of pulling values from the following oids: oids = [ ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets')), ObjectType(ObjectIdentity('IF-MIB', 'ifOutOctets')) ] There are no issues retrieving the values from all my devices using nextCmd. When I go to convert the OIDs received back to friendly text, I am getting intermittent results. For simplicity, here is an example of what I’ve tried: # results is a list of tuples, [(ip, varbinds),…] for device in results: outfile = open(device[0], 'w+') for varbinds in device[1]: outfile.write(' = '.join([x.prettyPrint() for x in varbinds])) outfile.write('\n') outfile.close() This produces a dump of all the bytes in/out for all the interfaces on a device. Here’s where things go wrong – when I execute my code, sometimes devices will display the friendly text properly, and sometimes they will not. If the translation fails, it fails for all the varbinds on the device. If it succeeds, they are all correct. Over multiple executions, devices will either be correct or incorrect, seemingly randomly. Here is a sample of correct vs. incorrect output. right - ('IF-MIB', 'ifInOctets', (InterfaceIndex(16875520),)) - wrong - ('SNMPv2-SMI', 'mib-2', (ObjectName('2.2.1.10.16875520'),)) Here is a sampling of runs against devices, and their failues: Nope 10.128.109.11 10.128.109.11 10.128.109.11 Nope 10.128.109.11 10.128.109.12 Nope 10.128.109.12 Nope 10.128.109.12 10.128.109.12 10.128.11.168 10.128.11.168 10.128.11.168 Nope 10.128.11.168 Nope 10.128.11.2 Nope 10.128.11.2 10.128.11.2 Nope 10.128.11.2 10.128.11.3 10.128.11.3 10.128.11.3 10.128.11.3 In all cases the underlying OID is correct – it’s simply the translation that is failing. I have tried to assign MIB sources either with addAsn1MibSource() or just addMibSource() as well as playing around with the getMibSymbol() function. I would accept that I am simply doing something wrong, but the intermittent nature of this working/not working has me thinking there’s something else going on. Any advice? Thanks in advance! Brett ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org<http://slashdot.org/>! http://sdm.link/slashdot_______________________________________________ pysnmp-users mailing list pys...@li...<mailto:pys...@li...> https://lists.sourceforge.net/lists/listinfo/pysnmp-users |
From: Brett K. <bre...@gd...> - 2017-02-23 16:31:44
|
Thank you for the prompt response. I may have provided too much information and confused the issue. I did attempt to use the loadMibs() methods, but I still received the same results. Since there are many layers, it is hard for me to produce a minimal reproduction, but I will see if I can spare some time this weekend to find one. Here is a general flow: 1. I specify a varbind ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets')) 2. Without any loading of MIBs, PySNMP converts this to the proper OID (this must mean it’s resolving the MIBs on my system, right?) 3. I then pull those values from my devices using nextCmd() to walk the table (this is done in a multi-threaded blast using a Threadpool via python’s pool.starmap()) 4. Once I have all the results collated, I write them out to files based on the IP addresses they were retrieved from, this is where I see issues. 5. Now is where things get hard to explain, but I will do my best. During different executions of my code (multiple runs), the behavior I see when using pretty print to display the same OIDs from the same device changes. Sometimes, I get the expected output ('IF-MIB', 'ifInOctets', (InterfaceIndex(16875520),)) and other times I get the ‘incorrect’ output ('SNMPv2-SMI', 'mib-2', (ObjectName('2.2.1.10.16875520'),)) – this occurs on a device by device basis. All OIDs for a given device either print correctly, or they don’t. And this occurs even if I do not attempt to load any MIBs from any external sources (and when I do). 6. There is a wrinkle to all this – as I mentioned, I’m using threading to read multiple devices at once. When I read fewer devices, this behavior does not occur. I have not yet narrowed it down to determine how many devices need to be run concurrently for this to happen. Also – I was having a lot of issues with the asyncio module for PySNMP, so I am using the synchronous PySNMP functions wrapped in my threads. Since each thread gets its own SNMPEngine instance, my understanding was that makes it thread safe – and again, everything appears to work fine, with the exception of this OID to MIB translation issue. This is a pretty complex sequence, so I understand that it can be hard to envision – I was hoping this might have been a known issue. I will try to provide a full sample that recreates the issue to help with troubleshooting. Brett From: Ilya Etingof [mailto:il...@gl...] Sent: Tuesday, February 21, 2017 6:03 PM To: Brett Kugler <bre...@gd...> Cc: pys...@li... Subject: Re: [pysnmp-users] SNMP MIB resolution issue Hi Brett, I believe there is no randomness here. I’d guess it really depends on whether the MIB (that maps an OID to a human-friendly name) is loaded into pysnmp or not. If you know which MIBs your SNMP agent implements, you could load them in advance before you run your SNMP manager app. To load particular MIBs you could use .loadMibs(‘FIRST-MIB’, ’SECOND-MIB’) method: http://pysnmp.sourceforge.net/docs/api-reference.html#pysnmp.smi.rfc1902.ObjectIdentity.loadMibs There is currently no automatic way in pysnmp to figure out which MIB maps given OID and load it up on demand. However this feature is being developed and should appear in pysnmp sooner rather than later. ;-) Let me know if you need further help. On 20 Feb 2017, at 23:04, Brett Kugler <bre...@gd...<mailto:bre...@gd...>> wrote: I am running the latest version of PySNMP (4.3.3) and am having issues with my OIDs not consistently converting to friendly format. Here is an example of pulling values from the following oids: oids = [ ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets')), ObjectType(ObjectIdentity('IF-MIB', 'ifOutOctets')) ] There are no issues retrieving the values from all my devices using nextCmd. When I go to convert the OIDs received back to friendly text, I am getting intermittent results. For simplicity, here is an example of what I’ve tried: # results is a list of tuples, [(ip, varbinds),…] for device in results: outfile = open(device[0], 'w+') for varbinds in device[1]: outfile.write(' = '.join([x.prettyPrint() for x in varbinds])) outfile.write('\n') outfile.close() This produces a dump of all the bytes in/out for all the interfaces on a device. Here’s where things go wrong – when I execute my code, sometimes devices will display the friendly text properly, and sometimes they will not. If the translation fails, it fails for all the varbinds on the device. If it succeeds, they are all correct. Over multiple executions, devices will either be correct or incorrect, seemingly randomly. Here is a sample of correct vs. incorrect output. right - ('IF-MIB', 'ifInOctets', (InterfaceIndex(16875520),)) - wrong - ('SNMPv2-SMI', 'mib-2', (ObjectName('2.2.1.10.16875520'),)) Here is a sampling of runs against devices, and their failues: Nope 10.128.109.11 10.128.109.11 10.128.109.11 Nope 10.128.109.11 10.128.109.12 Nope 10.128.109.12 Nope 10.128.109.12 10.128.109.12 10.128.11.168 10.128.11.168 10.128.11.168 Nope 10.128.11.168 Nope 10.128.11.2 Nope 10.128.11.2 10.128.11.2 Nope 10.128.11.2 10.128.11.3 10.128.11.3 10.128.11.3 10.128.11.3 In all cases the underlying OID is correct – it’s simply the translation that is failing. I have tried to assign MIB sources either with addAsn1MibSource() or just addMibSource() as well as playing around with the getMibSymbol() function. I would accept that I am simply doing something wrong, but the intermittent nature of this working/not working has me thinking there’s something else going on. Any advice? Thanks in advance! Brett ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org<http://slashdot.org/>! http://sdm.link/slashdot_______________________________________________ pysnmp-users mailing list pys...@li...<mailto:pys...@li...> https://lists.sourceforge.net/lists/listinfo/pysnmp-users |
From: Ilya E. <il...@gl...> - 2017-02-22 00:02:54
|
Hi Brett, I believe there is no randomness here. I’d guess it really depends on whether the MIB (that maps an OID to a human-friendly name) is loaded into pysnmp or not. If you know which MIBs your SNMP agent implements, you could load them in advance before you run your SNMP manager app. To load particular MIBs you could use .loadMibs(‘FIRST-MIB’, ’SECOND-MIB’) method: http://pysnmp.sourceforge.net/docs/api-reference.html#pysnmp.smi.rfc1902.ObjectIdentity.loadMibs <http://pysnmp.sourceforge.net/docs/api-reference.html#pysnmp.smi.rfc1902.ObjectIdentity.loadMibs> There is currently no automatic way in pysnmp to figure out which MIB maps given OID and load it up on demand. However this feature is being developed and should appear in pysnmp sooner rather than later. ;-) Let me know if you need further help. > On 20 Feb 2017, at 23:04, Brett Kugler <bre...@gd...> wrote: > > I am running the latest version of PySNMP (4.3.3) and am having issues with my OIDs not consistently converting to friendly format. Here is an example of pulling values from the following oids: > oids = [ > ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets')), > ObjectType(ObjectIdentity('IF-MIB', 'ifOutOctets')) > ] > > There are no issues retrieving the values from all my devices using nextCmd. > > When I go to convert the OIDs received back to friendly text, I am getting intermittent results. For simplicity, here is an example of what I’ve tried: > > # results is a list of tuples, [(ip, varbinds),…] > for device in results: > outfile = open(device[0], 'w+') > for varbinds in device[1]: > outfile.write(' = '.join([x.prettyPrint() for x in varbinds])) > outfile.write('\n') > outfile.close() > > This produces a dump of all the bytes in/out for all the interfaces on a device. > > Here’s where things go wrong – when I execute my code, sometimes devices will display the friendly text properly, and sometimes they will not. If the translation fails, it fails for all the varbinds on the device. If it succeeds, they are all correct. Over multiple executions, devices will either be correct or incorrect, seemingly randomly. > > Here is a sample of correct vs. incorrect output. > right - ('IF-MIB', 'ifInOctets', (InterfaceIndex(16875520),)) - wrong - ('SNMPv2-SMI', 'mib-2', (ObjectName('2.2.1.10.16875520'),)) > > Here is a sampling of runs against devices, and their failues: > Nope 10.128.109.11 10.128.109.11 10.128.109.11 Nope 10.128.109.11 > 10.128.109.12 Nope 10.128.109.12 Nope 10.128.109.12 10.128.109.12 > 10.128.11.168 10.128.11.168 10.128.11.168 Nope 10.128.11.168 > Nope 10.128.11.2 Nope 10.128.11.2 10.128.11.2 Nope 10.128.11.2 > 10.128.11.3 10.128.11.3 10.128.11.3 10.128.11.3 > > In all cases the underlying OID is correct – it’s simply the translation that is failing. > > I have tried to assign MIB sources either with addAsn1MibSource() or just addMibSource() as well as playing around with the getMibSymbol() function. I would accept that I am simply doing something wrong, but the intermittent nature of this working/not working has me thinking there’s something else going on. > > Any advice? Thanks in advance! > > Brett > > ------------------------------------------------------------------------------ > Check out the vibrant tech community on one of the world's most > engaging tech sites, SlashDot.org <http://slashdot.org/>! http://sdm.link/slashdot_______________________________________________ <http://sdm.link/slashdot_______________________________________________> > pysnmp-users mailing list > pys...@li... <mailto:pys...@li...> > https://lists.sourceforge.net/lists/listinfo/pysnmp-users <https://lists.sourceforge.net/lists/listinfo/pysnmp-users> |
From: Brett K. <bre...@gd...> - 2017-02-20 22:39:07
|
I am running the latest version of PySNMP (4.3.3) and am having issues with my OIDs not consistently converting to friendly format. Here is an example of pulling values from the following oids: oids = [ ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets')), ObjectType(ObjectIdentity('IF-MIB', 'ifOutOctets')) ] There are no issues retrieving the values from all my devices using nextCmd. When I go to convert the OIDs received back to friendly text, I am getting intermittent results. For simplicity, here is an example of what I've tried: # results is a list of tuples, [(ip, varbinds),...] for device in results: outfile = open(device[0], 'w+') for varbinds in device[1]: outfile.write(' = '.join([x.prettyPrint() for x in varbinds])) outfile.write('\n') outfile.close() This produces a dump of all the bytes in/out for all the interfaces on a device. Here's where things go wrong - when I execute my code, sometimes devices will display the friendly text properly, and sometimes they will not. If the translation fails, it fails for all the varbinds on the device. If it succeeds, they are all correct. Over multiple executions, devices will either be correct or incorrect, seemingly randomly. Here is a sample of correct vs. incorrect output. right - ('IF-MIB', 'ifInOctets', (InterfaceIndex(16875520),)) - wrong - ('SNMPv2-SMI', 'mib-2', (ObjectName('2.2.1.10.16875520'),)) Here is a sampling of runs against devices, and their failues: Nope 10.128.109.11 10.128.109.11 10.128.109.11 Nope 10.128.109.11 10.128.109.12 Nope 10.128.109.12 Nope 10.128.109.12 10.128.109.12 10.128.11.168 10.128.11.168 10.128.11.168 Nope 10.128.11.168 Nope 10.128.11.2 Nope 10.128.11.2 10.128.11.2 Nope 10.128.11.2 10.128.11.3 10.128.11.3 10.128.11.3 10.128.11.3 In all cases the underlying OID is correct - it's simply the translation that is failing. I have tried to assign MIB sources either with addAsn1MibSource() or just addMibSource() as well as playing around with the getMibSymbol() function. I would accept that I am simply doing something wrong, but the intermittent nature of this working/not working has me thinking there's something else going on. Any advice? Thanks in advance! Brett |
From: Fazio L. <lf...@rf...> - 2017-01-21 09:54:30
|
Hello, i'm new in this project, and i not sure if i have understand perfectly all, i have any question please... To use pysnmp as an Agent i have to RUN the engine, but i'm not sure how i can RUN my personal MIB, and how i can load/compie my MIB There are any other tutorial/Example ? Thanks for all!! Regard |
From: <riv...@wi...> - 2016-12-19 11:11:31
|
Hi, The link you have pointed below is different one . I am following this https://tools.ietf.org/html/rfc7666#section-6.1 RFC for VM-MIB. Thanks & Regards, Riva. -----Original Message----- From: Ilya Etingof [mailto:il...@gl...] Sent: Thursday, December 15, 2016 5:10 PM To: Rivarani Roy <riv...@wi...> Cc: pys...@li... Subject: Re: [pysnmp-users] Problem observed in new mib loading ** This mail has been sent from an external source ** Looking at VM-MIB, I do not see vmNumber object there: http://mibs.snmplabs.com/asn1/VM-MIB Do you have a newer MIB? Also, given you query an existing object, you should query MIB object rather than MIB object instance: ObjectType(ObjectIdentity('VM-MIB', 'vmNumber', 0).addAsn1MibSource('file:///usr/share/snmp', 'http://mibs.snmplabs.com/asn1/@mib@'))) On 12/15/2016 12:17 PM, riv...@wi... wrote: > Hi, > > > > I have tried this below one. > > > > #!/usr/bin/python > > from pysnmp.hlapi import * > > > > errorIndication, errorStatus, errorIndex, varBinds = next( > > getCmd(SnmpEngine(), > > CommunityData('public'), > > UdpTransportTarget(('10.154.19.88', 161)), > > ContextData(), > > ObjectType(ObjectIdentity('VM-MIB', > 'vmNumber').addAsn1MibSource('file:///usr/share/snmp', > > > 'http://mibs.snmplabs.com/asn1/@mib@'))) > > ) > > > > if errorIndication: > > print(errorIndication) > > elif errorStatus: > > print('%s at %s' % (errorStatus.prettyPrint(), > > errorIndex and varBinds[int(errorIndex) - > 1][0] or '?')) > > else: > > for varBind in varBinds: > > print(' = '.join([x.prettyPrint() for x in varBind])) > > > > > > VM-MIB::vmNumber = No Such Object currently exists at this OID > > > > Thanks & Regards, > > Riva. > > > > *From:*Rivarani Roy > *Sent:* Thursday, December 15, 2016 3:48 PM > *To:* 'Ilya Etingof' <il...@gl...> > *Cc:* pys...@li... > *Subject:* RE: [pysnmp-users] Problem observed in new mib loading > > > > Hi, > > > > I followed the below steps but got the same result. > > Currently using the latest pysnmp but didn't get any success. > > > > Thanks & Regards, > > Riva. > > > > *From:*Ilya Etingof [mailto:il...@gl...] > *Sent:* Thursday, December 15, 2016 2:26 PM > *To:* Rivarani Roy <riv...@wi... > <mailto:riv...@wi...>> > *Cc:* pys...@li... > <mailto:pys...@li...> > *Subject:* Re: [pysnmp-users] Problem observed in new mib loading > > > > ** This mail has been sent from an external source ** > > Try adding `lookupNames=True`, `lookupValues=True` as shown here: > > > > > > http://pysnmp.sourceforge.net/examples/current/v3arch/oneliner/manager > /cmdgen/getnext-v2c-with-mib-resolution.html > > > > But even better upgrade to the latest pysnmp and you could skip the > explicit mibdump-based conversion step. > > > > > > http://pysnmp.sourceforge.net/examples/hlapi/asyncore/sync/manager/cmd > gen/walking-operations.html > > > > > > On 15 Dec 2016, at 07:11, <riv...@wi... > <mailto:riv...@wi...>> <riv...@wi... > <mailto:riv...@wi...>> wrote: > > > > Hi, > > > > I am trying to automate VM-MIB by using pysnmp. > > > > 1. Generated VM-MIB.py file from VM-MIB.txt by mibdump.py > --debug=all --mib-borrower=/usr/share/snmp/mibs/ VM-MIB.txt > > 2. Tried loadmib and addmibsource modules to load VM-MIB. > > > > Its loading the Object from VM-MIB as I am able to see the output > but the MIB name is showing as SNMPv2-SMI. > > Is it the right procedure to do or do we have any other process. > > > > #!/usr/bin/python > > from pysnmp.entity.rfc3413.oneliner import cmdgen > > > > cmdGen = cmdgen.CommandGenerator() > > > > errorIndication, errorStatus, errorIndex, varBindTable = > cmdGen.nextCmd( > > cmdgen.CommunityData('public'), > > cmdgen.UdpTransportTarget(('10.154.19.88', 161)), > > #cmdgen.MibVariable('VM-MIB', 'vmEntry').loadmibs(), > > lexicographicMode=True, maxRows=100, > > ignoreNonIncreasingOid=True > > ) > > #print varBindTable > > > > # Check for errors and print out results > > if errorIndication: > > print(errorIndication) > > else: > > if errorStatus: > > print('%s at %s' % ( > > errorStatus.prettyPrint(), > > errorIndex and varBindTable[int(errorIndex)-1] or '?' > > ) > > ) > > else: > > #for name, val in varBindTable: > > #print('%s = %s' % (name.prettyPrint(), > val.prettyPrint())) > > #print (varBindTable[0][0].prettyPrint() +' = '+ > varBindTable[0][1].prettyPrint()) > > len_value= len(varBindTable) > > output = open('template.txt','a') > > for i in range(0,len_value): > > output.write(varBindTable[i][0].prettyPrint()) > > output.write("\n") > > output.close() > > > > > > > > Getting this below output. > > > > > > SNMPv2-SMI::mib-2.23456.1.4.1.2.2 = VM6 ----------- it should > represent as VM-MIB instead of SNMPV2-SMI > > SNMPv2-SMI::mib-2.23456.1.4.1.2.3 = VM1 > > SNMPv2-SMI::mib-2.23456.1.4.1.2.4 = VM2 > > SNMPv2-SMI::mib-2.23456.1.4.1.2.5 = VM3 > > SNMPv2-SMI::mib-2.23456.1.4.1.2.6 = VM4 > > > > > > > > Thanks & Regards, > > Riva. > The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments. WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email. www.wipro.com |