aboutsummaryrefslogtreecommitdiff
path: root/lib/mauve/notifiers
diff options
context:
space:
mode:
authorPatrick J Cherry <patrick@bytemark.co.uk>2011-09-06 15:32:31 +0100
committerPatrick J Cherry <patrick@bytemark.co.uk>2011-09-06 15:32:31 +0100
commitd2309ac606e008123d42fcea0819f80fe2204f70 (patch)
tree2dd085c8cec56d9b0f3d14d8975cc10a2bc179ad /lib/mauve/notifiers
parent76e9883e5408e30d74187ef7b272312eb7479c50 (diff)
Update to suppression code.
XMPP interface fixed.
Diffstat (limited to 'lib/mauve/notifiers')
-rw-r--r--lib/mauve/notifiers/email.rb2
-rw-r--r--lib/mauve/notifiers/sms_aql.rb2
-rw-r--r--lib/mauve/notifiers/templates/email.html.erb4
-rw-r--r--lib/mauve/notifiers/templates/email.txt.erb4
-rw-r--r--[l---------]lib/mauve/notifiers/templates/email_subject.txt.erb23
-rw-r--r--[l---------]lib/mauve/notifiers/templates/sms.txt.erb23
-rw-r--r--lib/mauve/notifiers/templates/xmpp.html.erb16
-rw-r--r--lib/mauve/notifiers/templates/xmpp.txt.erb8
-rw-r--r--lib/mauve/notifiers/xmpp.rb53
9 files changed, 100 insertions, 35 deletions
diff --git a/lib/mauve/notifiers/email.rb b/lib/mauve/notifiers/email.rb
index d450149..3134135 100644
--- a/lib/mauve/notifiers/email.rb
+++ b/lib/mauve/notifiers/email.rb
@@ -52,7 +52,7 @@ module Mauve
def prepare_message(destination, alert, all_alerts, conditions = {})
was_suppressed = conditions[:was_suppressed] || false
- is_suppressed = conditions[:is_suppressed] || false
+ will_suppress = conditions[:will_suppress] || false
m = RMail::Message.new
diff --git a/lib/mauve/notifiers/sms_aql.rb b/lib/mauve/notifiers/sms_aql.rb
index 54a3104..82b83bc 100644
--- a/lib/mauve/notifiers/sms_aql.rb
+++ b/lib/mauve/notifiers/sms_aql.rb
@@ -52,7 +52,7 @@ module Mauve
protected
def prepare_message(destination, alert, all_alerts, conditions={})
was_suppressed = conditions[:was_suppressed] || false
- is_suppressed = conditions[:is_suppressed] || false
+ will_suppress = conditions[:will_suppress] || 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 fb33de6..d63f837 100644
--- a/lib/mauve/notifiers/templates/email.html.erb
+++ b/lib/mauve/notifiers/templates/email.html.erb
@@ -19,9 +19,9 @@ end
<h2>Detail</h2>
<div><%= RedCloth.new(alert.detail).to_html %></div>
<hr />
-<% if was_suppressed and not is_suppressed %>
+<% if was_suppressed and not will_suppress %>
<p><strong>Better now. Your notifications have now restarted.</strong></p>
-<% elsif is_suppressed and not was_suppressed %>
+<% elsif will_suppress 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 aab44a8..3ea7626 100644
--- a/lib/mauve/notifiers/templates/email.txt.erb
+++ b/lib/mauve/notifiers/templates/email.txt.erb
@@ -19,9 +19,9 @@ end
-----------------------------------------------------------------------
-<% if was_suppressed and not is_suppressed
+<% if was_suppressed and not will_suppress
%>Better now. Your notifications have now restarted.<%
-elsif is_suppressed and not was_suppressed
+elsif will_suppress and not was_suppressed
%>Too noisy! Your notifications have been suppressed.<% end %>
--
diff --git a/lib/mauve/notifiers/templates/email_subject.txt.erb b/lib/mauve/notifiers/templates/email_subject.txt.erb
index 802c711..119c742 120000..100644
--- a/lib/mauve/notifiers/templates/email_subject.txt.erb
+++ b/lib/mauve/notifiers/templates/email_subject.txt.erb
@@ -1 +1,22 @@
-xmpp.txt.erb \ No newline at end of file
+<%=alert.id %>: <%= alert.update_type.upcase %>: <%
+case alert.update_type
+when "cleared"
+%><%= alert.cleared_at.to_s_relative %><%
+when "acknowledged"
+%><%= alert.acknowledged_at.to_s_relative %> by <%= alert.acknowledged_by %> until <%= alert.will_unacknowledge_at.to_s_human %><%
+else
+%><%= alert.raised_at.to_s_relative %><%
+end
+%>: <%= alert.subject %>: <%= alert.summary %><%
+if alert.source != alert.subject
+%> -- from <%= alert.source %><%
+end
+%>. <%=WebInterface.url_for(alert)%><%
+if defined? was_suppressed and defined? will_suppress
+ if was_suppressed and not will_suppress
+%> (Normal service has resumed.)<%
+ elsif will_suppress and not was_suppressed
+%> (Further alerts suppressed until things calm down.)<%
+ end
+end
+%>
diff --git a/lib/mauve/notifiers/templates/sms.txt.erb b/lib/mauve/notifiers/templates/sms.txt.erb
index 802c711..faec37d 120000..100644
--- a/lib/mauve/notifiers/templates/sms.txt.erb
+++ b/lib/mauve/notifiers/templates/sms.txt.erb
@@ -1 +1,22 @@
-xmpp.txt.erb \ No newline at end of file
+<%= alert.update_type.upcase %>: <%
+case alert.update_type
+when "cleared"
+%><%= alert.cleared_at.to_s_relative %><%
+when "acknowledged"
+%><%= alert.acknowledged_at.to_s_relative %> by <%= alert.acknowledged_by %> until <%= alert.will_unacknowledge_at.to_s_human %><%
+else
+%><%= alert.raised_at.to_s_relative %><%
+end
+%>: <%= alert.subject %>: <%= alert.summary %><%
+if alert.source != alert.subject
+%> -- from <%= alert.source %><%
+end
+%>. <%=WebInterface.url_for(alert)%><%
+if defined? was_suppressed and defined? will_suppress
+ if was_suppressed and not will_suppress
+%> (Normal service has resumed.)<%
+ elsif will_suppress and not was_suppressed
+%> (Further alerts suppressed until things calm down.)<%
+ end
+end
+%>
diff --git a/lib/mauve/notifiers/templates/xmpp.html.erb b/lib/mauve/notifiers/templates/xmpp.html.erb
index c6bfaed..7c0bbfd 100644
--- a/lib/mauve/notifiers/templates/xmpp.html.erb
+++ b/lib/mauve/notifiers/templates/xmpp.html.erb
@@ -1,5 +1,5 @@
<html xmlns="http://jabber.org/protocol/xhtml-im"><body xmlns="OAhttp://www.w3.org/1999/xhtml">
-<a href="<%=WebInterface.url_for(alert)%>"><%= alert.update_type.upcase %></a>: <%
+<a href="<%=WebInterface.url_for(alert)%>"><%= alert.id%>: <%= alert.update_type.upcase %></a>: <%
case alert.update_type
when "cleared"
%><%= alert.cleared_at.to_s_relative %><%
@@ -8,14 +8,16 @@ when "acknowledged"
else
%><%= alert.raised_at.to_s_relative %><%
end
-%>: <%= alert.subject %>: <%= alert.summary %><%
+%>: <strong><%= alert.subject %>:</strong> <%= alert.summary %><%
if alert.source != alert.subject
%> -- from <%= alert.source %><%
end
%>.<%
-if was_suppressed and not is_suppressed
-%><em> Normal service has resumed.</em><%
-elsif is_suppressed and not was_suppressed
-%><em> Further alerts suppressed until things calm down.</em><%
-end
+if defined? was_suppressed and defined? will_suppress
+ if was_suppressed and not will_suppress
+%><br /><em>Normal service has resumed.</em><%
+ elsif will_suppress and not was_suppressed
+%><br /><em>Further alerts suppressed until things calm down.</em><%
+ end
+end
%></body></html>
diff --git a/lib/mauve/notifiers/templates/xmpp.txt.erb b/lib/mauve/notifiers/templates/xmpp.txt.erb
index 57f16f4..119c742 100644
--- a/lib/mauve/notifiers/templates/xmpp.txt.erb
+++ b/lib/mauve/notifiers/templates/xmpp.txt.erb
@@ -1,4 +1,4 @@
-<%= alert.update_type.upcase %>: <%
+<%=alert.id %>: <%= alert.update_type.upcase %>: <%
case alert.update_type
when "cleared"
%><%= alert.cleared_at.to_s_relative %><%
@@ -12,10 +12,10 @@ if alert.source != alert.subject
%> -- from <%= alert.source %><%
end
%>. <%=WebInterface.url_for(alert)%><%
-if defined? was_suppressed and defined? is_suppressed
- if was_suppressed and not is_suppressed
+if defined? was_suppressed and defined? will_suppress
+ if was_suppressed and not will_suppress
%> (Normal service has resumed.)<%
- elsif is_suppressed and not was_suppressed
+ elsif will_suppress and not was_suppressed
%> (Further alerts suppressed until things calm down.)<%
end
end
diff --git a/lib/mauve/notifiers/xmpp.rb b/lib/mauve/notifiers/xmpp.rb
index 6a94ba8..a2ca14d 100644
--- a/lib/mauve/notifiers/xmpp.rb
+++ b/lib/mauve/notifiers/xmpp.rb
@@ -196,7 +196,7 @@ module Mauve
destination_jid = JID.new(destination)
was_suppressed = conditions[:was_suppressed] || false
- is_suppressed = conditions[:is_suppressed] || false
+ will_suppress = conditions[:will_suppress] || false
if conditions && !check_alert_conditions(destination_jid, conditions)
logger.info("Alert conditions not met, not sending XMPP alert to #{destination_jid}")
@@ -442,15 +442,14 @@ module Mauve
def parse_command(msg)
case msg.body
+ when /help(\s+\w+)?/i
+ do_parse_help(msg)
when /show\s?/i
do_parse_show(msg)
when /ack/i
do_parse_ack(msg)
- when /(\w+\W+){5,}\w/
- do_parse_help(msg)
- File.executable?('/usr/games/fortune') ? `/usr/games/fortune -s -n 60`.chomp : "I'd love to stay and chat, but I'm really quite busy"
else
- do_parse_help(msg)
+ File.executable?('/usr/games/fortune') ? `/usr/games/fortune -s -n 60`.chomp : "I'd love to stay and chat, but I'm really quite busy"
end
end
@@ -462,18 +461,30 @@ module Mauve
when /^show/
<<EOF
Show command: Lists all raised or acknowledged alerts, or the first or last few.
+
e.g.
show -- shows all raised alerts
show ack -- shows all acknowledged alerts
show first 10 acknowledged -- shows first 10 acknowledged
- show last 5 raised -- shows last 5 raised alerts
+ show last 5 raised -- shows last 5 raised alerts
EOF
when /^ack/
<<EOF
-Acknowledge command: Acknowledges one or more alerts for a set period of time. This can only be done from a "private" chat.
+Acknowledge command: Acknowledges one or more alerts for a set period of time.
+
+The syntax is
+
+ acknowledge <alert list> for <time period> because <note>
+
+ * The alert list is a comma separated list.
+ * The time period can be spefied in terms of days, hours, minutes, seconds,
+ which can be wall-clock (default), working, or daytime (see the examples).
+ * The note is appended to the acknowledgement.
+
e.g.
- ack 1 for 2 hours -- acknowledges alert no. 1 for 2 wall-clock hours
+ acknowledge 1 for 2 hours -- acknowledges alert no. 1 for 2 wall-clock hours
ack 1,2,3 for 2 working hours -- acknowledges alerts 1, 2, and 3 for 2 working hours
+ ack 4 for 3 days because something bad happened -- acknowledge alert 4 for 3 wall-clock days with the note "something bad happened"
EOF
else
"I am Mauve #{Mauve::VERSION}. I understand \"help\", \"show\" and \"acknowledge\" commands. Try \"help show\"."
@@ -518,28 +529,38 @@ EOF
end
(["Alerts #{type}:"] + items.collect do |alert|
- "#{alert.id}: " + ERB.new(template).result(binding).chomp
+ ERB.new(template).result(binding).chomp
end).join("\n")
end
def do_parse_ack(msg)
return "Sorry -- I don't understand your acknowledge command." unless
- msg.body =~ /ack(?:nowledge)?\s+([\d,]+)\s+for\s+(\d+)\s+(work(?:ing)|day(?:time)|wall(?:-?clock))?\s*hours?(?:\s(.*))?/i
+ msg.body =~ /ack(?:nowledge)?\s+([\d,]+)\s+for\s+(\d+(?:\.\d+)?)\s+(work(?:ing)?|day(?:time)?|wall(?:-?clock)?)?\s*(day|hour|min(?:ute)?|sec(?:ond))s?(?:\s+because\s+(.*))?/i
- alerts, n_hours, type_hours, note = [$1,$2, $3, $4]
+ alerts, n_hours, type_hours, dhms, note = [$1,$2, $3, $4, $5]
alerts = alerts.split(",")
- n_hours = n_hours.to_i
+
+ n_hours = case dhms
+ when /^day/
+ n_hours.to_f * 24.0
+ when /^min/
+ n_hours.to_f / 60.0
+ when /^sec/
+ n_hours.to_f / 3600.0
+ else
+ n_hours.to_f
+ end
type_hours = case type_hours
- when /^wall/
- "wallclock"
+ when /^day/
+ "daytime"
when /^work/
"working"
else
- "daytime"
+ "wallclock"
end
-
+
ack_until = Time.now.in_x_hours(n_hours, type_hours)
username = get_username_for(msg.from)