Class: ZombieCheck::Ping::Checker
- Inherits:
-
Object
- Object
- ZombieCheck::Ping::Checker
- Defined in:
- lib/zombie_check/ping/checker.rb
Instance Attribute Summary collapse
-
#delay ⇒ Object
Returns the value of attribute delay.
-
#hosts ⇒ Object
Returns the value of attribute hosts.
-
#hosts_file ⇒ Object
Returns the value of attribute hosts_file.
-
#interrupted ⇒ Object
Returns the value of attribute interrupted.
-
#report ⇒ Object
Returns the value of attribute report.
-
#tool ⇒ Object
readonly
Returns the value of attribute tool.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Checker
constructor
A new instance of Checker.
- #ping(host) ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Checker
Returns a new instance of Checker.
8 9 10 11 12 13 14 15 |
# File 'lib/zombie_check/ping/checker.rb', line 8 def initialize( = {}) @hosts_file ||= [:hosts_file] || "hosts.txt" @delay ||= ([:delay] || 1000).to_i @hosts ||= [] @report ||= CheckerReport.new @tool ||= [:tool] || "unix_ping" setup_interruptor end |
Instance Attribute Details
#delay ⇒ Object
Returns the value of attribute delay.
5 6 7 |
# File 'lib/zombie_check/ping/checker.rb', line 5 def delay @delay end |
#hosts ⇒ Object
Returns the value of attribute hosts.
5 6 7 |
# File 'lib/zombie_check/ping/checker.rb', line 5 def hosts @hosts end |
#hosts_file ⇒ Object
Returns the value of attribute hosts_file.
5 6 7 |
# File 'lib/zombie_check/ping/checker.rb', line 5 def hosts_file @hosts_file end |
#interrupted ⇒ Object
Returns the value of attribute interrupted.
5 6 7 |
# File 'lib/zombie_check/ping/checker.rb', line 5 def interrupted @interrupted end |
#report ⇒ Object
Returns the value of attribute report.
5 6 7 |
# File 'lib/zombie_check/ping/checker.rb', line 5 def report @report end |
#tool ⇒ Object (readonly)
Returns the value of attribute tool.
6 7 8 |
# File 'lib/zombie_check/ping/checker.rb', line 6 def tool @tool end |
Instance Method Details
#ping(host) ⇒ Object
27 28 29 30 |
# File 'lib/zombie_check/ping/checker.rb', line 27 def ping(host) response = sender_class.send(:new, host).send @report << response end |
#start ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/zombie_check/ping/checker.rb', line 17 def start puts "Using file #{hosts_file}, delay #{delay}ms, for exit press Ctrl+C" loop do update_hosts! @hosts.each { |host| Thread.new { ping host } } interrupted_exit! if interrupted sleep @delay / 1000.0 end end |