class Philae::HttpProbe
Attributes
name[R]
Public Class Methods
new(name, uri, username = nil, password = nil, tls_context = nil, timeout = nil)
click to toggle source
tls_context: {
cert: "path/to/cert", key: "path/to/key", ca: "path/to/ca"
}
# File lib/philae/http_probe.rb, line 14 def initialize(name, uri, username = nil, password = nil, tls_context = nil, timeout = nil) @name = name @uri = uri @username = username @password = password @tls_context = tls_context @timeout = timeout end
Public Instance Methods
check()
click to toggle source
# File lib/philae/http_probe.rb, line 23 def check begin uri = URI(@uri) http = Net::HTTP.new(uri.host, uri.port) if uri.scheme == "https" http.use_ssl = true if !@tls_context.nil? http.cert = OpenSSL::X509::Certificate.new(File.read(@tls_context[:cert])) http.key = OpenSSL::PKey::RSA.new(File.read(@tls_context[:key])) http.ca_file = @tls_context[:ca] http.verify_mode = OpenSSL::SSL::VERIFY_PEER end end if !@timeout.nil? http.read_timeout = @timeout http.open_timeout = @timeout http.write_timeout = @timeout http.ssl_timeout = @timeout end req = Net::HTTP::Get.new(uri) req.basic_auth @username, @password if !@username.nil? || !@password.nil? resp = http.start do |httpconn| httpconn.request(req) end 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' rescue => e return { healthy: false, comment: 'Unable to contact server', error: "#{e.class}: #{e.message}" } end return { healthy: true, comment: '' } end