flapjack 1.1.0 → 1.2.0rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.ruby-version +1 -1
- data/.travis.yml +12 -7
- data/CHANGELOG.md +12 -0
- data/Gemfile +6 -2
- data/Gemfile-ruby1.9 +29 -0
- data/Gemfile-ruby1.9.lock +251 -0
- data/README.md +2 -2
- data/Rakefile +1 -0
- data/etc/flapjack_config.yaml.example +2 -2
- data/features/steps/events_steps.rb +2 -2
- data/features/steps/flapjack-netsaint-parser_steps.rb +1 -1
- data/features/support/env.rb +1 -6
- data/lib/flapjack/cli/import.rb +2 -5
- data/lib/flapjack/cli/purge.rb +4 -4
- data/lib/flapjack/cli/receiver.rb +122 -54
- data/lib/flapjack/cli/server.rb +0 -5
- data/lib/flapjack/coordinator.rb +6 -0
- data/lib/flapjack/data/contact.rb +10 -62
- data/lib/flapjack/data/entity.rb +36 -52
- data/lib/flapjack/data/entity_check.rb +90 -21
- data/lib/flapjack/data/event.rb +4 -5
- data/lib/flapjack/data/notification.rb +8 -10
- data/lib/flapjack/data/notification_rule.rb +32 -35
- data/lib/flapjack/data/tagged.rb +48 -0
- data/lib/flapjack/gateways/jabber.rb +4 -5
- data/lib/flapjack/gateways/jsonapi/check_methods.rb +45 -7
- data/lib/flapjack/gateways/jsonapi/check_presenter.rb +1 -1
- data/lib/flapjack/gateways/jsonapi/contact_methods.rb +8 -2
- data/lib/flapjack/gateways/jsonapi/entity_methods.rb +26 -8
- data/lib/flapjack/gateways/jsonapi/medium_methods.rb +13 -9
- data/lib/flapjack/gateways/jsonapi/metrics_methods.rb +2 -2
- data/lib/flapjack/gateways/jsonapi/notification_rule_methods.rb +1 -1
- data/lib/flapjack/gateways/jsonapi/pagerduty_credential_methods.rb +24 -17
- data/lib/flapjack/gateways/jsonapi/rack/json_params_parser.rb +1 -1
- data/lib/flapjack/gateways/jsonapi/report_methods.rb +4 -4
- data/lib/flapjack/gateways/jsonapi.rb +52 -31
- data/lib/flapjack/gateways/oobetet.rb +2 -3
- data/lib/flapjack/gateways/pagerduty.rb +9 -8
- data/lib/flapjack/gateways/web/public/js/backbone.jsonapi.js +19 -0
- data/lib/flapjack/gateways/web/public/js/flapjack.js +6 -2
- data/lib/flapjack/gateways/web/public/js/modules/contact.js +9 -14
- data/lib/flapjack/gateways/web/public/js/modules/medium.js +1 -0
- data/lib/flapjack/gateways/web/public/js/self_stats.js +1 -1
- data/lib/flapjack/gateways/web/views/edit_contacts.html.erb +3 -3
- data/lib/flapjack/gateways/web.rb +8 -7
- data/lib/flapjack/notifier.rb +2 -4
- data/lib/flapjack/processor.rb +2 -2
- data/lib/flapjack/version.rb +1 -1
- data/lib/flapjack.rb +10 -0
- data/spec/lib/flapjack/coordinator_spec.rb +18 -0
- data/spec/lib/flapjack/data/contact_spec.rb +4 -12
- data/spec/lib/flapjack/data/entity_check_spec.rb +56 -3
- data/spec/lib/flapjack/data/entity_spec.rb +79 -67
- data/spec/lib/flapjack/data/event_spec.rb +78 -78
- data/spec/lib/flapjack/data/notification_rule_spec.rb +4 -2
- data/spec/lib/flapjack/gateways/jsonapi/check_methods_spec.rb +94 -11
- data/spec/lib/flapjack/gateways/jsonapi/entity_methods_spec.rb +84 -0
- data/spec/lib/flapjack/gateways/pagerduty_spec.rb +5 -3
- data/spec/lib/flapjack/gateways/web_spec.rb +3 -3
- data/spec/service_consumers/pact_helper.rb +74 -0
- data/spec/service_consumers/pacts/flapjack-diner_v1.0.json +4522 -0
- data/spec/service_consumers/provider_states_for_flapjack-diner.rb +356 -0
- data/spec/spec_helper.rb +0 -8
- data/spec/support/jsonapi_helper.rb +1 -1
- data/tasks/benchmarks.rake +6 -3
- data/tasks/profile.rake +1 -1
- data/tmp/acknowledge.rb +0 -3
- data/tmp/create_event_ok.rb +0 -3
- data/tmp/create_event_unknown.rb +0 -3
- data/tmp/create_events_failure.rb +0 -3
- data/tmp/create_events_ok.rb +0 -3
- data/tmp/create_events_ok_fail_ack_ok.rb +0 -3
- data/tmp/create_events_ok_failure.rb +2 -5
- data/tmp/create_events_ok_failure_ack.rb +0 -3
- data/tmp/test_json_post.rb +4 -3
- data/tmp/test_notification_rules_api.rb +2 -3
- metadata +13 -8
- data/lib/flapjack/data/tag.rb +0 -61
- data/lib/flapjack/data/tag_set.rb +0 -16
- data/spec/lib/flapjack/data/tag_spec.rb +0 -36
@@ -5,7 +5,7 @@ describe Flapjack::Data::Event do
|
|
5
5
|
|
6
6
|
let(:entity_name) { 'xyz-example.com' }
|
7
7
|
let(:check) { 'ping' }
|
8
|
-
let(:
|
8
|
+
let(:redis) { double(::Redis) }
|
9
9
|
|
10
10
|
let!(:time) { Time.now}
|
11
11
|
|
@@ -25,66 +25,66 @@ describe Flapjack::Data::Event do
|
|
25
25
|
context 'class' do
|
26
26
|
|
27
27
|
it "returns the next event (blocking, archiving)" do
|
28
|
-
expect(
|
28
|
+
expect(redis).to receive(:brpoplpush).
|
29
29
|
with('events', /^events_archive:/, 0).and_return(event_data.to_json)
|
30
|
-
expect(
|
30
|
+
expect(redis).to receive(:expire)
|
31
31
|
|
32
32
|
result = Flapjack::Data::Event.next('events', :block => true,
|
33
|
-
:archive_events => true, :redis =>
|
33
|
+
:archive_events => true, :redis => redis)
|
34
34
|
expect(result).to be_an_instance_of(Flapjack::Data::Event)
|
35
35
|
end
|
36
36
|
|
37
37
|
it "returns the next event (blocking, not archiving)" do
|
38
|
-
expect(
|
38
|
+
expect(redis).to receive(:brpop).with('events', 0).
|
39
39
|
and_return(['events', event_data.to_json])
|
40
40
|
|
41
41
|
result = Flapjack::Data::Event.next('events',:block => true,
|
42
|
-
:archive_events => false, :redis =>
|
42
|
+
:archive_events => false, :redis => redis)
|
43
43
|
expect(result).to be_an_instance_of(Flapjack::Data::Event)
|
44
44
|
end
|
45
45
|
|
46
46
|
it "returns the next event (non-blocking, archiving)" do
|
47
|
-
expect(
|
47
|
+
expect(redis).to receive(:rpoplpush).
|
48
48
|
with('events', /^events_archive:/).and_return(event_data.to_json)
|
49
|
-
expect(
|
49
|
+
expect(redis).to receive(:expire)
|
50
50
|
|
51
51
|
result = Flapjack::Data::Event.next('events', :block => false,
|
52
|
-
:archive_events => true, :redis =>
|
52
|
+
:archive_events => true, :redis => redis)
|
53
53
|
expect(result).to be_an_instance_of(Flapjack::Data::Event)
|
54
54
|
end
|
55
55
|
|
56
56
|
it "returns the next event (non-blocking, not archiving)" do
|
57
|
-
expect(
|
57
|
+
expect(redis).to receive(:rpop).with('events').
|
58
58
|
and_return(event_data.to_json)
|
59
59
|
|
60
60
|
result = Flapjack::Data::Event.next('events', :block => false,
|
61
|
-
:archive_events => false, :redis =>
|
61
|
+
:archive_events => false, :redis => redis)
|
62
62
|
expect(result).to be_an_instance_of(Flapjack::Data::Event)
|
63
63
|
end
|
64
64
|
|
65
65
|
it "rejects invalid event JSON (archiving)" do
|
66
66
|
bad_event_json = '{{{'
|
67
|
-
expect(
|
67
|
+
expect(redis).to receive(:brpoplpush).
|
68
68
|
with('events', /^events_archive:/, 0).and_return(bad_event_json)
|
69
|
-
expect(
|
70
|
-
expect(
|
71
|
-
expect(
|
72
|
-
expect(
|
73
|
-
expect(
|
69
|
+
expect(redis).to receive(:multi)
|
70
|
+
expect(redis).to receive(:lrem).with(/^events_archive:/, 1, bad_event_json)
|
71
|
+
expect(redis).to receive(:lpush).with(/^events_rejected:/, bad_event_json)
|
72
|
+
expect(redis).to receive(:exec)
|
73
|
+
expect(redis).to receive(:expire)
|
74
74
|
|
75
75
|
result = Flapjack::Data::Event.next('events', :block => true,
|
76
|
-
:archive_events => true, :redis =>
|
76
|
+
:archive_events => true, :redis => redis)
|
77
77
|
expect(result).to be_nil
|
78
78
|
end
|
79
79
|
|
80
80
|
it "rejects invalid event JSON (not archiving)" do
|
81
81
|
bad_event_json = '{{{'
|
82
|
-
expect(
|
82
|
+
expect(redis).to receive(:brpop).with('events', 0).
|
83
83
|
and_return(['events', bad_event_json])
|
84
|
-
expect(
|
84
|
+
expect(redis).to receive(:lpush).with(/^events_rejected:/, bad_event_json)
|
85
85
|
|
86
86
|
result = Flapjack::Data::Event.next('events', :block => true,
|
87
|
-
:archive_events => false, :redis =>
|
87
|
+
:archive_events => false, :redis => redis)
|
88
88
|
expect(result).to be_nil
|
89
89
|
end
|
90
90
|
|
@@ -94,16 +94,16 @@ describe Flapjack::Data::Event do
|
|
94
94
|
bad_event_data = event_data.clone
|
95
95
|
bad_event_data.delete(required_key)
|
96
96
|
bad_event_json = bad_event_data.to_json
|
97
|
-
expect(
|
97
|
+
expect(redis).to receive(:brpoplpush).
|
98
98
|
with('events', /^events_archive:/, 0).and_return(bad_event_json)
|
99
|
-
expect(
|
100
|
-
expect(
|
101
|
-
expect(
|
102
|
-
expect(
|
103
|
-
expect(
|
99
|
+
expect(redis).to receive(:multi)
|
100
|
+
expect(redis).to receive(:lrem).with(/^events_archive:/, 1, bad_event_json)
|
101
|
+
expect(redis).to receive(:lpush).with(/^events_rejected:/, bad_event_json)
|
102
|
+
expect(redis).to receive(:exec)
|
103
|
+
expect(redis).to receive(:expire)
|
104
104
|
|
105
105
|
result = Flapjack::Data::Event.next('events', :block => true,
|
106
|
-
:archive_events => true, :redis =>
|
106
|
+
:archive_events => true, :redis => redis)
|
107
107
|
expect(result).to be_nil
|
108
108
|
end
|
109
109
|
|
@@ -111,12 +111,12 @@ describe Flapjack::Data::Event do
|
|
111
111
|
bad_event_data = event_data.clone
|
112
112
|
bad_event_data.delete(required_key)
|
113
113
|
bad_event_json = bad_event_data.to_json
|
114
|
-
expect(
|
114
|
+
expect(redis).to receive(:brpop).with('events', 0).
|
115
115
|
and_return(['events', bad_event_json])
|
116
|
-
expect(
|
116
|
+
expect(redis).to receive(:lpush).with(/^events_rejected:/, bad_event_json)
|
117
117
|
|
118
118
|
result = Flapjack::Data::Event.next('events', :block => true,
|
119
|
-
:archive_events => false, :redis =>
|
119
|
+
:archive_events => false, :redis => redis)
|
120
120
|
expect(result).to be_nil
|
121
121
|
end
|
122
122
|
|
@@ -124,16 +124,16 @@ describe Flapjack::Data::Event do
|
|
124
124
|
bad_event_data = event_data.clone
|
125
125
|
bad_event_data[required_key] = {'hello' => 'there'}
|
126
126
|
bad_event_json = bad_event_data.to_json
|
127
|
-
expect(
|
127
|
+
expect(redis).to receive(:brpoplpush).
|
128
128
|
with('events', /^events_archive:/, 0).and_return(bad_event_json)
|
129
|
-
expect(
|
130
|
-
expect(
|
131
|
-
expect(
|
132
|
-
expect(
|
133
|
-
expect(
|
129
|
+
expect(redis).to receive(:multi)
|
130
|
+
expect(redis).to receive(:lrem).with(/^events_archive:/, 1, bad_event_json)
|
131
|
+
expect(redis).to receive(:lpush).with(/^events_rejected:/, bad_event_json)
|
132
|
+
expect(redis).to receive(:exec)
|
133
|
+
expect(redis).to receive(:expire)
|
134
134
|
|
135
135
|
result = Flapjack::Data::Event.next('events', :block => true,
|
136
|
-
:archive_events => true, :redis =>
|
136
|
+
:archive_events => true, :redis => redis)
|
137
137
|
expect(result).to be_nil
|
138
138
|
end
|
139
139
|
|
@@ -141,12 +141,12 @@ describe Flapjack::Data::Event do
|
|
141
141
|
bad_event_data = event_data.clone
|
142
142
|
bad_event_data[required_key] = {'hello' => 'there'}
|
143
143
|
bad_event_json = bad_event_data.to_json
|
144
|
-
expect(
|
144
|
+
expect(redis).to receive(:brpop).with('events', 0).
|
145
145
|
and_return(['events', bad_event_json])
|
146
|
-
expect(
|
146
|
+
expect(redis).to receive(:lpush).with(/^events_rejected:/, bad_event_json)
|
147
147
|
|
148
148
|
result = Flapjack::Data::Event.next('events', :block => true,
|
149
|
-
:archive_events => false, :redis =>
|
149
|
+
:archive_events => false, :redis => redis)
|
150
150
|
expect(result).to be_nil
|
151
151
|
end
|
152
152
|
end
|
@@ -156,16 +156,16 @@ describe Flapjack::Data::Event do
|
|
156
156
|
bad_event_data = event_data.clone
|
157
157
|
bad_event_data[optional_key] = {'hello' => 'there'}
|
158
158
|
bad_event_json = bad_event_data.to_json
|
159
|
-
expect(
|
159
|
+
expect(redis).to receive(:brpoplpush).
|
160
160
|
with('events', /^events_archive:/, 0).and_return(bad_event_json)
|
161
|
-
expect(
|
162
|
-
expect(
|
163
|
-
expect(
|
164
|
-
expect(
|
165
|
-
expect(
|
161
|
+
expect(redis).to receive(:multi)
|
162
|
+
expect(redis).to receive(:lrem).with(/^events_archive:/, 1, bad_event_json)
|
163
|
+
expect(redis).to receive(:lpush).with(/^events_rejected:/, bad_event_json)
|
164
|
+
expect(redis).to receive(:exec)
|
165
|
+
expect(redis).to receive(:expire)
|
166
166
|
|
167
167
|
result = Flapjack::Data::Event.next('events', :block => true,
|
168
|
-
:archive_events => true, :redis =>
|
168
|
+
:archive_events => true, :redis => redis)
|
169
169
|
expect(result).to be_nil
|
170
170
|
end
|
171
171
|
|
@@ -173,12 +173,12 @@ describe Flapjack::Data::Event do
|
|
173
173
|
bad_event_data = event_data.clone
|
174
174
|
bad_event_data[optional_key] = {'hello' => 'there'}
|
175
175
|
bad_event_json = bad_event_data.to_json
|
176
|
-
expect(
|
176
|
+
expect(redis).to receive(:brpop).with('events', 0).
|
177
177
|
and_return(['events', bad_event_json])
|
178
|
-
expect(
|
178
|
+
expect(redis).to receive(:lpush).with(/^events_rejected:/, bad_event_json)
|
179
179
|
|
180
180
|
result = Flapjack::Data::Event.next('events', :block => true,
|
181
|
-
:archive_events => false, :redis =>
|
181
|
+
:archive_events => false, :redis => redis)
|
182
182
|
expect(result).to be_nil
|
183
183
|
end
|
184
184
|
end
|
@@ -188,23 +188,23 @@ describe Flapjack::Data::Event do
|
|
188
188
|
it "it matches case-insensitively for #{key} (archiving)" do
|
189
189
|
case_event_data = event_data.clone
|
190
190
|
case_event_data[key] = event_data[key].upcase
|
191
|
-
expect(
|
191
|
+
expect(redis).to receive(:brpoplpush).
|
192
192
|
with('events', /^events_archive:/, 0).and_return(case_event_data.to_json)
|
193
|
-
expect(
|
193
|
+
expect(redis).to receive(:expire)
|
194
194
|
|
195
195
|
result = Flapjack::Data::Event.next('events', :block => true,
|
196
|
-
:archive_events => true, :redis =>
|
196
|
+
:archive_events => true, :redis => redis)
|
197
197
|
expect(result).to be_an_instance_of(Flapjack::Data::Event)
|
198
198
|
end
|
199
199
|
|
200
200
|
it "it matches case-insensitively for #{key} (not archiving)" do
|
201
201
|
case_event_data = event_data.clone
|
202
202
|
case_event_data[key] = event_data[key].upcase
|
203
|
-
expect(
|
203
|
+
expect(redis).to receive(:brpop).with('events', 0).
|
204
204
|
and_return(['events', case_event_data.to_json])
|
205
205
|
|
206
206
|
result = Flapjack::Data::Event.next('events',:block => true,
|
207
|
-
:archive_events => false, :redis =>
|
207
|
+
:archive_events => false, :redis => redis)
|
208
208
|
expect(result).to be_an_instance_of(Flapjack::Data::Event)
|
209
209
|
end
|
210
210
|
end
|
@@ -214,23 +214,23 @@ describe Flapjack::Data::Event do
|
|
214
214
|
it "it accepts an event with a numeric #{key} key (archiving)" do
|
215
215
|
num_event_data = event_data.clone
|
216
216
|
num_event_data[key] = event_data[key].to_i.to_s
|
217
|
-
expect(
|
217
|
+
expect(redis).to receive(:brpoplpush).
|
218
218
|
with('events', /^events_archive:/, 0).and_return(num_event_data.to_json)
|
219
|
-
expect(
|
219
|
+
expect(redis).to receive(:expire)
|
220
220
|
|
221
221
|
result = Flapjack::Data::Event.next('events', :block => true,
|
222
|
-
:archive_events => true, :redis =>
|
222
|
+
:archive_events => true, :redis => redis)
|
223
223
|
expect(result).to be_an_instance_of(Flapjack::Data::Event)
|
224
224
|
end
|
225
225
|
|
226
226
|
it "it accepts an event with a numeric #{key} key (not archiving)" do
|
227
227
|
num_event_data = event_data.clone
|
228
228
|
num_event_data[key] = event_data[key].to_i.to_s
|
229
|
-
expect(
|
229
|
+
expect(redis).to receive(:brpop).with('events', 0).
|
230
230
|
and_return(['events', num_event_data.to_json])
|
231
231
|
|
232
232
|
result = Flapjack::Data::Event.next('events',:block => true,
|
233
|
-
:archive_events => false, :redis =>
|
233
|
+
:archive_events => false, :redis => redis)
|
234
234
|
expect(result).to be_an_instance_of(Flapjack::Data::Event)
|
235
235
|
end
|
236
236
|
|
@@ -238,16 +238,16 @@ describe Flapjack::Data::Event do
|
|
238
238
|
bad_event_data = event_data.clone
|
239
239
|
bad_event_data[key] = 'NaN'
|
240
240
|
bad_event_json = bad_event_data.to_json
|
241
|
-
expect(
|
241
|
+
expect(redis).to receive(:brpoplpush).
|
242
242
|
with('events', /^events_archive:/, 0).and_return(bad_event_json)
|
243
|
-
expect(
|
244
|
-
expect(
|
245
|
-
expect(
|
246
|
-
expect(
|
247
|
-
expect(
|
243
|
+
expect(redis).to receive(:multi)
|
244
|
+
expect(redis).to receive(:lrem).with(/^events_archive:/, 1, bad_event_json)
|
245
|
+
expect(redis).to receive(:lpush).with(/^events_rejected:/, bad_event_json)
|
246
|
+
expect(redis).to receive(:exec)
|
247
|
+
expect(redis).to receive(:expire)
|
248
248
|
|
249
249
|
result = Flapjack::Data::Event.next('events', :block => true,
|
250
|
-
:archive_events => true, :redis =>
|
250
|
+
:archive_events => true, :redis => redis)
|
251
251
|
expect(result).to be_nil
|
252
252
|
end
|
253
253
|
|
@@ -255,12 +255,12 @@ describe Flapjack::Data::Event do
|
|
255
255
|
bad_event_data = event_data.clone
|
256
256
|
bad_event_data[key] = 'NaN'
|
257
257
|
bad_event_json = bad_event_data.to_json
|
258
|
-
expect(
|
258
|
+
expect(redis).to receive(:brpop).with('events', 0).
|
259
259
|
and_return(['events', bad_event_json])
|
260
|
-
expect(
|
260
|
+
expect(redis).to receive(:lpush).with(/^events_rejected:/, bad_event_json)
|
261
261
|
|
262
262
|
result = Flapjack::Data::Event.next('events', :block => true,
|
263
|
-
:archive_events => false, :redis =>
|
263
|
+
:archive_events => false, :redis => redis)
|
264
264
|
expect(result).to be_nil
|
265
265
|
end
|
266
266
|
|
@@ -268,26 +268,26 @@ describe Flapjack::Data::Event do
|
|
268
268
|
|
269
269
|
it "returns a count of pending events" do
|
270
270
|
events_len = 23
|
271
|
-
expect(
|
271
|
+
expect(redis).to receive(:llen).with('events').and_return(events_len)
|
272
272
|
|
273
|
-
pc = Flapjack::Data::Event.pending_count('events', :redis =>
|
273
|
+
pc = Flapjack::Data::Event.pending_count('events', :redis => redis)
|
274
274
|
expect(pc).to eq(events_len)
|
275
275
|
end
|
276
276
|
|
277
277
|
it "creates a notification testing event" do
|
278
278
|
expect(Time).to receive(:now).and_return(time)
|
279
|
-
expect(
|
279
|
+
expect(redis).to receive(:lpush).with('events', /"testing"/ )
|
280
280
|
|
281
281
|
Flapjack::Data::Event.test_notifications(entity_name, check,
|
282
|
-
:summary => 'test', :details => 'testing', :redis =>
|
282
|
+
:summary => 'test', :details => 'testing', :redis => redis)
|
283
283
|
end
|
284
284
|
|
285
285
|
it "creates an acknowledgement event" do
|
286
286
|
expect(Time).to receive(:now).and_return(time)
|
287
|
-
expect(
|
287
|
+
expect(redis).to receive(:lpush).with('events', /"acking"/ )
|
288
288
|
|
289
289
|
Flapjack::Data::Event.create_acknowledgement(entity_name, check,
|
290
|
-
:summary => 'acking', :time => time.to_i, :redis =>
|
290
|
+
:summary => 'acking', :time => time.to_i, :redis => redis)
|
291
291
|
end
|
292
292
|
|
293
293
|
end
|
@@ -302,7 +302,7 @@ describe Flapjack::Data::Event do
|
|
302
302
|
expect(event.time).to eq(event_data['time'])
|
303
303
|
expect(event.id).to eq('xyz-example.com:ping')
|
304
304
|
expect(event.type).to eq('service')
|
305
|
-
expect(event.tags).to be_an_instance_of(
|
305
|
+
expect(event.tags).to be_an_instance_of(Set)
|
306
306
|
expect(event.tags).to include('dev')
|
307
307
|
expect(event.tags).to_not include('prod')
|
308
308
|
|
@@ -90,8 +90,10 @@ describe Flapjack::Data::NotificationRule, :redis => true do
|
|
90
90
|
|
91
91
|
it "generates a JSON string representing its data" do
|
92
92
|
rule = existing_rule
|
93
|
-
# bit of extra hackery for the
|
94
|
-
|
93
|
+
# bit of extra hackery for the ID values
|
94
|
+
munged = {:id => rule.id}.merge(rule_data)
|
95
|
+
munged[:links] = {:contacts => [munged.delete(:contact_id)]}
|
96
|
+
expect(rule.to_jsonapi).to eq(Flapjack.dump_json(munged))
|
95
97
|
end
|
96
98
|
|
97
99
|
it "checks whether entity names match" do
|
@@ -18,12 +18,16 @@ describe 'Flapjack::Gateways::JSONAPI::CheckMethods', :sinatra => true, :logger
|
|
18
18
|
|
19
19
|
it "retrieves all checks" do
|
20
20
|
expect(entity).to receive(:id).and_return('23')
|
21
|
+
expect(entity).to receive(:name).exactly(3).times.and_return('www.example.net')
|
21
22
|
|
22
|
-
expect(
|
23
|
-
|
23
|
+
expect(Flapjack::Data::EntityCheck).to receive(:enabled_for).
|
24
|
+
with(['www.example.net:PING'], :redis => redis).and_return(['www.example.net:PING'])
|
25
|
+
|
26
|
+
expect(entity_check).to receive(:entity).exactly(3).times.and_return(entity)
|
27
|
+
expect(entity_check).to receive(:check).exactly(3).times.and_return('PING')
|
24
28
|
expect(entity_check).to receive(:to_jsonapi).and_return(check_data.to_json)
|
25
|
-
expect(Flapjack::Data::EntityCheck).to receive(:
|
26
|
-
and_return([entity_check])
|
29
|
+
expect(Flapjack::Data::EntityCheck).to receive(:all).
|
30
|
+
with(:logger => @logger, :redis => redis).and_return([entity_check])
|
27
31
|
|
28
32
|
aget '/checks'
|
29
33
|
expect(last_response).to be_ok
|
@@ -32,9 +36,13 @@ describe 'Flapjack::Gateways::JSONAPI::CheckMethods', :sinatra => true, :logger
|
|
32
36
|
|
33
37
|
it "retrieves one check" do
|
34
38
|
expect(entity).to receive(:id).and_return('23')
|
39
|
+
expect(entity).to receive(:name).exactly(3).times.and_return('www.example.net')
|
35
40
|
|
36
|
-
expect(
|
37
|
-
|
41
|
+
expect(Flapjack::Data::EntityCheck).to receive(:enabled_for).
|
42
|
+
with(['www.example.net:PING'], :redis => redis).and_return(['www.example.net:PING'])
|
43
|
+
|
44
|
+
expect(entity_check).to receive(:entity).exactly(3).times.and_return(entity)
|
45
|
+
expect(entity_check).to receive(:check).exactly(3).times.and_return('PING')
|
38
46
|
expect(entity_check).to receive(:to_jsonapi).and_return(check_data.to_json)
|
39
47
|
expect(Flapjack::Data::EntityCheck).to receive(:for_event_id).
|
40
48
|
with('www.example.com:PING', :logger => @logger, :redis => redis).
|
@@ -45,22 +53,27 @@ describe 'Flapjack::Gateways::JSONAPI::CheckMethods', :sinatra => true, :logger
|
|
45
53
|
expect(last_response.body).to eq({:checks => [check_data]}.to_json)
|
46
54
|
end
|
47
55
|
|
48
|
-
it "retrieves several
|
56
|
+
it "retrieves several checks" do
|
49
57
|
entity_check_2 = double(Flapjack::Data::EntityCheck)
|
50
58
|
check_data_2 = {'name' => 'SSH',
|
51
59
|
'entity_name' => 'www.example.com'}
|
52
60
|
|
53
61
|
expect(entity).to receive(:id).twice.and_return('23')
|
62
|
+
expect(entity).to receive(:name).exactly(6).times.and_return('www.example.net')
|
54
63
|
|
55
|
-
expect(
|
56
|
-
|
64
|
+
expect(Flapjack::Data::EntityCheck).to receive(:enabled_for).
|
65
|
+
with(['www.example.net:PING', 'www.example.net:SSH'], :redis => redis).
|
66
|
+
and_return(['www.example.net:PING', 'www.example.net:SSH'])
|
67
|
+
|
68
|
+
expect(entity_check).to receive(:entity).exactly(3).times.and_return(entity)
|
69
|
+
expect(entity_check).to receive(:check).exactly(3).times.and_return('PING')
|
57
70
|
expect(entity_check).to receive(:to_jsonapi).and_return(check_data.to_json)
|
58
71
|
expect(Flapjack::Data::EntityCheck).to receive(:for_event_id).
|
59
72
|
with('www.example.com:PING', :logger => @logger, :redis => redis).
|
60
73
|
and_return(entity_check)
|
61
74
|
|
62
|
-
expect(entity_check_2).to receive(:entity).and_return(entity)
|
63
|
-
expect(entity_check_2).to receive(:
|
75
|
+
expect(entity_check_2).to receive(:entity).exactly(3).times.and_return(entity)
|
76
|
+
expect(entity_check_2).to receive(:check).exactly(3).times.and_return('SSH')
|
64
77
|
expect(entity_check_2).to receive(:to_jsonapi).and_return(check_data_2.to_json)
|
65
78
|
expect(Flapjack::Data::EntityCheck).to receive(:for_event_id).
|
66
79
|
with('www.example.com:SSH', :logger => @logger, :redis => redis).
|
@@ -70,6 +83,35 @@ describe 'Flapjack::Gateways::JSONAPI::CheckMethods', :sinatra => true, :logger
|
|
70
83
|
expect(last_response).to be_ok
|
71
84
|
expect(last_response.body).to eq({:checks => [check_data, check_data_2]}.to_json)
|
72
85
|
end
|
86
|
+
it "creates checks from a submitted list" do
|
87
|
+
checks = {'checks' =>
|
88
|
+
[
|
89
|
+
{"entity_id" => "10001",
|
90
|
+
"name" => "PING"
|
91
|
+
},
|
92
|
+
{"entity_id" => "10001",
|
93
|
+
"name" => "SSH"
|
94
|
+
}
|
95
|
+
]
|
96
|
+
}
|
97
|
+
|
98
|
+
entity_check_2 = double(Flapjack::Data::EntityCheck)
|
99
|
+
expect(entity).to receive(:name).twice.and_return('example.com')
|
100
|
+
|
101
|
+
expect(entity_check).to receive(:entity).and_return(entity)
|
102
|
+
expect(entity_check_2).to receive(:entity).and_return(entity)
|
103
|
+
|
104
|
+
expect(entity_check).to receive(:check).and_return('PING')
|
105
|
+
expect(entity_check_2).to receive(:check).and_return('SSH')
|
106
|
+
|
107
|
+
expect(Flapjack::Data::EntityCheck).to receive(:add).twice.
|
108
|
+
and_return(entity_check, entity_check_2)
|
109
|
+
|
110
|
+
apost "/checks", checks.to_json, jsonapi_post_env
|
111
|
+
expect(last_response.status).to eq(201)
|
112
|
+
expect(last_response.headers['Location']).to eq("http://example.org/checks/example.com:PING,example.com:SSH")
|
113
|
+
expect(last_response.body).to eq('["example.com:PING","example.com:SSH"]')
|
114
|
+
end
|
73
115
|
|
74
116
|
it 'disables a check' do
|
75
117
|
expect(Flapjack::Data::Entity).to receive(:find_by_name).
|
@@ -83,7 +125,48 @@ describe 'Flapjack::Gateways::JSONAPI::CheckMethods', :sinatra => true, :logger
|
|
83
125
|
[{:op => 'replace', :path => '/checks/0/enabled', :value => false}].to_json,
|
84
126
|
jsonapi_patch_env
|
85
127
|
expect(last_response.status).to eq(204)
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'enables a check' do
|
131
|
+
expect(Flapjack::Data::Entity).to receive(:find_by_name).
|
132
|
+
with(entity_name, :redis => redis).and_return(entity)
|
133
|
+
expect(Flapjack::Data::EntityCheck).to receive(:for_entity).
|
134
|
+
with(entity, check, :redis => redis).and_return(entity_check)
|
135
|
+
|
136
|
+
expect(entity_check).to receive(:enable!)
|
137
|
+
|
138
|
+
apatch "/checks/#{check_esc}",
|
139
|
+
[{:op => 'replace', :path => '/checks/0/enabled', :value => true}].to_json,
|
140
|
+
jsonapi_patch_env
|
141
|
+
expect(last_response.status).to eq(204)
|
142
|
+
end
|
143
|
+
|
144
|
+
it "adds tags to a check" do
|
145
|
+
expect(Flapjack::Data::Entity).to receive(:find_by_name).
|
146
|
+
with(entity_name, :redis => redis).and_return(entity)
|
147
|
+
expect(Flapjack::Data::EntityCheck).to receive(:for_entity).
|
148
|
+
with(entity, check, :redis => redis).and_return(entity_check)
|
149
|
+
|
150
|
+
expect(entity_check).to receive(:add_tags).with('database', 'virtualised')
|
151
|
+
|
152
|
+
apatch "/checks/#{check_esc}",
|
153
|
+
[{:op => 'add', :path => '/checks/0/links/tags', :value => ['database', 'virtualised']}].to_json,
|
154
|
+
jsonapi_patch_env
|
155
|
+
expect(last_response.status).to eq(204)
|
156
|
+
end
|
157
|
+
|
158
|
+
it "removes tags from a check" do
|
159
|
+
expect(Flapjack::Data::Entity).to receive(:find_by_name).
|
160
|
+
with(entity_name, :redis => redis).and_return(entity)
|
161
|
+
expect(Flapjack::Data::EntityCheck).to receive(:for_entity).
|
162
|
+
with(entity, check, :redis => redis).and_return(entity_check)
|
163
|
+
|
164
|
+
expect(entity_check).to receive(:delete_tags).with('database')
|
86
165
|
|
166
|
+
apatch "/checks/#{check_esc}",
|
167
|
+
[{:op => 'remove', :path => '/checks/0/links/tags/database'}].to_json,
|
168
|
+
jsonapi_patch_env
|
169
|
+
expect(last_response.status).to eq(204)
|
87
170
|
end
|
88
171
|
|
89
172
|
it "creates an acknowledgement for an entity check" do
|
@@ -21,6 +21,8 @@ describe 'Flapjack::Gateways::JSONAPI::EntityMethods', :sinatra => true, :logger
|
|
21
21
|
|
22
22
|
expect(Flapjack::Data::Entity).to receive(:contact_ids_for).
|
23
23
|
with([entity_core['id']], :redis => redis).and_return({})
|
24
|
+
expect(Flapjack::Data::Entity).to receive(:check_ids_for).
|
25
|
+
with([entity_core['id']], :redis => redis).and_return({})
|
24
26
|
expect(entity).to receive(:to_jsonapi).and_return(entity_core.to_json)
|
25
27
|
expect(Flapjack::Data::Entity).to receive(:all).with(:enabled => nil, :redis => redis).
|
26
28
|
and_return([entity])
|
@@ -36,6 +38,8 @@ describe 'Flapjack::Gateways::JSONAPI::EntityMethods', :sinatra => true, :logger
|
|
36
38
|
expect(entity).to receive(:id).exactly(4).times.and_return(entity_core['id'])
|
37
39
|
expect(Flapjack::Data::Entity).to receive(:contact_ids_for).
|
38
40
|
with([entity_core['id']], :redis => redis).and_return({})
|
41
|
+
expect(Flapjack::Data::Entity).to receive(:check_ids_for).
|
42
|
+
with([entity_core['id']], :redis => redis).and_return({})
|
39
43
|
expect(entity).to receive(:to_jsonapi).and_return(entity_core.to_json)
|
40
44
|
expect(idless_entity).not_to receive(:to_jsonapi)
|
41
45
|
expect(Flapjack::Data::Entity).to receive(:all).with(:enabled => nil, :redis => redis).
|
@@ -53,6 +57,8 @@ describe 'Flapjack::Gateways::JSONAPI::EntityMethods', :sinatra => true, :logger
|
|
53
57
|
|
54
58
|
expect(Flapjack::Data::Entity).to receive(:contact_ids_for).
|
55
59
|
with(['1234'], :redis => redis).and_return({})
|
60
|
+
expect(Flapjack::Data::Entity).to receive(:check_ids_for).
|
61
|
+
with(['1234'], :redis => redis).and_return({})
|
56
62
|
expect(entity).to receive(:to_jsonapi).and_return(entity_core.to_json)
|
57
63
|
expect(Flapjack::Data::Entity).to receive(:find_by_id).
|
58
64
|
with('1234', :logger => @logger, :redis => redis).
|
@@ -73,6 +79,9 @@ describe 'Flapjack::Gateways::JSONAPI::EntityMethods', :sinatra => true, :logger
|
|
73
79
|
expect(Flapjack::Data::Entity).to receive(:contact_ids_for).
|
74
80
|
with(['1234', '5678'], :redis => redis).and_return({})
|
75
81
|
|
82
|
+
expect(Flapjack::Data::Entity).to receive(:check_ids_for).
|
83
|
+
with(['1234', '5678'], :redis => redis).and_return({})
|
84
|
+
|
76
85
|
expect(entity).to receive(:id).twice.and_return('1234')
|
77
86
|
expect(entity_2).to receive(:id).twice.and_return('5678')
|
78
87
|
|
@@ -152,6 +161,81 @@ describe 'Flapjack::Gateways::JSONAPI::EntityMethods', :sinatra => true, :logger
|
|
152
161
|
expect(last_response.status).to eq(204)
|
153
162
|
end
|
154
163
|
|
164
|
+
it "adds tags to an entity" do
|
165
|
+
expect(Flapjack::Data::Entity).to receive(:find_by_id).
|
166
|
+
with('1234', :redis => redis).and_return(entity)
|
167
|
+
|
168
|
+
expect(entity).to receive(:add_tags).with('database')
|
169
|
+
|
170
|
+
apatch "/entities/1234",
|
171
|
+
[{:op => 'add', :path => '/entities/0/links/tags', :value => 'database'}].to_json,
|
172
|
+
jsonapi_patch_env
|
173
|
+
expect(last_response.status).to eq(204)
|
174
|
+
end
|
175
|
+
|
176
|
+
it "removes tags from an entity" do
|
177
|
+
expect(Flapjack::Data::Entity).to receive(:find_by_id).
|
178
|
+
with('1234', :redis => redis).and_return(entity)
|
179
|
+
|
180
|
+
expect(entity).to receive(:delete_tags).with('database')
|
181
|
+
expect(entity).to receive(:delete_tags).with('virtualised')
|
182
|
+
|
183
|
+
apatch "/entities/1234",
|
184
|
+
[{:op => 'remove', :path => '/entities/0/links/tags/database'},
|
185
|
+
{:op => 'remove', :path => '/entities/0/links/tags/virtualised'}].to_json,
|
186
|
+
jsonapi_patch_env
|
187
|
+
expect(last_response.status).to eq(204)
|
188
|
+
end
|
189
|
+
|
190
|
+
it "renames an entity when an entity with the new name doesn't exist" do
|
191
|
+
expect(entity).to receive(:name).and_return('example.com')
|
192
|
+
expect(Flapjack::Data::Entity).to receive(:find_by_id).
|
193
|
+
with('1234', :redis => redis).and_return(entity)
|
194
|
+
|
195
|
+
expect(Flapjack::Data::Entity).to receive(:find_by_name).
|
196
|
+
with('example2.com', :redis => redis).and_return(nil)
|
197
|
+
|
198
|
+
expect(Flapjack::Data::Entity).to receive(:rename).
|
199
|
+
with('example.com', 'example2.com', :redis => redis)
|
200
|
+
|
201
|
+
apatch "/entities/1234",
|
202
|
+
[{:op => 'replace', :path => '/entities/0/name', :value => 'example2.com'}].to_json,
|
203
|
+
jsonapi_patch_env
|
204
|
+
expect(last_response.status).to eq(204)
|
205
|
+
end
|
206
|
+
|
207
|
+
it "merges an entity when an entity with the new name exists" do
|
208
|
+
expect(entity).to receive(:name).and_return('example.com')
|
209
|
+
expect(Flapjack::Data::Entity).to receive(:find_by_id).
|
210
|
+
with('1234', :redis => redis).and_return(entity)
|
211
|
+
|
212
|
+
expect(Flapjack::Data::Entity).to receive(:find_by_name).
|
213
|
+
with('example2.com', :redis => redis).and_return(double(Flapjack::Data::Entity))
|
214
|
+
|
215
|
+
expect(Flapjack::Data::Entity).to receive(:merge).
|
216
|
+
with('example.com', 'example2.com', :redis => redis)
|
217
|
+
|
218
|
+
apatch "/entities/1234",
|
219
|
+
[{:op => 'replace', :path => '/entities/0/name', :value => 'example2.com'}].to_json,
|
220
|
+
jsonapi_patch_env
|
221
|
+
expect(last_response.status).to eq(204)
|
222
|
+
end
|
223
|
+
|
224
|
+
it 'skips a rename if old and new names are the same' do
|
225
|
+
expect(entity).to receive(:name).and_return('example.com')
|
226
|
+
expect(Flapjack::Data::Entity).to receive(:find_by_id).
|
227
|
+
with('1234', :redis => redis).and_return(entity)
|
228
|
+
|
229
|
+
expect(Flapjack::Data::Entity).not_to receive(:find_by_name)
|
230
|
+
expect(Flapjack::Data::Entity).not_to receive(:rename)
|
231
|
+
|
232
|
+
apatch "/entities/1234",
|
233
|
+
[{:op => 'replace', :path => '/entities/0/name', :value => 'example.com'}].to_json,
|
234
|
+
|
235
|
+
jsonapi_patch_env
|
236
|
+
expect(last_response.status).to eq(204)
|
237
|
+
end
|
238
|
+
|
155
239
|
it "creates acknowledgements for all checks on an entity" do
|
156
240
|
expect(entity).to receive(:check_list).and_return([check])
|
157
241
|
expect(Flapjack::Data::Entity).to receive(:find_by_id).
|