guardian 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/.infinity_test +15 -0
- data/.rspec +2 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +57 -0
- data/Rakefile +9 -0
- data/guardian.gemspec +32 -0
- data/lib/guardian.rb +29 -0
- data/lib/guardian/notifier.rb +54 -0
- data/lib/guardian/status_page.rb +45 -0
- data/lib/guardian/status_page/public/style.css +76 -0
- data/lib/guardian/status_page/views/index.erb +65 -0
- data/lib/guardian/version.rb +3 -0
- data/readme.md +76 -0
- data/spec/guardian_spec.rb +36 -0
- data/spec/lib/notifier_spec.rb +86 -0
- data/spec/lib/status_page_spec.rb +95 -0
- data/spec/spec_helper.rb +14 -0
- data/spec/support/server.rb +6 -0
- data/spec/support/webmock.rb +3 -0
- metadata +180 -0
data/.infinity_test
ADDED
data/.rspec
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use 1.9.2@guardian-gem
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
guardian (0.0.1)
|
5
|
+
httparty
|
6
|
+
json
|
7
|
+
sinatra
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: http://rubygems.org/
|
11
|
+
specs:
|
12
|
+
addressable (2.2.5)
|
13
|
+
crack (0.1.8)
|
14
|
+
diff-lcs (1.1.2)
|
15
|
+
httparty (0.7.7)
|
16
|
+
crack (= 0.1.8)
|
17
|
+
infinity_test (1.0.2)
|
18
|
+
notifiers (>= 1.1.0)
|
19
|
+
watchr (>= 0.7)
|
20
|
+
json (1.5.1)
|
21
|
+
notifiers (1.1.0)
|
22
|
+
rack (1.2.2)
|
23
|
+
rack-test (0.5.7)
|
24
|
+
rack (>= 1.0)
|
25
|
+
rspec (2.5.0)
|
26
|
+
rspec-core (~> 2.5.0)
|
27
|
+
rspec-expectations (~> 2.5.0)
|
28
|
+
rspec-mocks (~> 2.5.0)
|
29
|
+
rspec-core (2.5.1)
|
30
|
+
rspec-expectations (2.5.0)
|
31
|
+
diff-lcs (~> 1.1.2)
|
32
|
+
rspec-mocks (2.5.0)
|
33
|
+
shotgun (0.9)
|
34
|
+
rack (>= 1.0)
|
35
|
+
simplecov (0.4.1)
|
36
|
+
simplecov-html (~> 0.4.3)
|
37
|
+
simplecov-html (0.4.3)
|
38
|
+
sinatra (1.2.3)
|
39
|
+
rack (~> 1.1)
|
40
|
+
tilt (< 2.0, >= 1.2.2)
|
41
|
+
tilt (1.3)
|
42
|
+
watchr (0.7)
|
43
|
+
webmock (1.6.2)
|
44
|
+
addressable (>= 2.2.2)
|
45
|
+
crack (>= 0.1.7)
|
46
|
+
|
47
|
+
PLATFORMS
|
48
|
+
ruby
|
49
|
+
|
50
|
+
DEPENDENCIES
|
51
|
+
guardian!
|
52
|
+
infinity_test
|
53
|
+
rack-test
|
54
|
+
rspec
|
55
|
+
shotgun
|
56
|
+
simplecov
|
57
|
+
webmock
|
data/Rakefile
ADDED
data/guardian.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "guardian/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "guardian"
|
7
|
+
s.version = Guardian::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Adam Hawkins"]
|
10
|
+
s.email = ["adam@guardianapp.com"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{Ruby library for interacting with the Guardian webservice.}
|
13
|
+
s.description = %q{Notify, retreive systems, and misc information from the webservice.}
|
14
|
+
|
15
|
+
s.rubyforge_project = "guardian-gem"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_dependency 'json'
|
23
|
+
s.add_dependency 'httparty'
|
24
|
+
s.add_dependency 'sinatra'
|
25
|
+
|
26
|
+
s.add_development_dependency 'rspec'
|
27
|
+
s.add_development_dependency 'webmock'
|
28
|
+
s.add_development_dependency 'infinity_test'
|
29
|
+
s.add_development_dependency 'simplecov'
|
30
|
+
s.add_development_dependency 'shotgun'
|
31
|
+
s.add_development_dependency 'rack-test'
|
32
|
+
end
|
data/lib/guardian.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
|
3
|
+
module Guardian
|
4
|
+
include HTTParty
|
5
|
+
|
6
|
+
API_URL = 'http://guardianapp.heroku.com'.freeze
|
7
|
+
|
8
|
+
base_uri API_URL
|
9
|
+
format :json
|
10
|
+
|
11
|
+
autoload :Notifier, 'guardian/notifier'
|
12
|
+
autoload :StatusPage, 'guardian/status_page'
|
13
|
+
|
14
|
+
class << self
|
15
|
+
def account_id=(val)
|
16
|
+
@account_id = val
|
17
|
+
end
|
18
|
+
|
19
|
+
def account_id
|
20
|
+
@account_id
|
21
|
+
end
|
22
|
+
|
23
|
+
def systems
|
24
|
+
raise RuntimeError, "Guardian is not configured! Set the account_id first." unless account_id
|
25
|
+
|
26
|
+
get("/accounts/#{account_id}/systems").parsed_response
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Guardian
|
2
|
+
require 'net/http'
|
3
|
+
require 'json'
|
4
|
+
require 'uri'
|
5
|
+
|
6
|
+
class Notifier
|
7
|
+
|
8
|
+
def self.notify system_id, attributes
|
9
|
+
assert_valid_keys! attributes, :online, :description, :data
|
10
|
+
|
11
|
+
unless attributes.has_key? :online
|
12
|
+
raise ArgumentError, ":online missing! Must specify :online as a boolean."
|
13
|
+
end
|
14
|
+
|
15
|
+
if !attributes.has_key?(:description) && attributes[:online] == false
|
16
|
+
raise ArgumentError, ":description missing! Must specify description when offline"
|
17
|
+
end
|
18
|
+
|
19
|
+
uri = URI.parse "#{Guardian::API_URL}/systems/#{system_id}/updates"
|
20
|
+
params = {:update => attributes, :account_id => Guardian.account_id}
|
21
|
+
|
22
|
+
request = Net::HTTP::Post.new(uri.path)
|
23
|
+
request.content_type = 'application/json'
|
24
|
+
request.body = params.to_json
|
25
|
+
|
26
|
+
response = Net::HTTP.new(uri.host, uri.port).start {|http| http.request(request) }
|
27
|
+
|
28
|
+
if response.is_a?(Net::HTTPUnauthorized)
|
29
|
+
raise RuntimeError, "Request unauthorized! You must specify correct account and system tokens"
|
30
|
+
end
|
31
|
+
|
32
|
+
unless response.is_a?(Net::HTTPCreated)
|
33
|
+
raise RuntimeError, "Guardian did something unexpected!\n #{response.body}"
|
34
|
+
end
|
35
|
+
|
36
|
+
true
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.online(system_id, description = nil, data = nil)
|
40
|
+
notify system_id, :online => true, :description => description, :data => data
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.offline(system_id, description, data = nil)
|
44
|
+
notify system_id, :online => false, :description => description, :data => data
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
# File activesupport/lib/active_support/core_ext/hash/keys.rb, line 41
|
49
|
+
def self.assert_valid_keys!(hash, *valid_keys)
|
50
|
+
unknown_keys = hash.keys - [valid_keys].flatten
|
51
|
+
raise(ArgumentError, "Unknown key(s): #{unknown_keys.join(", ")}") unless unknown_keys.empty?
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
require 'erb'
|
3
|
+
require 'guardian'
|
4
|
+
require 'guardian/version'
|
5
|
+
|
6
|
+
module Guardian
|
7
|
+
class StatusPage < Sinatra::Base
|
8
|
+
dir = File.dirname File.expand_path(__FILE__)
|
9
|
+
|
10
|
+
set :views, "#{dir}/status_page/views"
|
11
|
+
set :public, "#{dir}/status_page/public"
|
12
|
+
|
13
|
+
helpers do
|
14
|
+
include Rack::Utils
|
15
|
+
alias_method :h, :escape_html
|
16
|
+
|
17
|
+
def system_state(system)
|
18
|
+
if system['online']
|
19
|
+
:online
|
20
|
+
elsif system['data_reported'] == false
|
21
|
+
:no_data
|
22
|
+
else
|
23
|
+
:offline
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def system_status(system)
|
28
|
+
case system_state(system)
|
29
|
+
when :online
|
30
|
+
'Online'
|
31
|
+
when :offline
|
32
|
+
'Offline'
|
33
|
+
when :no_data
|
34
|
+
'No Data Reported'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
get '/' do
|
40
|
+
@systems = Guardian.systems.map {|h| h['system']}
|
41
|
+
|
42
|
+
erb :index
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
html {
|
2
|
+
background-color: #777;
|
3
|
+
}
|
4
|
+
|
5
|
+
body {
|
6
|
+
color: #868686;
|
7
|
+
font: 14px/18px "Helvetica Neue", Helvetica, Arial, sans-serif;
|
8
|
+
}
|
9
|
+
|
10
|
+
#container {
|
11
|
+
width: 500px;
|
12
|
+
margin: 36px auto;
|
13
|
+
background-color: #fff;
|
14
|
+
padding: 10px 0;
|
15
|
+
}
|
16
|
+
|
17
|
+
h2 {
|
18
|
+
background: #EEE;
|
19
|
+
padding: 9px 15px;
|
20
|
+
font-size: 16px;
|
21
|
+
color: #333;
|
22
|
+
}
|
23
|
+
|
24
|
+
#systems {
|
25
|
+
margin: 20px 0;
|
26
|
+
}
|
27
|
+
|
28
|
+
li.system {
|
29
|
+
margin: 15px 0
|
30
|
+
}
|
31
|
+
|
32
|
+
li.system p {
|
33
|
+
padding: 4px 15px;
|
34
|
+
}
|
35
|
+
|
36
|
+
.status {
|
37
|
+
font-weight: bold;
|
38
|
+
}
|
39
|
+
|
40
|
+
.offline .text, td.offline {
|
41
|
+
color: #bc0404;
|
42
|
+
text-transform: uppercase;
|
43
|
+
}
|
44
|
+
|
45
|
+
.no_data .text, td.no_data {
|
46
|
+
color: #bc0404;
|
47
|
+
text-transform: uppercase;
|
48
|
+
}
|
49
|
+
|
50
|
+
.online .text, td.online {
|
51
|
+
color: #199734;
|
52
|
+
text-transform: uppercase;
|
53
|
+
}
|
54
|
+
|
55
|
+
a {
|
56
|
+
color: #235985;
|
57
|
+
text-decoration: none;
|
58
|
+
}
|
59
|
+
|
60
|
+
h2.small {
|
61
|
+
font-size: 14px;
|
62
|
+
}
|
63
|
+
|
64
|
+
p.small {
|
65
|
+
font-size: 12px;
|
66
|
+
padding: 9px 15px;
|
67
|
+
}
|
68
|
+
|
69
|
+
table {
|
70
|
+
width: 100%
|
71
|
+
}
|
72
|
+
|
73
|
+
td,th {
|
74
|
+
padding: 9px 15px;
|
75
|
+
border-bottom: 1px solid #EEE;
|
76
|
+
}
|
@@ -0,0 +1,65 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
5
|
+
<title>Application Status</title>
|
6
|
+
<link rel='stylesheet' href='http://yui.yahooapis.com/3.3.0/build/cssreset/reset-min.css' type='text/css' media="screen, projection">
|
7
|
+
<link rel='stylesheet' href='style.css' type='text/css' media="screen, projection">
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
<div id="container">
|
11
|
+
<h2 class="small">About This Page</h2>
|
12
|
+
<p class="small">
|
13
|
+
This page is automatically generated by <a href="#">Guardian</a>.
|
14
|
+
Guardian is a tool to help you monitor and manage your applications.
|
15
|
+
It works with any application. You can try it free of charge.
|
16
|
+
</p>
|
17
|
+
<p class="small">Running Guardian v<%= Guardian::VERSION %></p>
|
18
|
+
|
19
|
+
<h2>Status</h2>
|
20
|
+
<table>
|
21
|
+
<thead>
|
22
|
+
<tr>
|
23
|
+
<th>System</th>
|
24
|
+
<th>Status</th>
|
25
|
+
</tr>
|
26
|
+
</thead>
|
27
|
+
<tbody>
|
28
|
+
<% @systems.each do |system| %>
|
29
|
+
<tr>
|
30
|
+
<td><%=h system['name'] %></td>
|
31
|
+
<td class="status <%= system_state(system) %>">
|
32
|
+
<%= system_status(system) %>
|
33
|
+
</td>
|
34
|
+
</tr>
|
35
|
+
<% end %>
|
36
|
+
</tbody>
|
37
|
+
</table>
|
38
|
+
|
39
|
+
<ul id="systems">
|
40
|
+
<% @systems.each do |system| %>
|
41
|
+
<li class="system">
|
42
|
+
<h2><%=h system['name'] %></h2>
|
43
|
+
<% if system_state(system) == :online %>
|
44
|
+
<p class='online status'>
|
45
|
+
<% if system['running_message'] %>
|
46
|
+
<span class='text'>Online:</span>
|
47
|
+
<%= h(system['running_message']) %>
|
48
|
+
<% else %>
|
49
|
+
<span class='text'>Online</span>
|
50
|
+
<% end %>
|
51
|
+
</p>
|
52
|
+
<% elsif system_state(system) == :no_data %>
|
53
|
+
<p class='no_data status'><span class='text'>No Data Reported</span></p>
|
54
|
+
<% elsif system_state(system) == :offline %>
|
55
|
+
<p class='offline status'><span class='text'>Offline:</span> <%=h system['failure_message'] %></p>
|
56
|
+
<% end %>
|
57
|
+
|
58
|
+
<p><%=h system['description'] %></p>
|
59
|
+
<p>Last Test: <%=h system['updated_at'].strftime('%Y-%m-%d %H:%I %Z') %></p>
|
60
|
+
</li>
|
61
|
+
<% end %>
|
62
|
+
</ul>
|
63
|
+
</div>
|
64
|
+
</body>
|
65
|
+
<html>
|
data/readme.md
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
# Guardian
|
2
|
+
|
3
|
+
This is the Guardian ruby gem. It's designed to be used inside your
|
4
|
+
application to do various things. It's also used to create the status
|
5
|
+
webpage for your application. The gem is easy to use and you should be
|
6
|
+
able to interact with most of your Guardian data through it.
|
7
|
+
|
8
|
+
## Configuration
|
9
|
+
|
10
|
+
Configuration is exteremly easy. You need one thing in the beginning.
|
11
|
+
Your `account_id` is required for all requests. You need the `system_id`
|
12
|
+
for each system you intend to work with through the API. Here's how you
|
13
|
+
set the `account_id`
|
14
|
+
|
15
|
+
Guardian.account_id = 'your-account-id-here'
|
16
|
+
|
17
|
+
You'll need the `system_id` later depending on what code you want to
|
18
|
+
use.
|
19
|
+
|
20
|
+
## Notifying
|
21
|
+
|
22
|
+
This one of the primary features. You should use it to inside your
|
23
|
+
application to report system status back to guardian. There are two
|
24
|
+
different types of notifications: 'online' and 'offline'. Creating an
|
25
|
+
offline update will send notifications to everyone who's configured
|
26
|
+
them. It will also update the system status on your site's dasboard.
|
27
|
+
Sending an 'online' update will switch the status to online if it is
|
28
|
+
offline. It will remain online if it was online previously. All updates
|
29
|
+
are stored so you can review them later. You'll need the `system_id` to
|
30
|
+
send any updates. Make sure the guardian gem is configured before use.
|
31
|
+
|
32
|
+
There are there general methods:
|
33
|
+
|
34
|
+
Guardian::Notifier.notify(system_id, attributes)
|
35
|
+
Guardian::Notifier.online(system_id, attributes = {})
|
36
|
+
Guardian::Notifier.offline(system_id, description, data = {})
|
37
|
+
|
38
|
+
The `online` and `offline` methods are wrappers around the `notify`
|
39
|
+
method. Attributes uses two keys: `:description` and `:data`.
|
40
|
+
`:description` is required if are creating an offline update. You can
|
41
|
+
send anything you want in `:data` as long as it can be represented in
|
42
|
+
JSON. It will be serialized so you an retreive it later.
|
43
|
+
|
44
|
+
Here are some examples:
|
45
|
+
|
46
|
+
require 'guardian'
|
47
|
+
require 'guardian/notifier'
|
48
|
+
|
49
|
+
Guardian::Notifier.account_id = 'your-account-id'
|
50
|
+
|
51
|
+
Guardian::Notifier.notify 'your-system-id', online, :description => "GOLIATH ONLINE!"
|
52
|
+
Guardian::Notifier.notify 'your-system-id', offline, :description => "FFFFFFUUUU", :data => hash_of_useful_context_data
|
53
|
+
|
54
|
+
Guardian::Notifier.online 'your-system-id'
|
55
|
+
Guardian::Notifier.online 'your-system-id', "GOLIATH ONLINE"
|
56
|
+
Guardian::Notifier.online 'your-system-id', "GOLIATH ONLINE", context_information
|
57
|
+
|
58
|
+
Guardian::Notifier.offline 'your-system-id', "GOLIATH FAILED"
|
59
|
+
Guardian::Notifier.offline 'your-system-id', "GOLIATH FAILED", hash_of_context_data
|
60
|
+
|
61
|
+
## Displaying a Status Page
|
62
|
+
|
63
|
+
The secondary purpose to create a dashboard for you. It will display the
|
64
|
+
status of all your systems. All you need is your `account_id` to start
|
65
|
+
the server. It is a single page application written in Sinatra. That
|
66
|
+
means it will run on any rack based server. Here is an example
|
67
|
+
`config.ru`:
|
68
|
+
|
69
|
+
require "rubygems"
|
70
|
+
require "bundler/setup"
|
71
|
+
|
72
|
+
require 'guardian'
|
73
|
+
|
74
|
+
Guardian.account_id = 'your-account-id-here'
|
75
|
+
|
76
|
+
run Guardian::StatusPage
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Guardian do
|
4
|
+
def api_url(string)
|
5
|
+
"#{Guardian::API_URL}/#{string}"
|
6
|
+
end
|
7
|
+
|
8
|
+
subject do
|
9
|
+
Guardian.account_id = 'fake-account-token'
|
10
|
+
Guardian
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:account_id) { 'fake-account-token' }
|
14
|
+
|
15
|
+
it { should respond_to(:account_id=, :account_id) }
|
16
|
+
|
17
|
+
describe 'Getting all the systems' do
|
18
|
+
let(:systems) { ['fake-systems'] }
|
19
|
+
|
20
|
+
it "should raise an error if it's not configured" do
|
21
|
+
subject.account_id = nil
|
22
|
+
lambda { subject.systems }.should raise_error(RuntimeError, /configured/)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should delegate to httparty to find the systems" do
|
26
|
+
mock_response = mock HTTParty::Response
|
27
|
+
|
28
|
+
subject.should_receive(:get).with("/accounts/#{account_id}/systems").
|
29
|
+
and_return(mock_response)
|
30
|
+
|
31
|
+
mock_response.should_receive(:parsed_response).and_return(systems)
|
32
|
+
|
33
|
+
subject.systems.should eql(systems)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Guardian::Notifier do
|
4
|
+
def api_url(string)
|
5
|
+
"#{Guardian::API_URL}/#{string}"
|
6
|
+
end
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
Guardian.account_id = 'fake-account-token'
|
10
|
+
end
|
11
|
+
|
12
|
+
subject { Guardian::Notifier }
|
13
|
+
|
14
|
+
let(:system_id) { 'fake-system-token' }
|
15
|
+
let(:account_id) { 'fake-account-token' }
|
16
|
+
let(:json) do
|
17
|
+
{
|
18
|
+
:update => {
|
19
|
+
:description => 'desc',
|
20
|
+
:data => 'context-info',
|
21
|
+
:online => true
|
22
|
+
},
|
23
|
+
:account_id => account_id
|
24
|
+
}.to_json
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should use the guardian api to create an update" do
|
28
|
+
stub_request(:post, api_url("systems/#{system_id}/updates")).
|
29
|
+
with(:body => json, :content_type => 'application/json').
|
30
|
+
to_return(:status => 201)
|
31
|
+
|
32
|
+
attributes = {
|
33
|
+
:description => 'desc',
|
34
|
+
:data => 'context-info',
|
35
|
+
:online => true
|
36
|
+
}
|
37
|
+
|
38
|
+
Guardian::Notifier.notify(system_id, attributes).should be_true
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should raise an error if the tokens are in correct" do
|
42
|
+
stub_request(:post, api_url("systems/#{system_id}/updates")).
|
43
|
+
to_return(:status => 401)
|
44
|
+
|
45
|
+
lambda { Guardian::Notifier.notify(system_id, :online => true) }.
|
46
|
+
should raise_error(RuntimeError, /authorized/)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should raise an error if it's anything other than 201" do
|
50
|
+
stub_request(:post, api_url("systems/#{system_id}/updates")).
|
51
|
+
to_return(:status => 500)
|
52
|
+
|
53
|
+
lambda { Guardian::Notifier.notify(system_id, :online => true) }.
|
54
|
+
should raise_error(RuntimeError, /unexpected/)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should raise an error if it's offline and there is no description" do
|
58
|
+
lambda { Guardian::Notifier.notify(system_id, :online => false) }.
|
59
|
+
should raise_error(ArgumentError, /missing/)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should raise an error if it's offline is missing" do
|
63
|
+
lambda { Guardian::Notifier.notify(system_id, {}) }.
|
64
|
+
should raise_error(ArgumentError, /:online missing/)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should raise an error if there are invalid keys" do
|
68
|
+
lambda { Guardian::Notifier.notify(system_id, :unknown_key => 'lolwut') }.
|
69
|
+
should raise_error(ArgumentError, /Unknown key/)
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should have a shortcut for taking a system online" do
|
73
|
+
attributes = {:data => 'data', :online => true, :description => 'desc'}
|
74
|
+
Guardian::Notifier.should_receive(:notify).with(system_id, attributes).and_return(true)
|
75
|
+
|
76
|
+
Guardian::Notifier.online(system_id, 'desc', 'data')
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should have a shortcut for taking a system offline" do
|
80
|
+
attributes = {:description => 'description', :data => 'data', :online => false}
|
81
|
+
|
82
|
+
Guardian::Notifier.should_receive(:notify).with(system_id, attributes).and_return(true)
|
83
|
+
|
84
|
+
Guardian::Notifier.offline(system_id, 'description', 'data')
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Guardian::StatusPage, :type => :rack do
|
4
|
+
def app
|
5
|
+
Guardian::StatusPage
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:online_system) do
|
9
|
+
{
|
10
|
+
'name' => 'System 1',
|
11
|
+
'description' => 'fake description',
|
12
|
+
'online' => true,
|
13
|
+
'data_reported' => true,
|
14
|
+
'updated_at' => Time.now,
|
15
|
+
'running_message' => 'GOLIATH ONLINE',
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
let(:offline_system) do
|
20
|
+
{
|
21
|
+
'name' => 'System 2',
|
22
|
+
'description' => 'fake description',
|
23
|
+
'online' => false,
|
24
|
+
'data_reported' => true,
|
25
|
+
'updated_at' => Time.now,
|
26
|
+
'failure_message' => 'fake-status-update',
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
let(:not_updated_system) do
|
31
|
+
{
|
32
|
+
'name' => 'System 3',
|
33
|
+
'description' => 'fake description',
|
34
|
+
'online' => false,
|
35
|
+
'data_reported' => false,
|
36
|
+
'updated_at' => Time.now,
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
let(:systems) { [
|
41
|
+
{'system' => online_system},
|
42
|
+
{'system' => offline_system},
|
43
|
+
{'system' => not_updated_system}
|
44
|
+
] }
|
45
|
+
|
46
|
+
it "should show the names of all the systems" do
|
47
|
+
Guardian.stub!(:systems).and_return(systems)
|
48
|
+
|
49
|
+
get '/'
|
50
|
+
|
51
|
+
last_response.body.should include(online_system['name'])
|
52
|
+
last_response.body.should include(offline_system['name'])
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should show the status of all the sytems" do
|
56
|
+
Guardian.stub!(:systems).and_return(systems)
|
57
|
+
|
58
|
+
get '/'
|
59
|
+
last_response.body.should include('online')
|
60
|
+
last_response.body.should include('offline')
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should show the descriptions of all the sytems" do
|
64
|
+
Guardian.stub!(:systems).and_return(systems)
|
65
|
+
|
66
|
+
get '/'
|
67
|
+
last_response.body.should include(online_system['description'])
|
68
|
+
last_response.body.should include(offline_system['description'])
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
it "should show the up message for an online system" do
|
73
|
+
Guardian.stub!(:systems).and_return(systems)
|
74
|
+
|
75
|
+
get '/'
|
76
|
+
|
77
|
+
last_response.body.should include(online_system['running_message'])
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should show the failure message for offline systems" do
|
81
|
+
Guardian.stub!(:systems).and_return(systems)
|
82
|
+
|
83
|
+
get '/'
|
84
|
+
|
85
|
+
last_response.body.should include(offline_system['failure_message'])
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should show systems that don't have any data" do
|
89
|
+
Guardian.stub!(:systems).and_return(systems)
|
90
|
+
|
91
|
+
get '/'
|
92
|
+
|
93
|
+
last_response.body.should include('No Data Reported')
|
94
|
+
end
|
95
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
SimpleCov.start
|
3
|
+
|
4
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
5
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
6
|
+
require 'rspec'
|
7
|
+
require 'guardian'
|
8
|
+
|
9
|
+
# Requires supporting files with custom matchers and macros, etc,
|
10
|
+
# in ./support/ and its subdirectories.
|
11
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
12
|
+
|
13
|
+
RSpec.configure do |config|
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,180 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: guardian
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Adam Hawkins
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-04-29 00:00:00 -07:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: json
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: "0"
|
25
|
+
type: :runtime
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: httparty
|
29
|
+
prerelease: false
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: "0"
|
36
|
+
type: :runtime
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: sinatra
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id003
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: rspec
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "0"
|
58
|
+
type: :development
|
59
|
+
version_requirements: *id004
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: webmock
|
62
|
+
prerelease: false
|
63
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: "0"
|
69
|
+
type: :development
|
70
|
+
version_requirements: *id005
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: infinity_test
|
73
|
+
prerelease: false
|
74
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: "0"
|
80
|
+
type: :development
|
81
|
+
version_requirements: *id006
|
82
|
+
- !ruby/object:Gem::Dependency
|
83
|
+
name: simplecov
|
84
|
+
prerelease: false
|
85
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: "0"
|
91
|
+
type: :development
|
92
|
+
version_requirements: *id007
|
93
|
+
- !ruby/object:Gem::Dependency
|
94
|
+
name: shotgun
|
95
|
+
prerelease: false
|
96
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: "0"
|
102
|
+
type: :development
|
103
|
+
version_requirements: *id008
|
104
|
+
- !ruby/object:Gem::Dependency
|
105
|
+
name: rack-test
|
106
|
+
prerelease: false
|
107
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: "0"
|
113
|
+
type: :development
|
114
|
+
version_requirements: *id009
|
115
|
+
description: Notify, retreive systems, and misc information from the webservice.
|
116
|
+
email:
|
117
|
+
- adam@guardianapp.com
|
118
|
+
executables: []
|
119
|
+
|
120
|
+
extensions: []
|
121
|
+
|
122
|
+
extra_rdoc_files: []
|
123
|
+
|
124
|
+
files:
|
125
|
+
- .gitignore
|
126
|
+
- .infinity_test
|
127
|
+
- .rspec
|
128
|
+
- .rvmrc
|
129
|
+
- Gemfile
|
130
|
+
- Gemfile.lock
|
131
|
+
- Rakefile
|
132
|
+
- guardian.gemspec
|
133
|
+
- lib/guardian.rb
|
134
|
+
- lib/guardian/notifier.rb
|
135
|
+
- lib/guardian/status_page.rb
|
136
|
+
- lib/guardian/status_page/public/style.css
|
137
|
+
- lib/guardian/status_page/views/index.erb
|
138
|
+
- lib/guardian/version.rb
|
139
|
+
- readme.md
|
140
|
+
- spec/guardian_spec.rb
|
141
|
+
- spec/lib/notifier_spec.rb
|
142
|
+
- spec/lib/status_page_spec.rb
|
143
|
+
- spec/spec_helper.rb
|
144
|
+
- spec/support/server.rb
|
145
|
+
- spec/support/webmock.rb
|
146
|
+
has_rdoc: true
|
147
|
+
homepage: ""
|
148
|
+
licenses: []
|
149
|
+
|
150
|
+
post_install_message:
|
151
|
+
rdoc_options: []
|
152
|
+
|
153
|
+
require_paths:
|
154
|
+
- lib
|
155
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
156
|
+
none: false
|
157
|
+
requirements:
|
158
|
+
- - ">="
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
version: "0"
|
161
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
162
|
+
none: false
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: "0"
|
167
|
+
requirements: []
|
168
|
+
|
169
|
+
rubyforge_project: guardian-gem
|
170
|
+
rubygems_version: 1.6.1
|
171
|
+
signing_key:
|
172
|
+
specification_version: 3
|
173
|
+
summary: Ruby library for interacting with the Guardian webservice.
|
174
|
+
test_files:
|
175
|
+
- spec/guardian_spec.rb
|
176
|
+
- spec/lib/notifier_spec.rb
|
177
|
+
- spec/lib/status_page_spec.rb
|
178
|
+
- spec/spec_helper.rb
|
179
|
+
- spec/support/server.rb
|
180
|
+
- spec/support/webmock.rb
|