Fork me on GitHub
Ruby SNMP

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

Install

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.


SNMP::Manager.open(:MibModules => ["DOCS-IF-MIB"]) do |snmp|
  mac = ".0.224.111.203.106.116"
  value = snmp.get_value("docsIfCmtsCmPtr" << mac)
end

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"]
SNMP::Manager.open(:Host => 'localhost') do |manager|
  manager.walk(ifTable_columns) do |row|
    row.each { |vb| print "\t#{vb.value}" }
    puts
  end
end

Useful SNMP Tools

libsmi

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

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.