flapjack 0.7.27 → 0.7.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/CHANGELOG.md +9 -0
- data/bin/flapjack +22 -28
- data/bin/flapjack-nagios-receiver +5 -27
- data/bin/flapjack-populator +2 -2
- data/bin/flapper +13 -14
- data/bin/receive-events +3 -20
- data/bin/simulate-failed-check +3 -20
- data/etc/flapjack_config.yaml.example +119 -86
- data/features/cli.feature +69 -0
- data/features/events.feature +15 -0
- data/features/packaging-lintian.feature +4 -6
- data/features/rollup.feature +198 -0
- data/features/steps/cli_steps.rb +81 -0
- data/features/steps/events_steps.rb +26 -16
- data/features/steps/notifications_steps.rb +2 -2
- data/features/steps/packaging-lintian_steps.rb +2 -2
- data/features/support/daemons.rb +113 -0
- data/features/support/env.rb +26 -4
- data/lib/flapjack/configuration.rb +2 -0
- data/lib/flapjack/data/contact.rb +76 -5
- data/lib/flapjack/data/entity_check.rb +16 -0
- data/lib/flapjack/data/message.rb +11 -8
- data/lib/flapjack/data/notification.rb +31 -3
- data/lib/flapjack/data/notification_rule.rb +1 -1
- data/lib/flapjack/filters/delays.rb +1 -5
- data/lib/flapjack/gateways/api/contact_methods.rb +12 -6
- data/lib/flapjack/gateways/email.rb +35 -26
- data/lib/flapjack/gateways/email/alert.html.erb +4 -4
- data/lib/flapjack/gateways/email/alert.text.erb +2 -2
- data/lib/flapjack/gateways/email/alert_subject.text.erb +14 -0
- data/lib/flapjack/gateways/email/rollup.html.erb +48 -0
- data/lib/flapjack/gateways/email/rollup.text.erb +20 -0
- data/lib/flapjack/gateways/email/rollup_subject.text.erb +19 -0
- data/lib/flapjack/gateways/jabber.rb +97 -47
- data/lib/flapjack/gateways/sms_messagenet.rb +26 -24
- data/lib/flapjack/gateways/sms_messagenet/alert.text.erb +15 -0
- data/lib/flapjack/gateways/sms_messagenet/rollup.text.erb +34 -0
- data/lib/flapjack/gateways/web/views/contact.html.erb +16 -8
- data/lib/flapjack/notifier.rb +17 -4
- data/lib/flapjack/processor.rb +1 -1
- data/lib/flapjack/version.rb +1 -1
- data/spec/lib/flapjack/coordinator_spec.rb +19 -19
- data/spec/lib/flapjack/data/contact_spec.rb +100 -25
- data/spec/lib/flapjack/data/event_spec.rb +1 -1
- data/spec/lib/flapjack/data/message_spec.rb +1 -1
- data/spec/lib/flapjack/data/notification_spec.rb +11 -3
- data/spec/lib/flapjack/gateways/api/contact_methods_spec.rb +36 -17
- data/spec/lib/flapjack/gateways/api/entity_check_presenter_spec.rb +1 -1
- data/spec/lib/flapjack/gateways/api/entity_methods_spec.rb +38 -38
- data/spec/lib/flapjack/gateways/api/entity_presenter_spec.rb +15 -15
- data/spec/lib/flapjack/gateways/email_spec.rb +4 -4
- data/spec/lib/flapjack/gateways/jabber_spec.rb +13 -14
- data/spec/lib/flapjack/gateways/oobetet_spec.rb +2 -2
- data/spec/lib/flapjack/gateways/pagerduty_spec.rb +5 -5
- data/spec/lib/flapjack/gateways/sms_messagenet.spec.rb +1 -1
- data/spec/lib/flapjack/gateways/web/views/contact.html.erb_spec.rb +2 -2
- data/spec/lib/flapjack/gateways/web_spec.rb +4 -4
- data/spec/lib/flapjack/logger_spec.rb +3 -3
- data/spec/lib/flapjack/pikelet_spec.rb +10 -10
- data/spec/lib/flapjack/processor_spec.rb +4 -4
- data/spec/lib/flapjack/redis_pool_spec.rb +1 -1
- metadata +70 -5
- checksums.yaml +0 -15
@@ -2,12 +2,13 @@
|
|
2
2
|
|
3
3
|
require 'em-synchrony'
|
4
4
|
require 'em-synchrony/em-http'
|
5
|
+
require 'active_support/inflector'
|
5
6
|
|
6
7
|
module Flapjack
|
7
8
|
module Gateways
|
8
9
|
class SmsMessagenet
|
9
10
|
|
10
|
-
|
11
|
+
MESSAGENET_DEFAULT_URL = 'https://www.messagenet.com.au/dotnet/Lodge.asmx/LodgeSMSMessage'
|
11
12
|
|
12
13
|
class << self
|
13
14
|
|
@@ -18,27 +19,32 @@ module Flapjack
|
|
18
19
|
def perform(notification)
|
19
20
|
@logger.debug "Woo, got a notification to send out: #{notification.inspect}"
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
state = notification['state']
|
25
|
-
summary = notification['summary']
|
26
|
-
time = notification['time']
|
27
|
-
entity, check = notification['event_id'].split(':', 2)
|
22
|
+
endpoint = @config["endpoint"] || MESSAGENET_DEFAULT_URL
|
23
|
+
username = @config["username"]
|
24
|
+
password = @config["password"]
|
28
25
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
26
|
+
@notification_type = notification['notification_type']
|
27
|
+
@rollup = notification['rollup']
|
28
|
+
@rollup_alerts = notification['rollup_alerts']
|
29
|
+
@state = notification['state']
|
30
|
+
@summary = notification['summary']
|
31
|
+
@time = notification['time']
|
32
|
+
@entity_name, @check = notification['event_id'].split(':', 2)
|
33
|
+
address = notification['address']
|
34
|
+
notification_id = notification['id']
|
35
|
+
|
36
|
+
message_type = case
|
37
|
+
when @rollup
|
38
|
+
'rollup'
|
39
|
+
else
|
40
|
+
'alert'
|
41
|
+
end
|
36
42
|
|
37
|
-
|
43
|
+
sms_template = ERB.new(File.read(File.dirname(__FILE__) +
|
44
|
+
"/sms_messagenet/#{message_type}.text.erb"), nil, '-')
|
38
45
|
|
39
|
-
|
40
|
-
message
|
41
|
-
message += " at #{Time.at(time).strftime('%-d %b %H:%M')}, #{summary}"
|
46
|
+
bnd = binding
|
47
|
+
message = sms_template.result(bnd).chomp
|
42
48
|
|
43
49
|
# TODO log error and skip instead of raising errors
|
44
50
|
if @config.nil? || (@config.respond_to?(:empty?) && @config.empty?)
|
@@ -48,11 +54,7 @@ module Flapjack
|
|
48
54
|
|
49
55
|
errors = []
|
50
56
|
|
51
|
-
username = @config["username"]
|
52
|
-
password = @config["password"]
|
53
|
-
address = notification['address']
|
54
57
|
safe_message = truncate(message, 159)
|
55
|
-
notification_id = notification['id']
|
56
58
|
|
57
59
|
[[username, "Messagenet username is missing"],
|
58
60
|
[password, "Messagenet password is missing"],
|
@@ -73,7 +75,7 @@ module Flapjack
|
|
73
75
|
'PhoneNumber' => address,
|
74
76
|
'PhoneMessage' => safe_message}
|
75
77
|
|
76
|
-
http = EM::HttpRequest.new(
|
78
|
+
http = EM::HttpRequest.new(endpoint).get(:query => query)
|
77
79
|
|
78
80
|
@logger.debug "server response: #{http.response}"
|
79
81
|
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<% case @notification_type -%>
|
2
|
+
<% when "problem" -%>
|
3
|
+
<%= "Problem: " -%>
|
4
|
+
<% when "recovery" -%>
|
5
|
+
<%= "Recovery: " -%>
|
6
|
+
<% when "acknowledgement" -%>
|
7
|
+
<%= "Ack: " -%>
|
8
|
+
<% when "test" -%>
|
9
|
+
<%= "Test notification: " -%>
|
10
|
+
<% end -%>
|
11
|
+
'<%= @check %>' on <%= @entity_name -%>
|
12
|
+
<% unless ['acknowledgement', 'test'].include?(@notification_type) -%>
|
13
|
+
is <%= ['ok'].include?(@state) ? @state.upcase : @state.titleize -%>
|
14
|
+
<% end -%>
|
15
|
+
at <%= Time.at(@time).strftime('%-d %b %H:%M') %>, <%= @summary -%>
|
@@ -0,0 +1,34 @@
|
|
1
|
+
<%
|
2
|
+
state_counts = @rollup_alerts.inject({}) do |memo, alert|
|
3
|
+
memo[alert[1]['state']] = (memo[alert[1]['state']] || 0) + 1
|
4
|
+
memo
|
5
|
+
end
|
6
|
+
|
7
|
+
states_summary = ['critical', 'warning', 'unknown'].inject([]) do |memo, state|
|
8
|
+
next memo unless state_counts[state]
|
9
|
+
memo << "#{state.titleize}: #{state_counts[state]}"
|
10
|
+
memo
|
11
|
+
end.join(', ')
|
12
|
+
|
13
|
+
states_detail = ['critical', 'warning', 'unknown'].inject([]) do |memo, state|
|
14
|
+
|
15
|
+
alerts = @rollup_alerts.find_all {|alert| alert[1]['state'] == state}
|
16
|
+
next memo if alerts.to_a.empty?
|
17
|
+
|
18
|
+
memo << "#{state.titleize}: " + alerts.inject([]) do |ret, alert|
|
19
|
+
entity, check = alert[0].split(':', 2)
|
20
|
+
ret << "'#{check}' on #{entity}"
|
21
|
+
ret
|
22
|
+
end.join(', ')
|
23
|
+
|
24
|
+
memo
|
25
|
+
end.join('; ')
|
26
|
+
|
27
|
+
-%>
|
28
|
+
<% case @rollup -%>
|
29
|
+
<% when "problem" -%>
|
30
|
+
<%= "Problem summary: " -%>
|
31
|
+
<% when "recovery" -%>
|
32
|
+
<%= "Problem summaries finishing: " -%>
|
33
|
+
<% end -%>
|
34
|
+
<%= states_summary %> (<%= states_detail -%>)
|
@@ -24,6 +24,7 @@
|
|
24
24
|
<th>Media</th>
|
25
25
|
<th>Address</th>
|
26
26
|
<th>Interval</th>
|
27
|
+
<th>Rollup Threshold</th>
|
27
28
|
</tr>
|
28
29
|
<% @contact.media.each_pair do |mk, mv| %>
|
29
30
|
<tr>
|
@@ -34,18 +35,25 @@
|
|
34
35
|
<p><%= 'password'.eql?(pk) ? h("#{pk}: ...") : h("#{pk}: #{pv}") %></p>
|
35
36
|
<% end %>
|
36
37
|
</td>
|
37
|
-
<td>-</td>
|
38
38
|
<% else %>
|
39
39
|
<td><%= h mk.capitalize %></td>
|
40
40
|
<td><%= h mv %></td>
|
41
|
-
<td>
|
42
|
-
<% if @contact.media_intervals[mk] %>
|
43
|
-
<%= h @contact.media_intervals[mk] %> seconds
|
44
|
-
<% else %>
|
45
|
-
no custom interval
|
46
|
-
<% end %>
|
47
|
-
</td>
|
48
41
|
<% end %>
|
42
|
+
|
43
|
+
<td>
|
44
|
+
<% if @contact.media_intervals[mk] %>
|
45
|
+
<%= h @contact.media_intervals[mk] %> seconds
|
46
|
+
<% else %>
|
47
|
+
no custom interval
|
48
|
+
<% end %>
|
49
|
+
</td>
|
50
|
+
<td>
|
51
|
+
<% if @contact.media_rollup_thresholds[mk] %>
|
52
|
+
<%= h @contact.media_rollup_thresholds[mk] %> failing checks
|
53
|
+
<% else %>
|
54
|
+
-
|
55
|
+
<% end %>
|
56
|
+
</td>
|
49
57
|
</tr>
|
50
58
|
<% end %>
|
51
59
|
</table>
|
data/lib/flapjack/notifier.rb
CHANGED
@@ -90,10 +90,10 @@ module Flapjack
|
|
90
90
|
def process_notification(notification)
|
91
91
|
@logger.debug ("Processing notification: #{notification.inspect}")
|
92
92
|
|
93
|
-
timestamp
|
94
|
-
event_id
|
93
|
+
timestamp = Time.now
|
94
|
+
event_id = notification.event_id
|
95
95
|
entity_check = Flapjack::Data::EntityCheck.for_event_id(event_id, :redis => @redis)
|
96
|
-
contacts
|
96
|
+
contacts = entity_check.contacts
|
97
97
|
|
98
98
|
if contacts.empty?
|
99
99
|
@logger.debug("No contacts for #{event_id}")
|
@@ -111,6 +111,19 @@ module Flapjack
|
|
111
111
|
address = message.address
|
112
112
|
contents = message.contents.merge(notification_contents)
|
113
113
|
|
114
|
+
if message.rollup
|
115
|
+
contents['rollup_alerts'] = message.contact.alerting_checks_for_media(media_type).inject({}) do |memo, alert|
|
116
|
+
ec = Flapjack::Data::EntityCheck.for_event_id(alert, :redis => @redis)
|
117
|
+
last_change = ec.last_change
|
118
|
+
memo[alert] = {
|
119
|
+
'duration' => last_change ? (Time.now.to_i - last_change) : nil,
|
120
|
+
'state' => ec.state
|
121
|
+
}
|
122
|
+
memo
|
123
|
+
end
|
124
|
+
contents['rollup_threshold'] = message.contact.rollup_threshold_for_media(media_type)
|
125
|
+
end
|
126
|
+
|
114
127
|
@notifylog.info("#{event_id} | " +
|
115
128
|
"#{notification.type} | #{message.contact.id} | #{media_type} | #{address}")
|
116
129
|
|
@@ -119,7 +132,7 @@ module Flapjack
|
|
119
132
|
return
|
120
133
|
end
|
121
134
|
|
122
|
-
@logger.info("Enqueueing #{media_type} alert for #{event_id} to #{address}")
|
135
|
+
@logger.info("Enqueueing #{media_type} alert for #{event_id} to #{address} type: #{notification.type} rollup: #{message.rollup || '-'}")
|
123
136
|
|
124
137
|
contact = message.contact
|
125
138
|
|
data/lib/flapjack/processor.rb
CHANGED
@@ -178,7 +178,7 @@ module Flapjack
|
|
178
178
|
# FIXME: create an event if there is dodgy data
|
179
179
|
|
180
180
|
case event.type
|
181
|
-
# Service events represent
|
181
|
+
# Service events represent current state of checks on monitored systems
|
182
182
|
when 'service'
|
183
183
|
@redis.multi
|
184
184
|
if event.ok?
|
data/lib/flapjack/version.rb
CHANGED
@@ -4,10 +4,10 @@ require 'flapjack/coordinator'
|
|
4
4
|
|
5
5
|
describe Flapjack::Coordinator do
|
6
6
|
|
7
|
-
let(:fiber) {
|
8
|
-
let(:config) {
|
7
|
+
let(:fiber) { double(Fiber) }
|
8
|
+
let(:config) { double(Flapjack::Configuration) }
|
9
9
|
|
10
|
-
let(:logger) {
|
10
|
+
let(:logger) { double(Flapjack::Logger) }
|
11
11
|
|
12
12
|
let!(:time) { Time.now }
|
13
13
|
|
@@ -19,7 +19,7 @@ describe Flapjack::Coordinator do
|
|
19
19
|
config.should_receive(:for_redis).and_return({})
|
20
20
|
config.should_receive(:all).and_return(cfg)
|
21
21
|
|
22
|
-
processor =
|
22
|
+
processor = double('processor')
|
23
23
|
processor.should_receive(:start)
|
24
24
|
processor.should_receive(:stop)
|
25
25
|
processor.should_receive(:update_status)
|
@@ -53,7 +53,7 @@ describe Flapjack::Coordinator do
|
|
53
53
|
config.should_receive(:for_redis).and_return({})
|
54
54
|
config.should_receive(:all).and_return(cfg)
|
55
55
|
|
56
|
-
processor =
|
56
|
+
processor = double('processor')
|
57
57
|
processor.should_receive(:start).and_raise(RuntimeError)
|
58
58
|
processor.should_receive(:stop)
|
59
59
|
processor.should_receive(:update_status)
|
@@ -84,13 +84,13 @@ describe Flapjack::Coordinator do
|
|
84
84
|
config.should_receive(:for_redis).and_return({})
|
85
85
|
config.should_receive(:all).and_return(cfg)
|
86
86
|
|
87
|
-
processor =
|
87
|
+
processor = double('processor')
|
88
88
|
processor.should_receive(:start)
|
89
89
|
processor.should_receive(:stop)
|
90
90
|
processor.should_receive(:update_status)
|
91
91
|
processor.should_receive(:status).exactly(3).times.and_return('stopped')
|
92
92
|
|
93
|
-
notifier =
|
93
|
+
notifier = double('processor')
|
94
94
|
notifier.should_receive(:start)
|
95
95
|
notifier.should_receive(:stop)
|
96
96
|
notifier.should_receive(:update_status)
|
@@ -127,7 +127,7 @@ describe Flapjack::Coordinator do
|
|
127
127
|
config.should_receive(:for_redis).and_return({})
|
128
128
|
config.should_receive(:all).and_return(cfg)
|
129
129
|
|
130
|
-
processor =
|
130
|
+
processor = double('processor')
|
131
131
|
processor.should_receive(:start)
|
132
132
|
processor.should_receive(:stop)
|
133
133
|
processor.should_receive(:update_status)
|
@@ -194,8 +194,8 @@ describe Flapjack::Coordinator do
|
|
194
194
|
old_cfg = {'processor' => {'enabled' => true}}
|
195
195
|
new_cfg = {'gateways' => {'jabber' => {'enabled' => true}}}
|
196
196
|
|
197
|
-
new_config =
|
198
|
-
filename =
|
197
|
+
new_config = double('new_config')
|
198
|
+
filename = double('filename')
|
199
199
|
|
200
200
|
config.should_receive(:all).and_return(old_cfg)
|
201
201
|
config.should_receive(:filename).and_return(filename)
|
@@ -204,7 +204,7 @@ describe Flapjack::Coordinator do
|
|
204
204
|
new_config.should_receive(:load).with(filename)
|
205
205
|
new_config.should_receive(:all).and_return(new_cfg)
|
206
206
|
|
207
|
-
processor =
|
207
|
+
processor = double('processor')
|
208
208
|
processor.should_receive(:type).twice.and_return('processor')
|
209
209
|
processor.should_receive(:stop)
|
210
210
|
processor.should_receive(:update_status)
|
@@ -213,7 +213,7 @@ describe Flapjack::Coordinator do
|
|
213
213
|
config.should_receive(:for_redis).and_return({})
|
214
214
|
fc = Flapjack::Coordinator.new(config)
|
215
215
|
|
216
|
-
jabber =
|
216
|
+
jabber = double('jabber')
|
217
217
|
Flapjack::Pikelet.should_receive(:create).
|
218
218
|
with('jabber', :config => {"enabled" => true}, :redis_config => {},
|
219
219
|
:boot_time => time, :coordinator => fc).
|
@@ -237,8 +237,8 @@ describe Flapjack::Coordinator do
|
|
237
237
|
old_cfg = {'processor' => {'enabled' => true, 'foo' => 'bar'}}
|
238
238
|
new_cfg = {'processor' => {'enabled' => true, 'foo' => 'baz'}}
|
239
239
|
|
240
|
-
new_config =
|
241
|
-
filename =
|
240
|
+
new_config = double('new_config')
|
241
|
+
filename = double('filename')
|
242
242
|
|
243
243
|
config.should_receive(:all).and_return(old_cfg)
|
244
244
|
config.should_receive(:filename).and_return(filename)
|
@@ -247,7 +247,7 @@ describe Flapjack::Coordinator do
|
|
247
247
|
new_config.should_receive(:load).with(filename)
|
248
248
|
new_config.should_receive(:all).and_return(new_cfg)
|
249
249
|
|
250
|
-
processor =
|
250
|
+
processor = double('processor')
|
251
251
|
processor.should_not_receive(:start)
|
252
252
|
processor.should_receive(:type).exactly(3).times.and_return('processor')
|
253
253
|
processor.should_receive(:reload).with(new_cfg['processor']).and_return(true)
|
@@ -267,8 +267,8 @@ describe Flapjack::Coordinator do
|
|
267
267
|
old_cfg = {'processor' => {'enabled' => true, 'foo' => 'bar'}}
|
268
268
|
new_cfg = {'processor' => {'enabled' => true, 'baz' => 'qux'}}
|
269
269
|
|
270
|
-
new_config =
|
271
|
-
filename =
|
270
|
+
new_config = double('new_config')
|
271
|
+
filename = double('filename')
|
272
272
|
|
273
273
|
config.should_receive(:all).and_return(old_cfg)
|
274
274
|
config.should_receive(:filename).and_return(filename)
|
@@ -277,7 +277,7 @@ describe Flapjack::Coordinator do
|
|
277
277
|
new_config.should_receive(:load).with(filename)
|
278
278
|
new_config.should_receive(:all).and_return(new_cfg)
|
279
279
|
|
280
|
-
processor =
|
280
|
+
processor = double('processor')
|
281
281
|
processor.should_receive(:type).exactly(5).times.and_return('processor')
|
282
282
|
processor.should_receive(:reload).with(new_cfg['processor']).and_return(false)
|
283
283
|
processor.should_receive(:stop)
|
@@ -287,7 +287,7 @@ describe Flapjack::Coordinator do
|
|
287
287
|
fiber.should_receive(:resume)
|
288
288
|
Fiber.should_receive(:new).and_yield.and_return(fiber)
|
289
289
|
|
290
|
-
new_exec =
|
290
|
+
new_exec = double('new_executive')
|
291
291
|
new_exec.should_receive(:start)
|
292
292
|
|
293
293
|
config.should_receive(:for_redis).and_return({})
|
@@ -14,8 +14,10 @@ describe Flapjack::Data::Contact, :redis => true do
|
|
14
14
|
{:tags => ["database","physical"],
|
15
15
|
:entities => ["foo-app-01.example.com"],
|
16
16
|
:time_restrictions => [],
|
17
|
+
:unknown_media => [],
|
17
18
|
:warning_media => ["email"],
|
18
19
|
:critical_media => ["sms", "email"],
|
20
|
+
:unknown_blackhole => false,
|
19
21
|
:warning_blackhole => false,
|
20
22
|
:critical_blackhole => false
|
21
23
|
}
|
@@ -25,38 +27,45 @@ describe Flapjack::Data::Contact, :redis => true do
|
|
25
27
|
{:entities => [],
|
26
28
|
:tags => Flapjack::Data::TagSet.new([]),
|
27
29
|
:time_restrictions => [],
|
30
|
+
:unknown_media => [],
|
28
31
|
:warning_media => ['email', 'sms', 'jabber', 'pagerduty'],
|
29
32
|
:critical_media => ['email', 'sms', 'jabber', 'pagerduty'],
|
33
|
+
:unknown_blackhole => false,
|
30
34
|
:warning_blackhole => false,
|
31
35
|
:critical_blackhole => false}
|
32
36
|
}
|
33
37
|
|
34
38
|
before(:each) do
|
35
|
-
Flapjack::Data::Contact.add({
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
39
|
+
Flapjack::Data::Contact.add( {
|
40
|
+
'id' => '362',
|
41
|
+
'first_name' => 'John',
|
42
|
+
'last_name' => 'Johnson',
|
43
|
+
'email' => 'johnj@example.com',
|
44
|
+
'media' => {
|
45
|
+
'pagerduty' => {
|
46
|
+
'service_key' => '123456789012345678901234',
|
47
|
+
'subdomain' => 'flpjck',
|
48
|
+
'username' => 'flapjack',
|
49
|
+
'password' => 'very_secure'
|
50
|
+
},
|
51
|
+
},
|
52
|
+
},
|
53
|
+
:redis => @redis)
|
54
|
+
|
55
|
+
Flapjack::Data::Contact.add( {
|
56
|
+
'id' => '363',
|
57
|
+
'first_name' => 'Jane',
|
58
|
+
'last_name' => 'Janeley',
|
59
|
+
'email' => 'janej@example.com',
|
60
|
+
'media' => {
|
61
|
+
'email' => {
|
62
|
+
'address' => 'janej@example.com',
|
63
|
+
'interval' => 60,
|
64
|
+
'rollup_threshold' => 5,
|
65
|
+
},
|
66
|
+
},
|
67
|
+
},
|
68
|
+
:redis => @redis)
|
60
69
|
end
|
61
70
|
|
62
71
|
it "returns a list of all contacts" do
|
@@ -240,4 +249,70 @@ describe Flapjack::Data::Contact, :redis => true do
|
|
240
249
|
'password' => 'very_secure'}
|
241
250
|
end
|
242
251
|
|
252
|
+
it "sets the interval for a contact's media" do
|
253
|
+
contact = Flapjack::Data::Contact.find_by_id('362', :redis => @redis)
|
254
|
+
contact.set_interval_for_media('email', 42)
|
255
|
+
email_interval_raw = @redis.hget("contact_media_intervals:#{contact.id}", 'email')
|
256
|
+
email_interval_raw.should == '42'
|
257
|
+
end
|
258
|
+
|
259
|
+
it "returns the interval for a contact's media" do
|
260
|
+
contact = Flapjack::Data::Contact.find_by_id('363', :redis => @redis)
|
261
|
+
email_interval = contact.interval_for_media('email')
|
262
|
+
email_interval.should == 60
|
263
|
+
end
|
264
|
+
|
265
|
+
it "returns default 15 mins for interval for a contact's media that has no set interval" do
|
266
|
+
contact = Flapjack::Data::Contact.find_by_id('362', :redis => @redis)
|
267
|
+
email_interval = contact.interval_for_media('email')
|
268
|
+
email_interval.should == 900
|
269
|
+
end
|
270
|
+
|
271
|
+
it "removes the interval for a contact's media" do
|
272
|
+
contact = Flapjack::Data::Contact.find_by_id('363', :redis => @redis)
|
273
|
+
contact.set_interval_for_media('email', nil)
|
274
|
+
email_interval_raw = @redis.hget("contact_media_intervals:#{contact.id}", 'email')
|
275
|
+
email_interval_raw.should be_nil
|
276
|
+
end
|
277
|
+
|
278
|
+
it "sets the rollup threshold for a contact's media" do
|
279
|
+
contact = Flapjack::Data::Contact.find_by_id('362', :redis => @redis)
|
280
|
+
email_rollup_threshold = contact.set_rollup_threshold_for_media('email', 3)
|
281
|
+
email_rollup_threshold_raw = @redis.hget("contact_media_rollup_thresholds:#{contact.id}", 'email')
|
282
|
+
email_rollup_threshold_raw.should == '3'
|
283
|
+
end
|
284
|
+
|
285
|
+
it "returns the rollup threshold for a contact's media" do
|
286
|
+
contact = Flapjack::Data::Contact.find_by_id('363', :redis => @redis)
|
287
|
+
email_rollup_threshold = contact.rollup_threshold_for_media('email')
|
288
|
+
email_rollup_threshold.should_not be_nil
|
289
|
+
email_rollup_threshold.should be_a(Integer)
|
290
|
+
email_rollup_threshold.should == 5
|
291
|
+
end
|
292
|
+
|
293
|
+
it "removes the rollup threshold for a contact's media" do
|
294
|
+
contact = Flapjack::Data::Contact.find_by_id('363', :redis => @redis)
|
295
|
+
email_rollup_threshold = contact.set_rollup_threshold_for_media('email', nil)
|
296
|
+
email_rollup_threshold_raw = @redis.hget("contact_media_rollup_thresholds:#{contact.id}", 'email')
|
297
|
+
email_rollup_threshold_raw.should be_nil
|
298
|
+
end
|
299
|
+
|
300
|
+
it "sets the address for a contact's media" do
|
301
|
+
contact = Flapjack::Data::Contact.find_by_id('362', :redis => @redis)
|
302
|
+
contact.set_address_for_media('email', 'spongebob@example.com')
|
303
|
+
email_address_raw = @redis.hget("contact_media:#{contact.id}", 'email')
|
304
|
+
email_address_raw.should == 'spongebob@example.com'
|
305
|
+
end
|
306
|
+
|
307
|
+
it "removes a contact's media" do
|
308
|
+
contact = Flapjack::Data::Contact.find_by_id('363', :redis => @redis)
|
309
|
+
contact.remove_media('email')
|
310
|
+
email_address_raw = @redis.hget("contac_media:#{contact.id}", 'email')
|
311
|
+
email_address_raw.should be_nil
|
312
|
+
email_rollup_threshold_raw = @redis.hget("contact_media_rollup_thresholds:#{contact.id}", 'email')
|
313
|
+
email_rollup_threshold_raw.should be_nil
|
314
|
+
email_interval_raw = @redis.hget("contact_media_intervals:#{contact.id}", 'email')
|
315
|
+
email_interval_raw.should be_nil
|
316
|
+
end
|
317
|
+
|
243
318
|
end
|