slight logic rework

Signed-off-by: fbt <fbt@fleshless.org>
This commit is contained in:
Jack L. Frost 2016-10-04 15:26:21 +03:00
parent f37bf2841b
commit 5fd9489f14

View File

@ -15,23 +15,23 @@ class Network < Worker
def network_status
hosts = @config['mod']['network']['hosts']
net_ok = 0
net_fail = 0
hosts.each do |h|
i,o,t = Open3.popen2("ping", "-c", "1", h)
t.join
net_ok += 1 if t.value.exitstatus == 0
net_fail += 1 unless 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
if net_fail == 0
status = "ok"
fg_colour = @config['mod']['network']['ok_colour']
elsif net_fail == hosts.length
status = "CRIT: all hosts failed!"
fg_colour = @config['mod']['network']['crit_colour']
else
status = "WARN: #{net_fail} host(s) failed"
fg_colour = @config['mod']['network']['warn_colour']
end
return "%{F#{fg_colour}}#{status}%{F-}"