easymon 1.6.3 → 1.6.4

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.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +28 -12
  3. data/Rakefile +1 -1
  4. data/app/controllers/easymon/checks_controller.rb +6 -6
  5. data/config/routes.rb +2 -2
  6. data/lib/easymon/checklist.rb +7 -7
  7. data/lib/easymon/checks/active_record_check.rb +5 -5
  8. data/lib/easymon/checks/active_record_mysql_writeable_check.rb +1 -1
  9. data/lib/easymon/checks/http_check.rb +6 -6
  10. data/lib/easymon/checks/memcached_check.rb +6 -6
  11. data/lib/easymon/checks/multi_active_record_check.rb +52 -0
  12. data/lib/easymon/checks/redis_check.rb +3 -3
  13. data/lib/easymon/checks/redis_writeable_check.rb +1 -1
  14. data/lib/easymon/checks/semaphore_check.rb +6 -6
  15. data/lib/easymon/checks/split_active_record_check.rb +6 -16
  16. data/lib/easymon/checks/traffic_enabled_check.rb +2 -2
  17. data/lib/easymon/engine.rb +1 -1
  18. data/lib/easymon/repository.rb +5 -5
  19. data/lib/easymon/result.rb +2 -2
  20. data/lib/easymon/testing.rb +2 -2
  21. data/lib/easymon/version.rb +1 -1
  22. data/lib/easymon.rb +10 -9
  23. data/test/controllers/easymon/checks_controller_test.rb +10 -11
  24. data/test/dummy/Rakefile +2 -3
  25. data/test/dummy/app/assets/stylesheets/application.css +6 -4
  26. data/test/dummy/app/controllers/application_controller.rb +2 -1
  27. data/test/dummy/app/jobs/application_job.rb +7 -0
  28. data/test/dummy/app/mailers/application_mailer.rb +4 -0
  29. data/test/dummy/app/models/application_record.rb +3 -0
  30. data/test/dummy/app/views/layouts/application.html.erb +22 -9
  31. data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
  32. data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
  33. data/test/dummy/app/views/pwa/manifest.json.erb +22 -0
  34. data/test/dummy/app/views/pwa/service-worker.js +26 -0
  35. data/test/dummy/bin/dev +2 -0
  36. data/test/dummy/bin/rails +4 -0
  37. data/test/dummy/bin/rake +4 -0
  38. data/test/dummy/bin/setup +34 -0
  39. data/test/dummy/config/application.rb +22 -50
  40. data/test/dummy/config/boot.rb +4 -9
  41. data/test/dummy/config/database.yml +25 -6
  42. data/test/dummy/config/environment.rb +4 -4
  43. data/test/dummy/config/environments/development.rb +55 -25
  44. data/test/dummy/config/environments/production.rb +64 -42
  45. data/test/dummy/config/environments/test.rb +35 -25
  46. data/test/dummy/config/initializers/assets.rb +7 -0
  47. data/test/dummy/config/initializers/content_security_policy.rb +25 -0
  48. data/test/dummy/config/initializers/easymon.rb +2 -2
  49. data/test/dummy/config/initializers/filter_parameter_logging.rb +8 -0
  50. data/test/dummy/config/initializers/inflections.rb +10 -9
  51. data/test/dummy/config/locales/en.yml +28 -2
  52. data/test/dummy/config/puma.rb +38 -0
  53. data/test/dummy/config/redis.yml +5 -6
  54. data/test/dummy/config/routes.rb +13 -0
  55. data/test/dummy/config/storage.yml +34 -0
  56. data/test/dummy/config.ru +4 -2
  57. data/test/dummy/public/400.html +114 -0
  58. data/test/dummy/public/404.html +113 -25
  59. data/test/dummy/public/406-unsupported-browser.html +114 -0
  60. data/test/dummy/public/422.html +113 -25
  61. data/test/dummy/public/500.html +113 -24
  62. data/test/dummy/public/icon.png +0 -0
  63. data/test/dummy/public/icon.svg +3 -0
  64. data/test/dummy/tmp/local_secret.txt +1 -0
  65. data/test/helpers/easymon/checks_helper_test.rb +1 -1
  66. data/test/integration/navigation_test.rb +1 -2
  67. data/test/test_helper.rb +3 -3
  68. data/test/unit/checklist_test.rb +5 -5
  69. data/test/unit/checks/active_record_check_on_postgresql_test.rb +1 -2
  70. data/test/unit/checks/active_record_check_test.rb +1 -2
  71. data/test/unit/checks/active_record_mysql_writeable_check_test.rb +2 -3
  72. data/test/unit/checks/http_check_test.rb +3 -3
  73. data/test/unit/checks/memcached_check_test.rb +6 -8
  74. data/test/unit/checks/multi_active_record_check_test.rb +73 -0
  75. data/test/unit/checks/redis_check_test.rb +8 -9
  76. data/test/unit/checks/redis_writeable_check_test.rb +2 -3
  77. data/test/unit/checks/semaphore_check_test.rb +2 -3
  78. data/test/unit/checks/split_active_record_check_test.rb +9 -24
  79. data/test/unit/checks/traffic_enabled_check_test.rb +2 -3
  80. data/test/unit/repository_test.rb +2 -3
  81. metadata +99 -75
  82. data/test/dummy/README.rdoc +0 -261
  83. data/test/dummy/app/assets/javascripts/application.js +0 -15
  84. data/test/dummy/app/assets/javascripts/easymon.js +0 -2
  85. data/test/dummy/app/assets/stylesheets/easymon.css +0 -4
  86. data/test/dummy/app/controllers/easymon_controller.rb +0 -7
  87. data/test/dummy/app/helpers/easymon_helper.rb +0 -2
  88. data/test/dummy/app/views/easymon/index.html.erb +0 -2
  89. data/test/dummy/app/views/easymon/show.html.erb +0 -2
  90. data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
  91. data/test/dummy/config/initializers/mime_types.rb +0 -5
  92. data/test/dummy/config/initializers/secret_token.rb +0 -7
  93. data/test/dummy/config/initializers/session_store.rb +0 -8
  94. data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
  95. data/test/dummy/public/favicon.ico +0 -0
  96. data/test/dummy/script/rails +0 -6
  97. /data/test/dummy/{app/assets/config/manifest.js → log/test.log} +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 82da9dec5eb66912f758fe04075ef2121f8c10d4659ab4c3b7cb79b43fc47bba
