= Sloth::Snmp
Sloth::Snmp is yet another wrapper library for snmp.
== Features
- Handles SNMP asynchronously.
- By referring to the YAML file generated from the MIB file, you can operate without describing raw OID.
== Installation
Add this line to your application's Gemfile:
[source,ruby]
gem 'sloth/snmp'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install sloth-snmp
or
$ gem install -l sloth-snmp-x.x.x.gem
== Usage
=== New
[source,ruby]
require "sloth/snmp"
snmp = Sloth::Snmp.new
snmp = Sloth::Snmp.new( bind: 1161 )
snmp = Sloth::Snmp.new( bind: "127.0.0.1" )
snmp = Sloth::Snmp.new( bind: "192.168.0.1:1161" )
snmp = Sloth::Snmp.new( mibs: "RS-232-MIB.yaml" )
snmp = Sloth::Snmp.new( mibs: "spec/sloth/RFC1414-MIB.yaml" )
=== Get
[source,ruby]
require "sloth/snmp"
snmp = Sloth::Snmp.new
peer = "127.0.0.1"
topics = [ "sysDescr.0", "sysUpTime.0", "sysName.0" ],
tuples = snmp.get( peer, topics )
tuples.each do |oid, tuple|
p tuple
end
=== Set
[source,ruby]
require "sloth/snmp"
snmp = Sloth::Snmp.new
peer = "127.0.0.1"
tuple = { topic: "sysName.0", type: SNMP::OctetString, value: Time.now.to_s },
snmp.set( peer, tuple )
tuples = snmp.get( peer, tuple[:topic] )
tuples.each do |oid, tuple|
p tuple
end
=== Walk
[source,ruby]
require "sloth/snmp"
snmp = Sloth::Snmp.new
peer = "127.0.0.1"
topic = "internet"
tuples = snmp.walk( peer, topic )
tuples.each do |oid, tuple|
p tuple
end
=== Trap
[source,ruby]
require "sloth/snmp"
snmp = Sloth::Snmp.new( bind: 1162 )
snmp.trap( "snmpInTraps", "snmpOutTraps" ) do |trapname, source_ip, tuples|
p [:trapname, trapname]
p [:source_ip, source_ip]
tuples.each do |oid, tuple|
p tuple
end
end
sleep
== Reference
=== Create a new Sloth::Snmp.
[source,ruby]
=== SNMP Get.
[source,ruby]
=== SNMP Set.
[source,ruby]
-
Result:
- Hash of key=>oid, value=>{name, value}.
-
Parameter:
** peer: Target IP address and port. (default port: 162)
** tuple: Hash of topic, type, value for SNMP Set Request.
** community: Community string. (default: nil)
** bindto: Interface address. (default: nil)
** device: Interface name. (default: nil)
=== SNMP Walk.
[source,ruby]
-
Result:
** Hash of key=>oid, value=>{name, value}.
-
Parameter:
** peer: Target IP address and port. (default port: 162)
** topic: Topic for SNMP Get Next.
** community: Community string. (default: nil)
** bindto: Interface address. (default: nil)
** device: Interface name. (default: nil)
=== SNMP Trap.
[source,ruby]
Sloth::Snmp#trap( *topics, &block )
=== SNMP Untrap.
[source,ruby]
Sloth::Snmp#untrap( *topics )
== Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/arimay/sloth-snmp.
== License
The gem is available as open source under the terms of the http://opensource.org/licenses/MIT[MIT License].
Copyright (c) ARIMA Yasuhiro arima.yasuhiro@gmail.com