Class: Net::SNMP::Agent

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

Overview

Agents delegate messages from the Net::SNMP::Listener to providers, which supply the actual responses to the varbinds in the request. See Net::SNMP::ProviderDsl

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Debug

#print_packet, #time

Constructor Details

#initializeAgent

Returns a new instance of Agent.



14
15
16
17
18
# File 'lib/net/snmp/agent/agent.rb', line 14

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.



11
12
13
# File 'lib/net/snmp/agent/agent.rb', line 11

def listener
  @listener
end

#providersObject

Returns the value of attribute providers.



11
12
13
# File 'lib/net/snmp/agent/agent.rb', line 11

def providers
  @providers
end

Instance Method Details

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

This method is called with a block to define a provider for some subtree of the MIB. When a request comes in with varbinds in that providers subtree, the provider’s handlers will be called to generate the varbind to send back in the response PDU.

Arguments

  • oid: The root OID of the MIB subtree this provider is responsible for.

  • &block: A block, to be instance_evaled on the new Provider.



29
30
31
32
33
34
35
36
37
38
# File 'lib/net/snmp/agent/agent.rb', line 29

def provide(oid = :all, &block)
  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