flapjack 0.7.5 → 0.7.6

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/CHANGELOG.md CHANGED
@@ -1,7 +1,11 @@
1
1
  ## Flapjack Changelog
2
2
 
3
+ # 0.7.6 - 2013-05-20
4
+ - Bug: Problems with email notifications (no name, text part missing fields) gh-158 (@ali-graham)
5
+
3
6
  # 0.7.5 - 2013-05-20
4
7
  - Bug: Removal of contact media via POST /contacts is not working gh-175 (@ali-graham)
8
+
5
9
  # 0.7.4 - 2013-05-16
6
10
  - Bug: Event counter values are strings, not integers gh-173 (@auxesis)
7
11
 
@@ -18,6 +18,11 @@ module Flapjack
18
18
  contacts = opts[:contacts]
19
19
  return [] if contacts.nil?
20
20
  @messages ||= contacts.collect {|contact|
21
+
22
+ # TODO don't include messages here if the contact doesn't have
23
+ # the medium enabled or has blackholed at this level -- this
24
+ # will simplify the executive logic
25
+
21
26
  contact.media.keys.inject([]) { |ret, mk|
22
27
  m = Flapjack::Data::Message.for_contact(:contact => contact)
23
28
  m.notification = self
@@ -11,7 +11,7 @@
11
11
  padding: 4px;
12
12
  }
13
13
 
14
- %p= "Hi #{@contact_first_name},"
14
+ %p Hi #{@contact_first_name}
15
15
 
16
16
  %p Monitoring has detected the following:
17
17
 
@@ -20,7 +20,7 @@
20
20
  %tr
21
21
  %td
22
22
  %strong Entity
23
- %td= @entity
23
+ %td= @entity_name
24
24
  %tr
25
25
  %td
26
26
  %strong Check
@@ -2,7 +2,7 @@ Hi <%= @contact_first_name %>,
2
2
 
3
3
  Monitoring has detected the following:
4
4
 
5
- Entity: <%= @entity %>
5
+ Entity: <%= @entity_name %>
6
6
  Check: <%= @check %>
7
7
  State: <%= @state %>
8
8
  Summary: <%= @summary %>
@@ -27,16 +27,20 @@ module Flapjack
27
27
  def perform(notification)
28
28
  @logger.debug "Woo, got a notification to send out: #{notification.inspect}"
29
29
 
30
- notification_type = notification['notification_type']
31
- contact_first_name = notification['contact_first_name']
32
- contact_last_name = notification['contact_last_name']
33
- state = notification['state']
34
- summary = notification['summary']
35
- time = notification['time']
30
+ @notification_type = notification['notification_type']
31
+ @contact_first_name = notification['contact_first_name']
32
+ @contact_last_name = notification['contact_last_name']
33
+ @state = notification['state']
34
+ @summary = notification['summary']
35
+ @time = notification['time']
36
+ @entity_name, @check = notification['event_id'].split(':')
36
37
 
37
38
  entity_check = Flapjack::Data::EntityCheck.for_event_id(notification['event_id'],
38
39
  :redis => ::Resque.redis)
39
40
 
41
+ @in_unscheduled_maintenance = entity_check.in_scheduled_maintenance?
42
+ @in_scheduled_maintenance = entity_check.in_unscheduled_maintenance?
43
+
40
44
  headline_map = {'problem' => 'Problem: ',
41
45
  'recovery' => 'Recovery: ',
42
46
  'acknowledgement' => 'Acknowledgement: ',
@@ -44,12 +48,10 @@ module Flapjack
44
48
  'unknown' => ''
45
49
  }
46
50
 
47
- headline = headline_map[notification_type] || ''
48
-
49
- subject = "#{headline}'#{entity_check.check}' on #{entity_check.entity_name}"
50
- subject += " is #{state.upcase}" unless ['acknowledgement', 'test'].include?(notification_type)
51
+ headline = headline_map[@notification_type] || ''
51
52
 
52
- notification['subject'] = subject
53
+ @subject = "#{headline}'#{@check}' on #{@entity_name}"
54
+ @subject += " is #{@state.upcase}" unless ['acknowledgement', 'test'].include?(@notification_type)
53
55
 
54
56
  begin
55
57
  host = @smtp_config ? @smtp_config['host'] : nil
@@ -61,10 +63,11 @@ module Flapjack
61
63
  m_reply_to = m_from
62
64
  m_to = notification['address']
63
65
 
64
- mail = prepare_email(notification,
65
- :from => m_from, :to => m_to,
66
- :in_scheduled_maintenance => entity_check.in_scheduled_maintenance?,
67
- :in_unscheduled_maintenance => entity_check.in_unscheduled_maintenance?)
66
+ @logger.debug("sending Flapjack::Notification::Email " +
67
+ "#{notification['id']} to: #{m_to} subject: #{@subject}")
68
+
69
+ mail = prepare_email(:subject => @subject,
70
+ :from => m_from, :to => m_to)
68
71
 
69
72
  email = EM::P::SmtpClient.send(
70
73
  :from => m_from,
@@ -97,22 +100,7 @@ module Flapjack
97
100
 
98
101
  private
99
102
 
100
- def self.prepare_email(notification, opts = {})
101
-
102
- @notification_type = notification['notification_type']
103
- @contact_first_name = notification['contact_first_name']
104
- @contact_last_name = notification['contact_last_name']
105
- @state = notification['state']
106
- @summary = notification['summary']
107
- @time = notification['time']
108
- @entity, @check = notification['event_id'].split(':')
109
- @in_unscheduled_maintenance = opts[:in_unscheduled_maintenance]
110
- @in_scheduled_maintenance = opts[:in_scheduled_maintenance]
111
-
112
- m_subject = notification['subject']
113
-
114
- @logger.debug("sending Flapjack::Notification::Email " +
115
- "#{notification['id']} to: #{opts[:to]} subject: #{m_subject}")
103
+ def self.prepare_email(opts = {})
116
104
 
117
105
  text_template = ERB.new(File.read(File.dirname(__FILE__) +
118
106
  '/email/alert.text.erb'))
@@ -121,17 +109,18 @@ module Flapjack
121
109
  '/email/alert.html.haml'))
