runscope_statuspage 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +159 -62
- data/lib/runscope_statuspage/exceptions.rb +1 -3
- data/lib/runscope_statuspage/runscope_api.rb +10 -5
- data/lib/runscope_statuspage/statuspage_api.rb +13 -4
- data/lib/runscope_statuspage/version.rb +1 -1
- data/lib/runscope_statuspage.rb +129 -24
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 741e2f3f579b40a040daf84442387a29148392a7
|
4
|
+
data.tar.gz: 536405a3f5bf68fe04c57efe35384f0cfdc51893
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0bbb5735fb83c37953b4105ac655772bf6a5e589724b7793283481e556d5878914cf6e855ba2966055a22daed242ce67262a9b60f285b0ec987143b854b0bdfd
|
7
|
+
data.tar.gz: 8462ec592908dc9d11715843832758864e321258178050eea037173d813175306bdb477daf0b39114d2e41b5febfe229f9aee45f52568edcbf88a65ea71d1cb8
|
data/README.md
CHANGED
@@ -1,62 +1,159 @@
|
|
1
|
-
# RunscopeStatuspage
|
2
|
-
|
3
|
-
Do you use [RunScope](https://runscope.com) to test your API, and [StatusPage](https://statuspage.io) to show it all off to your customers? Don't want to write bindings for both APIs? If yes, RunscopeStatuspage is perfect for you.
|
4
|
-
|
5
|
-
## Installation
|
6
|
-
|
7
|
-
Add this line to your application's Gemfile:
|
8
|
-
|
9
|
-
```ruby
|
10
|
-
gem 'runscope_statuspage'
|
11
|
-
```
|
12
|
-
|
13
|
-
And then execute:
|
14
|
-
|
15
|
-
$ bundle
|
16
|
-
|
17
|
-
Or install it yourself as:
|
18
|
-
|
19
|
-
$ gem install runscope_statuspage
|
20
|
-
|
21
|
-
## Usage
|
22
|
-
|
23
|
-
In a nutshell, each call will grab metrics from RunScope then send them over to StatusPage, once per call. There is no scheduling done by this gem, it is left as an exercise for the reader. Ideally, you will want to use something such as [Sidekiq](https://github.com/mperham/sidekiq) or [Resque](https://github.com/resque/resque) to fire these jobs off every few minutes/hours. Keep in mind that StatusPage will rate-limit requests to its API, one request per minute.
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
1
|
+
# RunscopeStatuspage
|
2
|
+
|
3
|
+
Do you use [RunScope](https://runscope.com) to test your API, and [StatusPage](https://statuspage.io) to show it all off to your customers? Don't want to write bindings for both APIs? If yes, RunscopeStatuspage is perfect for you.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'runscope_statuspage'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install runscope_statuspage
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
In a nutshell, each call will grab metrics from RunScope then send them over to StatusPage, once per call. There is no scheduling done by this gem, it is left as an exercise for the reader. Ideally, you will want to use something such as [Sidekiq](https://github.com/mperham/sidekiq) or [Resque](https://github.com/resque/resque) to fire these jobs off every few minutes/hours. Keep in mind that StatusPage will rate-limit requests to its API, one request per minute.
|
24
|
+
|
25
|
+
|
26
|
+
### Poll for incidents
|
27
|
+
|
28
|
+
*from general to specific:*
|
29
|
+
|
30
|
+
- *report_everything:* Report all radars of all buckets.
|
31
|
+
```ruby
|
32
|
+
opts = {:status => "page status (either 'investigating|identified|monitoring|resolved')",
|
33
|
+
:twitter_update => 'do you want to post status to twitter (bool)',
|
34
|
+
:fail_on => 'number of failures to induce statuspage update (int, default 0)'}
|
35
|
+
```
|
36
|
+
- *report_buckets:* Report all radars of buckets in list.
|
37
|
+
```ruby
|
38
|
+
opts = {:bucket_names => 'list of names of buckets containing radars',
|
39
|
+
:status => "page status (either 'investigating|identified|monitoring|resolved')",
|
40
|
+
:twitter_update => 'do you want to post status to twitter (bool)',
|
41
|
+
:fail_on => 'number of failures to induce statuspage update (int, default 0)'}
|
42
|
+
```
|
43
|
+
- *report_bucket:* Report all radars in bucket.
|
44
|
+
```ruby
|
45
|
+
opts = {:bucket_name => 'name of bucket containing radars',
|
46
|
+
:status => "page status (either 'investigating|identified|monitoring|resolved')",
|
47
|
+
:twitter_update => 'do you want to post status to twitter (bool)',
|
48
|
+
:fail_on => 'number of failures to induce statuspage update (int, default 0)'}
|
49
|
+
```
|
50
|
+
- *report_radars:* Report radars in list for given bucket.
|
51
|
+
```ruby
|
52
|
+
opts = {:bucket_name => 'name of bucket containing radars',
|
53
|
+
:radar_names => 'list of names of radars within bucket',
|
54
|
+
:status => "page status (either 'investigating|identified|monitoring|resolved')",
|
55
|
+
:twitter_update => 'do you want to post status to twitter (bool)',
|
56
|
+
:fail_on => 'number of failures to induce statuspage update (int, default 0)'}
|
57
|
+
```
|
58
|
+
- *report_radar:* Report one radar in bucket.
|
59
|
+
```ruby
|
60
|
+
opts = {:bucket_name => 'name of bucket containing radars',
|
61
|
+
:radar_name => 'name of radar within bucket',
|
62
|
+
:status => "page status (either 'investigating|identified|monitoring|resolved')",
|
63
|
+
:twitter_update => 'do you want to post status to twitter (bool)',
|
64
|
+
:fail_on => 'number of failures to induce statuspage update (int, default 0)'}
|
65
|
+
```
|
66
|
+
|
67
|
+
#### Important Notes
|
68
|
+
|
69
|
+
- `status` must be either `investigating|identified|monitoring|resolved`.
|
70
|
+
- RunScope likes to throw ISEs if you specify invalid IDs or names, just keep this in mind.
|
71
|
+
- If an exception is thrown while calling `latest_radar_result` in any of the above, it will not halt execution. This is to prevent breaking integrations when a new test is added and `runscope_statuspage` polls before it has the chance to run.
|
72
|
+
|
73
|
+
#### Runscope Bindings
|
74
|
+
Usage:
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
@client = RunscopeStatuspage::RunscopeAPI.new "token"
|
78
|
+
```
|
79
|
+
|
80
|
+
- **buckets**: Get list of buckets.
|
81
|
+
- **bucket_id_by_name(name)**: Get bucket ID from its name.
|
82
|
+
- **radars(bucket)**: Get list of radars for bucket (by ID).
|
83
|
+
- **get_radar(bucket, radar)**: Get radar from bucket (by both IDs)
|
84
|
+
- **latest_radar_result(bucket, radar)**: Get latest result from a radar, by ID.
|
85
|
+
- **messages(bucket, count)**: Get latest messages for bucket (by name).
|
86
|
+
- **message_detail(bucket, message)**: Get message detail (both by ID).
|
87
|
+
|
88
|
+
#### Statuspage Bindings
|
89
|
+
Usage:
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
@client = RunscopeStatuspage::StatspageAPI.new "token"
|
93
|
+
```
|
94
|
+
|
95
|
+
- **create_realtime_incident(page, name, msg, status, twitter)**: Creates a realtime incident.
|
96
|
+
- **push_metric_data(page_id, metric_id, data, timestamp)**: Publish data for a page metric. Data must be either int/float.
|
97
|
+
- **clear_metric_data(page_id, metric_id)**: Clear metric data for a specific page, for a specific metric.
|
98
|
+
|
99
|
+
### Glossary
|
100
|
+
|
101
|
+
- bucket: A group of radars/tests.
|
102
|
+
- radar: A test with one or more assertions.
|
103
|
+
- twitter_update parameter: StatusPage can spit incidents out to Twitter, this is a toggle for this functionality.
|
104
|
+
|
105
|
+
## Changelog
|
106
|
+
|
107
|
+
0.1.3
|
108
|
+
* Changed all functions in `RunscopeStatuspage` to use `options = {}` hash for better readability.
|
109
|
+
* Added `opts[:fail_on]` threshold parameter for greater granularity.
|
110
|
+
* Fixed no parameter issue on `StatuspageAPI.clear_metric_data`
|
111
|
+
* More informative exception messages
|
112
|
+
* Better error handling (not being able to retrieve a radar's latest result will not bring the whole sweep of operations for that bucket down).
|
113
|
+
|
114
|
+
0.1.2
|
115
|
+
* Added Statuspage metrics bindings.
|
116
|
+
|
117
|
+
0.1.1
|
118
|
+
* Fixed bugs + edge cases that shipped with release.
|
119
|
+
|
120
|
+
0.1.0
|
121
|
+
* Initial Release
|
122
|
+
|
123
|
+
## Development and Contributions
|
124
|
+
|
125
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
126
|
+
|
127
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
128
|
+
|
129
|
+
----
|
130
|
+
|
131
|
+
1. Fork it ( https://github.com/[my-github-username]/runscope_statuspage/fork )
|
132
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
133
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
134
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
135
|
+
5. Create a new Pull Request
|
136
|
+
|
137
|
+
## License
|
138
|
+
|
139
|
+
The MIT License (MIT)
|
140
|
+
|
141
|
+
Copyright (c) 2015 David Stancu
|
142
|
+
|
143
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
144
|
+
of this software and associated documentation files (the "Software"), to deal
|
145
|
+
in the Software without restriction, including without limitation the rights
|
146
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
147
|
+
copies of the Software, and to permit persons to whom the Software is
|
148
|
+
furnished to do so, subject to the following conditions:
|
149
|
+
|
150
|
+
The above copyright notice and this permission notice shall be included in
|
151
|
+
all copies or substantial portions of the Software.
|
152
|
+
|
153
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
154
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
155
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
156
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
157
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
158
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
159
|
+
THE SOFTWARE.
|
@@ -24,9 +24,10 @@ module RunscopeStatuspage
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
+
# Get bucket ID by name
|
27
28
|
def bucket_id_by_name(name)
|
28
29
|
self.buckets.each do |bucket|
|
29
|
-
return bucket["key"] if bucket["name"] == name
|
30
|
+
return bucket["key"] if bucket["name"] == name
|
30
31
|
end
|
31
32
|
end
|
32
33
|
|
@@ -49,7 +50,8 @@ module RunscopeStatuspage
|
|
49
50
|
if get_radar['meta']['status'] == 'success'
|
50
51
|
get_radar['data']
|
51
52
|
else
|
52
|
-
raise RunscopeAPIException.new,
|
53
|
+
raise RunscopeAPIException.new,
|
54
|
+
"Error attempting to get radar info for #{bucket}, #{radar}: #{get_radar['error']}"
|
53
55
|
end
|
54
56
|
end
|
55
57
|
end
|
@@ -61,7 +63,8 @@ module RunscopeStatuspage
|
|
61
63
|
if lrr['meta']['status'] == 'success'
|
62
64
|
lrr['data']
|
63
65
|
else
|
64
|
-
raise RunscopeAPIException.new,
|
66
|
+
raise RunscopeAPIException.new,
|
67
|
+
"Error attempting to fetch latest radar result for #{bucket}, #{radar}: #{lrr['error']}"
|
65
68
|
end
|
66
69
|
end
|
67
70
|
end
|
@@ -73,7 +76,8 @@ module RunscopeStatuspage
|
|
73
76
|
if messages['meta']['status'] == 'success'
|
74
77
|
messages['data']
|
75
78
|
else
|
76
|
-
raise RunscopeAPIException.new,
|
79
|
+
raise RunscopeAPIException.new,
|
80
|
+
"Error attempting to fetch messages for #{bucket}: #{detail['error']}"
|
77
81
|
end
|
78
82
|
end
|
79
83
|
end
|
@@ -85,7 +89,8 @@ module RunscopeStatuspage
|
|
85
89
|
if detail['meta']['status'] == 'success'
|
86
90
|
detail['data']
|
87
91
|
else
|
88
|
-
raise RunscopeAPIException.new,
|
92
|
+
raise RunscopeAPIException.new,
|
93
|
+
"Error attempting to fetch message detail for #{bucket}, #{message}: #{detail['error']}"
|
89
94
|
end
|
90
95
|
end
|
91
96
|
end
|
@@ -14,25 +14,34 @@ module RunscopeStatuspage
|
|
14
14
|
|
15
15
|
# Create incident
|
16
16
|
def create_realtime_incident(page, name, msg, status, twitter)
|
17
|
-
self.class.post("/pages/#{page}/incidents.json", @options.merge!(body: {"incident" => {
|
17
|
+
incident = self.class.post("/pages/#{page}/incidents.json", @options.merge!(body: {"incident" => {
|
18
18
|
"name" => name,
|
19
19
|
"message" => msg,
|
20
20
|
"status" => status.nil? ? 'investigating' : status,
|
21
21
|
"wants_twitter_update" => twitter
|
22
22
|
}}))
|
23
|
+
|
24
|
+
raise StatuspageAPIException.new,
|
25
|
+
"Could not create incident: #{incident}" if incident.key?('error')
|
23
26
|
end
|
24
27
|
|
25
28
|
# Publish data for a custom page metric
|
26
29
|
def push_metric_data(page_id, metric_id, data, timestamp)
|
27
|
-
self.class.post("/pages/#{page_id}/metrics/#{metric_id}/data.json", @options.merge!(body: {"data" => {
|
30
|
+
reply = self.class.post("/pages/#{page_id}/metrics/#{metric_id}/data.json", @options.merge!(body: {"data" => {
|
28
31
|
"value" => data,
|
29
32
|
"timestamp" => timestamp
|
30
33
|
}}))
|
34
|
+
|
35
|
+
raise StatuspageAPIException.new,
|
36
|
+
"Could not push to #{page_id}/#{metric_id}: #{reply}" if reply.key?('error')
|
31
37
|
end
|
32
38
|
|
33
39
|
# Delete all data for a custom page metric
|
34
|
-
def clear_metric_data
|
35
|
-
self.class.delete("/pages/#{page_id}/metrics/#{metric_id}/data.json", @options)
|
40
|
+
def clear_metric_data(page_id, metric_id)
|
41
|
+
reply = self.class.delete("/pages/#{page_id}/metrics/#{metric_id}/data.json", @options)
|
42
|
+
|
43
|
+
raise StatuspageAPIException.new,
|
44
|
+
"Could not delete all data for #{page_id}/#{metric_id}: #{reply}" if reply.key?('error')
|
36
45
|
end
|
37
46
|
|
38
47
|
end
|
data/lib/runscope_statuspage.rb
CHANGED
@@ -8,9 +8,7 @@ module RunscopeStatuspage
|
|
8
8
|
class << self; attr_accessor :rs_key, :sp_key, :sp_page, :name, :msg; end
|
9
9
|
|
10
10
|
# API credentials and IDs
|
11
|
-
@rs_key = ''
|
12
|
-
@sp_key = ''
|
13
|
-
@sp_page = ''
|
11
|
+
@rs_key, @sp_key, @sp_page = ''
|
14
12
|
|
15
13
|
# Verbage sent to statuspage
|
16
14
|
@name = 'Suspected issues with /name/'
|
@@ -51,82 +49,189 @@ module RunscopeStatuspage
|
|
51
49
|
|
52
50
|
# Update status page with all radars, from all buckets.
|
53
51
|
# An error will most likely be thrown if you have empty buckets.
|
54
|
-
|
55
|
-
|
52
|
+
#
|
53
|
+
# Parameters: {:status => page status (either 'investigating|identified|monitoring|resolved'),
|
54
|
+
# :twitter_update => do you want to post status to twitter (bool),
|
55
|
+
# :fail_on => number of failures to induce statuspage update (int, default 0)}
|
56
|
+
def self.report_everything(opts={})
|
57
|
+
raise MissingArgumentException.new, 'report_everything is missing arguments' \
|
58
|
+
if not (opts.key?(:status) or opts.key?(:twitter_update))
|
59
|
+
|
60
|
+
opts[:fail_on] = opts.key?(:fail_on) ? opts[:fail_on] : 0
|
61
|
+
failed_radars = []
|
56
62
|
|
63
|
+
reinit_rest
|
57
64
|
@rs.buckets.each do |bucket|
|
58
65
|
@rs.radars(bucket['key']).each do |radar|
|
59
|
-
|
60
|
-
@
|
66
|
+
begin
|
67
|
+
if @rs.latest_radar_result(bucket['key'], radar['uuid'])['result'] != 'pass'
|
68
|
+
failed_radars.push radar
|
69
|
+
end
|
70
|
+
rescue RunscopeAPIException => r
|
71
|
+
p r
|
72
|
+
next
|
61
73
|
end
|
62
74
|
end
|
63
75
|
end
|
76
|
+
|
77
|
+
if failed_radars.length >= opts[:fail_on]
|
78
|
+
failed_radars.each do |radar|
|
79
|
+
@sp.create_realtime_incident(@sp_page, *parameterize(radar).concat([opts[:status], opts[:twitter_update]]))
|
80
|
+
end
|
81
|
+
end
|
64
82
|
end
|
65
83
|
|
66
84
|
# Update status page with one radar, from one bucket.
|
67
|
-
|
68
|
-
|
85
|
+
#
|
86
|
+
# Parameters: {:bucket_name => name of bucket containing radars,
|
87
|
+
# :radar_name => name of radar within bucket,
|
88
|
+
# :status => page status (either 'investigating|identified|monitoring|resolved'),
|
89
|
+
# :twitter_update => do you want to post status to twitter (bool),
|
90
|
+
# :fail_on => number of failures to induce statuspage update (int, default 0)}
|
91
|
+
def self.report_radar(opts = {})
|
92
|
+
raise MissingArgumentException.new, 'report_radar is missing arguments' \
|
93
|
+
if not (opts.key?(:status) or opts.key?(:twitter_update) \
|
94
|
+
or opts.key?(:bucket_name) or opts.key?(:radar_name))
|
95
|
+
|
96
|
+
opts[:fail_on] = opts.key?(:fail_on) ? opts[:fail_on] : 0
|
97
|
+
failed_radars = []
|
69
98
|
|
99
|
+
reinit_rest
|
70
100
|
@rs.buckets.each do |bucket|
|
71
101
|
if bucket['name'] == bucket_name
|
72
102
|
@rs.radars(bucket['key']).each do |radar|
|
73
|
-
|
74
|
-
@
|
103
|
+
begin
|
104
|
+
if @rs.latest_radar_result(bucket['key'], radar['uuid'])['result'] != 'pass' and radar['name'] == radar_name
|
105
|
+
failed_radars.push radar
|
106
|
+
end
|
107
|
+
rescue RunscopeAPIException => r
|
108
|
+
p r
|
109
|
+
next
|
75
110
|
end
|
76
111
|
end
|
77
112
|
end
|
78
113
|
end
|
79
114
|
|
115
|
+
if failed_radars.length >= opts[:fail_on]
|
116
|
+
failed_radars.each do |radar|
|
117
|
+
@sp.create_realtime_incident(@sp_page, *parameterize(radar).concat([opts[:status], opts[:twitter_update]]))
|
118
|
+
end
|
119
|
+
end
|
80
120
|
end
|
81
121
|
|
82
122
|
# Update status page with list of radars, from one bucket.
|
83
|
-
|
84
|
-
|
123
|
+
#
|
124
|
+
# Parameters: {:bucket_name => name of bucket containing radars,
|
125
|
+
# :radar_names => list of names of radars within bucket,
|
126
|
+
# :status => page status (either 'investigating|identified|monitoring|resolved'),
|
127
|
+
# :twitter_update => do you want to post status to twitter (bool),
|
128
|
+
# :fail_on => number of failures to induce statuspage update (int, default 0)}
|
129
|
+
def self.report_radars(opts = {})
|
130
|
+
raise MissingArgumentException.new, 'report_radars is missing arguments' \
|
131
|
+
if not (opts.key?(:status) or opts.key?(:twitter_update) \
|
132
|
+
or opts.key?(:bucket_name) or opts.key?(:radar_names))
|
133
|
+
|
134
|
+
opts[:fail_on] = opts.key?(:fail_on) ? opts[:fail_on] : 0
|
135
|
+
failed_radars = []
|
85
136
|
|
137
|
+
reinit_rest
|
86
138
|
@rs.buckets.each do |bucket|
|
87
|
-
if bucket['name'] == bucket_name
|
139
|
+
if bucket['name'] == opts[:bucket_name]
|
88
140
|
@rs.radars(bucket['key']).each do |radar|
|
89
|
-
|
90
|
-
@
|
141
|
+
begin
|
142
|
+
if @rs.latest_radar_result(bucket['key'], radar['uuid'])['result'] != 'pass' and opts[:radar_names].include?(radar['name'])
|
143
|
+
failed_radars.push radar
|
144
|
+
end
|
145
|
+
rescue RunscopeAPIException => r
|
146
|
+
p r
|
147
|
+
next
|
91
148
|
end
|
92
149
|
end
|
93
150
|
end
|
94
151
|
end
|
95
152
|
|
153
|
+
if failed_radars.length >= opts[:fail_on]
|
154
|
+
failed_radars.each do |radar|
|
155
|
+
@sp.create_realtime_incident(@sp_page, *parameterize(radar).concat([opts[:status], opts[:twitter_update]]))
|
156
|
+
end
|
157
|
+
end
|
96
158
|
end
|
97
159
|
|
98
160
|
# Update status page with all radars under passed
|
99
161
|
# bucket name.
|
100
|
-
|
101
|
-
|
162
|
+
#
|
163
|
+
# Parameters: {:bucket_name => name of bucket containing radars,
|
164
|
+
# :status => page status (either 'investigating|identified|monitoring|resolved'),
|
165
|
+
# :twitter_update => do you want to post status to twitter (bool),
|
166
|
+
# :fail_on => number of failures to induce statuspage update (int, default 0)}
|
167
|
+
def self.report_bucket(opts={})
|
168
|
+
raise MissingArgumentException.new, 'report_bucket is missing arguments' \
|
169
|
+
if not (opts.key?(:status) or opts.key?(:twitter_update) \
|
170
|
+
or opts.key?(:bucket_name))
|
171
|
+
|
172
|
+
opts[:fail_on] = opts.key?(:fail_on) ? opts[:fail_on] : 0
|
173
|
+
failed_radars = []
|
102
174
|
|
175
|
+
reinit_rest
|
103
176
|
@rs.buckets.each do |bucket|
|
104
|
-
if bucket['name'] == bucket_name
|
177
|
+
if bucket['name'] == opts[:bucket_name]
|
105
178
|
@rs.radars(bucket['key']).each do |radar|
|
106
|
-
|
107
|
-
@
|
179
|
+
begin
|
180
|
+
if @rs.latest_radar_result(bucket['key'], radar['uuid'])['result'] != 'pass'
|
181
|
+
failed_radars.push radar
|
182
|
+
end
|
183
|
+
rescue RunscopeAPIException => r
|
184
|
+
p r
|
185
|
+
next
|
108
186
|
end
|
109
187
|
end
|
110
188
|
end
|
111
189
|
end
|
112
190
|
|
191
|
+
if failed_radars.length >= opts[:fail_on]
|
192
|
+
failed_radars.each do |radar|
|
193
|
+
@sp.create_realtime_incident(@sp_page, *parameterize(radar).concat([opts[:status], opts[:twitter_update]]))
|
194
|
+
end
|
195
|
+
end
|
113
196
|
end
|
114
197
|
|
115
198
|
# Update status page with all radars under the specified
|
116
199
|
# buckets
|
200
|
+
#
|
201
|
+
# Parameters: {:bucket_names => list of names of buckets containing radars,
|
202
|
+
# :status => page status (either 'investigating|identified|monitoring|resolved'),
|
203
|
+
# :twitter_update => do you want to post status to twitter (bool),
|
204
|
+
# :fail_on => number of failures to induce statuspage update (int, default 0)}
|
117
205
|
def self.report_buckets(bucket_names, status, twitter_update)
|
206
|
+
raise MissingArgumentException.new, 'report_buckets is missing arguments' \
|
207
|
+
if not (opts.key?(:status) or opts.key?(:twitter_update) \
|
208
|
+
or opts.key?(:bucket_name))
|
209
|
+
|
210
|
+
opts[:fail_on] = opts.key?(:fail_on) ? opts[:fail_on] : 0
|
211
|
+
failed_radars = []
|
212
|
+
|
118
213
|
reinit_rest
|
119
214
|
|
120
215
|
@rs.buckets.each do |bucket|
|
121
|
-
if bucket_names.include?(bucket['name'])
|
216
|
+
if opts[:bucket_names].include?(bucket['name'])
|
122
217
|
@rs.radars(bucket['key']).each do |radar|
|
123
|
-
|
124
|
-
@
|
218
|
+
begin
|
219
|
+
if @rs.latest_radar_result(bucket['key'], radar['uuid'])['result'] != 'pass'
|
220
|
+
failed_radars.push radar
|
221
|
+
end
|
222
|
+
rescue RunscopeAPIException => r
|
223
|
+
p r
|
224
|
+
next
|
125
225
|
end
|
126
226
|
end
|
127
227
|
end
|
128
228
|
end
|
129
229
|
|
230
|
+
if failed_radars.length >= opts[:fail_on]
|
231
|
+
failed_radars.each do |radar|
|
232
|
+
@sp.create_realtime_incident(@sp_page, *parameterize(radar).concat([opts[:status], opts[:twitter_update]]))
|
233
|
+
end
|
234
|
+
end
|
130
235
|
end
|
131
236
|
|
132
237
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: runscope_statuspage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Stancu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|