rails_health_check 3.0.0 → 3.0.1
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/.rubocop.yml +5 -0
- data/Gemfile +3 -2
- data/Rakefile +7 -5
- data/Vagrantfile +7 -6
- data/config/routes.rb +3 -1
- data/health_check.gemspec +2 -2
- data/init.rb +2 -1
- data/lib/health_check.rb +9 -9
- data/lib/health_check/base_health_check.rb +2 -0
- data/lib/health_check/health_check_controller.rb +17 -20
- data/lib/health_check/health_check_routes.rb +3 -3
- data/lib/health_check/middleware_health_check.rb +20 -21
- data/lib/health_check/resque_health_check.rb +11 -10
- data/lib/health_check/s3_health_check.rb +5 -8
- data/lib/health_check/sidekiq_health_check.rb +4 -3
- data/lib/health_check/utils.rb +91 -93
- data/lib/health_check/version.rb +3 -1
- data/test/fake_smtp_server +8 -8
- data/test/migrate/nine/9_create_countries.rb +2 -0
- data/test/migrate/twelve/011_create_roles.roles.rb +2 -0
- data/test/migrate/twelve/012_create_users.rb +3 -1
- data/test/migrate/twelve/9_create_countries.rb +2 -0
- data/test/rails_5.1.gemfile +9 -8
- data/test/rails_edge.gemfile +11 -9
- data/test/testurl +24 -14
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4569367e3c910ab49259c4744fff38cc16a741696462f56526db2a20b6e35993
|
4
|
+
data.tar.gz: 28de3529ecc64a42d682d52880597f8e0dd4a7f574543dac40c60955fcfbe3bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 884d6565824e9e9ae2d57b4fc5e5a6ec7f74a4cdcaed9f00360e220d788c7a13e9a6a2725e05efd41b0ece8397f95f2f2ca27d60d46488d204096eccc959bda6
|
7
|
+
data.tar.gz: 5c15d9b7a2bf2108fdcf64b46a67e15b860e870f25a7b17177675ad6fefaa629e12f4fe2f46f9542fc0741d83fb5a5687111ea3fab7b0423e18eabd82c8749f2
|
data/.rubocop.yml
ADDED
data/Gemfile
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
source 'https://rubygems.org'
|
2
4
|
|
3
5
|
# Specify your gem's dependencies in health_check.gemspec
|
@@ -6,8 +8,8 @@ gemspec
|
|
6
8
|
|
7
9
|
group :development, :test do
|
8
10
|
if defined?(JRUBY_VERSION)
|
9
|
-
gem 'jruby-openssl'
|
10
11
|
gem 'activerecord-jdbcsqlite3-adapter'
|
12
|
+
gem 'jruby-openssl'
|
11
13
|
else
|
12
14
|
gem 'sqlite3', '~> 1.3.7'
|
13
15
|
end
|
@@ -16,5 +18,4 @@ group :development, :test do
|
|
16
18
|
# mime-types 2.0 requires Ruby version >= 1.9.2
|
17
19
|
# mime-types 3.0 requires Ruby version >= 2.0
|
18
20
|
gem 'mime-types', defined?(JRUBY_VERSION) || RUBY_VERSION < '2.0' ? '< 3' : '>= 3.0'
|
19
|
-
|
20
21
|
end
|
data/Rakefile
CHANGED
@@ -1,14 +1,16 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
|
5
|
+
# require 'rubygems'
|
4
6
|
require 'rake'
|
5
7
|
|
6
|
-
#tests as gem
|
8
|
+
# tests as gem
|
7
9
|
task :test do
|
8
10
|
exec '/bin/bash', './test/test_with_railsapp'
|
9
11
|
end
|
10
12
|
|
11
|
-
task :
|
13
|
+
task default: :test
|
12
14
|
|
13
15
|
begin
|
14
16
|
gem 'rdoc'
|
@@ -25,5 +27,5 @@ begin
|
|
25
27
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
26
28
|
end
|
27
29
|
rescue Gem::LoadError
|
28
|
-
puts
|
30
|
+
puts 'rdoc (or a dependency) not available. Install it with: gem install rdoc'
|
29
31
|
end
|
data/Vagrantfile
CHANGED
@@ -1,20 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# -*- mode: ruby -*-
|
2
4
|
# vi: set ft=ruby :
|
3
5
|
|
4
|
-
Vagrant.configure(
|
6
|
+
Vagrant.configure('2') do |config|
|
5
7
|
# For a complete reference, please see the online documentation at
|
6
8
|
# https://docs.vagrantup.com.
|
7
9
|
|
8
|
-
config.vm.box =
|
10
|
+
config.vm.box = 'ubuntu/xenial64'
|
9
11
|
|
10
|
-
# set auto_update to false, if you do NOT want to check the correct
|
12
|
+
# set auto_update to false, if you do NOT want to check the correct
|
11
13
|
# additions version when booting this machine
|
12
14
|
config.vbguest.auto_update = false
|
13
|
-
|
15
|
+
|
14
16
|
# do NOT download the iso file from a webserver
|
15
17
|
config.vbguest.no_remote = true
|
16
18
|
|
17
19
|
# provision with a shell script.
|
18
|
-
config.vm.provision
|
19
|
-
|
20
|
+
config.vm.provision 'shell', path: './test/provision_vagrant'
|
20
21
|
end
|
data/config/routes.rb
CHANGED
data/health_check.gemspec
CHANGED
@@ -11,10 +11,10 @@ Gem::Specification.new do |gem|
|
|
11
11
|
gem.authors = ['Ian Heggie']
|
12
12
|
gem.email = ['ian@heggie.biz']
|
13
13
|
gem.summary = 'Simple health check of Rails app for uptime monitoring with Pingdom, NewRelic, EngineYard or uptime.openacs.org etc.'
|
14
|
-
gem.description = <<-
|
14
|
+
gem.description = <<-EOD
|
15
15
|
Fork of https://github.com/ianheggie/health_check.
|
16
16
|
Simple health check of Rails app for uptime monitoring with Pingdom, NewRelic, EngineYard or uptime.openacs.org etc.
|
17
|
-
|
17
|
+
EOD
|
18
18
|
gem.homepage = 'https://github.com/FinalCAD/health_check'
|
19
19
|
|
20
20
|
gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
data/init.rb
CHANGED
data/lib/health_check.rb
CHANGED
@@ -1,19 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Copyright (c) 2010-2013 Ian Heggie, released under the MIT license.
|
2
4
|
# See MIT-LICENSE for details.
|
3
5
|
|
4
6
|
module HealthCheck
|
5
|
-
|
6
7
|
class Engine < Rails::Engine
|
7
|
-
cattr_accessor :routes_explicitly_defined
|
8
|
+
cattr_accessor :routes_explicitly_defined
|
8
9
|
end
|
9
10
|
|
10
11
|
# Text output upon success
|
11
12
|
mattr_accessor :success
|
12
|
-
self.success =
|
13
|
+
self.success = 'success'
|
13
14
|
|
14
15
|
# Text output upon failure
|
15
16
|
mattr_accessor :failure
|
16
|
-
self.failure =
|
17
|
+
self.failure = 'failure'
|
17
18
|
|
18
19
|
# Timeout in seconds used when checking smtp server
|
19
20
|
mattr_accessor :smtp_timeout
|
@@ -57,13 +58,13 @@ module HealthCheck
|
|
57
58
|
mattr_accessor :custom_checks
|
58
59
|
mattr_accessor :full_checks
|
59
60
|
mattr_accessor :standard_checks
|
60
|
-
self.custom_checks = {
|
61
|
+
self.custom_checks = {}
|
61
62
|
self.full_checks = ['database', 'migrations', 'custom', 'email', 'cache', 'redis-if-present', 'sidekiq-redis-if-present', 'resque-redis-if-present', 's3-if-present']
|
62
|
-
self.standard_checks = [
|
63
|
+
self.standard_checks = %w[database migrations custom emailconf]
|
63
64
|
|
64
65
|
# Middleware based checks
|
65
66
|
mattr_accessor :middleware_checks
|
66
|
-
self.middleware_checks = [
|
67
|
+
self.middleware_checks = ['middleware']
|
67
68
|
|
68
69
|
mattr_accessor :installed_as_middleware
|
69
70
|
|
@@ -77,14 +78,13 @@ module HealthCheck
|
|
77
78
|
self.include_error_in_response_body = true
|
78
79
|
|
79
80
|
def self.add_custom_check(name = 'custom', &block)
|
80
|
-
custom_checks[name] ||= [
|
81
|
+
custom_checks[name] ||= []
|
81
82
|
custom_checks[name] << block
|
82
83
|
end
|
83
84
|
|
84
85
|
def self.setup
|
85
86
|
yield self
|
86
87
|
end
|
87
|
-
|
88
88
|
end
|
89
89
|
|
90
90
|
require 'health_check/version'
|
@@ -1,21 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Copyright (c) 2010-2013 Ian Heggie, released under the MIT license.
|
2
4
|
# See MIT-LICENSE for details.
|
3
5
|
|
4
6
|
module HealthCheck
|
5
7
|
class HealthCheckController < ActionController::Base
|
6
|
-
|
7
|
-
layout false if self.respond_to? :layout
|
8
|
+
layout false if respond_to? :layout
|
8
9
|
before_action :check_origin_ip
|
9
10
|
before_action :authenticate
|
10
11
|
|
11
12
|
def index
|
12
13
|
last_modified = Time.now.utc
|
13
14
|
max_age = HealthCheck.max_age
|
14
|
-
if max_age > 1
|
15
|
-
|
16
|
-
|
17
|
-
public = (max_age > 1) && ! HealthCheck.basic_auth_username
|
18
|
-
if stale?(:last_modified => last_modified, :public => public)
|
15
|
+
last_modified = Time.at((last_modified.to_f / max_age).floor * max_age).utc if max_age > 1
|
16
|
+
public = (max_age > 1) && !HealthCheck.basic_auth_username
|
17
|
+
if stale?(last_modified: last_modified, public: public)
|
19
18
|
checks = params[:checks] ? params[:checks].split('_') : ['standard']
|
20
19
|
checks -= HealthCheck.middleware_checks if HealthCheck.installed_as_middleware
|
21
20
|
begin
|
@@ -30,9 +29,7 @@ module HealthCheck
|
|
30
29
|
msg = HealthCheck.include_error_in_response_body ? "health_check failed: #{errors}" : nil
|
31
30
|
send_response false, msg, HealthCheck.http_status_for_error_text, HealthCheck.http_status_for_error_object
|
32
31
|
# Log a single line as some uptime checkers only record that it failed, not the text returned
|
33
|
-
|
34
|
-
logger.info msg
|
35
|
-
end
|
32
|
+
logger&.info msg
|
36
33
|
end
|
37
34
|
end
|
38
35
|
end
|
@@ -41,17 +38,18 @@ module HealthCheck
|
|
41
38
|
|
42
39
|
def send_response(healthy, msg, text_status, obj_status)
|
43
40
|
msg ||= healthy ? HealthCheck.success : HealthCheck.failure
|
44
|
-
obj = { :
|
41
|
+
obj = { healthy: healthy, message: msg }
|
45
42
|
respond_to do |format|
|
46
|
-
format.html { render :
|
47
|
-
format.json { render :
|
48
|
-
format.xml { render :
|
49
|
-
format.any { render :
|
43
|
+
format.html { render plain: msg, status: text_status, content_type: 'text/plain' }
|
44
|
+
format.json { render json: obj, status: obj_status }
|
45
|
+
format.xml { render xml: obj, status: obj_status }
|
46
|
+
format.any { render plain: msg, status: text_status, content_type: 'text/plain' }
|
50
47
|
end
|
51
48
|
end
|
52
49
|
|
53
50
|
def authenticate
|
54
51
|
return unless HealthCheck.basic_auth_username && HealthCheck.basic_auth_password
|
52
|
+
|
55
53
|
authenticate_or_request_with_http_basic('Health Check') do |username, password|
|
56
54
|
username == HealthCheck.basic_auth_username && password == HealthCheck.basic_auth_password
|
57
55
|
end
|
@@ -59,10 +57,10 @@ module HealthCheck
|
|
59
57
|
|
60
58
|
def check_origin_ip
|
61
59
|
unless HealthCheck.origin_ip_whitelist.blank? ||
|
62
|
-
|
63
|
-
render :
|
64
|
-
:
|
65
|
-
:
|
60
|
+
HealthCheck.origin_ip_whitelist.include?(request.ip)
|
61
|
+
render plain: 'Health check is not allowed for the requesting IP',
|
62
|
+
status: HealthCheck.http_status_for_ip_whitelist_error,
|
63
|
+
content_type: 'text/plain'
|
66
64
|
end
|
67
65
|
end
|
68
66
|
|
@@ -70,6 +68,5 @@ module HealthCheck
|
|
70
68
|
def protect_against_forgery?
|
71
69
|
false
|
72
70
|
end
|
73
|
-
|
74
71
|
end
|
75
72
|
end
|
@@ -1,6 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActionDispatch::Routing
|
2
4
|
class Mapper
|
3
|
-
|
4
5
|
def health_check_routes(prefix = nil)
|
5
6
|
HealthCheck::Engine.routes_explicitly_defined = true
|
6
7
|
add_health_check_routes(prefix)
|
@@ -8,8 +9,7 @@ module ActionDispatch::Routing
|
|
8
9
|
|
9
10
|
def add_health_check_routes(prefix = nil)
|
10
11
|
HealthCheck.uri = prefix if prefix
|
11
|
-
match "#{HealthCheck.uri}(/:checks)(.:format)", :
|
12
|
+
match "#{HealthCheck.uri}(/:checks)(.:format)", to: 'health_check/health_check#index', via: %i[get post], defaults: { format: 'txt' }
|
12
13
|
end
|
13
|
-
|
14
14
|
end
|
15
15
|
end
|
@@ -1,6 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module HealthCheck
|
2
4
|
class MiddlewareHealthcheck
|
3
|
-
|
4
5
|
def initialize(app)
|
5
6
|
@app = app
|
6
7
|
end
|
@@ -11,16 +12,15 @@ module HealthCheck
|
|
11
12
|
if error_response = (ip_blocked(env) || not_authenticated(env))
|
12
13
|
return error_response
|
13
14
|
end
|
15
|
+
|
14
16
|
HealthCheck.installed_as_middleware = true
|
15
17
|
errors = ''
|
16
18
|
begin
|
17
19
|
# Process the checks to be run from middleware
|
18
20
|
errors = HealthCheck::Utils.process_checks(middleware_checks, true)
|
19
21
|
# Process remaining checks through the full stack if there are any
|
20
|
-
unless full_stack_checks.empty?
|
21
|
-
|
22
|
-
end
|
23
|
-
rescue => e
|
22
|
+
return @app.call(env) unless full_stack_checks.empty?
|
23
|
+
rescue StandardError => e
|
24
24
|
errors = e.message.blank? ? e.class.to_s : e.message.to_s
|
25
25
|
end
|
26
26
|
healthy = errors.blank?
|
@@ -37,7 +37,7 @@ module HealthCheck
|
|
37
37
|
content_type = 'text/plain'
|
38
38
|
error_code = HealthCheck.http_status_for_error_text
|
39
39
|
end
|
40
|
-
[
|
40
|
+
[(healthy ? 200 : error_code), { 'Content-Type' => content_type }, [msg]]
|
41
41
|
else
|
42
42
|
@app.call(env)
|
43
43
|
end
|
@@ -47,46 +47,46 @@ module HealthCheck
|
|
47
47
|
|
48
48
|
def parse_env(env)
|
49
49
|
uri = env['PATH_INFO']
|
50
|
-
if uri =~
|
51
|
-
checks =
|
52
|
-
response_type =
|
50
|
+
if uri =~ %r{^/#{Regexp.escape HealthCheck.uri}(/([-_0-9a-zA-Z]*))?(\.(\w*))?$}
|
51
|
+
checks = Regexp.last_match(2).to_s == '' ? ['standard'] : Regexp.last_match(2).split('_')
|
52
|
+
response_type = Regexp.last_match(4).to_s
|
53
53
|
middleware_checks = checks & HealthCheck.middleware_checks
|
54
54
|
full_stack_checks = (checks - HealthCheck.middleware_checks) - ['and']
|
55
|
-
[response_type, middleware_checks, full_stack_checks
|
55
|
+
[response_type, middleware_checks, full_stack_checks]
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
59
|
def ip_blocked(env)
|
60
60
|
return false if HealthCheck.origin_ip_whitelist.blank?
|
61
|
+
|
61
62
|
req = Rack::Request.new(env)
|
62
63
|
unless HealthCheck.origin_ip_whitelist.include?(req.ip)
|
63
|
-
[
|
64
|
-
|
65
|
-
|
66
|
-
]
|
64
|
+
[HealthCheck.http_status_for_ip_whitelist_error,
|
65
|
+
{ 'Content-Type' => 'text/plain' },
|
66
|
+
['Health check is not allowed for the requesting IP']]
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
70
|
def not_authenticated(env)
|
71
71
|
return false unless HealthCheck.basic_auth_username && HealthCheck.basic_auth_password
|
72
|
+
|
72
73
|
auth = MiddlewareHealthcheck::Request.new(env)
|
73
74
|
if auth.provided? && auth.basic? && Rack::Utils.secure_compare(HealthCheck.basic_auth_username, auth.username) && Rack::Utils.secure_compare(HealthCheck.basic_auth_password, auth.password)
|
74
75
|
env['REMOTE_USER'] = auth.username
|
75
76
|
return false
|
76
77
|
end
|
77
|
-
[
|
78
|
-
|
79
|
-
|
80
|
-
]
|
78
|
+
[401,
|
79
|
+
{ 'Content-Type' => 'text/plain', 'WWW-Authenticate' => 'Basic realm="Health Check"' },
|
80
|
+
[]]
|
81
81
|
end
|
82
82
|
|
83
83
|
class Request < Rack::Auth::AbstractRequest
|
84
84
|
def basic?
|
85
|
-
|
85
|
+
scheme == 'basic'
|
86
86
|
end
|
87
87
|
|
88
88
|
def credentials
|
89
|
-
@credentials ||= params.
|
89
|
+
@credentials ||= params.unpack1('m*').split(/:/, 2)
|
90
90
|
end
|
91
91
|
|
92
92
|
def username
|
@@ -97,6 +97,5 @@ module HealthCheck
|
|
97
97
|
credentials.last
|
98
98
|
end
|
99
99
|
end
|
100
|
-
|
101
100
|
end
|
102
101
|
end
|
@@ -1,15 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module HealthCheck
|
2
|
-
|
3
|
-
|
4
|
+
class ResqueHealthCheck
|
5
|
+
extend BaseHealthCheck
|
6
|
+
|
7
|
+
def self.check
|
8
|
+
raise "Wrong configuration. Missing 'resque' gem" unless defined?(::Resque)
|
4
9
|
|
5
|
-
def self.check
|
6
|
-
unless defined?(::Resque)
|
7
|
-
raise "Wrong configuration. Missing 'resque' gem"
|
8
|
-
end
|
9
10
|
res = ::Resque.redis.ping
|
10
11
|
res == 'PONG' ? '' : "Resque.redis.ping returned #{res.inspect} instead of PONG"
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
rescue Exception => e
|
13
|
+
create_error 'resque-redis', e.message
|
14
|
+
end
|
15
|
+
end
|
15
16
|
end
|
@@ -1,24 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module HealthCheck
|
2
4
|
class S3HealthCheck
|
3
5
|
extend BaseHealthCheck
|
4
6
|
|
5
7
|
class << self
|
6
8
|
def check
|
7
|
-
unless defined?(::Aws)
|
8
|
-
raise "Wrong configuration. Missing 'aws-sdk' gem"
|
9
|
-
end
|
9
|
+
raise "Wrong configuration. Missing 'aws-sdk' gem" unless defined?(::Aws)
|
10
10
|
return create_error 's3', 'Could not connect to aws' if aws_s3_client.nil?
|
11
|
+
|
11
12
|
HealthCheck.buckets.each do |bucket_name, permissions|
|
12
|
-
if permissions.nil? # backward compatible
|
13
|
-
permissions = [:R, :W, :D]
|
14
|
-
end
|
13
|
+
permissions = %i[R W D] if permissions.nil? # backward compatible
|
15
14
|
permissions.each do |permision|
|
16
|
-
begin
|
17
15
|
send(permision, bucket_name)
|
18
16
|
rescue Exception => e
|
19
17
|
raise "bucket:#{bucket_name}, permission:#{permision} - #{e.message}"
|
20
18
|
end
|
21
|
-
end
|
22
19
|
end
|
23
20
|
''
|
24
21
|
rescue Exception => e
|
@@ -1,11 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module HealthCheck
|
2
4
|
class SidekiqHealthCheck
|
3
5
|
extend BaseHealthCheck
|
4
6
|
|
5
7
|
def self.check
|
6
|
-
unless defined?(::Sidekiq)
|
7
|
-
|
8
|
-
end
|
8
|
+
raise "Wrong configuration. Missing 'sidekiq' gem" unless defined?(::Sidekiq)
|
9
|
+
|
9
10
|
::Sidekiq.redis do |r|
|
10
11
|
res = r.ping
|
11
12
|
res == 'PONG' ? '' : "Sidekiq.redis.ping returned #{res.inspect} instead of PONG"
|
data/lib/health_check/utils.rb
CHANGED
@@ -1,19 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Copyright (c) 2010-2013 Ian Heggie, released under the MIT license.
|
2
4
|
# See MIT-LICENSE for details.
|
3
5
|
|
4
6
|
module HealthCheck
|
5
7
|
class Utils
|
6
|
-
|
7
8
|
@@default_smtp_settings =
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
9
|
+
{
|
10
|
+
address: 'localhost',
|
11
|
+
port: 25,
|
12
|
+
domain: 'localhost.localdomain',
|
13
|
+
user_name: nil,
|
14
|
+
password: nil,
|
15
|
+
authentication: nil,
|
16
|
+
enable_starttls_auto: true
|
17
|
+
}
|
17
18
|
|
18
19
|
cattr_accessor :default_smtp_settings
|
19
20
|
|
@@ -22,77 +23,75 @@ module HealthCheck
|
|
22
23
|
errors = ''
|
23
24
|
checks.each do |check|
|
24
25
|
case check
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
end
|
41
|
-
else
|
42
|
-
database_version = HealthCheck::Utils.get_database_version
|
43
|
-
migration_version = HealthCheck::Utils.get_migration_version
|
44
|
-
if database_version.to_i != migration_version.to_i
|
45
|
-
errors << "Current database version (#{database_version}) does not match latest migration (#{migration_version}). "
|
46
|
-
end
|
47
|
-
end
|
48
|
-
when 'cache'
|
49
|
-
errors << HealthCheck::Utils.check_cache
|
50
|
-
when 'resque-redis-if-present'
|
51
|
-
errors << HealthCheck::ResqueHealthCheck.check if defined?(::Resque)
|
52
|
-
when 'sidekiq-redis-if-present'
|
53
|
-
errors << HealthCheck::SidekiqHealthCheck.check if defined?(::Sidekiq)
|
54
|
-
when 'redis-if-present'
|
55
|
-
errors << HealthCheck::RedisHealthCheck.check if defined?(::Redis)
|
56
|
-
when 's3-if-present'
|
57
|
-
errors << HealthCheck::S3HealthCheck.check if defined?(::Aws)
|
58
|
-
when 'resque-redis'
|
59
|
-
errors << HealthCheck::ResqueHealthCheck.check
|
60
|
-
when 'sidekiq-redis'
|
61
|
-
errors << HealthCheck::SidekiqHealthCheck.check
|
62
|
-
when 'redis'
|
63
|
-
errors << HealthCheck::RedisHealthCheck.check
|
64
|
-
when 's3'
|
65
|
-
errors << HealthCheck::S3HealthCheck.check
|
66
|
-
when "standard"
|
67
|
-
errors << HealthCheck::Utils.process_checks(HealthCheck.standard_checks, called_from_middleware)
|
68
|
-
when "middleware"
|
69
|
-
errors << "Health check not called from middleware - probably not installed as middleware." unless called_from_middleware
|
70
|
-
when "custom"
|
71
|
-
HealthCheck.custom_checks.each do |name, list|
|
72
|
-
list.each do |custom_check|
|
73
|
-
errors << custom_check.call(self)
|
74
|
-
end
|
26
|
+
when 'and', 'site'
|
27
|
+
# do nothing
|
28
|
+
when 'database'
|
29
|
+
HealthCheck::Utils.get_database_version
|
30
|
+
when 'email'
|
31
|
+
errors << HealthCheck::Utils.check_email
|
32
|
+
when 'emailconf'
|
33
|
+
errors << HealthCheck::Utils.check_email if HealthCheck::Utils.mailer_configured?
|
34
|
+
when 'migrations', 'migration'
|
35
|
+
if defined?(ActiveRecord::Migration) && ActiveRecord::Migration.respond_to?(:check_pending!)
|
36
|
+
# Rails 4+
|
37
|
+
begin
|
38
|
+
ActiveRecord::Migration.check_pending!
|
39
|
+
rescue ActiveRecord::PendingMigrationError => ex
|
40
|
+
errors << ex.message
|
75
41
|
end
|
76
|
-
when "all", "full"
|
77
|
-
errors << HealthCheck::Utils.process_checks(HealthCheck.full_checks, called_from_middleware)
|
78
42
|
else
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
43
|
+
database_version = HealthCheck::Utils.get_database_version
|
44
|
+
migration_version = HealthCheck::Utils.get_migration_version
|
45
|
+
errors << "Current database version (#{database_version}) does not match latest migration (#{migration_version}). " if database_version.to_i != migration_version.to_i
|
46
|
+
end
|
47
|
+
when 'cache'
|
48
|
+
errors << HealthCheck::Utils.check_cache
|
49
|
+
when 'resque-redis-if-present'
|
50
|
+
errors << HealthCheck::ResqueHealthCheck.check if defined?(::Resque)
|
51
|
+
when 'sidekiq-redis-if-present'
|
52
|
+
errors << HealthCheck::SidekiqHealthCheck.check if defined?(::Sidekiq)
|
53
|
+
when 'redis-if-present'
|
54
|
+
errors << HealthCheck::RedisHealthCheck.check if defined?(::Redis)
|
55
|
+
when 's3-if-present'
|
56
|
+
errors << HealthCheck::S3HealthCheck.check if defined?(::Aws)
|
57
|
+
when 'resque-redis'
|
58
|
+
errors << HealthCheck::ResqueHealthCheck.check
|
59
|
+
when 'sidekiq-redis'
|
60
|
+
errors << HealthCheck::SidekiqHealthCheck.check
|
61
|
+
when 'redis'
|
62
|
+
errors << HealthCheck::RedisHealthCheck.check
|
63
|
+
when 's3'
|
64
|
+
errors << HealthCheck::S3HealthCheck.check
|
65
|
+
when 'standard'
|
66
|
+
errors << HealthCheck::Utils.process_checks(HealthCheck.standard_checks, called_from_middleware)
|
67
|
+
when 'middleware'
|
68
|
+
errors << 'Health check not called from middleware - probably not installed as middleware.' unless called_from_middleware
|
69
|
+
when 'custom'
|
70
|
+
HealthCheck.custom_checks.each do |_name, list|
|
71
|
+
list.each do |custom_check|
|
72
|
+
errors << custom_check.call(self)
|
85
73
|
end
|
74
|
+
end
|
75
|
+
when 'all', 'full'
|
76
|
+
errors << HealthCheck::Utils.process_checks(HealthCheck.full_checks, called_from_middleware)
|
77
|
+
else
|
78
|
+
if HealthCheck.custom_checks.include? check
|
79
|
+
HealthCheck.custom_checks[check].each do |custom_check|
|
80
|
+
errors << custom_check.call(self)
|
81
|
+
end
|
82
|
+
else
|
83
|
+
return 'invalid argument to health_test.'
|
84
|
+
end
|
86
85
|
end
|
87
86
|
end
|
88
|
-
|
89
|
-
rescue => e
|
90
|
-
|
87
|
+
errors
|
88
|
+
rescue StandardError => e
|
89
|
+
e.message
|
91
90
|
end
|
92
91
|
|
93
92
|
def self.db_migrate_path
|
94
93
|
# Lazy initialisation so Rails.root will be defined
|
95
|
-
@@db_migrate_path ||=
|
94
|
+
@@db_migrate_path ||= Rails.root.join('db', 'migrate')
|
96
95
|
end
|
97
96
|
|
98
97
|
def self.db_migrate_path=(value)
|
@@ -107,10 +106,14 @@ module HealthCheck
|
|
107
106
|
ActiveRecord::Migrator.current_version if defined?(ActiveRecord)
|
108
107
|
end
|
109
108
|
|
110
|
-
def self.get_migration_version(dir =
|
109
|
+
def self.get_migration_version(dir = db_migrate_path)
|
111
110
|
latest_migration = nil
|
112
|
-
Dir[File.join(dir,
|
113
|
-
l =
|
111
|
+
Dir[File.join(dir, '[0-9]*_*.rb')].each do |f|
|
112
|
+
l = begin
|
113
|
+
f.scan(/0*([0-9]+)_[_.a-zA-Z0-9]*.rb/).first.first
|
114
|
+
rescue StandardError
|
115
|
+
-1
|
116
|
+
end
|
114
117
|
latest_migration = l if !latest_migration || l.to_i > latest_migration.to_i
|
115
118
|
end
|
116
119
|
latest_migration
|
@@ -118,12 +121,12 @@ module HealthCheck
|
|
118
121
|
|
119
122
|
def self.check_email
|
120
123
|
case ActionMailer::Base.delivery_method
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
124
|
+
when :smtp
|
125
|
+
HealthCheck::Utils.check_smtp(ActionMailer::Base.smtp_settings, HealthCheck.smtp_timeout)
|
126
|
+
when :sendmail
|
127
|
+
HealthCheck::Utils.check_sendmail(ActionMailer::Base.sendmail_settings)
|
128
|
+
else
|
129
|
+
''
|
127
130
|
end
|
128
131
|
end
|
129
132
|
|
@@ -137,17 +140,13 @@ module HealthCheck
|
|
137
140
|
if @skip_external_checks
|
138
141
|
status = '221'
|
139
142
|
else
|
140
|
-
Timeout
|
143
|
+
Timeout.timeout(timeout) do |_timeout_length|
|
141
144
|
t = TCPSocket.new(settings[:address], settings[:port])
|
142
145
|
begin
|
143
146
|
status = t.gets
|
144
|
-
while status
|
145
|
-
status = t.gets
|
146
|
-
end
|
147
|
+
status = t.gets while !status.nil? && status !~ /^2/
|
147
148
|
t.puts "HELO #{settings[:domain]}\r"
|
148
|
-
while status
|
149
|
-
status = t.gets
|
150
|
-
end
|
149
|
+
status = t.gets while !status.nil? && status !~ /^250/
|
151
150
|
t.puts "QUIT\r"
|
152
151
|
status = t.gets
|
153
152
|
ensure
|
@@ -155,17 +154,16 @@ module HealthCheck
|
|
155
154
|
end
|
156
155
|
end
|
157
156
|
end
|
158
|
-
rescue Errno::EBADF
|
159
|
-
status =
|
157
|
+
rescue Errno::EBADF
|
158
|
+
status = 'Unable to connect to service'
|
160
159
|
rescue Exception => ex
|
161
160
|
status = ex.to_s
|
162
161
|
end
|
163
|
-
(status
|
162
|
+
/^221/.match?(status) ? '' : "SMTP: #{status || 'unexpected EOF on socket'}. "
|
164
163
|
end
|
165
164
|
|
166
165
|
def self.check_cache
|
167
|
-
Rails.cache.write('__health_check_cache_test__', 'ok', :
|
166
|
+
Rails.cache.write('__health_check_cache_test__', 'ok', expires_in: 1.second) ? '' : 'Unable to write to cache. '
|
168
167
|
end
|
169
|
-
|
170
168
|
end
|
171
169
|
end
|
data/lib/health_check/version.rb
CHANGED
data/test/fake_smtp_server
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require 'socket'
|
4
5
|
|
5
6
|
port = 3555
|
6
7
|
|
7
|
-
|
8
8
|
server = TCPServer.new port
|
9
9
|
puts "fake_smtp_server: Waiting for one connection to port #{port} ..."
|
10
10
|
|
@@ -19,20 +19,20 @@ def receive(client)
|
|
19
19
|
line
|
20
20
|
end
|
21
21
|
|
22
|
-
client = server.accept
|
23
|
-
send(client,
|
22
|
+
client = server.accept # Wait for a client to connect
|
23
|
+
send(client, '220 dummy-smtp.example.com SMTP')
|
24
24
|
cmd = receive(client)
|
25
25
|
|
26
26
|
while cmd !~ /^QUIT\r/
|
27
|
-
if
|
28
|
-
send(client,
|
27
|
+
if /^HELO(.*)\r/.match?(cmd)
|
28
|
+
send(client, '250 Welcome to a dummy smtp server')
|
29
29
|
else
|
30
|
-
send(client,
|
30
|
+
send(client, '502 I am so dumb I only understand HELO and QUIT')
|
31
31
|
end
|
32
32
|
cmd = receive(client)
|
33
33
|
end
|
34
|
-
send(client,
|
34
|
+
send(client, '221 Bye Bye')
|
35
35
|
|
36
36
|
client.close
|
37
|
-
puts
|
37
|
+
puts 'fake_smtp_server: Exiting now the conversation has finished.'
|
38
38
|
exit 0
|
data/test/rails_5.1.gemfile
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Gemfile for health_test testing
|
2
4
|
|
3
5
|
source 'https://rubygems.org'
|
@@ -9,18 +11,17 @@ gem 'rake', '>= 0.8.7'
|
|
9
11
|
|
10
12
|
group :development, :test do
|
11
13
|
if defined?(JRUBY_VERSION)
|
12
|
-
gem 'jruby-openssl'
|
13
14
|
gem 'activerecord-jdbcsqlite3-adapter'
|
15
|
+
gem 'jruby-openssl'
|
14
16
|
else
|
15
|
-
gem 'sqlite3',
|
17
|
+
gem 'sqlite3', '~> 1.3.7'
|
16
18
|
end
|
17
19
|
gem 'shoulda'
|
18
|
-
|
20
|
+
|
19
21
|
# redis based checks
|
20
|
-
gem '
|
21
|
-
gem '
|
22
|
-
gem '
|
22
|
+
gem 'redis', require: !ENV['REDIS_URL'].nil?
|
23
|
+
gem 'resque', require: !ENV['RESQUE'].nil?
|
24
|
+
gem 'sidekiq', require: !ENV['SIDEKIQ'].nil?
|
23
25
|
# s3 check
|
24
|
-
gem 'aws-sdk', :
|
26
|
+
gem 'aws-sdk', require: !ENV['AWS_ACCESS_KEY_ID'].nil?
|
25
27
|
end
|
26
|
-
|
data/test/rails_edge.gemfile
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Gemfile for health_test testing
|
2
4
|
|
3
5
|
source 'https://rubygems.org'
|
@@ -6,27 +8,27 @@ source 'https://rubygems.org'
|
|
6
8
|
|
7
9
|
ruby RUBY_VERSION < '2.2.2' ? '2.2.2' : RUBY_VERSION
|
8
10
|
|
11
|
+
gem 'rack'
|
9
12
|
gem 'rails'
|
10
13
|
gem 'rake'
|
11
|
-
gem 'rack'
|
12
14
|
|
13
15
|
group :development, :test do
|
14
16
|
if defined?(JRUBY_VERSION)
|
15
|
-
gem 'jruby-openssl'
|
16
17
|
gem 'activerecord-jdbcsqlite3-adapter'
|
18
|
+
gem 'jruby-openssl'
|
17
19
|
else
|
18
20
|
gem 'sqlite3'
|
19
21
|
end
|
20
22
|
gem 'shoulda'
|
21
|
-
|
23
|
+
|
22
24
|
# redis based checks
|
23
|
-
gem '
|
24
|
-
gem '
|
25
|
-
gem '
|
25
|
+
gem 'redis', require: !ENV['REDIS_URL'].nil?
|
26
|
+
gem 'resque', require: !ENV['RESQUE'].nil?
|
27
|
+
gem 'sidekiq', require: !ENV['SIDEKIQ'].nil?
|
26
28
|
# s3 check
|
27
|
-
gem 'aws-sdk', :
|
29
|
+
gem 'aws-sdk', require: !ENV['AWS_ACCESS_KEY_ID'].nil?
|
28
30
|
end
|
29
31
|
|
30
32
|
# Initial Gemfile has therubyracer commented out
|
31
|
-
gem '
|
32
|
-
gem '
|
33
|
+
gem 'therubyracer', platform: :ruby # REQUIRED
|
34
|
+
gem 'therubyrhino', platform: :jruby # REQUIRED
|
data/test/testurl
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
2
4
|
require 'net/http'
|
3
5
|
require 'uri'
|
4
6
|
|
@@ -10,17 +12,25 @@ def open(url)
|
|
10
12
|
http.request(req)
|
11
13
|
end
|
12
14
|
|
13
|
-
response =
|
15
|
+
response = begin
|
16
|
+
open(ARGV[0])
|
17
|
+
rescue StandardError
|
18
|
+
nil
|
19
|
+
end
|
14
20
|
unless response
|
15
|
-
i=0
|
16
|
-
print
|
17
|
-
while i < 120
|
18
|
-
#puts 'RESPONSE:', response.inspect
|
19
|
-
print
|
21
|
+
i = 0
|
22
|
+
print 'waiting..'
|
23
|
+
while (i < 120) && !response
|
24
|
+
# puts 'RESPONSE:', response.inspect
|
25
|
+
print '.'
|
20
26
|
STDOUT.flush
|
21
27
|
i += 1
|
22
28
|
sleep(1)
|
23
|
-
response =
|
29
|
+
response = begin
|
30
|
+
open(ARGV[0])
|
31
|
+
rescue StandardError
|
32
|
+
nil
|
33
|
+
end
|
24
34
|
end
|
25
35
|
unless response
|
26
36
|
puts "\nFAIL: timed out after waiting #{i} seconds"
|
@@ -32,32 +42,32 @@ end
|
|
32
42
|
page_content = response.body
|
33
43
|
|
34
44
|
puts " response code: #{response.code} #{response.message}"
|
35
|
-
response.header.each_header {|key,value| puts " #{key}: #{value}" }
|
45
|
+
response.header.each_header { |key, value| puts " #{key}: #{value}" }
|
36
46
|
puts " body: #{page_content}"
|
37
47
|
|
38
|
-
if ARGV[1]
|
48
|
+
if ARGV[1] && (ARGV[1] != '')
|
39
49
|
if ARGV[1].split(',').include?(response.code)
|
40
50
|
puts "PASS (response code was #{response.code} which matched #{ARGV[1]})"
|
41
51
|
else
|
42
|
-
puts "FAIL (response code was #{response.code}, expected #{ARGV[1]})"
|
52
|
+
puts "FAIL (response code was #{response.code}, expected #{ARGV[1]})"
|
43
53
|
exit 1
|
44
54
|
end
|
45
55
|
end
|
46
56
|
|
47
|
-
if ARGV[2]
|
57
|
+
if ARGV[2] && (ARGV[2] != '')
|
48
58
|
if response.content_type == ARGV[2]
|
49
59
|
puts "PASS (content type was #{response.content_type})"
|
50
60
|
else
|
51
|
-
puts "FAIL (content type was #{response.content_type}, expected #{ARGV[2]})"
|
61
|
+
puts "FAIL (content type was #{response.content_type}, expected #{ARGV[2]})"
|
52
62
|
exit 2
|
53
63
|
end
|
54
64
|
end
|
55
65
|
|
56
|
-
if ARGV[3]
|
66
|
+
if ARGV[3] && (ARGV[3] != '')
|
57
67
|
if page_content.to_s.include? ARGV[3]
|
58
68
|
puts "PASS (found #{ARGV[3]})"
|
59
69
|
else
|
60
|
-
puts "FAIL (expected to find #{ARGV[3]}) - page contents:"
|
70
|
+
puts "FAIL (expected to find #{ARGV[3]}) - page contents:", page_content.to_s, 'END-OF-CONTENTS'
|
61
71
|
exit 3
|
62
72
|
end
|
63
73
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_health_check
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ian Heggie
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-03-
|
11
|
+
date: 2019-03-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -106,6 +106,7 @@ extra_rdoc_files:
|
|
106
106
|
files:
|
107
107
|
- ".document"
|
108
108
|
- ".gitignore"
|
109
|
+
- ".rubocop.yml"
|
109
110
|
- ".travis.yml"
|
110
111
|
- CHANGELOG
|
111
112
|
- Gemfile
|