elbping 0.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'elbping'
3
- s.version = '0.1'
3
+ s.version = '0.2'
4
4
  s.date = '2013-08-13'
5
5
  s.summary = "Small tool to 'ping' the nodes that make up an Amazon Elastic Load Balancer"
6
6
  s.description = "elbping is a tool to ping all of the nodes behind an Amazon Elastic Load Balancer. It only works for ELBs in HTTP mode and works by triggering an HTTP 405 (METHOD NOT ALLOWED) error caused when the ELB receives a HTTP verb that is too long."
@@ -114,6 +114,7 @@ module ElbPing
114
114
  break if not run
115
115
 
116
116
  status = ElbPing::HttpPinger.ping_node(node,
117
+ elb_uri.host,
117
118
  elb_uri.port,
118
119
  (elb_uri.path == "") ? "/" : elb_uri.path,
119
120
  (elb_uri.scheme == 'https'),
@@ -49,11 +49,12 @@ module ElbPing
49
49
  exc = status[:exception]
50
50
  sslSubject = status[:sslSubject].join(',') if status[:sslSubject]
51
51
  sslExpires = status[:sslExpires]
52
+ sslHostMatch = status[:sslHostMatch]
52
53
 
53
54
  exc_display = exc ? "exception=#{exc}" : ''
54
- ssl_display = (sslSubject and sslExpires) ? "ssl_cn=#{sslSubject} ssl_expires=#{sslExpires}" : ''
55
+ ssl_display = (sslSubject and sslExpires) ? "ssl cn=#{sslSubject} match=#{sslHostMatch} expires=#{sslExpires}" : ''
55
56
 
56
- self.out "Response from: #{node.rjust(15)}: code=#{code.to_s} time=#{duration} ms #{ssl_display} #{exc_display}"
57
+ self.out "Response from: #{node.rjust(15)}: code=#{code.to_s} time=#{duration}ms #{ssl_display} #{exc_display}"
57
58
  end
58
59
 
59
60
  # Display summary of requests, responses, and latencies (for aggregate and per-node)
@@ -22,17 +22,28 @@ module ElbPing
22
22
  cn_bucket
23
23
  end
24
24
 
25
+ # Check if a given host matches a cert's pattern
26
+ #
27
+ # Arguments:
28
+ # * cert: (object) of X.509 certificate
29
+ # * host: (string) of a hostname to compare
30
+
31
+ def self.cert_matches?(cert, host)
32
+ File.fnmatch(cert_name(cert.subject).first, host)
33
+ end
34
+
25
35
  # Make HTTP request to given node using custom request method and measure response time
26
36
  #
27
37
  # Arguments:
28
38
  # * node: (string) of node IP
39
+ # * host: (string) of hostname, used for checking SSL cert match
29
40
  # * port: (string || Fixnum) of positive integer [1, 65535]
30
41
  # * path: (string) of path to request, e.g. "/"
31
42
  # * use_ssl: (boolean) Whether or not this is HTTPS
32
43
  # * verb_len: (Fixnum) of positive integer, how long the custom HTTP verb should be
33
44
  # * timeout: (Fixnum) of positive integer, how many _seconds_ for connect and read timeouts
34
45
 
35
- def self.ping_node(node, port, path, use_ssl, verb_len, timeout)
46
+ def self.ping_node(node, host, port, path, use_ssl, verb_len, timeout)
36
47
  ##
37
48
  # Build request class
38
49
  ping_request = Class.new(Net::HTTPRequest) do
@@ -86,8 +97,11 @@ module ElbPing
86
97
  ssl_status = {}
87
98
  if use_ssl
88
99
  raise "No cert when SSL enabled?!" unless cert
89
- ssl_status = {:sslSubject => cert_name(cert.subject),
90
- :sslExpires => cert.not_after}
100
+ ssl_status = {
101
+ :sslSubject => cert_name(cert.subject),
102
+ :sslExpires => cert.not_after,
103
+ :sslHostMatch => cert_matches?(cert, host)
104
+ }
91
105
  end
92
106
 
93
107
  {:code => error || response.code,
@@ -2,6 +2,7 @@ require 'test/unit'
2
2
  require 'elbping/pinger.rb'
3
3
 
4
4
  DEFAULT_NODE = ENV['TEST_NODE'] || '127.0.0.1'
5
+ DEFAULT_HOST = ENV['TEST_HOST'] || 'localhost'
5
6
  DEFAULT_PORT = ENV['TEST_PORT'] || '80'
6
7
  DEFAULT_PATH = ENV['TEST_PATH'] || '/'
7
8
  DEFAULT_SSL = ENV['TEST_SSL'] || false
@@ -16,6 +17,7 @@ class TestHttpPinger < Test::Unit::TestCase
16
17
  assert_nothing_raised do
17
18
  resp = ElbPing::HttpPinger.ping_node(
18
19
  DEFAULT_NODE,
20
+ DEFAULT_HOST,
19
21
  DEFAULT_PORT,
20
22
  DEFAULT_PATH,
21
23
  DEFAULT_SSL,
@@ -33,3 +35,22 @@ class TestHttpPinger < Test::Unit::TestCase
33
35
  end
34
36
  end
35
37
 
38
+ require 'openssl'
39
+ class TestCertMatches
40
+ def test_wildcard
41
+ cert = OpenSSL::X509::Certificate.new
42
+ cert.subject = OpenSSL::X509::Name.parse "/CN=*.example.com"
43
+
44
+ assert ElbPing::HttpPinger.cert_matches?(cert, "www.example.com")
45
+ assert_false ElbPing::HttpPinger.cert_matches?(cert, "www.example.org")
46
+ end
47
+
48
+ def test_static
49
+ cert = OpenSSL::X509::Certificate.new
50
+ cert.subject = OpenSSL::X509::Name.parse "/CN=www.example.com"
51
+
52
+ assert ElbPing::HttpPinger.cert_matches?(cert, "www.example.com")
53
+ assert_false ElbPing::HttpPinger.cert_matches?(cert, "www.example.org")
54
+ end
55
+ end
56
+
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.1'
4
+ version: '0.2'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -78,13 +78,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
78
78
  version: '0'
79
79
  requirements: []
80
80
  rubyforge_project:
81
- rubygems_version: 1.8.25
81
+ rubygems_version: 1.8.23
82
82
  signing_key:
83
83
  specification_version: 3
84
84
  summary: Small tool to 'ping' the nodes that make up an Amazon Elastic Load Balancer
85
- test_files:
86
- - test/test_latencybucket.rb
87
- - test/test_pinger.rb
88
- - test/test_resolver.rb
89
- - test/test_stats.rb
90
- - test/test_tests.rb
85
+ test_files: []