Fork me on GitHub

Network Management the Ruby Way

Network Equipment

If you want to write network management applications in Ruby, you're probably going to need an SNMP library. The goal of the Ruby SNMP project is to create an interface to SNMP that has the same intuitive, joyful feeling that the Ruby programming language does. With a crusty, old protocol like SNMP this is easier said than done, but we're working on it!

Getting Started


Using RubyGems all you need to do is:

gem install snmp

Import MIBs

If you are using standard IETF MIBs then you're ready to go. Most of the IETF MIBs have been included for you with Ruby SNMP. Just list the MIBs that you need when you open your SNMP session and you will have full symbolic access to all of the OIDs. => ["DOCS-IF-MIB"]) do |snmp|
  mac = "."
  value = snmp.get_value("docsIfCmtsCmPtr" << mac)

If you don't provide a MIB list then the default MIBs are loaded: SNMPv2-MIB, IF-MIB, IP-MIB, TCP-MIB, UDP-MIB

If you want to import custom MIBs, then have a look at the documentation for the SNMP::MIB class. If you use the import_module method, you will need to install libsmi first, or create the required YAML file manually.

Start Coding

Have a look at the documentation for the SNMP::Manager class. This class provides the main interface for sending and receiving SNMP PDUs.

Here's an example to get you started. You can find plenty more in the README file

require 'snmp'

ifTable_columns = ["ifIndex", "ifDescr", "ifInOctets", "ifOutOctets"] => 'localhost') do |manager|
  manager.walk(ifTable_columns) do |row|
    row.each { |vb| print "\t#{vb.value}" }

Useful SNMP Tools


The libsmi distribution includes some very useful tools for checking, analyzing, converting, and comparing MIBs. It also contains a complete archive of IETF and IANA MIBs which saves you from having to find and download them yourself.


Net-SNMP includes SNMP libraries for implementing SNMP agents and managers in C and a set of SNMP tools for setting and getting information from SNMP agents.