health_check 1.2.0 → 1.3.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.
data/.travis.yml CHANGED
@@ -62,12 +62,10 @@ matrix:
62
62
 
63
63
  # rails 4.0 - in development as of 5 mar 2013 - ruby 2.0
64
64
  - rvm: 2.0.0
65
- gemfile: test/rails_4.0-beta.gemfile
65
+ gemfile: test/rails_4.0.gemfile
66
66
  env: RUBYGEMS_VERSION=
67
67
 
68
68
  - rvm: jruby-19mode
69
69
  gemfile: test/rails_3.2.gemfile
70
70
  env: RUBYGEMS_VERSION=1.8.25
71
71
 
72
- allow_failures:
73
- - gemfile: test/rails_4.0-beta.gemfile
data/README.rdoc CHANGED
@@ -9,13 +9,17 @@ health_check provides various monitoring URIs, for example:
9
9
  curl localhost:3000/health_check
10
10
  success
11
11
 
12
- curl localhost:3000/health_check/all
13
- success
12
+ curl localhost:3000/health_check/all.json
13
+ {"healthy":true,"message":"success"}
14
14
 
15
- curl localhost:3000/health_check/database_cache_migration
16
- success
15
+ curl localhost:3000/health_check/database_cache_migration.xml
16
+ <?xml version="1.0" encoding="UTF-8"?>
17
+ <hash>
18
+ <healthy type="boolean">true</healthy>
19
+ <message>success</message>
20
+ </hash>
17
21
 
18
- On failure a 500 http status is returned with a simple explination of the failure
22
+ On failure a 500 http status is returned with a simple explanation of the failure
19
23
 
20
24
  curl localhost:3000/health_check/fail
21
25
  health_check failed: invalid argument to health_test.
@@ -25,18 +29,19 @@ The health_check controller disables sessions and logging for its actions to min
25
29
  == Checks
26
30
 
27
31
  * standard (default) - site, database and migrations checks are run plus email if settings have been changed
28
- * all / full - all checks are run
32
+ * all / full - all checks are run (can be overriden in config block)
29
33
  * database - checks that the current migration level can be read from the database
30
34
  * email - basic check of email - :test returns true, :sendmail checks file is present and executable, :smtp sends HELO command to server and checks response
31
35
  * migration - checks that the database migration level matches that in db/migrations
32
36
  * cache - checks that a value can be written to the cache
33
37
  * site - checks rails is running sufficiently to render text
38
+ * custom - runs checks added via config.add_custom_check
34
39
 
35
40
  The email gateway is not checked unless the smtp settings have been changed.
36
- Specify full or include email in the list of checks to varify the smtp settings
41
+ Specify full or include email in the list of checks to verify the smtp settings
37
42
  (eg use 127.0.0.1 instead of localhost).
38
43
 
39
- Note: rails 4.0 also checks migrations and throws a ActiveRecord::PendingMigrationError (http error 500)
44
+ Note: rails 4.0 also checks migrations and throws an ActiveRecord::PendingMigrationError exception (http error 500) if there is an error
40
45
 
41
46
  == Installation
42
47
 
@@ -81,19 +86,22 @@ To change the configuration of health_check, create a file `config/initializers/
81
86
  config.success = 'success'
82
87
 
83
88
  # Timeout in seconds used when checking smtp server
84
- self.smtp_timeout = 30.0
89
+ config.smtp_timeout = 30.0
85
90
 
86
91
  # http status code used when plain text error message is output
87
92
  # Set to 200 if you want your want to distinguish between partial (text does not include success) and
88
93
  # total failure of rails application (http status of 500 etc)
89
94
 
90
- self.http_status_for_error_text = 500
95
+ config.http_status_for_error_text = 500
91
96
 
92
97
  # http status code used when an error object is output (json or xml)
93
98
  # Set to 200 if you want your want to distinguish between partial (healthy property == false) and
94
99
  # total failure of rails application (http status of 500 etc)
95
100
 
96
- self.http_status_for_error_object = 500
101
+ config.http_status_for_error_object = 500
102
+
103
+ # You can set what tests are run with the 'full' or 'all' parameter
104
+ self.full_checks = ['database', 'migrations', 'custom', 'email', 'cache']
97
105
 
98
106
  # Add one or more custom checks that return a blank string if ok, or an error message if there is an error
99
107
  config.add_custom_check do
@@ -104,6 +112,9 @@ To change the configuration of health_check, create a file `config/initializers/
104
112
 
