health_check 0.2.4 → 1.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.
- data/Gemfile +18 -0
- data/Gemfile.lock +34 -0
- data/MIT-LICENSE +1 -1
- data/README.rdoc +38 -16
- data/Rakefile +48 -29
- data/VERSION +1 -1
- data/config/routes.rb +4 -11
- data/health_check.gemspec +50 -47
- data/lib/health_check.rb +16 -4
- data/lib/health_check/add_23_routes.rb +5 -2
- data/lib/health_check/health_check_controller.rb +85 -56
- data/lib/health_check/utils.rb +103 -0
- data/test/migrate/nine/9_create_countries.rb +11 -0
- data/test/migrate/twelve/012_create_users.rb +2 -1
- data/test/{helper.rb → test_helper.rb} +0 -1
- data/test/test_with_railsapp +164 -0
- data/test/testurl +33 -0
- data/test/{test_health_check_controller.rb → unit/health_check_controller_test.rb} +31 -31
- data/test/{test_routes.rb → unit/routes_test.rb} +1 -1
- metadata +92 -42
- data/.gitignore +0 -21
- data/lib/health_check/add_3x_routes.rb +0 -13
- data/lib/health_check/health_check_class.rb +0 -99
data/test/testurl
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'net/http'
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
def open(url)
|
6
|
+
Net::HTTP.get(URI.parse(url))
|
7
|
+
end
|
8
|
+
|
9
|
+
page_content = open(ARGV[0]) rescue nil
|
10
|
+
unless page_content
|
11
|
+
i=1
|
12
|
+
print "waiting.."
|
13
|
+
while i < 30 and not page_content
|
14
|
+
print "."
|
15
|
+
STDOUT.flush
|
16
|
+
i += 1
|
17
|
+
sleep(1)
|
18
|
+
page_content = open(ARGV[0]) rescue nil
|
19
|
+
end
|
20
|
+
puts " done"
|
21
|
+
end
|
22
|
+
|
23
|
+
puts page_content
|
24
|
+
if ARGV[1]
|
25
|
+
if page_content.to_s.include? ARGV[1]
|
26
|
+
puts "PASS (found #{ARGV[1]})"
|
27
|
+
exit 0
|
28
|
+
else
|
29
|
+
puts "FAIL (could not find #{ARGV[1]})"
|
30
|
+
exit 2
|
31
|
+
end
|
32
|
+
end
|
33
|
+
exit(page_content.nil? ? 1 : 0)
|
@@ -1,9 +1,9 @@
|
|
1
|
-
require '
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
2
|
|
3
3
|
class HealthCheckControllerTest < ActionController::TestCase
|
4
4
|
#context "HealthCheck plugin" do
|
5
|
-
#
|
6
|
-
#
|
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
7
|
#end
|
8
8
|
|
9
9
|
context "GET standard on empty db" do
|
@@ -18,10 +18,10 @@ class HealthCheckControllerTest < ActionController::TestCase
|
|
18
18
|
teardown_db
|
19
19
|
end
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
should respond_with :success
|
22
|
+
should_not set_the_flash
|
23
|
+
should respond_with_content_type 'text/plain'
|
24
|
+
should_not render_with_layout
|
25
25
|
should "return 'success' text" do
|
26
26
|
assert_equal HealthCheck.success, @response.body
|
27
27
|
end
|
@@ -39,10 +39,10 @@ class HealthCheckControllerTest < ActionController::TestCase
|
|
39
39
|
teardown_db
|
40
40
|
end
|
41
41
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
42
|
+
should respond_with :success
|
43
|
+
should_not set_the_flash
|
44
|
+
should respond_with_content_type 'text/plain'
|
45
|
+
should_not render_with_layout
|
46
46
|
should "return 'success' text" do
|
47
47
|
assert_equal HealthCheck.success, @response.body
|
48
48
|
end
|
@@ -60,10 +60,10 @@ class HealthCheckControllerTest < ActionController::TestCase
|
|
60
60
|
teardown_db
|
61
61
|
end
|
62
62
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
63
|
+
should respond_with 500
|
64
|
+
should_not set_the_flash
|
65
|
+
should respond_with_content_type 'text/plain'
|
66
|
+
should_not render_with_layout
|
67
67
|
should "not return 'success' text" do
|
68
68
|
assert_not_equal HealthCheck.success, @response.body
|
69
69
|
end
|
@@ -75,10 +75,10 @@ class HealthCheckControllerTest < ActionController::TestCase
|
|
75
75
|
get :check, :checks => 'email'
|
76
76
|
end
|
77
77
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
78
|
+
should respond_with :success
|
79
|
+
should_not set_the_flash
|
80
|
+
should respond_with_content_type 'text/plain'
|
81
|
+
should_not render_with_layout
|
82
82
|
should "return 'success' text" do
|
83
83
|
assert_equal HealthCheck.success, @response.body
|
84
84
|
end
|
@@ -102,10 +102,10 @@ class HealthCheckControllerTest < ActionController::TestCase
|
|
102
102
|
teardown_db
|
103
103
|
end
|
104
104
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
105
|
+
should respond_with 500
|
106
|
+
should_not set_the_flash
|
107
|
+
should respond_with_content_type 'text/plain'
|
108
|
+
should_not render_with_layout
|
109
109
|
should "not return 'success' text" do
|
110
110
|
assert_not_equal HealthCheck.success, @response.body
|
111
111
|
end
|
@@ -123,8 +123,8 @@ class HealthCheckControllerTest < ActionController::TestCase
|
|
123
123
|
get :check, :checks => 'email'
|
124
124
|
end
|
125
125
|
|
126
|
-
|
127
|
-
|
126
|
+
should respond_with :success
|
127
|
+
should respond_with_content_type 'text/plain'
|
128
128
|
should "return 'success' text" do
|
129
129
|
assert_equal HealthCheck.success, @response.body
|
130
130
|
end
|
@@ -144,10 +144,10 @@ class HealthCheckControllerTest < ActionController::TestCase
|
|
144
144
|
teardown_db
|
145
145
|
end
|
146
146
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
147
|
+
should respond_with 500
|
148
|
+
should_not set_the_flash
|
149
|
+
should respond_with_content_type 'text/plain'
|
150
|
+
should_not render_with_layout
|
151
151
|
should "not return 'success' text" do
|
152
152
|
assert_not_equal HealthCheck.success, @response.body
|
153
153
|
end
|
@@ -166,8 +166,8 @@ class HealthCheckControllerTest < ActionController::TestCase
|
|
166
166
|
teardown_db
|
167
167
|
end
|
168
168
|
|
169
|
-
|
170
|
-
|
169
|
+
should respond_with :success
|
170
|
+
should respond_with_content_type 'text/plain'
|
171
171
|
should "return 'success' text" do
|
172
172
|
assert_equal HealthCheck.success, @response.body
|
173
173
|
end
|
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:
|
4
|
+
hash: 21
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
|
+
- 1
|
7
8
|
- 0
|
8
|
-
-
|
9
|
-
|
10
|
-
version: 0.2.4
|
9
|
+
- 1
|
10
|
+
version: 1.0.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ian Heggie
|
@@ -15,54 +15,105 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2013-01-23 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
|
-
name: shoulda
|
22
|
-
prerelease: false
|
23
21
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
22
|
none: false
|
25
23
|
requirements:
|
26
24
|
- - ">="
|
27
25
|
- !ruby/object:Gem::Version
|
28
|
-
hash:
|
26
|
+
hash: 57
|
29
27
|
segments:
|
30
28
|
- 0
|
31
|
-
|
32
|
-
|
29
|
+
- 8
|
30
|
+
- 3
|
31
|
+
version: 0.8.3
|
33
32
|
version_requirements: *id001
|
34
|
-
|
35
|
-
name: sqlite3-ruby
|
33
|
+
name: rake
|
36
34
|
prerelease: false
|
35
|
+
type: :development
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
37
|
requirement: &id002 !ruby/object:Gem::Requirement
|
38
38
|
none: false
|
39
39
|
requirements:
|
40
|
-
- -
|
40
|
+
- - ~>
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
hash:
|
42
|
+
hash: 63
|
43
43
|
segments:
|
44
|
+
- 1
|
45
|
+
- 8
|
46
|
+
- 4
|
47
|
+
version: 1.8.4
|
48
|
+
version_requirements: *id002
|
49
|
+
name: jeweler
|
50
|
+
prerelease: false
|
51
|
+
type: :development
|
52
|
+
- !ruby/object:Gem::Dependency
|
53
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ~>
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
hash: 35
|
59
|
+
segments:
|
60
|
+
- 2
|
61
|
+
- 11
|
44
62
|
- 0
|
45
|
-
version:
|
63
|
+
version: 2.11.0
|
64
|
+
version_requirements: *id003
|
65
|
+
name: shoulda
|
66
|
+
prerelease: false
|
46
67
|
type: :development
|
47
|
-
version_requirements: *id002
|
48
68
|
- !ruby/object:Gem::Dependency
|
49
|
-
|
69
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ~>
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
hash: 21
|
75
|
+
segments:
|
76
|
+
- 1
|
77
|
+
- 3
|
78
|
+
- 7
|
79
|
+
version: 1.3.7
|
80
|
+
version_requirements: *id004
|
81
|
+
name: sqlite3
|
50
82
|
prerelease: false
|
51
|
-
|
83
|
+
type: :development
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
52
86
|
none: false
|
53
87
|
requirements:
|
54
88
|
- - ">="
|
55
89
|
- !ruby/object:Gem::Version
|
56
|
-
hash:
|
90
|
+
hash: 3
|
91
|
+
segments:
|
92
|
+
- 2
|
93
|
+
- 3
|
94
|
+
- 0
|
95
|
+
version: 2.3.0
|
96
|
+
version_requirements: *id005
|
97
|
+
name: activerecord
|
98
|
+
prerelease: false
|
99
|
+
type: :development
|
100
|
+
- !ruby/object:Gem::Dependency
|
101
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ~>
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
hash: 31
|
57
107
|
segments:
|
58
108
|
- 1
|
59
|
-
-
|
60
|
-
-
|
61
|
-
|
62
|
-
|
109
|
+
- 2
|
110
|
+
- 0
|
111
|
+
version: 1.2.0
|
112
|
+
version_requirements: *id006
|
113
|
+
name: bundler
|
114
|
+
prerelease: false
|
63
115
|
type: :development
|
64
|
-
|
65
|
-
description: Simple health check of Rails app for use with uptime monitoring sites
|
116
|
+
description: Simple health check of Rails app for use with Pingdom, NewRelic, EngineYard or uptime.openacs.org etc.
|
66
117
|
email: ian@heggie.biz
|
67
118
|
executables: []
|
68
119
|
|
@@ -72,31 +123,34 @@ extra_rdoc_files:
|
|
72
123
|
- README.rdoc
|
73
124
|
files:
|
74
125
|
- .document
|
75
|
-
-
|
126
|
+
- Gemfile
|
127
|
+
- Gemfile.lock
|
76
128
|
- MIT-LICENSE
|
77
129
|
- README.rdoc
|
78
130
|
- Rakefile
|
79
131
|
- VERSION
|
132
|
+
- config/routes.rb
|
80
133
|
- health_check.gemspec
|
81
134
|
- init.rb
|
82
|
-
- config/routes.rb
|
83
135
|
- lib/health_check.rb
|
84
136
|
- lib/health_check/add_23_routes.rb
|
85
|
-
- lib/health_check/add_3x_routes.rb
|
86
|
-
- lib/health_check/health_check_class.rb
|
87
137
|
- lib/health_check/health_check_controller.rb
|
88
|
-
-
|
138
|
+
- lib/health_check/utils.rb
|
89
139
|
- test/migrate/empty/do_not_remove.txt
|
140
|
+
- test/migrate/nine/9_create_countries.rb
|
90
141
|
- test/migrate/twelve/012_create_users.rb
|
91
142
|
- test/migrate/twelve/9_create_countries.rb
|
92
|
-
- test/
|
93
|
-
- test/
|
143
|
+
- test/test_helper.rb
|
144
|
+
- test/test_with_railsapp
|
145
|
+
- test/testurl
|
146
|
+
- test/unit/health_check_controller_test.rb
|
147
|
+
- test/unit/routes_test.rb
|
94
148
|
homepage: http://github.com/ianheggie/health_check
|
95
149
|
licenses: []
|
96
150
|
|
97
151
|
post_install_message:
|
98
|
-
rdoc_options:
|
99
|
-
|
152
|
+
rdoc_options: []
|
153
|
+
|
100
154
|
require_paths:
|
101
155
|
- lib
|
102
156
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -120,13 +174,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
174
|
requirements: []
|
121
175
|
|
122
176
|
rubyforge_project:
|
123
|
-
rubygems_version: 1.8.
|
177
|
+
rubygems_version: 1.8.24
|
124
178
|
signing_key:
|
125
179
|
specification_version: 3
|
126
|
-
summary: Simple health check of Rails app for
|
127
|
-
test_files:
|
128
|
-
|
129
|
-
- test/migrate/twelve/012_create_users.rb
|
130
|
-
- test/migrate/twelve/9_create_countries.rb
|
131
|
-
- test/test_health_check_controller.rb
|
132
|
-
- test/test_routes.rb
|
180
|
+
summary: Simple health check of Rails app for uptime monitoring
|
181
|
+
test_files: []
|
182
|
+
|
data/.gitignore
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
if defined?(Rails) and Rails.respond_to?(:version) && Rails.version =~ /^3/
|
2
|
-
if defined? Rails31
|
3
|
-
Rails31::Application.routes.draw do
|
4
|
-
match 'health_check', :to => 'health_check#index'
|
5
|
-
match 'health_check/:checks', :to => 'health_check#check'
|
6
|
-
end
|
7
|
-
else
|
8
|
-
Rails.application.routes.draw do |map|
|
9
|
-
match 'health_check', :to => 'health_check#index'
|
10
|
-
match 'health_check/:checks', :to => 'health_check#check'
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
@@ -1,99 +0,0 @@
|
|
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
|