jbreeden / net-snmp2

Cross platform net-snmp wrapper for Ruby, building on the original net-snmp gem
MIT License
4 stars 3 forks source link

snmp_sess_synch_response (Net::SNMP::Error) in session.rb #7

Open stideswell opened 6 years ago

stideswell commented 6 years ago

Hello

My SNMP server (on the loopback address) is listening and responding to SNMP gets OK (over SNMPv3).

$ snmpget -v 3 -u obfuscated -a SHA -A obfuscated -x AES -X obfuscated \\
                         -l authPriv 127.0.0.1 1.3.6.1.4.1.2021.11.54.0
iso.3.6.1.4.1.2021.11.54.0 = Counter32: 61037

Here's how I use net-snmp2 in my script (salient elements only) ...

require 'net-snmp2'
session = Net::SNMP::Session.open(:peername => "127.0.0.1", :version => 3,
                               :community => "obfuscated",
                               :security_level => Net::SNMP::Constants::SNMP_SEC_LEVEL_AUTHPRIV,
                               :username => "obfuscated", :auth_protocol => :sha1, 
                               :auth_password => "obfuscated",
                               :priv_protocol => :aes, :priv_password => "obfuscated")
pdu = session.get("1.3.6.1.4.1.2021.11.54.0")

The last line above is on line 132 of my script.

When I run it I get the following output ...

/var/lib/gems/2.5.0/gems/net-snmp2-0.3.1/lib/net/snmp/pdu.rb:25: warning: constant ::Fixnum is deprecated
/var/lib/gems/2.5.0/gems/net-snmp2-0.3.1/lib/net/snmp/pdu.rb:144: warning: constant ::Fixnum is deprecated
Traceback (most recent call last):
    4: from ./check_cpu.rb:**132**:in `<main>'
    3: from /var/lib/gems/2.5.0/gems/net-snmp2-0.3.1/lib/net/snmp/session.rb:192:in `get'
    2: from /var/lib/gems/2.5.0/gems/net-snmp2-0.3.1/lib/net/snmp/session.rb:469:in `send_pdu'
    1: from /var/lib/gems/2.5.0/gems/net-snmp2-0.3.1/lib/net/snmp/session.rb:521:in `send_pdu_blocking'
/var/lib/gems/2.5.0/gems/net-snmp2-0.3.1/lib/net/snmp/session.rb:271:in `error': snmp_sess_synch_response (Net::SNMP::Error)

I'm a total Ruby newbie and cannot work out why this is not working!?

If I run the CLI, it works as expected (well, except for the warnings).

$ net-snmp2 
[1] snmp(#<Net::SNMP::ManagerRepl>)> manage :peername => '127.0.0.1', :version => '3', :security_level => Net::SNMP::Constants::SNMP_SEC_LEVEL_AUTHPRIV,:username => 'obfuscated', :auth_protocol => :sha1, :auth_password => "obfuscated", :priv_protocol => :aes, :priv_password => "obfuscated"
=> "Opened session to manage peer: 127.0.0.1"
[2] snmp(#<Net::SNMP::ManagerRepl>)> get '1.3.6.1.4.1.2021.11.54.0'

127.0.0.1:161

1.3.6.1.4.1.2021.11.54.0
/var/lib/gems/2.5.0/gems/net-snmp2-0.3.1/lib/net/snmp/pdu.rb:25: warning: constant ::Fixnum is deprecated
/var/lib/gems/2.5.0/gems/net-snmp2-0.3.1/lib/net/snmp/pdu.rb:144: warning: constant ::Fixnum is deprecated
== PDU ==
Command: 162
 - Varbinds:
   + iso.3.6.1.4.1.2021.11.54.0(1.3.6.1.4.1.2021.11.54.0) = 61051

=> "GET"

$ ruby -v
ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-linux-gnu]
$ gem list | grep net-snmp2
net-snmp2 (0.3.1)
stideswell commented 6 years ago

I forgot to mention, this is seen on Ubuntu 16 & 18.

jbreeden commented 6 years ago

Just FYI: You can wrap code in three backticks to improve readability. I've already updated the description.

I'll try to take a look at the actual problem, and the warnings, more closely when I get a chance. Though admittedly I haven't had cause to use SNMP in some time, so I'm not sure what kind of expedience guarantees I can make.