status_cat 0.1.1 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +15 -11
  3. data/app/controllers/status_cat/status_controller.rb +19 -18
  4. data/app/helpers/status_cat/status_helper.rb +69 -64
  5. data/app/mailers/status_cat/status_mailer.rb +9 -8
  6. data/app/views/status_cat/status/index.html.erb +1 -1
  7. data/app/views/status_cat/status_mailer/failure.html.erb +1 -1
  8. data/app/views/status_cat/status_mailer/failure.text.erb +1 -1
  9. data/lib/status_cat.rb +1 -1
  10. data/lib/status_cat/checkers/action_mailer.rb +33 -17
  11. data/lib/status_cat/checkers/active_record.rb +22 -7
  12. data/lib/status_cat/checkers/base.rb +16 -9
  13. data/lib/status_cat/checkers/delayed_job.rb +21 -16
  14. data/lib/status_cat/checkers/fitbit.rb +18 -9
  15. data/lib/status_cat/checkers/profilesio.rb +4 -1
  16. data/lib/status_cat/checkers/s3.rb +9 -10
  17. data/lib/status_cat/checkers/send_hub.rb +9 -3
  18. data/lib/status_cat/checkers/stripe.rb +15 -10
  19. data/lib/status_cat/checkers/twilio.rb +10 -4
  20. data/lib/status_cat/config.rb +3 -7
  21. data/lib/status_cat/status.rb +9 -11
  22. data/lib/status_cat/version.rb +1 -1
  23. data/lib/tasks/status_cat.rake +3 -4
  24. data/spec/controllers/status_cat/status_controller_spec.rb +9 -9
  25. data/spec/dummy/app/checkers/dummy.rb +2 -2
  26. data/spec/dummy/app/controllers/application_controller.rb +2 -1
  27. data/spec/dummy/app/controllers/root_controller.rb +6 -7
  28. data/spec/dummy/config.ru +1 -1
  29. data/spec/dummy/config/application.rb +2 -2
  30. data/spec/dummy/config/environments/production.rb +1 -1
  31. data/spec/dummy/config/initializers/action_mailer.rb +2 -2
  32. data/spec/dummy/config/initializers/inflections.rb +1 -1
  33. data/spec/dummy/config/passwords.yml +5 -0
  34. data/spec/dummy/config/routes.rb +2 -2
  35. data/spec/dummy/db/development.sqlite3 +0 -0
  36. data/spec/dummy/db/schema.rb +0 -1
  37. data/spec/dummy/db/test.sqlite3 +0 -0
  38. data/spec/dummy/log/development.log +36 -0
  39. data/spec/dummy/log/test.log +16588 -13366
  40. data/spec/helpers/status_cat/status_helper_spec.rb +33 -33
  41. data/spec/hygiene_spec.rb +14 -0
  42. data/spec/lib/status_cat/checkers/action_mailer_spec.rb +15 -18
  43. data/spec/lib/status_cat/checkers/active_record_spec.rb +10 -10
  44. data/spec/lib/status_cat/checkers/base_spec.rb +30 -14
  45. data/spec/lib/status_cat/checkers/delayed_job_spec.rb +14 -16
  46. data/spec/lib/status_cat/checkers/fitbit_spec.rb +14 -8
  47. data/spec/lib/status_cat/checkers/profilesio_spec.rb +12 -12
  48. data/spec/lib/status_cat/checkers/s3_spec.rb +17 -18
  49. data/spec/lib/status_cat/checkers/send_hub_spec.rb +14 -8
  50. data/spec/lib/status_cat/checkers/stripe_spec.rb +18 -24
  51. data/spec/lib/status_cat/checkers/twilio_spec.rb +14 -8
  52. data/spec/lib/status_cat/config_spec.rb +32 -33
  53. data/spec/lib/status_cat/engine_spec.rb +2 -2
  54. data/spec/lib/status_cat/status_spec.rb +31 -32
  55. data/spec/lib/status_cat/version_spec.rb +4 -4
  56. data/spec/lib/status_cat_spec.rb +3 -3
  57. data/spec/lib/tasks/status_cat.rake_spec.rb +6 -6
  58. data/spec/mailers/status_cat/status_mailer_spec.rb +11 -12
  59. data/spec/spec_helper.rb +35 -16
  60. data/spec/support/shared/checker.rb +5 -6
  61. data/spec/views/status_cat/status/index.html.erb_spec.rb +8 -9
  62. data/spec/views/status_cat/status_mailer/failure.html.erb_spec.rb +4 -6
  63. data/spec/views/status_cat/status_mailer/failure.text.erb_spec.rb +4 -4
  64. metadata +69 -117
  65. data/spec/coverage_spec.rb +0 -20
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0ac65c223e10fd528530d66c77a8c4faa08c766f
4
- data.tar.gz: 1140f72ea64a6300ccff6d24587f911d98ea13f8
3
+ metadata.gz: c1f24af8d2c53c9ce0f534ab8fd91cc6f56a8c1b
4
+ data.tar.gz: 68cfac7ad65fc2fb391384f8ee9b2094e682492f
5
5
  SHA512:
