Skip to content
This repository has been archived by the owner on Apr 21, 2023. It is now read-only.

Not working with v1 (maybe) #54

Closed
zhum opened this issue Jun 25, 2021 · 15 comments
Closed

Not working with v1 (maybe) #54

zhum opened this issue Jun 25, 2021 · 15 comments

Comments

@zhum
Copy link

zhum commented Jun 25, 2021

I'm trying to get some values from proprietary service, supporting only V1. It works fine with console program:

snmpget -v1 -c public 10.0.251.1 SNMPv2-SMI::enterprises.10159.1.2.2.1.1.24.17.51.101.101.54.48.48.48.57.49.48.48.48.53.49.48.48.49
SNMPv2-SMI::enterprises.10159.1.2.2.1.1.24.17.51.101.101.54.48.48.48.57.49.48.48.48.53.49.48.48.49 = STRING: "Shelf-3,2"

While simple ruby program fails with timeout:

cat snmp-test.rb
require 'netsnmp'
require "netsnmp/mib/parser"
require 'pp'

oid = NETSNMP::MIB.oid('SNMPv2-SMI::enterprises.10159.1.2.2.1.1.24.17.51.101.101.54.48.48.48.57.49.48.48.48.53.49.48.48.49')
ADDR = '10.0.251.1'
COMM = 'public'
TMOUT = 2

print "get!\n"

manager = NETSNMP::Client.new(
  :host => ADDR, :community => COMM,
  :version => 1, :timeout => TMOUT
)
response = manager.get(oid: oid)
pp response

ruby ./snmp-test.rb

get!
Traceback (most recent call last):
        12: from p2v.rb:19:in `<main>'
        11: from /home/serg/.gem/ruby/gems/netsnmp-0.4.1/lib/netsnmp/client.rb:55:in `get'
        10: from /home/serg/.gem/ruby/gems/netsnmp-0.4.1/lib/netsnmp/client.rb:155:in `handle_retries'
         9: from /home/serg/.gem/ruby/gems/netsnmp-0.4.1/lib/netsnmp/client.rb:55:in `block in get'
         8: from /home/serg/.gem/ruby/gems/netsnmp-0.4.1/lib/netsnmp/session.rb:45:in `send'
         7: from /home/serg/.gem/ruby/gems/netsnmp-0.4.1/lib/netsnmp/session.rb:88:in `send'
         6: from /home/serg/.gem/ruby/gems/netsnmp-0.4.1/lib/netsnmp/session.rb:98:in `recv'
         5: from /home/serg/.gem/ruby/gems/netsnmp-0.4.1/lib/netsnmp/session.rb:107:in `perform_io'
         4: from /home/serg/.gem/ruby/gems/netsnmp-0.4.1/lib/netsnmp/session.rb:107:in `loop'
         3: from /home/serg/.gem/ruby/gems/netsnmp-0.4.1/lib/netsnmp/session.rb:109:in `block in perform_io'
         2: from /home/serg/.gem/ruby/gems/netsnmp-0.4.1/lib/netsnmp/session.rb:99:in `block in recv'
         1: from /opt/rh/rh-ruby27/root/usr/share/ruby/socket.rb:1272:in `recvfrom_nonblock'
/opt/rh/rh-ruby27/root/usr/share/ruby/socket.rb:1272:in `__recvfrom_nonblock': Resource temporarily unavailable - recvfrom(2) would block (IO::EAGAINWaitReadable)
        11: from p2v.rb:19:in `<main>'
        10: from /home/serg/.gem/ruby/gems/netsnmp-0.4.1/lib/netsnmp/client.rb:55:in `get'
         9: from /home/serg/.gem/ruby/gems/netsnmp-0.4.1/lib/netsnmp/client.rb:155:in `handle_retries'
         8: from /home/serg/.gem/ruby/gems/netsnmp-0.4.1/lib/netsnmp/client.rb:55:in `block in get'
         7: from /home/serg/.gem/ruby/gems/netsnmp-0.4.1/lib/netsnmp/session.rb:45:in `send'
         6: from /home/serg/.gem/ruby/gems/netsnmp-0.4.1/lib/netsnmp/session.rb:88:in `send'
         5: from /home/serg/.gem/ruby/gems/netsnmp-0.4.1/lib/netsnmp/session.rb:98:in `recv'
         4: from /home/serg/.gem/ruby/gems/netsnmp-0.4.1/lib/netsnmp/session.rb:107:in `perform_io'
         3: from /home/serg/.gem/ruby/gems/netsnmp-0.4.1/lib/netsnmp/session.rb:107:in `loop'
         2: from /home/serg/.gem/ruby/gems/netsnmp-0.4.1/lib/netsnmp/session.rb:108:in `block in perform_io'
         1: from /home/serg/.gem/ruby/gems/netsnmp-0.4.1/lib/netsnmp/session.rb:111:in `rescue in block in perform_io'
