elbping 0.0.16 → 0.1

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.0.16'
3
+ s.version = '0.1'
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."
@@ -47,9 +47,13 @@ module ElbPing
47
47
  code = status[:code]
48
48
  duration = status[:duration]
49
49
  exc = status[:exception]
50
+ sslSubject = status[:sslSubject].join(',') if status[:sslSubject]
51
+ sslExpires = status[:sslExpires]
52
+
50
53
  exc_display = exc ? "exception=#{exc}" : ''
54
+ ssl_display = (sslSubject and sslExpires) ? "ssl_cn=#{sslSubject} ssl_expires=#{sslExpires}" : ''
51
55
 
52
- self.out "Response from #{node}: code=#{code.to_s} time=#{duration} ms #{exc_display}"
56
+ self.out "Response from: #{node.rjust(15)}: code=#{code.to_s} time=#{duration} ms #{ssl_display} #{exc_display}"
53
57
  end
54
58
 
55
59
  # Display summary of requests, responses, and latencies (for aggregate and per-node)
@@ -1,11 +1,27 @@
1
1
 
2
2
  require "net/http"
3
3
  require "net/https"
4
+ require "openssl"
4
5
 
5
6
  module ElbPing
6
7
  # Responsible for all HTTP ping-like functionality
7
8
  module HttpPinger
8
9
 
10
+ # Extract CNs from a X509 subject string
11
+ #
12
+ # Arguments:
13
+ # * x509_subject: (string) of cert subject
14
+
15
+ def self.cert_name(x509_subject)
16
+ cn_bucket = Array.new
17
+ x509_subject.to_a.each do |entry|
18
+ if entry.first == 'CN' and entry[1]
19
+ cn_bucket << entry[1]
20
+ end
21
+ end
22
+ cn_bucket
23
+ end
24
+
9
25
  # Make HTTP request to given node using custom request method and measure response time
10
26
  #
11
27
  # Arguments:
@@ -42,10 +58,18 @@ module ElbPing
42
58
 
43
59
  ##
44
60
  # Make the HTTP request and handle any errors along the way
45
- error = nil
46
- exc = nil
61
+ error, exc = nil, nil
62
+ req, response, cert = nil, nil, nil
63
+
47
64
  begin
48
- response = http.request(ping_request.new(path))
65
+ http.start do
66
+ req = ping_request.new(path)
67
+ cert = http.peer_cert
68
+ response = http.request(req)
69
+ end
70
+ rescue OpenSSL::SSL::SSLError => e
71
+ # This probably? won't happen with VERIFY_NONE
72
+ error = :sslerror
49
73
  rescue Errno::ECONNREFUSED
50
74
  error = :econnrefused
51
75
  rescue Timeout::Error
@@ -59,10 +83,18 @@ module ElbPing
59
83
  error = :exception
60
84
  end
61
85
 
86
+ ssl_status = {}
87
+ if use_ssl
88
+ raise "No cert when SSL enabled?!" unless cert
89
+ ssl_status = {:sslSubject => cert_name(cert.subject),
90
+ :sslExpires => cert.not_after}
91
+ end
92
+
62
93
  {:code => error || response.code,
63
94
  :exception => exc,
64
95
  :node => node,
65
- :duration => ((Time.now.getutc - start) * 1000).to_i} # returns in ms
96
+ :duration => ((Time.now.getutc - start) * 1000).to_i, # returns in ms
97
+ }.merge(ssl_status)
66
98
  end
67
99
  end
68
100
  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.16
4
+ version: '0.1'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: