status_cat 0.1.1 → 5.0.0
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.
- checksums.yaml +4 -4
- data/README.md +15 -11
- data/app/controllers/status_cat/status_controller.rb +19 -18
- data/app/helpers/status_cat/status_helper.rb +69 -64
- data/app/mailers/status_cat/status_mailer.rb +9 -8
- data/app/views/status_cat/status/index.html.erb +1 -1
- data/app/views/status_cat/status_mailer/failure.html.erb +1 -1
- data/app/views/status_cat/status_mailer/failure.text.erb +1 -1
- data/lib/status_cat.rb +1 -1
- data/lib/status_cat/checkers/action_mailer.rb +33 -17
- data/lib/status_cat/checkers/active_record.rb +22 -7
- data/lib/status_cat/checkers/base.rb +16 -9
- data/lib/status_cat/checkers/delayed_job.rb +21 -16
- data/lib/status_cat/checkers/fitbit.rb +18 -9
- data/lib/status_cat/checkers/profilesio.rb +4 -1
- data/lib/status_cat/checkers/s3.rb +9 -10
- data/lib/status_cat/checkers/send_hub.rb +9 -3
- data/lib/status_cat/checkers/stripe.rb +15 -10
- data/lib/status_cat/checkers/twilio.rb +10 -4
- data/lib/status_cat/config.rb +3 -7
- data/lib/status_cat/status.rb +9 -11
- data/lib/status_cat/version.rb +1 -1
- data/lib/tasks/status_cat.rake +3 -4
- data/spec/controllers/status_cat/status_controller_spec.rb +9 -9
- data/spec/dummy/app/checkers/dummy.rb +2 -2
- data/spec/dummy/app/controllers/application_controller.rb +2 -1
- data/spec/dummy/app/controllers/root_controller.rb +6 -7
- data/spec/dummy/config.ru +1 -1
- data/spec/dummy/config/application.rb +2 -2
- data/spec/dummy/config/environments/production.rb +1 -1
- data/spec/dummy/config/initializers/action_mailer.rb +2 -2
- data/spec/dummy/config/initializers/inflections.rb +1 -1
- data/spec/dummy/config/passwords.yml +5 -0
- data/spec/dummy/config/routes.rb +2 -2
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/schema.rb +0 -1
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +36 -0
- data/spec/dummy/log/test.log +16588 -13366
- data/spec/helpers/status_cat/status_helper_spec.rb +33 -33
- data/spec/hygiene_spec.rb +14 -0
- data/spec/lib/status_cat/checkers/action_mailer_spec.rb +15 -18
- data/spec/lib/status_cat/checkers/active_record_spec.rb +10 -10
- data/spec/lib/status_cat/checkers/base_spec.rb +30 -14
- data/spec/lib/status_cat/checkers/delayed_job_spec.rb +14 -16
- data/spec/lib/status_cat/checkers/fitbit_spec.rb +14 -8
- data/spec/lib/status_cat/checkers/profilesio_spec.rb +12 -12
- data/spec/lib/status_cat/checkers/s3_spec.rb +17 -18
- data/spec/lib/status_cat/checkers/send_hub_spec.rb +14 -8
- data/spec/lib/status_cat/checkers/stripe_spec.rb +18 -24
- data/spec/lib/status_cat/checkers/twilio_spec.rb +14 -8
- data/spec/lib/status_cat/config_spec.rb +32 -33
- data/spec/lib/status_cat/engine_spec.rb +2 -2
- data/spec/lib/status_cat/status_spec.rb +31 -32
- data/spec/lib/status_cat/version_spec.rb +4 -4
- data/spec/lib/status_cat_spec.rb +3 -3
- data/spec/lib/tasks/status_cat.rake_spec.rb +6 -6
- data/spec/mailers/status_cat/status_mailer_spec.rb +11 -12
- data/spec/spec_helper.rb +35 -16
- data/spec/support/shared/checker.rb +5 -6
- data/spec/views/status_cat/status/index.html.erb_spec.rb +8 -9
- data/spec/views/status_cat/status_mailer/failure.html.erb_spec.rb +4 -6
- data/spec/views/status_cat/status_mailer/failure.text.erb_spec.rb +4 -4
- metadata +69 -117
- data/spec/coverage_spec.rb +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c1f24af8d2c53c9ce0f534ab8fd91cc6f56a8c1b
|
4
|
+
data.tar.gz: 68cfac7ad65fc2fb391384f8ee9b2094e682492f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
1
|
+
module StatusCat
|
2
|
+
class StatusController < ApplicationController
|
2
3
|
|
3
|
-
|
4
|
+
layout :set_layout
|
4
5
|
|
5
|
-
|
6
|
-
|
6
|
+
before_action :_authenticate!
|
7
|
+
before_action :_authorize!
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
def index
|
10
|
+
@checkers = StatusCat::Status.all
|
11
|
+
end
|
11
12
|
|
12
|
-
private
|
13
|
+
private
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
15
|
+
def set_layout
|
16
|
+
return StatusCat.config.layout
|
17
|
+
end
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
def _authenticate!
|
20
|
+
instance_eval(&StatusCat.config.authenticate_with)
|
21
|
+
end
|
21
22
|
|
22
|
-
|
23
|
-
|
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
|
1
|
+
module StatusCat
|
2
|
+
module StatusHelper
|
2
3
|
|
3
|
-
|
4
|
+
# Constructs an HTML table header
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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
|
-
|
14
|
+
# Constructs an HTML table row
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
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
|
-
|
30
|
-
|
30
|
+
return content_tag(:td, status)
|
31
|
+
end
|
31
32
|
|
32
|
-
|
33
|
+
# Returns an HTML style for the status table cell
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
35
|
+
def status_style(checker)
|
36
|
+
"background-color: #{checker.status.nil? ? :green : :red}"
|
37
|
+
end
|
37
38
|
|
38
|
-
|
39
|
+
# Returns an HTML table
|
39
40
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
-
|
48
|
+
# Returns an HTML title
|
48
49
|
|
49
|
-
|
50
|
-
|
51
|
-
|
50
|
+
def status_title
|
51
|
+
content_tag(:h1, t(:h1, scope: :status_cat))
|
52
|
+
end
|
52
53
|
|
53
|
-
|
54
|
+
# Constructs a text status report
|
54
55
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
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
|
-
|
62
|
-
|
63
|
-
|
62
|
+
result = separator + header + separator
|
63
|
+
checkers.each { |checker| result << checker.to_s(format) }
|
64
|
+
result << separator
|
64
65
|
|
65
|
-
|
66
|
-
|
66
|
+
return result
|
67
|
+
end
|
67
68
|
|
68
|
-
|
69
|
+
# Generate a format string to justify all values
|
69
70
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
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
|
-
|
76
|
-
|
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
|
-
|
79
|
-
|
79
|
+
return format, length
|
80
|
+
end
|
80
81
|
|
81
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
1
|
+
module StatusCat
|
2
|
+
class StatusMailer < ActionMailer::Base
|
2
3
|
|
3
|
-
|
4
|
+
add_template_helper(StatusCat::StatusHelper)
|
4
5
|
|
5
|
-
|
6
|
-
|
6
|
+
def failure(checkers)
|
7
|
+
@checkers = checkers
|
7
8
|
|
8
|
-
|
9
|
-
|
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 +1 @@
|
|
1
|
-
<%= status_report(
|
1
|
+
<%= status_report(@checkers) %>
|
data/lib/status_cat.rb
CHANGED
@@ -3,29 +3,45 @@ module StatusCat
|
|
3
3
|
class ActionMailer < Base
|
4
4
|
|
5
5
|
def initialize
|
6
|
-
@value = "#{
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
-
|
7
|
-
@
|
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
|
-
|
10
|
-
|
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(
|
11
|
-
klass.to_s.split(
|
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(
|
16
|
-
#self.class.to_s.split(
|
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(
|
20
|
-
|
19
|
+
def to_s(format = FORMAT)
|
20
|
+
format(format, name, value, status || I18n.t(:ok, scope: :status_cat))
|
21
21
|
end
|
22
22
|
|
23
|
-
|
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
|