Class: NetAtlas::Plugin::SNMP
Constant Summary collapse
- @@sessions =
[]
Constants inherited from Base
Instance Method Summary collapse
-
#initialize(*args) ⇒ SNMP
constructor
A new instance of SNMP.
- #poll(data_source, &block) ⇒ Object
Methods inherited from Base
arguments, method_missing, plugin_arguments
Constructor Details
#initialize(*args) ⇒ SNMP
Returns a new instance of SNMP.
11 12 13 14 |
# File 'lib/netatlas/plugin/snmp.rb', line 11 def initialize(*args) @sessions = {} super *args end |
Instance Method Details
#poll(data_source, &block) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/netatlas/plugin/snmp.rb', line 17 def poll(data_source, &block) arguments = data_source.arguments ? data_source.arguments.attributes : {:community => "public", :version => "1"} session = @@sessions[data_source.ip_address] ||= SNMP4EM::SNMPv1.new(:host => data_source.ip_address, :community => arguments[:community] || "public", :version => arguments[:version]) oid = Smi.translate(data_source.arguments.oid) request = session.get([oid]) request.callback { |response| block.call :ok, response[oid] } request.errback {|error| puts "SNMP ERROR: #{error.inspect}" puts data_source.attributes.inspect block.call :error, nil } end |