server_health_check-rails 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 462bcb33ddff0e63b2fdd82b38cb734578ca4ee0
4
+ data.tar.gz: 4756e7c64b8553709ae490e4db8c8af9b49f1520
5
+ SHA512:
6
+ metadata.gz: 517e853cf964201158a34b1a855cd385c18946f0edc5b590b4d14e656cb9183b1eeb7b45269744cf9c12d8d15347b04c9421ab355c343d46c609fac2a7d3b096
7
+ data.tar.gz: 79768519e033f82d43b741b801c7120cbb849f5a257bd64f9b293951e526ccc25dbeb8931a3708e4bebc19a506651cd4bd69d6fc1e4e2be8447a8ea578a2a96d
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.2
5
+ before_install: gem install bundler -v 1.13.3
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at mjstone@on-site.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in server_health_check-rails.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Mike Virata-Stone
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,101 @@
1
+ # server_health_check-rails
2
+
3
+ This gem provides a rails engine that automatically hooks in with the
4
+ [server_health_check gem](https://github.com/on-site/server_health_check). It
5
+ will add a /health and /health/:id endpoint which will return a JSON string of
6
+ the results of either all configured health checks, or just the one provided.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem "server_health_check-rails"
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Then configure your checks with the gem using the built in `server_health_check`
21
+ checks, or your own custom checks:
22
+
23
+ ```ruby
24
+ # config/initializers/health_checks.rb
25
+ ServerHealthCheckRails.check_active_record!
26
+ ServerHealthCheckRails.check_redis!(host: "someredis.host", port: 1234)
27
+ ServerHealthCheckRails.check_aws_s3!("aws-bucket-to-check")
28
+ ServerHealthCheckRails.check_aws_creds!
29
+ ServerHealthCheckRails.check "custom_check" do
30
+ # Do some work here, then return true if it succeeded for false if not
31
+ # (exceptions will be caught by the server_health_check gem and the message
32
+ # will be reported as the status).
33
+ true
34
+ end
35
+ ```
36
+
37
+ And mount the engine in your routes file:
38
+
39
+ ```ruby
40
+ # config/routes.rb
41
+ Rails.application.routes.draw do
42
+ mount ServerHealthCheckRails::Engine, at: "/"
43
+ # Your routes here
44
+ end
45
+ ```
46
+
47
+ ## Usage
48
+
49
+ You can now use your health checks in some automated service to monitor your app
50
+ with your custom checks.
51
+
52
+ You may use the endpoint for all checks at `/health`, which might result in
53
+ something like the following, though without the formatting:
54
+
55
+ ```json
56
+ {
57
+ "status": {
58
+ "active_record": "OK",
59
+ "redis": "OK",
60
+ "aws_s3": "Failed",
61
+ "aws_creds": "OK",
62
+ "custom_check": "OK"
63
+ }
64
+ }
65
+ ```
66
+
67
+ If you want to just check a single check, you can just use that in the url like
68
+ `/health/custom_check`:
69
+
70
+ ```json
71
+ {
72
+ "status": {
73
+ "custom_check": "OK"
74
+ }
75
+ }
76
+ ```
77
+
78
+ ## Development
79
+
80
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run
81
+ `rake test` to run the tests. You can also run `bin/console` for an interactive
82
+ prompt that will allow you to experiment.
83
+
84
+ To install this gem onto your local machine, run `bundle exec rake install`. To
85
+ release a new version, update the version number in `version.rb`, and then run
86
+ `bundle exec rake release`, which will create a git tag for the version, push
87
+ git commits and tags, and push the `.gem` file to
88
+ [rubygems.org](https://rubygems.org).
89
+
90
+ ## Contributing
91
+
92
+ Bug reports and pull requests are welcome on GitHub at
93
+ https://github.com/on-site/server_health_check-rails. This project is intended
94
+ to be a safe, welcoming space for collaboration, and contributors are expected
95
+ to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of
96
+ conduct.
97
+
98
+ ## License
99
+
100
+ The gem is available as open source under the terms of the
101
+ [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,5 @@
1
+ module ServerHealthCheckRails
2
+ class ApplicationController < ActionController::Base
3
+ protect_from_forgery with: :exception
4
+ end
5
+ end
@@ -0,0 +1,13 @@
1
+ module ServerHealthCheckRails
2
+ class HealthController < ServerHealthCheckRails::ApplicationController
3
+ def index
4
+ check = ServerHealthCheckRails::HealthCheck.all
5
+ render status: check.http_status, json: check.to_h
6
+ end
7
+
8
+ def show
9
+ check = ServerHealthCheckRails::HealthCheck.new(params[:id])
10
+ render status: check.http_status, json: check.to_h
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,26 @@
1
+ module ServerHealthCheckRails
2
+ class HealthCheck
3
+ def initialize(*checks)
4
+ @check = ServerHealthCheck.new
5
+ ServerHealthCheckRails.apply_checks(@check, checks)
6
+ end
7
+
8
+ def self.all
9
+ new(*ServerHealthCheckRails.all_checks)
10
+ end
11
+
12
+ def http_status
13
+ if @check.ok?
14
+ 200
15
+ else
16
+ 500
17
+ end
18
+ end
19
+
20
+ def to_h
21
+ {
22
+ status: @check.results
23
+ }
24
+ end
25
+ end
26
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "server_health_check/rails"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ ServerHealthCheckRails::Engine.routes.draw do
2
+ resources :health, only: [:index, :show]
3
+ end
@@ -0,0 +1 @@
1
+ require "server_health_check_rails"
@@ -0,0 +1 @@
1
+ require "server_health_check_rails"
@@ -0,0 +1,60 @@
1
+ require "server_health_check"
2
+ require "server_health_check_rails/version"
3
+ require "server_health_check_rails/engine"
4
+ require "set"
5
+
6
+ module ServerHealthCheckRails
7
+ class << self
8
+ def all_checks
9
+ raise ArgumentError, "Please configure server_health_check-rails!" if @checks.nil?
10
+ @checks.keys
11
+ end
12
+
13
+ def apply_checks(server_health_check, checks)
14
+ raise ArgumentError, "Please configure server_health_check-rails!" if @checks.nil?
15
+ checks = Set.new(checks)
16
+
17
+ @checks.each do |name, check|
18
+ next unless checks.include?(name)
19
+ check.call(server_health_check)
20
+ end
21
+ end
22
+
23
+ def check(name, &block)
24
+ add_check name do |server_health_check|
25
+ server_health_check.check!(name, &block)
26
+ end
27
+ end
28
+
29
+ def check_active_record!
30
+ add_check "active_record" do |server_health_check|
31
+ server_health_check.active_record!
32
+ end
33
+ end
34
+
35
+ def check_redis!(host: nil, port: 6379)
36
+ add_check "redis" do |server_health_check|
37
+ server_health_check.redis! host: nil, port: 6379
38
+ end
39
+ end
40
+
41
+ def check_aws_s3!(bucket = nil)
42
+ add_check "aws_s3" do |server_health_check|
43
+ server_health_check.aws_s3! bucket
44
+ end
45
+ end
46
+
47
+ def check_aws_creds!
48
+ add_check "aws_creds" do |server_health_check|
49
+ server_health_check.aws_creds!
50
+ end
51
+ end
52
+
53
+ private
54
+
55
+ def add_check(name, &block)
56
+ @checks ||= {}
57
+ @checks[name] = block
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,5 @@
1
+ module ServerHealthCheckRails
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace ServerHealthCheckRails
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module ServerHealthCheckRails
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'server_health_check_rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "server_health_check-rails"
8
+ spec.version = ServerHealthCheckRails::VERSION
9
+ spec.authors = ["Mike Virata-Stone"]
10
+ spec.email = ["mjstone@on-site.com"]
11
+
12
+ spec.summary = %q{Healthcheck for Rails apps.}
13
+ spec.description = %q{Health check for Rails apps checking things like active record, redis, and AWS.}
14
+ spec.homepage = "https://github.com/on-site/server_health_check-rails"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_runtime_dependency "rails", ">= 3.0", "< 6.0"
25
+ spec.add_runtime_dependency "server_health_check", "~> 1.0"
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.13"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "minitest", "~> 5.0"
30
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: server_health_check-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mike Virata-Stone
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-12-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '6.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '3.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '6.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: server_health_check
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '1.13'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '1.13'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '10.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '10.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: minitest
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '5.0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '5.0'
89
+ description: Health check for Rails apps checking things like active record, redis,
90
+ and AWS.
91
+ email:
92
+ - mjstone@on-site.com
93
+ executables: []
94
+ extensions: []
95
+ extra_rdoc_files: []
96
+ files:
97
+ - ".gitignore"
98
+ - ".travis.yml"
99
+ - CODE_OF_CONDUCT.md
100
+ - Gemfile
101
+ - LICENSE.txt
102
+ - README.md
103
+ - Rakefile
104
+ - app/controllers/server_health_check_rails/application_controller.rb
105
+ - app/controllers/server_health_check_rails/health_controller.rb
106
+ - app/models/server_health_check_rails/health_check.rb
107
+ - bin/console
108
+ - bin/setup
109
+ - config/routes.rb
110
+ - lib/server_health_check-rails.rb
111
+ - lib/server_health_check/rails.rb
112
+ - lib/server_health_check_rails.rb
113
+ - lib/server_health_check_rails/engine.rb
114
+ - lib/server_health_check_rails/version.rb
115
+ - server_health_check-rails.gemspec
116
+ homepage: https://github.com/on-site/server_health_check-rails
117
+ licenses:
118
+ - MIT
119
+ metadata: {}
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 2.4.8
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: Healthcheck for Rails apps.
140
+ test_files: []