Class: Nines::PingCheck
Instance Attribute Summary collapse
-
#protocol ⇒ Object
Returns the value of attribute protocol.
Attributes inherited from Check
#address, #cycles, #group, #hostname, #interval, #logger, #name, #notifier, #port, #since, #timeout, #up
Instance Method Summary collapse
-
#debug ⇒ Object
shortcuts.
-
#initialize(group, options) ⇒ PingCheck
constructor
A new instance of PingCheck.
- #run ⇒ Object
Methods inherited from Check
Constructor Details
#initialize(group, options) ⇒ PingCheck
Returns a new instance of PingCheck.
8 9 10 11 12 |
# File 'lib/nines/ping_check.rb', line 8 def initialize(group, ) super(group, ) @protocol = (['protocol'] || 'icmp').downcase end |
Instance Attribute Details
#protocol ⇒ Object
Returns the value of attribute protocol.
6 7 8 |
# File 'lib/nines/ping_check.rb', line 6 def protocol @protocol end |
Instance Method Details
#debug ⇒ Object
shortcuts
15 |
# File 'lib/nines/ping_check.rb', line 15 def debug ; Nines::App.debug ; end |
#run ⇒ Object
17 18 19 20 21 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 |
# File 'lib/nines/ping_check.rb', line 17 def run while Nines::App.continue do check_started = Time.now @address = Dnsruby::Resolv.getaddress(hostname) @pinger = case protocol when 'tcp' then Net::Ping::TCP.new(hostname, nil, timeout) when 'udp' then Net::Ping::UDP.new(hostname, nil, timeout) when 'icmp' if Process::UID == 0 Net::Ping::ICMP.new(hostname, nil, timeout) else Net::Ping::External.new(hostname, nil, timeout) end else "invalid ping protocol #{protocol}" end # the check log_status(@pinger.ping?, "#{protocol == 'icmp' ? 'icmp' : "#{protocol}/#{port}"} ping on #{hostname} (#{address})") break if debug wait = interval.to_f - (Time.now - check_started) while wait > 0 do break unless Nines::App.continue sleep [1, wait].min wait -= 1 end end end |