42 lines
744 B
Ruby
42 lines
744 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 = @config['mod']['network']['hosts']
|
|
|
|
net_ok = 0
|
|
hosts.each do |h|
|
|
i,o,t = Open3.popen2("ping", "-c", "1", h)
|
|
t.join
|
|
|
|
net_ok += 1 if t.value.exitstatus == 0
|
|
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
|
|
|
|
Modules.add("network", "Network")
|