snmp help needed

F

faron.hopper

i am trying to get a port count and if they are up/down. here is the
code i have and the problem i am having is trying to get the data out
of the snmp::manager block. I am new to ruby and am not sure how to
procede. any help is appreciated

the example code from snmplib.rubyforge.org returns this data

FastEthernet0/1 1
FastEthernet0/2 1
FastEthernet0/3 1
FastEthernet0/4 2

and i want to keep track of the digit after FastEthernet0/x. my
original thought was to create a hash and capture the port and the
status, however, i am having trouble getting my mind to grasp how the
snmp function and ruby are interacting.


code
=========================================
require 'snmp'

host=ARGV.shift or raise "usage: port_count.rb hostname read_community"
community=ARGV.shift or raise "usage: port_count.rb hostname
read_community"

ifTable_columns = ["ifDescr", "ifOperStatus"]
oid = "1.3.6.1.2.1.2.2.1.2"

data = Hash.new(0)
data = {
'switchName' => host,
'port1' => '',
'port2' => '',
'port3' => '',
'port4' => '',
'port5' => '',
'port6' => '',
'port7' => '',
'port8' => '',
'port9' => '',
'port10' => '',
'port11' => '',
'port12' => '',
'port13' => '',
'port14' => '',
'port15' => '',
'port16' => '',
'port17' => '',
'port18' => '',
'port19' => '',
'port20' => '',
'port21' => '',
'port22' => '',
'port23' => '',
'port24' => '',
'port25' => '',
'port26' => '',
'port27' => '',
'port28' => '',
'port29' => '',
'port30' => '',
'port31' => '',
'port32' => '',
'port33' => '',
'port34' => '',
'port35' => '',
'port36' => '',
'port37' => '',
'port38' => '',
'port39' => '',
'port40' => '',
'port41' => '',
'port42' => '',
'port43' => '',
'port44' => '',
'port45' => '',
'port46' => '',
'port47' => '',
'port48' => '',
}
count = 0

SNMP::Manager.open:)Host => host, :Community => community) do |manager|
manager.walk("ifOperStatus") do |row|
row.each { |vb| if "#{vb.value}" =~ /thernet/ then
data["port#{count}"] = "#{vb.value}"
count +=1
print "port#{count}=#{vb.value}\n"
end
}
#print "."
end
end
print "count = #{count}\n"
puts
puts
data.each {|key,value| puts "#{key} => #{value}"}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

ActiveRecord help 0
Need help to decode snmp string 2
SNMP oid error 1
snmp error 0
SNMP trap forwarding. 0
Working with SNMP 7
snmp with s2nmp or rubyonrails 0
snmp Gauge 32 .to_s or .to_i ??? 1

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top