6
- metadata.gz: 54b688cdeb93d39a70dd877ec14adeebb209ebed46e6f20bc5cbdcdaa3bfb437afb02e7da42cfd64107c62d1632f3978a4c0a2dba28d02bc7f28ad71cab5c93e
7
- data.tar.gz: 1be6f957bfb9bf1bbb707920c501c89230ef0e15e105b53a396a21483522de10a7b61307508a87c065d9b90780bb10f4323df9988326adbe9bb6f919c3571d8f
6
+ metadata.gz: 8733e4562489e67b2cf667226b2dc42de2c1ffee7b75d5d470f9872081d17ce721cfd482b901869466ca112429fc9c8feea378026dea561103df700cd8dcc88d
7
+ data.tar.gz: b073af12cb9fbd987830e20409f50c6ec950924e394b1fd42b872bd60ba4eb295c5ed40eca1669205595226d724876dd0d68cd005b4e7668b961efd15b0666d0
data/README.md CHANGED
@@ -40,7 +40,7 @@ such as:
40
40
 
41
41
  ## Configuration
42
42
 
43
- All configuration should go in `config/initializers/status_cat.rb`.
43
+ General configuration should go in `config/initializers/status_cat.rb`.
44
44
 
45
45
  Status.configure do |config|
46
46
 
@@ -61,6 +61,14 @@ such as:
61
61
 
62
62
  config.enabled = [ :action_mailer, :active_record ]
63
63
  end
64
+
65
+ Checker specific configuration should in the initializer it relates to,
66
+ so it will be kept in sync. i.e. `config/initializers/twilio.rb`
67
+
68
+ Twilio.configure do |config|
69
+ config.account_sid = StatusCat::Checkers::Twilio.sid = ENV['TWILIO_SID']
70
+ config.auth_token = StatusCat::Checkers::Twilio.auth_token = ENV['TWILIO_AUTH_TOKEN']
71
+ end
64
72
 
65
73
  ## How To
66
74
 
@@ -139,6 +147,11 @@ Create or add to `config/initializers/status_cat.rb`
139
147
  StatusCat.configure do |config|
140
148
  config.layout = 'admin'
141
149
  end
150
+
151
+ ### Get Started Developing
152
+
153
+ 1. `cp spec/dummy/config/passwords.yml.sample spec/dummy/config/passwords.yml`
154
+ 2. `rake app:db:create app:db:migrate app:db:test:prepare`
142
155
 
143
156
  ## Reference
144
157
 
@@ -157,16 +170,7 @@ Create or add to `config/initializers/status_cat.rb`
157
170
 
158
171
  * Version 0.0.2 = Rails 3 compatible
159
172
  * Version 0.0.3 = Rails 4 compatible
173
+ * Version 5.0.0 = Rails 5 compatible
160
174
 
161
- ## TODO
162
-
163
- * Add disk space checker with externally configurable limit
164
- * Add Zencoder checker?
165
- * Add NewRelic checker?
166
175
 
167
- * Dynamically create rake tasks for each checker
168
176
 
169
- * Doc
170
- * General checker concept
171
- * Shared spec
172
- * Env vars to configure services
@@ -1,26 +1,27 @@
1
- class StatusCat::StatusController < ApplicationController
1
+ module StatusCat
2
+ class StatusController < ApplicationController
2
3
 
3
- layout :set_layout
4
+ layout :set_layout
4
5
 
5
- before_filter :_authenticate!
6
- before_filter :_authorize!
6
+ before_action :_authenticate!
7
+ before_action :_authorize!
7
8
 
8
- def index
9
- @checkers = StatusCat::Status.all
10
- end
9
+ def index
10
+ @checkers = StatusCat::Status.all
11
+ end
11
12
 
