aboutsummaryrefslogtreecommitdiff
path: root/lib/mauve/notifiers
diff options
context:
space:
mode:
Diffstat (limited to 'lib/mauve/notifiers')
-rw-r--r--lib/mauve/notifiers/email.rb9
-rw-r--r--lib/mauve/notifiers/sms_aql.rb18
-rw-r--r--lib/mauve/notifiers/templates/email.html.erb7
-rw-r--r--lib/mauve/notifiers/templates/email.txt.erb5
-rw-r--r--lib/mauve/notifiers/templates/xmpp.txt.erb8
-rw-r--r--lib/mauve/notifiers/xmpp.rb7
6 files changed, 30 insertions, 24 deletions
diff --git a/lib/mauve/notifiers/email.rb b/lib/mauve/notifiers/email.rb
index 77b10f1..b6a1e1b 100644
--- a/lib/mauve/notifiers/email.rb
+++ b/lib/mauve/notifiers/email.rb
@@ -35,7 +35,7 @@ module Mauve
end
- def send_alert(destination, alert, all_alerts, conditions = nil)
+ def send_alert(destination, alert, all_alerts, conditions = {})
message = prepare_message(destination, alert, all_alerts, conditions)
args = [@server, @port]
args += [@username, @password, @login_method.to_sym] if @login_method
@@ -54,10 +54,9 @@ module Mauve
protected
- def prepare_message(destination, alert, all_alerts, conditions = nil)
- if conditions
- @suppressed_changed = conditions[:suppressed_changed]
- end
+ def prepare_message(destination, alert, all_alerts, conditions = {})
+ was_suppressed = conditions[:was_suppressed] || false
+ is_suppressed = conditions[:is_suppressed] || false
m = RMail::Message.new
diff --git a/lib/mauve/notifiers/sms_aql.rb b/lib/mauve/notifiers/sms_aql.rb
index dbda229..d0cf630 100644
--- a/lib/mauve/notifiers/sms_aql.rb
+++ b/lib/mauve/notifiers/sms_aql.rb
@@ -19,9 +19,9 @@ module Mauve
@name = name
end
- def send_alert(destination, alert, all_alerts, conditions = nil)
+ def send_alert(destination, alert, all_alerts, conditions = {})
uri = URI.parse(GATEWAY)
-
+
opts_string = {
:username => @username,
:password => @password,
@@ -52,17 +52,9 @@ module Mauve
end
protected
- def prepare_message(destination, alert, all_alerts, conditions=nil)
- if conditions
- @suppressed_changed = conditions[:suppressed_changed]
- end
-
- txt = case @suppressed_changed
- when true then "TOO MUCH NOISE! Last notification: "
- when false then "BACK TO NORMAL: "
- else
- ""
- end
+ def prepare_message(destination, alert, all_alerts, conditions={})
+ was_suppressed = conditions[:was_suppressed] || false
+ is_suppressed = conditions[:is_suppressed] || false
template_file = File.join(File.dirname(__FILE__),"templates","sms.txt.erb")
diff --git a/lib/mauve/notifiers/templates/email.html.erb b/lib/mauve/notifiers/templates/email.html.erb
index bf5aed5..99f56d5 100644
--- a/lib/mauve/notifiers/templates/email.html.erb
+++ b/lib/mauve/notifiers/templates/email.html.erb
@@ -19,4 +19,9 @@ end
<h2>Detail</h2>
<div><%= RedCloth.new(alert.detail).to_html %></div>
<hr />
-<address>--<br />Love mauve<br />xxx.</address></body></html>
+<% if was_supressed and not is_suppressed %>
+<p><strong>Better now. Your notifications have now restarted.</strong></p>
+<% elsif is_supressed and not was_suppressed %>
+<p><strong>Too noisy! Your notifications have been suppressed.</strong></p>
+<% end %>
+<address>-- <br />Love mauve<br />xxx.</address></body></html>
diff --git a/lib/mauve/notifiers/templates/email.txt.erb b/lib/mauve/notifiers/templates/email.txt.erb
index d112718..a08ec55 100644
--- a/lib/mauve/notifiers/templates/email.txt.erb
+++ b/lib/mauve/notifiers/templates/email.txt.erb
@@ -19,6 +19,11 @@ end
-----------------------------------------------------------------------
+<% if was_supressed and not is_suppressed
+%>Better now. Your notifications have now restarted.<%
+elsif is_supressed and not was_suppressed
+%>Too noisy! Your notifications have been suppressed.<% end %>
+
--
Love mauve.
xx
diff --git a/lib/mauve/notifiers/templates/xmpp.txt.erb b/lib/mauve/notifiers/templates/xmpp.txt.erb
index 2f86cb6..d39500c 100644
--- a/lib/mauve/notifiers/templates/xmpp.txt.erb
+++ b/lib/mauve/notifiers/templates/xmpp.txt.erb
@@ -11,4 +11,10 @@ end
if alert.source != alert.subject
%> -- from <%= alert.source %><%
end
-%>.
+%>.<%
+if was_suppressed and not is_suppressed
+%> Normal service has resumed.<%
+elsif is_suppressed and not was_suppressed
+%> Further alerts supressed until things calm down.<%
+end
+%>
diff --git a/lib/mauve/notifiers/xmpp.rb b/lib/mauve/notifiers/xmpp.rb
index 34cc815..7fe1e39 100644
--- a/lib/mauve/notifiers/xmpp.rb
+++ b/lib/mauve/notifiers/xmpp.rb
@@ -182,12 +182,11 @@ module Mauve
# which checks whether the jid in question has a presence matching one
# or more of the choices - see +check_jid_has_presence+ for options.
- def send_alert(destination, alert, all_alerts, conditions = nil)
+ def send_alert(destination, alert, all_alerts, conditions = {})
destination_jid = JID.new(destination)
- if conditions
- @suppressed_changed = conditions[:suppressed_changed]
- end
+ was_suppressed = conditions[:was_suppressed] || false
+ is_suppressed = conditions[:is_suppressed] || false
if conditions && !check_alert_conditions(destination_jid, conditions)
logger.info("Alert conditions not met, not sending XMPP alert to #{destination_jid}")