Use Open3.popen2

This commit is contained in:
Jack L. Frost 2016-09-27 16:06:04 +03:00
parent 8847f50ddb
commit 9175caa94d

View File

@ -3,6 +3,8 @@
class ModNetwork < ModBasic class ModNetwork < ModBasic
@@mod_name = 'network' @@mod_name = 'network'
require 'open3'
def data_loop() def data_loop()
$panel_data[@@mod_name.to_sym] = "checking..." $panel_data[@@mod_name.to_sym] = "checking..."
@ -18,9 +20,11 @@ class ModNetwork < ModBasic
net_ok = 0 net_ok = 0
hosts.each do |h| hosts.each do |h|
if system("ping -c 1 #{h} > /dev/null") i,o,t = Open3.popen2("ping", "-c", "1", h)
net_ok += 1 i.close; o.close
end t.join
net_ok += 1 if t.value
end end
if net_ok == 0 if net_ok == 0