Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Bridge between Ruby-SNMP and EventMachine
Ruby
branch: master

This branch is 3 commits ahead, 46 commits behind normelton:master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
examples
lib
spec
.gitignore
Gemfile
Manifest
README.rdoc
Rakefile
snmp4em.gemspec

README.rdoc

SNMP Library for EventMachine

Summary

This gem extends Ruby-SNMP to use the asynchronous EventMachine 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

Version 0.2.1 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 library, by David Halliday

  • EventMachine, 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 {
  snmp = SNMP4EM::Manager.new(:host => "192.168.1.1", :version => :SNMPv1)

  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
}

A simple SNMP-GETNEXT:

EM.run {
  snmp = SNMP4EM::Manager.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 "GETNEXT got error #{error}"
  end
}

A simple SNMP-SET:

EM.run {
  snmp = SNMP4EM::Manager.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 "SET got error #{error}"
  end
}

A simple SNMP-WALK:

EM.run {
  snmp = SNMP4EM::Manager.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 "WALK got error #{error}"
  end
}

A simple SNMP-GET-BULK:

EM.run {
  snmp = SNMP4EM::Manager.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-BULK got error #{error}"
  end
}

Change Log

Version 0.2.1:

  • Code cleanups, speed boosts

Version 0.2.0:

  • Added support for SNMPv2, including GET-BULK operations

Version 0.1.0:

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

Credits

Author: Norman Elton normelton@gmail.com

Something went wrong with that request. Please try again.