health_check 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Ian Heggie
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,79 @@
1
+ = health_check
2
+
3
+ Simple health check of Rails app for use with uptime.openacs.org or wasitup.com
4
+
5
+ The basic goal is to check that rails is being launched and that it has access to correctly configured resources (database, email gateway)
6
+
7
+ The email gateway is not checked unless the smtp settings have been changed,
8
+ specify full or include email in the list of checks or varify the smtp settings
9
+ (eg use 127.0.0.1 instead of localhost).
10
+
11
+ health_check provides various monitoring URIs
12
+
13
+ % curl localhost:3000/health_check
14
+ success
15
+
16
+ % curl localhost:3000/health_check/standard
17
+ success
18
+
19
+ % curl localhost:3000/health_check/all
20
+ success
21
+
22
+ % curl localhost:3000/health_check/site_and_database_and_email_migrations
23
+ success
24
+
25
+ == Installation
26
+
27
+ As a Plugin
28
+
29
+ % cd vendor/plugins
30
+ % git clone git://github.com/ianheggie/health_check.git
31
+
32
+ As a Gem from gemcutter
33
+
34
+ % gem install health_check
35
+ # Add the following line to config/environment.rb
36
+ config.gem "health_check"
37
+
38
+ == Uptime Monitoring
39
+
40
+ See
41
+ * [WasItUp](http://wasitup.com/)
42
+ * [Uptime by OpenACS](http://uptime.openacs.org/uptime/)
43
+ * [Engine Yard's guide](http://community-support.engineyard.com/faqs/guides/uptime-monitoring-for-your-rails-application) guide based on fitter_happier plugin includes monit and other setup help
44
+
45
+ == Checks
46
+
47
+ * standard (default) - site, database and migrations checks are run plus email if settings have been changed
48
+ * all / full - all checks are run
49
+ * database - checks that the database contains the current migration level
50
+ * email - basic check of email - :test returns true, :sendmail checks file is present and executable, :smtp sends HELO command to server and checks response
51
+ * migration - checks that the database migration level matches that in db/migrations
52
+ * site - checks rails is running sufficiently to render text
53
+
54
+ == Note on Patches/Pull Requests
55
+
56
+ * Fork the project.
57
+ * Make your feature addition or bug fix.
58
+ * Add tests for it. This is important so I don't break it in a
59
+ future version unintentionally.
60
+ * Commit, do not mess with rakefile, version, or history.
61
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
62
+ * Send me a pull request. Bonus points for topic branches.
63
+
64
+ == Copyright
65
+
66
+ Copyright (c) 2010 Ian Heggie, released under the MIT license.
67
+ See MIT-LICENSE for details.
68
+
69
+ == Known Issues
70
+
71
+ * Rails 1.x s not currently supported (smtp_settings versus server_settings)
72
+ * I wasn't able to get tests to work standalone - the gem has to be installed as a plugin for the tests to work
73
+ * No inline documentation for methods
74
+
75
+ * Feedback welcome especially with suggested replacement code and corresponding tests
76
+
77
+ == Similar projects
78
+
79
+ * fitter_happier plugin by atmos - plugin with similar goals, but not compatible with uptime, and does not check email gateway
data/Rakefile ADDED
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "health_check"
8
+ gem.summary = %Q{Simple health check of Rails app}
9
+ gem.description = %Q{Simple health check of Rails app for use with uptime.openacs.org or wasitup.com}
10
+ gem.email = "ian@heggie.biz"
11
+ gem.homepage = "http://github.com/ianheggie/health_check"
12
+ gem.authors = ["Ian Heggie"]
13
+ gem.add_development_dependency "shoulda", ">= 0"
14
+ gem.add_development_dependency "sqlite3-ruby", ">= 0"
15
+ gem.add_development_dependency 'activerecord', '>= 1.15.4.7794'
16
+
17
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18
+ end
19
+ Jeweler::GemcutterTasks.new
20
+ rescue LoadError
21
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
22
+ end
23
+
24
+ require 'rake/testtask'
25
+ Rake::TestTask.new(:test) do |test|
26
+ test.libs << 'lib' << 'test'
27
+ test.pattern = 'test/**/test_*.rb'
28
+ test.verbose = true
29
+ end
30
+
31
+ begin
32
+ require 'rcov/rcovtask'
33
+ Rcov::RcovTask.new do |test|
34
+ test.libs << 'test'
35
+ test.pattern = 'test/**/test_*.rb'
36
+ test.verbose = true
37
+ end
38
+ rescue LoadError
39
+ task :rcov do
40
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
41
+ end
42
+ end
43
+
44
+ task :test => :check_dependencies
45
+
46
+ task :default => :test
47
+
48
+ require 'rake/rdoctask'
49
+ Rake::RDocTask.new do |rdoc|
50
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
51
+
52
+ rdoc.rdoc_dir = 'rdoc'
53
+ rdoc.title = "health_check #{version}"
54
+ rdoc.rdoc_files.include('README*')
55
+ rdoc.rdoc_files.include('lib/**/*.rb')
56
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,70 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{health_check}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Ian Heggie"]
12
+ s.date = %q{2010-01-29}
13
+ s.description = %q{Simple health check of Rails app for use with uptime.openacs.org or wasitup.com}
14
+ s.email = %q{ian@heggie.biz}
15
+ s.extra_rdoc_files = [
16
+ "README.rdoc"
17
+ ]
18
+ s.files = [
19
+ ".document",
20
+ ".gitignore",
21
+ "MIT-LICENSE",
22
+ "README.rdoc",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "health_check.gemspec",
26
+ "init.rb",
27
+ "lib/health_check.rb",
28
+ "lib/health_check/add_routes.rb",
29
+ "lib/health_check/health_check_class.rb",
30
+ "lib/health_check/health_check_controller.rb",
31
+ "test/helper.rb",
32
+ "test/migrate/empty/do_not_remove.txt",
33
+ "test/migrate/twelve/012_create_users.rb",
34
+ "test/migrate/twelve/9_create_countries.rb",
35
+ "test/test_health_check_controller.rb",
36
+ "test/test_routes.rb"
37
+ ]
38
+ s.homepage = %q{http://github.com/ianheggie/health_check}
39
+ s.rdoc_options = ["--charset=UTF-8"]
40
+ s.require_paths = ["lib"]
41
+ s.rubygems_version = %q{1.3.5}
42
+ s.summary = %q{Simple health check of Rails app}
43
+ s.test_files = [
44
+ "test/helper.rb",
45
+ "test/migrate/twelve/012_create_users.rb",
46
+ "test/migrate/twelve/9_create_countries.rb",
47
+ "test/test_health_check_controller.rb",
48
+ "test/test_routes.rb"
49
+ ]
50
+
51
+ if s.respond_to? :specification_version then
52
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
53
+ s.specification_version = 3
54
+
55
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
56
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
57
+ s.add_development_dependency(%q<sqlite3-ruby>, [">= 0"])
58
+ s.add_development_dependency(%q<activerecord>, [">= 1.15.4.7794"])
59
+ else
60
+ s.add_dependency(%q<shoulda>, [">= 0"])
61
+ s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
62
+ s.add_dependency(%q<activerecord>, [">= 1.15.4.7794"])
63
+ end
64
+ else
65
+ s.add_dependency(%q<shoulda>, [">= 0"])
66
+ s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
67
+ s.add_dependency(%q<activerecord>, [">= 1.15.4.7794"])
68
+ end
69
+ end
70
+
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'health_check'
@@ -0,0 +1,17 @@
1
+ module ActionController
2
+ module Routing #:nodoc:
3
+ class RouteSet #:nodoc:
4
+ alias_method :draw_without_health_check_routes, :draw
5
+ def draw
6
+ draw_without_health_check_routes do |map|
7
+ map.connect 'health_check',
8
+ :controller => 'health_check', :action => 'index'
9
+ map.connect 'health_check/:checks',
10
+ :controller => 'health_check', :action => 'check'
11
+ yield map
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+
@@ -0,0 +1,99 @@
1
+ class HealthCheck
2
+
3
+ @@success = "success"
4
+
5
+ cattr_accessor :success
6
+
7
+ @@smtp_timeout = 30.0
8
+
9
+ cattr_accessor :smtp_timeout
10
+
11
+ @@default_smtp_settings =
12
+ {
13
+ :address => "localhost",
14
+ :port => 25,
15
+ :domain => 'localhost.localdomain',
16
+ :user_name => nil,
17
+ :password => nil,
18
+ :authentication => nil,
19
+ :enable_starttls_auto => true,
20
+ }
21
+
22
+ cattr_accessor :default_smtp_settings
23
+
24
+ def self.db_migrate_path
25
+ # Lazy initialisation so RAILS_ROOT will be defined
26
+ @@db_migrate_path ||= File.join(RAILS_ROOT, 'db', 'migrate')
27
+ end
28
+
29
+ def self.db_migrate_path=(value)
30
+ @@db_migrate_path = value
31
+ end
32
+
33
+ def self.default_action_mailer_configuration?
34
+ ActionMailer::Base.delivery_method == :smtp && HealthCheck.default_smtp_settings == ActionMailer::Base.smtp_settings
35
+ end
36
+
37
+ def self.get_database_version
38
+ ActiveRecord::Migrator.current_version
39
+ end
40
+
41
+ def self.get_migration_version(dir = self.db_migrate_path)
42
+ latest_migration = nil
43
+ Dir[File.join(dir, "[0-9]*_*.rb")].each do |f|
44
+ l = f.scan(/0*([0-9]+)_[_a-zA-Z0-9]*.rb/).first.first
45
+ latest_migration = l if !latest_migration || l.to_i > latest_migration.to_i
46
+ end
47
+ latest_migration
48
+ end
49
+
50
+ def self.check_email
51
+ case ActionMailer::Base.delivery_method
52
+ when :smtp
53
+ HealthCheck.check_smtp(ActionMailer::Base.smtp_settings, HealthCheck.smtp_timeout)
54
+ when :sendmail
55
+ HealthCheck.check_sendmail(ActionMailer::Base.sendmail_settings)
56
+ else
57
+ ''
58
+ end
59
+ end
60
+
61
+
62
+ def self.check_sendmail(settings)
63
+ File.executable?(settings[:location]) ? '' : 'no sendmail executable found. '
64
+ end
65
+
66
+ def self.check_smtp(settings, timeout)
67
+ status = ''
68
+ begin
69
+ if @skip_external_checks
70
+ status = '221'
71
+ else
72
+ Timeout::timeout(timeout) do |timeout_length|
73
+ t = TCPSocket.new(settings[:address], settings[:port])
74
+ begin
75
+ status = t.gets
76
+ while status != nil && status !~ /^2/
77
+ status = t.gets
78
+ end
79
+ t.puts "HELO #{settings[:domain]}"
80
+ while status != nil && status !~ /^250/
81
+ status = t.gets
82
+ end
83
+ t.puts "QUIT"
84
+ status = t.gets
85
+ ensure
86
+ t.close
87
+ end
88
+ end
89
+ end
90
+ rescue Errno::EBADF => ex
91
+ status = "Unable to connect to service"
92
+ rescue Exception => ex
93
+ status = ex.to_s
94
+ end
95
+ (status =~ /^221/) ? '' : "SMTP: #{status || 'unexpected EOF on socket'}. "
96
+ end
97
+
98
+
99
+ end
@@ -0,0 +1,70 @@
1
+ class HealthCheckController < ActionController::Base
2
+ session(:off) if Rails::VERSION::STRING < '2.3'
3
+ layout nil
4
+
5
+ def index
6
+ do_check('standard')
7
+ end
8
+
9
+ def check
10
+ do_check(params[:checks])
11
+ end
12
+
13
+ private
14
+
15
+ def do_check(checks)
16
+ begin
17
+ errors = process_checks(checks)
18
+ rescue Exception => e
19
+ errors = e.message
20
+ end
21
+ if errors.blank?
22
+ render :text => HealthCheck.success, :content_type => 'text/plain'
23
+ else
24
+ msg = "health_check failed: #{errors}"
25
+ render :text => msg, :status => 500, :content_type => 'text/plain'
26
+ # Log a single line as some uptime checkers only record that it failed, not the text returned
27
+ silence_level, logger.level = logger.level, @old_logger_level
28
+ logger.info msg
29
+ logger.level = silence_level
30
+ end
31
+ end
32
+
33
+ def process_checks(checks)
34
+ errors = ''
35
+ checks.split('_').each do |check|
36
+ case check
37
+ when 'and', 'site'
38
+ # do nothing
39
+ when "database"
40
+ HealthCheck.get_database_version
41
+ when "email"
42
+ errors << HealthCheck.check_email
43
+ when "migrations", "migration"
44
+ database_version = HealthCheck.get_database_version
45
+ migration_version = HealthCheck.get_migration_version
46
+ if database_version.to_i != migration_version.to_i
47
+ errors << "Current database version (#{database_version}) does not match latest migration (#{migration_version}). "
48
+ end
49
+ when "standard"
50
+ errors << process_checks("database_migrations")
51
+ errors << process_checks("email") unless HealthCheck.default_action_mailer_configuration?
52
+ when "all", "full"
53
+ errors << process_checks("database_migrations_email")
54
+ else
55
+ return "invalid argument to health_test. "
56
+ end
57
+ end
58
+ return errors
59
+ end
60
+
61
+
62
+ def process_with_silence(*args)
63
+ @old_logger_level = logger.level
64
+ logger.silence do
65
+ process_without_silence(*args)
66
+ end
67
+ end
68
+
69
+ alias_method_chain :process, :silence
70
+ end
@@ -0,0 +1,3 @@
1
+ require 'health_check/health_check_class'
2
+ require 'health_check/health_check_controller'
3
+ require 'health_check/add_routes'
data/test/helper.rb ADDED
@@ -0,0 +1,88 @@
1
+ ENV['RAILS_ENV'] = 'test'
2
+
3
+ require 'test/unit'
4
+ require 'rubygems'
5
+
6
+ # Tests are conducted with health_test as a plugin
7
+ environment_file = File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'config', 'environment.rb')
8
+ if File.exists?(environment_file)
9
+ # test as plugin
10
+ require environment_file
11
+ else
12
+ #tests as gem
13
+ fail "TODO: Work out how to test as a gem (test as a plugin instead)"
14
+ # TODO: Work out how to do this!
15
+ #require 'rails/version'
16
+ #RAILS_ROOT = "test" unless defined?(RAILS_ROOT)
17
+ #module Rails
18
+ # def backtrace_cleaner(args)
19
+ # # do nothing
20
+ # end
21
+ #end
22
+
23
+ #require 'active_support'
24
+ #require 'action_controller'
25
+ #require 'action_controller/base'
26
+ ##require 'action_controller/test_case'
27
+ #require 'action_view'
28
+ #require 'active_record'
29
+ ##require 'active_support/backtrace_cleaner'
30
+ ##require 'rails/backtrace_cleaner'
31
+
32
+ #require 'test_help'
33
+ end
34
+
35
+
36
+ gem "shoulda"
37
+ require 'shoulda'
38
+ require 'shoulda/action_controller'
39
+
40
+ # rails test help
41
+
42
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
43
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
44
+
45
+ # gem init
46
+ #require 'health_check'
47
+
48
+ # plugin init
49
+ require File.join(File.dirname(__FILE__), '..', 'init')
50
+
51
+ ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :dbfile => ":memory:")
52
+
53
+ EXAMPLE_SMTP_SETTINGS = {
54
+ :address => "smtp.gmail.com",
55
+ :domain => "test.example.com",
56
+ :port => 587
57
+ }
58
+
59
+ ActionMailer::Base.delivery_method = :test
60
+
61
+ # Make sure sendmail settings are set to something that is executrable (we wont actually execute it)
62
+ sendmail_path = '/usr/sbin/sendmail'
63
+ ['/bin/true', 'c:/windows/explorer.exe', 'c:/winnt/explorer.exe',
64
+ File.join(RAILS_ROOT, 'script', 'about')].each do |f|
65
+ sendmail_path = f if File.executable? f
66
+ end
67
+
68
+ EXAMPLE_SENDMAIL_SETTINGS = {
69
+ :location => sendmail_path,
70
+ :arguments => '--help'
71
+ }
72
+
73
+ def setup_db(version)
74
+ ActiveRecord::Base.connection.initialize_schema_migrations_table
75
+ ActiveRecord::Schema.define(:version => version) do
76
+ create_table :kitchen do |t|
77
+ t.column :owner, :string
78
+ t.column :description, :string
79
+ end
80
+ end if version
81
+ end
82
+
83
+ def teardown_db
84
+ ActiveRecord::Base.connection.tables.each do |table|
85
+ ActiveRecord::Base.connection.drop_table(table)
86
+ end
87
+ end
88
+
@@ -0,0 +1 @@
1
+ Don't remove
@@ -0,0 +1,10 @@
1
+ class CreateUsers < ActiveRecord::Migration
2
+ def self.up
3
+ create_table "users", :force => true do |t|
4
+ t.column :name, :string
5
+ end
6
+
7
+ def self.down
8
+ drop_table :users
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ class CreateCountries < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :countries do |t|
4
+ t.column :name, :string
5
+ end
6
+ end
7
+
8
+ def self.down
9
+ drop_table :countries
10
+ end
11
+ end
@@ -0,0 +1,175 @@
1
+ require 'helper'
2
+
3
+ class HealthCheckControllerTest < ActionController::TestCase
4
+ #context "HealthCheck plugin" do
5
+ # should_route :get, "/health_check", :controller => :health_check, :action => :index
6
+ # should_route :get, "/health_check/two_checks", :controller => :health_check, :action => :index, :checks => 'two_checks'
7
+ #end
8
+
9
+ context "GET standard on empty db" do
10
+ setup do
11
+ HealthCheck.db_migrate_path = File.join(File.dirname(__FILE__), 'migrate', 'empty')
12
+ setup_db(nil)
13
+ ActionMailer::Base.delivery_method = :test
14
+ get :index
15
+ end
16
+
17
+ teardown do
18
+ teardown_db
19
+ end
20
+
21
+ should_respond_with :success
22
+ should_not_set_the_flash
23
+ should_respond_with_content_type 'text/plain'
24
+ should_render_without_layout
25
+ should "return 'success' text" do
26
+ assert_equal HealthCheck.success, @response.body
27
+ end
28
+ end
29
+
30
+ context "GET migrations on db with migrations" do
31
+ setup do
32
+ HealthCheck.db_migrate_path = File.join(File.dirname(__FILE__), 'migrate', 'twelve')
33
+ setup_db(12)
34
+ ActionMailer::Base.delivery_method = :test
35
+ get :check, :checks => 'migrations'
36
+ end
37
+
38
+ teardown do
39
+ teardown_db
40
+ end
41
+
42
+ should_respond_with :success
43
+ should_not_set_the_flash
44
+ should_respond_with_content_type 'text/plain'
45
+ should_render_without_layout
46
+ should "return 'success' text" do
47
+ assert_equal HealthCheck.success, @response.body
48
+ end
49
+ end
50
+
51
+ context "GET standard with unactioned migrations" do
52
+ setup do
53
+ HealthCheck.db_migrate_path = File.join(File.dirname(__FILE__), 'migrate', 'twelve')
54
+ setup_db(nil)
55
+ ActionMailer::Base.delivery_method = :test
56
+ get :index
57
+ end
58
+
59
+ teardown do
60
+ teardown_db
61
+ end
62
+
63
+ should_respond_with 500
64
+ should_not_set_the_flash
65
+ should_respond_with_content_type 'text/plain'
66
+ should_render_without_layout
67
+ should "not return 'success' text" do
68
+ assert_not_equal HealthCheck.success, @response.body
69
+ end
70
+ end
71
+
72
+ context "GET email with :test" do
73
+ setup do
74
+ ActionMailer::Base.delivery_method = :test
75
+ get :check, :checks => 'email'
76
+ end
77
+
78
+ should_respond_with :success
79
+ should_not_set_the_flash
80
+ should_respond_with_content_type 'text/plain'
81
+ should_render_without_layout
82
+ should "return 'success' text" do
83
+ assert_equal HealthCheck.success, @response.body
84
+ end
85
+ end
86
+
87
+ context "GET standard with bad smtp" do
88
+ setup do
89
+ HealthCheck.db_migrate_path = File.join(File.dirname(__FILE__), 'migrate', 'twelve')
90
+ setup_db(12)
91
+ HealthCheck.smtp_timeout = 2.0
92
+ ActionMailer::Base.delivery_method = :smtp
93
+ ActionMailer::Base.smtp_settings = {
94
+ :address => "127.0.0.1",
95
+ :domain => "testing.example.com",
96
+ :port => 7
97
+ }
98
+ get :index
99
+ end
100
+
101
+ teardown do
102
+ teardown_db
103
+ end
104
+
105
+ should_respond_with 500
106
+ should_not_set_the_flash
107
+ should_respond_with_content_type 'text/plain'
108
+ should_render_without_layout
109
+ should "not return 'success' text" do
110
+ assert_not_equal HealthCheck.success, @response.body
111
+ end
112
+ end
113
+
114
+
115
+ context "GET email with :smtp" do
116
+ setup do
117
+ # it should not care that the database isnt setup correctly
118
+ HealthCheck.db_migrate_path = File.join(File.dirname(__FILE__), 'migrate', 'empty')
119
+ setup_db(nil)
120
+ ActionMailer::Base.delivery_method = :smtp
121
+ HealthCheck.smtp_timeout = 60.0
122
+ ActionMailer::Base.smtp_settings = EXAMPLE_SMTP_SETTINGS
123
+ get :check, :checks => 'email'
124
+ end
125
+
126
+ should_respond_with :success
127
+ should_respond_with_content_type 'text/plain'
128
+ should "return 'success' text" do
129
+ assert_equal HealthCheck.success, @response.body
130
+ end
131
+ end
132
+
133
+
134
+ context "GET database_migration_email with missing sendmail" do
135
+ setup do
136
+ HealthCheck.db_migrate_path = File.join(File.dirname(__FILE__), 'migrate', 'twelve')
137
+ setup_db(12)
138
+ ActionMailer::Base.delivery_method = :sendmail
139
+ ActionMailer::Base.sendmail_settings = { :location => '/no/such/executable', :arguments => '' }
140
+ get :check, :checks => 'database_migration_email'
141
+ end
142
+
143
+ teardown do
144
+ teardown_db
145
+ end
146
+
147
+ should_respond_with 500
148
+ should_not_set_the_flash
149
+ should_respond_with_content_type 'text/plain'
150
+ should_render_without_layout
151
+ should "not return 'success' text" do
152
+ assert_not_equal HealthCheck.success, @response.body
153
+ end
154
+ end
155
+
156
+ context "GET all with :sendmail" do
157
+ setup do
158
+ ActionMailer::Base.delivery_method = :sendmail
159
+ ActionMailer::Base.sendmail_settings = EXAMPLE_SENDMAIL_SETTINGS
160
+ HealthCheck.db_migrate_path = File.join(File.dirname(__FILE__), 'migrate', 'empty')
161
+ setup_db(nil)
162
+ get :check, :checks => 'all'
163
+ end
164
+
165
+ teardown do
166
+ teardown_db
167
+ end
168
+
169
+ should_respond_with :success
170
+ should_respond_with_content_type 'text/plain'
171
+ should "return 'success' text" do
172
+ assert_equal HealthCheck.success, @response.body
173
+ end
174
+ end
175
+ end
@@ -0,0 +1,32 @@
1
+ require 'helper'
2
+
3
+ class RoutingTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ ActionController::Routing::Routes.draw do |map|
7
+ # do nothing - routes should be added automatically
8
+ end
9
+ end
10
+
11
+ def test_health_check_plain_route
12
+ assert_recognition :get, "/health_check", :controller => "health_check", :action => "index"
13
+ end
14
+
15
+ def test_health_check_checks_specified_route
16
+ assert_recognition :get, "/health_check/two_checks", :controller => "health_check", :action => "check", :checks => 'two_checks'
17
+ end
18
+
19
+ private
20
+
21
+ # yes, I know about assert_recognizes, but it has proven problematic to
22
+ # use in these tests, since it uses RouteSet#recognize (which actually
23
+ # tries to instantiate the controller) and because it uses an awkward
24
+ # parameter order.
25
+ def assert_recognition(method, path, options)
26
+ result = ActionController::Routing::Routes.recognize_path(path, :method => method)
27
+ assert_equal options, result
28
+ end
29
+
30
+ # with Thanks to http://izumi.plan99.net/manuals/creating_plugins-8f53e4d6.html
31
+
32
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: health_check
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ian Heggie
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-29 00:00:00 +11:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: shoulda
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: sqlite3-ruby
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: activerecord
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 1.15.4.7794
44
+ version:
45
+ description: Simple health check of Rails app for use with uptime.openacs.org or wasitup.com
46
+ email: ian@heggie.biz
47
+ executables: []
48
+
49
+ extensions: []
50
+
51
+ extra_rdoc_files:
52
+ - README.rdoc
53
+ files:
54
+ - .document
55
+ - .gitignore
56
+ - MIT-LICENSE
57
+ - README.rdoc
58
+ - Rakefile
59
+ - VERSION
60
+ - health_check.gemspec
61
+ - init.rb
62
+ - lib/health_check.rb
63
+ - lib/health_check/add_routes.rb
64
+ - lib/health_check/health_check_class.rb
65
+ - lib/health_check/health_check_controller.rb
66
+ - test/helper.rb
67
+ - test/migrate/empty/do_not_remove.txt
68
+ - test/migrate/twelve/012_create_users.rb
69
+ - test/migrate/twelve/9_create_countries.rb
70
+ - test/test_health_check_controller.rb
71
+ - test/test_routes.rb
72
+ has_rdoc: true
73
+ homepage: http://github.com/ianheggie/health_check
74
+ licenses: []
75
+
76
+ post_install_message:
77
+ rdoc_options:
78
+ - --charset=UTF-8
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: "0"
86
+ version:
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: "0"
92
+ version:
93
+ requirements: []
94
+
95
+ rubyforge_project:
96
+ rubygems_version: 1.3.5
97
+ signing_key:
98
+ specification_version: 3
99
+ summary: Simple health check of Rails app
100
+ test_files:
101
+ - test/helper.rb
102
+ - test/migrate/twelve/012_create_users.rb
103
+ - test/migrate/twelve/9_create_countries.rb
104
+ - test/test_health_check_controller.rb
105
+ - test/test_routes.rb