aboutsummaryrefslogtreecommitdiff
path: root/lib/mauve/notifiers/email.rb
diff options
context:
space:
mode:
authorPatrick J Cherry <patrick@bytemark.co.uk>2011-06-13 11:02:37 +0100
committerPatrick J Cherry <patrick@bytemark.co.uk>2011-06-13 11:02:37 +0100
commitb22cbc87927553f6dbb5754281e95fe9bad2eed1 (patch)
tree5575791fe84492648a8cc92433c267815056507a /lib/mauve/notifiers/email.rb
parent495c44445642cfae8f23fadde299ad5307f5be58 (diff)
* Tidied up mauveserver to handle HUP restarts
* Added HTML santizing to the alert class, so bad HTML is stripped as part of processing. * Alert#cleared? now means "not raised" * Better error handling in the Timer class, making sure that the timer never gets permanently frozen. * Moved notification and packet buffers to the Server class, meaning that if the Processor or Notifier threads crash, we don't lose all the items waiting to be processed/notified. * XMPP/Email Alerts now use templates, instead of instance methods. * Emails now get sent as multipart with HTML to allow detail fields to be shown as nature intended.
Diffstat (limited to 'lib/mauve/notifiers/email.rb')
-rw-r--r--lib/mauve/notifiers/email.rb70
1 files changed, 15 insertions, 55 deletions
diff --git a/lib/mauve/notifiers/email.rb b/lib/mauve/notifiers/email.rb
index f3b9a0f..168a9d6 100644
--- a/lib/mauve/notifiers/email.rb
+++ b/lib/mauve/notifiers/email.rb
@@ -66,70 +66,30 @@ module Mauve
@suppressed_changed = conditions[:suppressed_changed]
end
- other_alerts = all_alerts - [alert]
-
m = RMail::Message.new
- m.header.subject = subject_prefix +
- case @suppressed_changed
- when true
- "Suppressing notifications (#{all_alerts.length} total)"
-
- else
- alert.summary_one_line.to_s
- end
+ m.header.subject = "Arse"
m.header.to = destination
m.header.from = @from
m.header.date = MauveTime.now
+ m.header['Content-Type'] = "multipart/alternative"
- summary_formatted = " * "+alert.summary_two_lines.join("\n ")
-
- case alert.update_type.to_sym
- when :cleared
- m.body = "An alert has been cleared:\n"+summary_formatted+"\n\n"
- when :raised
- m.body = "An alert has been raised:\n"+summary_formatted+"\n\n"
- when :acknowledged
- m.body = "An alert has been acknowledged by #{alert.acknowledged_by}:\n"+summary_formatted+"\n\n"
- when :changed
- m.body = "An alert has changed in nature:\n"+summary_formatted+"\n\n"
- else
- raise ArgumentError.new("Unknown update_type #{alert.update_type}")
+ txt_template = File.join(File.dirname(__FILE__), "templates", "email.txt.erb")
+ if File.exists?(txt_template)
+ txt = RMail::Message.new
+ txt.header['Content-Type'] = "text/plain; charset=\"utf-8\""
+ txt.body = ERB.new(File.read(txt_template)).result(binding).chomp
+ m.add_part(txt)
end
-
- # FIXME: include alert.detail as multipart mime
- ##Thread.abort_on_exception = true
- m.body += "\n" + '-'*10 + " This is the detail field " + '-'*44 + "\n\n"
- m.body += alert.detail.to_s
-#' m.body += alert.get_details_plain_text()
- m.body += "\n" + '-'*80 + "\n\n"
-
- if @suppressed_changed == true
- m.body += <<-END
-IMPORTANT: I've been configured to suppress notification of individual changes
-to alerts until their rate decreases. If you still need notification of evrey
-single alert, you must watch the web front-end instead.
- END
- elsif @suppressed_changed == false
- m.body += "(Notifications have slowed down - you will now be notified of every change)\n\n"
- end
-
- if other_alerts.empty?
- m.body += (alert.update_type == :cleared ? "That was" : "This is")+
- " currently the only alert outstanding\n\n"
- else
- m.body += other_alerts.length == 1 ?
- "There is currently one other alert outstanding:\n\n" :
- "There are currently #{other_alerts.length} other alerts outstanding:\n\n"
-
- other_alerts.each do |other|
- m.body += " * "+other.summary_two_lines.join("\n ")+"\n\n"
- end
+ html_template = File.join(File.dirname(__FILE__), "templates", "email.html.erb")
+ if File.exists?(html_template)
+ html = RMail::Message.new
+ html.header['Content-Type'] = "text/html; charset=\"utf-8\""
+ html.body = ERB.new(File.read(html_template)).result(binding).chomp
+ m.add_part(html)
end
-
- m.body += "-- \n"+@signature
-
+
m.to_s
end
include Debug