moltenbar/mod/network
2019-05-15 16:04:27 +03:00

38 lines
646 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']
Open3.popen2("fping", "-u", *hosts) do |i,o,t|
hosts_down = o.each_line.count
hosts_up = hosts.count - hosts_down
if hosts_down == 0
fg_colour = "ok_colour"
elsif hosts_down == hosts.count
fg_colour = "crit_colour"
else
fg_colour = "warn_colour"
end
@rstr = "%%{FC{%s}}%s/%s%%{F-}" % [ fg_colour, hosts_up, hosts.count ]
end
return @rstr
end
end
Modules.add("network", "Network")