From 09dea79ab2bd066a7d5d37c9696f0f6f2cb1e3ad Mon Sep 17 00:00:00 2001 From: fbt Date: Fri, 14 Oct 2016 14:27:47 +0300 Subject: [PATCH] use fping Signed-off-by: fbt --- mod/network | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/mod/network b/mod/network index 499c751..a05846a 100644 --- a/mod/network +++ b/mod/network @@ -16,21 +16,19 @@ class Network < Worker hosts = @my_config['hosts'] net_fail = 0 - hosts.each do |h| - i,o,t = Open3.popen2("ping", "-c", "1", h) - t.join + i,o,t = Open3.popen2("fping", *hosts) + t.join - net_fail += 1 unless t.value.exitstatus == 0 - end + net_ok = o.each_line.count - if net_fail == 0 + if net_ok == hosts.count status = "ok" fg_colour = @my_config['ok_colour'] - elsif net_fail == hosts.length + elsif net_ok == 0 status = "CRIT: all hosts failed!" fg_colour = @my_config['crit_colour'] else - status = "WARN: #{net_fail} host(s) failed" + status = "WARN: #{net_ok} host(s) failed" fg_colour = @my_config['warn_colour'] end