class Philae::PhilaeProbe

Attributes

name[RW]

Public Class Methods

new(name, uri, username = nil, password = nil) click to toggle source
# File lib/philae/philae_probe.rb, line 8
def initialize(name, uri, username = nil, password = nil)
  @name = name
  @uri = uri
  @username = username
  @password = password
end

Public Instance Methods

check() click to toggle source
# File lib/philae/philae_probe.rb, line 15
def check
  begin
    uri = URI(@uri)
    req = Net::HTTP::Get.new(uri)
    req.basic_auth @username, @password if !@username.nil? || !@password.nil?
    resp = Net::HTTP.start(uri.hostname, uri.port) do |http|
      http.request(req)
    end

    if resp.code.to_s[0] != '2' && resp.code.to_s[0] != '3'
      return { healthy: false, comment: 'Invalid return code' }
    end

    status = JSON.parse(resp.body)
    if status['healthy']
      return { healthy: true, comment: '' }
    else
      return { healthy: false, comment: 'node not healthy' }
    end
  rescue
    return { healthy: false, comment: 'Unable to contact server' }
  end
end