Working with SNMP

Hello,

I am working with SNMP in ruby, I have installed the SNMP library and
written these two functions for Set and Get request but when i rub this
I am getting

SNMP::RequestTimeout: host xx.xx.xx.xx.xx not responding

What might be the reason?

oid = '1.3.6.1.4.1.318.1.1.12.3.3.1.1.4';
result = GdPortalApcReboot.find_by_device_id(self.id) //this object will
have address, community_str and reset_port fields.

manager = SNMP::Manager.new(:Host => result.address,:Community =>
result.snmp_community_str)
        varbind = VarBind.new(oid.to_s + '.' + result.reset_port.to_s,
OctetString.new("3"))
        manager.set(varbind)
        manager.close

and

response = manager.get(oid.to_s + "." + result.reset_port.to_s)
          response.each_varbind do |vb|
            status = "#{vb.name.to_s} #{vb.value.to_s}
#{vb.value.asn1_type}"
          end
          manager.close

and i expect the output of snmpget as INTEGER:1 or INTEGER:2 or
INTEGER:3

Any help will be appreciated. Thanks in advance :slight_smile:

···

--
Posted via http://www.ruby-forum.com/.

The reason might be that host xx.xx.xx.xx.xx is not running an snmpd
or its snmpd might be too slow or its snmpd might be configured to not
respond to the host you are testing from. Unfortunately, there are
(likely many) other possibilities too.

Double check that you are using the correct host address, community
string, etc. and that the host is running snmpd. You could also try
to verify with the admin of the host that your client machine is
allowed to connect to the host (e.g. not blocked by a firewall).
Another option would be to use a network sniffer to see what is
actually being transmitted by your request.

···

On Tue, Jan 19, 2010 at 10:44 AM, Atheeq Pasha <atheeq@carmatec.com> wrote:

I am working with SNMP in ruby, I have installed the SNMP library and
written these two functions for Set and Get request but when i rub this
I am getting

SNMP::RequestTimeout: host xx.xx.xx.xx.xx not responding

What might be the reason?

You can open the Manager with :Timeout (and :Retries) options to
increase the time to wait for an answer, like:

SNMP::Manager.new(:Host => host,:Community => 'public', :Timeout => 5)

Martin

(...)

···

On Wed, 20 Jan 2010 00:44:21 +0900 Atheeq Pasha <atheeq@carmatec.com> wrote:

Hello,

I am working with SNMP in ruby, I have installed the SNMP library and
written these two functions for Set and Get request but when i rub
this I am getting

SNMP::RequestTimeout: host xx.xx.xx.xx.xx not responding

What might be the reason?

unknown wrote:

···

On Tue, Jan 19, 2010 at 10:44 AM, Atheeq Pasha <atheeq@carmatec.com> > wrote:

I am working with SNMP in ruby, I have installed the SNMP library and
written these two functions for Set and Get request but when i rub this
I am getting

SNMP::RequestTimeout: host xx.xx.xx.xx.xx not responding

What might be the reason?

The reason might be that host xx.xx.xx.xx.xx is not running an snmpd
or its snmpd might be too slow or its snmpd might be configured to not
respond to the host you are testing from. Unfortunately, there are
(likely many) other possibilities too.

Double check that you are using the correct host address, community
string, etc. and that the host is running snmpd. You could also try
to verify with the admin of the host that your client machine is
allowed to connect to the host (e.g. not blocked by a firewall).
Another option would be to use a network sniffer to see what is
actually being transmitted by your request.

Thank you for that useful information.
Do we have to close the Manager class after every set and get methods.
Because I am using snmpset for manipulating and then snmpget for
retrieving in the same function.
--
Posted via http://www.ruby-forum.com/\.

I haven't used this library before, but I don't think you should (need
to) close the Manager; I think you should be able to:

SNMP::Manager.open(...){|manager|
  ...
  manager.set...
  ...
  manager.get...
  ...
}

(I'm using the block form there instead of explicit new and close.)

···

On Tue, Jan 19, 2010 at 12:11 PM, Atheeq Pasha <atheeq@carmatec.com> wrote:

Do we have to close the Manager class after every set and get methods.
Because I am using snmpset for manipulating and then snmpget for
retrieving in the same function.

Hello,

I've not used the ruby snmp library yet. But I have been using ruby to
drive NetSNMP.
It's a good tool to use to make sure the agent that you're trying to
communicate with
is working properly. Also using wireshark to see what going on is also
useful - it allows
you to load your device specific mibs.

regards,
Darryl

···

On Jan 19, 2:51 pm, brab...@gmail.com wrote:

On Tue, Jan 19, 2010 at 12:11 PM, Atheeq Pasha <ath...@carmatec.com> wrote:
> Do we have to close the Manager class after every set and get methods.
> Because I am using snmpset for manipulating and then snmpget for
> retrieving in the same function.

I haven't used this library before, but I don't think you should (need
to) close the Manager; I think you should be able to:

SNMP::Manager.open(...){|manager|
...
manager.set...
...
manager.get...
...

}

(I'm using the block form there instead of explicit new and close.)

I've not used the ruby snmp library yet. But I have been using ruby to
drive NetSNMP.
It's a good tool to use to make sure the agent that you're trying to
communicate with
is working properly. Also using wireshark to see what going on is also
useful - it allows
you to load your device specific mibs.

regards,
Darryl

Darryl, isn't driving NetSNMP's cli client from ruby a little
cumbersome? Or are you using the libs directly through ffi?

For simple snmp stuff I've been using the s2nmp library.
http://members.at.infoseek.co.jp/m6809/

It's pretty straight forward, like this little snippet (this just gets
the status of the consumables on a printer).

#!/usr/bin/ruby
require 'socket'
require 's2nmp'
printer=SNMP.new("lj2")
printer.get("public",["1.3.6.1.2.1.43.11.1.1.9.1.1"])
puts printer.vars

Kyle Schmitt wrote:

Darryl

Darryl, isn't driving NetSNMP's cli client from ruby a little
cumbersome? Or are you using the libs directly through ffi?

For simple snmp stuff I've been using the s2nmp library.
http://members.at.infoseek.co.jp/m6809/

It's pretty straight forward, like this little snippet (this just gets
the status of the consumables on a printer).

#!/usr/bin/ruby
require 'socket'
require 's2nmp'
printer=SNMP.new("lj2")
printer.get("public",["1.3.6.1.2.1.43.11.1.1.9.1.1"])
puts printer.vars

Hello Kyle,

It seems simpler and pretty straight forward. I am using this set method
to remote reboot APC PDU device via snmp.

Can you rewrite this function using s2nmp set method for me

oid = '1.3.6.1.4.1.318.1.';
result = GdPortalApcReboot.find_by_device_id(1963)

result.address //will have the IP address
result.snmp_community_str //will contain community string
result.reset_port //contain the reset_port.

manager = SNMP::Manager.new(:Host => result.address,:Community =>
result.snmp_community_str)
        varbind = VarBind.new(oid.to_s + '.' + result.reset_port.to_s,
OctetString.new("3"))
        manager.set(varbind)
        manager.close

???

and this with s2nmp get method

SNMP::Manager.open(:Host => result.address) do |manager|
            response = manager.get(oid.to_s + "." +
result.reset_port.to_s)
            response.each_varbind do |vb|
              status = "#{vb.name.to_s} #{vb.value.to_s}
#{vb.value.asn1_type}"
            end
          end

???

When i run these functions I am getting SNMP::RequestTimeout Host
xx.xx.xx.xx not responding.

Any kind of help will be appreciated. Thanks in advance :slight_smile:

···

--
Posted via http://www.ruby-forum.com/\.