Bridge between Ruby-SNMP and EventMachine
Ruby
Switch branches/tags
Nothing to show
Pull request Compare This branch is 85 commits behind normelton:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
.gitignore
Manifest
README
Rakefile
snmp4em.gemspec

README

= SNMP Library for EventMachine

== Summary

This library extends the Ruby-SNMP[http://snmplib.rubyforge.org] to use the asynchronous EventMachine[http://rubyeventmachine.com] library for added performance and scalability. This allows code to scale monitoring applications to access a very high number of devices without the need for complex asynchronous I/O handling.


== Features

The initial version 0.1.0 of this software supports:

* SNMP v1 and v2 only
* SNMP Get, GetNext, GetBulk (v2 only), Set, and Walk requests.
* Ability to query/set/walk multiple OIDs in parallel.

Future revisions of this library may support:

* Ability to act as an SNMP agent, responding to external queries.
* Ability to send/receive SNMP traps

There are no plans to support SNMP v3.


== Acknowledgements

* The SNMP packet processing is handled by the Ruby-SNMP[http://snmplib.rubyforge.org] library, by David Halliday
* EventMachine[http://rubyeventmachine.com], by Francis Cianfrocca and Aman Gupta
* All the helpful folks on the Freenode #eventmachine channel


== Examples

A few definitions:

  OID_SYSTEM = "1.3.6.1.2.1.1"
  OID_SYSNAME = "1.3.6.1.2.1.1.5.0"
  OID_SYSLOCATION = "1.3.6.1.2.1.1.6.0"

A simple SNMP-GET:

  EM::run do
	  snmp = SNMP4EM::SNMPv1.new(:host => "192.168.1.1")
  
	  request = snmp.get([OID_SYSNAME, OID_SYSLOCATION])
  
	  request.callback do |response|
	    puts "System name = #{response[OID_SYSNAME]}"
	    puts "System location = #{response[OID_SYSLOCATION]}"
	  end
  
	  request.errback do |error|
	    puts "GET got error #{error}"
	  end
	end

A simple SNMP-GETNEXT:

  EM::run do
    snmp = SNMP4EM::SNMPv1.new(:host => "192.168.1.1")

    request = snmp.getnext([OID_SYSNAME])

    request.callback do |response|
      r = response[OID_SYSNAME]
      puts "The next OID is #{r[0]}, the next value is #{r[1]}"
    end

    request.errback do |error|
      puts "GET got error #{error}"
    end
  end

A simple SNMP-SET:

  EM::run do
    snmp = SNMP4EM::SNMPv1.new(:host => "192.168.1.1")

    request = snmp.set({OID_SYSNAME => "My System Name", OID_SYSLOCATION => "My System Location"})

    request.callback do |response|
      if (response[OID_SYSNAME] == true)
        puts "System name set successful"
      else
        puts "System name set unsuccessful: #{response[OID_SYSNAME]}"
      end

      if (response[OID_SYSLOCATION] == true)
        puts "System location set successful"
      else
        puts "System location set unsuccessful: #{response[OID_SYSLOCATION]}"
      end
    end

    request.errback do |error|
      puts "GET got error #{error}"
    end
  end

A simple SNMP-WALK:

  EM::run do
    snmp = SNMP4EM::SNMPv1.new(:host => "192.168.1.1")

    request = snmp.walk([OID_SYSTEM])

    request.callback do |response|
      if (response[OID_SYSTEM].is_a? Array)
        response[OID_SYSTEM].each do |vb|
          puts "#{vb[0]} = #{vb[1]}"
        end
      else
        puts "Got error: #{response[OID_SYSTEM]}"
      end
    end

    request.errback do |error|
      puts "GET got error #{error}"
    end
  end

A simple SNMP-GET-BULK:

  EM::run do
    snmp = SNMP4EM::SNMPv2.new(:host => "192.168.1.1")

    request = snmp.getbulk([OID_SYSTEM])

    request.callback do |response|
      if (response[OID_SYSTEM].is_a? Array)
        response[OID_SYSTEM].each do |vb|
          puts "#{vb[0]} = #{vb[1]}"
        end
      else
        puts "Got error: #{response[OID_SYSTEM]}"
      end
    end

    request.errback do |error|
      puts "GET got error #{error}"
    end
  end

== Change Log

Version 0.1.0:

* Initial deployment, ability to run get/getnext/set/walk requests in parallel

Version 0.2.0:

* Added support for SNMPv2, including GET-BULK operations

== Developer Contact Information

Norman Elton
normelton@gmail.com