Class: ZombieCheck::Ping::Checker

Inherits:
Object
  • Object
show all
Defined in:
lib/zombie_check/ping/checker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options = {})
  @hosts_file ||= options[:hosts_file] || "hosts.txt"
  @delay ||= (options[:delay] || 1000).to_i
  @hosts ||= []
  @report ||= CheckerReport.new
  @tool ||= options[:tool] || "unix_ping"
  setup_interruptor
end

Instance Attribute Details

#delayObject

Returns the value of attribute delay.



5
6
7
# File 'lib/zombie_check/ping/checker.rb', line 5

def delay
  @delay
end

#hostsObject

Returns the value of attribute hosts.



5
6
7
# File 'lib/zombie_check/ping/checker.rb', line 5

def hosts
  @hosts
end

#hosts_fileObject

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

#interruptedObject

Returns the value of attribute interrupted.



5
6
7
# File 'lib/zombie_check/ping/checker.rb', line 5

def interrupted
  @interrupted
end

#reportObject

Returns the value of attribute report.



5
6
7
# File 'lib/zombie_check/ping/checker.rb', line 5

def report
  @report
end

#toolObject (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

#startObject



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