![]()
|
Ruby SNMPRuby 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:
Changesrubysnmp 0.2.1
InstallBefore 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 methodRuby SNMP provides SNMP and SNMPVAR class. Methods of SNMP and SNMPVAR class are below:ModuleClassesFollowing classes are defined under the SNMP module.How to useSee example programs below.SNMP GETRequest '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 GETNEXTSame 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 WALKGet 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 |