4
- data.tar.gz: 03ef075f7573a79461e40e6924a1c0a57d8cafa6292b7381217a0e2dfe2aef06
3
+ metadata.gz: 7bc697369e22923ddb3ad6cdee3577767e064e7fa3bc96e0d377cf8d19e0f8a9
4
+ data.tar.gz: d0527f2b8b69761afe25d4d103f2b382fd438147087edb788179c86de7462f1e
5
5
  SHA512:
6
- metadata.gz: 37b5c45c57e1fefb47d3eca2549d3bd5dc611697cb5c6efa577f94f8646c67e8240c38ef0de7021dc5f1a9de157fb06bd6ed9f40addeb74f180b61a78ee04912
7
- data.tar.gz: 829e5f4a17106de067477d9ffc11d64fc631562a560732945e7b21a15d6b013b19fe49f0b96d7ab3c7e29b45cb3c84ebc23df6b018f450dee1acbd8613cecd9e
6
+ metadata.gz: 43eb27d784907c6fe180edbc543da84fdc83b06cae7e9dde06f9fe4a5e1223c4e4f6b621a4a0064443eeaca97cba6b7e7adb9f0d0320b261db54d43d259b2faa
7
+ data.tar.gz: d529dd1f51527b4d42db73967e225913b4625ce68f24e26dd28b8e4f31abc4340be3bca36d064aba331b97da5381ccff193be8918d26d781239b7623a49341f5
data/README.md CHANGED
@@ -124,6 +124,7 @@ check.
124
124
  * Semaphore
125
125
  * Traffic Enabled
126
126
  * Split ActiveRecord
