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-09-28 20:30:07 +00:00
|
|
|
hosts = @config['mod']['network']['hosts']
|
2016-09-27 08:13:42 +00:00
|
|
|
|
|
|
|
net_ok = 0
|
|
|
|
hosts.each do |h|
|
2016-09-27 13:06:04 +00:00
|
|
|
i,o,t = Open3.popen2("ping", "-c", "1", h)
|
|
|
|
t.join
|
|
|
|
|
2016-09-28 20:30:07 +00:00
|
|
|
net_ok += 1 if t.value.exitstatus == 0
|
2016-09-27 08:13:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
if net_ok == 0
|
|
|
|
status = "CRIT"
|
2016-09-28 20:30:07 +00:00
|
|
|
fg_colour = @config['mod']['network']['crit_colour']
|
2016-09-27 08:13:42 +00:00
|
|
|
elsif net_ok < hosts.length
|
|
|
|
status = "WARN"
|
2016-09-28 20:30:07 +00:00
|
|
|
fg_colour = @config['mod']['network']['warn_colour']
|
2016-09-27 08:13:42 +00:00
|
|
|
else
|
|
|
|
status = "ok"
|
2016-09-28 20:30:07 +00:00
|
|
|
fg_colour = @config['mod']['network']['ok_colour']
|
2016-09-27 08:13:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return "%{F#{fg_colour}}#{status}%{F-}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-28 20:30:07 +00:00
|
|
|
Modules.add("network", "Network")
|