flapjack 0.7.35 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -1
- data/Gemfile +3 -4
- data/Guardfile +1 -1
- data/README.md +38 -19
- data/Rakefile +1 -3
- data/etc/flapjack_config.yaml.example +11 -1
- data/features/steps/cli_steps.rb +3 -3
- data/features/steps/events_steps.rb +7 -6
- data/features/steps/flapjack-netsaint-parser_steps.rb +8 -8
- data/features/steps/notifications_steps.rb +10 -10
- data/features/steps/packaging-lintian_steps.rb +5 -9
- data/features/steps/time_travel_steps.rb +1 -1
- data/flapjack.gemspec +4 -3
- data/lib/flapjack/data/contact.rb +78 -6
- data/lib/flapjack/data/entity.rb +11 -2
- data/lib/flapjack/data/notification_rule.rb +67 -59
- data/lib/flapjack/data/semaphore.rb +44 -0
- data/lib/flapjack/gateways/api.rb +24 -28
- data/lib/flapjack/gateways/api/contact_methods.rb +1 -2
- data/lib/flapjack/gateways/api/entity_methods.rb +3 -3
- data/lib/flapjack/gateways/jsonapi.rb +249 -0
- data/lib/flapjack/gateways/jsonapi/contact_methods.rb +544 -0
- data/lib/flapjack/gateways/jsonapi/entity_check_presenter.rb +217 -0
- data/lib/flapjack/gateways/jsonapi/entity_methods.rb +350 -0
- data/lib/flapjack/gateways/jsonapi/entity_presenter.rb +75 -0
- data/lib/flapjack/gateways/jsonapi/rack/json_params_parser.rb +32 -0
- data/lib/flapjack/gateways/web.rb +78 -12
- data/lib/flapjack/gateways/web/public/css/bootstrap-theme.css +397 -0
- data/lib/flapjack/gateways/web/public/css/bootstrap-theme.min.css +7 -0
- data/lib/flapjack/gateways/web/public/css/bootstrap.css +7118 -0
- data/lib/flapjack/gateways/web/public/css/bootstrap.min.css +6 -8
- data/lib/flapjack/gateways/web/public/css/font-awesome.css +1338 -0
- data/lib/flapjack/gateways/web/public/css/font-awesome.min.css +4 -0
- data/lib/flapjack/gateways/web/public/css/screen.css +80 -0
- data/lib/flapjack/gateways/web/public/css/select2-bootstrap.css +87 -0
- data/lib/flapjack/gateways/web/public/css/select2.css +615 -0
- data/lib/flapjack/gateways/web/public/fonts/FontAwesome.otf +0 -0
- data/lib/flapjack/gateways/web/public/fonts/fontawesome-webfont.eot +0 -0
- data/lib/flapjack/gateways/web/public/fonts/fontawesome-webfont.svg +414 -0
- data/lib/flapjack/gateways/web/public/fonts/fontawesome-webfont.ttf +0 -0
- data/lib/flapjack/gateways/web/public/fonts/fontawesome-webfont.woff +0 -0
- data/lib/flapjack/gateways/web/public/fonts/glyphicons-halflings-regular.eot +0 -0
- data/lib/flapjack/gateways/web/public/fonts/glyphicons-halflings-regular.svg +229 -0
- data/lib/flapjack/gateways/web/public/fonts/glyphicons-halflings-regular.ttf +0 -0
- data/lib/flapjack/gateways/web/public/fonts/glyphicons-halflings-regular.woff +0 -0
- data/lib/flapjack/gateways/web/public/img/flapjack-2013-notext-transparent-300-300.png +0 -0
- data/lib/flapjack/gateways/web/public/img/select2.png +0 -0
- data/lib/flapjack/gateways/web/public/img/select2x2.png +0 -0
- data/lib/flapjack/gateways/web/public/js/backbone-min.js +2 -0
- data/lib/flapjack/gateways/web/public/js/backbone.js +1581 -0
- data/lib/flapjack/gateways/web/public/js/backbone.jsonapi.js +75 -0
- data/lib/flapjack/gateways/web/public/js/bootstrap.js +2276 -0
- data/lib/flapjack/gateways/web/public/js/contacts.js +225 -0
- data/lib/flapjack/gateways/web/public/js/jquery-1.10.2.js +9789 -0
- data/lib/flapjack/gateways/web/public/js/jquery-1.10.2.min.js +6 -0
- data/lib/flapjack/gateways/web/public/js/select2.js +3255 -0
- data/lib/flapjack/gateways/web/public/js/select2.min.js +22 -0
- data/lib/flapjack/gateways/web/public/js/underscore-min.js +6 -0
- data/lib/flapjack/gateways/web/public/js/underscore.js +1276 -0
- data/lib/flapjack/gateways/web/views/check.html.erb +423 -193
- data/lib/flapjack/gateways/web/views/checks.html.erb +51 -71
- data/lib/flapjack/gateways/web/views/contact.html.erb +142 -164
- data/lib/flapjack/gateways/web/views/contacts.html.erb +20 -40
- data/lib/flapjack/gateways/web/views/edit_contacts.html.erb +83 -0
- data/lib/flapjack/gateways/web/views/entities.html.erb +18 -37
- data/lib/flapjack/gateways/web/views/entity.html.erb +46 -65
- data/lib/flapjack/gateways/web/views/index.html.erb +6 -27
- data/lib/flapjack/gateways/web/views/layout.erb +95 -0
- data/lib/flapjack/gateways/web/views/self_stats.html.erb +100 -114
- data/lib/flapjack/pikelet.rb +4 -2
- data/lib/flapjack/version.rb +1 -1
- data/spec/lib/flapjack/coordinator_spec.rb +120 -120
- data/spec/lib/flapjack/data/contact_spec.rb +66 -58
- data/spec/lib/flapjack/data/entity_check_spec.rb +179 -179
- data/spec/lib/flapjack/data/entity_spec.rb +71 -71
- data/spec/lib/flapjack/data/event_spec.rb +34 -30
- data/spec/lib/flapjack/data/message_spec.rb +6 -6
- data/spec/lib/flapjack/data/notification_rule_spec.rb +24 -24
- data/spec/lib/flapjack/data/notification_spec.rb +19 -19
- data/spec/lib/flapjack/data/semaphore_spec.rb +24 -0
- data/spec/lib/flapjack/data/tag_spec.rb +11 -10
- data/spec/lib/flapjack/gateways/api/contact_methods_spec.rb +201 -201
- data/spec/lib/flapjack/gateways/api/entity_check_presenter_spec.rb +55 -55
- data/spec/lib/flapjack/gateways/api/entity_methods_spec.rb +257 -257
- data/spec/lib/flapjack/gateways/api/entity_presenter_spec.rb +26 -26
- data/spec/lib/flapjack/gateways/api_spec.rb +1 -1
- data/spec/lib/flapjack/gateways/email_spec.rb +4 -4
- data/spec/lib/flapjack/gateways/jabber_spec.rb +77 -77
- data/spec/lib/flapjack/gateways/jsonapi/contact_methods_spec.rb +830 -0
- data/spec/lib/flapjack/gateways/jsonapi/entity_check_presenter_spec.rb +211 -0
- data/spec/lib/flapjack/gateways/jsonapi/entity_methods_spec.rb +863 -0
- data/spec/lib/flapjack/gateways/jsonapi/entity_presenter_spec.rb +108 -0
- data/spec/lib/flapjack/gateways/jsonapi_spec.rb +8 -0
- data/spec/lib/flapjack/gateways/oobetet_spec.rb +35 -35
- data/spec/lib/flapjack/gateways/pagerduty_spec.rb +40 -40
- data/spec/lib/flapjack/gateways/sms_messagenet_spec.rb +3 -3
- data/spec/lib/flapjack/gateways/web/views/check.html.erb_spec.rb +1 -1
- data/spec/lib/flapjack/gateways/web/views/contact.html.erb_spec.rb +5 -5
- data/spec/lib/flapjack/gateways/web/views/index.html.erb_spec.rb +1 -1
- data/spec/lib/flapjack/gateways/web_spec.rb +73 -74
- data/spec/lib/flapjack/logger_spec.rb +13 -13
- data/spec/lib/flapjack/pikelet_spec.rb +33 -33
- data/spec/lib/flapjack/processor_spec.rb +22 -22
- data/spec/lib/flapjack/redis_pool_spec.rb +1 -1
- data/spec/lib/flapjack/utility_spec.rb +12 -12
- data/spec/spec_helper.rb +9 -9
- data/spec/support/erb_view_helper.rb +4 -0
- metadata +107 -96
- data/lib/flapjack/gateways/web/public/css/flapjack.css +0 -49
- data/lib/flapjack/gateways/web/views/_css.html.erb +0 -42
- data/lib/flapjack/gateways/web/views/_foot.html.erb +0 -3
- data/lib/flapjack/gateways/web/views/_head.html.erb +0 -5
- data/lib/flapjack/gateways/web/views/_nav.html.erb +0 -10
@@ -9,9 +9,9 @@ describe Flapjack::Data::Entity, :redis => true do
|
|
9
9
|
it "creates an entity if allowed when it can't find it" do
|
10
10
|
entity = Flapjack::Data::Entity.find_by_name(name, :redis => @redis, :create => true)
|
11
11
|
|
12
|
-
entity.
|
13
|
-
entity.name.
|
14
|
-
@redis.get("entity_id:#{name}").
|
12
|
+
expect(entity).not_to be_nil
|
13
|
+
expect(entity.name).to eq(name)
|
14
|
+
expect(@redis.get("entity_id:#{name}")).to eq('')
|
15
15
|
end
|
16
16
|
|
17
17
|
it "adds a registered contact with an entity" do
|
@@ -27,12 +27,12 @@ describe Flapjack::Data::Entity, :redis => true do
|
|
27
27
|
:redis => @redis)
|
28
28
|
|
29
29
|
entity = Flapjack::Data::Entity.find_by_id('5000', :redis => @redis)
|
30
|
-
entity.
|
30
|
+
expect(entity).not_to be_nil
|
31
31
|
contacts = entity.contacts
|
32
|
-
contacts.
|
33
|
-
contacts.
|
34
|
-
contacts.
|
35
|
-
contacts.first.name.
|
32
|
+
expect(contacts).not_to be_nil
|
33
|
+
expect(contacts).to be_an(Array)
|
34
|
+
expect(contacts.size).to eq(1)
|
35
|
+
expect(contacts.first.name).to eq('John Johnson')
|
36
36
|
end
|
37
37
|
|
38
38
|
it "does not add a registered contact with an entity if the contact is unknown" do
|
@@ -42,11 +42,11 @@ describe Flapjack::Data::Entity, :redis => true do
|
|
42
42
|
:redis => @redis)
|
43
43
|
|
44
44
|
entity = Flapjack::Data::Entity.find_by_id('5000', :redis => @redis)
|
45
|
-
entity.
|
45
|
+
expect(entity).not_to be_nil
|
46
46
|
contacts = entity.contacts
|
47
|
-
contacts.
|
48
|
-
contacts.
|
49
|
-
contacts.
|
47
|
+
expect(contacts).not_to be_nil
|
48
|
+
expect(contacts).to be_an(Array)
|
49
|
+
expect(contacts).to be_empty
|
50
50
|
end
|
51
51
|
|
52
52
|
it "finds an entity by id" do
|
@@ -55,8 +55,8 @@ describe Flapjack::Data::Entity, :redis => true do
|
|
55
55
|
:redis => @redis)
|
56
56
|
|
57
57
|
entity = Flapjack::Data::Entity.find_by_id('5000', :redis => @redis)
|
58
|
-
entity.
|
59
|
-
entity.name.
|
58
|
+
expect(entity).not_to be_nil
|
59
|
+
expect(entity.name).to eq(name)
|
60
60
|
end
|
61
61
|
|
62
62
|
it "finds an entity by name" do
|
@@ -65,8 +65,8 @@ describe Flapjack::Data::Entity, :redis => true do
|
|
65
65
|
:redis => @redis)
|
66
66
|
|
67
67
|
entity = Flapjack::Data::Entity.find_by_name(name, :redis => @redis)
|
68
|
-
entity.
|
69
|
-
entity.id.
|
68
|
+
expect(entity).not_to be_nil
|
69
|
+
expect(entity.id).to eq('5000')
|
70
70
|
end
|
71
71
|
|
72
72
|
it "returns a list of all entities" do
|
@@ -78,11 +78,11 @@ describe Flapjack::Data::Entity, :redis => true do
|
|
78
78
|
:redis => @redis)
|
79
79
|
|
80
80
|
entities = Flapjack::Data::Entity.all(:redis => @redis)
|
81
|
-
entities.
|
82
|
-
entities.
|
83
|
-
entities.
|
84
|
-
entities[0].id.
|
85
|
-
entities[1].id.
|
81
|
+
expect(entities).not_to be_nil
|
82
|
+
expect(entities).to be_an(Array)
|
83
|
+
expect(entities.size).to eq(2)
|
84
|
+
expect(entities[0].id).to eq('5000')
|
85
|
+
expect(entities[1].id).to eq('5001')
|
86
86
|
end
|
87
87
|
|
88
88
|
it "returns a list of checks for an entity" do
|
@@ -95,11 +95,11 @@ describe Flapjack::Data::Entity, :redis => true do
|
|
95
95
|
|
96
96
|
entity = Flapjack::Data::Entity.find_by_name(name, :redis => @redis)
|
97
97
|
check_list = entity.check_list
|
98
|
-
check_list.
|
99
|
-
check_list.
|
98
|
+
expect(check_list).not_to be_nil
|
99
|
+
expect(check_list.size).to eq(2)
|
100
100
|
sorted_list = check_list.sort
|
101
|
-
sorted_list[0].
|
102
|
-
sorted_list[1].
|
101
|
+
expect(sorted_list[0]).to eq('ping')
|
102
|
+
expect(sorted_list[1]).to eq('ssh')
|
103
103
|
end
|
104
104
|
|
105
105
|
it "returns a count of checks for an entity" do
|
@@ -113,8 +113,8 @@ describe Flapjack::Data::Entity, :redis => true do
|
|
113
113
|
|
114
114
|
entity = Flapjack::Data::Entity.find_by_id(5000, :redis => @redis)
|
115
115
|
check_count = entity.check_count
|
116
|
-
check_count.
|
117
|
-
check_count.
|
116
|
+
expect(check_count).not_to be_nil
|
117
|
+
expect(check_count).to eq(2)
|
118
118
|
end
|
119
119
|
|
120
120
|
it "finds entity names matching a pattern" do
|
@@ -129,10 +129,10 @@ describe Flapjack::Data::Entity, :redis => true do
|
|
129
129
|
:redis => @redis)
|
130
130
|
|
131
131
|
entities = Flapjack::Data::Entity.find_all_name_matching('abc', :redis => @redis)
|
132
|
-
entities.
|
133
|
-
entities.
|
134
|
-
entities.
|
135
|
-
entities.first.
|
132
|
+
expect(entities).not_to be_nil
|
133
|
+
expect(entities).to be_an(Array)
|
134
|
+
expect(entities.size).to eq(1)
|
135
|
+
expect(entities.first).to eq('abc-123')
|
136
136
|
end
|
137
137
|
|
138
138
|
it "adds tags to entities" do
|
@@ -143,16 +143,16 @@ describe Flapjack::Data::Entity, :redis => true do
|
|
143
143
|
|
144
144
|
entity.add_tags('source:foobar', 'foo')
|
145
145
|
|
146
|
-
entity.
|
147
|
-
entity.
|
148
|
-
entity.name.
|
149
|
-
entity.tags.
|
150
|
-
entity.tags.
|
146
|
+
expect(entity).not_to be_nil
|
147
|
+
expect(entity).to be_an(Flapjack::Data::Entity)
|
148
|
+
expect(entity.name).to eq('abc-123')
|
149
|
+
expect(entity.tags).to include("source:foobar")
|
150
|
+
expect(entity.tags).to include("foo")
|
151
151
|
|
152
152
|
# and test the tags as read back from redis
|
153
153
|
entity = Flapjack::Data::Entity.find_by_id('5000', :redis => @redis)
|
154
|
-
entity.tags.
|
155
|
-
entity.tags.
|
154
|
+
expect(entity.tags).to include("source:foobar")
|
155
|
+
expect(entity.tags).to include("foo")
|
156
156
|
|
157
157
|
end
|
158
158
|
|
@@ -164,14 +164,14 @@ describe Flapjack::Data::Entity, :redis => true do
|
|
164
164
|
|
165
165
|
entity.add_tags('source:foobar', 'foo')
|
166
166
|
|
167
|
-
entity.
|
168
|
-
entity.tags.
|
169
|
-
entity.tags.
|
167
|
+
expect(entity).not_to be_nil
|
168
|
+
expect(entity.tags).to include("source:foobar")
|
169
|
+
expect(entity.tags).to include("foo")
|
170
170
|
|
171
171
|
entity.delete_tags('source:foobar')
|
172
172
|
|
173
|
-
entity.tags.
|
174
|
-
entity.tags.
|
173
|
+
expect(entity.tags).not_to include("source:foobar")
|
174
|
+
expect(entity.tags).to include("foo")
|
175
175
|
|
176
176
|
end
|
177
177
|
|
@@ -189,25 +189,25 @@ describe Flapjack::Data::Entity, :redis => true do
|
|
189
189
|
entity0.add_tags('source:foobar', 'abc')
|
190
190
|
entity1.add_tags('source:foobar', 'def')
|
191
191
|
|
192
|
-
entity0.
|
193
|
-
entity0.
|
194
|
-
entity0.tags.
|
195
|
-
entity0.tags.
|
196
|
-
entity0.tags.
|
197
|
-
entity1.
|
198
|
-
entity1.
|
199
|
-
entity1.tags.
|
200
|
-
entity1.tags.
|
201
|
-
entity1.tags.
|
192
|
+
expect(entity0).not_to be_nil
|
193
|
+
expect(entity0).to be_an(Flapjack::Data::Entity)
|
194
|
+
expect(entity0.tags).to include("source:foobar")
|
195
|
+
expect(entity0.tags).to include("abc")
|
196
|
+
expect(entity0.tags).not_to include("def")
|
197
|
+
expect(entity1).not_to be_nil
|
198
|
+
expect(entity1).to be_an(Flapjack::Data::Entity)
|
199
|
+
expect(entity1.tags).to include("source:foobar")
|
200
|
+
expect(entity1.tags).to include("def")
|
201
|
+
expect(entity1.tags).not_to include("abc")
|
202
202
|
|
203
203
|
entities = Flapjack::Data::Entity.find_all_with_tags(['abc'], :redis => @redis)
|
204
|
-
entities.
|
205
|
-
entities.
|
206
|
-
entities.first.
|
204
|
+
expect(entities).to be_an(Array)
|
205
|
+
expect(entities.size).to eq(1)
|
206
|
+
expect(entities.first).to eq('abc-123')
|
207
207
|
|
208
208
|
entities = Flapjack::Data::Entity.find_all_with_tags(['donkey'], :redis => @redis)
|
209
|
-
entities.
|
210
|
-
entities.
|
209
|
+
expect(entities).to be_an(Array)
|
210
|
+
expect(entities).to be_empty
|
211
211
|
end
|
212
212
|
|
213
213
|
it "finds entities with several tags" do
|
@@ -224,23 +224,23 @@ describe Flapjack::Data::Entity, :redis => true do
|
|
224
224
|
entity0.add_tags('source:foobar', 'abc')
|
225
225
|
entity1.add_tags('source:foobar', 'def')
|
226
226
|
|
227
|
-
entity0.
|
228
|
-
entity0.
|
229
|
-
entity0.tags.
|
230
|
-
entity0.tags.
|
231
|
-
entity1.
|
232
|
-
entity1.
|
233
|
-
entity1.tags.
|
234
|
-
entity1.tags.
|
227
|
+
expect(entity0).not_to be_nil
|
228
|
+
expect(entity0).to be_an(Flapjack::Data::Entity)
|
229
|
+
expect(entity0.tags).to include("source:foobar")
|
230
|
+
expect(entity0.tags).to include("abc")
|
231
|
+
expect(entity1).not_to be_nil
|
232
|
+
expect(entity1).to be_an(Flapjack::Data::Entity)
|
233
|
+
expect(entity1.tags).to include("source:foobar")
|
234
|
+
expect(entity1.tags).to include("def")
|
235
235
|
|
236
236
|
entities = Flapjack::Data::Entity.find_all_with_tags(['source:foobar'], :redis => @redis)
|
237
|
-
entities.
|
238
|
-
entities.
|
237
|
+
expect(entities).to be_an(Array)
|
238
|
+
expect(entities.size).to eq(2)
|
239
239
|
|
240
240
|
entities = Flapjack::Data::Entity.find_all_with_tags(['source:foobar', 'def'], :redis => @redis)
|
241
|
-
entities.
|
242
|
-
entities.
|
243
|
-
entities.first.
|
241
|
+
expect(entities).to be_an(Array)
|
242
|
+
expect(entities.size).to eq(1)
|
243
|
+
expect(entities.first).to eq('def-456')
|
244
244
|
end
|
245
245
|
|
246
246
|
end
|
@@ -23,56 +23,56 @@ describe Flapjack::Data::Event do
|
|
23
23
|
context 'class' do
|
24
24
|
|
25
25
|
it "returns the next event (blocking, archiving)" do
|
26
|
-
mock_redis.
|
27
|
-
mock_redis.
|
26
|
+
expect(mock_redis).to receive(:brpoplpush).with('events', /^events_archive:/, 0).and_return(event_data.to_json)
|
27
|
+
expect(mock_redis).to receive(:expire)
|
28
28
|
|
29
29
|
result = Flapjack::Data::Event.next('events', :block => true, :archive_events => true, :redis => mock_redis)
|
30
|
-
result.
|
30
|
+
expect(result).to be_an_instance_of(Flapjack::Data::Event)
|
31
31
|
end
|
32
32
|
|
33
33
|
it "returns the next event (blocking, not archiving)" do
|
34
|
-
mock_redis.
|
34
|
+
expect(mock_redis).to receive(:brpop).with('events', 0).and_return(['events', event_data.to_json])
|
35
35
|
|
36
36
|
result = Flapjack::Data::Event.next('events', :block => true, :archive_events => false, :redis => mock_redis)
|
37
|
-
result.
|
37
|
+
expect(result).to be_an_instance_of(Flapjack::Data::Event)
|
38
38
|
end
|
39
39
|
|
40
40
|
it "returns the next event (non-blocking, archiving)" do
|
41
|
-
mock_redis.
|
42
|
-
mock_redis.
|
41
|
+
expect(mock_redis).to receive(:rpoplpush).with('events', /^events_archive:/).and_return(event_data.to_json)
|
42
|
+
expect(mock_redis).to receive(:expire)
|
43
43
|
|
44
44
|
result = Flapjack::Data::Event.next('events', :block => false, :archive_events => true, :redis => mock_redis)
|
45
|
-
result.
|
45
|
+
expect(result).to be_an_instance_of(Flapjack::Data::Event)
|
46
46
|
end
|
47
47
|
|
48
48
|
it "returns the next event (non-blocking, not archiving)" do
|
49
|
-
mock_redis.
|
49
|
+
expect(mock_redis).to receive(:rpop).with('events').and_return(event_data.to_json)
|
50
50
|
|
51
51
|
result = Flapjack::Data::Event.next('events', :block => false, :archive_events => false, :redis => mock_redis)
|
52
|
-
result.
|
52
|
+
expect(result).to be_an_instance_of(Flapjack::Data::Event)
|
53
53
|
end
|
54
54
|
|
55
55
|
it "handles invalid event JSON"
|
56
56
|
|
57
57
|
it "returns a count of pending events" do
|
58
58
|
events_len = 23
|
59
|
-
mock_redis.
|
59
|
+
expect(mock_redis).to receive(:llen).with('events').and_return(events_len)
|
60
60
|
|
61
61
|
pc = Flapjack::Data::Event.pending_count('events', :redis => mock_redis)
|
62
|
-
pc.
|
62
|
+
expect(pc).to eq(events_len)
|
63
63
|
end
|
64
64
|
|
65
65
|
it "creates a notification testing event" do
|
66
|
-
Time.
|
67
|
-
mock_redis.
|
66
|
+
expect(Time).to receive(:now).and_return(time)
|
67
|
+
expect(mock_redis).to receive(:lpush).with('events', /"testing"/ )
|
68
68
|
|
69
69
|
Flapjack::Data::Event.test_notifications(entity_name, check,
|
70
70
|
:summary => 'test', :details => 'testing', :redis => mock_redis)
|
71
71
|
end
|
72
72
|
|
73
73
|
it "creates an acknowledgement event" do
|
74
|
-
Time.
|
75
|
-
mock_redis.
|
74
|
+
expect(Time).to receive(:now).and_return(time)
|
75
|
+
expect(mock_redis).to receive(:lpush).with('events', /"acking"/ )
|
76
76
|
|
77
77
|
Flapjack::Data::Event.create_acknowledgement(entity_name, check,
|
78
78
|
:summary => 'acking', :time => time.to_i, :redis => mock_redis)
|
@@ -81,20 +81,24 @@ describe Flapjack::Data::Event do
|
|
81
81
|
end
|
82
82
|
|
83
83
|
context 'instance' do
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
84
|
+
let(:event) { Flapjack::Data::Event.new(event_data) }
|
85
|
+
|
86
|
+
it "matches the data it is initialised with" do
|
87
|
+
expect(event.entity).to eq(event_data['entity'])
|
88
|
+
expect(event.state).to eq(event_data['state'])
|
89
|
+
expect(event.duration).to eq(event_data['duration'])
|
90
|
+
expect(event.time).to eq(event_data['time'])
|
91
|
+
expect(event.id).to eq('xyz-example.com:ping')
|
92
|
+
expect(event.type).to eq('service')
|
93
|
+
|
94
|
+
expect(event).to be_a_service
|
95
|
+
expect(event).to be_a_service
|
96
|
+
expect(event).not_to be_an_acknowledgement
|
97
|
+
expect(event).not_to be_a_test_notifications
|
98
|
+
expect(event).not_to be_ok
|
99
|
+
expect(event).to be_a_failure
|
100
|
+
end
|
101
|
+
|
98
102
|
end
|
99
103
|
|
100
104
|
end
|
@@ -8,19 +8,19 @@ describe Flapjack::Data::Message do
|
|
8
8
|
it "assigns itself an ID" do
|
9
9
|
message = Flapjack::Data::Message.for_contact(contact)
|
10
10
|
mid = message.id
|
11
|
-
mid.
|
12
|
-
mid.
|
11
|
+
expect(mid).not_to be_nil
|
12
|
+
expect(mid).to be_a(String)
|
13
13
|
end
|
14
14
|
|
15
15
|
it "returns its contained data" do
|
16
16
|
message = Flapjack::Data::Message.for_contact(contact, :medium => 'email',
|
17
17
|
:address => 'jja@example.com')
|
18
18
|
|
19
|
-
contact.
|
20
|
-
contact.
|
21
|
-
contact.
|
19
|
+
expect(contact).to receive(:id).and_return('23')
|
20
|
+
expect(contact).to receive(:first_name).and_return('James')
|
21
|
+
expect(contact).to receive(:last_name).and_return('Jameson')
|
22
22
|
|
23
|
-
message.contents.
|
23
|
+
expect(message.contents).to include('contact_id' => '23',
|
24
24
|
'contact_first_name' => 'James',
|
25
25
|
'contact_last_name' => 'Jameson',
|
26
26
|
'media' => 'email',
|
@@ -35,18 +35,18 @@ describe Flapjack::Data::NotificationRule, :redis => true do
|
|
35
35
|
}
|
36
36
|
|
37
37
|
it "checks that a notification rule exists" do
|
38
|
-
Flapjack::Data::NotificationRule.exists_with_id?(existing_rule.id, :redis => @redis).
|
39
|
-
Flapjack::Data::NotificationRule.exists_with_id?('not_there', :redis => @redis).
|
38
|
+
expect(Flapjack::Data::NotificationRule.exists_with_id?(existing_rule.id, :redis => @redis)).to be true
|
39
|
+
expect(Flapjack::Data::NotificationRule.exists_with_id?('not_there', :redis => @redis)).to be false
|
40
40
|
end
|
41
41
|
|
42
42
|
it "returns a notification rule if it exists" do
|
43
43
|
rule = Flapjack::Data::NotificationRule.find_by_id(existing_rule.id, :redis => @redis)
|
44
|
-
rule.
|
44
|
+
expect(rule).not_to be_nil
|
45
45
|
end
|
46
46
|
|
47
47
|
it "does not return a notification rule if it does not exist" do
|
48
48
|
rule = Flapjack::Data::NotificationRule.find_by_id('not_there', :redis => @redis)
|
49
|
-
rule.
|
49
|
+
expect(rule).to be_nil
|
50
50
|
end
|
51
51
|
|
52
52
|
it "updates a notification rule" do
|
@@ -55,50 +55,50 @@ describe Flapjack::Data::NotificationRule, :redis => true do
|
|
55
55
|
expect {
|
56
56
|
rule_data[:warning_blackhole] = true
|
57
57
|
errors = rule.update(rule_data)
|
58
|
-
errors.
|
58
|
+
expect(errors).to be_nil
|
59
59
|
}.to change { rule.warning_blackhole }.from(false).to(true)
|
60
60
|
end
|
61
61
|
|
62
62
|
it "converts time restriction data to an IceCube schedule" do
|
63
63
|
sched = Flapjack::Data::NotificationRule.
|
64
64
|
time_restriction_to_icecube_schedule(weekdays_8_18, timezone)
|
65
|
-
sched.
|
65
|
+
expect(sched).not_to be_nil
|
66
66
|
end
|
67
67
|
|
68
68
|
it "generates a JSON string representing its data" do
|
69
69
|
rule = existing_rule
|
70
70
|
# bit of extra hackery for the inserted ID values
|
71
|
-
rule.to_json.
|
71
|
+
expect(rule.to_json).to eq({:id => rule.id}.merge(rule_data).to_json)
|
72
72
|
end
|
73
73
|
|
74
74
|
it "checks whether entity names match" do
|
75
75
|
rule = existing_rule
|
76
76
|
|
77
|
-
rule.match_entity?('foo-app-01.example.com').
|
78
|
-
rule.match_entity?('foo-app-02.example.com').
|
77
|
+
expect(rule.match_entity?('foo-app-01.example.com')).to be true
|
78
|
+
expect(rule.match_entity?('foo-app-02.example.com')).to be false
|
79
79
|
end
|
80
80
|
|
81
81
|
it "checks whether entity tags match" do
|
82
82
|
rule = existing_rule
|
83
83
|
|
84
|
-
rule.match_tags?(['database', 'physical'].to_set).
|
85
|
-
rule.match_tags?(['database', 'physical', 'beetroot'].to_set).
|
86
|
-
rule.match_tags?(['database'].to_set).
|
87
|
-
rule.match_tags?(['virtual'].to_set).
|
84
|
+
expect(rule.match_tags?(['database', 'physical'].to_set)).to be true
|
85
|
+
expect(rule.match_tags?(['database', 'physical', 'beetroot'].to_set)).to be true
|
86
|
+
expect(rule.match_tags?(['database'].to_set)).to be false
|
87
|
+
expect(rule.match_tags?(['virtual'].to_set)).to be false
|
88
88
|
end
|
89
89
|
|
90
90
|
it "checks if blackhole settings for a rule match a severity level" do
|
91
91
|
rule_data[:warning_blackhole] = true
|
92
92
|
rule = Flapjack::Data::NotificationRule.add(rule_data, :redis => @redis)
|
93
93
|
|
94
|
-
rule.blackhole?('warning').
|
95
|
-
rule.blackhole?('critical').
|
94
|
+
expect(rule.blackhole?('warning')).to be true
|
95
|
+
expect(rule.blackhole?('critical')).to be false
|
96
96
|
end
|
97
97
|
|
98
98
|
it "returns the media settings for a rule's severity level" do
|
99
99
|
rule = existing_rule
|
100
|
-
rule.media_for_severity('warning').
|
101
|
-
rule.media_for_severity('critical').
|
100
|
+
expect(rule.media_for_severity('warning')).to eq(['email'])
|
101
|
+
expect(rule.media_for_severity('critical')).to match_array(['email', 'sms'])
|
102
102
|
end
|
103
103
|
|
104
104
|
context 'validation' do
|
@@ -106,10 +106,10 @@ describe Flapjack::Data::NotificationRule, :redis => true do
|
|
106
106
|
it "fails to add a notification rule with invalid data" do
|
107
107
|
rule_data[:entities] = [1, {}]
|
108
108
|
rule_or_errors = Flapjack::Data::NotificationRule.add(rule_data, :redis => @redis)
|
109
|
-
rule_or_errors.
|
110
|
-
rule_or_errors.
|
111
|
-
rule_or_errors.
|
112
|
-
rule_or_errors.
|
109
|
+
expect(rule_or_errors).not_to be_nil
|
110
|
+
expect(rule_or_errors).to be_an(Array)
|
111
|
+
expect(rule_or_errors.size).to eq(1)
|
112
|
+
expect(rule_or_errors).to eq(["Rule entities must be a list of strings"])
|
113
113
|
end
|
114
114
|
|
115
115
|
it "fails to update a notification rule with invalid data" do
|
@@ -117,9 +117,9 @@ describe Flapjack::Data::NotificationRule, :redis => true do
|
|
117
117
|
expect {
|
118
118
|
rule_data[:entities] = [57]
|
119
119
|
errors = rule.update(rule_data)
|
120
|
-
errors.
|
121
|
-
errors.
|
122
|
-
errors.
|
120
|
+
expect(errors).not_to be_nil
|
121
|
+
expect(errors.size).to eq(1)
|
122
|
+
expect(errors).to eq(["Rule entities must be a list of strings"])
|
123
123
|
}.not_to change { rule.entities }
|
124
124
|
end
|
125
125
|
|