umarcts-sensu-plugins-statuspage 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +41 -0
- data/LICENSE +22 -0
- data/README.md +127 -0
- data/bin/umarcts-handler-statuspage.rb +134 -0
- data/bin/umarcts-metrics-statuspageio.rb +62 -0
- data/lib/redphone/helpers.rb +61 -0
- data/lib/redphone/statuspage.rb +144 -0
- data/lib/umarcts-sensu-plugins-statuspage.rb +3 -0
- data/lib/umarcts-sensu-plugins-statuspage/version.rb +11 -0
- metadata +214 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9530f89829a4cdb789cc74953c1e629cb4b94db9
|
4
|
+
data.tar.gz: d31d95956b843841cf7cac5be98763180de6e87c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2195a39c384b33b72958c1c4aa2e155d869f65292871af1dcbeb7b04929c5ffe18f844aeab4bdb908a741c96180bc5bf0d45a1f3d3d3c7f7758a7245bb48e008
|
7
|
+
data.tar.gz: 2789242c1c05eca3c8c4b63f4d8ce4bb0bb1164568db383f0584e5b15a8f60aca4356819c233e8fdfba281b67878ef09bd83448239195f005031786557e51ba8
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Change Log
|
2
|
+
This project adheres to [Semantic Versioning](http://semver.org/).
|
3
|
+
|
4
|
+
This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachangelog.com/)
|
5
|
+
|
6
|
+
## [Unreleased]
|
7
|
+
|
8
|
+
## [1.1.0] - 2017-06
|
9
|
+
### Added
|
10
|
+
- handler-statuspage.rb: add ability to send requests through an unauthenticated proxy (@drhey)
|
11
|
+
|
12
|
+
## [1.0.0] - 2017-05-16
|
13
|
+
### Added
|
14
|
+
- Support for Ruby 2.3 and 2.4 (@eheydrick)
|
15
|
+
|
16
|
+
### Removed
|
17
|
+
- Support for Ruby < 2 (@eheydrick)
|
18
|
+
|
19
|
+
### Changed
|
20
|
+
- Allow desired component/incident status configuration per check. (@athal7)
|
21
|
+
- Update existing incidents on any change, not just on resolution. (@athal7)
|
22
|
+
- 'minor' alerts are now mapped to 'partial_outage' component status (@athal7)
|
23
|
+
- All alerts make the incident status 'identified' rather than 'investigating' (@athal7)
|
24
|
+
|
25
|
+
## [0.0.3] - 2015-12-30
|
26
|
+
### Changed
|
27
|
+
- fixed incident resolving
|
28
|
+
|
29
|
+
## [0.0.2] - 2015-07-14
|
30
|
+
### Changed
|
31
|
+
- updated sensu-plugin gem to 1.2.0
|
32
|
+
|
33
|
+
## 0.0.1 - 2015-07-04
|
34
|
+
### Added
|
35
|
+
- initial release
|
36
|
+
|
37
|
+
[Unreleased]: https://github.com/sensu-plugins/sensu-plugins-statuspage/compare/1.1.0...HEAD
|
38
|
+
[1.1.0]: https://github.com/sensu-plugins/sensu-plugins-statuspage/compare/1.0.0...1.1.0
|
39
|
+
[1.0.0]: https://github.com/sensu-plugins/sensu-plugins-statuspage/compare/0.0.3...1.0.0
|
40
|
+
[0.0.3]: https://github.com/sensu-plugins/sensu-plugins-statuspage/compare/0.0.2...0.0.3
|
41
|
+
[0.0.2]: https://github.com/sensu-plugins/sensu-plugins-statuspage/compare/0.0.1...0.0.2
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Sensu-Plugins
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
## umarcts-sensu-plugins-statuspage
|
2
|
+
|
3
|
+
## Functionality
|
4
|
+
|
5
|
+
This is a fork of the original plugin from https://github.com/sensu-plugins/sensu-plugins-statuspage. Rather than having individual machines report into StatusPage, we wanted Sensu check aggregates to be the main generator of information into StatusPage. This took only a small reworking of the original code.
|
6
|
+
|
7
|
+
Instead of creating StatusPage incidents from information like `@event['client']['name'] + '/' + @event['check']['name']`, the handler will now look for a custom check attribute (`@event['check']['custom']['incident_name']`) in the event data and title the StatusPage incident name after that (for ease of understanding).
|
8
|
+
|
9
|
+
Also The Redphone functionality required by this plugin has now been baked in. One no longer has to clone the Redphone repo, build, and install from scratch. Also, proxy address and port have been added to this handler as well as the dependent Redphone bits.
|
10
|
+
|
11
|
+
**handler-statuspage**
|
12
|
+
|
13
|
+
Creates an issue on StatusPage.io and (optionally) updates a component status.
|
14
|
+
|
15
|
+
**metrics-statuspageio**
|
16
|
+
|
17
|
+
Sends graphite-style metrics to statuspage.io, for displaying public metrics. Note, this forks and is not meant for high-throughput. Rather, it is meant for high-value, low-throughput metrics for display on status page.
|
18
|
+
|
19
|
+
## Files
|
20
|
+
* bin/handler-statuspage
|
21
|
+
* bin/metrics-statuspageio
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
**handler-statuspage**
|
26
|
+
```
|
27
|
+
{
|
28
|
+
"statuspage": {
|
29
|
+
"api_key": "YOURAPIKEY",
|
30
|
+
"page_id": "YOURPAGEID"
|
31
|
+
}
|
32
|
+
}
|
33
|
+
```
|
34
|
+
|
35
|
+
For use of a basic proxy, use "proxy_address" and "proxy_port":
|
36
|
+
```
|
37
|
+
{
|
38
|
+
"statuspage": {
|
39
|
+
"api_key": "YOURAPIKEY",
|
40
|
+
"page_id": "YOURPAGEID",
|
41
|
+
"proxy_port": "YOURPROXY",
|
42
|
+
"proxy_address": "YOURPROXYADDRESS"
|
43
|
+
}
|
44
|
+
}
|
45
|
+
```
|
46
|
+
|
47
|
+
**metrics-statuspageio**
|
48
|
+
```
|
49
|
+
{
|
50
|
+
"metrics-statuspageio": {
|
51
|
+
"api_key": "my_api_key",
|
52
|
+
"page_id": "my_page_id",
|
53
|
+
"metrics": {
|
54
|
+
"some.metric.identifier": "my_metric_id",
|
55
|
+
"another.metric.identifier": "another_metric_id"
|
56
|
+
}
|
57
|
+
}
|
58
|
+
}
|
59
|
+
```
|
60
|
+
## Installation
|
61
|
+
|
62
|
+
[Installation and Setup](http://sensu-plugins.io/docs/installation_instructions.html)
|
63
|
+
|
64
|
+
## Notes
|
65
|
+
|
66
|
+
To update a component add a `"component_id": "IDHERE"` attribute to the corresponding check definition
|
67
|
+
|
68
|
+
Example:
|
69
|
+
```
|
70
|
+
{
|
71
|
+
"checks": {
|
72
|
+
"check_sshd": {
|
73
|
+
"handlers": ["statuspage"],
|
74
|
+
"component_id": "IDHERE",
|
75
|
+
"command": "/etc/sensu/plugins/check-procs.rb -p sshd -C 1 ",
|
76
|
+
"interval": 60,
|
77
|
+
"subscribers": [ "default" ]
|
78
|
+
}
|
79
|
+
}
|
80
|
+
}
|
81
|
+
```
|
82
|
+
|
83
|
+
To choose your own component or incident statuses instead of the defaults add the `statuspage_<component/incident>_<status>` in the check definition.
|
84
|
+
|
85
|
+
Example:
|
86
|
+
```
|
87
|
+
{
|
88
|
+
"checks": {
|
89
|
+
"check_sshd": {
|
90
|
+
"handlers": ["statuspage"],
|
91
|
+
"component_id": "IDHERE",
|
92
|
+
"statuspage_component_warning": "degraded_performance",
|
93
|
+
"statuspage_component_critical": "partial_outage",
|
94
|
+
"statuspage_incident_warning": "ignore",
|
95
|
+
"statuspage_incident_critical": "identified",
|
96
|
+
"command": "/etc/sensu/plugins/check-procs.rb -p sshd -C 1 ",
|
97
|
+
"interval": 60,
|
98
|
+
"subscribers": [ "default" ]
|
99
|
+
}
|
100
|
+
}
|
101
|
+
}
|
102
|
+
```
|
103
|
+
|
104
|
+
To choose the name of your incident that will be reported to StatusPage, simply add a custom attribute (e.g. `"custom": { "incident_name": "What you want the incident to be called" },`) like this in your check definition:
|
105
|
+
|
106
|
+
Example:
|
107
|
+
```
|
108
|
+
{
|
109
|
+
"checks": {
|
110
|
+
"check_keepalive_aggregate": {
|
111
|
+
"command": "check-aggregate.rb -c AGGREGATENAME -C 66 -W 33 -a http://127.0.0.1:4567 -u USER -p PASSWORD",
|
112
|
+
"handle": true,
|
113
|
+
"interval": 30,
|
114
|
+
"occurrences": 5,
|
115
|
+
"handlers": [ "statuspage" ],
|
116
|
+
"component_id": "IDHERE",
|
117
|
+
"custom": {
|
118
|
+
"incident_name": "Compute Nodes"
|
119
|
+
},
|
120
|
+
"refresh": 3600,
|
121
|
+
"standalone": true
|
122
|
+
}
|
123
|
+
}
|
124
|
+
}
|
125
|
+
```
|
126
|
+
|
127
|
+
The handler is specifically looking for the above to be defined. If it's not, then incident_key won't be defined in the handler and this will cause errors and improper functionality
|
@@ -0,0 +1,134 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This handler creates and updates incidents and changes a component status (optional) for StatusPage.IO.
|
4
|
+
# Due to a bug with their API, please pair a Twitter account to your StatusPage even if you don't plan to tweet.
|
5
|
+
#
|
6
|
+
# Copyright 2011 Sonian, Inc <chefs@sonian.net>
|
7
|
+
# Copyright 2013 DISQUS, Inc.
|
8
|
+
# Updated by jfledvin with Basic Component Support 4/14/2015
|
9
|
+
#
|
10
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
11
|
+
# for details.
|
12
|
+
|
13
|
+
require 'sensu-handler'
|
14
|
+
require 'redphone/statuspage'
|
15
|
+
|
16
|
+
ALLOWED_COMPONENT_STATUSES = %w(operational degraded_performance partial_outage major_outage ignore).freeze
|
17
|
+
DEFAULT_COMPONENT_STATUSES = {
|
18
|
+
'warning' => 'partial_outage',
|
19
|
+
'critical' => 'major_outage'
|
20
|
+
}.freeze
|
21
|
+
|
22
|
+
ALLOWED_INCIDENT_STATUSES = %w(investigating identified monitoring resolved ignore).freeze
|
23
|
+
DEFAULT_INCIDENT_STATUSES = {
|
24
|
+
'warning' => 'identified',
|
25
|
+
'critical' => 'identified'
|
26
|
+
}.freeze
|
27
|
+
|
28
|
+
# main plugin class
|
29
|
+
class StatusPage < Sensu::Handler
|
30
|
+
def incident_key
|
31
|
+
@event['check']['custom']['incident_name']
|
32
|
+
end
|
33
|
+
|
34
|
+
def status_name
|
35
|
+
case @event['check']['status']
|
36
|
+
when 1
|
37
|
+
'warning'
|
38
|
+
when 2
|
39
|
+
'critical'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def component_status
|
44
|
+
case @event['action']
|
45
|
+
when 'create'
|
46
|
+
desired_status = @event['check']["statuspage_component_#{status_name}"]
|
47
|
+
if desired_status && ALLOWED_COMPONENT_STATUSES.include?(desired_status)
|
48
|
+
desired_status
|
49
|
+
else
|
50
|
+
DEFAULT_COMPONENT_STATUSES[status_name]
|
51
|
+
end
|
52
|
+
when 'resolve'
|
53
|
+
'operational'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def incident_status
|
58
|
+
case @event['action']
|
59
|
+
when 'create'
|
60
|
+
desired_status = @event['check']["statuspage_incident_#{status_name}"]
|
61
|
+
if desired_status && ALLOWED_INCIDENT_STATUSES.include?(desired_status)
|
62
|
+
desired_status
|
63
|
+
else
|
64
|
+
DEFAULT_INCIDENT_STATUSES[status_name]
|
65
|
+
end
|
66
|
+
when 'resolve'
|
67
|
+
'resolved'
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def ignore_status?(status)
|
72
|
+
['ignore', nil].include?(status)
|
73
|
+
end
|
74
|
+
|
75
|
+
def description
|
76
|
+
@event['check']['custom']['description'] || [@event['client']['name'], @event['check']['name'], @event['check']['output']].join(' : ')
|
77
|
+
end
|
78
|
+
|
79
|
+
def incident_message(status)
|
80
|
+
if status == 'resolved'
|
81
|
+
"Problem with #{incident_key} has been resolved."
|
82
|
+
else
|
83
|
+
"There has been a problem: #{description}."
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def handle
|
88
|
+
statuspage = Redphone::Statuspage.new(
|
89
|
+
page_id: settings['statuspage']['page_id'],
|
90
|
+
api_key: settings['statuspage']['api_key'],
|
91
|
+
proxy_address: settings['statuspage']['proxy_address'],
|
92
|
+
proxy_port: settings['statuspage']['proxy_port']
|
93
|
+
)
|
94
|
+
begin
|
95
|
+
Timeout.timeout(3) do
|
96
|
+
if @event['check'].key?('component_id')
|
97
|
+
unless ignore_status?(component_status)
|
98
|
+
statuspage.update_component(
|
99
|
+
component_id: @event['check']['component_id'],
|
100
|
+
status: component_status
|
101
|
+
)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
existing_incident = statuspage.get_all_incidents.detect { |incident| incident['name'] == incident_key && incident['status'] != 'resolved' }
|
105
|
+
response = if existing_incident
|
106
|
+
statuspage.update_incident(
|
107
|
+
name: incident_key,
|
108
|
+
wants_twitter_update: 'f',
|
109
|
+
status: incident_status,
|
110
|
+
incident_id: existing_incident['id'],
|
111
|
+
message: incident_message(incident_status)
|
112
|
+
)
|
113
|
+
elsif !ignore_status?(incident_status)
|
114
|
+
statuspage.create_realtime_incident(
|
115
|
+
name: incident_key,
|
116
|
+
status: incident_status,
|
117
|
+
wants_twitter_update: 'f',
|
118
|
+
message: incident_message(incident_status)
|
119
|
+
)
|
120
|
+
end
|
121
|
+
if ignore_status?(incident_status) ||
|
122
|
+
(response['status'] == incident_status && @event['action'] == 'create') ||
|
123
|
+
(response['status'] == 'resolved' && @event['action'] == 'resolve')
|
124
|
+
|
125
|
+
puts 'statuspage -- ' + @event['action'].capitalize + 'd incident -- ' + incident_key
|
126
|
+
else
|
127
|
+
puts 'statuspage -- failed to ' + @event['action'] + ' incident -- ' + incident_key
|
128
|
+
end
|
129
|
+
end
|
130
|
+
rescue Timeout::Error
|
131
|
+
puts 'statuspage -- timed out while attempting to ' + @event['action'] + ' a incident -- ' + incident_key
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Copyright 2013 Nick Stielau
|
4
|
+
#
|
5
|
+
# This handler will send graphite-style metrics to statuspage.io, for
|
6
|
+
# displaying public metrics. Note, this forks and is not meant for
|
7
|
+
# high-throughput. Rather, it is meant for high-value, low-throughput
|
8
|
+
# metrics for display on status page.
|
9
|
+
#
|
10
|
+
# Depends on httpary gem
|
11
|
+
# gem install httparty
|
12
|
+
#
|
13
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
14
|
+
# for details.
|
15
|
+
|
16
|
+
require 'sensu-handler'
|
17
|
+
require 'httparty'
|
18
|
+
|
19
|
+
# main plugin class
|
20
|
+
class StatusPageIOMetrics < Sensu::Handler
|
21
|
+
# override filters from Sensu::Handler. not appropriate for metric handlers
|
22
|
+
def filter; end
|
23
|
+
|
24
|
+
def send_metric(value, timestamp, metric_id)
|
25
|
+
# puts "Sending #{value} #{timestamp} #{metric_id}"
|
26
|
+
timeout(3) do
|
27
|
+
HTTParty.post(
|
28
|
+
"https://api.statuspage.io/v1/pages/#{@page_id}/metrics/#{metric_id}/data.json",
|
29
|
+
headers: { 'Authorization' => "OAuth #{@api_key}" },
|
30
|
+
body: {
|
31
|
+
data: {
|
32
|
+
timestamp: timestamp,
|
33
|
+
value: value.to_f
|
34
|
+
}
|
35
|
+
}
|
36
|
+
)
|
37
|
+
end
|
38
|
+
rescue Timeout::Error
|
39
|
+
puts 'statuspageio -- timed out while sending metrics'
|
40
|
+
rescue => error
|
41
|
+
puts "statuspageio -- failed to send metric #{metric_id} : #{error}"
|
42
|
+
end
|
43
|
+
|
44
|
+
def handle
|
45
|
+
# Grab page_id and api_key from dashboard
|
46
|
+
@api_key = settings['handlers']['statuspageio_metrics']['api_key']
|
47
|
+
@page_id = settings['handlers']['statuspageio_metrics']['page_id']
|
48
|
+
|
49
|
+
# Get a dict of metric_from_output => metric_ids
|
50
|
+
# This allows the re-use of standard metrics plugins that can be mapped to
|
51
|
+
# statuspage io metrics
|
52
|
+
@metrics = settings['handlers']['statuspageio_metrics']['metrics'] || {}
|
53
|
+
|
54
|
+
# Split graphite-style metrics
|
55
|
+
@event['check']['output'].split(/\n/).each do |m|
|
56
|
+
metric, value, timestamp = m.split
|
57
|
+
# Get the metric ID from the check, or from the global mapping
|
58
|
+
metric_id = @event['check']['statuspageio_metric_id'] || @metrics[metric]
|
59
|
+
send_metric(value, timestamp, metric_id) if metric_id
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require "rubygems" if RUBY_VERSION < "1.9.0"
|
2
|
+
require "net/http"
|
3
|
+
require "net/https"
|
4
|
+
require "uri"
|
5
|
+
require "json"
|
6
|
+
require "cgi"
|
7
|
+
|
8
|
+
def http_request(options={})
|
9
|
+
raise "You must supply a URI" if options[:uri].nil?
|
10
|
+
method = options[:method] || "get"
|
11
|
+
uri = URI.parse(options[:uri])
|
12
|
+
user = options[:user]
|
13
|
+
password = options[:password]
|
14
|
+
headers = options[:headers] || Hash.new
|
15
|
+
parameters = options[:parameters] || Hash.new
|
16
|
+
body = options[:body]
|
17
|
+
proxy_address = options[:proxy_address]
|
18
|
+
proxy_port = options[:proxy_port]
|
19
|
+
http = if @proxy_address.nil?
|
20
|
+
Net::HTTP.new(uri.host, uri.port)
|
21
|
+
else
|
22
|
+
Net::HTTP::Proxy(@proxy_address, @proxy_port).new(uri.host, uri.port)
|
23
|
+
end
|
24
|
+
if options[:ssl] == true
|
25
|
+
http.use_ssl = true
|
26
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
27
|
+
end
|
28
|
+
request_uri = uri.request_uri
|
29
|
+
unless parameters.empty?
|
30
|
+
request_uri += "?"
|
31
|
+
request_uri += parameters.map { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join("&")
|
32
|
+
end
|
33
|
+
request = case method
|
34
|
+
when "get"
|
35
|
+
Net::HTTP::Get.new(request_uri)
|
36
|
+
when "post"
|
37
|
+
Net::HTTP::Post.new(request_uri)
|
38
|
+
when "put"
|
39
|
+
Net::HTTP::Put.new(request_uri)
|
40
|
+
when "delete"
|
41
|
+
Net::HTTP::Delete.new(request_uri)
|
42
|
+
when "patch"
|
43
|
+
Net::HTTP::Patch.new(request_uri)
|
44
|
+
else
|
45
|
+
raise "Unknown HTTP method: #{method}"
|
46
|
+
end
|
47
|
+
headers.each do |header, value|
|
48
|
+
request.add_field(header, value)
|
49
|
+
end
|
50
|
+
if user && password
|
51
|
+
request.basic_auth user, password
|
52
|
+
end
|
53
|
+
request.body = body
|
54
|
+
http.request(request)
|
55
|
+
end
|
56
|
+
|
57
|
+
def has_options(options={}, required=[])
|
58
|
+
required.each do |option|
|
59
|
+
raise "You must supply a #{option}" unless options.has_key?(option) && !options[option].nil?
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,144 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'helpers')
|
2
|
+
|
3
|
+
module Redphone
|
4
|
+
class Statuspage
|
5
|
+
def initialize(options={})
|
6
|
+
has_options(options, [:api_key, :page_id])
|
7
|
+
@proxy_address = options[:proxy_address]
|
8
|
+
@proxy_port = options[:proxy_port]
|
9
|
+
@page_id = options[:page_id]
|
10
|
+
@request_options = {
|
11
|
+
:ssl => true,
|
12
|
+
:headers => {"Authorization" => "OAuth #{options[:api_key]}"}
|
13
|
+
}
|
14
|
+
@api_url = "https://api.statuspage.io/v1/pages/#{@page_id}/"
|
15
|
+
end
|
16
|
+
|
17
|
+
def convert_options(options={})
|
18
|
+
incident_options = Hash.new
|
19
|
+
options.each do |key, val|
|
20
|
+
incident_options["incident[#{key}]"] = val
|
21
|
+
end
|
22
|
+
return incident_options
|
23
|
+
end
|
24
|
+
|
25
|
+
def check_attributes(options={}, checked_options=[])
|
26
|
+
checked_options.each do |option|
|
27
|
+
raise "You must supply an incident #{option}." if options[option].nil?
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def get_all_incidents()
|
32
|
+
response = http_request(
|
33
|
+
@request_options.merge({
|
34
|
+
:method => "get",
|
35
|
+
:uri => @api_url + "incidents.json"
|
36
|
+
})
|
37
|
+
)
|
38
|
+
JSON.parse(response.body)
|
39
|
+
end
|
40
|
+
|
41
|
+
def create_realtime_incident(options={})
|
42
|
+
check_attributes(options, [:name, :wants_twitter_update])
|
43
|
+
options = convert_options(options)
|
44
|
+
response = http_request(
|
45
|
+
@request_options.merge({
|
46
|
+
:method => "post",
|
47
|
+
:uri => @api_url + "incidents.json",
|
48
|
+
:parameters => options
|
49
|
+
})
|
50
|
+
)
|
51
|
+
JSON.parse(response.body)
|
52
|
+
end
|
53
|
+
|
54
|
+
def create_scheduled_incident(options={})
|
55
|
+
check_attributes(options, [:name, :status, :wants_twitter_update, :scheduled_for, :scheduled_until])
|
56
|
+
options = convert_options(options)
|
57
|
+
response = http_request(
|
58
|
+
@request_options.merge({
|
59
|
+
:method => "post",
|
60
|
+
:uri => @api_url + "incidents.json",
|
61
|
+
:parameters => options
|
62
|
+
})
|
63
|
+
)
|
64
|
+
JSON.parse(response.body)
|
65
|
+
end
|
66
|
+
|
67
|
+
def create_historical_incident(options={})
|
68
|
+
check_attributes(options, [:name, :message, :backfilled, :backfill_date])
|
69
|
+
options = convert_options(options)
|
70
|
+
response = http_request(
|
71
|
+
@request_options.merge({
|
72
|
+
:method => "post",
|
73
|
+
:uri => @api_url + "incidents.json",
|
74
|
+
:parameters => options
|
75
|
+
})
|
76
|
+
)
|
77
|
+
JSON.parse(response.body)
|
78
|
+
end
|
79
|
+
|
80
|
+
def update_incident(options={})
|
81
|
+
check_attributes(options, [:name, :wants_twitter_update, :incident_id])
|
82
|
+
incident_id = options[:incident_id]
|
83
|
+
options.delete(:incident_id)
|
84
|
+
options = convert_options(options)
|
85
|
+
response = http_request(
|
86
|
+
@request_options.merge({
|
87
|
+
:method => "patch",
|
88
|
+
:uri => @api_url + "incidents/#{incident_id}.json",
|
89
|
+
:parameters => options
|
90
|
+
})
|
91
|
+
)
|
92
|
+
JSON.parse(response.body)
|
93
|
+
end
|
94
|
+
|
95
|
+
def delete_incident(options={})
|
96
|
+
check_attributes(options, [:incident_id])
|
97
|
+
response = http_request(
|
98
|
+
@request_options.merge({
|
99
|
+
:method => "delete",
|
100
|
+
:uri => @api_url + "incidents/#{options[:incident_id]}.json"
|
101
|
+
})
|
102
|
+
)
|
103
|
+
JSON.parse(response.body)
|
104
|
+
end
|
105
|
+
|
106
|
+
def tune_incident_update(options={})
|
107
|
+
check_attributes(options, [:incident_id, :incident_update_id])
|
108
|
+
parameter_options = Hash.new
|
109
|
+
parameter_options["incident_update[body]"] = options[:body] unless options[:body].nil?
|
110
|
+
parameter_options["incident_update[display_at]"] = options[:display_at] unless options[:display_at].nil?
|
111
|
+
response = http_request(
|
112
|
+
@request_options.merge({
|
113
|
+
:method => "patch",
|
114
|
+
:uri => @api_url + "incidents/#{options[:incident_id]}/incident_updates/#{options[:incident_update_id]}.json",
|
115
|
+
:parameters => parameter_options
|
116
|
+
})
|
117
|
+
)
|
118
|
+
JSON.parse(response.body)
|
119
|
+
end
|
120
|
+
|
121
|
+
def get_all_components()
|
122
|
+
response = http_request(
|
123
|
+
@request_options.merge({
|
124
|
+
:method => "get",
|
125
|
+
:uri => @api_url + "components.json"
|
126
|
+
})
|
127
|
+
)
|
128
|
+
JSON.parse(response.body)
|
129
|
+
end
|
130
|
+
|
131
|
+
def update_component(options={})
|
132
|
+
check_attributes(options, [:component_id, :status])
|
133
|
+
parameter_options = {"component[status]" => options[:status]}
|
134
|
+
response = http_request(
|
135
|
+
@request_options.merge({
|
136
|
+
:method => "patch",
|
137
|
+
:uri => @api_url + "components/#{options[:component_id]}.json",
|
138
|
+
:parameters => parameter_options
|
139
|
+
})
|
140
|
+
)
|
141
|
+
JSON.parse(response.body)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
metadata
ADDED
@@ -0,0 +1,214 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: umarcts-sensu-plugins-statuspage
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sensu-Plugins and contributors
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-07-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sensu-plugin
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: httparty
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.13.5
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.13.5
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.7'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: codeclimate-test-reporter
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.4'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.4'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: github-markup
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.3'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.3'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.10'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.10'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.40.0
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.40.0
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '3.1'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '3.1'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rake
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '10.0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '10.0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: redcarpet
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '3.2'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '3.2'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: yard
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0.8'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0.8'
|
167
|
+
description: UM ARCTS Sensu statuspage plugins
|
168
|
+
email: "<sensu-users@googlegroups.com>"
|
169
|
+
executables:
|
170
|
+
- umarcts-handler-statuspage.rb
|
171
|
+
- umarcts-metrics-statuspageio.rb
|
172
|
+
extensions: []
|
173
|
+
extra_rdoc_files: []
|
174
|
+
files:
|
175
|
+
- CHANGELOG.md
|
176
|
+
- LICENSE
|
177
|
+
- README.md
|
178
|
+
- bin/umarcts-handler-statuspage.rb
|
179
|
+
- bin/umarcts-metrics-statuspageio.rb
|
180
|
+
- lib/redphone/helpers.rb
|
181
|
+
- lib/redphone/statuspage.rb
|
182
|
+
- lib/umarcts-sensu-plugins-statuspage.rb
|
183
|
+
- lib/umarcts-sensu-plugins-statuspage/version.rb
|
184
|
+
homepage: https://github.com/drhey/umarcts-sensu-plugins-statuspage
|
185
|
+
licenses:
|
186
|
+
- MIT
|
187
|
+
metadata:
|
188
|
+
maintainer: sensu-plugin
|
189
|
+
development_status: active
|
190
|
+
production_status: unstable - testing recommended
|
191
|
+
release_draft: 'false'
|
192
|
+
release_prerelease: 'false'
|
193
|
+
post_install_message: You can use the embedded Ruby by setting EMBEDDED_RUBY=true
|
194
|
+
in /etc/default/sensu
|
195
|
+
rdoc_options: []
|
196
|
+
require_paths:
|
197
|
+
- lib
|
198
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
199
|
+
requirements:
|
200
|
+
- - ">="
|
201
|
+
- !ruby/object:Gem::Version
|
202
|
+
version: 2.0.0
|
203
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
204
|
+
requirements:
|
205
|
+
- - ">="
|
206
|
+
- !ruby/object:Gem::Version
|
207
|
+
version: '0'
|
208
|
+
requirements: []
|
209
|
+
rubyforge_project:
|
210
|
+
rubygems_version: 2.6.10
|
211
|
+
signing_key:
|
212
|
+
specification_version: 4
|
213
|
+
summary: UM ARCTS Sensu plugins for statuspage
|
214
|
+
test_files: []
|