elbping 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/elbping/cli.rb +27 -10
  2. metadata +1 -1
data/lib/elbping/cli.rb CHANGED
@@ -13,7 +13,7 @@ module ElbPing
13
13
  OPTIONS = {}
14
14
  OPTIONS[:verb_len] = ENV['PING_ELB_MAXVERBLEN'] || 128
15
15
  OPTIONS[:nameserver] = ENV['PING_ELB_NS'] || 'ns-941.amazon.com'
16
- OPTIONS[:count] = ENV['PING_ELB_PINGCOUNT'] || 4
16
+ OPTIONS[:count] = ENV['PING_ELB_PINGCOUNT'] || 0
17
17
  OPTIONS[:timeout] = ENV['PING_ELB_TIMEOUT'] || 10
18
18
  OPTIONS[:wait] = ENV['PING_ELB_WAIT'] || 0
19
19
 
@@ -21,19 +21,24 @@ module ElbPing
21
21
  PARSER = OptionParser.new do |opts|
22
22
  opts.banner = "Usage: #{$0} [options] <elb hostname>"
23
23
 
24
- opts.on("-N NAMESERVER", "--nameserver NAMESERVER", "Use NAMESERVER to perform DNS queries") do |ns|
24
+ opts.on("-N NAMESERVER", "--nameserver NAMESERVER",
25
+ "Use NAMESERVER to perform DNS queries (default: #{OPTIONS[:nameserver]})") do |ns|
25
26
  OPTIONS[:nameserver] = ns
26
27
  end
27
- opts.on("-L LENGTH", "--verb-length LENGTH", Integer, "Use verb LENGTH characters long") do |n|
28
+ opts.on("-L LENGTH", "--verb-length LENGTH", Integer,
29
+ "Use verb LENGTH characters long (default: #{OPTIONS[:verb_len]})") do |n|
28
30
  OPTIONS[:verb_len] = n
29
31
  end
30
- opts.on("-W SECONDS", "--timeout SECONDS", Integer, "Use timeout of SECONDS for HTTP requests") do |n|
32
+ opts.on("-W SECONDS", "--timeout SECONDS", Integer,
33
+ "Use timeout of SECONDS for HTTP requests (default: #{OPTIONS[:timeout]})") do |n|
31
34
  OPTIONS[:timeout] = n
32
35
  end
33
- opts.on("-w SECONDS", "--wait SECONDS", Integer, "Wait SECONDS between pings (default: 0)") do |n|
36
+ opts.on("-w SECONDS", "--wait SECONDS", Integer,
37
+ "Wait SECONDS between pings (default: #{OPTIONS[:wait]})") do |n|
34
38
  OPTIONS[:wait] = n
35
39
  end
36
- opts.on("-c COUNT", "--count COUNT", Integer, "Ping each node COUNT times") do |n|
40
+ opts.on("-c COUNT", "--count COUNT", Integer,
41
+ "Ping each node COUNT times (default: #{OPTIONS[:count]})") do |n|
37
42
  OPTIONS[:count] = n
38
43
  end
39
44
  end
@@ -53,7 +58,17 @@ module ElbPing
53
58
  end
54
59
 
55
60
  target = ARGV[0]
56
- nodes = ElbPing::Resolver.find_elb_nodes(target, OPTIONS[:nameserver])
61
+ begin
62
+ nodes = ElbPing::Resolver.find_elb_nodes(target, OPTIONS[:nameserver])
63
+ rescue
64
+ puts "Error querying DNS for #{target} (NS: #{OPTIONS[:nameserver]})"
65
+ exit(false)
66
+ end
67
+
68
+ if nodes.size < 1
69
+ puts "Could not find any ELB nodes, no pings sent."
70
+ exit(false)
71
+ end
57
72
 
58
73
  # Set up summary objects
59
74
  total_summary = {
@@ -70,8 +85,9 @@ module ElbPing
70
85
  exit
71
86
  }
72
87
 
73
- (1..OPTIONS[:count]).each { |i|
74
- sleep OPTIONS[:wait] if i > 1
88
+ i = 0
89
+ while OPTIONS[:count] < 1 || i < OPTIONS[:count]
90
+ sleep OPTIONS[:wait] if i > 0
75
91
 
76
92
  nodes.map { |node|
77
93
  total_summary[:reqs_attempted] += 1
@@ -86,8 +102,9 @@ module ElbPing
86
102
  end
87
103
 
88
104
  ElbPing::Display.response(status)
105
+ i += 1
89
106
  }
90
- }
107
+ end
91
108
  ElbPing::Display.summary(total_summary, node_summary)
92
109
  end
93
110
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elbping
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: