exhuma / puresnmp

Pure Python SNMPv2 Library
MIT License
79 stars 22 forks source link

multiget to SNMPv1 device timeout #86

Closed mig21a closed 3 years ago

mig21a commented 4 years ago

Issue Description

pursnmp 1.9.1

python3

from puresnmp import multiget result = multiget('x.x.x.x', 'public', ['1.3.6.1.2.1.1.5.0'], port=161, timeout=3, version=1) Traceback (most recent call last): File "", line 1, in File "/ec/acc/app/dynatrace/OneAgent_SDK/py36a/lib/python3.6/site-packages/puresnmp/api/pythonic.py", line 147, in multiget raw_output = raw.multiget(ip, community, oids, port, timeout, version=version) File "/ec/acc/app/dynatrace/OneAgent_SDK/py36a/lib/python3.6/site-packages/puresnmp/api/raw.py", line 97, in multiget response = transport.send(ip, port, to_bytes(packet)) File "/ec/acc/app/dynatrace/OneAgent_SDK/py36a/lib/python3.6/site-packages/puresnmp/transport.py", line 93, in send "Max of %d retries reached" % self.retries) # type: ignore puresnmp.exc.Timeout: Max of 3 retries reached

HexDump

DEBUG:puresnmp.transport:Sending packet to 10.65.100.80:161 (attempt 1/3) 30 29 02 01 01 04 06 70 75 62 6c 69 63 a0 1c 02 0).....public... 04 5f 6f c0 ae 02 01 00 02 01 00 30 0e 30 0c 06 ._o........0.0.. 08 2b 06 01 02 01 01 09 01 05 00 .+......... DEBUG:puresnmp.transport:Timeout during attempt #1 DEBUG:puresnmp.transport:Sending packet to 10.65.100.80:161 (attempt 2/3) 30 29 02 01 01 04 06 70 75 62 6c 69 63 a0 1c 02 0).....public... 04 5f 6f c0 ae 02 01 00 02 01 00 30 0e 30 0c 06 ._o........0.0.. 08 2b 06 01 02 01 01 09 01 05 00 .+......... DEBUG:puresnmp.transport:Timeout during attempt #2 DEBUG:puresnmp.transport:Sending packet to 10.65.100.80:161 (attempt 3/3) 30 29 02 01 01 04 06 70 75 62 6c 69 63 a0 1c 02 0).....public... 04 5f 6f c0 ae 02 01 00 02 01 00 30 0e 30 0c 06 ._o........0.0.. 08 2b 06 01 02 01 01 09 01 05 00 .+......... DEBUG:puresnmp.transport:Timeout during attempt #3 Traceback (most recent call last): File "9.py", line 5, in result = multiget('10.65.100.80', 'public', ['1.3.6.1.2.1.1.9.1'], port=161, timeout=3, version=1) File "/ec/acc/app/dynatrace/OneAgent_SDK/py36a/lib/python3.6/site-packages/puresnmp/api/pythonic.py", line 147, in multiget raw_output = raw.multiget(ip, community, oids, port, timeout, version=version) File "/ec/acc/app/dynatrace/OneAgent_SDK/py36a/lib/python3.6/site-packages/puresnmp/api/raw.py", line 97, in multiget response = transport.send(ip, port, to_bytes(packet)) File "/ec/acc/app/dynatrace/OneAgent_SDK/py36a/lib/python3.6/site-packages/puresnmp/transport.py", line 93, in send "Max of %d retries reached" % self.retries) # type: ignore puresnmp.exc.Timeout: Max of 3 retries reached

Kind regards

exhuma commented 4 years ago

This is unlikely an issue with the SNMP library itself. The UDP connection itself gets a timeout.

This happens for example if the community string is incorrect.

If it is correct, then this can have a couple of reasons:

The network device is:

mig21a commented 4 years ago

Hello,

