copperegg-alerts 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8a07dd86b4cd13a3f6ee891bbc8639030a7687d5
4
+ data.tar.gz: f268648e78a0bc168fc3e0e63b21dbca235e525b
5
+ SHA512:
6
+ metadata.gz: 49fbe3637dbd50f8e0cebee612f10944fe11c461e8a1826cc8fde2d19dec4deb202354a26c3de914d368d294e4e5efec611ab2ebf4938031cda01ca80a5ef848
7
+ data.tar.gz: 1968d6a08b0f37e137845adbf5de27817f95283b7c901657e66dc1a9025368f92a6319be112f7938ddf139784e24dd5b5896532c70e9c6d0a4b5275bb3c3945f
@@ -0,0 +1,4 @@
1
+ .bundler
2
+ doc/
3
+ .idea
4
+ *.iml
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in copperegg-alerts.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Cargo Media
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Copperegg::Alerts
2
+
3
+ Minimalistic API client to manipulate [Copperegg's alert schedules](http://dev.copperegg.com/alerts/schedules.html) aka Maintenance Mode
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'copperegg-alerts'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install copperegg-alerts
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/[my-github-username]/copperegg-alerts/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create a new Pull Request
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
2
+
3
+ require 'bundler/gem_tasks'
4
+
5
+ Dir.glob(File.expand_path('../tasks/*.rake', __FILE__)).each do |task|
6
+ load task
7
+ end
8
+
9
+
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'copperegg/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "copperegg-alerts"
8
+ spec.version = Copperegg::VERSION
9
+ spec.authors = ['Cargo Media', 'ppp0']
10
+ spec.email = 'hello@cargomedia.ch'
11
+ spec.summary = 'A very minimalistic Copperegg API client for managing alert schedules'
12
+ spec.description = 'Set and remove alert silencing schedules aka maintenance windows'
13
+ spec.homepage = 'https://github.com/cargomedia/copperegg-alerts'
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency 'httparty'
22
+ spec.add_runtime_dependency 'deep_merge'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.6'
25
+ spec.add_development_dependency 'rake'
26
+ spec.add_development_dependency 'rspec'
27
+ spec.add_development_dependency 'webmock'
28
+ spec.add_development_dependency 'vcr'
29
+ spec.add_development_dependency 'hashdiff'
30
+ end
@@ -0,0 +1,5 @@
1
+ module Copperegg
2
+ require 'copperegg/client'
3
+ require 'copperegg/alerts'
4
+ require "copperegg/version"
5
+ end
@@ -0,0 +1,59 @@
1
+ require 'deep_merge'
2
+
3
+ module Copperegg
4
+ class Alerts
5
+ attr_reader :schedules
6
+
7
+ def initialize
8
+ @client = Copperegg::Client.instance
9
+ @schedules = @client.get('alerts/schedules.json')
10
+ end
11
+
12
+ def set_schedule(name, tags = {})
13
+ reset_schedules(name)
14
+ create_schedule(name, tags)
15
+ end
16
+
17
+ def modify_schedule(name, *args)
18
+ body = {}
19
+ args.each { |arg| body.deep_merge!(arg) }
20
+ selected_schedules = @schedules.select { |h| h['name'] == name }
21
+ if selected_schedules
22
+ @schedules -= selected_schedules
23
+ selected_schedules.each do |s|
24
+ result = @client.put?("alerts/schedules/#{s['id']}.json", body)
25
+ if result == nil
26
+ @schedules << s
27
+ else
28
+ @schedules << result
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+ def create_schedule(name, *args)
35
+ defaults = {
36
+ 'name' => name,
37
+ 'state' => 'enabled',
38
+ 'duration' => 10,
39
+ 'start_time' => Time.now.gmtime.strftime('%Y-%m-%dt%H:%M:%Sz'),
40
+ }
41
+ args.each { |arg| defaults.deep_merge!(arg) }
42
+ if result = @client.post?('alerts/schedules.json', defaults)
43
+ @schedules << result.parsed_response
44
+ end
45
+ end
46
+
47
+ def reset_schedules(name)
48
+ selected_schedules = @schedules.select { |h| h['name'] == name }
49
+ if selected_schedules
50
+ @schedules -= selected_schedules
51
+ selected_schedules.each do |s|
52
+ if @client.delete?("alerts/schedules/#{s['id']}.json") == nil
53
+ @schedules << s
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,48 @@
1
+ require 'singleton'
2
+ require 'httparty'
3
+ require 'deep_merge'
4
+
5
+ module Copperegg
6
+ class Client
7
+ include Singleton
8
+
9
+ attr_reader :api_base_uri
10
+
11
+ def initialize
12
+ @api_base_uri = 'https://api.copperegg.com/v2/'
13
+ end
14
+
15
+ def auth_setup(api_key)
16
+ @auth = {:basic_auth => {:username => api_key, :password => 'U'}}
17
+ return self
18
+ end
19
+
20
+ def get(resource, *args)
21
+ HTTParty.get(@api_base_uri + resource, @auth.to_hash)
22
+ end
23
+
24
+ JSON = {'content-type' => 'application/json'}
25
+
26
+ def method_missing(method, resource, *args)
27
+ if method.to_s =~ /\?$/
28
+ method = method.to_s.sub!(/\?$/, '')
29
+ result = self.send(method.to_sym, resource, *args)
30
+ return result if result.code == 200
31
+ end
32
+ end
33
+
34
+ ['post', 'put'].each do |method|
35
+ define_method(method) do |resource, *args|
36
+ body = {}
37
+ args.each { |arg| body.deep_merge!(arg) }
38
+ HTTParty.send(method.to_sym, @api_base_uri + resource, @auth.merge({:headers => JSON}.merge({:body => body.to_json})))
39
+ end
40
+ end
41
+
42
+ def delete(resource, *args)
43
+ HTTParty.delete(@api_base_uri + resource, @auth.to_hash)
44
+ end
45
+
46
+ end
47
+ end
48
+
@@ -0,0 +1,3 @@
1
+ module Copperegg
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,85 @@
1
+ require 'spec_helper'
2
+ require 'copperegg'
3
+ require 'webmock/rspec'
4
+ require 'pp'
5
+ require 'hashdiff'
6
+
7
+ describe Copperegg::Alerts do
8
+
9
+
10
+ before :each do
11
+
12
+ @client = Copperegg::Client.instance.auth_setup(Copperegg::Test::API_KEY)
13
+ VCR.use_cassette('schedules', :record => :once, :match_requests_on => [:method, :path]) do
14
+ @alerts = Copperegg::Alerts.new
15
+ end
16
+
17
+ end
18
+
19
+ describe '#new' do
20
+ it 'requests a list of all schedules' do
21
+ expect(@alerts.schedules.size > 0).to be(true)
22
+ expect(WebMock).to have_requested(:get, /\/alerts\/schedules\.json$/).once
23
+ end
24
+ end
25
+
26
+ describe 'create schedule' do
27
+ it 'creates three new schedules with name "spec_test"' do
28
+ alerts_schedules_list_size_before = @alerts.schedules.size
29
+ VCR.use_cassette('schedule_create', :record => :once, :match_requests_on => [:body_as_json], :allow_playback_repeats => true) do
30
+ 3.times { @alerts.create_schedule('spec_test', 'match' => {'tag' => ['foo']}, 'state' => 'disabled', 'duration' => 7, 'start_time' => '2014-09-14T10:21:40Z') }
31
+ end
32
+ expect(@alerts.schedules.size - alerts_schedules_list_size_before).to eq(3)
33
+ end
34
+ end
35
+
36
+ describe 'reset_schedules("spec_test")' do
37
+ before :each do
38
+ VCR.use_cassette('schedule_create', :record => :once, :match_requests_on => [:body_as_json], :allow_playback_repeats => true) do
39
+ 3.times { @alerts.create_schedule('spec_test', 'match' => {'tag' => ['foo']}, 'state' => 'disabled', 'duration' => 7, 'start_time' => '2014-09-14T10:21:40Z') }
40
+ end
41
+ expect(WebMock).to have_requested(:post, /\/alerts\/schedules\.json$/).times(3)
42
+ end
43
+
44
+ it 'removes all schedules with name "spec_test" from the list if any' do
45
+ alerts_schedules_list_size_before = @alerts.schedules.size
46
+ VCR.use_cassette('schedule_reset', :record => :once, :match_requests_on => [:method, :path]) do
47
+ @alerts.reset_schedules('spec_test')
48
+ end
49
+ expect(alerts_schedules_list_size_before - @alerts.schedules.size).to eq(3)
50
+ expect(WebMock).to have_requested(:delete, /.*alerts\/schedules\/\d+\.json$/).times(3)
51
+ end
52
+
53
+ it 'deletes schedules from the instance list variable only if api call was successful' do
54
+ alerts_schedules_list_size_before = @alerts.schedules.size
55
+ VCR.use_cassette('schedule_reset_with_error', :record => :once, :match_requests_on => [:method, :path]) do
56
+ @alerts.reset_schedules('spec_test')
57
+ end
58
+ expect(alerts_schedules_list_size_before - @alerts.schedules.size).to eq(2)
59
+ expect(WebMock).to have_requested(:delete, /.*alerts\/schedules\/\d+\.json$/).times(3)
60
+ end
61
+ end
62
+
63
+
64
+ describe 'modify schedule' do
65
+ before :each do
66
+ VCR.use_cassette('schedule_create', :record => :once, :match_requests_on => [:body_as_json], :allow_playback_repeats => true) do
67
+ @alerts.create_schedule('spec_test', 'match' => {'tag' => ['foo']}, 'state' => 'disabled', 'duration' => 7, 'start_time' => '2014-09-14T10:21:40Z')
68
+ end
69
+ expect(WebMock).to have_requested(:post, /\/alerts\/schedules\.json$/).once
70
+ end
71
+
72
+ it 'modifies a schedule with name "spec_test"' do
73
+ schedule_name='spec_test'
74
+ alert_schedule_before = @alerts.schedules.select { |schedule| schedule['name'] == schedule_name }
75
+ VCR.use_cassette('schedule_modify', :record => :once, :match_requests_on => [:body_as_json], :allow_playback_repeats => true) do
76
+ @alerts.modify_schedule(schedule_name, {'duration' => 33, 'state' => 'enabled'})
77
+ end
78
+ alert_schedule_after = @alerts.schedules.select { |schedule| schedule['name'] == schedule_name }
79
+ diff = HashDiff.diff(alert_schedule_before.first, alert_schedule_after.first)
80
+ expect(diff).to eq([['~', 'duration', 7, 33], ['~', 'state', 'disabled', 'enabled' ]])
81
+ expect(WebMock).to have_requested(:put, /.*alerts\/schedules\/\d+\.json$/).once
82
+ end
83
+ end
84
+
85
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+ require 'copperegg'
3
+
4
+ describe Copperegg::Client do
5
+
6
+ before :each do
7
+ @client = Copperegg::Client.instance.auth_setup(Copperegg::Test::API_KEY)
8
+ end
9
+
10
+ describe 'Client' do
11
+
12
+ it 'is an instance of Copperegg::Client' do
13
+ expect(@client) === Copperegg::Client
14
+ end
15
+
16
+ it 'has set the base_uri' do
17
+ expect(@api_base_uri) == 'https://api.copperegg.com/v2'
18
+ end
19
+
20
+ it 'has set the auth hash' do
21
+ expect(@auth) == {:basic_auth => {:username => Copperegg::Test::API_KEY, :password => 'U'}}
22
+ end
23
+
24
+ %w(get post put delete).each do |verb|
25
+ it "returns nil on wrong #{verb}" do
26
+ VCR.use_cassette('4xx', :record => :once, :match_requests_on => [:path], :allow_playback_repeats => true) do
27
+ expect(@client.send(verb + '?', 'veryWrong', {} )).to eq(nil)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,34 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://foo:U@api.copperegg.com/v2/veryWrong
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 400
13
+ message: Bad Request
14
+ headers:
15
+ Date:
16
+ - Mon, 15 Sep 2014 10:53:28 CDT
17
+ Server:
18
+ - nginx/1.2.8 + Phusion Passenger 4.0.2
19
+ Status:
20
+ - 400 Bad Request
21
+ X-Powered-By:
22
+ - Phusion Passenger 4.0.2
23
+ X-Runtime:
24
+ - '0.003397'
25
+ Transfer-Encoding:
26
+ - chunked
27
+ Connection:
28
+ - keep-alive
29
+ body:
30
+ encoding: UTF-8
31
+ string: '{"error":true,"error_type":"message","message":"invalid route: /v2/veryWrong"}'
32
+ http_version:
33
+ recorded_at: Mon, 15 Sep 2014 15:53:28 GMT
34
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,138 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://foo:U@api.copperegg.com/v2/alerts/schedules.json
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"name":"spec_test","state":"disabled","duration":7,"start_time":"2014-09-14T10:21:40Z","match":{"tag":["foo"]}}'
9
+ headers:
10
+ Content-Type:
11
+ - application/json
12
+ response:
13
+ status:
14
+ code: 200
15
+ message: OK
16
+ headers:
17
+ Access-Control-Allow-Origin:
18
+ - "*"
19
+ Cache-Control:
20
+ - max-age=0, private, must-revalidate
21
+ Content-Type:
22
+ - application/json; charset=utf-8
23
+ Date:
24
+ - Sun, 14 Sep 2014 05:21:45 CDT
25
+ Etag:
26
+ - '"cf6a6d6c2b8b2d2c3fd23de31e3f63f3"'
27
+ Server:
28
+ - nginx/1.2.8 + Phusion Passenger 4.0.2
29
+ Status:
30
+ - 200 OK
31
+ X-Ce-Now:
32
+ - '1410690105'
33
+ X-Powered-By:
34
+ - Phusion Passenger 4.0.2
35
+ X-Runtime:
36
+ - '0.148460'
37
+ X-Ua-Compatible:
38
+ - IE=Edge,chrome=1
39
+ Transfer-Encoding:
40
+ - chunked
41
+ Connection:
42
+ - keep-alive
43
+ body:
44
+ encoding: UTF-8
45
+ string: '{"id":1284,"name":"spec_test","start_time":"2014-09-14T10:21:40Z","end_time":"2014-09-14T10:28:40Z","duration":7,"state":"disabled","match":{"tag":["foo"]},"match_exclude":{},"recurring":false}'
46
+ http_version:
47
+ recorded_at: Sun, 14 Sep 2014 10:21:45 GMT
48
+ - request:
49
+ method: post
50
+ uri: https://foo:U@api.copperegg.com/v2/alerts/schedules.json
51
+ body:
52
+ encoding: UTF-8
53
+ string: '{"name":"spec_test","state":"disabled","duration":7,"start_time":"2014-09-14T10:21:40Z","match":{"tag":["foo"]}}'
54
+ headers:
55
+ Content-Type:
56
+ - application/json
57
+ response:
58
+ status:
59
+ code: 200
60
+ message: OK
61
+ headers:
62
+ Access-Control-Allow-Origin:
63
+ - "*"
64
+ Cache-Control:
65
+ - max-age=0, private, must-revalidate
66
+ Content-Type:
67
+ - application/json; charset=utf-8
68
+ Date:
69
+ - Sun, 14 Sep 2014 05:21:46 CDT
70
+ Etag:
71
+ - '"55c9edd9e0005127f6dd7037dda97f00"'
72
+ Server:
73
+ - nginx/1.2.8 + Phusion Passenger 4.0.2
74
+ Status:
75
+ - 200 OK
76
+ X-Ce-Now:
77
+ - '1410690106'
78
+ X-Powered-By:
79
+ - Phusion Passenger 4.0.2
80
+ X-Runtime:
81
+ - '0.060226'
82
+ X-Ua-Compatible:
83
+ - IE=Edge,chrome=1
84
+ Transfer-Encoding:
85
+ - chunked
86
+ Connection:
87
+ - keep-alive
88
+ body:
89
+ encoding: UTF-8
90
+ string: '{"id":1285,"name":"spec_test","start_time":"2014-09-14T10:21:45Z","end_time":"2014-09-14T10:28:45Z","duration":7,"state":"disabled","match":{"tag":["foo"]},"match_exclude":{},"recurring":false}'
91
+ http_version:
92
+ recorded_at: Sun, 14 Sep 2014 10:21:46 GMT
93
+ - request:
94
+ method: post
95
+ uri: https://foo:U@api.copperegg.com/v2/alerts/schedules.json
96
+ body:
97
+ encoding: UTF-8
98
+ string: '{"name":"spec_test","state":"disabled","duration":7,"start_time":"2014-09-14T10:21:40Z","match":{"tag":["foo"]}}'
99
+ headers:
100
+ Content-Type:
101
+ - application/json
102
+ response:
103
+ status:
104
+ code: 200
105
+ message: OK
106
+ headers:
107
+ Access-Control-Allow-Origin:
108
+ - "*"
109
+ Cache-Control:
110
+ - max-age=0, private, must-revalidate
111
+ Content-Type:
112
+ - application/json; charset=utf-8
113
+ Date:
114
+ - Sun, 14 Sep 2014 05:21:46 CDT
115
+ Etag:
116
+ - '"68f3d83eb36e2c9173e077a57bc774cd"'
117
+ Server:
118
+ - nginx/1.2.8 + Phusion Passenger 4.0.2
119
+ Status:
120
+ - 200 OK
121
+ X-Ce-Now:
122
+ - '1410690106'
123
+ X-Powered-By:
124
+ - Phusion Passenger 4.0.2
125
+ X-Runtime:
126
+ - '0.029386'
127
+ X-Ua-Compatible:
128
+ - IE=Edge,chrome=1
129
+ Content-Length:
130
+ - '193'
131
+ Connection:
132
+ - keep-alive
133
+ body:
134
+ encoding: UTF-8
135
+ string: '{"id":1286,"name":"spec_test","start_time":"2014-09-14T10:21:46Z","end_time":"2014-09-14T10:28:46Z","duration":7,"state":"disabled","match":{"tag":["foo"]},"match_exclude":{},"recurring":false}'
136
+ http_version:
137
+ recorded_at: Sun, 14 Sep 2014 10:21:46 GMT
138
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,48 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: put
5
+ uri: https://foo:U@api.copperegg.com/v2/alerts/1284.json
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"duration":33,"state":"enabled"}'
9
+ headers:
10
+ Content-Type:
11
+ - application/json
12
+ response:
13
+ status:
14
+ code: 200
15
+ message: OK
16
+ headers:
17
+ Access-Control-Allow-Origin:
18
+ - "*"
19
+ Cache-Control:
20
+ - max-age=0, private, must-revalidate
21
+ Content-Type:
22
+ - application/json; charset=utf-8
23
+ Date:
24
+ - Sun, 14 Sep 2014 05:21:45 CDT
25
+ Etag:
26
+ - '"cf6a6d6c2b8b2d2c3fd23de31e3f63f3"'
27
+ Server:
28
+ - nginx/1.2.8 + Phusion Passenger 4.0.2
29
+ Status:
30
+ - 200 OK
31
+ X-Ce-Now:
32
+ - '1410690105'
33
+ X-Powered-By:
34
+ - Phusion Passenger 4.0.2
35
+ X-Runtime:
36
+ - '0.148460'
37
+ X-Ua-Compatible:
38
+ - IE=Edge,chrome=1
39
+ Transfer-Encoding:
40
+ - chunked
41
+ Connection:
42
+ - keep-alive
43
+ body:
44
+ encoding: UTF-8
45
+ string: '{"id":1284,"name":"spec_test","start_time":"2014-09-14T10:21:40Z","end_time":"2014-09-14T10:28:40Z","duration":33,"state":"enabled","match":{"tag":["foo"]},"match_exclude":{},"recurring":false}'
46
+ http_version:
47
+ recorded_at: Sun, 14 Sep 2014 10:21:45 GMT
48
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,132 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: delete
5
+ uri: https://foo:U@api.copperegg.com/v2/alerts/schedules/1284.json
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 200
13
+ message: OK
14
+ headers:
15
+ Access-Control-Allow-Origin:
16
+ - "*"
17
+ Cache-Control:
18
+ - max-age=0, private, must-revalidate
19
+ Content-Type:
20
+ - application/json; charset=utf-8
21
+ Date:
22
+ - Sun, 14 Sep 2014 05:26:02 CDT
23
+ Etag:
24
+ - '"99914b932bd37a50b983c5e7c90ae93b"'
25
+ Server:
26
+ - nginx/1.2.8 + Phusion Passenger 4.0.2
27
+ Status:
28
+ - 200 OK
29
+ X-Ce-Now:
30
+ - '1410690362'
31
+ X-Powered-By:
32
+ - Phusion Passenger 4.0.2
33
+ X-Runtime:
34
+ - '0.116250'
35
+ X-Ua-Compatible:
36
+ - IE=Edge,chrome=1
37
+ Transfer-Encoding:
38
+ - chunked
39
+ Connection:
40
+ - keep-alive
41
+ body:
42
+ encoding: UTF-8
43
+ string: "{}"
44
+ http_version:
45
+ recorded_at: Sun, 14 Sep 2014 10:26:02 GMT
46
+ - request:
47
+ method: delete
48
+ uri: https://foo:U@api.copperegg.com/v2/alerts/schedules/1285.json
49
+ body:
50
+ encoding: US-ASCII
51
+ string: ''
52
+ headers: {}
53
+ response:
54
+ status:
55
+ code: 200
56
+ message: OK
57
+ headers:
58
+ Access-Control-Allow-Origin:
59
+ - "*"
60
+ Cache-Control:
61
+ - max-age=0, private, must-revalidate
62
+ Content-Type:
63
+ - application/json; charset=utf-8
64
+ Date:
65
+ - Sun, 14 Sep 2014 05:26:03 CDT
66
+ Etag:
67
+ - '"99914b932bd37a50b983c5e7c90ae93b"'
68
+ Server:
69
+ - nginx/1.2.8 + Phusion Passenger 4.0.2
70
+ Status:
71
+ - 200 OK
72
+ X-Ce-Now:
73
+ - '1410690363'
74
+ X-Powered-By:
75
+ - Phusion Passenger 4.0.2
76
+ X-Runtime:
77
+ - '0.035337'
78
+ X-Ua-Compatible:
79
+ - IE=Edge,chrome=1
80
+ Content-Length:
81
+ - '2'
82
+ Connection:
83
+ - keep-alive
84
+ body:
85
+ encoding: UTF-8
86
+ string: "{}"
87
+ http_version:
88
+ recorded_at: Sun, 14 Sep 2014 10:26:03 GMT
89
+ - request:
90
+ method: delete
91
+ uri: https://foo:U@api.copperegg.com/v2/alerts/schedules/1286.json
92
+ body:
93
+ encoding: US-ASCII
94
+ string: ''
95
+ headers: {}
96
+ response:
97
+ status:
98
+ code: 200
99
+ message: OK
100
+ headers:
101
+ Access-Control-Allow-Origin:
102
+ - "*"
103
+ Cache-Control:
104
+ - max-age=0, private, must-revalidate
105
+ Content-Type:
106
+ - application/json; charset=utf-8
107
+ Date:
108
+ - Sun, 14 Sep 2014 05:26:03 CDT
109
+ Etag:
110
+ - '"99914b932bd37a50b983c5e7c90ae93b"'
111
+ Server:
112
+ - nginx/1.2.8 + Phusion Passenger 4.0.2
113
+ Status:
114
+ - 200 OK
115
+ X-Ce-Now:
116
+ - '1410690363'
117
+ X-Powered-By:
118
+ - Phusion Passenger 4.0.2
119
+ X-Runtime:
120
+ - '0.024569'
121
+ X-Ua-Compatible:
122
+ - IE=Edge,chrome=1
123
+ Content-Length:
124
+ - '2'
125
+ Connection:
126
+ - keep-alive
127
+ body:
128
+ encoding: UTF-8
129
+ string: "{}"
130
+ http_version:
131
+ recorded_at: Sun, 14 Sep 2014 10:26:03 GMT
132
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,122 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: delete
5
+ uri: https://foo:U@api.copperegg.com/v2/alerts/schedules/1284.json
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 200
13
+ message: OK
14
+ headers:
15
+ Access-Control-Allow-Origin:
16
+ - "*"
17
+ Cache-Control:
18
+ - max-age=0, private, must-revalidate
19
+ Content-Type:
20
+ - application/json; charset=utf-8
21
+ Date:
22
+ - Sun, 14 Sep 2014 05:26:02 CDT
23
+ Etag:
24
+ - '"99914b932bd37a50b983c5e7c90ae93b"'
25
+ Server:
26
+ - nginx/1.2.8 + Phusion Passenger 4.0.2
27
+ Status:
28
+ - 200 OK
29
+ X-Ce-Now:
30
+ - '1410690362'
31
+ X-Powered-By:
32
+ - Phusion Passenger 4.0.2
33
+ X-Runtime:
34
+ - '0.116250'
35
+ X-Ua-Compatible:
36
+ - IE=Edge,chrome=1
37
+ Transfer-Encoding:
38
+ - chunked
39
+ Connection:
40
+ - keep-alive
41
+ body:
42
+ encoding: UTF-8
43
+ string: "{}"
44
+ http_version:
45
+ recorded_at: Sun, 14 Sep 2014 10:26:02 GMT
46
+ - request:
47
+ method: delete
48
+ uri: https://foo:U@api.copperegg.com/v2/alerts/schedules/1285.json
49
+ body:
50
+ encoding: US-ASCII
51
+ string: ''
52
+ headers: {}
53
+ response:
54
+ status:
55
+ code: 200
56
+ message: OK
57
+ headers:
58
+ Access-Control-Allow-Origin:
59
+ - "*"
60
+ Cache-Control:
61
+ - max-age=0, private, must-revalidate
62
+ Content-Type:
63
+ - application/json; charset=utf-8
64
+ Date:
65
+ - Sun, 14 Sep 2014 05:26:03 CDT
66
+ Etag:
67
+ - '"99914b932bd37a50b983c5e7c90ae93b"'
68
+ Server:
69
+ - nginx/1.2.8 + Phusion Passenger 4.0.2
70
+ Status:
71
+ - 200 OK
72
+ X-Ce-Now:
73
+ - '1410690363'
74
+ X-Powered-By:
75
+ - Phusion Passenger 4.0.2
76
+ X-Runtime:
77
+ - '0.035337'
78
+ X-Ua-Compatible:
79
+ - IE=Edge,chrome=1
80
+ Content-Length:
81
+ - '2'
82
+ Connection:
83
+ - keep-alive
84
+ body:
85
+ encoding: UTF-8
86
+ string: "{}"
87
+ http_version:
88
+ recorded_at: Sun, 14 Sep 2014 10:26:03 GMT
89
+ - request:
90
+ method: delete
91
+ uri: https://foo:U@api.copperegg.com/v2/alerts/schedules/1286.json
92
+ body:
93
+ encoding: US-ASCII
94
+ string: ''
95
+ headers: {}
96
+ response:
97
+ status:
98
+ code: 500
99
+ message: Internal Server Error
100
+ headers:
101
+ Date:
102
+ - Tue, 16 Sep 2014 07:32:17 CDT
103
+ Server:
104
+ - nginx/1.2.8 + Phusion Passenger 4.0.2
105
+ Status:
106
+ - 500 Internal Server Error
107
+ X-Powered-By:
108
+ - Phusion Passenger 4.0.2
109
+ X-Runtime:
110
+ - '0.017949'
111
+ Transfer-Encoding:
112
+ - chunked
113
+ Connection:
114
+ - keep-alive
115
+ body:
116
+ encoding: UTF-8
117
+ string: '{"error":true,"error_type":"message","message":"internal error: Couldn''t
118
+ find MaintenanceSchedule with ID=1286 [WHERE (`maintenance_schedules`.site_id
119
+ = 15310)]. Please report this to support@copperegg.com"}'
120
+ http_version:
121
+ recorded_at: Tue, 16 Sep 2014 12:32:17 GMT
122
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,52 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://foo:U@api.copperegg.com/v2/alerts/schedules.json
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 200
13
+ message: OK
14
+ headers:
15
+ Access-Control-Allow-Origin:
16
+ - "*"
17
+ Cache-Control:
18
+ - max-age=0, private, must-revalidate
19
+ Content-Type:
20
+ - application/json; charset=utf-8
21
+ Date:
22
+ - Sun, 14 Sep 2014 05:24:44 CDT
23
+ Etag:
24
+ - '"d93c69f8ab9a5078a9f9c593386a2db9"'
25
+ Server:
26
+ - nginx/1.2.8 + Phusion Passenger 4.0.2
27
+ Status:
28
+ - 200 OK
29
+ X-Ce-Now:
30
+ - '1410690284'
31
+ X-Powered-By:
32
+ - Phusion Passenger 4.0.2
33
+ X-Runtime:
34
+ - '0.027304'
35
+ X-Ua-Compatible:
36
+ - IE=Edge,chrome=1
37
+ Transfer-Encoding:
38
+ - chunked
39
+ Connection:
40
+ - keep-alive
41
+ body:
42
+ encoding: UTF-8
43
+ string: '[{"id":445,"name":"swapping stream servers","start_time":"2014-02-25T19:50:54Z","end_time":"2014-02-25T20:00:54Z","duration":10,"state":"disabled","match":{"tag":["softlayer"]},"match_exclude":{},"recurring":false},{"id":448,"name":"backup1
44
+ upgrade","start_time":"2014-02-26T18:54:56Z","end_time":"2014-02-26T19:04:56Z","duration":10,"state":"disabled","match":{"tag":["hetzner"]},"match_exclude":{},"recurring":false},{"id":453,"name":"expected
45
+ downtime","start_time":"2014-07-30T10:33:33Z","end_time":"2014-07-30T11:03:33Z","duration":30,"state":"disabled","match":{},"match_exclude":{},"recurring":false},{"id":768,"name":"mysql
46
+ load (data copy etc)","start_time":"2014-07-10T10:06:51Z","end_time":"2014-07-10T11:06:51Z","duration":60,"state":"disabled","match":{"tag":["softlayer--vlan1850--db4","softlayer--vlan1850--db5"]},"match_exclude":{},"recurring":false},{"id":805,"name":"db5
47
+ disk replacement","start_time":"2014-07-04T15:34:02Z","end_time":"2014-07-04T20:34:02Z","duration":300,"state":"disabled","match":{"tag":["softlayer--vlan1850--db5"]},"match_exclude":{},"recurring":false},{"id":1021,"name":"cluster
48
+ investigation","start_time":"2014-07-30T17:32:23Z","end_time":"2014-07-30T18:32:23Z","duration":60,"state":"disabled","match":{"tag":["softlayer--mongodb"]},"match_exclude":{},"recurring":false},{"id":1233,"name":"sk
49
+ release","start_time":"2014-09-08T09:52:11Z","end_time":"2014-09-08T10:07:11Z","duration":15,"state":"disabled","match":{"tag":["softlayer"]},"match_exclude":{},"recurring":false}]'
50
+ http_version:
51
+ recorded_at: Sun, 14 Sep 2014 10:24:44 GMT
52
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,16 @@
1
+ require 'copperegg'
2
+ require 'webmock'
3
+ require 'vcr'
4
+
5
+ module Copperegg
6
+ module Test
7
+ API_KEY = 'foo'
8
+ end
9
+ end
10
+
11
+ VCR.configure do |c|
12
+ c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
13
+ c.hook_into :webmock
14
+ end
15
+
16
+ WebMock.enable!
@@ -0,0 +1,8 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ task :default => :spec
4
+
5
+ desc 'Run all specs'
6
+ RSpec::Core::RakeTask.new(:spec) do |t|
7
+ t.pattern = 'spec/*_spec.rb'
8
+ end
metadata ADDED
@@ -0,0 +1,185 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: copperegg-alerts
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Cargo Media
8
+ - ppp0
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-09-16 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: deep_merge
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: bundler
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '1.6'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '1.6'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rake
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rspec
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: webmock
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: vcr
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: hashdiff
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ description: Set and remove alert silencing schedules aka maintenance windows
127
+ email: hello@cargomedia.ch
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - Gemfile
134
+ - LICENSE
135
+ - README.md
136
+ - Rakefile
137
+ - copperegg-alerts.gemspec
138
+ - lib/copperegg.rb
139
+ - lib/copperegg/alerts.rb
140
+ - lib/copperegg/client.rb
141
+ - lib/copperegg/version.rb
142
+ - spec/alert_spec.rb
143
+ - spec/client_spec.rb
144
+ - spec/fixtures/vcr_cassettes/4xx.yml
145
+ - spec/fixtures/vcr_cassettes/schedule_create.yml
146
+ - spec/fixtures/vcr_cassettes/schedule_modify.yml
147
+ - spec/fixtures/vcr_cassettes/schedule_reset.yml
148
+ - spec/fixtures/vcr_cassettes/schedule_reset_with_error.yml
149
+ - spec/fixtures/vcr_cassettes/schedules.yml
150
+ - spec/spec_helper.rb
151
+ - tasks/rspec.rake
152
+ homepage: https://github.com/cargomedia/copperegg-alerts
153
+ licenses:
154
+ - MIT
155
+ metadata: {}
156
+ post_install_message:
157
+ rdoc_options: []
158
+ require_paths:
159
+ - lib
160
+ required_ruby_version: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ required_rubygems_version: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - ">="
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
170
+ requirements: []
171
+ rubyforge_project:
172
+ rubygems_version: 2.4.1
173
+ signing_key:
174
+ specification_version: 4
175
+ summary: A very minimalistic Copperegg API client for managing alert schedules
176
+ test_files:
177
+ - spec/alert_spec.rb
178
+ - spec/client_spec.rb
179
+ - spec/fixtures/vcr_cassettes/4xx.yml
180
+ - spec/fixtures/vcr_cassettes/schedule_create.yml
181
+ - spec/fixtures/vcr_cassettes/schedule_modify.yml
182
+ - spec/fixtures/vcr_cassettes/schedule_reset.yml
183
+ - spec/fixtures/vcr_cassettes/schedule_reset_with_error.yml
184
+ - spec/fixtures/vcr_cassettes/schedules.yml
185
+ - spec/spec_helper.rb