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:
- FreeBSD-3.3, UCD-SNMP-4.0.1
- FreeBSD-3.2, UCD-SNMP-3.6.1
- debian(potato), UCD-SNMP-4.1.1
- sparc SunOS 5.7, UCD-SNMP-4.1.2
Changes
rubysnmp 0.2.1
- Add walk, <, >, ==, !=, <=, >= methods for MIBView class.
rubysnmp 0.2.0
- Add SNMP module and MIBView class.
- Move all classes under SNMP module.
rubysnmp 0.1.6
- Fix value() to return unsigned integer for Counter, Gauge, TimeTicks.
- Fix session retry.
- Add retry!() method.
rubysnmp 0.1.5
- Support old UCD-SNMP lib without SNMP_FREE, SNMPv3, init_snmp(arg).
- Fix value() for TimeTicks.
rubysnmp 0.1.4
- Fix community string bug.(lost community string after first get)
- Fix snmpwalk oid checking.
- Change snmpwalk specification.
- Fix SNMPVAR free() bug.
rubysnmp 0.1.3
- Fix snmpwalk critical bug.
rubysnmp 0.1.2
- Add timeout! method
- Fix system error handling.
- Fix value() method for OBJECT_OID type.
- Fix broken version ucd-snmp library's error handling.
rubysnmp 0.1.1
- Supports Ruby thread.
- Add community! method.
- Call rb_raise when an error occured.
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