moltenbar/mod/network

38 lines
646 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
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
if hosts_down == 0
fg_colour = "ok_colour"
elsif hosts_down == hosts.count
fg_colour = "crit_colour"
2016-10-21 14:56:25 +00:00
else
fg_colour = "warn_colour"
2016-10-21 14:56:25 +00:00
end
@rstr = "%%{FC{%s}}%s/%s%%{F-}" % [ fg_colour, hosts_up, hosts.count ]
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")