Module: Net::Fping

Defined in:
lib/net/fping.rb

Class Method Summary collapse

Class Method Details

.alive(hosts = [], **opts) ⇒ Object



22
23
24
25
26
# File 'lib/net/fping.rb', line 22

def alive(hosts=[], **opts)
  return [] if hosts.empty?
  args = build_args(opts)
  %x[fping #{args} -a #{hosts.join(" ")} 2>/dev/null].split("\n");
end

.alive_in_range(from, to, **opts) ⇒ Object



39
40
41
42
# File 'lib/net/fping.rb', line 39

def alive_in_range(from, to, **opts)
  args = build_args(opts)
  %x[fping #{args} -ag #{from} #{to} 2>/dev/null].split("\n")
end

.alive_in_subnet(subnet, **opts) ⇒ Object



34
35
36
37
# File 'lib/net/fping.rb', line 34

def alive_in_subnet(subnet, **opts)
  args = build_args(opts)
  %x[fping #{args} -ag #{subnet} 2>/dev/null].split("\n")
end

.build_args(opts) ⇒ Object



17
18
19
20
# File 'lib/net/fping.rb', line 17

def build_args(opts)
  opts = default_options.merge(options)
  "-c #{opts[:count]} -r #{opts[:retries]} -t #{opts[:timeout]} -i #{opts[:interval]} -b #{opts[:bytes]}"
end

.dead(hosts = [], **opts) ⇒ Object



28
29
30
31
32
# File 'lib/net/fping.rb', line 28

def dead(hosts=[], **opts)
  return [] if hosts.empty?
  args = build_args(opts)
  %x[fping #{args} -u #{hosts.join(" ")} 2>/dev/null].split("\n")
end

.default_optionsObject



7
8
9
10
11
12
13
14
15
# File 'lib/net/fping.rb', line 7

def default_options
  {
    retries: 3,
    count: 1,
    bytes: 56,
    interval: 25,
    timeout: 500
  }
end

.latency(host, bytes, count, interval = 1000) ⇒ Object



52
53
54
55
56
57
58
59
60
# File 'lib/net/fping.rb', line 52

def latency(host, bytes, count, interval=1000)
  cmd = "fping -b #{bytes} -c #{count} -q -p #{interval} #{host}"
  Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
    # output is written to stderr for some reason
    ltc = stderr.read.gsub(/[%, ]/, "/")
    ltc = ltc.split(/.*loss\/=\/[0-9]+\/[0-9]+\/([0-9]+)\/\/\/min\/avg\/max\/=\/([0-9.]+)\/([0-9.]+)\/([0-9.]+)/)[-5..4]
   return ltc
  end
end

.latency_simple(host) ⇒ Object

Added defs for latency based metrics



45
46
47
48
49
50
# File 'lib/net/fping.rb', line 45

def latency_simple(host)
  bytes = 68
  count = 6
  interval = 1000
  %x[fping -b #{bytes} -c #{count} -q -p #{interval} #{host}]
end