slight logic rework
Signed-off-by: fbt <fbt@fleshless.org>
This commit is contained in:
parent
f37bf2841b
commit
5fd9489f14
18
mod/network
18
mod/network
|
@ -15,23 +15,23 @@ class Network < Worker
|
||||||
def network_status
|
def network_status
|
||||||
hosts = @config['mod']['network']['hosts']
|
hosts = @config['mod']['network']['hosts']
|
||||||
|
|
||||||
net_ok = 0
|
net_fail = 0
|
||||||
hosts.each do |h|
|
hosts.each do |h|
|
||||||
i,o,t = Open3.popen2("ping", "-c", "1", h)
|
i,o,t = Open3.popen2("ping", "-c", "1", h)
|
||||||
t.join
|
t.join
|
||||||
|
|
||||||
net_ok += 1 if t.value.exitstatus == 0
|
net_fail += 1 unless t.value.exitstatus == 0
|
||||||
end
|
end
|
||||||
|
|
||||||
if net_ok == 0
|
if net_fail == 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"
|
status = "ok"
|
||||||
fg_colour = @config['mod']['network']['ok_colour']
|
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
|
end
|
||||||
|
|
||||||
return "%{F#{fg_colour}}#{status}%{F-}"
|
return "%{F#{fg_colour}}#{status}%{F-}"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user