Module: Net::SNMP::RequestDispatcher

Defined in:
lib/net/snmp/agent/request_dispatcher.rb

Overview

RequestDispatcher module handles calling all required providers for a request in the context of a ProviderDsl object (which itself provides the agent DSL)

Class Method Summary collapse

Class Method Details

.dispatch(message, providers) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/net/snmp/agent/request_dispatcher.rb', line 8

def self.dispatch(message, providers)
  response_pdu = Message::response_pdu_for(message)
  context = ProviderDsl.new
  context.message = message
  context.response_pdu = response_pdu
  message.pdu.varbinds.each_with_index do |vb, index|
    context.varbind = vb
    provider = providers.find { |p| p.oid == :all || vb.oid.to_s.start_with?(p.oid.to_s) }
    if provider
      if message.pdu.command == Constants::SNMP_MSG_GETBULK && index < message.pdu.non_repeaters
        handler = provider.handler_for(Constants::SNMP_MSG_GETNEXT)
      else
        handler = provider.handler_for(message)
      end
      if handler
        context.instance_exec(&handler)
      else
        Debug.warn "No handler for command: #{message.pdu.command} @ #{vb.oid}"
        context.no_such_object
      end
    else
      Debug.warn "No provider for oid: #{vb.oid}"
      context.no_such_object
    end
  end

  response_pdu
end