From d2309ac606e008123d42fcea0819f80fe2204f70 Mon Sep 17 00:00:00 2001 From: Patrick J Cherry Date: Tue, 6 Sep 2011 15:32:31 +0100 Subject: Update to suppression code. XMPP interface fixed. --- lib/mauve/alert.rb | 2 +- lib/mauve/notifiers/email.rb | 2 +- lib/mauve/notifiers/sms_aql.rb | 2 +- lib/mauve/notifiers/templates/email.html.erb | 4 +- lib/mauve/notifiers/templates/email.txt.erb | 4 +- .../notifiers/templates/email_subject.txt.erb | 23 +++++++++- lib/mauve/notifiers/templates/sms.txt.erb | 23 +++++++++- lib/mauve/notifiers/templates/xmpp.html.erb | 16 ++++--- lib/mauve/notifiers/templates/xmpp.txt.erb | 8 ++-- lib/mauve/notifiers/xmpp.rb | 53 +++++++++++++++------- lib/mauve/person.rb | 31 +++++++------ lib/mauve/version.rb | 2 +- 12 files changed, 119 insertions(+), 51 deletions(-) mode change 120000 => 100644 lib/mauve/notifiers/templates/email_subject.txt.erb mode change 120000 => 100644 lib/mauve/notifiers/templates/sms.txt.erb (limited to 'lib/mauve') diff --git a/lib/mauve/alert.rb b/lib/mauve/alert.rb index ee5c1ba..786ecab 100644 --- a/lib/mauve/alert.rb +++ b/lib/mauve/alert.rb @@ -24,7 +24,7 @@ module Mauve # http://www.mail-archive.com/datamapper@googlegroups.com/msg02314.html # def self.create_view! - the_distant_future = Time.now + 10000.days # it is the year 2000 - the humans are dead + the_distant_future = Time.now + 2000.days # it is the year 2000 - the humans are dead ["BEGIN TRANSACTION", "DROP VIEW IF EXISTS mauve_alert_earliest_dates", "CREATE VIEW 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

Detail

<%= RedCloth.new(alert.detail).to_html %>

-<% 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 %>
--
Love mauve
xxx.
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 deleted file mode 120000 index 802c711..0000000 --- a/lib/mauve/notifiers/templates/email_subject.txt.erb +++ /dev/null @@ -1 +0,0 @@ -xmpp.txt.erb \ No newline at end of file diff --git a/lib/mauve/notifiers/templates/email_subject.txt.erb b/lib/mauve/notifiers/templates/email_subject.txt.erb new file mode 100644 index 0000000..119c742 --- /dev/null +++ b/lib/mauve/notifiers/templates/email_subject.txt.erb @@ -0,0 +1,22 @@ +<%=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 deleted file mode 120000 index 802c711..0000000 --- a/lib/mauve/notifiers/templates/sms.txt.erb +++ /dev/null @@ -1 +0,0 @@ -xmpp.txt.erb \ No newline at end of file diff --git a/lib/mauve/notifiers/templates/sms.txt.erb b/lib/mauve/notifiers/templates/sms.txt.erb new file mode 100644 index 0000000..faec37d --- /dev/null +++ b/lib/mauve/notifiers/templates/sms.txt.erb @@ -0,0 +1,22 @@ +<%= 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 @@ -<%= alert.update_type.upcase %>: <% +<%= alert.id%>: <%= alert.update_type.upcase %>: <% 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 %><% +%>: <%= alert.subject %>: <%= alert.summary %><% 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 suppressed until things calm down.<% -end +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.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/ < for