41 lines
713 B
Ruby
41 lines
713 B
Ruby
# vim: ft=ruby
|
|
|
|
class Network < Worker
|
|
require 'open3'
|
|
|
|
def mainloop()
|
|
self.write "checking..."
|
|
|
|
while true do
|
|
self.write network_status
|
|
sleep(10)
|
|
end
|
|
end
|
|
|
|
def network_status
|
|
hosts = @my_config['hosts']
|
|
|
|
net_fail = 0
|
|
Open3.popen2("fping", *hosts) do |i,o,t|
|
|
net_ok = o.each_line.count
|
|
|
|
if net_ok == hosts.count
|
|
status = "ok"
|
|
fg_colour = @my_config['ok_colour']
|
|
elsif net_ok == 0
|
|
status = "CRIT: all hosts failed!"
|
|
fg_colour = @my_config['crit_colour']
|
|
else
|
|
status = "WARN: #{net_ok} host(s) failed"
|
|
fg_colour = @my_config['warn_colour']
|
|
end
|
|
|
|
@rstr = "%{F#{fg_colour}}#{status}%{F-}"
|
|
end
|
|
|
|
return @rstr
|
|
end
|
|
end
|
|
|
|
Modules.add("network", "Network")
|