127
+ * Multi ActiveRecord
127
128
  * Http
128
129
 
129
130
  ### ActiveRecord
@@ -194,18 +195,8 @@ For example, given the following other class:
194
195
 
195
196
  ````ruby
196
197
  module Easymon
197
- class Base < ActiveRecord::Base
198
- def establish_connection(spec = nil)
199
- if spec
200
- super
201
- elsif config = Easymon.database_configuration
202
- super config
203
- end
204
- end
205
- def database_configuration
206
- env = "#{Rails.env}_replica"
207
- config = YAML.load_file(Rails.root.join('config/database.yml'))[env]
208
- end
198
+ class Replica < ActiveRecord::Base
199
+ establish_connection :"primary_replica"
209
200
  end
210
201
  end
211
202
  ````
@@ -219,6 +210,31 @@ check = Easymon::SplitActiveRecordCheck.new {
219
210
  Easymon::Repository.add("split-database", check)
220
211
  ````
221
212
 
213
+ ### Multi ActiveRecord
214
+ `Easymon::MultiActiveRecordCheck` is similar to the `SplitActiveRecordCheck`,
215
+ but it can take an arbitrary number of databases:
216
+
217
+ ```ruby
218
+ module Easymon
219
+ class PrimaryReplica < ActiveRecord::Base
220
+ establish_connection :"primary_replica"
221
+ end
222
+
223
+ class OtherReplica < ActiveRecord::Base
224
+ establish_connection :"other_replica"
225
+ end
226
+ end
227
+
228
+ check = Easymon::MultiActiveRecordCheck.new {
229
+ {
230
+ "Primary": ActiveRecord::Base.connection,
231
+ "PrimaryReplica": Easymon::PrimaryReplica.connection
232
+ "OtherReplica": Easymon::OtherReplica.connection
233
+ }
234
+ }
235
+ Easymon::Repository.add("multi-database", check)
236
+ ```
237
+
222
238
  ### Http
223
239
  `Easymon::HttpCheck` will check the return status of a HEAD request to a URL.
224
240
  Great for checking service endpoint availability! The following will make a
data/Rakefile CHANGED
@@ -37,4 +37,4 @@ Rake::TestTask.new(:test) do |t|
37
37
  end
38
38
 
39
39
 
40
- task :default => :test
40
+ task default: :test
@@ -7,7 +7,7 @@ module Easymon
7
7
  # the latter for forward compatibility.
8
8
  unless defined?(before_action)
9
9
  class << self
10
- %w( before ).each do |callback|
10
+ %w[ before ].each do |callback|
11
11
  alias_method :"#{callback}_action", :"#{callback}_filter"
12
12
  end
13
13
  end
@@ -18,7 +18,7 @@ module Easymon
18
18
  rescue_from Easymon::NoSuchCheck do |e|
19
19
  respond_to do |format|
20
20
  format.any(:text, :html) { render_result "Check Not Found", :not_found }
21
- format.json { render :json => "Check Not Found", :status => :not_found }
21
+ format.json { render json: "Check Not Found", status: :not_found }
22
22
  end
23
23
  end
24
24
 
@@ -34,7 +34,7 @@ module Easymon
34
34
  unless checklist.empty?
35
35
  # override response_status if we have a "critical" checklist
36
36
  unless Easymon::Repository.critical.empty?
37
- critical_checks = checklist.items.map{|name, entry| checklist.results[name] if Easymon::Repository.critical.include?(name)}.compact
37
+ critical_checks = checklist.items.map { |name, entry| checklist.results[name] if Easymon::Repository.critical.include?(name) }.compact
38
38
  critical_success = critical_checks.all?(&:success?)
39
39
  response_status = critical_success ? :ok : :service_unavailable
40
40
  message = add_prefix(critical_success, message)
@@ -45,7 +45,7 @@ module Easymon
45
45
 
46
46
  respond_to do |format|
47
47
  format.any(:text, :html) { render_result message, response_status }
48
- format.json { render :json => checklist, :status => response_status }
48
+ format.json { render json: checklist, status: response_status }
49
49
  end
50
50
  end
51
51
 
@@ -77,9 +77,9 @@ module Easymon
77
77
  end
78
78
  format.json do
79
79
  if is_critical
80
- render :json => checklist, :status => checklist.response_status
80
+ render json: checklist, status: checklist.response_status
81
81
  else
82
- render :json => result, :status => result.response_status
82
+ render json: result, status: result.response_status
83
83
  end
84
84
  end
85
85
  end
data/config/routes.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # use `mount Easymon::Engine => "/up"` in the host application routes.rb
2
- if Gem::Version.new(Rails.version) >= Gem::Version.new('3.1')
2
+ if Gem::Version.new(Rails.version) >= Gem::Version.new("3.1")
3
3
  Easymon::Engine.routes.draw do
4
4
  Easymon.routes(self)
5
5
  end
6
- end
6
+ end
@@ -1,4 +1,4 @@
1
- require 'benchmark'
1
+ require "benchmark"
2
2
 
3
3
  module Easymon
4
4
  class Checklist
@@ -8,7 +8,7 @@ module Easymon
8
8
  attr_accessor :items
9
9
  attr_accessor :results
10
10
 
11
- def initialize(items={})
11
+ def initialize(items = {})
12
12
  self.items = items
13
13
  self.results = {}
14
14
  end
@@ -20,11 +20,11 @@ module Easymon
20
20
  hash[name] = Easymon::Result.new(check_result, timing, check[:critical])
21
21
  hash
22
22
  end
23
- [self.success?, self.to_s]
23
+ [ self.success?, self.to_s ]
24
24
  end
25
25
 
26
26
  def timing
27
- results.values.map{|r| r.timing}.inject(0, :+)
27
+ results.values.map { |r| r.timing }.inject(0, :+)
28
28
  end
29
29
 
30
30
  def to_text
@@ -32,12 +32,12 @@ module Easymon
32
32
  end
33
33
 
34
34
  def to_s
35
- results.map{|name, result| "#{name}: #{result.to_s}"}.join("\n") +
35
+ results.map { |name, result| "#{name}: #{result}" }.join("\n") +
36
36
  "\n - Total Time - " + Easymon.timing_to_ms(self.timing) + "ms"
37
37
  end
38
38
 
39
39
  def to_hash
40
- combined = {:timing => Easymon.timing_to_ms(timing)}
40
+ combined = { timing: Easymon.timing_to_ms(timing) }
41
41
  results.each do |name, result|
42
42
  combined[name] = result.to_hash
43
43
  end
@@ -67,4 +67,4 @@ module Easymon
67
67
  raise NoSuchCheck, "No check named '#{name}'"
68
68
  end
69
69
  end
70
- end
70
+ end
@@ -1,11 +1,11 @@
1
1
  module Easymon
2
2
  class ActiveRecordCheck
3
3
  attr_accessor :klass
4
-
4
+
5
5
  def initialize(klass)
6
6
  self.klass = klass
7
- end
8
-
7
+ end
8
+
9
9
  def check
10
10
  check_status = database_up?
11
11
  if check_status
@@ -13,9 +13,9 @@ module Easymon
13
13
  else
14
14
  message = "Down"
15
15
  end
16
- [check_status, message]
16
+ [ check_status, message ]
17
17
  end
18
-
18
+
19
19
  private
20
20
  def database_up?
21
21
  klass.connection.connect!
@@ -14,7 +14,7 @@ module Easymon
14
14
  else
15
15
  message = "@@read_only is 1"
16
16
  end
17
- [check_status, message]
17
+ [ check_status, message ]
18
18
  end
19
19
 
20
20
  private
@@ -1,13 +1,13 @@
1
- require 'net/https'
1
+ require "net/https"
2
2
 
3
3
  module Easymon
4
4
  class HttpCheck
5
5
  attr_accessor :url
6
-
6
+
7
7
  def initialize(url)
8
8
  self.url = url
9
- end
10
-
9
+ end
10
+
11
11
  def check
12
12
  check_status = http_up?(url)
13
13
  if check_status
@@ -15,9 +15,9 @@ module Easymon
15
15
  else
16
16
  message = "Down"
17
17
  end
18
- [check_status, message]
18
+ [ check_status, message ]
19
19
  end
20
-
20
+
21
21
  private
22
22
  def http_up?(url)
23
23
  http_head(url).is_a?(Net::HTTPSuccess)
@@ -1,11 +1,11 @@
1
1
  module Easymon
2
2
  class MemcachedCheck
3
3
  attr_accessor :cache
4
-
4
+
5
5
  def initialize(cache)
6
6
  self.cache = cache
7
- end
8
-
7
+ end
8
+
9
9
  def check
10
10
  check_status = memcached_up?
11
11
  if check_status
@@ -13,9 +13,9 @@ module Easymon
13
13
  else
14
14
  message = "Down"
15
15
  end
16
- [check_status, message]
16
+ [ check_status, message ]
17
17
  end
18
-
18
+
19
19
  private
20
20
  def memcached_up?
21
21
  cache.write "health_check", 1
@@ -24,4 +24,4 @@ module Easymon
24
24
  false
25
25
  end
26
26
  end
27
- end
27
+ end
@@ -0,0 +1,52 @@
1
+ module Easymon
2
+ class MultiActiveRecordCheck
3
+ attr_accessor :block
4
+ attr_accessor :results
5
+
6
+ # Here we pass a block so we get a fresh instance of ActiveRecord::Base or
7
+ # whatever other class we might be using to make database connections
8
+ #
9
+ # For example, given the following other class:
10
+ # module Easymon
11
+ # class PrimaryReplica < ActiveRecord::Base
12
+ # establish_connection :"primary_replica"
13
+ # end
14
+ #
15
+ # class OtherReplica < ActiveRecord::Base
16
+ # establish_connection :"other_replica"
17
+ # end
18
+ # end
19
+ #
20
+ # We would check both it and ActiveRecord::Base like so:
21
+ # check = Easymon::MultiActiveRecordCheck.new {
22
+ # {
23
+ # "Primary": ActiveRecord::Base.connection,
24
+ # "PrimaryReplica": Easymon::PrimaryReplica.connection
25
+ # "OtherReplica": Easymon::OtherReplica.connection
26
+ # }
27
+ # }
28
+ # Easymon::Repository.add("multi-database", check)
29
+
30
+ def initialize(&block)
31
+ self.block = block
32
+ end
33
+
34
+ def check
35
+ connections = Hash(@block.call)
36
+
37
+ results = connections.transform_values { |connection| database_up?(connection) }
38
+
39
+ status = results.map { |db_name, result| "#{db_name}: #{result ? 'Up' : 'Down'}" }.join(" - ")
40
+
41
+ [ (results.any? && results.values.all?), status ]
42
+ end
43
+
44
+ private
45
+ def database_up?(connection)
46
+ connection.connect!
47
+ connection.active?
48
+ rescue
49
+ false
50
+ end
51
+ end
52
+ end
@@ -15,13 +15,13 @@ module Easymon
15
15
  else
16
16
  message = "Down"
17
17
  end
18
- [check_status, message]
18
+ [ check_status, message ]
19
19
  end
20
20
 
21
21
  private
22
22
  def redis_up?
23
23
  redis = Redis.new(@config)
24
- reply = redis.ping == 'PONG'
24
+ reply = redis.ping == "PONG"
25
25
  if redis.respond_to? :close
26
26
  redis.close # Redis 4+
27
27
  else
@@ -32,4 +32,4 @@ module Easymon
32
32
  false
33
33
  end
34
34
  end
35
- end
35
+ end
@@ -12,7 +12,7 @@ module Easymon
12
12
  check_status = redis_writeable?
13
13
  message = check_status ? "Writeable" : "Read Only"
14
14
 
15
- [check_status, message]
15
+ [ check_status, message ]
16
16
  end
17
17
 
18
18
  private
@@ -1,11 +1,11 @@
1
1
  module Easymon
2
2
  class SemaphoreCheck
3
3
  attr_accessor :file_name
4
-
4
+
5
5
  def initialize(file_name)
6
6
  self.file_name = file_name
7
- end
8
-
7
+ end
8
+
9
9
  def check
10
10
  check_status = semaphore_exists?
11
11
  if check_status
@@ -13,9 +13,9 @@ module Easymon
13
13
  else
14
14
  message = "#{file_name} does not exist!"
15
15
  end
16
- [check_status, message]
16
+ [ check_status, message ]
17
17
  end
18
-
18
+
19
19
  private
20
20
  def semaphore_exists?
21
21
  Rails.root.join(file_name).exist?
@@ -23,4 +23,4 @@ module Easymon
23
23
  false
24
24
  end
25
25
  end
26
- end
26
+ end
@@ -8,25 +8,14 @@ module Easymon
8
8
  #
9
9
  # For example, given the following other class:
10
10
  # module Easymon
11
- # class Base < ActiveRecord::Base
12
- # def establish_connection(spec = nil)
13
- # if spec
14
- # super
15
- # elsif config = Easymon.database_configuration
16
- # super config
17
- # end
18
- # end
19
- #
20
- # def database_configuration
21
- # env = "#{Rails.env}_replica"
22
- # config = YAML.load_file(Rails.root.join('config/database.yml'))[env]
23
- # end
11
+ # class Replica < ActiveRecord::Base
12
+ # establish_connection :"primary_replica"
24
13
  # end
25
14
  # end
26
15
  #
27
16
  # We would check both it and ActiveRecord::Base like so:
28
17
  # check = Easymon::SplitActiveRecordCheck.new {
29
- # [ActiveRecord::Base.connection, Easymon::Base.connection]
18
+ # [ActiveRecord::Base.connection, Easymon::Replica.connection]
30
19
  # }
31
20
  # Easymon::Repository.add("split-database", check)
32
21
  def initialize(&block)
@@ -37,16 +26,17 @@ module Easymon
37
26
  def check
38
27
  connections = Array(@block.call)
39
28
 
40
- results = connections.map{|connection| database_up?(connection) }
29
+ results = connections.map { |connection| database_up?(connection) }
41
30
 
42
31
  primary_status = results.first ? "Primary: Up" : "Primary: Down"
43
32
  replica_status = results.last ? "Replica: Up" : "Replica: Down"
44
33
 
45
- [(results.all? && results.count > 0), "#{primary_status} - #{replica_status}"]
34
+ [ (results.all? && results.count > 0), "#{primary_status} - #{replica_status}" ]
46
35
  end
47
36
 
48
37
  private
49
38
  def database_up?(connection)
39
+ connection.connect!
50
40
  connection.active?
51
41
  rescue
52
42
  false
@@ -7,7 +7,7 @@ module Easymon
7
7
  else
8
8
  message = "DISABLED"
9
9
  end
10
- [check_status, message]
10
+ [ check_status, message ]
11
11
  end
12
12
  end
13
- end
13
+ end
@@ -1,7 +1,7 @@
1
1
  module Easymon
2
2
  class Engine < ::Rails::Engine
3
3
  # Rails Engines weren't isolated until v3.1
4
- if Gem::Version.new(Rails.version) >= Gem::Version.new('3.1')
4
+ if Gem::Version.new(Rails.version) >= Gem::Version.new("3.1")
5
5
  isolate_namespace Easymon
6
6
  end
7
7
  end
@@ -3,7 +3,7 @@ module Easymon
3
3
  attr_reader :repository
4
4
 
5
5
  def self.fetch(name)
6
- return repository.fetch(name)
6
+ repository.fetch(name)
7
7
  rescue IndexError
8
8
  raise NoSuchCheck, "No check named '#{name}'"
9
9
  end
@@ -16,8 +16,8 @@ module Easymon
16
16
  repository.keys
17
17
  end
18
18
 
19
- def self.add(name, check, is_critical=false)
20
- entry = {:check => check, :critical => is_critical ? true : false}
19
+ def self.add(name, check, is_critical = false)
20
+ entry = { check: check, critical: is_critical ? true : false }
21
21
  repository[name] = entry
22
22
  end
23
23
 
@@ -30,7 +30,7 @@ module Easymon
30
30
  end
31
31
 
32
32
  def self.critical
33
- repository.map{ |name, entry| name if entry[:critical] }.compact
33
+ repository.map { |name, entry| name if entry[:critical] }.compact
34
34
  end
35
35
  end
36
- end
36
+ end
@@ -33,7 +33,7 @@ module Easymon
33
33
  end
34
34
 
35
35
  def to_hash
36
- {:success => success, :message => message, :timing => Easymon.timing_to_ms(timing), :critical => critical}
36
+ { success: success, message: message, timing: Easymon.timing_to_ms(timing), critical: critical }
37
37
  end
38
38
  end
39
- end
39
+ end
@@ -7,11 +7,11 @@ module Easymon
7
7
  end
8
8
 
9
9
  def stub_service_success(name)
10
- stub_check(name).returns([true, "Up"])
10
+ stub_check(name).returns([ true, "Up" ])
11
11
  end
12
12
 
13
13
  def stub_service_failure(name)
14
- stub_check(name).returns([false, "Down"])
14
+ stub_check(name).returns([ false, "Down" ])
15
15
  end
16
16
  end
17
17
  end
@@ -1,3 +1,3 @@
1
1
  module Easymon
2
- VERSION = "1.6.3"
2
+ VERSION = "1.6.4"
3
3
  end
data/lib/easymon.rb CHANGED
@@ -9,6 +9,7 @@ require "easymon/result"
9
9
 
10
10
  require "easymon/checks/active_record_check"
11
11
  require "easymon/checks/active_record_mysql_writeable_check"
12
+ require "easymon/checks/multi_active_record_check"
12
13
  require "easymon/checks/split_active_record_check"
13
14
  require "easymon/checks/redis_check"
14
15
  require "easymon/checks/redis_writeable_check"
@@ -55,25 +56,25 @@ module Easymon
55
56
  # Rails 2.3.x (anything less than 3, really)
56
57
  $:.unshift File.expand_path(File.join(
57
58
  File.dirname(__FILE__),
58
- "..","app","controllers"))
59
- require 'easymon/checks_controller'
59
+ "..", "app", "controllers"))
60
+ require "easymon/checks_controller"
60
61
 
