Snmp Gauge 32 .to_s or .to_i?

Hi,

does anybody have an idea how to tranform a Gauge 32 value into a
integer value or string?

Here the code:

#!/usr/bin/ruby -w

require ‘yaml’
require ‘snmp’

oid_for_established_ipsec_tunnels = “1.3.6.1.4.1.9.9.171.1.3.1.1.0”
host = “192.168.0.1”
rocommunity = “readonly”
check_established_tunnels = 6

manager = SNMP::Manager.new(:Host => host, :Port => 161, :Community =>
rocommunity)
response = manager.get([oid_for_established_ipsec_tunnels])
#response.each_varbind {|vb| puts vb.value}
gathered_established_tunnels = response.each_varbind {|vb| puts
vb.value}
manager.close

puts gathered_established_tunnels

Here the output:

./get-asa-tunnels.rb
6
[name=1.3.6.1.4.1.9.9.171.1.3.1.1.0, value=6 (Gauge32)]

Any ideas how I can assign the value (in this case 6) to the variable
gathered_established_tunnels ?

bye
Henry

Heinrich P. wrote:

Hi,

does anybody have an idea how to tranform a Gauge 32 value into a
integer value or string?

Here the code:

#!/usr/bin/ruby -w

require ‘yaml’
require ‘snmp’

oid_for_established_ipsec_tunnels = “1.3.6.1.4.1.9.9.171.1.3.1.1.0”
host = “192.168.0.1”
rocommunity = “readonly”
check_established_tunnels = 6

manager = SNMP::Manager.new(:Host => host, :Port => 161, :Community =>
rocommunity)
response = manager.get([oid_for_established_ipsec_tunnels])
#response.each_varbind {|vb| puts vb.value}
gathered_established_tunnels = response.each_varbind {|vb| puts
vb.value}
manager.close

puts gathered_established_tunnels

Here the output:

./get-asa-tunnels.rb
6
[name=1.3.6.1.4.1.9.9.171.1.3.1.1.0, value=6 (Gauge32)]

Any ideas how I can assign the value (in this case 6) to the variable
gathered_established_tunnels ?

bye
Henry

OK - got it myself:

changed the code to the following lines

response = manager.get_value([oid_for_established_ipsec_tunnels])
#response.each_varbind {|vb| puts vb.value}
#gathered_established_tunnels = response.each_varbind {|vb| puts
vb.value}
gathered_established_tunnels = response.to_s

Hi Henry,

This is chandra sekhar and I am new to ruby. for my proj reqs, i am
developing a ruby script for snmp MIBs.

However, I got stuck up in SNMP SET for Gauge value.

could you please help me out.

Thanks in advance

here’s my script

   SNMP::Manager.open( :Host => bsmiIp,
                       :Version => :SNMPv2c,
                       :Community =>community password,
                       :Timeout => 5) do |manager|

    userID = VarBind.new("1.3.6.1.4.1.100.106.34.1.0",
             OctetString.new(userName))

             manager.set(userID)

    pass = VarBind.new("1.3.6.1.4.1.100.106.34.2.0",
           OctetString.new(password))

           manager.set(pass)

    varbind = VarBind.new("1.3.6.1.4.1.100.106.27.2.1.1.1",
              Gauge.new(10))

              manager.set(varbind)

Thanks,
Chandra

Heinrich P. wrote in post #660504:

Heinrich P. wrote:

Hi,

does anybody have an idea how to tranform a Gauge 32 value into a
integer value or string?

Here the code:

#!/usr/bin/ruby -w

require ‘yaml’
require ‘snmp’

oid_for_established_ipsec_tunnels = “1.3.6.1.4.1.9.9.171.1.3.1.1.0”
host = “192.168.0.1”
rocommunity = “readonly”
check_established_tunnels = 6

manager = SNMP::Manager.new(:Host => host, :Port => 161, :Community =>
rocommunity)
response = manager.get([oid_for_established_ipsec_tunnels])
#response.each_varbind {|vb| puts vb.value}
gathered_established_tunnels = response.each_varbind {|vb| puts
vb.value}
manager.close

puts gathered_established_tunnels

Here the output:

./get-asa-tunnels.rb
6
[name=1.3.6.1.4.1.9.9.171.1.3.1.1.0, value=6 (Gauge32)]

Any ideas how I can assign the value (in this case 6) to the variable
gathered_established_tunnels ?

bye
Henry

OK - got it myself:

changed the code to the following lines

response = manager.get_value([oid_for_established_ipsec_tunnels])
#response.each_varbind {|vb| puts vb.value}
#gathered_established_tunnels = response.each_varbind {|vb| puts
vb.value}
gathered_established_tunnels = response.to_s

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs