Path: | README |
Last Update: | Wed Jan 05 18:19:22 +0000 2011 |
This library implements SNMP (the Simple Network Management Protocol). It is implemented in pure Ruby, so there are no dependencies on external libraries like net-snmp. You can run this library anywhere that Ruby can run.
See snmplib.rubyforge.org for more info.
Version 1.0.3 of this software supports the following:
See the SNMP.Manager, SNMP.TrapListener, and SNMP.MIB classes and the examples below for more details.
Changes for version 1.0.3:
object or a class. Explicity call Timeout.timeout so that a timeout method may be defined in subclasses. Thanks to Eric Monti.
Changes for version 1.0.2:
Changes for version 1.0.1:
Changes for version 1.0.0:
Changes for version 0.6.1:
Changes for version 0.6.0:
Changes for version 0.5.1:
Changes for version 0.4.0:
* It can now take an OID list as a parameter. (Thanks to Simon Barnes for the suggestion.) * Takes a block instead of returning a list to allow incremental processing of results.
Changes for version 0.3.0:
Changes for version 0.2.0:
You can use RubyGems [rubyforge.org/projects/rubygems] to install the latest version of the SNMP library remotely.
gem install --remote snmp
The SNMP Library can be downloaded from RubyForge in several different formats.
From the .gem file you can install using RubyGems.
gem install snmp-1.0.3.gem
From the .tgz or .zip file you can install using setup.rb. Uncompress the archive and then run setup.
cd snmp-1.0.3 ruby setup.rb (may require root privilege)
This library has received limited testing:
I‘m very interested in hearing about successes or failures on other platforms.
Send me an email at hallidave at gmail.com.
Retrieve a system description.
require 'snmp' SNMP::Manager.open(:Host => 'localhost') do |manager| response = manager.get(["sysDescr.0", "sysName.0"]) response.each_varbind do |vb| puts "#{vb.name.to_s} #{vb.value.to_s} #{vb.value.asn1_type}" end end
Create a varbind for setting the system name.
require 'snmp' include SNMP manager = Manager.new(:Host => 'localhost') varbind = VarBind.new("1.3.6.1.2.1.1.5.0", OctetString.new("My System Name")) manager.set(varbind) manager.close
Walk the ifTable.
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
A more difficult way to walk the ifTable.
require 'snmp' include SNMP Manager.open(:Host => 'localhost') do |manager| ifTable = ObjectId.new("1.3.6.1.2.1.2.2") next_oid = ifTable while next_oid.subtree_of?(ifTable) response = manager.get_next(next_oid) varbind = response.varbind_list.first next_oid = varbind.name puts varbind.to_s end end
Get interface description and admin status for 10 rows of the ifTable.
require 'snmp' include SNMP ifDescr_OID = ObjectId.new("1.3.6.1.2.1.2.2.1.2") ifAdminStatus_OID = ObjectId.new("1.3.6.1.2.1.2.2.1.7") MAX_ROWS = 10 Manager.open(:Host => 'localhost') do |manager| response = manager.get_bulk(0, MAX_ROWS, [ifDescr_OID, ifAdminStatus_OID]) list = response.varbind_list until list.empty? ifDescr = list.shift ifAdminStatus = list.shift puts "#{ifDescr.value} #{ifAdminStatus.value}" end end
Log traps to STDOUT.
require 'snmp' require 'logger' log = Logger.new(STDOUT) m = SNMP::TrapListener.new do |manager| manager.on_trap_default do |trap| log.info trap.inspect end end m.join
This SNMP Library is Copyright (c) 2004-2010 by David R. Halliday. It is free software. Redistribution is permitted under the same terms and conditions as the standard Ruby distribution. See the COPYING file in the Ruby distribution for details.