Ruby SNMP

Ruby SNMP is UCD-SNMP library interface for the Ruby. A current version is 0.2.1 (unstable), only supporting SNMP protocols are SNMPv1 GET, GETNEXT reqest. Currently, tested platforms are:

Changes

rubysnmp 0.2.1 rubysnmp 0.2.0 rubysnmp 0.1.6 rubysnmp 0.1.5 rubysnmp 0.1.4 rubysnmp 0.1.3 rubysnmp 0.1.2 rubysnmp 0.1.1

Install

Before installing SNMP Ruby, you must install UCD-SNMP library.

To install Ruby SNMP, download rubysnmp-0.2.1.tgz (older versions: rubysnmp-0.0.0.tgz, rubysnmp-0.1.1.tgz, rubysnmp-0.1.2.tgz, rubysnmp-0.1.3.tgz, rubysnmp-0.1.4.tgz, rubysnmp-0.1.5.tgz, rubysnmp-0.1.6.tgz, rubysnmp-0.2.0.tgz) , extract it, and make. Show sample instructions.

Classes, module and method

Ruby SNMP provides SNMP and SNMPVAR class. Methods of SNMP and SNMPVAR class are below:

Module

Classes

Following classes are defined under the SNMP module.

How to use

See example programs below.

SNMP GET

Request 'system.sysDescr.0' variable of router1 with 'public' community name.
       # Load SNMP Ruby library.
       require 'snmp.o'

       agent_hostname = "router1.internal.net"
       agent_community = "public"

       s = SNMP::Session.open agent_hostname, agent_community
       v = s.get [ 'sysDescr.0', 'sysUpTime.0' ]
       STDOUT.printf "System Description:%s\n", v[0].value()
       STDOUT.printf "System Up Time:%s\n", v[1].value()
       s.close()
    

SNMP GETNEXT

Same as above. Request a next of 'sysDescr.0'.
       require 'snmp.o'

       agent_hostname = "router1.internel.net"
       agent_community = "public"

       s = SNMP::Session.open agent_hostname, agent_community
       v = s.getnext 'sysDescr'
       STDOUT.print "System Description OID:"
       v[0].oid().each {|i| STDOUT.printf("%d ",i)}
       s.close()
    

SNMP WALK

Get all interface descriptions under the router1.
       require 'snmp.o'

       agent_hostname = "router1.internel.net"
       agent_community = "public"

       s = SNMP::Session.open agent_hostname, agent_community
       v = s.walk(['ifDescr']) {|x| print x[0].value()}
       s.close()
    

Nobuhiko Tsuruoka
--> Last modified: Mon Jul 10 19:18:13 JST 2000