2016-09-27 08:13:42 +00:00
|
|
|
# vim: ft=ruby
|
|
|
|
|
2016-09-28 20:30:07 +00:00
|
|
|
class Network < Worker
|
2016-09-27 13:06:04 +00:00
|
|
|
require 'open3'
|
|
|
|
|
2016-09-28 20:30:07 +00:00
|
|
|
def mainloop()
|
|
|
|
self.write "checking..."
|
2016-09-27 08:13:42 +00:00
|
|
|
|
|
|
|
while true do
|
2016-09-28 20:30:07 +00:00
|
|
|
self.write network_status
|
2016-09-27 08:13:42 +00:00
|
|
|
sleep(10)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def network_status
|
2016-10-04 12:34:25 +00:00
|
|
|
hosts = @my_config['hosts']
|
2016-09-27 08:13:42 +00:00
|
|
|
|
2017-05-30 12:08:45 +00:00
|
|
|
Open3.popen2("fping", "-u", *hosts) do |i,o,t|
|
|
|
|
hosts_down = o.each_line.count
|
|
|
|
hosts_up = hosts.count - hosts_down
|
2016-10-21 14:56:25 +00:00
|
|
|
|
2017-05-30 12:08:45 +00:00
|
|
|
if hosts_down == 0
|
2016-10-21 14:56:25 +00:00
|
|
|
fg_colour = @my_config['ok_colour']
|
2017-05-30 12:08:45 +00:00
|
|
|
elsif hosts_down == hosts.count
|
2016-10-21 14:56:25 +00:00
|
|
|
fg_colour = @my_config['crit_colour']
|
|
|
|
else
|
|
|
|
fg_colour = @my_config['warn_colour']
|
|
|
|
end
|
|
|
|
|
2017-05-30 12:08:45 +00:00
|
|
|
@rstr = "%%{F%s}%s/%s%%{F-}" % [ fg_colour, hosts_up, hosts.count ]
|
2016-10-22 23:07:59 +00:00
|
|
|
end
|
2016-10-21 14:56:25 +00:00
|
|
|
|
|
|
|
return @rstr
|
2016-09-27 08:13:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-28 20:30:07 +00:00
|
|
|
Modules.add("network", "Network")
|