61
62
  mapper.instance_eval do
62
- connect "#{path}.:format", :controller => "easymon/checks", :action => "index"
63
- connect "#{path}/:check.:format", :controller => "easymon/checks", :action => "show"
63
+ connect "#{path}.:format", controller: "easymon/checks", action: "index"
64
+ connect "#{path}/:check.:format", controller: "easymon/checks", action: "show"
64
65
  end
65
66
  elsif Easymon.rails30?
66
67
  # Greater than 3.0, but less than 3.1
67
68
  mapper.instance_eval do
68
- get "#{path}(.:format)", :controller => 'easymon/checks', :action => 'index'
69
- get "#{path}/:check", :controller => 'easymon/checks', :action => 'show'
69
+ get "#{path}(.:format)", controller: "easymon/checks", action: "index"
70
+ get "#{path}/:check", controller: "easymon/checks", action: "show"
70
71
  end
71
72
  elsif Easymon.mountable_engine?
72
73
  # Rails 3.1+
73
74
  mapper.instance_eval do
74
- get "/(.:format)", :to => "checks#index"
75
- root :to => "checks#index"
76
- get "/:check", :to => "checks#show"
75
+ get "/(.:format)", to: "checks#index"
76
+ root to: "checks#index"
77
+ get "/:check", to: "checks#show"
77
78
  end
