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
@@ -5,24 +5,29 @@ module StatusCat
|
|
5
5
|
include ActionView::Helpers::DateHelper
|
6
6
|
|
7
7
|
def initialize
|
8
|
-
if
|
9
|
-
|
10
|
-
|
11
|
-
@status = fail_on_exception do
|
12
|
-
sql = 'select count(*) from delayed_jobs where failed_at is null'
|
13
|
-
result = ::ActiveRecord::Base.connection.execute( sql ).first
|
14
|
-
@value = result.is_a?( Hash ) ? result[ 'count' ] : result[ 0 ]
|
8
|
+
return if gem_missing?('delayed_job', defined?(::Delayed))
|
9
|
+
@status = fail_on_exception { test }
|
10
|
+
end
|
15
11
|
|
16
|
-
|
17
|
-
|
18
|
-
result = ::ActiveRecord::Base.connection.execute( sql ).first
|
19
|
-
value = result.is_a?( Hash ) ? result[ 'count' ] : result[ 0 ]
|
12
|
+
def test
|
13
|
+
@value = count_jobs
|
20
14
|
|
21
|
-
|
22
|
-
|
23
|
-
|
15
|
+
expires = 1.day.ago
|
16
|
+
expired = count_expired(expires)
|
17
|
+
expired.zero? ? nil : "#{expired} jobs more than #{time_ago_in_words(expires)} old"
|
18
|
+
end
|
19
|
+
|
20
|
+
def count_jobs
|
21
|
+
sql = 'select count(*) from delayed_jobs where failed_at is null'
|
22
|
+
result = ::ActiveRecord::Base.connection.execute(sql).first
|
23
|
+
return result.is_a?(Hash) ? result['count'] : result[0]
|
24
24
|
end
|
25
|
-
end
|
26
25
|
|
26
|
+
def count_expired(expires)
|
27
|
+
sql = "select count(*) from delayed_jobs where created_at < '#{expires.to_s(:db)}' and failed_at is null"
|
28
|
+
result = ::ActiveRecord::Base.connection.execute(sql).first
|
29
|
+
return result.is_a?(Hash) ? result['count'] : result[0]
|
30
|
+
end
|
31
|
+
end
|
27
32
|
end
|
28
|
-
end
|
33
|
+
end
|
@@ -1,20 +1,29 @@
|
|
1
1
|
module StatusCat
|
2
2
|
module Checkers
|
3
3
|
class Fitbit < Base
|
4
|
+
|
5
|
+
cattr_accessor :consumer_key
|
6
|
+
cattr_accessor :consumer_secret
|
7
|
+
cattr_accessor :test_token
|
8
|
+
cattr_accessor :test_secret
|
9
|
+
cattr_accessor :test_user_id
|
10
|
+
|
4
11
|
def initialize
|
5
|
-
|
12
|
+
return if gem_missing?('fitgem', defined?(::Fitgem))
|
13
|
+
|
14
|
+
@value = consumer_key
|
6
15
|
@status = fail_on_exception do
|
7
16
|
user_info = ::Fitgem::Client.new(
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
17
|
+
consumer_key: consumer_key,
|
18
|
+
consumer_secret: consumer_secret,
|
19
|
+
token: test_token,
|
20
|
+
secret: test_secret,
|
21
|
+
user_id: test_user_id
|
22
|
+
).user_info
|
14
23
|
|
15
|
-
user_info[
|
24
|
+
user_info['errors'] ? user_info.inspect : nil
|
16
25
|
end
|
17
26
|
end
|
18
27
|
end
|
19
28
|
end
|
20
|
-
end
|
29
|
+
end
|
@@ -1,8 +1,11 @@
|
|
1
1
|
module StatusCat
|
2
2
|
module Checkers
|
3
3
|
class Profilesio < Base
|
4
|
+
|
5
|
+
cattr_accessor :api_key
|
6
|
+
|
4
7
|
def initialize
|
5
|
-
@value =
|
8
|
+
@value = api_key
|
6
9
|
@status = fail_on_exception do
|
7
10
|
response = ::HTTParty.get('https://profiles.io/record/register')
|
8
11
|
response.code == 200 ? nil : 'fail'
|
@@ -3,17 +3,16 @@ module StatusCat
|
|
3
3
|
class S3 < Base
|
4
4
|
|
5
5
|
def initialize
|
6
|
-
if
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
@status = fail_on_exception do
|
11
|
-
s3 = AWS::S3.new
|
12
|
-
( s3.buckets.count > 0 ) ? nil : 'no buckets'
|
13
|
-
end
|
14
|
-
end
|
6
|
+
return if gem_missing?('aws-sdk', defined?(::Aws))
|
7
|
+
|
8
|
+
@value = Aws.config[:credentials].access_key_id
|
9
|
+
@status = fail_on_exception { test }
|
15
10
|
end
|
16
11
|
|
12
|
+
def test
|
13
|
+
s3 = Aws::S3::Resource.new
|
14
|
+
return s3.buckets.count.zero? ? 'no buckets' : nil
|
15
|
+
end
|
17
16
|
end
|
18
17
|
end
|
19
|
-
end
|
18
|
+
end
|
@@ -1,13 +1,19 @@
|
|
1
1
|
module StatusCat
|
2
2
|
module Checkers
|
3
3
|
class SendHub < Base
|
4
|
+
|
5
|
+
cattr_accessor :api_key
|
6
|
+
cattr_accessor :number
|
7
|
+
|
4
8
|
def initialize
|
5
|
-
|
9
|
+
return if gem_missing?('ruby-sendhub', defined?(::SendHub))
|
10
|
+
|
11
|
+
@value = number
|
6
12
|
@status = fail_on_exception do
|
7
|
-
send_hub = ::SendHub.new(
|
13
|
+
send_hub = ::SendHub.new(api_key, number)
|
8
14
|
send_hub.get_contacts ? nil : 'fail'
|
9
15
|
end
|
10
16
|
end
|
11
17
|
end
|
12
18
|
end
|
13
|
-
end
|
19
|
+
end
|
@@ -2,18 +2,23 @@ module StatusCat
|
|
2
2
|
module Checkers
|
3
3
|
|
4
4
|
class Stripe < Base
|
5
|
+
|
5
6
|
def initialize
|
6
|
-
if
|
7
|
-
|
8
|
-
|
9
|
-
@
|
10
|
-
|
11
|
-
@value = account.email
|
12
|
-
account.charge_enabled ? nil : 'Charge is not enabled'
|
13
|
-
end
|
7
|
+
return if gem_missing?('stripe', defined?(::Stripe))
|
8
|
+
|
9
|
+
@status = fail_on_exception do
|
10
|
+
@value = account.email
|
11
|
+
test
|
14
12
|
end
|
15
13
|
end
|
16
|
-
end
|
17
14
|
|
15
|
+
def test
|
16
|
+
return account.charge_enabled ? nil : 'Charge is not enabled'
|
17
|
+
end
|
18
|
+
|
19
|
+
def account
|
20
|
+
return ::Stripe::Account.retrieve
|
21
|
+
end
|
22
|
+
end
|
18
23
|
end
|
19
|
-
end
|
24
|
+
end
|
@@ -1,13 +1,19 @@
|
|
1
1
|
module StatusCat
|
2
2
|
module Checkers
|
3
3
|
class Twilio < Base
|
4
|
+
|
5
|
+
cattr_accessor :sid
|
6
|
+
cattr_accessor :auth_token
|
7
|
+
|
4
8
|
def initialize
|
5
|
-
|
9
|
+
return if gem_missing?('twilio-ruby', defined?(::Twilio))
|
10
|
+
|
11
|
+
@value = sid
|
6
12
|
@status = fail_on_exception do
|
7
|
-
twilio = ::Twilio::REST::Client.new(
|
8
|
-
twilio.account.messages.total ? nil : 'fail'
|
13
|
+
twilio = ::Twilio::REST::Client.new(sid, auth_token)
|
14
|
+
twilio.api.account.messages.total ? nil : 'fail'
|
9
15
|
end
|
10
16
|
end
|
11
17
|
end
|
12
18
|
end
|
13
|
-
end
|
19
|
+
end
|
data/lib/status_cat/config.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'singleton'
|
2
2
|
|
3
3
|
module StatusCat
|
4
|
-
|
5
4
|
class Config
|
6
5
|
include Singleton
|
7
6
|
|
@@ -13,9 +12,8 @@ module StatusCat
|
|
13
12
|
attr_accessor :layout
|
14
13
|
|
15
14
|
def initialize
|
16
|
-
|
17
|
-
|
18
|
-
}.sort
|
15
|
+
descendants = StatusCat::Checkers::Base.descendants
|
16
|
+
@enabled = descendants.map { |klass| StatusCat::Checkers::Base.class_to_name(klass) }.sort
|
19
17
|
end
|
20
18
|
|
21
19
|
def authenticate_with(&blk)
|
@@ -27,7 +25,5 @@ module StatusCat
|
|
27
25
|
@authorize = block if block
|
28
26
|
@authorize || NIL_PROC
|
29
27
|
end
|
30
|
-
|
31
28
|
end
|
32
|
-
|
33
|
-
end
|
29
|
+
end
|
data/lib/status_cat/status.rb
CHANGED
@@ -4,34 +4,32 @@ module StatusCat
|
|
4
4
|
|
5
5
|
# Returns an array of instances of StatusCat::Checkers::Base subclasses
|
6
6
|
def self.all
|
7
|
-
StatusCat::Config.instance.enabled.map { |name| factory(
|
7
|
+
StatusCat::Config.instance.enabled.map { |name| factory(name) }
|
8
8
|
end
|
9
9
|
|
10
10
|
# By default, returns all checkers
|
11
11
|
# If given a list of checker names, returns an array of those checkers
|
12
12
|
# If given a single checker name, just returns that checker
|
13
|
-
def self.check(
|
13
|
+
def self.check(which = :all)
|
14
14
|
return all if which == :all
|
15
|
-
return factory(
|
16
|
-
return which.map { |name| factory(
|
15
|
+
return factory(which) unless which.is_a?(Array)
|
16
|
+
return which.map { |name| factory(name) }
|
17
17
|
end
|
18
18
|
|
19
19
|
# Emails ::failed list if it is not empty
|
20
20
|
def self.cron
|
21
|
-
checkers =
|
22
|
-
StatusCat::StatusMailer.failure(
|
21
|
+
checkers = failed
|
22
|
+
StatusCat::StatusMailer.failure(checkers).deliver_now unless checkers.empty?
|
23
23
|
end
|
24
24
|
|
25
25
|
# Constructs a checker instance given it's name
|
26
|
-
def self.factory(
|
27
|
-
(
|
26
|
+
def self.factory(name)
|
27
|
+
('StatusCat::Checkers::' + name.to_s.classify).constantize.new
|
28
28
|
end
|
29
29
|
|
30
30
|
# Returns an array of failed instances of ::all
|
31
31
|
def self.failed
|
32
|
-
|
32
|
+
all.map { |checker| checker.status.nil? ? nil : checker }.compact
|
33
33
|
end
|
34
|
-
|
35
34
|
end
|
36
|
-
|
37
35
|
end
|
data/lib/status_cat/version.rb
CHANGED
data/lib/tasks/status_cat.rake
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
namespace :status_cat do
|
2
2
|
|
3
3
|
desc 'Run all checkers and output results'
|
4
|
-
task :
|
4
|
+
task check: :environment do
|
5
5
|
include StatusCat::StatusHelper
|
6
|
-
Kernel.puts status_report(
|
6
|
+
Kernel.puts status_report(StatusCat::Status.all)
|
7
7
|
end
|
8
8
|
|
9
9
|
desc 'Run all checkers and email failures'
|
10
|
-
task :
|
10
|
+
task cron: :environment do
|
11
11
|
StatusCat::Status.cron
|
12
12
|
end
|
13
|
-
|
14
13
|
end
|
@@ -6,29 +6,29 @@ describe StatusCat::StatusController do
|
|
6
6
|
|
7
7
|
it 'gets successfully' do
|
8
8
|
get :index
|
9
|
-
expect(
|
9
|
+
expect(response).to be_success
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'assigns @checkers to StatusCat::Status.all' do
|
13
13
|
get :index
|
14
14
|
|
15
|
-
@checkers = assigns[
|
16
|
-
expect(
|
17
|
-
expect(
|
18
|
-
@checkers.each { |checker| expect(
|
15
|
+
@checkers = assigns[:checkers]
|
16
|
+
expect(@checkers).to_not be(nil)
|
17
|
+
expect(@checkers.length).to eql(StatusCat::Status.all.length)
|
18
|
+
@checkers.each { |checker| expect(checker).to be_a_kind_of(StatusCat::Checkers::Base) }
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'uses the configured before authentication filter' do
|
22
|
-
allow(
|
23
|
-
expect(
|
24
|
-
expect(
|
22
|
+
allow(Rails.env).to receive(:test?).and_return(false)
|
23
|
+
expect(controller).to receive(:authenticate!)
|
24
|
+
expect(controller).to receive(:authorize!)
|
25
25
|
|
26
26
|
get :index
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'renders with the configured layout' do
|
30
30
|
get :index
|
31
|
-
expect(
|
31
|
+
expect(response).to render_template(StatusCat.config.layout)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
@@ -4,17 +4,16 @@ class RootController < ApplicationController
|
|
4
4
|
end
|
5
5
|
|
6
6
|
def mail
|
7
|
-
StatusCat::StatusMailer.failure(
|
7
|
+
StatusCat::StatusMailer.failure(StatusCat::Status.all).deliver
|
8
8
|
end
|
9
9
|
|
10
10
|
def login
|
11
|
-
cookies[
|
12
|
-
redirect_to :
|
11
|
+
cookies[:login] = { value: true, expires: 10.years.from_now }
|
12
|
+
redirect_to action: :index
|
13
13
|
end
|
14
14
|
|
15
15
|
def logout
|
16
|
-
cookies.delete(
|
17
|
-
redirect_to :
|
16
|
+
cookies.delete(:login)
|
17
|
+
redirect_to action: :index
|
18
18
|
end
|
19
|
-
|
20
|
-
end
|
19
|
+
end
|
data/spec/dummy/config.ru
CHANGED
@@ -46,7 +46,7 @@ Dummy::Application.configure do
|
|
46
46
|
# config.action_controller.asset_host = "http://assets.example.com"
|
47
47
|
|
48
48
|
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
|
49
|
-
# config.assets.precompile += %w(
|
49
|
+
# config.assets.precompile += %w(search.js)
|
50
50
|
|
51
51
|
# Disable delivery errors, bad email addresses will be ignored
|
52
52
|
# config.action_mailer.raise_delivery_errors = false
|
@@ -1,8 +1,8 @@
|
|
1
1
|
if Rails.env.test?
|
2
2
|
ActionMailer::Base.delivery_method = :test
|
3
3
|
else
|
4
|
-
yaml = YAML::load(
|
5
|
-
passwords = HashWithIndifferentAccess.new(
|
4
|
+
yaml = YAML::load(IO.read(File.join(Rails.root, 'config', 'passwords.yml')))
|
5
|
+
passwords = HashWithIndifferentAccess.new(yaml[ Rails.env ])
|
6
6
|
|
7
7
|
ActionMailer::Base.delivery_method = :smtp
|
8
8
|
ActionMailer::Base.smtp_settings = {
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# inflect.plural /^(ox)$/i, '\1en'
|
7
7
|
# inflect.singular /^(ox)en/i, '\1'
|
8
8
|
# inflect.irregular 'person', 'people'
|
9
|
-
# inflect.uncountable %w(
|
9
|
+
# inflect.uncountable %w(fish sheep)
|
10
10
|
# end
|
11
11
|
#
|
12
12
|
# These inflection rules are supported but not enabled by default:
|