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
|
||||
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-}"
|
||||
|
|
Loading…
Reference in New Issue
Block a user