12
- private
13
+ private
13
14
 
14
- def set_layout
15
- return StatusCat.config.layout
16
- end
15
+ def set_layout
16
+ return StatusCat.config.layout
17
+ end
17
18
 
18
- def _authenticate!
19
- instance_eval( &StatusCat.config.authenticate_with )
20
- end
19
+ def _authenticate!
20
+ instance_eval(&StatusCat.config.authenticate_with)
21
+ end
21
22
 
22
- def _authorize!
23
- instance_eval( &StatusCat.config.authorize_with )
23
+ def _authorize!
24
+ instance_eval(&StatusCat.config.authorize_with)
25
+ end
24
26
  end
25
-
26
- end
27
+ end
@@ -1,90 +1,95 @@
1
- module StatusCat::StatusHelper
1
+ module StatusCat
2
+ module StatusHelper
2
3
 
3
- # Constructs an HTML table header
4
+ # Constructs an HTML table header
4
5
 
5
- def status_header
6
- content_tag( :tr ) do
7
- concat content_tag( :th, t( :name, :scope => :status_cat ) )
8
- concat content_tag( :th, t( :value, :scope => :status_cat ) )
9
- concat content_tag( :th, t( :status, :scope => :status_cat ) )
6
+ def status_header
7
+ content_tag(:tr) do
8
+ concat content_tag(:th, t(:name, scope: :status_cat))
9
+ concat content_tag(:th, t(:value, scope: :status_cat))
10
+ concat content_tag(:th, t(:status, scope: :status_cat))
11
+ end
10
12
  end
11
- end
12
13
 
13
- # Constructs an HTML table row
14
+ # Constructs an HTML table row
14
15
 
15
- def status_row( checker )
16
- content_tag( :tr ) do
17
- concat content_tag( :td, checker.name, :style => status_style( checker ) )
18
- concat content_tag( :td, checker.value )
19
- concat status_cell(checker.status || t( :ok, :scope => :status_cat ))
16
+ def status_row(checker)
17
+ content_tag(:tr) do
18
+ concat content_tag(:td, checker.name, style: status_style(checker))
19
+ concat content_tag(:td, checker.value)
20
+ concat status_cell(checker.status || t(:ok, scope: :status_cat))
21
+ end
20
22
  end
21
- end
22
23
 
23
- def status_cell( status )
24
- if status.kind_of?(Array)
25
- list = status.map { |s| content_tag( :li, s ) }
26
- status = content_tag( :ul, list.join.html_safe )
27
- end
24
+ def status_cell(status)
25
+ if status.is_a?(Array)
26
+ list = status.map { |s| content_tag(:li, s) }
27
+ status = content_tag(:ul, list.join.html_safe)
28
+ end
28
29
 
29
- return content_tag( :td, status )
30
- end
30
+ return content_tag(:td, status)
31
+ end
31
32
 
32
- # Returns an HTML style for the status table cell
33
+ # Returns an HTML style for the status table cell
33
34
 
34
- def status_style( checker )
35
- "background-color: #{checker.status.nil? ? :green : :red}"
36
- end
35
+ def status_style(checker)
36
+ "background-color: #{checker.status.nil? ? :green : :red}"
37
+ end
37
38
 
38
- # Returns an HTML table
39
+ # Returns an HTML table
39
40
 
40
- def status_table( checkers )
41
- content_tag( :table, :border => 1 ) do
42
- concat status_header
43
- checkers.each { |checker| concat status_row( checker ) }
41
+ def status_table(checkers)
42
+ content_tag(:table, border: 1) do
43
+ concat status_header
44
+ checkers.each { |checker| concat status_row(checker) }
45
+ end
44
46
  end
45
- end
46
47
 
47
- # Returns an HTML title
48
+ # Returns an HTML title
48
49
 
49
- def status_title
50
- content_tag( :h1, t( :h1, :scope => :status_cat ) )
51
- end
50
+ def status_title
51
+ content_tag(:h1, t(:h1, scope: :status_cat))
52
+ end
52
53
 
53
- # Constructs a text status report
54
+ # Constructs a text status report
54
55
 