122
110
 
123
111
  mail_scope = self
112
+ bnd = binding
124
113
 
125
114
  # this part is the only use of the mail gem -- maybe this can be done
126
115
  # using standard library calls instead?
127
116
  mail = Mail.new do
128
117
  from opts[:from]
129
118
  to opts[:to]
130
- subject m_subject
119
+ subject opts[:subject]
131
120
  reply_to opts[:from]
132
121
 
133
122
  text_part do
134
- body text_template.result(binding)
123
+ body text_template.result(bnd)
135
124
  end
136
125
 
137
126
  html_part do
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  module Flapjack
4
- VERSION = "0.7.5"
4
+ VERSION = "0.7.6"
5
5
  end
@@ -1,6 +1,47 @@
1
1
  require 'spec_helper'
2
2
  require 'flapjack/gateways/email'
3
3
 
4
- describe Flapjack::Gateways::Email do
4
+ describe Flapjack::Gateways::Email, :logger => true do
5
+
6
+ before(:each) do
7
+ Flapjack::Gateways::Email.instance_variable_set('@config', {})
8
+ Flapjack::Gateways::Email.instance_variable_set('@logger', @logger)
9
+ Flapjack::Gateways::Email.start
10
+ end
11
+
12
+ it "sends a mail with text and html parts" do
13
+ email = mock('email')
14
+
15
+ entity_check = mock(Flapjack::Data::EntityCheck)
16
+ entity_check.should_receive(:in_scheduled_maintenance?).and_return(false)
17
+ entity_check.should_receive(:in_unscheduled_maintenance?).and_return(false)
18
+
19
+ redis = mock('redis')
20
+ ::Resque.should_receive(:redis).and_return(redis)
21
+
22
+ Flapjack::Data::EntityCheck.should_receive(:for_event_id).
23
+ with('example.com:ping', :redis => redis).and_return(entity_check)
24
+
25
+ # TODO better checking of what gets passed here
26
+ EM::P::SmtpClient.should_receive(:send).with(
27
+ hash_including(:host => 'localhost',
28
+ :port => 25)).and_return(email)
29
+
30
+ response = mock(response)
31
+ response.should_receive(:"respond_to?").with(:code).and_return(true)
32
+ response.should_receive(:code).and_return(250)
33
+
34
+ EM::Synchrony.should_receive(:sync).with(email).and_return(response)
35
+
36
+ notification = {'notification_type' => 'recovery',
37
+ 'contact_first_name' => 'John',
38
+ 'contact_last_name' => 'Smith',
39
+ 'state' => 'ok',
40
+ 'summary' => 'smile',
41
+ 'time' => Time.now.to_i,
42
+ 'event_id' => 'example.com:ping'}
43
+
44
+ Flapjack::Gateways::Email.perform(notification)
45
+ end
5
46
 
6
47
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flapjack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.5
4
+ version: 0.7.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -553,7 +553,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
553
553
  version: '0'
554
554
  segments:
555
555
  - 0
556
- hash: 4158008018986153398
556
+ hash: -549406373323108870
557
557
  required_rubygems_version: !ruby/object:Gem::Requirement
558
558
  none: false
559
559
  requirements:
@@ -562,7 +562,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
562
562
  version: '0'
563
563
  segments:
564
564
  - 0
565
- hash: 4158008018986153398
565
+ hash: -549406373323108870
566
566
  requirements: []
567
567
  rubyforge_project:
568
568
  rubygems_version: 1.8.23