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.open(:Host => '192.168.0.253', :Version => :SNMPv1, :Community => 'public') do |manager|
manager.load_module("RC-VLAN-MIB")
48.times do |i|
i = i+1
response = 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.
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
I get:
RC-VLAN-MIB::rcVlanPortVlanIds.1 = Hex-STRING: 00 01 00 04 00 05 00 06 00 0C
RC-VLAN-MIB::rcVlanPortVlanIds.2 = Hex-STRING: 00 01 00 0C
RC-VLAN-MIB::rcVlanPortVlanIds.3 = Hex-STRING: 00 01 00 02 00 05 00 06 00 07 00 08 00 0B 00 0C
Nicola