moltenbar/mod/network

46 lines
836 B
Plaintext
Raw Normal View History

2016-09-27 08:13:42 +00:00
# vim: ft=ruby
class ModNetwork < ModBasic
@@mod_name = 'network'
2016-09-27 13:06:04 +00:00
require 'open3'
2016-09-27 08:13:42 +00:00
def data_loop()
$panel_data[@@mod_name.to_sym] = "checking..."
while true do
$panel_data[@@mod_name.to_sym] = network_status.chomp
$queue << 1
sleep(10)
end
end
def network_status
hosts = $config['mod']['network']['hosts']
net_ok = 0
hosts.each do |h|
2016-09-27 13:06:04 +00:00
i,o,t = Open3.popen2("ping", "-c", "1", h)
i.close; o.close
t.join
net_ok += 1 if t.value
2016-09-27 08:13:42 +00:00
end
if net_ok == 0
status = "CRIT"
fg_colour = $config['mod']['network']['crit_colour']
elsif net_ok < hosts.length
status = "WARN"
fg_colour = $config['mod']['network']['warn_colour']
else
status = "ok"
fg_colour = $config['mod']['network']['ok_colour']
end
return "%{F#{fg_colour}}#{status}%{F-}"
end
end
ModNetwork.new.mainloop()