net-fping 0.2.1 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +35 -4
  3. data/lib/net/fping.rb +30 -11
  4. data/net-fping.gemspec +1 -2
  5. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ff8f5ae54f34481b98c2b3744124da8e57d6d0be
4
- data.tar.gz: adb7a3ad0bcc3bf33569d5f5aef3959f3f756a45
3
+ metadata.gz: 0844a28f622940227eca27a24393106db83aca17
4
+ data.tar.gz: 1b41817221c7c2776abac62c6e08badb23e99ee0
5
5
  SHA512:
6
- metadata.gz: aafb98dc4b5f6342e50427fb88e96c0bac6b68634706115ee72eae0ae7680e23759a2c812e49650fe6b65de3e0addab1080343ae26e9c865ec3f1a65daac36a6
7
- data.tar.gz: 4eb76c23a432ec58cb3a74aa03e05b5904b34984925147681c7d398aa63b126ce7dd6d332365e2c7305e62c26d1ca8248382d4797a5313d3944d8e0f608b4bb4
6
+ metadata.gz: 72e415c0e5c4b60a783ca757f3beb52eb3e2d7dac27de2f4c2bb6dc68c70057efbfed5ea0e6e9c4909b79d3dba9fbd0e6855376d52c82b14d6744b8bf99f7aaf
7
+ data.tar.gz: 38b9cbc9b00dc12837aedfe6256cba14a8c803d7af373d2f936c065ed32a0af28e09d770a4df01a4abef1b7d215b932c94be7655dbd1f273573187b723659bc4
data/README.md CHANGED
@@ -9,15 +9,46 @@ Pretty straight forward:
9
9
  ```ruby
10
10
  require 'net/fping'
11
11
 
12
- alive = Fping.alive(["10.0.0.1", "10.0.0.2", "10.0.0.3"])
12
+ alive = Net::Fping.alive(["10.0.0.1", "10.0.0.2", "10.0.0.3"])
13
13
  > ["10.0.0.1", "10.0.0.3"]
14
14
 
15
- alive = Fping.dead(["10.0.0.1", "10.0.0.2", "10.0.0.3"])
15
+ alive = Net::Fping.dead(["10.0.0.1", "10.0.0.2", "10.0.0.3"])
16
16
  > ["10.0.0.2"]
17
17
 
18
- alive = Fping.alive_in_subnet("192.168.0.0/24")
18
+ alive = Net::Fping.alive_in_subnet("192.168.0.0/24")
19
19
  > ["192.168.0.1", "192.168.0.100", "192.168.0.254"]
20
20
 
21
- alive = Fping.alive_in_range("192.168.0.0", "192.168.0.200")
21
+ alive = Net::Fping.alive_in_range("192.168.0.0", "192.168.0.200")
22
22
  > ["192.168.0.1", "192.168.0.100"]
23
23
  ```
24
+
25
+ You can also specify the following options on each command (defaults as per fping shown):
26
+
27
+ ```ruby
28
+ {
29
+ retries: 3,
30
+ count: 1,
31
+ bytes: 56,
32
+ interval: 25,
33
+ timeout: 500
34
+ }
35
+ ```
36
+
37
+ So this would be a faster way to ping a 16 bit subnet:
38
+
39
+ ```ruby
40
+ alive = Net::Fping.alive_in_subnet("172.16.0.0/16", retries: 0)
41
+ ```
42
+
43
+ You can also extract latencies:
44
+
45
+ ```ruby
46
+ latencies = Net::Fping.latency("4.2.2.2", 68, 6, 1000)
47
+ pp latencies
48
+ > [
49
+ 0, # LOSS
50
+ 13.7, # MIN
51
+ 15.5, # AVG
52
+ 17.3 # MAX
53
+ ]
54
+ ```
data/lib/net/fping.rb CHANGED
@@ -4,24 +4,43 @@ module Net
4
4
  module Fping
5
5
  class << self
6
6
 