55
- def status_report( checkers )
56
- format, format_length = status_report_format( checkers )
57
- header = status_report_header( format )
58
- length = [ format_length, header.length ].max
59
- separator = ( '-' * length ) + "\n"
56
+ def status_report(checkers)
57
+ format, format_length = status_report_format(checkers)
58
+ header = status_report_header(format)
59
+ length = [format_length, header.length].max
60
+ separator = ('-' * length) + "\n"
60
61
 
61
- result = separator + header + separator
62
- checkers.each { |checker| result << checker.to_s( format ) }
63
- result << separator
62
+ result = separator + header + separator
63
+ checkers.each { |checker| result << checker.to_s(format) }
64
+ result << separator
64
65
 
65
- return result
66
- end
66
+ return result
67
+ end
67
68
 
68
- # Generate a format string to justify all values
69
+ # Generate a format string to justify all values
69
70
 
70
- def status_report_format( checkers )
71
- name_max = checkers.map { |c| c.name.to_s.length }.max
72
- value_max = checkers.map { |c| c.value.to_s.length }.max
73
- status_max = checkers.map { |c| c.status.to_s.length }.max
71
+ def status_report_format(checkers)
72
+ name_max = status_report_format_max_length(checkers, :name)
73
+ value_max = status_report_format_max_length(checkers, :value)
74
+ status_max = status_report_format_max_length(checkers, :status)
74
75
 
75
- format = "%#{name_max}s | %#{value_max}s | %#{status_max}s\n"
76
- length = name_max + 3 + value_max + 3 + status_max
76
+ format = "%#{name_max}s | %#{value_max}s | %#{status_max}s\n"
77
+ length = name_max + 3 + value_max + 3 + status_max
77
78
 
78
- return format, length
79
- end
79
+ return format, length
80
+ end
80
81
 
81
- # Generate a header string
82
+ def status_report_format_max_length(checkers, column)
83
+ return checkers.map { |c| c.send(column).to_s.length }.max
84
+ end
82
85
 
83
- def status_report_header( format = StatusCat::Checkers::Base::FORMAT )
84
- name = I18n.t( :name, :scope => :status_cat )
85
- value = I18n.t( :value, :scope => :status_cat )
86
- status = I18n.t( :status, :scope => :status_cat )
87
- return sprintf( format, name, value, status )
88
- end
86
+ # Generate a header string
89
87
 
90
- end
88
+ def status_report_header(format = StatusCat::Checkers::Base::FORMAT)
89
+ name = I18n.t(:name, scope: :status_cat)
90
+ value = I18n.t(:value, scope: :status_cat)
91
+ status = I18n.t(:status, scope: :status_cat)
92
+ return format(format, name, value, status)
93
+ end
94
+ end
95
+ end
@@ -1,12 +1,13 @@
1
- class StatusCat::StatusMailer < ActionMailer::Base
1
+ module StatusCat
2
+ class StatusMailer < ActionMailer::Base
2
3
 
3
- add_template_helper( StatusCat::StatusHelper )
4
+ add_template_helper(StatusCat::StatusHelper)
4
5
 
5
- def failure( checkers )
6
- @checkers = checkers
6
+ def failure(checkers)
7
+ @checkers = checkers
7
8
 
8
- config = StatusCat.config
9
- mail( :to => config.to, :from => config.from, :subject => config.subject )
9
+ config = StatusCat.config
10
+ mail(to: config.to, from: config.from, subject: config.subject)
11
+ end
10
12
  end
11
-
12
- end
13
+ end
@@ -1,4 +1,4 @@
1
1
  <div class="status_cat">
2
2
  <%= status_title %>
3
- <%= status_table( @checkers ) %>
3
+ <%= status_table(@checkers) %>
4
4
  </div>
@@ -4,6 +4,6 @@
4
4
  <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
5
5
  </head>
6
6
  <body>
7
- <%= status_table( @checkers ) %>
7
+ <%= status_table(@checkers) %>
8
8
  </body>
9
9
  </html>
@@ -1 +1 @@
1
- <%= status_report( @checkers ) %>
1
+ <%= status_report(@checkers) %>
data/lib/status_cat.rb CHANGED
@@ -23,4 +23,4 @@ module StatusCat
23
23
  yield config
24
24
  end
25
25
 
26
- end
26
+ end
@@ -3,29 +3,45 @@ module StatusCat
3
3
  class ActionMailer < Base
4
4
 
5
5
  def initialize
