Class: SNMP4EM::SnmpGetBulkRequest

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

Overview

The result of calling SNMPv2Requests#getbulk.

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_getbulk_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_getbulk_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_getbulk_request.rb', line 14

def errback &block
  super
end

#handle_response(response) ⇒ Object



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
65
66
67
68
69
70
71
# File 'lib/snmp4em/requests/snmp_getbulk_request.rb', line 27

def handle_response(response)  # @private
  super
  
  pending_repeating_oids = pending_oids.select{|oid| oid[:method] == :repeating}
  pending_non_repeating_oids = pending_oids.select{|oid| oid[:method] == :non_repeating}

  if response.error_status == :noError
    # No errors, populate the @responses object so it can be returned

    vb_list = response.vb_list
    vb_index = 0

    pending_non_repeating_oids.each do |oid|
      response_vb = vb_list.shift
      oid[:responses][response_vb.name.to_s] = format_value(response_vb)
      oid[:state] = :complete
    end

    while response_vb = vb_list.shift
      oid = pending_repeating_oids[vb_index % pending_repeating_oids.count]
      oid[:responses][response_vb.name.to_s] = format_value(response_vb) unless response_vb.value == SNMP::EndOfMibView
      oid[:state] = :complete
      vb_index += 1
    end
    
  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?
    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
21
22
23
24
25
# File 'lib/snmp4em/requests/snmp_getbulk_request.rb', line 18

def on_init args  # @private
  @oids.each_index do |i|
    @oids[i][:responses] = {}
    @oids[i][:method] = (i < (args[:non_repeaters] || 0) ? :non_repeating : :repeating)
  end

  @max_results ||= 10
end