flapjack-diner 0.15 → 1.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +423 -736
- data/lib/flapjack-diner.rb +325 -258
- data/lib/flapjack-diner/argument_validator.rb +19 -1
- data/lib/flapjack-diner/version.rb +1 -1
- data/spec/flapjack-diner_spec.rb +1084 -681
- metadata +25 -41
@@ -35,6 +35,24 @@ module Flapjack
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
+
def boolean(*elements)
|
39
|
+
elements.each do |element|
|
40
|
+
if target = @query[element]
|
41
|
+
next if [TrueClass, FalseClass].include?(target.class)
|
42
|
+
@errors << "'#{target}' should be 'true' or 'false'."
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def array_of_strings(*elements)
|
48
|
+
elements.each do |element|
|
49
|
+
if target = @query[element]
|
50
|
+
next if target.is_a?(Array) && target.all? {|t| t.is_a?(String)}
|
51
|
+
@errors << "'#{target}' should be an Array of Strings."
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
38
56
|
def required(*elements)
|
39
57
|
elements.each do |element|
|
40
58
|
@errors << "'#{element}' is required." if @query[element].nil?
|
@@ -49,7 +67,7 @@ module Flapjack
|
|
49
67
|
return super unless klass = classify_name(name)
|
50
68
|
elements = args
|
51
69
|
elements.each do |element|
|
52
|
-
@errors << "'#{element}' is expected to be a #{klass}" unless @query[element].is_a?(klass)
|
70
|
+
@errors << "'#{element}' is expected to be a #{klass}" unless @query[element].nil? || @query[element].is_a?(klass)
|
53
71
|
end
|
54
72
|
end
|
55
73
|
|
data/spec/flapjack-diner_spec.rb
CHANGED
@@ -4,23 +4,12 @@ require 'flapjack-diner'
|
|
4
4
|
describe Flapjack::Diner do
|
5
5
|
|
6
6
|
let(:server) { 'flapjack.com' }
|
7
|
-
|
8
|
-
let(:
|
9
|
-
|
10
|
-
|
11
|
-
{"
|
12
|
-
|
13
|
-
"entities" => ["foo-app-01.example.com"],
|
14
|
-
"time_restrictions" => nil,
|
15
|
-
"warning_media" => ["email"],
|
16
|
-
"critical_media" => ["sms", "email"],
|
17
|
-
"warning_blackhole" => false,
|
18
|
-
"critical_blackhole" => false
|
19
|
-
}
|
20
|
-
}
|
21
|
-
|
22
|
-
let(:response) { '{"key":"value"}' }
|
23
|
-
let(:response_body) { {'key' => 'value'} }
|
7
|
+
|
8
|
+
let(:time) { Time.now }
|
9
|
+
|
10
|
+
def response_with_data(name, data = [])
|
11
|
+
"{\"#{name}\":#{data.to_json}}"
|
12
|
+
end
|
24
13
|
|
25
14
|
before(:each) do
|
26
15
|
Flapjack::Diner.base_uri(server)
|
@@ -31,704 +20,1177 @@ describe Flapjack::Diner do
|
|
31
20
|
WebMock.reset!
|
32
21
|
end
|
33
22
|
|
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
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
end
|
76
|
-
|
77
|
-
it "returns a json list of check statuses for an entity, legacy" do
|
78
|
-
req = stub_request(:get, "http://#{server}/status/#{entity}").
|
79
|
-
to_return(:body => response)
|
80
|
-
|
81
|
-
result = Flapjack::Diner.status(entity)
|
82
|
-
req.should have_been_requested
|
83
|
-
result.should_not be_nil
|
84
|
-
result.should == response_body
|
85
|
-
end
|
86
|
-
|
87
|
-
it "returns a list of entity statuses for a bulk query" do
|
88
|
-
req = stub_request(:get, "http://#{server}/status").
|
89
|
-
with(:query => {:entity => ['abc.net', 'def.com'], :check => {'ghi.net' => 'ping', 'jkl.org' => ['ping', 'ssh']}}).
|
90
|
-
to_return(:body => response)
|
91
|
-
|
92
|
-
result = Flapjack::Diner.bulk_status(:entity => ['abc.net', 'def.com'], :check => {'ghi.net' => 'ping', 'jkl.org' => ['ping', 'ssh']})
|
93
|
-
req.should have_been_requested
|
94
|
-
result.should_not be_nil
|
95
|
-
result.should == response_body
|
96
|
-
end
|
97
|
-
|
98
|
-
it "returns a single check status for an entity" do
|
99
|
-
req = stub_request(:get, "http://#{server}/status").
|
100
|
-
with(:query => {:check => {entity => check}}).
|
101
|
-
to_return(:body => response)
|
102
|
-
|
103
|
-
result = Flapjack::Diner.bulk_status(:check => {entity => check})
|
104
|
-
req.should have_been_requested
|
105
|
-
result.should_not be_nil
|
106
|
-
result.should == response_body
|
107
|
-
end
|
108
|
-
|
109
|
-
it "returns a single check status for an entity, legacy" do
|
110
|
-
req = stub_request(:get, "http://#{server}/status/#{entity}/#{check}").
|
111
|
-
to_return(:body => response)
|
112
|
-
|
113
|
-
result = Flapjack::Diner.status(entity, :check => check)
|
114
|
-
req.should have_been_requested
|
115
|
-
result.should_not be_nil
|
116
|
-
result.should == response_body
|
117
|
-
end
|
118
|
-
|
119
|
-
it "returns a list of scheduled maintenance periods for all checks on an entity" do
|
120
|
-
req = stub_request(:get, "http://#{server}/scheduled_maintenances/#{entity}").
|
121
|
-
to_return(:body => response)
|
122
|
-
|
123
|
-
result = Flapjack::Diner.scheduled_maintenances(entity)
|
124
|
-
req.should have_been_requested
|
125
|
-
result.should_not be_nil
|
126
|
-
result.should == response_body
|
127
|
-
end
|
128
|
-
|
129
|
-
it "returns a list of scheduled maintenance periods for a check on an entity" do
|
130
|
-
req = stub_request(:get, "http://#{server}/scheduled_maintenances/#{entity}/#{check}").
|
131
|
-
to_return(:body => response)
|
132
|
-
|
133
|
-
result = Flapjack::Diner.scheduled_maintenances(entity, :check => check)
|
134
|
-
req.should have_been_requested
|
135
|
-
result.should_not be_nil
|
136
|
-
result.should == response_body
|
137
|
-
end
|
138
|
-
|
139
|
-
it "returns a list of scheduled maintenance periods for a bulk query" do
|
140
|
-
req = stub_request(:get, "http://#{server}/scheduled_maintenances").
|
141
|
-
with(:query => {:entity => 'abc.net', :check => {'def.org' => 'ping'}}).
|
142
|
-
to_return(:body => response)
|
143
|
-
|
144
|
-
result = Flapjack::Diner.bulk_scheduled_maintenances(:entity => 'abc.net', :check => {'def.org' => 'ping'})
|
145
|
-
req.should have_been_requested
|
146
|
-
result.should_not be_nil
|
147
|
-
result.should == response_body
|
148
|
-
end
|
149
|
-
|
150
|
-
it "returns a list of unscheduled maintenance periods for all checks on an entity" do
|
151
|
-
req = stub_request(:get, "http://#{server}/unscheduled_maintenances/#{entity}").
|
152
|
-
to_return(:body => response)
|
153
|
-
|
154
|
-
result = Flapjack::Diner.unscheduled_maintenances(entity)
|
155
|
-
req.should have_been_requested
|
156
|
-
result.should_not be_nil
|
157
|
-
result.should == response_body
|
158
|
-
end
|
159
|
-
|
160
|
-
it "returns a list of unscheduled maintenance periods for a check on an entity" do
|
161
|
-
req = stub_request(:get, "http://#{server}/unscheduled_maintenances/#{entity}/#{check}").
|
162
|
-
to_return(:body => response)
|
163
|
-
|
164
|
-
result = Flapjack::Diner.unscheduled_maintenances(entity, :check => check)
|
165
|
-
req.should have_been_requested
|
166
|
-
result.should_not be_nil
|
167
|
-
result.should == response_body
|
168
|
-
end
|
169
|
-
|
170
|
-
it "returns a list of unscheduled maintenance periods for a bulk query" do
|
171
|
-
req = stub_request(:get, "http://#{server}/unscheduled_maintenances").
|
172
|
-
with(:query => {:entity => 'abc.net', :check => {'def.org' => 'ping'}}).
|
173
|
-
to_return(:body => response)
|
174
|
-
|
175
|
-
result = Flapjack::Diner.bulk_unscheduled_maintenances(:entity => 'abc.net', :check => {'def.org' => 'ping'})
|
176
|
-
req.should have_been_requested
|
177
|
-
result.should_not be_nil
|
178
|
-
result.should == response_body
|
179
|
-
end
|
180
|
-
|
181
|
-
it "returns a list of outages for all checks on an entity" do
|
182
|
-
req = stub_request(:get, "http://#{server}/outages/#{entity}").
|
183
|
-
to_return(:body => response)
|
23
|
+
context 'contacts' do
|
24
|
+
context 'create' do
|
25
|
+
|
26
|
+
it "submits a POST request for a contact" do
|
27
|
+
data = [{:first_name => 'Jim',
|
28
|
+
:last_name => 'Smith',
|
29
|
+
:email => 'jims@example.com',
|
30
|
+
:timezone => 'UTC',
|
31
|
+
:tags => ['admin', 'night_shift']}]
|
32
|
+
|
33
|
+
req = stub_request(:post, "http://#{server}/contacts").
|
34
|
+
with(:body => {:contacts => data}.to_json,
|
35
|
+
:headers => {'Content-Type'=>'application/vnd.api+json'}).
|
36
|
+
to_return(:status => 201, :body => response_with_data('contacts', data))
|
37
|
+
|
38
|
+
result = Flapjack::Diner.create_contacts(data)
|
39
|
+
req.should have_been_requested
|
40
|
+
result.should_not be_nil
|
41
|
+
result.should be_true
|
42
|
+
end
|
43
|
+
|
44
|
+
it "submits a POST request for several contacts" do
|
45
|
+
data = [{:first_name => 'Jim',
|
46
|
+
:last_name => 'Smith',
|
47
|
+
:email => 'jims@example.com',
|
48
|
+
:timezone => 'UTC',
|
49
|
+
:tags => ['admin', 'night_shift']},
|
50
|
+
{:first_name => 'Joan',
|
51
|
+
:last_name => 'Smith',
|
52
|
+
:email => 'joans@example.com'}]
|
53
|
+
|
54
|
+
req = stub_request(:post, "http://#{server}/contacts").
|
55
|
+
with(:body => {:contacts => data}.to_json,
|
56
|
+
:headers => {'Content-Type'=>'application/vnd.api+json'}).
|
57
|
+
to_return(:status => 201, :body => response_with_data('contacts', data))
|
58
|
+
|
59
|
+
result = Flapjack::Diner.create_contacts(data)
|
60
|
+
req.should have_been_requested
|
61
|
+
result.should_not be_nil
|
62
|
+
result.should be_true
|
63
|
+
end
|
184
64
|
|
185
|
-
|
186
|
-
req.should have_been_requested
|
187
|
-
result.should_not be_nil
|
188
|
-
result.should == response_body
|
189
|
-
end
|
65
|
+
end
|
190
66
|
|
191
|
-
|
192
|
-
|
193
|
-
|
67
|
+
context 'read' do
|
68
|
+
it "submits a GET request for all contacts" do
|
69
|
+
req = stub_request(:get, "http://#{server}/contacts").to_return(
|
70
|
+
:status => 200, :body => response_with_data('contacts'))
|
71
|
+
|
72
|
+
result = Flapjack::Diner.contacts
|
73
|
+
req.should have_been_requested
|
74
|
+
result.should_not be_nil
|
75
|
+
end
|
76
|
+
|
77
|
+
it "submits a GET request for one contact" do
|
78
|
+
req = stub_request(:get, "http://#{server}/contacts/72").to_return(
|
79
|
+
:body => response_with_data('contacts'))
|
80
|
+
|
81
|
+
result = Flapjack::Diner.contacts('72')
|
82
|
+
req.should have_been_requested
|
83
|
+
result.should_not be_nil
|
84
|
+
end
|
85
|
+
|
86
|
+
it "submits a GET request for several contacts" do
|
87
|
+
req = stub_request(:get, "http://#{server}/contacts/72,150").to_return(
|
88
|
+
:body => response_with_data('contacts'))
|
89
|
+
|
90
|
+
result = Flapjack::Diner.contacts('72', '150')
|
91
|
+
req.should have_been_requested
|
92
|
+
result.should_not be_nil
|
93
|
+
end
|
94
|
+
end
|
194
95
|
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
96
|
+
context 'update' do
|
97
|
+
|
98
|
+
it "submits a PATCH request for one contact" do
|
99
|
+
req = stub_request(:patch, "http://#{server}/contacts/23").
|
100
|
+
with(:body => [{:op => 'replace', :path => '/contacts/0/timezone', :value => 'UTC'}].to_json,
|
101
|
+
:headers => {'Content-Type'=>'application/json-patch+json'}).
|
102
|
+
to_return(:status => 204)
|
103
|
+
|
104
|
+
result = Flapjack::Diner.update_contacts(23, :timezone => 'UTC')
|
105
|
+
req.should have_been_requested
|
106
|
+
result.should_not be_nil
|
107
|
+
result.should be_true
|
108
|
+
end
|
109
|
+
|
110
|
+
it "submits a PATCH request for several contacts" do
|
111
|
+
req = stub_request(:patch, "http://#{server}/contacts/23,87").
|
112
|
+
with(:body => [{:op => 'replace', :path => '/contacts/0/timezone', :value => 'UTC'}].to_json,
|
113
|
+
:headers => {'Content-Type'=>'application/json-patch+json'}).
|
114
|
+
to_return(:status => 204)
|
115
|
+
|
116
|
+
result = Flapjack::Diner.update_contacts(23, 87, :timezone => 'UTC')
|
117
|
+
req.should have_been_requested
|
118
|
+
result.should_not be_nil
|
119
|
+
result.should be_true
|
120
|
+
end
|
121
|
+
|
122
|
+
it "submits a PATCH request to change a link for one contact" do
|
123
|
+
req = stub_request(:patch, "http://#{server}/contacts/23").
|
124
|
+
with(:body => [{:op => 'add', :path => '/contacts/0/links/entities/-', :value => '57'}].to_json,
|
125
|
+
:headers => {'Content-Type'=>'application/json-patch+json'}).
|
126
|
+
to_return(:status => 204)
|
127
|
+
|
128
|
+
result = Flapjack::Diner.update_contacts(23, :add_entity => '57')
|
129
|
+
req.should have_been_requested
|
130
|
+
result.should_not be_nil
|
131
|
+
result.should be_true
|
132
|
+
end
|
133
|
+
|
134
|
+
it "submits a PATCH request to change links for several contacts" do
|
135
|
+
req = stub_request(:patch, "http://#{server}/contacts/23,87").
|
136
|
+
with(:body => [{:op => 'add', :path => '/contacts/0/links/entities/-', :value => '57'}].to_json,
|
137
|
+
:headers => {'Content-Type'=>'application/json-patch+json'}).
|
138
|
+
to_return(:status => 204)
|
139
|
+
|
140
|
+
result = Flapjack::Diner.update_contacts(23, 87, :add_entity => '57')
|
141
|
+
req.should have_been_requested
|
142
|
+
result.should_not be_nil
|
143
|
+
result.should be_true
|
144
|
+
end
|
200
145
|
|
201
|
-
|
202
|
-
req = stub_request(:get, "http://#{server}/outages").
|
203
|
-
with(:query => {:entity => 'abc.net', :check => {'def.org' => 'ping'}}).
|
204
|
-
to_return(:body => response)
|
146
|
+
end
|
205
147
|
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
148
|
+
context 'delete' do
|
149
|
+
it "submits a DELETE request for one contact" do
|
150
|
+
req = stub_request(:delete, "http://#{server}/contacts/72").
|
151
|
+
to_return(:status => 204)
|
152
|
+
|
153
|
+
result = Flapjack::Diner.delete_contacts('72')
|
154
|
+
req.should have_been_requested
|
155
|
+
result.should_not be_nil
|
156
|
+
result.should be_true
|
157
|
+
end
|
158
|
+
|
159
|
+
it "submits a DELETE request for several contacts" do
|
160
|
+
req = stub_request(:delete, "http://#{server}/contacts/72,150").
|
161
|
+
to_return(:status => 204)
|
162
|
+
|
163
|
+
result = Flapjack::Diner.delete_contacts('72', '150')
|
164
|
+
req.should have_been_requested
|
165
|
+
result.should_not be_nil
|
166
|
+
result.should be_true
|
167
|
+
end
|
168
|
+
end
|
210
169
|
end
|
211
170
|
|
212
|
-
|
213
|
-
|
214
|
-
|
171
|
+
context 'media' do
|
172
|
+
context 'create' do
|
173
|
+
|
174
|
+
it "submits a POST request for a medium" do
|
175
|
+
data = [{
|
176
|
+
:type => 'sms',
|
177
|
+
:address => '0123456789',
|
178
|
+
:interval => 300,
|
179
|
+
:rollup_threshold => 5
|
180
|
+
}]
|
181
|
+
|
182
|
+
req = stub_request(:post, "http://#{server}/contacts/1/media").
|
183
|
+
with(:body => {:media => data}.to_json,
|
184
|
+
:headers => {'Content-Type'=>'application/vnd.api+json'}).
|
185
|
+
to_return(:status => 201, :body => response_with_data('media', data))
|
186
|
+
|
187
|
+
result = Flapjack::Diner.create_contact_media(1, data)
|
188
|
+
req.should have_been_requested
|
189
|
+
result.should_not be_nil
|
190
|
+
result.should be_true
|
191
|
+
end
|
192
|
+
|
193
|
+
it "submits a POST request for several media" do
|
194
|
+
data = [{
|
195
|
+
:type => 'sms',
|
196
|
+
:address => '0123456789',
|
197
|
+
:interval => 300,
|
198
|
+
:rollup_threshold => 5
|
199
|
+
}, {
|
200
|
+
:type => 'email',
|
201
|
+
:address => 'ablated@example.org',
|
202
|
+
:interval => 180,
|
203
|
+
:rollup_threshold => 3
|
204
|
+
}]
|
205
|
+
|
206
|
+
req = stub_request(:post, "http://#{server}/contacts/1/media").
|
207
|
+
with(:body => {:media => data}.to_json,
|
208
|
+
:headers => {'Content-Type'=>'application/vnd.api+json'}).
|
209
|
+
to_return(:status => 201, :body => response_with_data('media', data))
|
210
|
+
|
211
|
+
result = Flapjack::Diner.create_contact_media(1, data)
|
212
|
+
req.should have_been_requested
|
213
|
+
result.should_not be_nil
|
214
|
+
result.should be_true
|
215
|
+
end
|
215
216
|
|
216
|
-
|
217
|
-
req.should have_been_requested
|
218
|
-
result.should_not be_nil
|
219
|
-
result.should == response_body
|
220
|
-
end
|
221
|
-
|
222
|
-
it "returns a list of downtimes for all checks on an entity between two times" do
|
223
|
-
start = Time.iso8601('2011-08-01T00:00:00+10:00')
|
224
|
-
finish = Time.iso8601('2011-08-31T00:00:00+10:00')
|
217
|
+
end
|
225
218
|
|
226
|
-
|
227
|
-
|
228
|
-
|
219
|
+
context 'read' do
|
220
|
+
it "submits a GET request for all media" do
|
221
|
+
req = stub_request(:get, "http://#{server}/media").
|
222
|
+
to_return(:body => response_with_data('media'))
|
223
|
+
|
224
|
+
result = Flapjack::Diner.media
|
225
|
+
req.should have_been_requested
|
226
|
+
result.should_not be_nil
|
227
|
+
end
|
228
|
+
|
229
|
+
it "submits a GET request for one medium" do
|
230
|
+
req = stub_request(:get, "http://#{server}/media/72_sms").
|
231
|
+
to_return(:body => response_with_data('media'))
|
232
|
+
|
233
|
+
result = Flapjack::Diner.media('72_sms')
|
234
|
+
req.should have_been_requested
|
235
|
+
result.should_not be_nil
|
236
|
+
end
|
237
|
+
|
238
|
+
it "submits a GET request for several media" do
|
239
|
+
req = stub_request(:get, "http://#{server}/media/72_sms,150_email").
|
240
|
+
to_return(:body => response_with_data('media'))
|
241
|
+
|
242
|
+
result = Flapjack::Diner.media('72_sms', '150_email')
|
243
|
+
req.should have_been_requested
|
244
|
+
result.should_not be_nil
|
245
|
+
end
|
246
|
+
end
|
229
247
|
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
248
|
+
context 'update' do
|
249
|
+
|
250
|
+
it "submits a PATCH request for one medium" do
|
251
|
+
req = stub_request(:patch, "http://#{server}/media/23_email").
|
252
|
+
with(:body => [{:op => 'replace', :path => '/media/0/interval', :value => 50},
|
253
|
+
{:op => 'replace', :path => '/media/0/rollup_threshold', :value => 3}].to_json,
|
254
|
+
:headers => {'Content-Type'=>'application/json-patch+json'}).
|
255
|
+
to_return(:status => 204)
|
256
|
+
|
257
|
+
result = Flapjack::Diner.update_media('23_email', :interval => 50, :rollup_threshold => 3)
|
258
|
+
req.should have_been_requested
|
259
|
+
result.should_not be_nil
|
260
|
+
result.should be_true
|
261
|
+
end
|
262
|
+
|
263
|
+
it "submits a PATCH request for several media" do
|
264
|
+
req = stub_request(:patch, "http://#{server}/media/23_email,87_sms").
|
265
|
+
with(:body => [{:op => 'replace', :path => '/media/0/interval', :value => 50},
|
266
|
+
{:op => 'replace', :path => '/media/0/rollup_threshold', :value => 3}].to_json,
|
267
|
+
:headers => {'Content-Type'=>'application/json-patch+json'}).
|
268
|
+
to_return(:status => 204)
|
269
|
+
|
270
|
+
result = Flapjack::Diner.update_media('23_email', '87_sms', :interval => 50, :rollup_threshold => 3)
|
271
|
+
req.should have_been_requested
|
272
|
+
result.should_not be_nil
|
273
|
+
result.should be_true
|
274
|
+
end
|
235
275
|
|
236
|
-
|
237
|
-
req = stub_request(:get, "http://#{server}/downtime/#{entity}/#{check}").
|
238
|
-
to_return(:body => response)
|
276
|
+
end
|
239
277
|
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
278
|
+
context 'delete' do
|
279
|
+
it "submits a DELETE request for one medium" do
|
280
|
+
req = stub_request(:delete, "http://#{server}/media/72_sms").
|
281
|
+
to_return(:status => 204)
|
282
|
+
|
283
|
+
result = Flapjack::Diner.delete_media('72_sms')
|
284
|
+
req.should have_been_requested
|
285
|
+
result.should_not be_nil
|
286
|
+
result.should be_true
|
287
|
+
end
|
288
|
+
|
289
|
+
it "submits a DELETE request for several media" do
|
290
|
+
req = stub_request(:delete, "http://#{server}/media/72_sms,150_email").
|
291
|
+
to_return(:status => 204)
|
292
|
+
|
293
|
+
result = Flapjack::Diner.delete_media('72_sms', '150_email')
|
294
|
+
req.should have_been_requested
|
295
|
+
result.should_not be_nil
|
296
|
+
result.should be_true
|
297
|
+
end
|
298
|
+
end
|
244
299
|
end
|
245
300
|
|
246
|
-
|
247
|
-
|
248
|
-
finish = Time.iso8601('2011-08-31T00:00:00+10:00')
|
301
|
+
context 'pagerduty credentials' do
|
302
|
+
context 'create' do
|
249
303
|
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
304
|
+
it "submits a POST request for pagerduty credentials" do
|
305
|
+
data = [{:service_key => 'abc',
|
306
|
+
:subdomain => 'def',
|
307
|
+
:username => 'ghi',
|
308
|
+
:password => 'jkl',
|
309
|
+
}]
|
254
310
|
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
result.should == response_body
|
260
|
-
end
|
311
|
+
req = stub_request(:post, "http://#{server}/contacts/1/pagerduty_credentials").
|
312
|
+
with(:body => {:pagerduty_credentials => data}.to_json,
|
313
|
+
:headers => {'Content-Type'=>'application/vnd.api+json'}).
|
314
|
+
to_return(:status => 201, :body => response_with_data('pagerduty_credentials', data))
|
261
315
|
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
316
|
+
result = Flapjack::Diner.create_contact_pagerduty_credentials(1, data)
|
317
|
+
req.should have_been_requested
|
318
|
+
result.should_not be_nil
|
319
|
+
result.should be_true
|
320
|
+
end
|
266
321
|
|
267
|
-
|
268
|
-
req.should have_been_requested
|
269
|
-
result.should be_true
|
270
|
-
end
|
322
|
+
end
|
271
323
|
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
324
|
+
context 'read' do
|
325
|
+
it "submits a GET request for all pagerduty credentials" do
|
326
|
+
req = stub_request(:get, "http://#{server}/pagerduty_credentials").
|
327
|
+
to_return(:body => response_with_data('pagerduty_credentials'))
|
328
|
+
|
329
|
+
result = Flapjack::Diner.pagerduty_credentials
|
330
|
+
req.should have_been_requested
|
331
|
+
result.should_not be_nil
|
332
|
+
end
|
333
|
+
|
334
|
+
it "submits a GET request for one set of pagerduty credentials" do
|
335
|
+
req = stub_request(:get, "http://#{server}/pagerduty_credentials/72").
|
336
|
+
to_return(:body => response_with_data('pagerduty_credentials'))
|
337
|
+
|
338
|
+
result = Flapjack::Diner.pagerduty_credentials('72')
|
339
|
+
req.should have_been_requested
|
340
|
+
result.should_not be_nil
|
341
|
+
end
|
342
|
+
|
343
|
+
it "submits a GET request for several sets of pagerduty credentials" do
|
344
|
+
req = stub_request(:get, "http://#{server}/pagerduty_credentials/72,150").
|
345
|
+
to_return(:body => response_with_data('pagerduty_credentials'))
|
346
|
+
|
347
|
+
result = Flapjack::Diner.pagerduty_credentials('72', '150')
|
348
|
+
req.should have_been_requested
|
349
|
+
result.should_not be_nil
|
350
|
+
end
|
351
|
+
end
|
277
352
|
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
353
|
+
context 'update' do
|
354
|
+
|
355
|
+
it "submits a PATCH request for one set of pagerduty credentials" do
|
356
|
+
req = stub_request(:patch, "http://#{server}/pagerduty_credentials/23").
|
357
|
+
with(:body => [{:op => 'replace', :path => '/pagerduty_credentials/0/password', :value => 'lmno'}].to_json,
|
358
|
+
:headers => {'Content-Type'=>'application/json-patch+json'}).
|
359
|
+
to_return(:status => 204)
|
360
|
+
|
361
|
+
result = Flapjack::Diner.update_pagerduty_credentials('23', :password => 'lmno')
|
362
|
+
req.should have_been_requested
|
363
|
+
result.should_not be_nil
|
364
|
+
result.should be_true
|
365
|
+
end
|
366
|
+
|
367
|
+
it "submits a PATCH request for several sets of pagerduty credentials" do
|
368
|
+
req = stub_request(:patch, "http://#{server}/pagerduty_credentials/23,87").
|
369
|
+
with(:body => [{:op => 'replace', :path => '/pagerduty_credentials/0/username', :value => 'hijk'},
|
370
|
+
{:op => 'replace', :path => '/pagerduty_credentials/0/password', :value => 'lmno'}].to_json,
|
371
|
+
:headers => {'Content-Type'=>'application/json-patch+json'}).
|
372
|
+
to_return(:status => 204)
|
373
|
+
|
374
|
+
result = Flapjack::Diner.update_pagerduty_credentials('23', '87', :username => 'hijk', :password => 'lmno')
|
375
|
+
req.should have_been_requested
|
376
|
+
result.should_not be_nil
|
377
|
+
result.should be_true
|
378
|
+
end
|
282
379
|
|
283
|
-
|
284
|
-
req = stub_request(:post, "http://#{server}/acknowledgements").with(
|
285
|
-
:body => {:entity => [entity, 'lmn.net'], :summary => 'dealing with it'}).to_return(
|
286
|
-
:status => 204)
|
380
|
+
end
|
287
381
|
|
288
|
-
|
289
|
-
|
290
|
-
|
382
|
+
context 'delete' do
|
383
|
+
it "submits a DELETE request for one set of pagerduty credentials" do
|
384
|
+
req = stub_request(:delete, "http://#{server}/pagerduty_credentials/72").
|
385
|
+
to_return(:status => 204)
|
386
|
+
|
387
|
+
result = Flapjack::Diner.delete_pagerduty_credentials('72')
|
388
|
+
req.should have_been_requested
|
389
|
+
result.should_not be_nil
|
390
|
+
result.should be_true
|
391
|
+
end
|
392
|
+
|
393
|
+
it "submits a DELETE request for several media" do
|
394
|
+
req = stub_request(:delete, "http://#{server}/pagerduty_credentials/72,150").
|
395
|
+
to_return(:status => 204)
|
396
|
+
|
397
|
+
result = Flapjack::Diner.delete_pagerduty_credentials('72', '150')
|
398
|
+
req.should have_been_requested
|
399
|
+
result.should_not be_nil
|
400
|
+
result.should be_true
|
401
|
+
end
|
402
|
+
end
|
291
403
|
end
|
292
404
|
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
405
|
+
context 'notification rules' do
|
406
|
+
|
407
|
+
context 'create' do
|
408
|
+
|
409
|
+
it "submits a POST request for a notification rule" do
|
410
|
+
data = [{
|
411
|
+
"entity_tags" => ["database","physical"],
|
412
|
+
"entities" => ["foo-app-01.example.com"],
|
413
|
+
"time_restrictions" => nil,
|
414
|
+
"warning_media" => ["email"],
|
415
|
+
"critical_media" => ["sms", "email"],
|
416
|
+
"warning_blackhole" => false,
|
417
|
+
"critical_blackhole" => false
|
418
|
+
}]
|
419
|
+
|
420
|
+
req = stub_request(:post, "http://#{server}/contacts/1/notification_rules").
|
421
|
+
with(:body => {:notification_rules => data}.to_json,
|
422
|
+
:headers => {'Content-Type'=>'application/vnd.api+json'}).
|
423
|
+
to_return(:status => 201, :body => response_with_data('notification_rules', data))
|
424
|
+
|
425
|
+
|
426
|
+
result = Flapjack::Diner.create_contact_notification_rules(1, data)
|
427
|
+
req.should have_been_requested
|
428
|
+
result.should_not be_nil
|
429
|
+
result.should be_true
|
430
|
+
end
|
431
|
+
|
432
|
+
it "submits a POST request for several notification rules" do
|
433
|
+
data = [{
|
434
|
+
"entity_tags" => ["database","physical"],
|
435
|
+
"entities" => ["foo-app-01.example.com"],
|
436
|
+
"time_restrictions" => nil,
|
437
|
+
"warning_media" => ["email"],
|
438
|
+
"critical_media" => ["sms", "email"],
|
439
|
+
"warning_blackhole" => false,
|
440
|
+
"critical_blackhole" => false
|
441
|
+
}, {
|
442
|
+
"entity_tags" => nil,
|
443
|
+
"entities" => ["foo-app-02.example.com"],
|
444
|
+
"time_restrictions" => nil,
|
445
|
+
"warning_media" => ["email"],
|
446
|
+
"critical_media" => ["sms", "email"],
|
447
|
+
"warning_blackhole" => true,
|
448
|
+
"critical_blackhole" => false
|
449
|
+
}]
|
450
|
+
|
451
|
+
req = stub_request(:post, "http://#{server}/contacts/1/notification_rules").
|
452
|
+
with(:body => {:notification_rules => data}.to_json,
|
453
|
+
:headers => {'Content-Type'=>'application/vnd.api+json'}).
|
454
|
+
to_return(:status => 201, :body => response_with_data('notification_rules', data))
|
455
|
+
|
456
|
+
result = Flapjack::Diner.create_contact_notification_rules(1, data)
|
457
|
+
req.should have_been_requested
|
458
|
+
result.should_not be_nil
|
459
|
+
result.should be_true
|
460
|
+
end
|
297
461
|
|
298
|
-
|
299
|
-
req.should have_been_requested
|
300
|
-
result.should be_true
|
301
|
-
end
|
462
|
+
end
|
302
463
|
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
464
|
+
context 'read' do
|
465
|
+
it "submits a GET request for all notification rules" do
|
466
|
+
req = stub_request(:get, "http://#{server}/notification_rules").
|
467
|
+
to_return(:body => response_with_data('notification_rules'))
|
468
|
+
|
469
|
+
result = Flapjack::Diner.notification_rules
|
470
|
+
req.should have_been_requested
|
471
|
+
result.should_not be_nil
|
472
|
+
end
|
473
|
+
|
474
|
+
it "submits a GET request for one notification rule" do
|
475
|
+
req = stub_request(:get, "http://#{server}/notification_rules/30fd36ae-3922-4957-ae3e-c8f6dd27e543").
|
476
|
+
to_return(:body => response_with_data('notification_rules'))
|
477
|
+
|
478
|
+
result = Flapjack::Diner.notification_rules('30fd36ae-3922-4957-ae3e-c8f6dd27e543')
|
479
|
+
req.should have_been_requested
|
480
|
+
result.should_not be_nil
|
481
|
+
end
|
482
|
+
|
483
|
+
it "submits a GET request for several media" do
|
484
|
+
req = stub_request(:get, "http://#{server}/notification_rules/30fd36ae-3922-4957-ae3e-c8f6dd27e543,bfd8be61-3d80-4b95-94df-6e77183ce4e3").
|
485
|
+
to_return(:body => response_with_data('notification_rules'))
|
486
|
+
|
487
|
+
result = Flapjack::Diner.notification_rules('30fd36ae-3922-4957-ae3e-c8f6dd27e543', 'bfd8be61-3d80-4b95-94df-6e77183ce4e3')
|
488
|
+
req.should have_been_requested
|
489
|
+
result.should_not be_nil
|
490
|
+
end
|
491
|
+
end
|
307
492
|
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
493
|
+
context 'update' do
|
494
|
+
|
495
|
+
it "submits a PATCH request for one notification rule" do
|
496
|
+
req = stub_request(:patch, "http://#{server}/notification_rules/30fd36ae-3922-4957-ae3e-c8f6dd27e543").
|
497
|
+
with(:body => [{:op => 'replace', :path => '/notification_rules/0/warning_blackhole', :value => false}].to_json,
|
498
|
+
:headers => {'Content-Type'=>'application/json-patch+json'}).
|
499
|
+
to_return(:status => 204)
|
500
|
+
|
501
|
+
result = Flapjack::Diner.update_notification_rules('30fd36ae-3922-4957-ae3e-c8f6dd27e543', :warning_blackhole => false)
|
502
|
+
req.should have_been_requested
|
503
|
+
result.should_not be_nil
|
504
|
+
result.should be_true
|
505
|
+
end
|
506
|
+
|
507
|
+
it "submits a PATCH request for several notification rules" do
|
508
|
+
req = stub_request(:patch, "http://#{server}/notification_rules/30fd36ae-3922-4957-ae3e-c8f6dd27e543,bfd8be61-3d80-4b95-94df-6e77183ce4e3").
|
509
|
+
with(:body => [{:op => 'replace', :path => '/notification_rules/0/warning_blackhole', :value => false}].to_json,
|
510
|
+
:headers => {'Content-Type'=>'application/json-patch+json'}).
|
511
|
+
to_return(:status => 204)
|
512
|
+
|
513
|
+
result = Flapjack::Diner.update_notification_rules('30fd36ae-3922-4957-ae3e-c8f6dd27e543',
|
514
|
+
'bfd8be61-3d80-4b95-94df-6e77183ce4e3', :warning_blackhole => false)
|
515
|
+
req.should have_been_requested
|
516
|
+
result.should_not be_nil
|
517
|
+
result.should be_true
|
518
|
+
end
|
312
519
|
|
313
|
-
|
314
|
-
req = stub_request(:post, "http://#{server}/test_notifications").with(
|
315
|
-
:body => {:entity => [entity, 'lmn.net'], :summary => 'testing notifications'}).to_return(
|
316
|
-
:status => 204)
|
520
|
+
end
|
317
521
|
|
318
|
-
|
319
|
-
|
320
|
-
|
522
|
+
context 'delete' do
|
523
|
+
it "submits a DELETE request for a notification rule" do
|
524
|
+
req = stub_request(:delete, "http://#{server}/notification_rules/30fd36ae-3922-4957-ae3e-c8f6dd27e543").
|
525
|
+
to_return(:status => 204)
|
526
|
+
|
527
|
+
result = Flapjack::Diner.delete_notification_rules('30fd36ae-3922-4957-ae3e-c8f6dd27e543')
|
528
|
+
req.should have_been_requested
|
529
|
+
result.should_not be_nil
|
530
|
+
result.should be_true
|
531
|
+
end
|
532
|
+
|
533
|
+
it "submits a DELETE request for several notification rules" do
|
534
|
+
req = stub_request(:delete, "http://#{server}/notification_rules/30fd36ae-3922-4957-ae3e-c8f6dd27e543,bfd8be61-3d80-4b95-94df-6e77183ce4e3").
|
535
|
+
to_return(:status => 204)
|
536
|
+
|
537
|
+
result = Flapjack::Diner.delete_notification_rules('30fd36ae-3922-4957-ae3e-c8f6dd27e543', 'bfd8be61-3d80-4b95-94df-6e77183ce4e3')
|
538
|
+
req.should have_been_requested
|
539
|
+
result.should_not be_nil
|
540
|
+
result.should be_true
|
541
|
+
end
|
542
|
+
end
|
321
543
|
end
|
322
544
|
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
545
|
+
context 'entities' do
|
546
|
+
|
547
|
+
context 'create' do
|
548
|
+
|
549
|
+
it "submits a POST request for an entity" do
|
550
|
+
data = [{
|
551
|
+
:name => 'example.org',
|
552
|
+
:id => '57_example'
|
553
|
+
}]
|
554
|
+
|
555
|
+
req = stub_request(:post, "http://#{server}/entities").
|
556
|
+
with(:body => {:entities => data}.to_json,
|
557
|
+
:headers => {'Content-Type'=>'application/vnd.api+json'}).
|
558
|
+
to_return(:status => 201, :body => response_with_data('entities', data))
|
559
|
+
|
560
|
+
result = Flapjack::Diner.create_entities(data)
|
561
|
+
req.should have_been_requested
|
562
|
+
result.should_not be_nil
|
563
|
+
result.should be_true
|
564
|
+
end
|
565
|
+
|
566
|
+
it "submits a POST request for several entities" do
|
567
|
+
data = [{
|
568
|
+
:name => 'example.org',
|
569
|
+
:id => '57_example'
|
570
|
+
}, {
|
571
|
+
:name => 'example2.org',
|
572
|
+
:id => '58'
|
573
|
+
}]
|
574
|
+
|
575
|
+
req = stub_request(:post, "http://#{server}/entities").
|
576
|
+
with(:body => {:entities => data}.to_json,
|
577
|
+
:headers => {'Content-Type'=>'application/vnd.api+json'}).
|
578
|
+
to_return(:status => 201, :body => response_with_data('entities', data))
|
579
|
+
|
580
|
+
result = Flapjack::Diner.create_entities(data)
|
581
|
+
req.should have_been_requested
|
582
|
+
result.should_not be_nil
|
583
|
+
result.should be_true
|
584
|
+
end
|
585
|
+
|
586
|
+
context 'scheduled maintenance periods' do
|
587
|
+
|
588
|
+
it "submits a POST request on an entity" do
|
589
|
+
data = [{:start_time => time.iso8601, :duration => 3600, :summary => 'working'}]
|
590
|
+
req = stub_request(:post, "http://#{server}/scheduled_maintenances/entities/72").
|
591
|
+
with(:body => {:scheduled_maintenances => data}.to_json,
|
592
|
+
:headers => {'Content-Type'=>'application/vnd.api+json'}).
|
332
593
|
to_return(:status => 204)
|
333
594
|
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
req = stub_request(:post, "http://#{server}/scheduled_maintenances").
|
346
|
-
with(:body => {:entity => entity, :start_time => start_time.iso8601,
|
347
|
-
:duration => duration, :summary => summary},
|
348
|
-
:headers => {'Content-Type'=>'application/json'}).
|
595
|
+
result = Flapjack::Diner.create_scheduled_maintenances_entities(72, data)
|
596
|
+
req.should have_been_requested
|
597
|
+
result.should_not be_nil
|
598
|
+
result.should be_true
|
599
|
+
end
|
600
|
+
|
601
|
+
it "submits a POST request on several entities" do
|
602
|
+
data = [{:start_time => time.iso8601, :duration => 3600, :summary => 'working'}]
|
603
|
+
req = stub_request(:post, "http://#{server}/scheduled_maintenances/entities/72,150").
|
604
|
+
with(:body => {:scheduled_maintenances => data}.to_json,
|
605
|
+
:headers => {'Content-Type'=>'application/vnd.api+json'}).
|
349
606
|
to_return(:status => 204)
|
350
607
|
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
with(:body => {:check => {entity => 'ping', 'pqr.org' => 'ssh'}, :start_time => start_time.iso8601,
|
364
|
-
:duration => duration, :summary => summary},
|
365
|
-
:headers => {'Content-Type'=>'application/json'}).
|
608
|
+
result = Flapjack::Diner.create_scheduled_maintenances_entities(72, 150, data)
|
609
|
+
req.should have_been_requested
|
610
|
+
result.should_not be_nil
|
611
|
+
result.should be_true
|
612
|
+
end
|
613
|
+
|
614
|
+
it "submits a POST request for multiple periods on an entity" do
|
615
|
+
data = [{:start_time => time.iso8601, :duration => 3600, :summary => 'working'},
|
616
|
+
{:start_time => (time + 7200).iso8601, :duration => 3600, :summary => 'more work'}]
|
617
|
+
req = stub_request(:post, "http://#{server}/scheduled_maintenances/entities/72").
|
618
|
+
with(:body => {:scheduled_maintenances => data}.to_json,
|
619
|
+
:headers => {'Content-Type'=>'application/vnd.api+json'}).
|
366
620
|
to_return(:status => 204)
|
367
621
|
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
with(:body => {:
|
379
|
-
:headers => {'Content-Type'=>'application/json'}).
|
622
|
+
result = Flapjack::Diner.create_scheduled_maintenances_entities(72, data)
|
623
|
+
req.should have_been_requested
|
624
|
+
result.should_not be_nil
|
625
|
+
result.should be_true
|
626
|
+
end
|
627
|
+
|
628
|
+
it "submits a POST request for multiple periods on several entities" do
|
629
|
+
data = [{:start_time => time.iso8601, :duration => 3600, :summary => 'working'},
|
630
|
+
{:start_time => (time + 7200).iso8601, :duration => 3600, :summary => 'more work'}]
|
631
|
+
req = stub_request(:post, "http://#{server}/scheduled_maintenances/entities/72,150").
|
632
|
+
with(:body => {:scheduled_maintenances => data}.to_json,
|
633
|
+
:headers => {'Content-Type'=>'application/vnd.api+json'}).
|
380
634
|
to_return(:status => 204)
|
381
635
|
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
636
|
+
result = Flapjack::Diner.create_scheduled_maintenances_entities(72, 150, data)
|
637
|
+
req.should have_been_requested
|
638
|
+
result.should_not be_nil
|
639
|
+
result.should be_true
|
640
|
+
end
|
387
641
|
|
388
|
-
|
389
|
-
start_time = Time.now
|
642
|
+
end
|
390
643
|
|
391
|
-
|
392
|
-
with(:body => {:entity => entity, :start_time => start_time.iso8601},
|
393
|
-
:headers => {'Content-Type'=>'application/json'}).
|
394
|
-
to_return(:status => 204)
|
644
|
+
context 'unscheduled maintenance periods' do
|
395
645
|
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
646
|
+
it "submits a POST request on an entity" do
|
647
|
+
data = [{:duration => 3600, :summary => 'working'}]
|
648
|
+
req = stub_request(:post, "http://#{server}/unscheduled_maintenances/entities/72").
|
649
|
+
with(:body => {:unscheduled_maintenances => data}.to_json,
|
650
|
+
:headers => {'Content-Type'=>'application/vnd.api+json'}).
|
651
|
+
to_return(:status => 204)
|
401
652
|
|
402
|
-
|
403
|
-
|
653
|
+
result = Flapjack::Diner.create_unscheduled_maintenances_entities(72, data)
|
654
|
+
req.should have_been_requested
|
655
|
+
result.should_not be_nil
|
656
|
+
result.should be_true
|
657
|
+
end
|
658
|
+
|
659
|
+
it "submits a POST request on several entities" do
|
660
|
+
data = [{:duration => 3600, :summary => 'working'}]
|
661
|
+
req = stub_request(:post, "http://#{server}/unscheduled_maintenances/entities/72,150").
|
662
|
+
with(:body => {:unscheduled_maintenances => data}.to_json,
|
663
|
+
:headers => {'Content-Type'=>'application/vnd.api+json'}).
|
664
|
+
to_return(:status => 204)
|
404
665
|
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
666
|
+
result = Flapjack::Diner.create_unscheduled_maintenances_entities(72, 150, data)
|
667
|
+
req.should have_been_requested
|
668
|
+
result.should_not be_nil
|
669
|
+
result.should be_true
|
670
|
+
end
|
671
|
+
|
672
|
+
it "submits a POST request for multiple periods on several entities" do
|
673
|
+
data = [{:duration => 3600, :summary => 'working'},
|
674
|
+
{:duration => 3600, :summary => 'more work'}]
|
675
|
+
req = stub_request(:post, "http://#{server}/unscheduled_maintenances/entities/72,150").
|
676
|
+
with(:body => {:unscheduled_maintenances => data}.to_json,
|
677
|
+
:headers => {'Content-Type'=>'application/vnd.api+json'}).
|
409
678
|
to_return(:status => 204)
|
410
679
|
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
680
|
+
result = Flapjack::Diner.create_unscheduled_maintenances_entities(72, 150, data)
|
681
|
+
req.should have_been_requested
|
682
|
+
result.should_not be_nil
|
683
|
+
result.should be_true
|
684
|
+
end
|
416
685
|
|
417
|
-
|
418
|
-
end_time = Time.now
|
686
|
+
end
|
419
687
|
|
420
|
-
|
421
|
-
with(:body => {:check => {entity => check}, :end_time => end_time.iso8601},
|
422
|
-
:headers => {'Content-Type'=>'application/json'}).
|
423
|
-
to_return(:status => 204)
|
688
|
+
context 'test notifications' do
|
424
689
|
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
690
|
+
it "submits a POST request for an entity" do
|
691
|
+
req = stub_request(:post, "http://#{server}/test_notifications/entities/72").
|
692
|
+
with(:body => {:test_notifications => [{:summary => 'testing'}]}.to_json,
|
693
|
+
:headers => {'Content-Type'=>'application/vnd.api+json'}).
|
694
|
+
to_return(:status => 204)
|
430
695
|
|
431
|
-
|
432
|
-
|
696
|
+
result = Flapjack::Diner.create_test_notifications_entities(72, [:summary => 'testing'])
|
697
|
+
req.should have_been_requested
|
698
|
+
result.should_not be_nil
|
699
|
+
result.should be_true
|
700
|
+
end
|
433
701
|
|
434
|
-
|
435
|
-
|
436
|
-
|
702
|
+
it "submits a POST request for several entities" do
|
703
|
+
req = stub_request(:post, "http://#{server}/test_notifications/entities/72,150").
|
704
|
+
with(:body => {:test_notifications => [{:summary => 'testing'}]}.to_json,
|
705
|
+
:headers => {'Content-Type'=>'application/vnd.api+json'}).
|
437
706
|
to_return(:status => 204)
|
438
707
|
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
708
|
+
result = Flapjack::Diner.create_test_notifications_entities(72, 150, [:summary => 'testing'])
|
709
|
+
req.should have_been_requested
|
710
|
+
result.should_not be_nil
|
711
|
+
result.should be_true
|
712
|
+
end
|
713
|
+
|
714
|
+
it "submits a POST request for multiple notifications on an entity" do
|
715
|
+
data = [{:summary => 'testing'}, {:summary => 'another test'}]
|
716
|
+
req = stub_request(:post, "http://#{server}/test_notifications/entities/72").
|
717
|
+
with(:body => {:test_notifications => data}.to_json,
|
718
|
+
:headers => {'Content-Type'=>'application/vnd.api+json'}).
|
719
|
+
to_return(:status => 204)
|
447
720
|
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
721
|
+
result = Flapjack::Diner.create_test_notifications_entities(72, data)
|
722
|
+
req.should have_been_requested
|
723
|
+
result.should_not be_nil
|
724
|
+
result.should be_true
|
725
|
+
end
|
726
|
+
|
727
|
+
it "submits a POST request for multiple notifications on several entities" do
|
728
|
+
data = [{:summary => 'testing'}, {:summary => 'another test'}]
|
729
|
+
req = stub_request(:post, "http://#{server}/test_notifications/entities/72,150").
|
730
|
+
with(:body => {:test_notifications => data}.to_json,
|
731
|
+
:headers => {'Content-Type'=>'application/vnd.api+json'}).
|
452
732
|
to_return(:status => 204)
|
453
733
|
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
734
|
+
result = Flapjack::Diner.create_test_notifications_entities(72, 150, data)
|
735
|
+
req.should have_been_requested
|
736
|
+
result.should_not be_nil
|
737
|
+
result.should be_true
|
738
|
+
end
|
459
739
|
|
740
|
+
end
|
460
741
|
|
461
|
-
|
462
|
-
req = stub_request(:get, "http://#{server}/contacts").to_return(
|
463
|
-
:body => response)
|
742
|
+
end
|
464
743
|
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
744
|
+
context 'read' do
|
745
|
+
it "submits a GET request for all entities" do
|
746
|
+
req = stub_request(:get, "http://#{server}/entities").
|
747
|
+
to_return(:body => response_with_data('entities'))
|
748
|
+
|
749
|
+
result = Flapjack::Diner.entities
|
750
|
+
req.should have_been_requested
|
751
|
+
result.should_not be_nil
|
752
|
+
end
|
753
|
+
|
754
|
+
it "submits a GET request for one entity" do
|
755
|
+
req = stub_request(:get, "http://#{server}/entities/72").
|
756
|
+
to_return(:body => response_with_data('entities'))
|
757
|
+
|
758
|
+
result = Flapjack::Diner.entities('72')
|
759
|
+
req.should have_been_requested
|
760
|
+
result.should_not be_nil
|
761
|
+
end
|
762
|
+
|
763
|
+
it "submits a GET request for several entities" do
|
764
|
+
req = stub_request(:get, "http://#{server}/entities/72,150").
|
765
|
+
to_return(:body => response_with_data('entities'))
|
766
|
+
|
767
|
+
result = Flapjack::Diner.entities('72', '150')
|
768
|
+
req.should have_been_requested
|
769
|
+
result.should_not be_nil
|
770
|
+
end
|
771
|
+
end
|
470
772
|
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
773
|
+
context 'update' do
|
774
|
+
|
775
|
+
it "submits a PATCH request for an entity" do
|
776
|
+
req = stub_request(:patch, "http://#{server}/entities/57").
|
777
|
+
with(:body => [{:op => 'replace', :path => '/entities/0/name', :value => 'example3.com'}].to_json,
|
778
|
+
:headers => {'Content-Type'=>'application/json-patch+json'}).
|
779
|
+
to_return(:status => 204)
|
780
|
+
|
781
|
+
result = Flapjack::Diner.update_entities('57', :name => 'example3.com')
|
782
|
+
req.should have_been_requested
|
783
|
+
result.should_not be_nil
|
784
|
+
result.should be_true
|
785
|
+
end
|
786
|
+
|
787
|
+
it "submits a PATCH request for unscheduled maintenances on an entity" do
|
788
|
+
req = stub_request(:patch, "http://#{server}/unscheduled_maintenances/entities/72").
|
789
|
+
with(:body => [{:op => 'replace', :path => '/unscheduled_maintenances/0/end_time', :value => time.iso8601}].to_json,
|
790
|
+
:headers => {'Content-Type'=>'application/json-patch+json'}).
|
791
|
+
to_return(:status => 204)
|
792
|
+
|
793
|
+
result = Flapjack::Diner.update_unscheduled_maintenances_entities('72', :end_time => time)
|
794
|
+
req.should have_been_requested
|
795
|
+
result.should_not be_nil
|
796
|
+
result.should be_true
|
797
|
+
end
|
798
|
+
|
799
|
+
it "submits a PATCH request for unscheduled maintenances on several entities" do
|
800
|
+
req = stub_request(:patch, "http://#{server}/unscheduled_maintenances/entities/72,150").
|
801
|
+
with(:body => [{:op => 'replace', :path => '/unscheduled_maintenances/0/end_time', :value => time.iso8601}].to_json,
|
802
|
+
:headers => {'Content-Type'=>'application/json-patch+json'}).
|
803
|
+
to_return(:status => 204)
|
804
|
+
|
805
|
+
result = Flapjack::Diner.update_unscheduled_maintenances_entities('72', '150', :end_time => time)
|
806
|
+
req.should have_been_requested
|
807
|
+
result.should_not be_nil
|
808
|
+
result.should be_true
|
809
|
+
end
|
475
810
|
|
476
|
-
|
477
|
-
req.should have_been_requested
|
478
|
-
result.should_not be_nil
|
479
|
-
result.should == response_body
|
480
|
-
end
|
811
|
+
end
|
481
812
|
|
482
|
-
|
483
|
-
contact_id = '21'
|
484
|
-
req = stub_request(:get, "http://#{server}/contacts/#{contact_id}/notification_rules").to_return(
|
485
|
-
:body => response)
|
813
|
+
context 'delete' do
|
486
814
|
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
end
|
815
|
+
it "submits a DELETE request for scheduled maintenances on an entity" do
|
816
|
+
req = stub_request(:delete, "http://#{server}/scheduled_maintenances/entities/72").
|
817
|
+
with(:query => {:start_time => time.iso8601}).
|
818
|
+
to_return(:status => 204)
|
492
819
|
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
820
|
+
result = Flapjack::Diner.delete_scheduled_maintenances_entities('72', :start_time => time.iso8601)
|
821
|
+
req.should have_been_requested
|
822
|
+
result.should_not be_nil
|
823
|
+
result.should be_true
|
824
|
+
end
|
497
825
|
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
end
|
826
|
+
it "submits a DELETE request for scheduled maintenances on several entities" do
|
827
|
+
req = stub_request(:delete, "http://#{server}/scheduled_maintenances/entities/72,150").
|
828
|
+
with(:query => {:start_time => time.iso8601}).
|
829
|
+
to_return(:status => 204)
|
503
830
|
|
504
|
-
|
505
|
-
|
831
|
+
result = Flapjack::Diner.delete_scheduled_maintenances_entities('72', '150', :start_time => time.iso8601)
|
832
|
+
req.should have_been_requested
|
833
|
+
result.should_not be_nil
|
834
|
+
result.should be_true
|
835
|
+
end
|
506
836
|
|
507
|
-
|
508
|
-
with(:body => rule_data,
|
509
|
-
:headers => {'Content-Type'=>'application/json'}).
|
510
|
-
to_return(:body => rule_result.to_json)
|
837
|
+
end
|
511
838
|
|
512
|
-
result = Flapjack::Diner.create_notification_rule!(rule_data)
|
513
|
-
req.should have_been_requested
|
514
|
-
result.should == rule_result
|
515
839
|
end
|
516
840
|
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
rule_data_with_id = rule_data.merge('id' => rule_id)
|
841
|
+
context 'checks' do
|
842
|
+
context 'create' do
|
521
843
|
|
522
|
-
|
523
|
-
with(:body => rule_data_with_id,
|
524
|
-
:headers => {'Content-Type'=>'application/json'}).
|
525
|
-
to_return(:body => rule_data_with_id.to_json)
|
844
|
+
context 'scheduled maintenance periods' do
|
526
845
|
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
846
|
+
it "submits a POST request on a check" do
|
847
|
+
data = [{:start_time => time.iso8601, :duration => 3600, :summary => 'working'}]
|
848
|
+
req = stub_request(:post, "http://#{server}/scheduled_maintenances/checks/example.com:SSH").
|
849
|
+
with(:body => {:scheduled_maintenances => data}.to_json,
|
850
|
+
:headers => {'Content-Type'=>'application/vnd.api+json'}).
|
851
|
+
to_return(:status => 204)
|
531
852
|
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
853
|
+
result = Flapjack::Diner.create_scheduled_maintenances_checks('example.com:SSH', data)
|
854
|
+
req.should have_been_requested
|
855
|
+
result.should_not be_nil
|
856
|
+
result.should be_true
|
857
|
+
end
|
858
|
+
|
859
|
+
it "submits a POST request on several checks" do
|
860
|
+
data = [{:start_time => time.iso8601, :duration => 3600, :summary => 'working'}]
|
861
|
+
req = stub_request(:post, "http://#{server}/scheduled_maintenances/checks/example.com:SSH,example2.com:PING").
|
862
|
+
with(:body => {:scheduled_maintenances => data}.to_json,
|
863
|
+
:headers => {'Content-Type'=>'application/vnd.api+json'}).
|
864
|
+
to_return(:status => 204)
|
536
865
|
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
866
|
+
result = Flapjack::Diner.create_scheduled_maintenances_checks('example.com:SSH', 'example2.com:PING', data)
|
867
|
+
req.should have_been_requested
|
868
|
+
result.should_not be_nil
|
869
|
+
result.should be_true
|
870
|
+
end
|
871
|
+
|
872
|
+
it "submits a POST request for multiple periods on a check" do
|
873
|
+
data = [{:start_time => time.iso8601, :duration => 3600, :summary => 'working'},
|
874
|
+
{:start_time => (time + 7200).iso8601, :duration => 3600, :summary => 'more work'}]
|
875
|
+
req = stub_request(:post, "http://#{server}/scheduled_maintenances/checks/example.com:SSH").
|
876
|
+
with(:body => {:scheduled_maintenances => data}.to_json,
|
877
|
+
:headers => {'Content-Type'=>'application/vnd.api+json'}).
|
878
|
+
to_return(:status => 204)
|
541
879
|
|
542
|
-
|
543
|
-
|
544
|
-
|
880
|
+
result = Flapjack::Diner.create_scheduled_maintenances_checks('example.com:SSH', data)
|
881
|
+
req.should have_been_requested
|
882
|
+
result.should_not be_nil
|
883
|
+
result.should be_true
|
884
|
+
end
|
885
|
+
|
886
|
+
it "submits a POST request for multiple periods on several checks" do
|
887
|
+
data = [{:start_time => time.iso8601, :duration => 3600, :summary => 'working'},
|
888
|
+
{:start_time => (time + 7200).iso8601, :duration => 3600, :summary => 'more work'}]
|
889
|
+
req = stub_request(:post, "http://#{server}/scheduled_maintenances/checks/example.com:SSH,example2.com:PING").
|
890
|
+
with(:body => {:scheduled_maintenances => data}.to_json,
|
891
|
+
:headers => {'Content-Type'=>'application/vnd.api+json'}).
|
892
|
+
to_return(:status => 204)
|
545
893
|
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
894
|
+
result = Flapjack::Diner.create_scheduled_maintenances_checks('example.com:SSH', 'example2.com:PING', data)
|
895
|
+
req.should have_been_requested
|
896
|
+
result.should_not be_nil
|
897
|
+
result.should be_true
|
898
|
+
end
|
550
899
|
|
551
|
-
|
552
|
-
req = stub_request(:post, "http://#{server}/entities/#{entity}/tags").
|
553
|
-
with(:body => {:tag => ['web', 'app']},
|
554
|
-
:headers => {'Content-Type'=>'application/json'}).
|
555
|
-
to_return(:body => ['web', 'app'].to_json)
|
900
|
+
end
|
556
901
|
|
557
|
-
|
558
|
-
req.should have_been_requested
|
559
|
-
result.should == ['web', 'app']
|
560
|
-
end
|
902
|
+
context 'unscheduled maintenance periods' do
|
561
903
|
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
904
|
+
it "submits a POST request on a check" do
|
905
|
+
data = [{:duration => 3600, :summary => 'working'}]
|
906
|
+
req = stub_request(:post, "http://#{server}/unscheduled_maintenances/checks/example.com:SSH").
|
907
|
+
with(:body => {:unscheduled_maintenances => data}.to_json,
|
908
|
+
:headers => {'Content-Type'=>'application/vnd.api+json'}).
|
566
909
|
to_return(:status => 204)
|
567
910
|
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
result.should == ['user', 'admin']
|
581
|
-
end
|
911
|
+
result = Flapjack::Diner.create_unscheduled_maintenances_checks('example.com:SSH', data)
|
912
|
+
req.should have_been_requested
|
913
|
+
result.should_not be_nil
|
914
|
+
result.should be_true
|
915
|
+
end
|
916
|
+
|
917
|
+
it "submits a POST request on several checks" do
|
918
|
+
data = [{:duration => 3600, :summary => 'working'}]
|
919
|
+
req = stub_request(:post, "http://#{server}/unscheduled_maintenances/checks/example.com:SSH,example2.com:PING").
|
920
|
+
with(:body => {:unscheduled_maintenances => data}.to_json,
|
921
|
+
:headers => {'Content-Type'=>'application/vnd.api+json'}).
|
922
|
+
to_return(:status => 204)
|
582
923
|
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
924
|
+
result = Flapjack::Diner.create_unscheduled_maintenances_checks('example.com:SSH', 'example2.com:PING', data)
|
925
|
+
req.should have_been_requested
|
926
|
+
result.should_not be_nil
|
927
|
+
result.should be_true
|
928
|
+
end
|
929
|
+
|
930
|
+
it "submits a POST request for multiple periods on several checks" do
|
931
|
+
data = [{:duration => 3600, :summary => 'working'},
|
932
|
+
{:duration => 3600, :summary => 'more work'}]
|
933
|
+
req = stub_request(:post, "http://#{server}/unscheduled_maintenances/checks/example.com:SSH,example2.com:PING").
|
934
|
+
with(:body => {:unscheduled_maintenances => data}.to_json,
|
935
|
+
:headers => {'Content-Type'=>'application/vnd.api+json'}).
|
936
|
+
to_return(:status => 204)
|
587
937
|
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
938
|
+
result = Flapjack::Diner.create_unscheduled_maintenances_checks('example.com:SSH', 'example2.com:PING', data)
|
939
|
+
req.should have_been_requested
|
940
|
+
result.should_not be_nil
|
941
|
+
result.should be_true
|
942
|
+
end
|
592
943
|
|
593
|
-
|
594
|
-
contact_id = 21
|
595
|
-
req = stub_request(:post, "http://#{server}/contacts/#{contact_id}/entity_tags").
|
596
|
-
with(:body => {:entity => {'entity_1' => ['web', 'app']}},
|
597
|
-
:headers => {'Content-Type'=>'application/json'}).
|
598
|
-
to_return(:body => {'entity_1' => ['web', 'app']}.to_json)
|
944
|
+
end
|
599
945
|
|
600
|
-
|
601
|
-
req.should have_been_requested
|
602
|
-
result.should == {'entity_1' => ['web', 'app']}
|
603
|
-
end
|
946
|
+
context 'test notifications' do
|
604
947
|
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
:headers => {'Content-Type'=>'application/json'}).
|
948
|
+
it "submits a POST request for a check" do
|
949
|
+
req = stub_request(:post, "http://#{server}/test_notifications/checks/example.com:SSH").
|
950
|
+
with(:body => {:test_notifications => [{:summary => 'testing'}]}.to_json,
|
951
|
+
:headers => {'Content-Type'=>'application/vnd.api+json'}).
|
610
952
|
to_return(:status => 204)
|
611
953
|
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
it "adds tags to a contact" do
|
618
|
-
contact_id = 21
|
619
|
-
req = stub_request(:post, "http://#{server}/contacts/#{contact_id}/tags").
|
620
|
-
with(:body => {:tag => ['admin', 'user']},
|
621
|
-
:headers => {'Content-Type'=>'application/json'}).
|
622
|
-
to_return(:body => ['admin', 'user'].to_json)
|
954
|
+
result = Flapjack::Diner.create_test_notifications_checks('example.com:SSH', [{:summary => 'testing'}])
|
955
|
+
req.should have_been_requested
|
956
|
+
result.should_not be_nil
|
957
|
+
result.should be_true
|
958
|
+
end
|
623
959
|
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
960
|
+
it "submits a POST request for several checks" do
|
961
|
+
req = stub_request(:post, "http://#{server}/test_notifications/checks/example.com:SSH,example2.com:PING").
|
962
|
+
with(:test_notifications => [{:summary => 'testing'}]).
|
963
|
+
to_return(:status => 204)
|
628
964
|
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
965
|
+
result = Flapjack::Diner.create_test_notifications_checks('example.com:SSH', 'example2.com:PING', [{:summary => 'testing'}])
|
966
|
+
req.should have_been_requested
|
967
|
+
result.should_not be_nil
|
968
|
+
result.should be_true
|
969
|
+
end
|
970
|
+
|
971
|
+
it "submits a POST request for multiple notifications on a check" do
|
972
|
+
data = [{:summary => 'testing'}, {:summary => 'more testing'}]
|
973
|
+
req = stub_request(:post, "http://#{server}/test_notifications/checks/example.com:SSH").
|
974
|
+
with(:body => {:test_notifications => data}.to_json,
|
975
|
+
:headers => {'Content-Type'=>'application/vnd.api+json'}).
|
634
976
|
to_return(:status => 204)
|
635
977
|
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
978
|
+
result = Flapjack::Diner.create_test_notifications_checks('example.com:SSH', data)
|
979
|
+
req.should have_been_requested
|
980
|
+
result.should_not be_nil
|
981
|
+
result.should be_true
|
982
|
+
end
|
983
|
+
|
984
|
+
it "submits a POST request for multiple notifications on several checks" do
|
985
|
+
data = [{:summary => 'testing'}, {:summary => 'more testing'}]
|
986
|
+
req = stub_request(:post, "http://#{server}/test_notifications/checks/example.com:SSH,example2.com:PING").
|
987
|
+
with(:body => {:test_notifications => data}.to_json,
|
988
|
+
:headers => {'Content-Type'=>'application/vnd.api+json'}).
|
989
|
+
to_return(:status => 204)
|
640
990
|
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
991
|
+
result = Flapjack::Diner.create_test_notifications_checks('example.com:SSH', 'example2.com:PING', data)
|
992
|
+
req.should have_been_requested
|
993
|
+
result.should_not be_nil
|
994
|
+
result.should be_true
|
995
|
+
end
|
645
996
|
|
646
|
-
|
647
|
-
req.should have_been_requested
|
648
|
-
result.should_not be_nil
|
649
|
-
result.should == response_body
|
650
|
-
end
|
997
|
+
end
|
651
998
|
|
652
|
-
|
653
|
-
contact_id = '21'
|
654
|
-
media = 'sms'
|
655
|
-
req = stub_request(:get, "http://#{server}/contacts/#{contact_id}/media/#{media}").to_return(
|
656
|
-
:body => response)
|
999
|
+
end
|
657
1000
|
|
658
|
-
|
659
|
-
req.should have_been_requested
|
660
|
-
result.should_not be_nil
|
661
|
-
result.should == response_body
|
662
|
-
end
|
1001
|
+
context 'update' do
|
663
1002
|
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
1003
|
+
it "submits a PATCH request for unscheduled maintenances on a check" do
|
1004
|
+
req = stub_request(:patch, "http://#{server}/unscheduled_maintenances/checks/example.com:SSH").
|
1005
|
+
with(:body => [{:op => 'replace', :path => '/unscheduled_maintenances/0/end_time', :value => time.iso8601}].to_json,
|
1006
|
+
:headers => {'Content-Type'=>'application/json-patch+json'}).
|
1007
|
+
to_return(:status => 204)
|
669
1008
|
|
670
|
-
|
671
|
-
|
1009
|
+
result = Flapjack::Diner.update_unscheduled_maintenances_checks('example.com:SSH', :end_time => time)
|
1010
|
+
req.should have_been_requested
|
1011
|
+
result.should_not be_nil
|
1012
|
+
result.should be_true
|
1013
|
+
end
|
672
1014
|
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
1015
|
+
it "submits a PATCH request for unscheduled maintenances on several checks" do
|
1016
|
+
req = stub_request(:patch, "http://#{server}/unscheduled_maintenances/checks/example.com:SSH,example2.com:PING").
|
1017
|
+
with(:body => [{:op => 'replace', :path => '/unscheduled_maintenances/0/end_time', :value => time.iso8601}].to_json,
|
1018
|
+
:headers => {'Content-Type'=>'application/json-patch+json'}).
|
1019
|
+
to_return(:status => 204)
|
677
1020
|
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
result = Flapjack::Diner.delete_contact_medium!(contact_id, media)
|
685
|
-
req.should have_been_requested
|
686
|
-
result.should be_true
|
687
|
-
end
|
1021
|
+
result = Flapjack::Diner.update_unscheduled_maintenances_checks('example.com:SSH', 'example2.com:PING', :end_time => time)
|
1022
|
+
req.should have_been_requested
|
1023
|
+
result.should_not be_nil
|
1024
|
+
result.should be_true
|
1025
|
+
end
|
688
1026
|
|
689
|
-
|
690
|
-
contact_id = '21'
|
691
|
-
req = stub_request(:get, "http://#{server}/contacts/#{contact_id}/timezone").to_return(
|
692
|
-
:body => response)
|
1027
|
+
end
|
693
1028
|
|
694
|
-
|
695
|
-
req.should have_been_requested
|
696
|
-
result.should_not be_nil
|
697
|
-
result.should == response_body
|
698
|
-
end
|
1029
|
+
context 'delete' do
|
699
1030
|
|
700
|
-
|
701
|
-
|
702
|
-
|
1031
|
+
it "submits a DELETE request for scheduled maintenances on a check" do
|
1032
|
+
req = stub_request(:delete, "http://#{server}/scheduled_maintenances/checks/example.com:SSH").
|
1033
|
+
with(:query => {:start_time => time.iso8601}).
|
1034
|
+
to_return(:status => 204)
|
703
1035
|
|
704
|
-
|
705
|
-
|
1036
|
+
result = Flapjack::Diner.delete_scheduled_maintenances_checks('example.com:SSH', :start_time => time.iso8601)
|
1037
|
+
req.should have_been_requested
|
1038
|
+
result.should_not be_nil
|
1039
|
+
result.should be_true
|
1040
|
+
end
|
706
1041
|
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
1042
|
+
it "submits a DELETE request for scheduled maintenances on several checks" do
|
1043
|
+
req = stub_request(:delete, "http://#{server}/scheduled_maintenances/checks/example.com:SSH,example2.com:PING").
|
1044
|
+
with(:query => {:start_time => time.iso8601}).
|
1045
|
+
to_return(:status => 204)
|
711
1046
|
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
1047
|
+
result = Flapjack::Diner.delete_scheduled_maintenances_checks('example.com:SSH', 'example2.com:PING', :start_time => time.iso8601)
|
1048
|
+
req.should have_been_requested
|
1049
|
+
result.should_not be_nil
|
1050
|
+
result.should be_true
|
1051
|
+
end
|
716
1052
|
|
717
|
-
|
718
|
-
req.should have_been_requested
|
719
|
-
result.should be_true
|
1053
|
+
end
|
720
1054
|
end
|
721
1055
|
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
1056
|
+
context 'reports' do
|
1057
|
+
context 'read' do
|
1058
|
+
|
1059
|
+
['status', 'scheduled_maintenance', 'unscheduled_maintenance', 'downtime', 'outage'].each do |report_type|
|
1060
|
+
|
1061
|
+
it "submits a GET request for a #{report_type} report on all entities" do
|
1062
|
+
req = stub_request(:get, "http://#{server}/#{report_type}_report/entities").
|
1063
|
+
to_return(:body => response_with_data("#{report_type}_reports"))
|
1064
|
+
|
1065
|
+
result = Flapjack::Diner.send("#{report_type}_report_entities".to_sym)
|
1066
|
+
req.should have_been_requested
|
1067
|
+
result.should_not be_nil
|
1068
|
+
end
|
1069
|
+
|
1070
|
+
it "submits a GET request for a #{report_type} report on one entity" do
|
1071
|
+
req = stub_request(:get, "http://#{server}/#{report_type}_report/entities/72").
|
1072
|
+
to_return(:body => response_with_data("#{report_type}_reports"))
|
1073
|
+
|
1074
|
+
result = Flapjack::Diner.send("#{report_type}_report_entities".to_sym, '72')
|
1075
|
+
req.should have_been_requested
|
1076
|
+
result.should_not be_nil
|
1077
|
+
end
|
1078
|
+
|
1079
|
+
it "submits a GET request for a #{report_type} report on several entities" do
|
1080
|
+
req = stub_request(:get, "http://#{server}/#{report_type}_report/entities/72,150").
|
1081
|
+
to_return(:body => response_with_data("#{report_type}_reports"))
|
1082
|
+
|
1083
|
+
result = Flapjack::Diner.send("#{report_type}_report_entities".to_sym, '72', '150')
|
1084
|
+
req.should have_been_requested
|
1085
|
+
result.should_not be_nil
|
1086
|
+
end
|
1087
|
+
|
1088
|
+
it "submits a GET request for a #{report_type} report on all checks" do
|
1089
|
+
req = stub_request(:get, "http://#{server}/#{report_type}_report/checks").
|
1090
|
+
to_return(:body => response_with_data("#{report_type}_reports"))
|
1091
|
+
|
1092
|
+
result = Flapjack::Diner.send("#{report_type}_report_checks".to_sym)
|
1093
|
+
req.should have_been_requested
|
1094
|
+
result.should_not be_nil
|
1095
|
+
end
|
1096
|
+
|
1097
|
+
it "submits a GET request for a #{report_type} report on one check" do
|
1098
|
+
req = stub_request(:get, "http://#{server}/#{report_type}_report/checks/example.com:SSH").
|
1099
|
+
to_return(:body => response_with_data("#{report_type}_reports"))
|
1100
|
+
|
1101
|
+
result = Flapjack::Diner.send("#{report_type}_report_checks".to_sym,
|
1102
|
+
'example.com:SSH')
|
1103
|
+
req.should have_been_requested
|
1104
|
+
result.should_not be_nil
|
1105
|
+
end
|
1106
|
+
|
1107
|
+
it "submits a GET request for a #{report_type} report on several checks" do
|
1108
|
+
req = stub_request(:get, "http://#{server}/#{report_type}_report/checks/example.com:SSH,example2.com:PING").
|
1109
|
+
to_return(:body => response_with_data("#{report_type}_reports"))
|
1110
|
+
|
1111
|
+
result = Flapjack::Diner.send("#{report_type}_report_checks".to_sym,
|
1112
|
+
'example.com:SSH', 'example2.com:PING')
|
1113
|
+
req.should have_been_requested
|
1114
|
+
result.should_not be_nil
|
1115
|
+
end
|
1116
|
+
|
1117
|
+
end
|
1118
|
+
|
1119
|
+
['scheduled_maintenance', 'unscheduled_maintenance', 'downtime', 'outage'].each do |report_type|
|
1120
|
+
|
1121
|
+
let(:start_time) { Time.now }
|
1122
|
+
let(:end_time) { start_time + (60 * 60 * 12) }
|
1123
|
+
|
1124
|
+
it "submits a time-limited GET request for a #{report_type} report on all entities" do
|
1125
|
+
req = stub_request(:get, "http://#{server}/#{report_type}_report/entities").
|
1126
|
+
with(:query => {:start_time => start_time.iso8601, :end_time => end_time.iso8601}).
|
1127
|
+
to_return(:body => response_with_data("#{report_type}_reports"))
|
1128
|
+
|
1129
|
+
result = Flapjack::Diner.send("#{report_type}_report_entities".to_sym,
|
1130
|
+
:start_time => start_time, :end_time => end_time)
|
1131
|
+
req.should have_been_requested
|
1132
|
+
result.should_not be_nil
|
1133
|
+
end
|
1134
|
+
|
1135
|
+
it "submits a time-limited GET request for a #{report_type} report on one entity" do
|
1136
|
+
req = stub_request(:get, "http://#{server}/#{report_type}_report/entities/72").
|
1137
|
+
with(:query => {:start_time => start_time.iso8601, :end_time => end_time.iso8601}).
|
1138
|
+
to_return(:body => response_with_data("#{report_type}_reports"))
|
1139
|
+
|
1140
|
+
result = Flapjack::Diner.send("#{report_type}_report_entities".to_sym,
|
1141
|
+
'72', :start_time => start_time, :end_time => end_time)
|
1142
|
+
req.should have_been_requested
|
1143
|
+
result.should_not be_nil
|
1144
|
+
end
|
1145
|
+
|
1146
|
+
it "submits a time-limited GET request for a #{report_type} report on several entities" do
|
1147
|
+
req = stub_request(:get, "http://#{server}/#{report_type}_report/entities/72,150").
|
1148
|
+
with(:query => {:start_time => start_time.iso8601, :end_time => end_time.iso8601}).
|
1149
|
+
to_return(:body => response_with_data("#{report_type}_reports"))
|
1150
|
+
|
1151
|
+
result = Flapjack::Diner.send("#{report_type}_report_entities".to_sym,
|
1152
|
+
'72', '150', :start_time => start_time, :end_time => end_time)
|
1153
|
+
req.should have_been_requested
|
1154
|
+
result.should_not be_nil
|
1155
|
+
end
|
1156
|
+
|
1157
|
+
it "submits a time-limited GET request for a #{report_type} report on all checks" do
|
1158
|
+
req = stub_request(:get, "http://#{server}/#{report_type}_report/checks").
|
1159
|
+
with(:query => {:start_time => start_time.iso8601, :end_time => end_time.iso8601}).
|
1160
|
+
to_return(:body => response_with_data("#{report_type}_reports"))
|
1161
|
+
|
1162
|
+
result = Flapjack::Diner.send("#{report_type}_report_checks".to_sym,
|
1163
|
+
:start_time => start_time, :end_time => end_time)
|
1164
|
+
req.should have_been_requested
|
1165
|
+
result.should_not be_nil
|
1166
|
+
end
|
1167
|
+
|
1168
|
+
it "submits a time-limited GET request for a #{report_type} report on one check" do
|
1169
|
+
req = stub_request(:get, "http://#{server}/#{report_type}_report/checks/example.com:SSH").
|
1170
|
+
with(:query => {:start_time => start_time.iso8601, :end_time => end_time.iso8601}).
|
1171
|
+
to_return(:body => response_with_data("#{report_type}_reports"))
|
1172
|
+
|
1173
|
+
result = Flapjack::Diner.send("#{report_type}_report_checks".to_sym,
|
1174
|
+
'example.com:SSH', :start_time => start_time, :end_time => end_time)
|
1175
|
+
req.should have_been_requested
|
1176
|
+
result.should_not be_nil
|
1177
|
+
end
|
1178
|
+
|
1179
|
+
it "submits a time-limited GET request for a #{report_type} report on several checks" do
|
1180
|
+
req = stub_request(:get, "http://#{server}/#{report_type}_report/checks/example.com:SSH,example2.com:PING").
|
1181
|
+
with(:query => {:start_time => start_time.iso8601, :end_time => end_time.iso8601}).
|
1182
|
+
to_return(:body => response_with_data("#{report_type}_reports"))
|
1183
|
+
|
1184
|
+
result = Flapjack::Diner.send("#{report_type}_report_checks".to_sym,
|
1185
|
+
'example.com:SSH', 'example2.com:PING',
|
1186
|
+
:start_time => start_time, :end_time => end_time)
|
1187
|
+
req.should have_been_requested
|
1188
|
+
result.should_not be_nil
|
1189
|
+
end
|
1190
|
+
|
1191
|
+
end
|
726
1192
|
|
727
|
-
|
728
|
-
last_error = Flapjack::Diner.last_error
|
729
|
-
req.should have_been_requested
|
730
|
-
result.should be_nil
|
731
|
-
last_error.should_not be_nil
|
1193
|
+
end
|
732
1194
|
end
|
733
1195
|
|
734
1196
|
context "logging" do
|
@@ -740,8 +1202,9 @@ describe Flapjack::Diner do
|
|
740
1202
|
end
|
741
1203
|
|
742
1204
|
it "logs a GET request without a path" do
|
743
|
-
|
744
|
-
|
1205
|
+
response = response_with_data('entities')
|
1206
|
+
req = stub_request(:get, "http://#{server}/entities").
|
1207
|
+
to_return(:body => response)
|
745
1208
|
|
746
1209
|
logger.should_receive(:info).with("GET http://#{server}/entities")
|
747
1210
|
logger.should_receive(:info).with(" Response Code: 200")
|
@@ -750,63 +1213,29 @@ describe Flapjack::Diner do
|
|
750
1213
|
result = Flapjack::Diner.entities
|
751
1214
|
req.should have_been_requested
|
752
1215
|
result.should_not be_nil
|
753
|
-
result.should == response_body
|
754
|
-
end
|
755
|
-
|
756
|
-
it "logs a GET request with a path" do
|
757
|
-
req = stub_request(:get, "http://#{server}/checks/#{entity}").to_return(
|
758
|
-
:body => response)
|
759
|
-
|
760
|
-
logger.should_receive(:info).with("GET http://#{server}/checks/#{entity}")
|
761
|
-
logger.should_receive(:info).with(" Response Code: 200")
|
762
|
-
logger.should_receive(:info).with(" Response Body: #{response}")
|
763
|
-
|
764
|
-
result = Flapjack::Diner.checks(entity)
|
765
|
-
req.should have_been_requested
|
766
|
-
result.should_not be_nil
|
767
|
-
result.should == response_body
|
768
1216
|
end
|
769
1217
|
|
770
1218
|
it "logs a POST request" do
|
771
|
-
req = stub_request(:post, "http://#{server}/
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
logger.should_receive(:info).with("
|
776
|
-
" Params: {:summary=>\"dealing with it\", :check=>{\"ex-abcd-data-17.example.com\"=>\"ping\"}}")
|
777
|
-
logger.should_receive(:info).with(" Response Code: 204")
|
1219
|
+
req = stub_request(:post, "http://#{server}/test_notifications/entities/27").
|
1220
|
+
to_return(:status => 200)
|
1221
|
+
logger.should_receive(:info).with("POST http://#{server}/test_notifications/entities/27\n" +
|
1222
|
+
" Params: {:test_notifications=>[{:summary=>\"dealing with it\"}]}")
|
1223
|
+
logger.should_receive(:info).with(" Response Code: 200")
|
778
1224
|
|
779
|
-
result = Flapjack::Diner.
|
1225
|
+
result = Flapjack::Diner.create_test_notifications_entities(27, [{:summary => 'dealing with it'}])
|
780
1226
|
req.should have_been_requested
|
781
1227
|
result.should be_true
|
782
1228
|
end
|
783
1229
|
|
784
|
-
it "logs a JSON put request" do
|
785
|
-
contact_id = '21'
|
786
|
-
timezone_data = {:timezone => "Australia/Perth"}
|
787
|
-
|
788
|
-
req = stub_request(:put, "http://#{server}/contacts/#{contact_id}/timezone").with(
|
789
|
-
:body => timezone_data).to_return(:body => timezone_data.to_json, :status => [200, 'OK'])
|
790
|
-
|
791
|
-
logger.should_receive(:info).
|
792
|
-
with("PUT http://#{server}/contacts/#{contact_id}/timezone\n Params: #{timezone_data.inspect}")
|
793
|
-
logger.should_receive(:info).with(" Response Code: 200 OK")
|
794
|
-
logger.should_receive(:info).with(" Response Body: #{timezone_data.to_json}")
|
795
|
-
|
796
|
-
result = Flapjack::Diner.update_contact_timezone!(contact_id, timezone_data[:timezone])
|
797
|
-
req.should have_been_requested
|
798
|
-
result.should == {'timezone' => "Australia/Perth"}
|
799
|
-
end
|
800
|
-
|
801
1230
|
it "logs a DELETE request" do
|
802
|
-
|
803
|
-
|
804
|
-
:status => 204)
|
1231
|
+
req = stub_request(:delete, "http://#{server}/scheduled_maintenances/checks/example.com:SSH").
|
1232
|
+
with(:query => {:start_time => time.iso8601}).
|
1233
|
+
to_return(:status => 204)
|
805
1234
|
|
806
|
-
logger.should_receive(:info).with("DELETE http://#{server}/
|
1235
|
+
logger.should_receive(:info).with("DELETE http://#{server}/scheduled_maintenances/checks/#{CGI.escape('example.com:SSH')}?start_time=#{CGI.escape(time.iso8601)}")
|
807
1236
|
logger.should_receive(:info).with(" Response Code: 204")
|
808
1237
|
|
809
|
-
result = Flapjack::Diner.
|
1238
|
+
result = Flapjack::Diner.delete_scheduled_maintenances_checks('example.com:SSH', :start_time => time)
|
810
1239
|
req.should have_been_requested
|
811
1240
|
result.should be_true
|
812
1241
|
end
|
@@ -838,34 +1267,7 @@ describe Flapjack::Diner do
|
|
838
1267
|
req = stub_request(:get, /http:\/\/#{server}\/*/)
|
839
1268
|
|
840
1269
|
expect {
|
841
|
-
Flapjack::Diner.
|
842
|
-
}.to raise_error
|
843
|
-
req.should_not have_been_requested
|
844
|
-
end
|
845
|
-
|
846
|
-
it "raises an exception if bulk queries don't have entity or check arguments" do
|
847
|
-
req = stub_request(:get, /http:\/\/#{server}\/*/)
|
848
|
-
|
849
|
-
expect {
|
850
|
-
Flapjack::Diner.bulk_downtime({})
|
851
|
-
}.to raise_error
|
852
|
-
req.should_not have_been_requested
|
853
|
-
end
|
854
|
-
|
855
|
-
it "raises an exception if bulk queries have invalid entity arguments" do
|
856
|
-
req = stub_request(:get, /http:\/\/#{server}\/*/)
|
857
|
-
|
858
|
-
expect {
|
859
|
-
Flapjack::Diner.bulk_scheduled_maintenances(:entity => 23)
|
860
|
-
}.to raise_error
|
861
|
-
req.should_not have_been_requested
|
862
|
-
end
|
863
|
-
|
864
|
-
it "raises an exception if bulk queries have invalid check arguments" do
|
865
|
-
req = stub_request(:get, /http:\/\/#{server}\/*/)
|
866
|
-
|
867
|
-
expect {
|
868
|
-
Flapjack::Diner.bulk_outages(:check => {'abc.com' => ['ping', 5]})
|
1270
|
+
Flapjack::Diner.delete_scheduled_maintenances_checks('example.com:SSH', :start_time => nil)
|
869
1271
|
}.to raise_error
|
870
1272
|
req.should_not have_been_requested
|
871
1273
|
end
|
@@ -879,7 +1281,8 @@ describe Flapjack::Diner do
|
|
879
1281
|
req = stub_request(:get, /http:\/\/#{server}\/*/)
|
880
1282
|
|
881
1283
|
expect {
|
882
|
-
Flapjack::Diner.
|
1284
|
+
Flapjack::Diner.downtime_report_checks('example.com:SSH',
|
1285
|
+
:start_time => start_time, :end_time => end_time)
|
883
1286
|
}.to raise_error
|
884
1287
|
req.should_not have_been_requested
|
885
1288
|
end
|