Sha256: 4c589a412752a3fd9cfa66cfd027a179cfd58653850363c50a3058d37a752295

Contents?: true

Size: 1.09 KB

Versions: 22

Compression:

Stored size: 1.09 KB

Contents

#
# Orchestration Healthcheck Utility
#
#
# https://github.com/bobf/orchestration
#

require 'net/http'

def run
  client = Net::HTTP.new(
    ENV.fetch('WEB_HOST', 'localhost'),
    ENV.fetch('WEB_PORT', '8080').to_i
  )

  client.read_timeout = ENV.fetch('WEB_HEALTHCHECK_READ_TIMEOUT', '10').to_i
  client.open_timeout = ENV.fetch('WEB_HEALTHCHECK_OPEN_TIMEOUT', '10').to_i

  client.start do |request|
    request.get(ENV.fetch('WEB_HEALTHCHECK_PATH') { '/' })
  end
end

def success_codes
  ENV.fetch('WEB_HEALTHCHECK_SUCCESS_CODES', '200,202,204').split(',')
end

def success?(code)
  success_codes.include?(code.to_s)
end

def message(code)
  if success?(code)
    outcome = 'SUCCESS ✓ '
    in_or_not = 'IN'
  else
    outcome = 'FAILURE ✘ '
    in_or_not = 'NOT IN'
  end

  accepted = success_codes.join(', ')

  "# HTTP_STATUS(#{code}) #{in_or_not} [#{accepted}] : #{outcome} [#{__FILE__}]"
end

return_code = 1

begin
  response = run
  return_code = 0 if success?(response.code)
  puts message(response.code)
rescue Exception => e
  puts "[#{__FILE__}] ERROR: #{e.inspect}"
ensure
  exit return_code
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
orchestration-0.5.0 lib/orchestration/templates/healthcheck.rb.erb
orchestration-0.4.21 lib/orchestration/templates/healthcheck.rb.erb
orchestration-0.4.20 lib/orchestration/templates/healthcheck.rb.erb
orchestration-0.4.19 lib/orchestration/templates/healthcheck.rb.erb
orchestration-0.4.18 lib/orchestration/templates/healthcheck.rb.erb
orchestration-0.4.17 lib/orchestration/templates/healthcheck.rb.erb
orchestration-0.4.16 lib/orchestration/templates/healthcheck.rb.erb
orchestration-0.4.15 lib/orchestration/templates/healthcheck.rb.erb
orchestration-0.4.14 lib/orchestration/templates/healthcheck.rb.erb
orchestration-0.4.13 lib/orchestration/templates/healthcheck.rb.erb
orchestration-0.4.12 lib/orchestration/templates/healthcheck.rb.erb
orchestration-0.4.10 lib/orchestration/templates/healthcheck.rb.erb
orchestration-0.4.9 lib/orchestration/templates/healthcheck.rb.erb
orchestration-0.4.8 lib/orchestration/templates/healthcheck.rb.erb
orchestration-0.4.7 lib/orchestration/templates/healthcheck.rb.erb
orchestration-0.4.6 lib/orchestration/templates/healthcheck.rb.erb
orchestration-0.4.5 lib/orchestration/templates/healthcheck.rb.erb
orchestration-0.4.4 lib/orchestration/templates/healthcheck.rb.erb
orchestration-0.4.3 lib/orchestration/templates/healthcheck.rb.erb
orchestration-0.4.2 lib/orchestration/templates/healthcheck.rb.erb