elbping 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/elbping/cli.rb +16 -10
- data/lib/elbping/pinger.rb +10 -3
- metadata +1 -1
data/lib/elbping/cli.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'optparse'
|
4
|
+
require 'uri'
|
4
5
|
|
5
6
|
require 'elbping/pinger.rb'
|
6
7
|
require 'elbping/resolver.rb'
|
@@ -16,11 +17,10 @@ module ElbPing
|
|
16
17
|
OPTIONS[:count] = ENV['PING_ELB_PINGCOUNT'] || 0
|
17
18
|
OPTIONS[:timeout] = ENV['PING_ELB_TIMEOUT'] || 10
|
18
19
|
OPTIONS[:wait] = ENV['PING_ELB_WAIT'] || 0
|
19
|
-
OPTIONS[:port] = ENV['PING_ELB_PORT'] || 80
|
20
20
|
|
21
21
|
# Build parser for command line options
|
22
22
|
PARSER = OptionParser.new do |opts|
|
23
|
-
opts.banner = "Usage: #{$0} [options] <elb
|
23
|
+
opts.banner = "Usage: #{$0} [options] <elb uri>"
|
24
24
|
|
25
25
|
opts.on("-N NAMESERVER", "--nameserver NAMESERVER",
|
26
26
|
"Use NAMESERVER to perform DNS queries (default: #{OPTIONS[:nameserver]})") do |ns|
|
@@ -42,10 +42,6 @@ module ElbPing
|
|
42
42
|
"Ping each node COUNT times (default: #{OPTIONS[:count]})") do |n|
|
43
43
|
OPTIONS[:count] = n
|
44
44
|
end
|
45
|
-
opts.on("-p PORT", "--port PORT", Integer,
|
46
|
-
"Port to send requests to (default: #{OPTIONS[:port]})") do |n|
|
47
|
-
OPTIONS[:port] = n
|
48
|
-
end
|
49
45
|
end
|
50
46
|
|
51
47
|
# Parse options
|
@@ -75,12 +71,18 @@ module ElbPing
|
|
75
71
|
if ARGV.size < 1
|
76
72
|
usage
|
77
73
|
end
|
74
|
+
unless ARGV[0] =~ URI::regexp
|
75
|
+
puts "ERROR: ELB URI does not seem valid"
|
76
|
+
usage
|
77
|
+
end
|
78
|
+
elb_uri_s = ARGV[0]
|
79
|
+
elb_uri = URI.parse(elb_uri_s)
|
78
80
|
|
79
|
-
target = ARGV[0]
|
80
81
|
begin
|
81
|
-
nodes = ElbPing::Resolver.find_elb_nodes(
|
82
|
+
nodes = ElbPing::Resolver.find_elb_nodes(elb_uri.host,
|
83
|
+
OPTIONS[:nameserver])
|
82
84
|
rescue
|
83
|
-
puts "Error querying DNS for #{
|
85
|
+
puts "Error querying DNS for #{elb_uri.host} (NS: #{OPTIONS[:nameserver]})"
|
84
86
|
exit(false)
|
85
87
|
end
|
86
88
|
|
@@ -98,8 +100,12 @@ module ElbPing
|
|
98
100
|
nodes.map { |node|
|
99
101
|
total_summary[:reqs_attempted] += 1
|
100
102
|
node_summary[node][:reqs_attempted] += 1
|
103
|
+
|
101
104
|
status = ElbPing::HttpPinger.ping_node(node,
|
102
|
-
|
105
|
+
elb_uri.port,
|
106
|
+
(elb_uri.path == "") ? "/" : elb_uri.path,
|
107
|
+
(elb_uri.scheme == 'https'),
|
108
|
+
OPTIONS[:verb_len], OPTIONS[:timeout])
|
103
109
|
|
104
110
|
unless status[:code] == :timeout
|
105
111
|
total_summary[:reqs_completed] += 1
|
data/lib/elbping/pinger.rb
CHANGED
@@ -1,23 +1,30 @@
|
|
1
1
|
|
2
2
|
require "net/http"
|
3
|
+
require "net/https"
|
3
4
|
|
4
5
|
module ElbPing
|
5
6
|
module HttpPinger
|
6
7
|
# Make HTTP request to given node using custom request method
|
7
|
-
def self.ping_node(node,
|
8
|
-
|
8
|
+
def self.ping_node(node, port, path, use_ssl, verb_len, timeout)
|
9
|
+
# Build request class
|
9
10
|
ping_request = Class.new(Net::HTTPRequest) do
|
10
11
|
const_set :METHOD, "A" * verb_len
|
11
12
|
const_set :REQUEST_HAS_BODY, false
|
12
13
|
const_set :RESPONSE_HAS_BODY, false
|
13
14
|
end
|
14
15
|
|
16
|
+
# Configure http object
|
15
17
|
start = Time.now.getutc
|
16
18
|
http = Net::HTTP.new(node, port.to_s)
|
17
19
|
http.open_timeout = timeout
|
18
20
|
http.read_timeout = timeout
|
19
21
|
http.continue_timeout = timeout
|
20
|
-
|
22
|
+
|
23
|
+
if use_ssl
|
24
|
+
http.use_ssl = true
|
25
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
26
|
+
http.ssl_timeout = timeout
|
27
|
+
end
|
21
28
|
|
22
29
|
error = nil
|
23
30
|
exc = nil
|