# ActiveRecord help

**URL:** <https://www.ruby-forum.com/t/activerecord-help/126889>\
**Category:** Ruby\
**Created:** [January 23, 2008, 3:48am UTC](https://www.ruby-forum.com/t/activerecord-help/126889 "2008-01-23T03:48:18Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jasonb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a587f6/32.png) [@jasonb](https://www.ruby-forum.com/u/jasonb)\
**Post date:** [January 23, 2008, 3:48am UTC](https://www.ruby-forum.com/t/activerecord-help/126889/1 "2008-01-23T03:48:18Z")

</div>

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 😛 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
