From edfe588a9a39a761c7433f4d019201505081e289 Mon Sep 17 00:00:00 2001 From: Patrick J Cherry Date: Wed, 24 Aug 2011 17:26:21 +0100 Subject: Alert#all_unacknowledged created, reflecting reality of what all_raised was being used for XMPP alerts now sorted sanely --- lib/mauve/alert.rb | 8 ++++++-- lib/mauve/notifiers/xmpp.rb | 15 ++++++++------- lib/mauve/web_interface.rb | 4 ++-- 3 files changed, 16 insertions(+), 11 deletions(-) (limited to 'lib/mauve') diff --git a/lib/mauve/alert.rb b/lib/mauve/alert.rb index 752a132..76e79cd 100644 --- a/lib/mauve/alert.rb +++ b/lib/mauve/alert.rb @@ -412,7 +412,11 @@ module Mauve # # def all_raised - all(:raised_at.not => nil, :acknowledged_at => nil, :cleared_at => nil) + all(:raised_at.not => nil, :order => [:raised_at.asc]) & (all(:cleared_at => nil) | all(:raised_at.gte => :cleared_at)) + end + + def all_unacknowledged + all_raised - all_acknowledged end def all_acknowledged @@ -420,7 +424,7 @@ module Mauve end def all_cleared - all(:cleared_at.not => nil, :acknowledged_at => nil) + all - all_raised - all_acknowledged end # Returns a hash of all the :urgent, :normal and :low alerts. diff --git a/lib/mauve/notifiers/xmpp.rb b/lib/mauve/notifiers/xmpp.rb index 38d7242..6a94ba8 100644 --- a/lib/mauve/notifiers/xmpp.rb +++ b/lib/mauve/notifiers/xmpp.rb @@ -442,14 +442,15 @@ module Mauve def parse_command(msg) case msg.body - when /help/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 - File.executable?('/usr/games/fortune') ? `/usr/games/fortune -s -n 60`.chomp : "Sorry. I don't understand. Try asking me for help." + do_parse_help(msg) end end @@ -458,8 +459,8 @@ module Mauve cmd = $1 return case cmd - when "show" - < [:acknowledged_at.asc]) when "events" History.all(:created_at.gte => Time.now - 24.hours) else - Alert.all_raised + Alert.all_unacknowledged.all(:order => [:raised_at.asc]) end if first_or_last == "first" diff --git a/lib/mauve/web_interface.rb b/lib/mauve/web_interface.rb index fdf2ddb..928340c 100644 --- a/lib/mauve/web_interface.rb +++ b/lib/mauve/web_interface.rb @@ -283,7 +283,7 @@ EOF counts = Hash.new{|h,k| h[k] = 0} - Alert.all_raised.each{|a| counts[a.level] += 1} + Alert.all_unacknowledged.each{|a| counts[a.level] += 1} (AlertGroup::LEVELS.reverse.collect{|l| counts[l]}+ [Alert.all_acknowledged.length, Alert.all_cleared.length]).to_json @@ -559,7 +559,7 @@ EOF end def find_active_alerts - @alerts_raised = Alert.all_raised + @alerts_raised = Alert.all_unacknowledged @alerts_cleared = Alert.all_cleared @alerts_ackd = Alert.all_acknowledged -- cgit v1.2.1