78
79
  end
79
80
  end
@@ -1,8 +1,7 @@
1
- require 'test_helper'
1
+ require "test_helper"
2
2
 
3
3
  module Easymon
4
4
  class ChecksControllerTest < ActionController::TestCase
5
-
6
5
  setup do
7
6
  @routes = Easymon::Engine.routes
8
7
  Easymon.authorize_with = nil
@@ -23,7 +22,7 @@ module Easymon
23
22
 
24
23
  test "index when a check fails" do
25
24
  Easymon::Repository.add("database", Easymon::ActiveRecordCheck.new(ActiveRecord::Base))
26
- Easymon::Repository.add("redis", Easymon::RedisCheck.new(YAML.load_file(Rails.root.join("config/redis.yml"))[Rails.env].symbolize_keys))
25
+ Easymon::Repository.add("redis", Easymon::RedisCheck.new(YAML.load_file(Rails.root.join("config/redis.yml"), aliases: true)[Rails.env].symbolize_keys))
27
26
  Redis.any_instance.stubs(:ping).raises("boom")
28
27
  get :index
29
28
  assert_response :service_unavailable
@@ -41,7 +40,7 @@ module Easymon
41
40
 
42
41
  test "index when a non-critical check fails" do
43
42
  Easymon::Repository.add("database", Easymon::ActiveRecordCheck.new(ActiveRecord::Base), :critical)
