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.
Files changed (64) hide show
  1. data/.gitignore +1 -0
  2. data/CHANGELOG.md +9 -0
  3. data/bin/flapjack +22 -28
  4. data/bin/flapjack-nagios-receiver +5 -27
  5. data/bin/flapjack-populator +2 -2
  6. data/bin/flapper +13 -14
  7. data/bin/receive-events +3 -20
  8. data/bin/simulate-failed-check +3 -20
  9. data/etc/flapjack_config.yaml.example +119 -86
  10. data/features/cli.feature +69 -0
  11. data/features/events.feature +15 -0
  12. data/features/packaging-lintian.feature +4 -6
  13. data/features/rollup.feature +198 -0
  14. data/features/steps/cli_steps.rb +81 -0
  15. data/features/steps/events_steps.rb +26 -16
  16. data/features/steps/notifications_steps.rb +2 -2
  17. data/features/steps/packaging-lintian_steps.rb +2 -2
  18. data/features/support/daemons.rb +113 -0
  19. data/features/support/env.rb +26 -4
  20. data/lib/flapjack/configuration.rb +2 -0
  21. data/lib/flapjack/data/contact.rb +76 -5
  22. data/lib/flapjack/data/entity_check.rb +16 -0
  23. data/lib/flapjack/data/message.rb +11 -8
  24. data/lib/flapjack/data/notification.rb +31 -3
  25. data/lib/flapjack/data/notification_rule.rb +1 -1
  26. data/lib/flapjack/filters/delays.rb +1 -5
  27. data/lib/flapjack/gateways/api/contact_methods.rb +12 -6
  28. data/lib/flapjack/gateways/email.rb +35 -26
  29. data/lib/flapjack/gateways/email/alert.html.erb +4 -4
  30. data/lib/flapjack/gateways/email/alert.text.erb +2 -2
  31. data/lib/flapjack/gateways/email/alert_subject.text.erb +14 -0
  32. data/lib/flapjack/gateways/email/rollup.html.erb +48 -0
  33. data/lib/flapjack/gateways/email/rollup.text.erb +20 -0
  34. data/lib/flapjack/gateways/email/rollup_subject.text.erb +19 -0
  35. data/lib/flapjack/gateways/jabber.rb +97 -47
  36. data/lib/flapjack/gateways/sms_messagenet.rb +26 -24
  37. data/lib/flapjack/gateways/sms_messagenet/alert.text.erb +15 -0
  38. data/lib/flapjack/gateways/sms_messagenet/rollup.text.erb +34 -0
  39. data/lib/flapjack/gateways/web/views/contact.html.erb +16 -8
  40. data/lib/flapjack/notifier.rb +17 -4
  41. data/lib/flapjack/processor.rb +1 -1
  42. data/lib/flapjack/version.rb +1 -1
  43. data/spec/lib/flapjack/coordinator_spec.rb +19 -19
  44. data/spec/lib/flapjack/data/contact_spec.rb +100 -25
  45. data/spec/lib/flapjack/data/event_spec.rb +1 -1
  46. data/spec/lib/flapjack/data/message_spec.rb +1 -1
  47. data/spec/lib/flapjack/data/notification_spec.rb +11 -3
  48. data/spec/lib/flapjack/gateways/api/contact_methods_spec.rb +36 -17
  49. data/spec/lib/flapjack/gateways/api/entity_check_presenter_spec.rb +1 -1
  50. data/spec/lib/flapjack/gateways/api/entity_methods_spec.rb +38 -38
  51. data/spec/lib/flapjack/gateways/api/entity_presenter_spec.rb +15 -15
  52. data/spec/lib/flapjack/gateways/email_spec.rb +4 -4
  53. data/spec/lib/flapjack/gateways/jabber_spec.rb +13 -14
  54. data/spec/lib/flapjack/gateways/oobetet_spec.rb +2 -2
  55. data/spec/lib/flapjack/gateways/pagerduty_spec.rb +5 -5
  56. data/spec/lib/flapjack/gateways/sms_messagenet.spec.rb +1 -1
  57. data/spec/lib/flapjack/gateways/web/views/contact.html.erb_spec.rb +2 -2
  58. data/spec/lib/flapjack/gateways/web_spec.rb +4 -4
  59. data/spec/lib/flapjack/logger_spec.rb +3 -3
  60. data/spec/lib/flapjack/pikelet_spec.rb +10 -10
  61. data/spec/lib/flapjack/processor_spec.rb +4 -4
  62. data/spec/lib/flapjack/redis_pool_spec.rb +1 -1
  63. metadata +70 -5
  64. 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
