monitor_page 0.1.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8a03ac4d174c4df6f065e924816f97b23006d393
4
+ data.tar.gz: 8816a43169b12265fa961bb85be2cbd632d7ff92
5
+ SHA512:
6
+ metadata.gz: 569f38fae88e403df8fd22b143a9fd7e24da4b0cd4c44fb0df411c737a52a291ac5414b9e830244f28c08a90e6153e8378644f90616f72ec403994e9e55fcf40
7
+ data.tar.gz: d63f6656c654af8c05d7bcf1f36eb356e159150044bac0eed7148a67c7773849e29a8100e7c3b0cb7483dc588a9dae8300f0fc1b1690e82c701e7c249fa5055e
@@ -0,0 +1,20 @@
1
+ Copyright 2018 Chris Gooley
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,63 @@
1
+ # MonitorPage
2
+ A gem to view status checks of multiple services from a single page.
3
+
4
+ ## Usage
5
+ Create an initializer and setup your checks. Each check should have a `pass` and an `error` call.
6
+
7
+ ```ruby
8
+ MonitorPage.configure do
9
+ permit '1.1.1.1', '1.1.2.2' # optional, will be available everywhere if left out
10
+
11
+ check 'Sidekiq' do
12
+ if Sidekiq::Queue.all.select{ |q| q.size > 50 }.any?
13
+ error "Sidekiq has too many jobs"
14
+ else
15
+ pass
16
+ end
17
+ end
18
+
19
+ check 'Passing Check' do
20
+ pass
21
+ end
22
+
23
+ check 'Failing Check' do
24
+ error "GAME OVER MAN, GAME OVER!"
25
+ end
26
+ end
27
+ ```
28
+
29
+ In your routes:
30
+ ```ruby
31
+ mount MonitorPage::Engine, at: '/monitor_page'
32
+ ```
33
+
34
+ Visiting `/monitor_page` should give you something like this:
35
+ ```
36
+ Sidekiq: Passed
37
+ Passing Check: Passed
38
+ Failing Check: Failed - GAME OVER MAN, GAME OVER!
39
+ -----------
40
+ Overall: Failed
41
+ ```
42
+
43
+ `Overall` will always display `Passed` or `Failed` based on if all the above checks have passed or if there is a failure.
44
+
45
+ ## Installation
46
+ Add this line to your application's Gemfile:
47
+
48
+ ```ruby
49
+ gem 'monitor_page'
50
+ ```
51
+
52
+ And then execute:
53
+ ```bash
54
+ $ bundle
55
+ ```
56
+
57
+ Or install it yourself as:
58
+ ```bash
59
+ $ gem install monitor_page
60
+ ```
61
+
62
+ ## License
63
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,32 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'MonitorPage'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+ load 'rails/tasks/statistics.rake'
21
+
22
+ require 'bundler/gem_tasks'
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'test'
28
+ t.pattern = 'test/**/*_test.rb'
29
+ t.verbose = false
30
+ end
31
+
32
+ task default: :test
@@ -0,0 +1,2 @@
1
+ //= link_directory ../javascripts/monitor_page .js
2
+ //= link_directory ../stylesheets/monitor_page .css
@@ -0,0 +1,5 @@
1
+ module MonitorPage
2
+ class ApplicationController < ActionController::Base
3
+ protect_from_forgery with: :exception
4
+ end
5
+ end
@@ -0,0 +1,30 @@
1
+ require_dependency "monitor_page/application_controller"
2
+
3
+ module MonitorPage
4
+ class StatusController < ApplicationController
5
+ layout 'monitor_page/application'
6
+
7
+ def index
8
+ if MonitorPage.allowed_ips && !MonitorPage.allowed_ips.include?(request.remote_ip)
9
+ render html: 'Forbidden' and return
10
+ end
11
+
12
+ check_results = MonitorPage.checks.map{|c| c.call }
13
+
14
+ overall_pass = check_results.inject(true) { |res, check| res && check[:result] }
15
+
16
+ results = check_results.map do |r|
17
+ if r[:result]
18
+ "#{r[:label]}: Passed"
19
+ else
20
+ "#{r[:label]}: Failed - #{r[:message]}"
21
+ end
22
+ end
23
+
24
+ results << "-----------"
25
+ results << "Overall: #{overall_pass ? 'Passed' : 'Failed'}"
26
+
27
+ render html: results.join("<br/>").html_safe
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,4 @@
1
+ module MonitorPage
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module MonitorPage
2
+ module StatusHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module MonitorPage
2
+ class ApplicationJob < ActiveJob::Base
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ module MonitorPage
2
+ class ApplicationMailer < ActionMailer::Base
3
+ default from: 'from@example.com'
4
+ layout 'mailer'
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module MonitorPage
2
+ class ApplicationRecord < ActiveRecord::Base
3
+ self.abstract_class = true
4
+ end
5
+ end
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Monitor Page</title>
5
+ <%= csrf_meta_tags %>
6
+ <%= csp_meta_tag %>
7
+ </head>
8
+ <body>
9
+
10
+ <%= yield %>
11
+
12
+ </body>
13
+ </html>
@@ -0,0 +1,4 @@
1
+ MonitorPage::Engine.routes.draw do
2
+
3
+ root to: 'status#index'
4
+ end
@@ -0,0 +1,5 @@
1
+ require "monitor_page/engine"
2
+
3
+ module MonitorPage
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,52 @@
1
+ require "ipaddr"
2
+
3
+ module MonitorPage
4
+ class Engine < ::Rails::Engine
5
+ isolate_namespace MonitorPage
6
+ end
7
+
8
+ class << self
9
+ attr_accessor :checks, :allowed_ips
10
+
11
+ def checks
12
+ @checks || []
13
+ end
14
+
15
+ def configure &block
16
+ instance_eval(&block)
17
+ end
18
+
19
+ def check(label, &block)
20
+ self.checks += [Proc.new { StatusCheck.create_check(label, &block) }]
21
+ end
22
+
23
+ def permit(ips)
24
+ ip_ranges = ips.is_a?(String) ? ips.split(/,\s?/) : ips
25
+ self.allowed_ips
26
+ end
27
+ end
28
+
29
+ class StatusCheck
30
+ attr_accessor :label
31
+
32
+ def initialize(label)
33
+ @label = label
34
+ end
35
+
36
+ def self.create_check(label, &block)
37
+ new(label).create_check(&block)
38
+ end
39
+
40
+ def create_check(&block)
41
+ instance_eval(&block)
42
+ end
43
+
44
+ def pass
45
+ return { label: label, result: true }
46
+ end
47
+
48
+ def error(message)
49
+ return { label: label, result: false, message: message }
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,3 @@
1
+ module MonitorPage
2
+ VERSION = '0.1.1'
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :monitor_page do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: monitor_page
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Chris Gooley
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-10-25 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: '5.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.0'
27
+ description:
28
+ email:
29
+ - chris@gooddogdesign.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - MIT-LICENSE
35
+ - README.md
36
+ - Rakefile
37
+ - app/assets/config/monitor_page_manifest.js
38
+ - app/controllers/monitor_page/application_controller.rb
39
+ - app/controllers/monitor_page/status_controller.rb
40
+ - app/helpers/monitor_page/application_helper.rb
41
+ - app/helpers/monitor_page/status_helper.rb
42
+ - app/jobs/monitor_page/application_job.rb
43
+ - app/mailers/monitor_page/application_mailer.rb
44
+ - app/models/monitor_page/application_record.rb
45
+ - app/views/layouts/monitor_page/application.html.erb
46
+ - config/routes.rb
47
+ - lib/monitor_page.rb
48
+ - lib/monitor_page/engine.rb
49
+ - lib/monitor_page/version.rb
50
+ - lib/tasks/monitor_page_tasks.rake
51
+ homepage: ''
52
+ licenses:
53
+ - MIT
54
+ metadata: {}
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubyforge_project:
71
+ rubygems_version: 2.6.12
72
+ signing_key:
73
+ specification_version: 4
74
+ summary: A gem to view status checks of multiple services from a single page.
75
+ test_files: []