philae 0.2.7 → 0.2.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.
- checksums.yaml +4 -4
- data/lib/philae/http_probe.rb +24 -6
- data/lib/philae/nsq_probe.rb +7 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c89dc51a566e3ab1b66da0e01b73f7203a571994
|
4
|
+
data.tar.gz: 2c226f8704ce011064bc1d459e3e64dcfc14103f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e7868bab5c1a030919830409f8ed852e0be2a21ed08d6f75578b0ac052161fc416eb7b9d67278673b27d7e9a0ab3b58b294609bf76d49a16733d4ee36a115ab
|
7
|
+
data.tar.gz: 4c1dc3bd083e810d0ca158300f3d4b10eaba05624c0012693a1c7c3cfd548229d681bb2775cfb352281b5ae2ce4b8d6716c767e98b932d0f750244cc8b8d5ae8
|
data/lib/philae/http_probe.rb
CHANGED
@@ -1,27 +1,45 @@
|
|
1
1
|
require 'net/http'
|
2
|
+
require 'openssl'
|
2
3
|
|
3
4
|
module Philae
|
4
5
|
class HttpProbe
|
5
6
|
attr_reader :name
|
6
7
|
|
7
|
-
|
8
|
+
# tls_context:
|
9
|
+
# {
|
10
|
+
# cert: "path/to/cert",
|
11
|
+
# key: "path/to/key",
|
12
|
+
# ca: "path/to/ca"
|
13
|
+
# }
|
14
|
+
def initialize(name, uri, username = nil, password = nil, tls_context = nil)
|
8
15
|
@name = name
|
9
16
|
@uri = uri
|
10
17
|
@username = username
|
11
18
|
@password = password
|
19
|
+
@tls_context = tls_context
|
12
20
|
end
|
13
21
|
|
14
22
|
def check
|
15
23
|
begin
|
16
24
|
uri = URI(@uri)
|
25
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
26
|
+
if uri.scheme == "https"
|
27
|
+
http.use_ssl = true
|
28
|
+
if !@tls_context.nil?
|
29
|
+
http.cert = OpenSSL::X509::Certificate.new(File.read(@tls_context[:cert]))
|
30
|
+
http.key = OpenSSL::PKey::RSA.new(File.read(@tls_context[:key]))
|
31
|
+
http.ca_file = @tls_context[:ca]
|
32
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
33
|
+
end
|
34
|
+
end
|
17
35
|
req = Net::HTTP::Get.new(uri)
|
18
36
|
req.basic_auth @username, @password if !@username.nil? || !@password.nil?
|
19
|
-
resp =
|
20
|
-
|
37
|
+
resp = http.start do |httpconn|
|
38
|
+
httpconn.request(req)
|
21
39
|
end
|
22
|
-
return { healthy: false, comment: 'Invalid response code' } if resp.code.to_s[0] != '2' && resp.code.to_s[0] != '3'
|
23
|
-
rescue
|
24
|
-
return { healthy: false, comment: 'Unable to contact server' }
|
40
|
+
return { healthy: false, comment: 'Invalid response code', code: resp.code.to_s } if resp.code.to_s[0] != '2' && resp.code.to_s[0] != '3'
|
41
|
+
rescue => e
|
42
|
+
return { healthy: false, comment: 'Unable to contact server', error: "#{e.class}: #{e.message}" }
|
25
43
|
end
|
26
44
|
{ healthy: true, comment: '' }
|
27
45
|
end
|
data/lib/philae/nsq_probe.rb
CHANGED
@@ -2,9 +2,14 @@ require File.join File.dirname(__FILE__), 'http_probe.rb'
|
|
2
2
|
|
3
3
|
module Philae
|
4
4
|
class NSQProbe < HttpProbe
|
5
|
-
def initialize(name, host, port = 4151)
|
5
|
+
def initialize(name, host, port = 4151, tls_context = nil)
|
6
6
|
@name = name
|
7
|
-
|
7
|
+
scheme = "http"
|
8
|
+
if !tls_context.nil?
|
9
|
+
scheme = "https"
|
10
|
+
end
|
11
|
+
@uri = "#{scheme}://#{host}:#{port}/ping"
|
12
|
+
@tls_context = tls_context
|
8
13
|
end
|
9
14
|
end
|
10
15
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: philae
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- leo@scalingo.com
|
@@ -103,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
103
|
version: '0'
|
104
104
|
requirements: []
|
105
105
|
rubyforge_project:
|
106
|
-
rubygems_version: 2.6.
|
106
|
+
rubygems_version: 2.6.13
|
107
107
|
signing_key:
|
108
108
|
specification_version: 4
|
109
109
|
summary: Provide an health check api
|