Class: SNMP4EM::SnmpSetRequest

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

Overview

The result of calling SNMP4EM::SNMPCommonRequests#set.

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, #pending_oids

Constructor Details

#initialize(sender, oids, args = {}) ⇒ SnmpSetRequest

Returns a new instance of SnmpSetRequest.



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

def initialize(sender, oids, args = {})  # @private
  @oids = [*oids].collect { |oid_str, value| { :requested_oid => SNMP::ObjectId.new(oid_str), :requested_string => oid_str, :value => format_outgoing_value(value), :state => :pending, :response => nil }}
  super
end

Instance Attribute Details

#snmp_idObject

Returns the value of attribute snmp_id.



6
7
8
# File 'lib/snmp4em/requests/snmp_set_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_set_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_set_request.rb', line 14

def errback &block
  super
end

#handle_response(response) ⇒ Object



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
# File 'lib/snmp4em/requests/snmp_set_request.rb', line 23

def handle_response(response)  # @private
  super
  
  if (response.error_status == :noError)
    pending_oids.zip(response.varbind_list).each do |oid, response_vb|
      oid[:response] = true
      oid[:state] = :complete
    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[:response]
    end

    succeed result
    return
  end

  send_msg
end