flapjack 0.8.10 → 0.8.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/Gemfile +1 -1
- data/bin/flapjack +10 -1
- data/bin/flapjack-nagios-receiver +1 -2
- data/bin/simulate-failed-check +12 -4
- data/etc/flapjack_config.yaml.example +2 -1
- data/flapjack.gemspec +1 -0
- data/lib/flapjack/data/contact.rb +46 -26
- data/lib/flapjack/data/entity.rb +28 -0
- data/lib/flapjack/data/entity_check.rb +52 -11
- data/lib/flapjack/data/event.rb +9 -3
- data/lib/flapjack/data/notification_rule.rb +8 -0
- data/lib/flapjack/gateways/api.rb +0 -1
- data/lib/flapjack/gateways/api/entity_check_presenter.rb +2 -1
- data/lib/flapjack/gateways/email.rb +1 -2
- data/lib/flapjack/gateways/jabber.rb +3 -3
- data/lib/flapjack/gateways/jsonapi.rb +186 -38
- data/lib/flapjack/gateways/jsonapi/check_methods.rb +120 -0
- data/lib/flapjack/gateways/jsonapi/{entity_check_presenter.rb → check_presenter.rb} +7 -6
- data/lib/flapjack/gateways/jsonapi/contact_methods.rb +61 -352
- data/lib/flapjack/gateways/jsonapi/entity_methods.rb +117 -248
- data/lib/flapjack/gateways/jsonapi/medium_methods.rb +179 -0
- data/lib/flapjack/gateways/jsonapi/notification_rule_methods.rb +124 -0
- data/lib/flapjack/gateways/jsonapi/pagerduty_credential_methods.rb +128 -0
- data/lib/flapjack/gateways/jsonapi/rack/json_params_parser.rb +4 -5
- data/lib/flapjack/gateways/jsonapi/report_methods.rb +143 -0
- data/lib/flapjack/gateways/web.rb +1 -0
- data/lib/flapjack/gateways/web/public/js/backbone.jsonapi.js +165 -101
- data/lib/flapjack/gateways/web/public/js/contacts.js +34 -46
- data/lib/flapjack/gateways/web/public/js/select2.js +232 -90
- data/lib/flapjack/gateways/web/public/js/select2.min.js +4 -4
- data/lib/flapjack/gateways/web/views/check.html.erb +11 -2
- data/lib/flapjack/processor.rb +6 -6
- data/lib/flapjack/version.rb +1 -1
- data/spec/lib/flapjack/data/entity_check_spec.rb +1 -1
- data/spec/lib/flapjack/data/event_spec.rb +10 -9
- data/spec/lib/flapjack/gateways/api/entity_methods_spec.rb +25 -25
- data/spec/lib/flapjack/gateways/api_spec.rb +23 -1
- data/spec/lib/flapjack/gateways/email_spec.rb +40 -2
- data/spec/lib/flapjack/gateways/jabber_spec.rb +1 -1
- data/spec/lib/flapjack/gateways/jsonapi/check_methods_spec.rb +134 -0
- data/spec/lib/flapjack/gateways/jsonapi/{entity_check_presenter_spec.rb → check_presenter_spec.rb} +17 -17
- data/spec/lib/flapjack/gateways/jsonapi/contact_methods_spec.rb +27 -232
- data/spec/lib/flapjack/gateways/jsonapi/entity_methods_spec.rb +217 -687
- data/spec/lib/flapjack/gateways/jsonapi/medium_methods_spec.rb +232 -0
- data/spec/lib/flapjack/gateways/jsonapi/notification_rule_methods_spec.rb +131 -0
- data/spec/lib/flapjack/gateways/jsonapi/pagerduty_credential_methods_spec.rb +113 -0
- data/spec/lib/flapjack/gateways/jsonapi/report_methods_spec.rb +546 -0
- data/spec/lib/flapjack/gateways/jsonapi_spec.rb +10 -1
- data/spec/lib/flapjack/gateways/web_spec.rb +1 -0
- data/spec/support/jsonapi_helper.rb +62 -0
- metadata +36 -8
- data/lib/flapjack/gateways/jsonapi/entity_presenter.rb +0 -75
- data/spec/lib/flapjack/gateways/jsonapi/entity_presenter_spec.rb +0 -108
data/spec/lib/flapjack/gateways/jsonapi/{entity_check_presenter_spec.rb → check_presenter_spec.rb}
RENAMED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'flapjack/gateways/jsonapi/
|
2
|
+
require 'flapjack/gateways/jsonapi/check_presenter'
|
3
3
|
|
4
|
-
describe 'Flapjack::Gateways::JSONAPI::
|
4
|
+
describe 'Flapjack::Gateways::JSONAPI::CheckPresenter' do
|
5
5
|
|
6
6
|
let(:entity_check) { double(Flapjack::Data::EntityCheck) }
|
7
7
|
|
@@ -44,8 +44,8 @@ describe 'Flapjack::Gateways::JSONAPI::EntityCheckPresenter' do
|
|
44
44
|
expect(entity_check).to receive(:historical_state_before).
|
45
45
|
with(time - (4 * 60 * 60)).and_return(nil)
|
46
46
|
|
47
|
-
ecp = Flapjack::Gateways::JSONAPI::
|
48
|
-
outages = ecp.
|
47
|
+
ecp = Flapjack::Gateways::JSONAPI::CheckPresenter.new(entity_check)
|
48
|
+
outages = ecp.outage(time - (5 * 60 * 60), time - (2 * 60 * 60))
|
49
49
|
expect(outages).not_to be_nil
|
50
50
|
expect(outages).to be_an(Array)
|
51
51
|
expect(outages.size).to eq(4)
|
@@ -60,8 +60,8 @@ describe 'Flapjack::Gateways::JSONAPI::EntityCheckPresenter' do
|
|
60
60
|
expect(entity_check).to receive(:historical_state_before).
|
61
61
|
with(time - (4 * 60 * 60)).and_return(nil)
|
62
62
|
|
63
|
-
ecp = Flapjack::Gateways::JSONAPI::
|
64
|
-
outages = ecp.
|
63
|
+
ecp = Flapjack::Gateways::JSONAPI::CheckPresenter.new(entity_check)
|
64
|
+
outages = ecp.outage(nil, nil)
|
65
65
|
expect(outages).not_to be_nil
|
66
66
|
expect(outages).to be_an(Array)
|
67
67
|
expect(outages.size).to eq(4)
|
@@ -79,8 +79,8 @@ describe 'Flapjack::Gateways::JSONAPI::EntityCheckPresenter' do
|
|
79
79
|
expect(entity_check).to receive(:historical_state_before).
|
80
80
|
with(time - (4 * 60 * 60)).and_return(nil)
|
81
81
|
|
82
|
-
ecp = Flapjack::Gateways::JSONAPI::
|
83
|
-
outages = ecp.
|
82
|
+
ecp = Flapjack::Gateways::JSONAPI::CheckPresenter.new(entity_check)
|
83
|
+
outages = ecp.outage(nil, nil)
|
84
84
|
expect(outages).not_to be_nil
|
85
85
|
expect(outages).to be_an(Array)
|
86
86
|
expect(outages.size).to eq(3)
|
@@ -92,8 +92,8 @@ describe 'Flapjack::Gateways::JSONAPI::EntityCheckPresenter' do
|
|
92
92
|
expect(entity_check).to receive(:historical_state_before).
|
93
93
|
with(time - (4 * 60 * 60)).and_return(nil)
|
94
94
|
|
95
|
-
ecp = Flapjack::Gateways::JSONAPI::
|
96
|
-
outages = ecp.
|
95
|
+
ecp = Flapjack::Gateways::JSONAPI::CheckPresenter.new(entity_check)
|
96
|
+
outages = ecp.outage(nil, nil)
|
97
97
|
expect(outages).not_to be_nil
|
98
98
|
expect(outages).to be_an(Array)
|
99
99
|
expect(outages.size).to eq(1)
|
@@ -106,8 +106,8 @@ describe 'Flapjack::Gateways::JSONAPI::EntityCheckPresenter' do
|
|
106
106
|
expect(entity_check).to receive(:maintenances).
|
107
107
|
with(nil, time - (12 * 60 * 60), :scheduled => false).and_return([])
|
108
108
|
|
109
|
-
ecp = Flapjack::Gateways::JSONAPI::
|
110
|
-
unsched_maint = ecp.
|
109
|
+
ecp = Flapjack::Gateways::JSONAPI::CheckPresenter.new(entity_check)
|
110
|
+
unsched_maint = ecp.unscheduled_maintenance(time - (12 * 60 * 60), time)
|
111
111
|
|
112
112
|
expect(unsched_maint).to be_an(Array)
|
113
113
|
expect(unsched_maint.size).to eq(4)
|
@@ -122,8 +122,8 @@ describe 'Flapjack::Gateways::JSONAPI::EntityCheckPresenter' do
|
|
122
122
|
expect(entity_check).to receive(:maintenances).
|
123
123
|
with(nil, time - (12 * 60 * 60), :scheduled => true).and_return([])
|
124
124
|
|
125
|
-
ecp = Flapjack::Gateways::JSONAPI::
|
126
|
-
sched_maint = ecp.
|
125
|
+
ecp = Flapjack::Gateways::JSONAPI::CheckPresenter.new(entity_check)
|
126
|
+
sched_maint = ecp.scheduled_maintenance(time - (12 * 60 * 60), time)
|
127
127
|
|
128
128
|
expect(sched_maint).to be_an(Array)
|
129
129
|
expect(sched_maint.size).to eq(4)
|
@@ -144,7 +144,7 @@ describe 'Flapjack::Gateways::JSONAPI::EntityCheckPresenter' do
|
|
144
144
|
expect(entity_check).to receive(:maintenances).
|
145
145
|
with(nil, time - (12 * 60 * 60), :scheduled => true).and_return([])
|
146
146
|
|
147
|
-
ecp = Flapjack::Gateways::JSONAPI::
|
147
|
+
ecp = Flapjack::Gateways::JSONAPI::CheckPresenter.new(entity_check)
|
148
148
|
downtimes = ecp.downtime(time - (12 * 60 * 60), time)
|
149
149
|
|
150
150
|
# 22 minutes, 3 + 8 + 11
|
@@ -169,7 +169,7 @@ describe 'Flapjack::Gateways::JSONAPI::EntityCheckPresenter' do
|
|
169
169
|
expect(entity_check).to receive(:maintenances).
|
170
170
|
with(nil, nil, :scheduled => true).and_return(maintenances)
|
171
171
|
|
172
|
-
ecp = Flapjack::Gateways::JSONAPI::
|
172
|
+
ecp = Flapjack::Gateways::JSONAPI::CheckPresenter.new(entity_check)
|
173
173
|
downtimes = ecp.downtime(nil, nil)
|
174
174
|
|
175
175
|
# 22 minutes, 3 + 8 + 11
|
@@ -196,7 +196,7 @@ describe 'Flapjack::Gateways::JSONAPI::EntityCheckPresenter' do
|
|
196
196
|
expect(entity_check).to receive(:maintenances).
|
197
197
|
with(nil, nil, :scheduled => true).and_return([])
|
198
198
|
|
199
|
-
ecp = Flapjack::Gateways::JSONAPI::
|
199
|
+
ecp = Flapjack::Gateways::JSONAPI::CheckPresenter.new(entity_check)
|
200
200
|
downtimes = ecp.downtime(nil, nil)
|
201
201
|
|
202
202
|
expect(downtimes).to be_a(Hash)
|
@@ -3,11 +3,7 @@ require 'flapjack/gateways/jsonapi'
|
|
3
3
|
|
4
4
|
describe 'Flapjack::Gateways::JSONAPI::ContactMethods', :sinatra => true, :logger => true do
|
5
5
|
|
6
|
-
|
7
|
-
Flapjack::Gateways::JSONAPI
|
8
|
-
end
|
9
|
-
|
10
|
-
JSON_REQUEST_MIME = 'application/vnd.api+json'
|
6
|
+
include_context "jsonapi"
|
11
7
|
|
12
8
|
let(:contact) { double(Flapjack::Data::Contact, :id => '21') }
|
13
9
|
let(:contact_core) {
|
@@ -19,90 +15,33 @@ describe 'Flapjack::Gateways::JSONAPI::ContactMethods', :sinatra => true, :logge
|
|
19
15
|
}
|
20
16
|
}
|
21
17
|
|
22
|
-
let(:media) {
|
23
|
-
{'email' => 'ada@example.com',
|
24
|
-
'sms' => '04123456789'
|
25
|
-
}
|
26
|
-
}
|
27
|
-
|
28
|
-
let(:media_intervals) {
|
29
|
-
{'email' => 500,
|
30
|
-
'sms' => 300
|
31
|
-
}
|
32
|
-
}
|
33
|
-
|
34
|
-
let(:media_rollup_thresholds) {
|
35
|
-
{'email' => 5}
|
36
|
-
}
|
37
|
-
|
38
|
-
let(:redis) { double(::Redis) }
|
39
|
-
|
40
|
-
let(:notification_rule) {
|
41
|
-
double(Flapjack::Data::NotificationRule, :id => '1', :contact_id => '21')
|
42
|
-
}
|
43
|
-
|
44
|
-
let(:notification_rule_data) {
|
45
|
-
{"contact_id" => "21",
|
46
|
-
"tags" => ["database","physical"],
|
47
|
-
"regex_tags" => ["^data.*$","^(physical|bare_metal)$"],
|
48
|
-
"regex_entities" => ["^foo-\S{3}-\d{2}.example.com$"],
|
49
|
-
"time_restrictions" => nil,
|
50
|
-
"unknown_media" => ["jabber"],
|
51
|
-
"warning_media" => ["email"],
|
52
|
-
"critical_media" => ["sms", "email"],
|
53
|
-
"unknown_blackhole" => false,
|
54
|
-
"warning_blackhole" => false,
|
55
|
-
"critical_blackhole" => false
|
56
|
-
}
|
57
|
-
}
|
58
|
-
|
59
18
|
let(:semaphore) {
|
60
19
|
double(Flapjack::Data::Semaphore, :resource => 'folly',
|
61
20
|
:key => 'semaphores:folly', :expiry => 30, :token => 'spatulas-R-us')
|
62
21
|
}
|
63
22
|
|
64
|
-
before(:all) do
|
65
|
-
Flapjack::Gateways::JSONAPI.class_eval {
|
66
|
-
set :raise_errors, true
|
67
|
-
}
|
68
|
-
end
|
69
|
-
|
70
|
-
before(:each) do
|
71
|
-
expect(Flapjack::RedisPool).to receive(:new).and_return(redis)
|
72
|
-
Flapjack::Gateways::JSONAPI.instance_variable_set('@config', {})
|
73
|
-
Flapjack::Gateways::JSONAPI.instance_variable_set('@logger', @logger)
|
74
|
-
Flapjack::Gateways::JSONAPI.start
|
75
|
-
end
|
76
|
-
|
77
23
|
it "returns all the contacts" do
|
78
|
-
expect(Flapjack::Data::Contact).to receive(:
|
79
|
-
with([contact.id], :redis => redis).and_return(
|
80
|
-
expect(contact).to receive(:media).and_return({})
|
81
|
-
expect(contact).to receive(:linked_entity_ids=).with(nil)
|
82
|
-
expect(contact).to receive(:linked_media_ids=).with(nil)
|
24
|
+
expect(Flapjack::Data::Contact).to receive(:entity_ids_for).
|
25
|
+
with([contact.id], :redis => redis).and_return({})
|
83
26
|
expect(contact).to receive(:to_jsonapi).and_return(contact_core.to_json)
|
84
27
|
expect(Flapjack::Data::Contact).to receive(:all).with(:redis => redis).
|
85
28
|
and_return([contact])
|
86
29
|
|
87
30
|
aget '/contacts'
|
88
31
|
expect(last_response).to be_ok
|
89
|
-
expect(last_response.body).to eq({:contacts => [contact_core]
|
32
|
+
expect(last_response.body).to eq({:contacts => [contact_core]}.to_json)
|
90
33
|
end
|
91
34
|
|
92
35
|
it "returns the core information of a specified contact" do
|
93
|
-
|
94
|
-
|
95
|
-
with([contact.id], :redis => redis).and_return([[], {}])
|
96
|
-
expect(contact).to receive(:media).and_return({})
|
97
|
-
expect(contact).to receive(:linked_entity_ids=).with(nil)
|
98
|
-
expect(contact).to receive(:linked_media_ids=).with(nil)
|
36
|
+
expect(Flapjack::Data::Contact).to receive(:entity_ids_for).
|
37
|
+
with([contact.id], :redis => redis).and_return({})
|
99
38
|
expect(contact).to receive(:to_jsonapi).and_return(contact_core.to_json)
|
100
39
|
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
101
40
|
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
102
41
|
|
103
42
|
aget "/contacts/#{contact.id}"
|
104
43
|
expect(last_response).to be_ok
|
105
|
-
expect(last_response.body).to eq({:contacts => [contact_core]
|
44
|
+
expect(last_response.body).to eq({:contacts => [contact_core]}.to_json)
|
106
45
|
end
|
107
46
|
|
108
47
|
it "does not return information for a contact that does not exist" do
|
@@ -134,186 +73,42 @@ describe 'Flapjack::Gateways::JSONAPI::ContactMethods', :sinatra => true, :logge
|
|
134
73
|
with(contact_data, {:redis => redis}).and_return(contact)
|
135
74
|
expect(semaphore).to receive(:release).and_return(true)
|
136
75
|
|
137
|
-
apost "/contacts", {
|
138
|
-
|
139
|
-
|
140
|
-
expect(last_response.status).to eq(200)
|
76
|
+
apost "/contacts", {:contacts => [contact_data]}.to_json, jsonapi_post_env
|
77
|
+
expect(last_response.status).to eq(201)
|
141
78
|
expect(last_response.body).to eq(["0362"].to_json)
|
142
79
|
end
|
143
80
|
|
144
81
|
it "updates a contact" do
|
82
|
+
expect(Flapjack::Data::Semaphore).to receive(:new).
|
83
|
+
with("contact_mass_update", {:redis => redis, :expiry => 30}).and_return(semaphore)
|
145
84
|
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
146
|
-
with(
|
147
|
-
expect(contact).to receive(:update)
|
148
|
-
expect(contact).to receive(:to_jsonapi).and_return('{"sausage": "good"}')
|
149
|
-
|
150
|
-
aput "/contacts/21", {:contacts => [{'sausage' => 'good'}]}.to_json,
|
151
|
-
{'CONTENT_TYPE' => JSON_REQUEST_MIME}
|
152
|
-
expect(last_response.status).to eq(200)
|
153
|
-
end
|
154
|
-
|
155
|
-
it "deletes a contact" do
|
156
|
-
end
|
157
|
-
|
158
|
-
it "does not create a contact if the data is improperly formatted" do
|
159
|
-
expect(Flapjack::Data::Contact).not_to receive(:add)
|
160
|
-
|
161
|
-
apost "/contacts", {'sausage' => 'good'}.to_json,
|
162
|
-
{'CONTENT_TYPE' => JSON_REQUEST_MIME}
|
163
|
-
expect(last_response.status).to eq(422)
|
164
|
-
end
|
165
|
-
|
166
|
-
it "does not update a contact if id exists in sent entity" do
|
167
|
-
contact_data = {'id' => '21'}
|
168
|
-
expect(Flapjack::Data::Contact).not_to receive(:find_by_id)
|
169
|
-
expect(Flapjack::Data::Contact).not_to receive(:update)
|
170
|
-
|
171
|
-
aput "/contacts/21", contact_data.to_json,
|
172
|
-
{'CONTENT_TYPE' => JSON_REQUEST_MIME}
|
173
|
-
expect(last_response.status).to eq(422)
|
174
|
-
end
|
175
|
-
|
176
|
-
it "returns a specified notification rule" do
|
177
|
-
expect(notification_rule).to receive(:to_json).and_return('"rule_1"')
|
178
|
-
expect(Flapjack::Data::NotificationRule).to receive(:find_by_id).
|
179
|
-
with(notification_rule.id, {:redis => redis, :logger => @logger}).and_return(notification_rule)
|
180
|
-
|
181
|
-
aget "/notification_rules/#{notification_rule.id}"
|
182
|
-
expect(last_response).to be_ok
|
183
|
-
expect(last_response.body).to eq('{"notification_rules":["rule_1"]}')
|
184
|
-
end
|
185
|
-
|
186
|
-
it "does not return a notification rule that does not exist" do
|
187
|
-
expect(Flapjack::Data::NotificationRule).to receive(:find_by_id).
|
188
|
-
with(notification_rule.id, {:redis => redis, :logger => @logger}).and_return(nil)
|
189
|
-
|
190
|
-
aget "/notification_rules/#{notification_rule.id}"
|
191
|
-
expect(last_response.status).to eq(404)
|
192
|
-
end
|
193
|
-
|
194
|
-
# POST /notification_rules
|
195
|
-
it "creates a new notification rule" do
|
196
|
-
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
197
|
-
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
198
|
-
expect(notification_rule).to receive(:respond_to?).with(:critical_media).and_return(true)
|
199
|
-
expect(notification_rule).to receive(:to_json).and_return('"rule_1"')
|
200
|
-
|
201
|
-
# symbolize the keys
|
202
|
-
notification_rule_data_sym = notification_rule_data.inject({}){|memo,(k,v)|
|
203
|
-
memo[k.to_sym] = v; memo
|
204
|
-
}
|
205
|
-
notification_rule_data_sym.delete(:contact_id)
|
206
|
-
|
207
|
-
expect(contact).to receive(:add_notification_rule).
|
208
|
-
with(notification_rule_data_sym, :logger => @logger).and_return(notification_rule)
|
209
|
-
|
210
|
-
apost "/notification_rules", {"notification_rules" => [notification_rule_data]}.to_json,
|
211
|
-
{'CONTENT_TYPE' => JSON_REQUEST_MIME}
|
212
|
-
expect(last_response.status).to eq(201)
|
213
|
-
expect(last_response.body).to eq('{"notification_rules":["rule_1"]}')
|
214
|
-
end
|
215
|
-
|
216
|
-
it "does not create a notification_rule for a contact that's not present" do
|
217
|
-
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
218
|
-
with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
|
219
|
-
|
220
|
-
apost "/notification_rules", {"notification_rules" => [notification_rule_data]}.to_json,
|
221
|
-
{'CONTENT_TYPE' => JSON_REQUEST_MIME}
|
222
|
-
expect(last_response.status).to eq(404)
|
223
|
-
end
|
224
|
-
|
225
|
-
# PUT /notification_rules/RULE_ID
|
226
|
-
it "updates a notification rule" do
|
227
|
-
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
228
|
-
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
229
|
-
expect(notification_rule).to receive(:to_json).and_return('"rule_1"')
|
230
|
-
expect(Flapjack::Data::NotificationRule).to receive(:find_by_id).
|
231
|
-
with(notification_rule.id, {:redis => redis, :logger => @logger}).and_return(notification_rule)
|
232
|
-
|
233
|
-
# symbolize the keys
|
234
|
-
notification_rule_data_sym = notification_rule_data.inject({}){|memo,(k,v)|
|
235
|
-
memo[k.to_sym] = v; memo
|
236
|
-
}
|
237
|
-
notification_rule_data_sym.delete(:contact_id)
|
85
|
+
with('1234', :logger => @logger, :redis => redis).and_return(contact)
|
238
86
|
|
239
|
-
expect(
|
240
|
-
|
241
|
-
aput "/notification_rules/#{notification_rule.id}", {"notification_rules" => [notification_rule_data]}.to_json,
|
242
|
-
{'CONTENT_TYPE' => JSON_REQUEST_MIME}
|
243
|
-
expect(last_response).to be_ok
|
244
|
-
expect(last_response.body).to eq('{"notification_rules":["rule_1"]}')
|
245
|
-
end
|
246
|
-
|
247
|
-
it "does not update a notification rule that's not present" do
|
248
|
-
expect(Flapjack::Data::NotificationRule).to receive(:find_by_id).
|
249
|
-
with(notification_rule.id, {:redis => redis, :logger => @logger}).and_return(nil)
|
250
|
-
|
251
|
-
aput "/notification_rules/#{notification_rule.id}", {"notification_rules" => [notification_rule_data]}.to_json,
|
252
|
-
{'CONTENT_TYPE' => JSON_REQUEST_MIME}
|
253
|
-
expect(last_response.status).to eq(404)
|
254
|
-
end
|
255
|
-
|
256
|
-
it "does not update a notification_rule for a contact that's not present" do
|
257
|
-
expect(Flapjack::Data::NotificationRule).to receive(:find_by_id).
|
258
|
-
with(notification_rule.id, {:redis => redis, :logger => @logger}).and_return(notification_rule)
|
259
|
-
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
260
|
-
with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
|
87
|
+
expect(contact).to receive(:update).with('first_name' => 'Elias').and_return(nil)
|
88
|
+
expect(semaphore).to receive(:release).and_return(true)
|
261
89
|
|
262
|
-
|
263
|
-
{'
|
264
|
-
|
90
|
+
apatch "/contacts/1234",
|
91
|
+
[{:op => 'replace', :path => '/contacts/0/first_name', :value => 'Elias'}].to_json,
|
92
|
+
jsonapi_patch_env
|
93
|
+
expect(last_response.status).to eq(204)
|
265
94
|
end
|
266
95
|
|
267
|
-
|
268
|
-
it "deletes a notification rule" do
|
269
|
-
expect(notification_rule).to receive(:contact_id).and_return(contact.id)
|
270
|
-
expect(Flapjack::Data::NotificationRule).to receive(:find_by_id).
|
271
|
-
with(notification_rule.id, {:redis => redis, :logger => @logger}).and_return(notification_rule)
|
272
|
-
expect(contact).to receive(:delete_notification_rule).with(notification_rule)
|
96
|
+
it "deletes a contact" do
|
273
97
|
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
274
98
|
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
99
|
+
expect(Flapjack::Data::Semaphore).to receive(:new).and_return(semaphore)
|
100
|
+
expect(semaphore).to receive(:release)
|
101
|
+
expect(contact).to receive(:delete!)
|
275
102
|
|
276
|
-
adelete "/
|
103
|
+
adelete "/contacts/21"
|
277
104
|
expect(last_response.status).to eq(204)
|
278
105
|
end
|
279
106
|
|
280
|
-
it "does not
|
281
|
-
expect(Flapjack::Data::
|
282
|
-
with(notification_rule.id, {:redis => redis, :logger => @logger}).and_return(nil)
|
283
|
-
|
284
|
-
adelete "/notification_rules/#{notification_rule.id}"
|
285
|
-
expect(last_response.status).to eq(404)
|
286
|
-
end
|
287
|
-
|
288
|
-
it "does not delete a notification rule if the contact is not present" do
|
289
|
-
expect(notification_rule).to receive(:contact_id).and_return(contact.id)
|
290
|
-
expect(Flapjack::Data::NotificationRule).to receive(:find_by_id).
|
291
|
-
with(notification_rule.id, {:redis => redis, :logger => @logger}).and_return(notification_rule)
|
292
|
-
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
293
|
-
with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
|
107
|
+
it "does not create a contact if the data is improperly formatted" do
|
108
|
+
expect(Flapjack::Data::Contact).not_to receive(:add)
|
294
109
|
|
295
|
-
|
296
|
-
expect(last_response.status).to eq(
|
110
|
+
apost "/contacts", {'sausage' => 'good'}.to_json, jsonapi_post_env
|
111
|
+
expect(last_response.status).to eq(422)
|
297
112
|
end
|
298
113
|
|
299
|
-
it "returns the media of a contact"
|
300
|
-
|
301
|
-
it "returns the specified media of a contact"
|
302
|
-
|
303
|
-
it "does not return the media of a contact if the media is not present"
|
304
|
-
|
305
|
-
it "creates/updates a media of a contact"
|
306
|
-
|
307
|
-
it "updates a contact's pagerduty media credentials"
|
308
|
-
|
309
|
-
it "does not create a media of a contact that's not present"
|
310
|
-
|
311
|
-
it "does not create a media of a contact if no address is provided"
|
312
|
-
|
313
|
-
it "creates a media of a contact even if no interval is provided"
|
314
|
-
|
315
|
-
it "deletes a media of a contact"
|
316
|
-
|
317
|
-
it "does not delete a media of a contact that's not present"
|
318
|
-
|
319
114
|
end
|
@@ -3,758 +3,288 @@ require 'flapjack/gateways/jsonapi'
|
|
3
3
|
|
4
4
|
describe 'Flapjack::Gateways::JSONAPI::EntityMethods', :sinatra => true, :logger => true do
|
5
5
|
|
6
|
-
|
7
|
-
Flapjack::Gateways::JSONAPI
|
8
|
-
end
|
6
|
+
include_context "jsonapi"
|
9
7
|
|
10
8
|
let(:entity) { double(Flapjack::Data::Entity) }
|
11
9
|
let(:entity_check) { double(Flapjack::Data::EntityCheck) }
|
12
10
|
|
11
|
+
let(:entity_id) { '457' }
|
13
12
|
let(:entity_name) { 'www.example.net'}
|
14
13
|
let(:entity_name_esc) { URI.escape(entity_name) }
|
15
14
|
let(:check) { 'ping' }
|
16
15
|
|
17
|
-
let(:
|
18
|
-
let(:entity_check_presenter) { double(Flapjack::Gateways::JSONAPI::EntityCheckPresenter) }
|
16
|
+
let(:check_presenter) { double(Flapjack::Gateways::JSONAPI::CheckPresenter) }
|
19
17
|
|
20
|
-
|
18
|
+
it "retrieves all entities" do
|
19
|
+
entity_core = {'id' => '1234',
|
20
|
+
'name' => 'www.example.com'}
|
21
|
+
expect(entity).to receive(:id).twice.and_return('1234')
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
23
|
+
expect(Flapjack::Data::Entity).to receive(:contact_ids_for).
|
24
|
+
with(['1234'], :redis => redis).and_return({})
|
25
|
+
expect(entity).to receive(:to_jsonapi).and_return(entity_core.to_json)
|
26
|
+
expect(Flapjack::Data::Entity).to receive(:all).with(:redis => redis).
|
27
|
+
and_return([entity])
|
27
28
|
|
28
|
-
|
29
|
-
expect(
|
30
|
-
|
31
|
-
Flapjack::Gateways::JSONAPI.instance_variable_set('@logger', @logger)
|
32
|
-
Flapjack::Gateways::JSONAPI.start
|
29
|
+
aget '/entities'
|
30
|
+
expect(last_response).to be_ok
|
31
|
+
expect(last_response.body).to eq({:entities => [entity_core]}.to_json)
|
33
32
|
end
|
34
33
|
|
35
|
-
it "
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
aget "/status/#{entity_name_esc}"
|
51
|
-
expect(last_response).to be_ok
|
52
|
-
expect(last_response.body).to eq(['status!'].to_json)
|
53
|
-
end
|
54
|
-
|
55
|
-
it "should not show the status for an entity that's not found" do
|
56
|
-
expect(Flapjack::Data::Entity).to receive(:find_by_name).
|
57
|
-
with(entity_name, :redis => redis).and_return(nil)
|
58
|
-
|
59
|
-
aget "/status/#{entity_name_esc}"
|
60
|
-
expect(last_response.status).to eq(404)
|
61
|
-
end
|
62
|
-
|
63
|
-
it "returns the status for a check on an entity" do
|
64
|
-
status = double('status', :to_json => 'status!'.to_json)
|
65
|
-
expect(entity_check_presenter).to receive(:status).and_return(status)
|
66
|
-
|
67
|
-
expect(Flapjack::Gateways::JSONAPI::EntityCheckPresenter).to receive(:new).
|
68
|
-
with(entity_check).and_return(entity_check_presenter)
|
69
|
-
|
70
|
-
expect(Flapjack::Data::EntityCheck).to receive(:for_entity).
|
71
|
-
with(entity, check, :redis => redis).and_return(entity_check)
|
72
|
-
|
73
|
-
expect(Flapjack::Data::Entity).to receive(:find_by_name).
|
74
|
-
with(entity_name, :redis => redis).and_return(entity)
|
75
|
-
|
76
|
-
aget "/status/#{entity_name_esc}/#{check}"
|
77
|
-
expect(last_response).to be_ok
|
78
|
-
expect(last_response.body).to eq('status!'.to_json)
|
79
|
-
end
|
80
|
-
|
81
|
-
it "should not show the status for a check on an entity that's not found" do
|
82
|
-
expect(Flapjack::Data::Entity).to receive(:find_by_name).
|
83
|
-
with(entity_name, :redis => redis).and_return(nil)
|
84
|
-
|
85
|
-
aget "/status/#{entity_name_esc}/#{check}"
|
86
|
-
expect(last_response.status).to eq(404)
|
87
|
-
end
|
88
|
-
|
89
|
-
it "should not show the status for a check that's not found on an entity" do
|
90
|
-
expect(Flapjack::Data::Entity).to receive(:find_by_name).
|
91
|
-
with(entity_name, :redis => redis).and_return(entity)
|
92
|
-
|
93
|
-
expect(Flapjack::Data::EntityCheck).to receive(:for_entity).
|
94
|
-
with(entity, check, :redis => redis).and_return(nil)
|
95
|
-
|
96
|
-
aget "/status/#{entity_name_esc}/#{check}"
|
97
|
-
expect(last_response.status).to eq(404)
|
98
|
-
end
|
99
|
-
|
100
|
-
it "returns a list of scheduled maintenance periods for an entity" do
|
101
|
-
sched = double('sched', :to_json => 'sched!'.to_json)
|
102
|
-
result = {:entity => entity_name, :check => check, :scheduled_maintenances => sched}
|
103
|
-
expect(entity_presenter).to receive(:scheduled_maintenances).with(nil, nil).and_return(result)
|
104
|
-
expect(Flapjack::Gateways::JSONAPI::EntityPresenter).to receive(:new).
|
105
|
-
with(entity, :redis => redis).and_return(entity_presenter)
|
106
|
-
expect(Flapjack::Data::Entity).to receive(:find_by_name).
|
107
|
-
with(entity_name, :redis => redis).and_return(entity)
|
108
|
-
|
109
|
-
aget "/scheduled_maintenances/#{entity_name_esc}"
|
110
|
-
expect(last_response).to be_ok
|
111
|
-
expect(last_response.body).to eq([{:check => check, :scheduled_maintenance => sched}].to_json)
|
112
|
-
end
|
113
|
-
|
114
|
-
it "returns a list of scheduled maintenance periods within a time window for an entity" do
|
115
|
-
start = Time.parse('1 Jan 2012')
|
116
|
-
finish = Time.parse('6 Jan 2012')
|
117
|
-
|
118
|
-
sched = double('sched', :to_json => 'sched!'.to_json)
|
119
|
-
result = {:entity => entity_name, :check => check, :scheduled_maintenances => sched}
|
120
|
-
expect(entity_presenter).to receive(:scheduled_maintenances).with(start.to_i, finish.to_i).and_return(result)
|
121
|
-
expect(Flapjack::Gateways::JSONAPI::EntityPresenter).to receive(:new).
|
122
|
-
with(entity, :redis => redis).and_return(entity_presenter)
|
123
|
-
expect(Flapjack::Data::Entity).to receive(:find_by_name).
|
124
|
-
with(entity_name, :redis => redis).and_return(entity)
|
125
|
-
|
126
|
-
aget "/scheduled_maintenances/#{entity_name_esc}?" +
|
127
|
-
"start_time=#{CGI.escape(start.iso8601)}&end_time=#{CGI.escape(finish.iso8601)}"
|
128
|
-
expect(last_response).to be_ok
|
129
|
-
expect(last_response.body).to eq([{:check => check, :scheduled_maintenance => sched}].to_json)
|
130
|
-
end
|
131
|
-
|
132
|
-
it "returns a list of scheduled maintenance periods for a check on an entity" do
|
133
|
-
sched = double('sched', :to_json => 'sched!'.to_json)
|
134
|
-
expect(entity_check_presenter).to receive(:scheduled_maintenances).with(nil, nil).and_return(sched)
|
135
|
-
expect(Flapjack::Gateways::JSONAPI::EntityCheckPresenter).to receive(:new).
|
136
|
-
with(entity_check).and_return(entity_check_presenter)
|
137
|
-
expect(Flapjack::Data::Entity).to receive(:find_by_name).
|
138
|
-
with(entity_name, :redis => redis).and_return(entity)
|
139
|
-
expect(Flapjack::Data::EntityCheck).to receive(:for_entity).
|
140
|
-
with(entity, check, :redis => redis).and_return(entity_check)
|
141
|
-
|
142
|
-
aget "/scheduled_maintenances/#{entity_name_esc}/#{check}"
|
143
|
-
expect(last_response).to be_ok
|
144
|
-
expect(last_response.body).to eq('sched!'.to_json)
|
145
|
-
end
|
146
|
-
|
147
|
-
it "creates an acknowledgement for an entity check" do
|
148
|
-
expect(entity_check).to receive(:entity_name).and_return(entity_name)
|
149
|
-
expect(entity_check).to receive(:check).and_return(check)
|
150
|
-
|
151
|
-
expect(Flapjack::Data::Entity).to receive(:find_by_name).
|
152
|
-
with(entity_name, :redis => redis).and_return(entity)
|
153
|
-
expect(Flapjack::Data::EntityCheck).to receive(:for_entity).
|
154
|
-
with(entity, check, :redis => redis).and_return(entity_check)
|
155
|
-
expect(Flapjack::Data::Event).to receive(:create_acknowledgement).
|
156
|
-
with(entity_name, check, :summary => nil, :duration => (4 * 60 * 60), :redis => redis)
|
157
|
-
|
158
|
-
apost "/acknowledgements/#{entity_name_esc}/#{check}"
|
159
|
-
expect(last_response.status).to eq(204)
|
160
|
-
end
|
161
|
-
|
162
|
-
it "returns a list of unscheduled maintenance periods for an entity" do
|
163
|
-
unsched = double('unsched', :to_json => 'unsched!'.to_json)
|
164
|
-
result = {:entity => entity_name, :check => check, :unscheduled_maintenances => unsched}
|
165
|
-
expect(entity_presenter).to receive(:unscheduled_maintenances).with(nil, nil).and_return(result)
|
166
|
-
expect(Flapjack::Gateways::JSONAPI::EntityPresenter).to receive(:new).
|
167
|
-
with(entity, :redis => redis).and_return(entity_presenter)
|
168
|
-
expect(Flapjack::Data::Entity).to receive(:find_by_name).
|
169
|
-
with(entity_name, :redis => redis).and_return(entity)
|
170
|
-
|
171
|
-
aget "/unscheduled_maintenances/#{entity_name_esc}"
|
172
|
-
expect(last_response).to be_ok
|
173
|
-
expect(last_response.body).to eq([{:check => check, :unscheduled_maintenance => unsched}].to_json)
|
174
|
-
end
|
175
|
-
|
176
|
-
it "returns a list of unscheduled maintenance periods for a check on an entity" do
|
177
|
-
unsched = double('unsched', :to_json => 'unsched!'.to_json)
|
178
|
-
expect(entity_check_presenter).to receive(:unscheduled_maintenances).with(nil, nil).and_return(unsched)
|
179
|
-
expect(Flapjack::Gateways::JSONAPI::EntityCheckPresenter).to receive(:new).
|
180
|
-
with(entity_check).and_return(entity_check_presenter)
|
181
|
-
expect(Flapjack::Data::Entity).to receive(:find_by_name).
|
182
|
-
with(entity_name, :redis => redis).and_return(entity)
|
183
|
-
expect(Flapjack::Data::EntityCheck).to receive(:for_entity).
|
184
|
-
with(entity, check, :redis => redis).and_return(entity_check)
|
185
|
-
|
186
|
-
aget "/unscheduled_maintenances/#{entity_name_esc}/#{check}"
|
187
|
-
expect(last_response).to be_ok
|
188
|
-
expect(last_response.body).to eq('unsched!'.to_json)
|
189
|
-
end
|
190
|
-
|
191
|
-
it "returns a list of unscheduled maintenance periods within a time window for a check an entity" do
|
192
|
-
start = Time.parse('1 Jan 2012')
|
193
|
-
finish = Time.parse('6 Jan 2012')
|
194
|
-
|
195
|
-
unsched = double('unsched', :to_json => 'unsched!'.to_json)
|
196
|
-
expect(entity_check_presenter).to receive(:unscheduled_maintenances).with(start.to_i, finish.to_i).and_return(unsched)
|
197
|
-
expect(Flapjack::Gateways::JSONAPI::EntityCheckPresenter).to receive(:new).
|
198
|
-
with(entity_check).and_return(entity_check_presenter)
|
199
|
-
expect(Flapjack::Data::Entity).to receive(:find_by_name).
|
200
|
-
with(entity_name, :redis => redis).and_return(entity)
|
201
|
-
expect(Flapjack::Data::EntityCheck).to receive(:for_entity).
|
202
|
-
with(entity, check, :redis => redis).and_return(entity_check)
|
203
|
-
|
204
|
-
aget "/unscheduled_maintenances/#{entity_name_esc}/#{check}" +
|
205
|
-
"?start_time=#{CGI.escape(start.iso8601)}&end_time=#{CGI.escape(finish.iso8601)}"
|
206
|
-
expect(last_response).to be_ok
|
207
|
-
expect(last_response.body).to eq('unsched!'.to_json)
|
208
|
-
end
|
209
|
-
|
210
|
-
it "returns a list of outages for an entity" do
|
211
|
-
out = double('out', :to_json => 'out!'.to_json)
|
212
|
-
result = {:entity => entity_name, :check => check, :outages => out}
|
213
|
-
expect(entity_presenter).to receive(:outages).with(nil, nil).and_return(result)
|
214
|
-
expect(Flapjack::Gateways::JSONAPI::EntityPresenter).to receive(:new).
|
215
|
-
with(entity, :redis => redis).and_return(entity_presenter)
|
216
|
-
expect(Flapjack::Data::Entity).to receive(:find_by_name).
|
217
|
-
with(entity_name, :redis => redis).and_return(entity)
|
218
|
-
|
219
|
-
aget "/outages/#{entity_name_esc}"
|
220
|
-
expect(last_response).to be_ok
|
221
|
-
expect(last_response.body).to eq([{:check => check, :outages => out}].to_json)
|
222
|
-
end
|
223
|
-
|
224
|
-
it "returns a list of outages for a check on an entity" do
|
225
|
-
out = double('out', :to_json => 'out!'.to_json)
|
226
|
-
expect(entity_check_presenter).to receive(:outages).with(nil, nil).and_return(out)
|
227
|
-
expect(Flapjack::Gateways::JSONAPI::EntityCheckPresenter).to receive(:new).
|
228
|
-
with(entity_check).and_return(entity_check_presenter)
|
229
|
-
expect(Flapjack::Data::Entity).to receive(:find_by_name).
|
230
|
-
with(entity_name, :redis => redis).and_return(entity)
|
231
|
-
expect(Flapjack::Data::EntityCheck).to receive(:for_entity).
|
232
|
-
with(entity, check, :redis => redis).and_return(entity_check)
|
233
|
-
|
234
|
-
aget "/outages/#{entity_name_esc}/#{check}"
|
235
|
-
expect(last_response).to be_ok
|
236
|
-
expect(last_response.body).to eq('out!'.to_json)
|
237
|
-
end
|
238
|
-
|
239
|
-
it "returns a list of downtimes for an entity" do
|
240
|
-
down = double('down', :to_json => 'down!'.to_json)
|
241
|
-
result = {:entity => entity_name, :check => check, :downtime => down}
|
242
|
-
expect(entity_presenter).to receive(:downtime).with(nil, nil).and_return(result)
|
243
|
-
expect(Flapjack::Gateways::JSONAPI::EntityPresenter).to receive(:new).
|
244
|
-
with(entity, :redis => redis).and_return(entity_presenter)
|
245
|
-
expect(Flapjack::Data::Entity).to receive(:find_by_name).
|
246
|
-
with(entity_name, :redis => redis).and_return(entity)
|
247
|
-
|
248
|
-
aget "/downtime/#{entity_name_esc}"
|
249
|
-
expect(last_response).to be_ok
|
250
|
-
expect(last_response.body).to eq([{:check => check, :downtime => down}].to_json)
|
251
|
-
end
|
252
|
-
|
253
|
-
it "returns a list of downtimes for a check on an entity" do
|
254
|
-
down = double('down', :to_json => 'down!'.to_json)
|
255
|
-
expect(entity_check_presenter).to receive(:downtime).with(nil, nil).and_return(down)
|
256
|
-
expect(Flapjack::Gateways::JSONAPI::EntityCheckPresenter).to receive(:new).
|
257
|
-
with(entity_check).and_return(entity_check_presenter)
|
258
|
-
expect(Flapjack::Data::Entity).to receive(:find_by_name).
|
259
|
-
with(entity_name, :redis => redis).and_return(entity)
|
260
|
-
expect(Flapjack::Data::EntityCheck).to receive(:for_entity).
|
261
|
-
with(entity, check, :redis => redis).and_return(entity_check)
|
262
|
-
|
263
|
-
aget "/downtime/#{entity_name_esc}/#{check}"
|
264
|
-
expect(last_response).to be_ok
|
265
|
-
expect(last_response.body).to eq('down!'.to_json)
|
266
|
-
end
|
267
|
-
|
268
|
-
it "creates a test notification event for check on an entity" do
|
269
|
-
expect(Flapjack::Data::Entity).to receive(:find_by_name).
|
270
|
-
with(entity_name, :redis => redis).and_return(entity)
|
271
|
-
expect(entity).to receive(:name).and_return(entity_name)
|
272
|
-
expect(entity_check).to receive(:entity).and_return(entity)
|
273
|
-
expect(entity_check).to receive(:entity_name).and_return(entity_name)
|
274
|
-
expect(entity_check).to receive(:check).and_return('foo')
|
275
|
-
expect(Flapjack::Data::EntityCheck).to receive(:for_entity).
|
276
|
-
with(entity, 'foo', :redis => redis).and_return(entity_check)
|
277
|
-
|
278
|
-
expect(Flapjack::Data::Event).to receive(:test_notifications).
|
279
|
-
with(entity_name, 'foo', hash_including(:redis => redis))
|
280
|
-
|
281
|
-
apost "/test_notifications/#{entity_name_esc}/foo"
|
282
|
-
expect(last_response.status).to eq(204)
|
283
|
-
end
|
284
|
-
|
34
|
+
it "retrieves one entity" do
|
35
|
+
entity_core = {'id' => '1234',
|
36
|
+
'name' => 'www.example.com'}
|
37
|
+
expect(entity).to receive(:id).twice.and_return('1234')
|
38
|
+
|
39
|
+
expect(Flapjack::Data::Entity).to receive(:contact_ids_for).
|
40
|
+
with(['1234'], :redis => redis).and_return({})
|
41
|
+
expect(entity).to receive(:to_jsonapi).and_return(entity_core.to_json)
|
42
|
+
expect(Flapjack::Data::Entity).to receive(:find_by_id).
|
43
|
+
with('1234', :logger => @logger, :redis => redis).
|
44
|
+
and_return(entity)
|
45
|
+
|
46
|
+
aget '/entities/1234'
|
47
|
+
expect(last_response).to be_ok
|
48
|
+
expect(last_response.body).to eq({:entities => [entity_core]}.to_json)
|
285
49
|
end
|
286
50
|
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
expect(Flapjack::Gateways::JSONAPI::EntityPresenter).to receive(:new).
|
295
|
-
with(entity, :redis => redis).and_return(entity_presenter)
|
296
|
-
|
297
|
-
expect(Flapjack::Data::Entity).to receive(:find_by_name).
|
298
|
-
with(entity_name, :redis => redis).and_return(entity)
|
299
|
-
|
300
|
-
aget "/status", :entity => entity_name
|
301
|
-
expect(last_response.body).to eq(result.to_json)
|
302
|
-
end
|
303
|
-
|
304
|
-
it "should not show the status for an entity that's not found" do
|
305
|
-
expect(Flapjack::Data::Entity).to receive(:find_by_name).
|
306
|
-
with(entity_name, :redis => redis).and_return(nil)
|
307
|
-
|
308
|
-
aget "/status", :entity => entity_name
|
309
|
-
expect(last_response.status).to eq(404)
|
310
|
-
end
|
311
|
-
|
312
|
-
it "returns the status for a check on an entity" do
|
313
|
-
status = double('status')
|
314
|
-
result = [{:entity => entity_name, :check => check, :status => status}]
|
315
|
-
expect(entity_check_presenter).to receive(:status).and_return(status)
|
316
|
-
|
317
|
-
expect(Flapjack::Gateways::JSONAPI::EntityCheckPresenter).to receive(:new).
|
318
|
-
with(entity_check).and_return(entity_check_presenter)
|
319
|
-
|
320
|
-
expect(Flapjack::Data::EntityCheck).to receive(:for_entity).
|
321
|
-
with(entity, check, :redis => redis).and_return(entity_check)
|
322
|
-
|
323
|
-
expect(Flapjack::Data::Entity).to receive(:find_by_name).
|
324
|
-
with(entity_name, :redis => redis).and_return(entity)
|
325
|
-
|
326
|
-
aget "/status", :check => {entity_name => check}
|
327
|
-
expect(last_response).to be_ok
|
328
|
-
expect(last_response.body).to eq(result.to_json)
|
329
|
-
end
|
330
|
-
|
331
|
-
it "should not show the status for a check on an entity that's not found" do
|
332
|
-
expect(Flapjack::Data::Entity).to receive(:find_by_name).
|
333
|
-
with(entity_name, :redis => redis).and_return(nil)
|
334
|
-
|
335
|
-
aget "/status", :check => {entity_name => check}
|
336
|
-
expect(last_response.status).to eq(404)
|
337
|
-
end
|
338
|
-
|
339
|
-
it "should not show the status for a check that's not found on an entity" do
|
340
|
-
expect(Flapjack::Data::Entity).to receive(:find_by_name).
|
341
|
-
with(entity_name, :redis => redis).and_return(entity)
|
342
|
-
|
343
|
-
expect(Flapjack::Data::EntityCheck).to receive(:for_entity).
|
344
|
-
with(entity, check, :redis => redis).and_return(nil)
|
345
|
-
|
346
|
-
aget "/status", :check => {entity_name => check}
|
347
|
-
expect(last_response.status).to eq(404)
|
348
|
-
end
|
349
|
-
|
350
|
-
it "creates an acknowledgement for an entity check" do
|
351
|
-
expect(Flapjack::Data::Entity).to receive(:find_by_name).
|
352
|
-
with(entity_name, :redis => redis).and_return(entity)
|
353
|
-
expect(Flapjack::Data::EntityCheck).to receive(:for_entity).
|
354
|
-
with(entity, check, :redis => redis).and_return(entity_check)
|
355
|
-
|
356
|
-
expect(entity_check).to receive(:entity_name).and_return(entity_name)
|
357
|
-
expect(entity_check).to receive(:check).and_return(check)
|
358
|
-
|
359
|
-
expect(Flapjack::Data::Event).to receive(:create_acknowledgement).
|
360
|
-
with(entity_name, check, :summary => nil, :duration => (4 * 60 * 60), :redis => redis)
|
361
|
-
|
362
|
-
apost '/acknowledgements',:check => {entity_name => check}
|
363
|
-
expect(last_response.status).to eq(204)
|
364
|
-
end
|
365
|
-
|
366
|
-
it "deletes an unscheduled maintenance period for an entity check" do
|
367
|
-
end_time = Time.now + (60 * 60) # an hour from now
|
368
|
-
expect(entity_check).to receive(:end_unscheduled_maintenance).with(end_time.to_i)
|
369
|
-
|
370
|
-
expect(Flapjack::Data::EntityCheck).to receive(:for_entity).
|
371
|
-
with(entity, check, :redis => redis).and_return(entity_check)
|
372
|
-
|
373
|
-
expect(Flapjack::Data::Entity).to receive(:find_by_name).
|
374
|
-
with(entity_name, :redis => redis).and_return(entity)
|
375
|
-
|
376
|
-
adelete "/unscheduled_maintenances", :check => {entity_name => check}, :end_time => end_time.iso8601
|
377
|
-
expect(last_response.status).to eq(204)
|
378
|
-
end
|
379
|
-
|
380
|
-
it "creates a scheduled maintenance period for an entity check" do
|
381
|
-
start = Time.now + (60 * 60) # an hour from now
|
382
|
-
duration = (2 * 60 * 60) # two hours
|
383
|
-
expect(Flapjack::Data::Entity).to receive(:find_by_name).
|
384
|
-
with(entity_name, :redis => redis).and_return(entity)
|
385
|
-
expect(Flapjack::Data::EntityCheck).to receive(:for_entity).
|
386
|
-
with(entity, check, :redis => redis).and_return(entity_check)
|
387
|
-
expect(entity_check).to receive(:create_scheduled_maintenance).
|
388
|
-
with(start.getutc.to_i, duration, :summary => 'test')
|
389
|
-
|
390
|
-
apost "/scheduled_maintenances/#{entity_name_esc}/#{check}?" +
|
391
|
-
"start_time=#{CGI.escape(start.iso8601)}&summary=test&duration=#{duration}"
|
392
|
-
expect(last_response.status).to eq(204)
|
393
|
-
end
|
394
|
-
|
395
|
-
it "doesn't create a scheduled maintenance period if the start time isn't passed" do
|
396
|
-
duration = (2 * 60 * 60) # two hours
|
397
|
-
|
398
|
-
apost "/scheduled_maintenances/#{entity_name_esc}/#{check}?" +
|
399
|
-
"summary=test&duration=#{duration}"
|
400
|
-
expect(last_response.status).to eq(403)
|
401
|
-
end
|
402
|
-
|
403
|
-
it "deletes a scheduled maintenance period for an entity check" do
|
404
|
-
start_time = Time.now + (60 * 60) # an hour from now
|
405
|
-
expect(entity_check).to receive(:end_scheduled_maintenance).with(start_time.to_i)
|
51
|
+
it "retrieves several entities" do
|
52
|
+
entity_2 = double(Flapjack::Data::Entity)
|
53
|
+
entity_core = {'id' => '1234',
|
54
|
+
'name' => 'www.example.com'}
|
55
|
+
entity_core_2 = {'id' => '5678',
|
56
|
+
'name' => 'www.example2.com'}
|
406
57
|
|
407
|
-
|
408
|
-
|
58
|
+
expect(Flapjack::Data::Entity).to receive(:contact_ids_for).
|
59
|
+
with(['1234', '5678'], :redis => redis).and_return({})
|
409
60
|
|
410
|
-
|
411
|
-
|
61
|
+
expect(entity).to receive(:id).twice.and_return('1234')
|
62
|
+
expect(entity_2).to receive(:id).twice.and_return('5678')
|
412
63
|
|
413
|
-
|
414
|
-
|
415
|
-
end
|
64
|
+
expect(entity).to receive(:to_jsonapi).and_return(entity_core.to_json)
|
65
|
+
expect(entity_2).to receive(:to_jsonapi).and_return(entity_core_2.to_json)
|
416
66
|
|
417
|
-
|
418
|
-
|
67
|
+
expect(Flapjack::Data::Entity).to receive(:find_by_id).
|
68
|
+
with('1234', :logger => @logger, :redis => redis).
|
69
|
+
and_return(entity)
|
70
|
+
expect(Flapjack::Data::Entity).to receive(:find_by_id).
|
71
|
+
with('5678', :logger => @logger, :redis => redis).
|
72
|
+
and_return(entity_2)
|
419
73
|
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
it "deletes scheduled maintenance periods for multiple entity checks" do
|
425
|
-
start_time = Time.now + (60 * 60) # an hour from now
|
426
|
-
|
427
|
-
entity_check_2 = double(Flapjack::Data::EntityCheck)
|
428
|
-
|
429
|
-
expect(entity_check).to receive(:end_scheduled_maintenance).with(start_time.to_i)
|
430
|
-
expect(entity_check_2).to receive(:end_scheduled_maintenance).with(start_time.to_i)
|
431
|
-
|
432
|
-
expect(Flapjack::Data::EntityCheck).to receive(:for_entity).
|
433
|
-
with(entity, check, :redis => redis).and_return(entity_check)
|
434
|
-
expect(Flapjack::Data::EntityCheck).to receive(:for_entity).
|
435
|
-
with(entity, 'foo', :redis => redis).and_return(entity_check_2)
|
436
|
-
|
437
|
-
expect(Flapjack::Data::Entity).to receive(:find_by_name).
|
438
|
-
with(entity_name, :redis => redis).and_return(entity)
|
439
|
-
|
440
|
-
adelete "/scheduled_maintenances", :check => {entity_name => [check, 'foo']}, :start_time => start_time.iso8601
|
441
|
-
expect(last_response.status).to eq(204)
|
442
|
-
end
|
443
|
-
|
444
|
-
it "returns a list of scheduled maintenance periods for an entity" do
|
445
|
-
sm = double('sched_maint')
|
446
|
-
result = [{:entity => entity_name, :check => check, :scheduled_maintenances => sm}]
|
447
|
-
|
448
|
-
expect(entity_presenter).to receive(:scheduled_maintenances).with(nil, nil).and_return(result)
|
449
|
-
|
450
|
-
expect(Flapjack::Gateways::JSONAPI::EntityPresenter).to receive(:new).
|
451
|
-
with(entity, :redis => redis).and_return(entity_presenter)
|
452
|
-
|
453
|
-
expect(Flapjack::Data::Entity).to receive(:find_by_name).
|
454
|
-
with(entity_name, :redis => redis).and_return(entity)
|
455
|
-
|
456
|
-
aget "/scheduled_maintenances", :entity => entity_name
|
457
|
-
expect(last_response).to be_ok
|
458
|
-
expect(last_response.body).to eq(result.to_json)
|
459
|
-
end
|
460
|
-
|
461
|
-
it "returns a list of scheduled maintenance periods within a time window for an entity" do
|
462
|
-
start = Time.parse('1 Jan 2012')
|
463
|
-
finish = Time.parse('6 Jan 2012')
|
464
|
-
|
465
|
-
sm = double('sched_maint')
|
466
|
-
result = [{:entity => entity_name, :check => check, :scheduled_maintenances => sm}]
|
467
|
-
|
468
|
-
expect(entity_presenter).to receive(:scheduled_maintenances).with(start.to_i, finish.to_i).and_return(result)
|
469
|
-
|
470
|
-
expect(Flapjack::Gateways::JSONAPI::EntityPresenter).to receive(:new).
|
471
|
-
with(entity, :redis => redis).and_return(entity_presenter)
|
472
|
-
|
473
|
-
expect(Flapjack::Data::Entity).to receive(:find_by_name).
|
474
|
-
with(entity_name, :redis => redis).and_return(entity)
|
475
|
-
|
476
|
-
aget "/scheduled_maintenances", :entity => entity_name,
|
477
|
-
:start_time => start.iso8601, :end_time => finish.iso8601
|
478
|
-
expect(last_response).to be_ok
|
479
|
-
expect(last_response.body).to eq(result.to_json)
|
480
|
-
end
|
481
|
-
|
482
|
-
it "returns a list of scheduled maintenance periods for a check on an entity" do
|
483
|
-
sm = double('sched_maint')
|
484
|
-
result = [{:entity => entity_name, :check => check, :scheduled_maintenances => sm}]
|
485
|
-
|
486
|
-
expect(entity_check_presenter).to receive(:scheduled_maintenances).with(nil, nil).and_return(sm)
|
74
|
+
aget '/entities/1234,5678'
|
75
|
+
expect(last_response).to be_ok
|
76
|
+
expect(last_response.body).to eq({:entities => [entity_core, entity_core_2]}.to_json)
|
77
|
+
end
|
487
78
|
|
488
|
-
|
489
|
-
|
79
|
+
it "creates entities from a submitted list" do
|
80
|
+
entities = {'entities' =>
|
81
|
+
[
|
82
|
+
{"id" => "10001",
|
83
|
+
"name" => "clientx-app-01",
|
84
|
+
"contacts" => ["0362","0363","0364"]
|
85
|
+
},
|
86
|
+
{"id" => "10002",
|
87
|
+
"name" => "clientx-app-02",
|
88
|
+
"contacts" => ["0362"]
|
89
|
+
}
|
90
|
+
]
|
91
|
+
}
|
92
|
+
expect(Flapjack::Data::Entity).to receive(:add).twice
|
490
93
|
|
491
|
-
|
492
|
-
|
94
|
+
apost "/entities", entities.to_json, jsonapi_post_env
|
95
|
+
expect(last_response.status).to eq(201)
|
96
|
+
expect(last_response.headers['Location']).to eq("http://example.org/entities/10001,10002")
|
97
|
+
expect(last_response.body).to eq('["10001","10002"]')
|
98
|
+
end
|
493
99
|
|
494
|
-
|
495
|
-
|
100
|
+
it "does not create entities if the data is improperly formatted" do
|
101
|
+
expect(Flapjack::Data::Entity).not_to receive(:add)
|
496
102
|
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
end
|
103
|
+
apost "/entities", {'entities' => ["Hello", "there"]}.to_json, jsonapi_post_env
|
104
|
+
expect(last_response.status).to eq(403)
|
105
|
+
end
|
501
106
|
|
502
|
-
|
503
|
-
|
504
|
-
|
107
|
+
it "does not create entities if they don't contain an id" do
|
108
|
+
entities = {'entities' =>
|
109
|
+
[
|
110
|
+
{"id" => "10001",
|
111
|
+
"name" => "clientx-app-01",
|
112
|
+
"contacts" => ["0362","0363","0364"]
|
113
|
+
},
|
114
|
+
{"name" => "clientx-app-02",
|
115
|
+
"contacts" => ["0362"]
|
116
|
+
}
|
117
|
+
]
|
118
|
+
}
|
119
|
+
expect(Flapjack::Data::Entity).not_to receive(:add)
|
505
120
|
|
506
|
-
|
121
|
+
apost "/entities", entities.to_json, jsonapi_post_env
|
122
|
+
expect(last_response.status).to eq(403)
|
123
|
+
end
|
507
124
|
|
508
|
-
|
509
|
-
|
125
|
+
it "updates an entity" do
|
126
|
+
contact = double(Flapjack::Data::Contact)
|
127
|
+
expect(contact).to receive(:add_entity).with(entity)
|
128
|
+
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
129
|
+
with('32', :redis => redis).and_return(contact)
|
510
130
|
|
511
|
-
|
512
|
-
|
131
|
+
expect(Flapjack::Data::Entity).to receive(:find_by_id).
|
132
|
+
with('1234', :redis => redis).and_return(entity)
|
513
133
|
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
134
|
+
apatch "/entities/1234",
|
135
|
+
[{:op => 'add', :path => '/entities/0/links/contacts/-', :value => '32'}].to_json,
|
136
|
+
jsonapi_patch_env
|
137
|
+
expect(last_response.status).to eq(204)
|
138
|
+
end
|
518
139
|
|
519
|
-
|
520
|
-
|
521
|
-
|
140
|
+
it "creates acknowledgements for all checks on an entity" do
|
141
|
+
expect(entity).to receive(:check_list).and_return([check])
|
142
|
+
expect(Flapjack::Data::Entity).to receive(:find_by_id).
|
143
|
+
with(entity_id, :redis => redis).and_return(entity)
|
144
|
+
expect(Flapjack::Data::EntityCheck).to receive(:for_entity).
|
145
|
+
with(entity, check, :redis => redis).and_return(entity_check)
|
522
146
|
|
523
|
-
|
147
|
+
expect(entity_check).to receive(:entity_name).and_return(entity_name)
|
148
|
+
expect(entity_check).to receive(:check).and_return(check)
|
524
149
|
|
525
|
-
|
526
|
-
|
150
|
+
expect(Flapjack::Data::Event).to receive(:create_acknowledgement).
|
151
|
+
with(entity_name, check, :duration => (4 * 60 * 60), :redis => redis)
|
527
152
|
|
528
|
-
|
529
|
-
|
153
|
+
apost "/unscheduled_maintenances/entities/#{entity_id}"
|
154
|
+
expect(last_response.status).to eq(204)
|
155
|
+
end
|
530
156
|
|
531
|
-
|
532
|
-
|
157
|
+
it "ends unscheduled maintenance periods for all checks on an entity" do
|
158
|
+
end_time = Time.now + (60 * 60) # an hour from now
|
159
|
+
expect(entity_check).to receive(:end_unscheduled_maintenance).with(end_time.to_i)
|
533
160
|
|
534
|
-
|
535
|
-
|
536
|
-
expect(last_response.body).to eq(result.to_json)
|
537
|
-
end
|
161
|
+
expect(Flapjack::Data::EntityCheck).to receive(:for_entity).
|
162
|
+
with(entity, check, :redis => redis).and_return(entity_check)
|
538
163
|
|
539
|
-
|
540
|
-
|
541
|
-
|
164
|
+
expect(entity).to receive(:check_list).and_return([check])
|
165
|
+
expect(Flapjack::Data::Entity).to receive(:find_by_id).
|
166
|
+
with(entity_id, :redis => redis).and_return(entity)
|
542
167
|
|
543
|
-
|
544
|
-
|
168
|
+
apatch "/unscheduled_maintenances/entities/#{entity_id}",
|
169
|
+
[{:op => 'replace', :path => '/unscheduled_maintenances/0/end_time', :value => end_time.iso8601}].to_json,
|
170
|
+
jsonapi_patch_env
|
171
|
+
expect(last_response.status).to eq(204)
|
172
|
+
end
|
545
173
|
|
546
|
-
|
174
|
+
it "creates scheduled maintenance periods for all checks on an entity" do
|
175
|
+
start = Time.now + (60 * 60) # an hour from now
|
176
|
+
duration = (2 * 60 * 60) # two hours
|
547
177
|
|
548
|
-
|
549
|
-
|
178
|
+
expect(entity).to receive(:check_list).and_return([check])
|
179
|
+
expect(Flapjack::Data::Entity).to receive(:find_by_id).
|
180
|
+
with(entity_id, :redis => redis).and_return(entity)
|
181
|
+
expect(Flapjack::Data::EntityCheck).to receive(:for_entity).
|
182
|
+
with(entity, check, :redis => redis).and_return(entity_check)
|
183
|
+
expect(entity_check).to receive(:create_scheduled_maintenance).
|
184
|
+
with(start.getutc.to_i, duration, :summary => 'test')
|
550
185
|
|
551
|
-
|
552
|
-
|
186
|
+
apost "/scheduled_maintenances/entities/#{entity_id}",
|
187
|
+
{:scheduled_maintenances => [{:start_time => start.iso8601, :summary => 'test', :duration => duration}]}.to_json,
|
188
|
+
jsonapi_post_env
|
553
189
|
|
554
|
-
|
555
|
-
|
190
|
+
expect(last_response.status).to eq(204)
|
191
|
+
end
|
556
192
|
|
557
|
-
|
558
|
-
|
559
|
-
expect(last_response).to be_ok
|
560
|
-
expect(last_response.body).to eq(result.to_json)
|
561
|
-
end
|
193
|
+
it "doesn't create scheduled maintenance periods if the start time isn't passed" do
|
194
|
+
duration = (2 * 60 * 60) # two hours
|
562
195
|
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
196
|
+
expect(entity).to receive(:check_list).and_return([check])
|
197
|
+
expect(Flapjack::Data::Entity).to receive(:find_by_id).
|
198
|
+
with(entity_id, :redis => redis).and_return(entity)
|
199
|
+
expect(Flapjack::Data::EntityCheck).to receive(:for_entity).
|
200
|
+
with(entity, check, :redis => redis).and_return(entity_check)
|
201
|
+
expect(entity_check).not_to receive(:create_scheduled_maintenance)
|
567
202
|
|
568
|
-
|
569
|
-
|
203
|
+
apost "/scheduled_maintenances/entities/#{entity_id}",
|
204
|
+
{:scheduled_maintenances => [{:summary => 'test', :duration => duration}]}.to_json, jsonapi_post_env
|
205
|
+
expect(last_response.status).to eq(403)
|
206
|
+
end
|
570
207
|
|
571
|
-
|
572
|
-
|
573
|
-
|
208
|
+
it "deletes scheduled maintenance periods for all checks on an entity" do
|
209
|
+
start_time = Time.now + (60 * 60) # an hour from now
|
210
|
+
expect(entity_check).to receive(:end_scheduled_maintenance).with(start_time.to_i)
|
574
211
|
|
575
|
-
|
576
|
-
|
212
|
+
expect(Flapjack::Data::EntityCheck).to receive(:for_entity).
|
213
|
+
with(entity, check, :redis => redis).and_return(entity_check)
|
577
214
|
|
578
|
-
|
579
|
-
|
215
|
+
expect(entity).to receive(:check_list).and_return([check])
|
216
|
+
expect(Flapjack::Data::Entity).to receive(:find_by_id).
|
217
|
+
with(entity_id, :redis => redis).and_return(entity)
|
580
218
|
|
581
|
-
|
582
|
-
|
583
|
-
|
219
|
+
adelete "/scheduled_maintenances/entities/#{entity_id}",
|
220
|
+
:start_time => start_time.iso8601
|
221
|
+
expect(last_response.status).to eq(204)
|
222
|
+
end
|
584
223
|
|
585
|
-
|
586
|
-
|
224
|
+
it "doesn't delete scheduled maintenance periods if the start time isn't passed" do
|
225
|
+
expect(entity_check).not_to receive(:end_scheduled_maintenance)
|
587
226
|
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
with(bar_check).and_return(bar_check_presenter)
|
227
|
+
adelete "/scheduled_maintenances/entities/#{entity_id}"
|
228
|
+
expect(last_response.status).to eq(403)
|
229
|
+
end
|
592
230
|
|
593
|
-
|
594
|
-
|
595
|
-
expect(Flapjack::Data::Entity).to receive(:find_by_name).
|
596
|
-
with(entity_2_name, :redis => redis).and_return(entity_2)
|
231
|
+
it "deletes scheduled maintenance periods for all checks on a multiple entities" do
|
232
|
+
start_time = Time.now + (60 * 60) # an hour from now
|
597
233
|
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
with(entity_2, 'bar', :redis => redis).and_return(bar_check)
|
234
|
+
check_2 = 'HOST'
|
235
|
+
entity_2 = double(Flapjack::Data::Entity)
|
236
|
+
entity_check_2 = double(Flapjack::Data::EntityCheck)
|
602
237
|
|
603
|
-
|
604
|
-
|
605
|
-
expect(last_response.body).to eq(result.to_json)
|
606
|
-
end
|
238
|
+
expect(entity_check).to receive(:end_scheduled_maintenance).with(start_time.to_i)
|
239
|
+
expect(entity_check_2).to receive(:end_scheduled_maintenance).with(start_time.to_i)
|
607
240
|
|
608
|
-
|
609
|
-
|
610
|
-
|
241
|
+
expect(Flapjack::Data::EntityCheck).to receive(:for_entity).
|
242
|
+
with(entity, check, :redis => redis).and_return(entity_check)
|
243
|
+
expect(Flapjack::Data::EntityCheck).to receive(:for_entity).
|
244
|
+
with(entity_2, check_2, :redis => redis).and_return(entity_check_2)
|
611
245
|
|
612
|
-
|
246
|
+
expect(entity).to receive(:check_list).and_return([check])
|
247
|
+
expect(Flapjack::Data::Entity).to receive(:find_by_id).
|
248
|
+
with(entity_id, :redis => redis).and_return(entity)
|
613
249
|
|
614
|
-
|
615
|
-
|
250
|
+
expect(entity_2).to receive(:check_list).and_return([check_2])
|
251
|
+
expect(Flapjack::Data::Entity).to receive(:find_by_id).
|
252
|
+
with('873', :redis => redis).and_return(entity_2)
|
616
253
|
|
617
|
-
|
618
|
-
|
254
|
+
adelete "/scheduled_maintenances/entities/#{entity_id},873",
|
255
|
+
:start_time => start_time.iso8601
|
256
|
+
expect(last_response.status).to eq(204)
|
257
|
+
end
|
619
258
|
|
620
|
-
|
621
|
-
|
259
|
+
it "creates test notification events for all checks on an entity" do
|
260
|
+
expect(entity).to receive(:check_list).and_return([check, 'foo'])
|
261
|
+
expect(entity).to receive(:name).twice.and_return(entity_name)
|
262
|
+
expect(Flapjack::Data::Entity).to receive(:find_by_id).
|
263
|
+
with(entity_id, :redis => redis).and_return(entity)
|
622
264
|
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
end
|
265
|
+
expect(entity_check).to receive(:entity).and_return(entity)
|
266
|
+
expect(entity_check).to receive(:entity_name).and_return(entity_name)
|
267
|
+
expect(entity_check).to receive(:check).and_return(check)
|
627
268
|
|
628
|
-
|
629
|
-
|
630
|
-
result = [{:entity => entity_name, :check => check, :downtime => downtime}]
|
269
|
+
expect(Flapjack::Data::EntityCheck).to receive(:for_entity).
|
270
|
+
with(entity, check, :redis => redis).and_return(entity_check)
|
631
271
|
|
632
|
-
|
272
|
+
entity_check_2 = double(Flapjack::Data::EntityCheck)
|
273
|
+
expect(entity_check_2).to receive(:entity).and_return(entity)
|
274
|
+
expect(entity_check_2).to receive(:entity_name).and_return(entity_name)
|
275
|
+
expect(entity_check_2).to receive(:check).and_return('foo')
|
633
276
|
|
634
|
-
|
635
|
-
|
277
|
+
expect(Flapjack::Data::EntityCheck).to receive(:for_entity).
|
278
|
+
with(entity, 'foo', :redis => redis).and_return(entity_check_2)
|
636
279
|
|
637
|
-
|
638
|
-
|
280
|
+
expect(Flapjack::Data::Event).to receive(:test_notifications).
|
281
|
+
with(entity_name, check, hash_including(:redis => redis))
|
639
282
|
|
640
|
-
|
641
|
-
|
642
|
-
expect(last_response.body).to eq(result.to_json)
|
643
|
-
end
|
644
|
-
|
645
|
-
it "returns a list of downtimes for a check on an entity" do
|
646
|
-
downtime = double('downtime')
|
647
|
-
result = [{:entity => entity_name, :check => check, :downtime => downtime}]
|
648
|
-
|
649
|
-
expect(entity_check_presenter).to receive(:downtime).with(nil, nil).and_return(downtime)
|
650
|
-
|
651
|
-
expect(Flapjack::Gateways::JSONAPI::EntityCheckPresenter).to receive(:new).
|
652
|
-
with(entity_check).and_return(entity_check_presenter)
|
653
|
-
|
654
|
-
expect(Flapjack::Data::EntityCheck).to receive(:for_entity).
|
655
|
-
with(entity, check, :redis => redis).and_return(entity_check)
|
656
|
-
|
657
|
-
expect(Flapjack::Data::Entity).to receive(:find_by_name).
|
658
|
-
with(entity_name, :redis => redis).and_return(entity)
|
659
|
-
|
660
|
-
aget "/downtime", :check => {entity_name => check}
|
661
|
-
expect(last_response).to be_ok
|
662
|
-
expect(last_response.body).to eq(result.to_json)
|
663
|
-
end
|
664
|
-
|
665
|
-
it "creates test notification events for all checks on an entity" do
|
666
|
-
expect(entity).to receive(:check_list).and_return([check, 'foo'])
|
667
|
-
expect(entity).to receive(:name).twice.and_return(entity_name)
|
668
|
-
expect(Flapjack::Data::Entity).to receive(:find_by_name).
|
669
|
-
with(entity_name, :redis => redis).and_return(entity)
|
670
|
-
|
671
|
-
expect(entity_check).to receive(:entity).and_return(entity)
|
672
|
-
expect(entity_check).to receive(:entity_name).and_return(entity_name)
|
673
|
-
expect(entity_check).to receive(:check).and_return(check)
|
674
|
-
|
675
|
-
expect(Flapjack::Data::EntityCheck).to receive(:for_entity).
|
676
|
-
with(entity, check, :redis => redis).and_return(entity_check)
|
677
|
-
|
678
|
-
entity_check_2 = double(Flapjack::Data::EntityCheck)
|
679
|
-
expect(entity_check_2).to receive(:entity).and_return(entity)
|
680
|
-
expect(entity_check_2).to receive(:entity_name).and_return(entity_name)
|
681
|
-
expect(entity_check_2).to receive(:check).and_return('foo')
|
682
|
-
|
683
|
-
expect(Flapjack::Data::EntityCheck).to receive(:for_entity).
|
684
|
-
with(entity, 'foo', :redis => redis).and_return(entity_check_2)
|
685
|
-
|
686
|
-
expect(Flapjack::Data::Event).to receive(:test_notifications).
|
687
|
-
with(entity_name, check, hash_including(:redis => redis))
|
688
|
-
|
689
|
-
expect(Flapjack::Data::Event).to receive(:test_notifications).
|
690
|
-
with(entity_name, 'foo', hash_including(:redis => redis))
|
691
|
-
|
692
|
-
apost '/test_notifications', :entity => entity_name
|
693
|
-
expect(last_response.status).to eq(204)
|
694
|
-
end
|
695
|
-
|
696
|
-
it "creates a test notification event for check on an entity" do
|
697
|
-
expect(Flapjack::Data::Entity).to receive(:find_by_name).
|
698
|
-
with(entity_name, :redis => redis).and_return(entity)
|
699
|
-
expect(entity).to receive(:name).and_return(entity_name)
|
700
|
-
expect(entity_check).to receive(:entity).and_return(entity)
|
701
|
-
expect(entity_check).to receive(:entity_name).and_return(entity_name)
|
702
|
-
expect(entity_check).to receive(:check).and_return(check)
|
703
|
-
expect(Flapjack::Data::EntityCheck).to receive(:for_entity).
|
704
|
-
with(entity, check, :redis => redis).and_return(entity_check)
|
705
|
-
|
706
|
-
expect(Flapjack::Data::Event).to receive(:test_notifications).
|
707
|
-
with(entity_name, check, hash_including(:redis => redis))
|
708
|
-
|
709
|
-
apost '/test_notifications', :check => {entity_name => check}
|
710
|
-
expect(last_response.status).to eq(204)
|
711
|
-
end
|
712
|
-
|
713
|
-
it "creates entities from a submitted list" do
|
714
|
-
entities = {'entities' =>
|
715
|
-
[
|
716
|
-
{"id" => "10001",
|
717
|
-
"name" => "clientx-app-01",
|
718
|
-
"contacts" => ["0362","0363","0364"]
|
719
|
-
},
|
720
|
-
{"id" => "10002",
|
721
|
-
"name" => "clientx-app-02",
|
722
|
-
"contacts" => ["0362"]
|
723
|
-
}
|
724
|
-
]
|
725
|
-
}
|
726
|
-
expect(Flapjack::Data::Entity).to receive(:add).twice
|
727
|
-
|
728
|
-
apost "/entities", entities.to_json, {'CONTENT_TYPE' => 'application/json'}
|
729
|
-
expect(last_response.status).to eq(204)
|
730
|
-
end
|
731
|
-
|
732
|
-
it "does not create entities if the data is improperly formatted" do
|
733
|
-
expect(Flapjack::Data::Entity).not_to receive(:add)
|
734
|
-
|
735
|
-
apost "/entities", {'entities' => ["Hello", "there"]}.to_json,
|
736
|
-
{'CONTENT_TYPE' => 'application/json'}
|
737
|
-
expect(last_response.status).to eq(403)
|
738
|
-
end
|
739
|
-
|
740
|
-
it "does not create entities if they don't contain an id" do
|
741
|
-
entities = {'entities' =>
|
742
|
-
[
|
743
|
-
{"id" => "10001",
|
744
|
-
"name" => "clientx-app-01",
|
745
|
-
"contacts" => ["0362","0363","0364"]
|
746
|
-
},
|
747
|
-
{"name" => "clientx-app-02",
|
748
|
-
"contacts" => ["0362"]
|
749
|
-
}
|
750
|
-
]
|
751
|
-
}
|
752
|
-
expect(Flapjack::Data::Entity).to receive(:add)
|
753
|
-
|
754
|
-
apost "/entities", entities.to_json, {'CONTENT_TYPE' => 'application/json'}
|
755
|
-
expect(last_response.status).to eq(403)
|
756
|
-
end
|
283
|
+
expect(Flapjack::Data::Event).to receive(:test_notifications).
|
284
|
+
with(entity_name, 'foo', hash_including(:redis => redis))
|
757
285
|
|
286
|
+
apost "/test_notifications/entities/#{entity_id}"
|
287
|
+
expect(last_response.status).to eq(204)
|
758
288
|
end
|
759
289
|
|
760
290
|
end
|