It is not firewall, switched off, comunnity string or not listening. I am able to collect data from same machine with perl net::snmp. snmpget.pl -v 1 -c public -p 161 10.65.100.80 .1.3.6.1.2.1.1.5.0 .1.3.6.1.2.1.1.5.0 = OCTET STRING: CMC-RJ15-1

Below is example for request with version=1 and without. I am not able to notice difference in the two request.

CODE

from puresnmp import multiget import logging logging.basicConfig(level=logging.DEBUG) result = multiget('10.218.161.24', 'public', ['.1.3.6.1.2.1.1.5.0'], port=161, timeout=3) result = multiget('10.65.100.80', 'public', ['.1.3.6.1.2.1.1.5.0'], port=161, timeout=3, version=1)

DEBUG

DEBUG:puresnmp.transport:Sending packet to 10.218.161.24:161 (attempt 1/3) 30 29 02 01 01 04 06 70 75 62 6c 69 63 a0 1c 02 0).....public... 04 5f 70 d7 37 02 01 00 02 01 00 30 0e 30 0c 06 ._p.7......0.0.. 08 2b 06 01 02 01 01 05 00 05 00 .+......... DEBUG:puresnmp.transport:Received packet: 30 34 02 01 01 04 06 70 75 62 6c 69 63 a2 27 02 04.....public.'. 04 5f 70 d7 37 02 01 00 02 01 00 30 19 30 17 06 ._p.7......0.0.. 08 2b 06 01 02 01 01 05 00 04 0b 43 4d 43 2d 52 .+.........CMC-R 33 38 31 35 2d 31 3815-1 DEBUG:puresnmp.transport:Sending packet to 10.65.100.80:161 (attempt 1/3) 30 29 02 01 01 04 06 70 75 62 6c 69 63 a0 1c 02 0).....public... 04 5f 70 d7 37 02 01 00 02 01 00 30 0e 30 0c 06 ._p.7......0.0.. 08 2b 06 01 02 01 01 05 00 05 00 .+......... DEBUG:puresnmp.transport:Timeout during attempt #1 DEBUG:puresnmp.transport:Sending packet to 10.65.100.80:161 (attempt 2/3) 30 29 02 01 01 04 06 70 75 62 6c 69 63 a0 1c 02 0).....public... 04 5f 70 d7 37 02 01 00 02 01 00 30 0e 30 0c 06 ._p.7......0.0.. 08 2b 06 01 02 01 01 05 00 05 00 .+......... DEBUG:puresnmp.transport:Timeout during attempt #2 DEBUG:puresnmp.transport:Sending packet to 10.65.100.80:161 (attempt 3/3) 30 29 02 01 01 04 06 70 75 62 6c 69 63 a0 1c 02 0).....public... 04 5f 70 d7 37 02 01 00 02 01 00 30 0e 30 0c 06 ._p.7......0.0.. 08 2b 06 01 02 01 01 05 00 05 00 .+.........

exhuma commented 4 years ago

Are you able to fetch the "sysObjectId" (1.3.6.1.2.1.1.2.0) with a simple puresnmp.get(...) instead of a "multiget" call?

SNMPv1 is not thoroughly tested so there might be some issues with it that I have not seen yet.

mig21a commented 4 years ago

It is not responding. There is no version available in get function.

frogmaster commented 3 years ago

I think version argument type is in actuality puresnmp.const.Version.V2c or V1. Integer values of those don't correspond to snmp version. V2c is 1 and V1 is 0. So when you passed version=1 you actually made a v2c call. The proper call would be:

from puresnmp.const import Version
result = multiget('x.x.x.x', 'public', ['1.3.6.1.2.1.1.5.0'], port=161, timeout=3, version=Version.V1)

I guess this issue could be safely closed.

exhuma commented 3 years ago

Good catch. I'll close this.

I really hope I'll get puresnmp-2.0 out soon. This will clarify this.

Waiting for a minor response from our legal dept which is the only blocker for now 😄