7
- def alive(hosts=[])
7
+ def default_options
8
+ {
9
+ retries: 3,
10
+ count: 1,
11
+ bytes: 56,
12
+ interval: 25,
13
+ timeout: 500
14
+ }
15
+ end
16
+
17
+ def build_args(opts)
18
+ opts = default_options.merge(options)
19
+ "-c #{opts[:count]} -r #{opts[:retries]} -t #{opts[:timeout]} -i #{opts[:interval]} -b #{opts[:bytes]}"
20
+ end
21
+
22
+ def alive(hosts=[], **opts)
8
23
  return [] if hosts.empty?
9
- %x[fping -a #{hosts.join(" ")} 2>/dev/null].split("\n");
24
+ args = build_args(opts)
25
+ %x[fping #{args} -a #{hosts.join(" ")} 2>/dev/null].split("\n");
10
26
  end
11
27
 
12
- def dead(hosts=[])
28
+ def dead(hosts=[], **opts)
13
29
  return [] if hosts.empty?
14
- %x[fping -u #{hosts.join(" ")} 2>/dev/null].split("\n")
30
+ args = build_args(opts)
31
+ %x[fping #{args} -u #{hosts.join(" ")} 2>/dev/null].split("\n")
15
32
  end
16
33
 
17
- def alive_in_subnet(subnet)
18
- %x[fping -ag #{subnet} 2>/dev/null].split("\n")
34
+ def alive_in_subnet(subnet, **opts)
35
+ args = build_args(opts)
36
+ %x[fping #{args} -ag #{subnet} 2>/dev/null].split("\n")
19
37
  end
20
38
 
21
- def alive_in_range(from, to)
22
- %x[fping -ag #{from} #{to} 2>/dev/null].split("\n")
39
+ def alive_in_range(from, to, **opts)
40
+ args = build_args(opts)
41
+ %x[fping #{args} -ag #{from} #{to} 2>/dev/null].split("\n")
23
42
  end
24
-
43
+
25
44
  # Added defs for latency based metrics
26
45
  def latency_simple(host)
27
46
  bytes = 68
@@ -30,13 +49,13 @@ module Net
30
49
  %x[fping -b #{bytes} -c #{count} -q -p #{interval} #{host}]
31
50
  end
32
51
 
33
- def latency(host, bytes, count, interval)
52
+ def latency(host, bytes, count, interval=1000)
34
53
  cmd = "fping -b #{bytes} -c #{count} -q -p #{interval} #{host}"
35
54
  Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
36
55
  # output is written to stderr for some reason
37
56
  ltc = stderr.read.gsub(/[%, ]/, "/")
38
57
  ltc = ltc.split(/.*loss\/=\/[0-9]+\/[0-9]+\/([0-9]+)\/\/\/min\/avg\/max\/=\/([0-9.]+)\/([0-9.]+)\/([0-9.]+)/)[-5..4]
39
- return ltc
58
+ return ltc
40
59
  end
41
60
  end
42
61
 
data/net-fping.gemspec CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "net-fping"
7
- spec.version = "0.2.1"
7
+ spec.version = "0.3"
8
8
  spec.authors = ["Robert McLeod"]
9
9
  spec.email = ["robert@penguinpower.co.nz"]
10
10
  spec.description = %q{Net-fping is an fping wrapper that allows fast ping checks on multiple remote hosts}
@@ -15,4 +15,3 @@ Gem::Specification.new do |spec|
15
15
  spec.files = `git ls-files`.split($/)
16
16
  spec.require_paths = ["lib"]
17
17
  end
18
-
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: net-fping
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: '0.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert McLeod
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-13 00:00:00.000000000 Z
11
+ date: 2016-05-30 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Net-fping is an fping wrapper that allows fast ping checks on multiple
14
14
  remote hosts
@@ -41,7 +41,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
41
41
  version: '0'
42
42
  requirements: []
43
43
  rubyforge_project:
44
- rubygems_version: 2.2.2
44
+ rubygems_version: 2.4.8
45
45
  signing_key:
46
46
  specification_version: 4
47
47
  summary: fast ping checks using fping