moltenbar/mod/network

41 lines
722 B
Plaintext
Raw Normal View History

2016-09-27 08:13:42 +00:00
# vim: ft=ruby
class Network < Worker
2016-09-27 13:06:04 +00:00
require 'open3'
def mainloop()
self.write "checking..."
2016-09-27 08:13:42 +00:00
while true do
self.write network_status
2016-09-27 08:13:42 +00:00
sleep(10)
end
end
def network_status
hosts = @my_config['hosts']
2016-09-27 08:13:42 +00:00
net_fail = 0
Open3.popen2("fping", *hosts) do |i,o,t|
2016-10-21 14:56:25 +00:00
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}/#{hosts.count} hosts ok"
2016-10-21 14:56:25 +00:00
fg_colour = @my_config['warn_colour']
end
@rstr = "%{F#{fg_colour}}#{status}%{F-}"
end
2016-10-21 14:56:25 +00:00
return @rstr
2016-09-27 08:13:42 +00:00
end
end
Modules.add("network", "Network")