105
113
  You may call add_custom_check multiple times with different tests. These tests will be included in the default list ("standard").
106
114
 
115
+ If you have a catchall route in a rails 3.0 or later application then add the following line above the catch all route (in `config/routes.rb`):
116
+ health_check_routes
117
+
107
118
  == Uptime Monitoring
108
119
 
109
120
  Use a website monitoring service to check the url regularly for the word "success" (without the quotes) rather than just a 200 http status so
@@ -175,11 +186,13 @@ See https://github.com/ianheggie/health_check/wiki/Ajax-Example for an Ajax exam
175
186
 
176
187
  == Testing
177
188
 
178
- === Automated testing
189
+ === Automated testing and other checks
179
190
 
180
- See Travis CI testing result: {<img src="https://travis-ci.org/ianheggie/health_check.png">}[https://travis-ci.org/ianheggie/health_check]
191
+ Travis CI runs the tests: {<img src="https://travis-ci.org/ianheggie/health_check.png">}[https://travis-ci.org/ianheggie/health_check]
181
192
 
182
- Code Climate also monitors this project for code quality: {<img src="https://codeclimate.com/github/ianheggie/health_check.png" />}[https://codeclimate.com/github/ianheggie/health_check]
193
+ Code Climate monitors code quality: {<img src="https://codeclimate.com/github/ianheggie/health_check.png" />}[https://codeclimate.com/github/ianheggie/health_check]
194
+
195
+ Gemnasium monitors gem dependencies {<img src="https://gemnasium.com/ianheggie/health_check.png">}[https://gemnasium.com/ianheggie/health_check]
183
196
 
184
197
  === Manual testing
185
198
 
@@ -219,3 +232,7 @@ The command `rake test` will also launch these tests, except it cannot install t
219
232
  Copyright (c) 2010-2013 Ian Heggie, released under the MIT license.
220
233
  See MIT-LICENSE for details.
221
234
 
235
+ == Contributors
236
+
237
+ Thanks go to the various people who have given feedback and suggestions via the issues list and pull requests
238
+
data/config/routes.rb CHANGED
@@ -1,8 +1,5 @@
1
1
  if defined?(HealthCheck::Engine)
2
2
  Rails.application.routes.draw do
3
- get 'health_check', :to => 'health_check/health_check#index'
4
- get 'health_check.:format', :to => 'health_check/health_check#index'
5
- get 'health_check/:checks', :to => 'health_check/health_check#index'
6
- get 'health_check/:checks.:format', :to => 'health_check/health_check#index'
3
+ health_check_routes
7
4
  end
8
5
  end
data/health_check.gemspec CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |gem|
13
13
  gem.description = <<-EOF
14
14
  Simple health check of Rails app for uptime monitoring with Pingdom, NewRelic, EngineYard or uptime.openacs.org etc.
15
15
  EOF
16
- gem.homepage = "https://github.com/ianheggie/health_check"
16
+ gem.homepage = "http://ianheggie.github.io/health_check/"
17
17
 
18
18
  gem.files = `git ls-files`.split($/)
19
19
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
data/lib/health_check.rb CHANGED
@@ -5,6 +5,7 @@ module HealthCheck
5
5
 
6
6
  if Rails.version >= '3.0'
7
7
  class Engine < Rails::Engine
8
+ cattr_accessor :routes_defined
8
9
  end
9
10
  end
10
11
 
@@ -26,12 +27,14 @@ module HealthCheck
26
27
 
27
28
  # Array of custom check blocks
28
29
  mattr_accessor :custom_checks
30
+ mattr_accessor :full_checks
29
31
  self.custom_checks = [ ]
32
+ self.full_checks = ['database', 'migrations', 'custom', 'email', 'cache']
30
33
 
31
34
  def self.add_custom_check(&block)
32
35
  custom_checks << block
33
36
  end
34
-
37
+
35
38
  def self.setup
36
39
  yield self
37
40
  end
@@ -42,7 +45,9 @@ require "health_check/version"
42
45
  require 'health_check/utils'
43
46
  require 'health_check/health_check_controller'
44
47
 
45
- unless defined?(HealthCheck::Engine)
48
+ if defined?(HealthCheck::Engine)
49
+ require 'health_check/health_check_routes'
50
+ else
46
51
  require 'health_check/add_23_routes'
47
52
  end
48
53
 
@@ -0,0 +1,17 @@
1
+ if defined?(HealthCheck::Engine)
2
+
3
+ module ActionDispatch::Routing
4
+ class Mapper
5
+ def health_check_routes
6
+ unless HealthCheck::Engine.routes_defined
7
+ HealthCheck::Engine.routes_defined = true
8
+ get 'health_check', :to => 'health_check/health_check#index'
9
+ get 'health_check.:format', :to => 'health_check/health_check#index'
10
+ get 'health_check/:checks', :to => 'health_check/health_check#index'
11
+ get 'health_check/:checks.:format', :to => 'health_check/health_check#index'
12
+ end
13
+ end
14
+ end
15
+ end
16
+
17
+ end
@@ -44,7 +44,7 @@ module HealthCheck
44
44
  errors << custom_check.call(self)
45
45
  end
46
46
  when "all", "full"
47
- errors << HealthCheck::Utils.process_checks("database_migrations_custom_email_cache")
47
+ errors << HealthCheck::Utils.process_checks(HealthCheck.full_checks.join('_'))
48
48
  else
49
49
  return "invalid argument to health_test. "
50
50
  end
@@ -67,13 +67,13 @@ module HealthCheck
67
67
  end
68
68
 
69
69
  def self.get_database_version
70
- ActiveRecord::Migrator.current_version
70
+ ActiveRecord::Migrator.current_version if defined?(ActiveRecord)
71
71
  end
72
72
 
73
73
  def self.get_migration_version(dir = self.db_migrate_path)
74
74
  latest_migration = nil
75
75
  Dir[File.join(dir, "[0-9]*_*.rb")].each do |f|
76
- l = f.scan(/0*([0-9]+)_[_a-zA-Z0-9]*.rb/).first.first
76
+ l = f.scan(/0*([0-9]+)_[_.a-zA-Z0-9]*.rb/).first.first rescue -1
77
77
  latest_migration = l if !latest_migration || l.to_i > latest_migration.to_i
78
78
  end
79
79
  latest_migration
@@ -1,4 +1,4 @@
1
1
  module HealthCheck
2
- VERSION = "1.2.0"
2
+ VERSION = "1.3.1"
3
3
  end
4
4
 
@@ -0,0 +1,11 @@
1
+ class CreateRoles < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :roles do |t|
4
+ t.column :name, :string
5
+ end
6
+ end
7
+
8
+ def self.down
9
+ drop_table :roles
10
+ end
11
+ end
@@ -6,7 +6,7 @@ source 'https://rubygems.org'
6
6
 
7
7
  ruby "1.9.3" if RUBY_VERSION < '1.9'
8
8
 
9
- gem 'rails', "~> 4.0.0.beta1"
9
+ gem 'rails', "~> 4.0.0"
10
10
  gem 'rake', '>= 0.8.3'
11
11
  gem "rack", '~> 1.5.2'
12
12
 
data/test/setup_railsapp CHANGED
@@ -227,12 +227,12 @@ cat > public/ajax_example.html <<'EOF'
227
227
  <ul>
228
228
  <li><a href="#" onclick="dynamic_call('text', 'http://localhost:3000/health_check/site');">Minimal health check should always work</a>
229
229
  (<a href="#" onclick="dynamic_call('json', 'http://localhost:3000/health_check/site.json');">json</a>,
230
- <a href="#" onclick="dynamic_call('site', 'http://localhost:3000/health_check/site.xml');">xml</a>,
230
+ <a href="#" onclick="dynamic_call('xml', 'http://localhost:3000/health_check/site.xml');">xml</a>,
231
231
  <a href="#" onclick="dynamic_call('text', 'http://localhost:3000/health_check/site.html');">html</a>)
232
232
 
233
233
  <li><a href="#" onclick="dynamic_call('text', 'http://localhost:3000/health_check/fail');">Force health check to fail!</a>
234
234
  (<a href="#" onclick="dynamic_call('json', 'http://localhost:3000/health_check/fail.json');">json</a>,
235
- <a href="#" onclick="dynamic_call('site', 'http://localhost:3000/health_check/fail.xml');">xml</a>,
235
+ <a href="#" onclick="dynamic_call('xml', 'http://localhost:3000/health_check/fail.xml');">xml</a>,
236
236
  <a href="#" onclick="dynamic_call('text', 'http://localhost:3000/health_check/fail.html');">html</a>)
237
237
  <li>Last results sent to success:<ul>
238
238
  <li><b>Data:</b><span id=data_success></span>
@@ -129,6 +129,13 @@ echo
129
129
 
130
130
  echo 'TESTING health_check/migration should fail without all migrations ...'
131
131
  cp $base_dir/test/migrate/twelve/* db/migrate
132
+
133
+ case "$actual_rails_version" in
134
+ *' '[12].*|*' '3.[01]*)
135
+ echo removing db/migrate/*.*.rb "($actual_rails_version does not support extra dots in migration names)"
136
+ rm -f db/migrate/*.*.rb
137
+ ;;
138
+ esac
132
139
  ls db/migrate
133
140
  $testurl ${host}/health_check/migration 550 text/plain failed
134
141
  echo
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: health_check
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 2
9
- - 0
10
- version: 1.2.0
8
+ - 3
9
+ - 1
10
+ version: 1.3.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ian Heggie
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-03-06 00:00:00 +11:00
18
+ date: 2013-09-25 00:00:00 +10:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -122,19 +122,21 @@ files:
122
122
  - lib/health_check.rb
123
123
  - lib/health_check/add_23_routes.rb
124
124
  - lib/health_check/health_check_controller.rb
125
+ - lib/health_check/health_check_routes.rb
125
126
  - lib/health_check/utils.rb
126
127
  - lib/health_check/version.rb
127
128
  - test/fake_smtp_server
128
129
  - test/init_variables
129
130
  - test/migrate/empty/do_not_remove.txt
130
131
  - test/migrate/nine/9_create_countries.rb
132
+ - test/migrate/twelve/011_create_roles.roles.rb
131
133
  - test/migrate/twelve/012_create_users.rb
132
134
  - test/migrate/twelve/9_create_countries.rb
133
135
  - test/rails_2.3.gemfile
134
136
  - test/rails_3.0.gemfile
135
137
  - test/rails_3.1.gemfile
136
138
  - test/rails_3.2.gemfile
137
- - test/rails_4.0-beta.gemfile
139
+ - test/rails_4.0.gemfile
138
140
  - test/setup_railsapp
139
141
  - test/test_helper.rb
140
142
  - test/test_with_railsapp
@@ -142,7 +144,7 @@ files:
142
144
  - test/unit/health_check_controller_test.rb
143
145
  - test/unit/routes_test.rb
144
146
  has_rdoc: true
145
- homepage: https://github.com/ianheggie/health_check
147
+ homepage: http://ianheggie.github.io/health_check/
146
148
  licenses: []
147
149
 
148
150
  post_install_message:
@@ -180,13 +182,14 @@ test_files:
180
182
  - test/init_variables
181
183
  - test/migrate/empty/do_not_remove.txt
182
184
  - test/migrate/nine/9_create_countries.rb
185
+ - test/migrate/twelve/011_create_roles.roles.rb
183
186
  - test/migrate/twelve/012_create_users.rb
184
187
  - test/migrate/twelve/9_create_countries.rb
185
188
  - test/rails_2.3.gemfile
186
189
  - test/rails_3.0.gemfile
187
190
  - test/rails_3.1.gemfile
188
191
  - test/rails_3.2.gemfile
189
- - test/rails_4.0-beta.gemfile
192
+ - test/rails_4.0.gemfile
190
193
  - test/setup_railsapp
191
194
  - test/test_helper.rb
192
195
  - test/test_with_railsapp