44
- Easymon::Repository.add("redis", Easymon::RedisCheck.new(YAML.load_file(Rails.root.join("config/redis.yml"))[Rails.env].symbolize_keys))
43
+ Easymon::Repository.add("redis", Easymon::RedisCheck.new(YAML.load_file(Rails.root.join("config/redis.yml"), aliases: true)[Rails.env].symbolize_keys))
45
44
  Redis.any_instance.stubs(:ping).raises("boom")
46
45
  get :index
47
46
  assert_response :success
@@ -51,7 +50,7 @@ module Easymon
51
50
 
52
51
  test "index returns valid json" do
53
52
  Easymon::Repository.add("database", Easymon::ActiveRecordCheck.new(ActiveRecord::Base))
54
- get :index, :format => :json
53
+ get :index, format: :json
55
54
 
56
55
  json = JSON.parse(response.body)
57
56
 
@@ -61,14 +60,14 @@ module Easymon
61
60
 
62
61
  test "show when the check passes" do
63
62
  Easymon::Repository.add("database", Easymon::ActiveRecordCheck.new(ActiveRecord::Base))
64
- get :show, :params => { check: "database" }
63
+ get :show, params: { check: "database" }
65
64
  assert_response :success
66
65
  assert response.body.include?("Up"), "Response should include message text, got #{response.body}"
