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