Class: Net::SNMP::Agent

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Debug
Defined in:
lib/net/snmp/agent/agent.rb

Overview

  • Manages the request/response cycle for incoming messages

    + Listens for incoming requests
    + Parses request packets into Message objects
    + Dispatches the messages to (sub) Agents
    + Serializes the response from the subagents and sends it to the caller
    

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Debug

#debug, #error, #fatal, #info, #print_packet, #time, #warn

Constructor Details

#initializeAgent

Returns a new instance of Agent.



16
17
18
19
20
# File 'lib/net/snmp/agent/agent.rb', line 16

def initialize
  @listener = Net::SNMP::Listener.new
  @providers = []
  @listener.on_message(&method(:process_message))
end

Instance Attribute Details

#listenerObject

Returns the value of attribute listener.



13
14
15
# File 'lib/net/snmp/agent/agent.rb', line 13

def listener
  @listener
end

#providersObject

Returns the value of attribute providers.



13
14
15
# File 'lib/net/snmp/agent/agent.rb', line 13

def providers
  @providers
end

Instance Method Details

#provide(oid = :all, &block) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/net/snmp/agent/agent.rb', line 22

def provide(oid = :all, &block)
  # Need a trailing dot on the oid so we can avoid
  # considering 1.3.22 a child of 1.3.2
  oid = (oid.to_sym == :all || oid.end_with?('.')) ? oid : "#{oid}."
  provider = Provider.new(oid)
  provider.instance_eval(&block)

  # Providers are pushed onto the end of the provider queue.
  # When dispatching, this is searched in order for a match.
  # So, like exception handlers, you such specify providers
  # in order of most -> least specific oid. ('1.3.1' comes before '1.3')
  providers << provider
end