- MESSAGENET_URL = 'https://www.messagenet.com.au/dotnet/Lodge.asmx/LodgeSMSMessage'
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
- notification_type = notification['notification_type']
22
- contact_first_name = notification['contact_first_name']
23
- contact_last_name = notification['contact_last_name']
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
- headline_map = {'problem' => 'PROBLEM: ',
30
- 'recovery' => 'RECOVERY: ',
31
- 'acknowledgement' => 'ACK: ',
32
- 'test' => 'TEST NOTIFICATION: ',
33
- 'unknown' => '',
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
- headline = headline_map[notification_type] || ''
43
+ sms_template = ERB.new(File.read(File.dirname(__FILE__) +
44
+ "/sms_messagenet/#{message_type}.text.erb"), nil, '-')
38
45
 
39
- message = "#{headline}'#{check}' on #{entity}"
40
- message += " is #{state.upcase}" unless ['acknowledgement', 'test'].include?(notification_type)
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(MESSAGENET_URL).get(:query => query)
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>
@@ -90,10 +90,10 @@ module Flapjack
90
90
  def process_notification(notification)
91
91
  @logger.debug ("Processing notification: #{notification.inspect}")
92
92
 
93
- timestamp = Time.now
94
- event_id = notification.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 = entity_check.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
 
@@ -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 changes in state on monitored systems
181
+ # Service events represent current state of checks on monitored systems
182
182
  when 'service'
183
183
  @redis.multi
184
184
  if event.ok?
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  module Flapjack
4
- VERSION = "0.7.27"
4
+ VERSION = "0.7.28"
5
5
  end
@@ -4,10 +4,10 @@ require 'flapjack/coordinator'
4
4
 
5
5
  describe Flapjack::Coordinator do
6
6
 
7
- let(:fiber) { mock(Fiber) }
8
- let(:config) { mock(Flapjack::Configuration) }
7
+ let(:fiber) { double(Fiber) }
8
+ let(:config) { double(Flapjack::Configuration) }
9
9
 
10
- let(:logger) { mock(Flapjack::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 = mock('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 = mock('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 = mock('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 = mock('processor')
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 = mock('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 = mock('new_config')
198
- filename = mock('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 = mock('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 = mock('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 = mock('new_config')
241
- filename = mock('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 = mock('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 = mock('new_config')
271
- filename = mock('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 = mock('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 = mock('new_executive')
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({'id' => '362',
36
- 'first_name' => 'John',
37
- 'last_name' => 'Johnson',
38
- 'email' => 'johnj@example.com',
39
- 'media' => {
40
- 'pagerduty' => {
41
- 'service_key' => '123456789012345678901234',
42
- 'subdomain' => 'flpjck',
43
- 'username' => 'flapjack',
44
- 'password' => 'very_secure'
45
- }
46
- }},
47
- :redis => @redis)
48
-
49
- Flapjack::Data::Contact.add({'id' => '363',
50
- 'first_name' => 'Jane',
51
- 'last_name' => 'Janeley',
52
- 'email' => 'janej@example.com',
53
- 'media' => {
54
- 'email' => {
55
- 'address' => 'janej@example.com',
56
- 'interval' => 60
57
- }
58
- }},
59
- :redis => @redis)
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