N
Nicola Tiling
Hi
I'm a ruby newbie and need a little help. I think I'm wrong with class =
and instance methods? I can't figure out how to do a decode a snmp =
output.
I use the snmp library http://rubyforge.org/projects/snmplib/
My script:
#!/usr/local/bin/ruby18 -w
require "rubygems"
gem "snmp"
require "snmp"
SNMP::Manager.openHost =3D> '192.168.0.253', :Version =3D> :SNMPv1, =
:Community =3D> 'public') do |manager|
manager.load_module("RC-VLAN-MIB")
48.times do |i|
i =3D i+1
response =3D manager.get(["rcVlanPortVlanIds.#{i}"])
response.each_varbind do |varbind|
p varbind.value
end
end
end
The output is like this
"\000\001\000\004\000\005\000\006\000\f"
"\000\001\000\f"
"\000\001\000\002\000\005\000\006\000\a\000\b\000\v\000\f\000\r"
"\000\001"
But I want to decode this output to integer vlan id's.=20
1,4,5,6,12
1,12
1,2,5,6,7,8,11,12,13
1
How can I do it with methodes from the snmp library? I'm playing with =
decode and decode_value. But the only result was
"undefined method `decode' for #<SNMP::VarBind:0x801fc7ca0> =
(NoMethodError)"
But "decode" is a (Public Class) methode of VarBind and I don't =
understand what's wrong.
http://snmplib.rubyforge.org/doc/index.html
Also I don't understand why "f" stands for "12" and "v" for "11" and "r" =
for "13"
ruby says it is a octet string ("p varbind.value.asn1_type" shows "OCTET =
STRING")
With net-snmp I fetch vlan ids per port in hex
snmpwalk -v 1 -c public -m RC-VLAN-MIB 192.168.0.253 =
1.3.6.1.4.1.2272.1.3.3.1.3=20
I get:
RC-VLAN-MIB::rcVlanPortVlanIds.1 =3D Hex-STRING: 00 01 00 04 00 =
05 00 06 00 0C=20
RC-VLAN-MIB::rcVlanPortVlanIds.2 =3D Hex-STRING: 00 01 00 0C=20
RC-VLAN-MIB::rcVlanPortVlanIds.3 =3D Hex-STRING: 00 01 00 02 00 =
05 00 06 00 07 00 08 00 0B 00 0C=20
Nicola=
I'm a ruby newbie and need a little help. I think I'm wrong with class =
and instance methods? I can't figure out how to do a decode a snmp =
output.
I use the snmp library http://rubyforge.org/projects/snmplib/
My script:
#!/usr/local/bin/ruby18 -w
require "rubygems"
gem "snmp"
require "snmp"
SNMP::Manager.openHost =3D> '192.168.0.253', :Version =3D> :SNMPv1, =
:Community =3D> 'public') do |manager|
manager.load_module("RC-VLAN-MIB")
48.times do |i|
i =3D i+1
response =3D manager.get(["rcVlanPortVlanIds.#{i}"])
response.each_varbind do |varbind|
p varbind.value
end
end
end
The output is like this
"\000\001\000\004\000\005\000\006\000\f"
"\000\001\000\f"
"\000\001\000\002\000\005\000\006\000\a\000\b\000\v\000\f\000\r"
"\000\001"
But I want to decode this output to integer vlan id's.=20
1,4,5,6,12
1,12
1,2,5,6,7,8,11,12,13
1
How can I do it with methodes from the snmp library? I'm playing with =
decode and decode_value. But the only result was
"undefined method `decode' for #<SNMP::VarBind:0x801fc7ca0> =
(NoMethodError)"
But "decode" is a (Public Class) methode of VarBind and I don't =
understand what's wrong.
http://snmplib.rubyforge.org/doc/index.html
Also I don't understand why "f" stands for "12" and "v" for "11" and "r" =
for "13"
ruby says it is a octet string ("p varbind.value.asn1_type" shows "OCTET =
STRING")
With net-snmp I fetch vlan ids per port in hex
snmpwalk -v 1 -c public -m RC-VLAN-MIB 192.168.0.253 =
1.3.6.1.4.1.2272.1.3.3.1.3=20
I get:
RC-VLAN-MIB::rcVlanPortVlanIds.1 =3D Hex-STRING: 00 01 00 04 00 =
05 00 06 00 0C=20
RC-VLAN-MIB::rcVlanPortVlanIds.2 =3D Hex-STRING: 00 01 00 0C=20
RC-VLAN-MIB::rcVlanPortVlanIds.3 =3D Hex-STRING: 00 01 00 02 00 =
05 00 06 00 07 00 08 00 0B 00 0C=20
Nicola=