67
66
  end
68
67
 
69
68
  test "show json when the check passes" do
70
69
  Easymon::Repository.add("database", Easymon::ActiveRecordCheck.new(ActiveRecord::Base))
71
- get :show, :params => { :check => "database", :format => :json }
70
+ get :show, params: { check: "database", format: :json }
72
71
 
73
72
  json = JSON.parse(response.body)
74
73
 
@@ -80,16 +79,16 @@ module Easymon
80
79
  Easymon::Repository.add("database", Easymon::ActiveRecordCheck.new(ActiveRecord::Base))
81
80
  ActiveRecord::Base.connection.stubs(:active?).raises("boom")
82
81
 
83
- get :show, :params => { :check => "database" }
82
+ get :show, params: { check: "database" }
84
83
 
85
84
  assert_response :service_unavailable
86
85
  assert response.body.include?("Down"), "Response should include failure text, got #{response.body}"
87
86
  end
88
87
 
89
88
  test "show if the check is not found" do
90
- Easymon::Repository.names.each {|name| Easymon::Repository.remove(name)}
89
+ Easymon::Repository.names.each { |name| Easymon::Repository.remove(name) }
91
90
 
92
- get :show, :params => { :check => "database" }
91
+ get :show, params: { check: "database" }
93
92
  assert_response :not_found
94
93
  end
95
94
 
@@ -99,7 +98,7 @@ module Easymon
99
98
  get :index
100
99
  assert_response :forbidden
101
100
 
102
- get :show, :params => { :check => "database" }
101
+ get :show, params: { check: "database" }
103
102
  assert_response :forbidden
104
103
  end
105
104
  end