6
- @value = "#{config[ :address ]}:#{config[ :port ]}"
7
-
8
- unless ::ActionMailer::Base.delivery_method == :test
9
- @status = fail_on_exception do
10
- address = config[ :address ]
11
- port = config[ :port ]
12
- domain = config[ :domain ]
13
- user_name = config[ :user_name ]
14
- password = config[ :password ]
15
- authentication = config[ :authentication ]
16
-
17
- Net::SMTP.start( address, port, domain, user_name, password, authentication ) do |smtp|
18
- smtp.send_message( '', StatusCat.config.from, StatusCat.config.noreply )
19
- end
20
- nil
21
- end
6
+ @value = "#{address}:#{port}"
7
+ return if ::ActionMailer::Base.delivery_method == :test
8
+ @status = fail_on_exception { test }
9
+ end
10
+
11
+ def test
12
+ Net::SMTP.start(address, port, domain, user_name, password, authentication) do |smtp|
13
+ smtp.helo(domain)
22
14
  end
15
+ return nil
23
16
  end
24
17
 
25
18
  def config
26
19
  @config ||= ::ActionMailer::Base.smtp_settings
27
20
  end
28
21
 
22
+ def address
23
+ return config[:address]
24
+ end
25
+
26
+ def authentication
27
+ return config[:authentication]
28
+ end
29
+
30
+ def domain
31
+ return config[:domain]
32
+ end
33
+
34
+ def password
35
+ return config[:password]
36
+ end
37
+
38
+ def port
39
+ return config[:port]
40
+ end
41
+
42
+ def user_name
43
+ return config[:user_name]
44
+ end
29
45
  end
30
46
  end
31
- end
47
+ end
@@ -3,15 +3,30 @@ module StatusCat
3
3
  class ActiveRecord < Base
4
4
 
5
5
  def initialize
6
- config = ::ActiveRecord::Base.connection_config
7
- @value = "#{config[ :adapter ]}:#{config[ :username ]}@#{config[ :database ]}"
6
+ @value = "#{adapter}:#{username}@#{database}"
7
+ @status = fail_on_exception { test }
8
+ end
9
+
10
+ def test
11
+ ::ActiveRecord::Base.connection.execute('select max(version) from schema_migrations')
12
+ return nil
13
+ end
14
+
15
+ def config
16
+ return ::ActiveRecord::Base.connection_config
17
+ end
18
+
19
+ def adapter
20
+ return config[:adapter]
21
+ end
8
22
 
9
- @status = fail_on_exception do
10
- ::ActiveRecord::Base.connection.execute( "select max(version) from schema_migrations" )
11
- nil
12
- end
23
+ def database
24
+ return config[:database]
13
25
  end
14
26
 
27
+ def username
28
+ return config[:username]
29
+ end
15
30
  end
16
31
  end
17
- end
32
+ end
@@ -3,34 +3,41 @@ module StatusCat
3
3
  class Base
4
4
  extend ActiveSupport::DescendantsTracker
5
5
 
6
- FORMAT = "%s | %s | %s\n"
6
+ FORMAT = "%s | %s | %s\n".freeze
7
7
 
8
8
  attr_reader :value, :status
9
9
 
10
- def self.class_to_name( klass )
11
- klass.to_s.split( '::' ).last.underscore.to_sym
10
+ def self.class_to_name(klass)
11
+ klass.to_s.split('::').last.underscore.to_sym
12
12
  end
13
13
 
14
14
  def name
15
- Base.class_to_name( self.class )
16
- #self.class.to_s.split( '::' ).last.underscore.to_sym
15
+ Base.class_to_name(self.class)
16
+ # self.class.to_s.split('::').last.underscore.to_sym
17
17
  end
18
18
 
19
- def to_s( format = FORMAT )
20
- sprintf( format, name, value, status || I18n.t( :ok, :scope => :status_cat ) )
19
+ def to_s(format = FORMAT)
20
+ format(format, name, value, status || I18n.t(:ok, scope: :status_cat))
21
21
  end
22
22
 
23
- protected
23
+ protected
24
24
 
25
+ # rubocop:disable Lint/RescueException
25
26
  def fail_on_exception
26
27
  begin
27
28
  return yield
28
29
  rescue Exception => e
29
30
  return e
30
31
  end
31
-
32
32
  return nil
33
33
  end
34
+
35
+ def gem_missing?(gem, present)
36
+ return false if present
37
+
38
+ @status = "#{gem} gem is not installed"
39
+ return true
40
+ end
34
41
  end
35
42
  end
36
43
  end