okcomputer 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +40 -8
- data/app/controllers/ok_computer_controller.rb +18 -0
- data/lib/okcomputer.rb +1 -0
- data/lib/okcomputer/check_collection.rb +7 -2
- data/lib/okcomputer/configuration.rb +55 -0
- data/lib/okcomputer/version.rb +1 -1
- metadata +5 -4
data/README.markdown
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
[![Code Climate](https://codeclimate.com/github/tstmedia/okcomputer.png)](https://codeclimate.com/github/tstmedia/okcomputer)
|
2
|
+
[![Build Status](https://travis-ci.org/tstmedia/okcomputer.png)](https://travis-ci.org/tstmedia/okcomputer)
|
3
|
+
|
1
4
|
# OK Computer
|
2
5
|
|
3
6
|
Inspired by the ease of installing and setting up [fitter-happier] as a Rails
|
@@ -39,9 +42,18 @@ build your own database check and register it with the name "database" to
|
|
39
42
|
replace the built-in check, or use `OKComputer::Registry.deregister "database"`
|
40
43
|
to stop checking your database altogether.
|
41
44
|
|
45
|
+
### Requiring Authentication
|
46
|
+
|
47
|
+
Optionally require HTTP Basic authentication to view the results of checks in an initializer, like so:
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
# config/initializers/okcomputer.rb
|
51
|
+
OKComputer.require_authentication("username", "password")
|
52
|
+
```
|
53
|
+
|
42
54
|
### Registering Additional Checks
|
43
55
|
|
44
|
-
Register additional checks in an initializer, like
|
56
|
+
Register additional checks in an initializer, like so:
|
45
57
|
|
46
58
|
```ruby
|
47
59
|
# config/initializers/okcomputer.rb
|
@@ -72,6 +84,18 @@ end
|
|
72
84
|
OKComputer::Registry.register "check_for_odds", MyCustomCheck.new
|
73
85
|
```
|
74
86
|
|
87
|
+
## Performing Checks
|
88
|
+
|
89
|
+
* Perform a simple up check: http://example.com/okcomputer
|
90
|
+
* Perform all installed checks: http://example.com/okcomputer/all
|
91
|
+
* Perform a specific installed check: http://example.com/okcomputer/database
|
92
|
+
|
93
|
+
Checks are available as plain text (by default) or JSON by appending .json, e.g.:
|
94
|
+
* http://example.com/okcomputer.json
|
95
|
+
* http://example.com/okcomputer/all.json
|
96
|
+
|
97
|
+
## Deprecations and Breaking Changes
|
98
|
+
|
75
99
|
#### Deprecation of Check#call
|
76
100
|
|
77
101
|
Versions before 0.2.0 implemented a "#call" method which returned the message.
|
@@ -80,15 +104,22 @@ define a #check method which calls `mark_failure` and `mark_message` as
|
|
80
104
|
appropriate. In the meantime, OKComputer displays a warning and uses the result
|
81
105
|
of the #call method as the message.
|
82
106
|
|
83
|
-
|
107
|
+
#### Breaking Change of JSON Output
|
84
108
|
|
85
|
-
|
86
|
-
|
87
|
-
|
109
|
+
Versions before 0.3.0, when performing multiple checks, returned an Array of
|
110
|
+
the check results, each being a JSON object. Starting with 0.3.0, these are
|
111
|
+
combined into a single JSON object with each check having its own key. For
|
112
|
+
example:
|
88
113
|
|
89
|
-
|
90
|
-
|
91
|
-
|
114
|
+
**before 0.3.0**
|
115
|
+
```json
|
116
|
+
[{"check": "result"}, {"other": "result"}]
|
117
|
+
```
|
118
|
+
|
119
|
+
**0.3.0 and above**
|
120
|
+
```json
|
121
|
+
{"check": "result", "other": "result"}
|
122
|
+
```
|
92
123
|
|
93
124
|
## Contributing
|
94
125
|
|
@@ -99,3 +130,4 @@ Checks are available as plain text (by default) or JSON by appending .json, e.g.
|
|
99
130
|
5. Create new Pull Request
|
100
131
|
|
101
132
|
[fitter-happier]:https://rubygems.org/gems/fitter-happier
|
133
|
+
|
@@ -2,6 +2,15 @@ class OkComputerController < ActionController::Base
|
|
2
2
|
layout nil
|
3
3
|
respond_to :text, :json
|
4
4
|
|
5
|
+
before_filter :authenticate
|
6
|
+
|
7
|
+
rescue_from OKComputer::Registry::CheckNotFound do |e|
|
8
|
+
respond_to do |f|
|
9
|
+
f.text { render text: e.message, status: :not_found }
|
10
|
+
f.json { render json: { error: e.message }, status: :not_found }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
5
14
|
def index
|
6
15
|
checks = OKComputer::Registry.all
|
7
16
|
checks.run
|
@@ -20,4 +29,13 @@ class OkComputerController < ActionController::Base
|
|
20
29
|
check.success? ? :ok : :error
|
21
30
|
end
|
22
31
|
private :status_code
|
32
|
+
|
33
|
+
def authenticate
|
34
|
+
if OKComputer.requires_authentication?
|
35
|
+
authenticate_or_request_with_http_basic do |username, password|
|
36
|
+
OKComputer.authenticate(username, password)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
private :authenticate
|
23
41
|
end
|
data/lib/okcomputer.rb
CHANGED
@@ -33,8 +33,13 @@ module OKComputer
|
|
33
33
|
#
|
34
34
|
# Returns a String containing a JSON array of hashes
|
35
35
|
def to_json(*args)
|
36
|
-
# smooshing their #to_json objects into
|
37
|
-
|
36
|
+
# smooshing their #to_json objects into one JSON hash
|
37
|
+
combined = {}
|
38
|
+
checks.each do |check|
|
39
|
+
combined.merge!(JSON.parse(check.to_json))
|
40
|
+
end
|
41
|
+
|
42
|
+
combined.to_json
|
38
43
|
end
|
39
44
|
|
40
45
|
# Public: Whether all the checks succeed
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module OKComputer
|
2
|
+
# Public: Configure HTTP Basic authentication
|
3
|
+
#
|
4
|
+
# username - Username required to view checks
|
5
|
+
# password - Password required to view checks
|
6
|
+
def self.require_authentication(username, password)
|
7
|
+
self.username = username
|
8
|
+
self.password = password
|
9
|
+
end
|
10
|
+
|
11
|
+
# Public: Attempt to authenticate against required username and password
|
12
|
+
#
|
13
|
+
# username - Username to authenticate with
|
14
|
+
# password - Password to authenticate with
|
15
|
+
#
|
16
|
+
# Returns a Boolean
|
17
|
+
def self.authenticate(username_try, password_try)
|
18
|
+
return true unless requires_authentication?
|
19
|
+
|
20
|
+
username == username_try && password == password_try
|
21
|
+
end
|
22
|
+
|
23
|
+
# Public: Whether OKComputer is configured to require authentication
|
24
|
+
#
|
25
|
+
# Returns a Boolean
|
26
|
+
def self.requires_authentication?
|
27
|
+
username && password
|
28
|
+
end
|
29
|
+
|
30
|
+
# attr_accessor isn't doing what I want inside a module, so here we go.
|
31
|
+
|
32
|
+
# Private: The username configured for access to checks
|
33
|
+
def self.username
|
34
|
+
@username
|
35
|
+
end
|
36
|
+
private_class_method :username
|
37
|
+
|
38
|
+
# Private: Configure the username to access checks
|
39
|
+
def self.username=(username)
|
40
|
+
@username = username
|
41
|
+
end
|
42
|
+
private_class_method :username=
|
43
|
+
|
44
|
+
# Private: The password configured for access to checks
|
45
|
+
def self.password
|
46
|
+
@password
|
47
|
+
end
|
48
|
+
private_class_method :password
|
49
|
+
|
50
|
+
# Private: Configure the password to access checks
|
51
|
+
def self.password=(password)
|
52
|
+
@password = password
|
53
|
+
end
|
54
|
+
private_class_method :password=
|
55
|
+
end
|
data/lib/okcomputer/version.rb
CHANGED
metadata
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
name: okcomputer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.3.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Patrick Byrne
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-03-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -78,6 +78,7 @@ files:
|
|
78
78
|
- lib/okcomputer/built_in_checks/resque_down_check.rb
|
79
79
|
- lib/okcomputer/check.rb
|
80
80
|
- lib/okcomputer/check_collection.rb
|
81
|
+
- lib/okcomputer/configuration.rb
|
81
82
|
- lib/okcomputer/engine.rb
|
82
83
|
- lib/okcomputer/registry.rb
|
83
84
|
- lib/okcomputer/version.rb
|
@@ -99,7 +100,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
99
100
|
version: '0'
|
100
101
|
segments:
|
101
102
|
- 0
|
102
|
-
hash: -
|
103
|
+
hash: -2545106061881900479
|
103
104
|
none: false
|
104
105
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
106
|
requirements:
|
@@ -108,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
109
|
version: '0'
|
109
110
|
segments:
|
110
111
|
- 0
|
111
|
-
hash: -
|
112
|
+
hash: -2545106061881900479
|
112
113
|
none: false
|
113
114
|
requirements: []
|
114
115
|
rubyforge_project:
|