Class: SNMP4EM::SnmpWalkRequest

Inherits:
SnmpRequest show all
Defined in:
lib/snmp4em/requests/snmp_walk_request.rb

Overview

The result of calling SNMP4EM::SNMPCommonRequests#walk.

Instance Attribute Summary collapse

Attributes inherited from SnmpRequest

#timeout_timer

Instance Method Summary collapse

Methods inherited from SnmpRequest

#format_outgoing_value, #format_value, #init_callbacks, #initialize, #pending_oids

Constructor Details

This class inherits a constructor from SNMP4EM::SnmpRequest

Instance Attribute Details

#snmp_idObject

Returns the value of attribute snmp_id.



6
7
8
# File 'lib/snmp4em/requests/snmp_walk_request.rb', line 6

def snmp_id
  @snmp_id
end

Instance Method Details

#callback(&block) ⇒ Object

Used to register a callback that is triggered when the query result is ready. The resulting object is passed as a parameter to the block.



9
10
11
# File 'lib/snmp4em/requests/snmp_walk_request.rb', line 9

def callback &block
  super
end

#errback(&block) ⇒ Object

Used to register a callback that is triggered when query fails to complete successfully.



14
15
16
# File 'lib/snmp4em/requests/snmp_walk_request.rb', line 14

def errback &block
  super
end

#handle_response(response) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/snmp4em/requests/snmp_walk_request.rb', line 22

def handle_response(response)  # @private
  super

  if response.error_status == :noError
    pending_oids.zip(response.varbind_list).each do |oid, response_vb|
      response_oid = response_vb.name

      if SNMP::EndOfMibView == response_vb.value
        # For SNMPv2, this indicates we've reached the end of the MIB
        oid[:state] = :complete
      elsif ! response_oid.subtree_of?(oid[:requested_oid])
        oid[:state] = :complete
      else
        oid[:responses][response_oid.to_s] = format_value(response_vb)
        oid[:next_oid] = response_oid
      end
    end

  elsif response.error_status == :noSuchName
    # For SNMPv1, this indicates we've reached the end of the MIB
    error_oid = pending_oids[response.error_index - 1]
    error_oid[:state] = :complete

  else
    error_oid = pending_oids[response.error_index - 1]
    error_oid[:state] = :error
    error_oid[:error] = SNMP::ResponseError.new(response.error_status)
  end

  if pending_oids.empty? || (@max_results && @oids.collect{|oid| oid[:responses].count}.max >= @max_results)
    result = {}

    @oids.each do |oid|
      requested_oid = oid[:requested_string]
      result[requested_oid] = oid[:error] || oid[:responses]
    end

    succeed result
    return
  end

  send_msg
end

#on_init(args) ⇒ Object



18
19
20
# File 'lib/snmp4em/requests/snmp_walk_request.rb', line 18

def on_init args  # @private
  @oids.each{|oid| oid.merge!({:next_oid => oid[:requested_oid], :responses => {}})}
end