ActiveRecord help

J

Jason Ballou

Im a ruby newb trying to learn how pull snmp data from devices and put
into database. I am testing with two paticular snmp entities: ifindex
and ifdescr and put the values from the poll into thier respective
colums/rows in a mysql db called test in the interfaces table. I tried
the unDRY conventions :p by duplicating my polls and putting them into
thier respective rows however I didnt get what i wanted. Being a super
newb, I am unable to figure out conceptually how to accomplish this. Any
assitance would be greatly appreciated.


DB output

the outcome i get is:
id interfaces
| 1 | NULL |
| 2 | NULL |
| 3 | NULL |
| 0 | Ethernet0/0 |
| 0 | Serial0/0 |
| 0 | Ethernet0/1 |


the outcome i would love to have is:
id interfaces

| 1 | Ethernet0/0 |
| 2 | Serial0/0 |
| 3 | Ethernet0/1 |


My code

require 'rubygems'
require 'snmp'
require 'mysql'
require 'active_record'

ActiveRecord::Base.establish_connection(
:adapter => "mysql",
:host => "localhost",
:database => "test"
)

class Server < ActiveRecord::Base
set_table_name "interfaces"
end


ifTable_columns = ["ifIndex", ]

SNMP::Manager.open:)Host => '10.0.0.1', :Version => :SNMPv2c, :Community
=> 'pub') do |manager|
manager.walk(ifTable_columns) do |row|
row.each { |vb| print "\t#{vb.value}"
server = Server.new
server.id = "#{vb.value}"
server.save
}



end
end

ifTable_columns = ["ifDescr", ]

SNMP::Manager.open:)Host => '10.0.0.1', :Version => :SNMPv2c, :Community
=> 'pub') do |manager|
manager.walk(ifTable_columns) do |row|
row.each { |vb| print "\t#{vb.value}"
server = Server.new
server.interfaces = "#{vb.value}"
server.save
}



end
end
 

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


Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top