/home/serg/.gem/ruby/gems/netsnmp-0.4.1/lib/netsnmp/session.rb:120:in `wait': Timeout after 2 seconds (Timeout::Error)

How can I debug this?

@HoneyryderChuck
Copy link
Collaborator

hi @zhum ,

Hum... seems like a network issue. Do you mind running this in debug mode?

Also, you don't need to set the :timeout, as there's already a 2 sec default.

@zhum
Copy link
Author

zhum commented Jun 25, 2021

Here is the output (repeated several times):

sending request...

pdu: 3041
        snmp_version: 0201 ("1")
        community: xxxx xxxx xxxx xxxx ("commuity name here")
        request: a033
                request_id: 0204 221e 8d1f ("572427551")
                error: 0201 ("0")
                error_index: 0201 ("0")
                varbinds: 3025
                        Sequence: 3023
                                ObjectId: 061f 2b06 0104 01cf 2f01 0202 0101 1811 3365 6536 3030 3039 3130 3030 3531 3030 ("1.3.6.1.4.1.10159.1.2.2.1.1.24.17.51.101.101.54.48.48.48.57.49.48.48.48.53.49.48.48.49")
                                Null: 0500

3041 0201 0104 0770 616e 6c6f 6d32 a033
0204 221e 8d1f 0201 0002 0100 3025 3023
061f 2b06 0104 01cf 2f01 0202 0101 1811
3365 6536 3030 3039 3130 3030 3531 3030
3105

@zhum
Copy link
Author

zhum commented Jun 25, 2021

Here is tcpdump of console snmpget:

14:19:03.546387 IP manage-02.52723 > 10.0.251.1.snmp:  C=xxxxxxxx GetRequest(51)  E:10159.1.2.2.1.1.24.17.51.101.101.54.48.48.48.57.49.48.48.48.53.49.48.48.49
        0x0000:  4500 005f 943f 4000 4011 9e4a 0a00 f902
        0x0010:  0a00 fb01 cdf3 00a1 004b 0861 3041 0201
        0x0020:  0004 0770 616e 6c6f 6d32 a033 0204 32d3
        0x0030:  9cb2 0201 0002 0100 3025 3023 061f 2b06
        0x0040:  0104 01cf 2f01 0202 0101 1811 3365 6536
        0x0050:  3030 3039 3130 3030 3531 3030 3105 00

May be last 00 byte in ruby code transmission is missing?

@HoneyryderChuck
Copy link
Collaborator

Could you also tcpdump the packets for netsnmp example? Just making sure that it's send packets to the right peer.

@zhum
Copy link
Author

zhum commented Jun 25, 2021

Here it is:

17:41:41.649167 IP manage-02.35647 > 10.0.251.1.snmp:  C=xxxxxxxxx GetRequest(51)  E:10159.1.2.2.1.1.24.17.51.101.101.54.48.48.48.57.49.48.48.48.53.49.48.48.49
        0x0000:  4500 005f 94b3 4000 4011 9dd6 0a00 f902
        0x0010:  0a00 fb01 8b3f 00a1 004b 0861 3041 0201
        0x0020:  0104 0770 616e 6c6f 6d32 a033 0204 0e00
        0x0030:  a1ee 0201 0002 0100 3025 3023 061f 2b06
        0x0040:  0104 01cf 2f01 0202 0101 1811 3365 6536
        0x0050:  3030 3039 3130 3030 3531 3030 3105 00

@HoneyryderChuck
Copy link
Collaborator

Ok, so we confirmm that the packet is well-formed, and it's sent to the right peer. I guess the legacy device takes longer to reply? Try increasing the :timeout to, let's say, 10.

@zhum
Copy link
Author

zhum commented Jun 28, 2021

Tried this, didn't help... Seems very strange, may be my legacy device has some peculiarity, but how can we detect it?

@HoneyryderChuck
Copy link
Collaborator

can you run run snmpget in verbose mode (-DALL, or perhaps lower verbosity, if it helps your case), and see if there's anything in the output that might help uncover what snmpget does that netsnmp doesn't?

@zhum
Copy link
Author

zhum commented Jun 28, 2021

Here is the log:
snmp-get.log

It seems strange, that answer for a request was received very fast, but in case ruby code there was no answer at all...

@HoneyryderChuck
Copy link
Collaborator

HoneyryderChuck commented Jun 29, 2021

@zhum can you try theissue-54 branch to see if it fixes your issue?.

EDIT: Also forgot to ask: what's your environment, i.e. OS, ruby version, etc.

@zhum
Copy link
Author

zhum commented Jun 30, 2021

Did not help :(

I use Centos 7.8.2003, ruby 2.7 (via scl). Gem is installed via gem install --local), no bundler or rbenv yet. New version I've installed with git clone ...; cd ruby-netsnmp; git checkout issue-54; gem build; gem install --local netsnmp-0.4.2.gem.

@HoneyryderChuck
Copy link
Collaborator

I'm out of ideas for remote troubleshooting 😞 I think I'd I'd require remote access to figure out what's going on, as that's a weird network behaviour: the request packet goes, but the response never arrives...

Do you know how to work with wireshark? Could you inspect all UDP, SNMP traffic during your script run, to see if things are workingn as expected network-wise? Maybe compare it with the snmpget example of yours?

@zhum
Copy link
Author

zhum commented Jul 1, 2021

I can get you the remote ssh access, if you provide an open ssh key to me (serg at parallel.ru), also I can get you sudo access for tcpdump and wireshark.

HoneyryderChuck added a commit that referenced this issue Jul 4, 2021
privilege connectionless interactions, as agents might send PDUs from
destinations other than the ones the request was sent to.

Fixes #54.
@HoneyryderChuck
Copy link
Collaborator

@zhum I've found out what was going on. It was two things:

  • your script declares the wrong version (1 instead of 0). I understand the confusion, given how the README is more focused on the v3 case, but the documentation declares that, if you're passing an integer, then you should be passing the correct PDU version code, which in the case of "v1", it's 0 (snmp can be a bit confusing). In order to spare you the confusion, netsnmp allows you to pass "v1", so I suggest you use if from now on.
  • Even with the above, the current version wasn't able to get the PDU from a different source port, so I patched it to use connectionless UDPs. This did the trick. I still have to do some tweaks, but feel free to use the issue-54 branch, until I release a new version.

Thank you again for the collaboration.

@zhum
Copy link
Author

zhum commented Jul 5, 2021

Wow! Yes, it works with these notes. Thank you!

@zhum zhum closed this as completed Jul 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants