Class: SNMP4EM::SnmpRequest
- Inherits:
-
Object
- Object
- SNMP4EM::SnmpRequest
show all
- Includes:
- EM::Deferrable
- Defined in:
- lib/snmp4em/snmp_request.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(sender, oids, args = {}) ⇒ SnmpRequest
Returns a new instance of SnmpRequest.
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/snmp4em/snmp_request.rb', line 7
def initialize(sender, oids, args = {})
@sender = sender
@oids ||= [*oids].collect { |oid_str| { :requested_string => oid_str, :requested_oid => SNMP::ObjectId.new(oid_str), :state => :pending }}
retries = args[:retries] || @sender.retries
timeout = args[:timeout] || @sender.timeout
if retries.is_a?(Array)
@timeouts = retries.clone
else
@timeouts = (retries + 1).times.collect { timeout }
end
@return_raw = args[:return_raw] || false
@max_results = args[:max_results] || nil
init_callbacks
on_init(args) if respond_to?(:on_init)
send_msg
end
|
Instance Attribute Details
#timeout_timer ⇒ Object
Returns the value of attribute timeout_timer.
5
6
7
|
# File 'lib/snmp4em/snmp_request.rb', line 5
def timeout_timer
@timeout_timer
end
|
Instance Method Details
43
44
45
46
47
48
49
50
51
|
# File 'lib/snmp4em/snmp_request.rb', line 43
def format_outgoing_value value
if value.is_a? Integer
return SNMP::Integer.new(value)
elsif value.is_a? String
return SNMP::OctetString.new(value)
else
return value
end
end
|
33
34
35
36
37
38
39
40
41
|
# File 'lib/snmp4em/snmp_request.rb', line 33
def format_value vb
if [SNMP::EndOfMibView, SNMP::NoSuchObject, SNMP::NoSuchInstance].include? vb.value
SNMP::ResponseError.new(vb.value)
elsif @return_raw || !vb.value.respond_to?(:rubify)
vb.value
else
vb.value.rubify
end
end
|
#handle_response(response) ⇒ Object
80
81
82
|
# File 'lib/snmp4em/snmp_request.rb', line 80
def handle_response response
@timeout_timer.cancel
end
|
#init_callbacks ⇒ Object
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/snmp4em/snmp_request.rb', line 53
def init_callbacks
self.callback do
Manager.untrack_request(@snmp_id)
end
self.errback do
@timeout_timer.cancel
Manager.untrack_request(@snmp_id)
end
end
|
#pending_oids ⇒ Object
29
30
31
|
# File 'lib/snmp4em/snmp_request.rb', line 29
def pending_oids
@oids.select{|oid| oid[:state] == :pending}
end
|
#send_msg(msg) ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/snmp4em/snmp_request.rb', line 64
def send_msg(msg)
@sender.send_msg msg
@timeout_timer.cancel if @timeout_timer.is_a?(EM::Timer)
@timeout_timer = EM::Timer.new(@timeouts.first) do
@timeouts.shift
if @timeouts.empty?
fail "exhausted all timeout retries"
else
send_msg
end
end
end
|