diff options
author | Patrick J Cherry <patrick@bytemark.co.uk> | 2011-08-24 17:26:21 +0100 |
---|---|---|
committer | Patrick J Cherry <patrick@bytemark.co.uk> | 2011-08-24 17:26:21 +0100 |
commit | edfe588a9a39a761c7433f4d019201505081e289 (patch) | |
tree | 1df23a4bd82ec17be81e61e1e64e8f3d640839a5 | |
parent | c22a82f711abc51eebced905588c9527a9db8895 (diff) |
Alert#all_unacknowledged created, reflecting reality of what all_raised was being used for
XMPP alerts now sorted sanely
-rw-r--r-- | lib/mauve/alert.rb | 8 | ||||
-rw-r--r-- | lib/mauve/notifiers/xmpp.rb | 15 | ||||
-rw-r--r-- | lib/mauve/web_interface.rb | 4 |
3 files changed, 16 insertions, 11 deletions
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" - <<EOF + when /^show/ + <<EOF Show command: Lists all raised or acknowledged alerts, or the first or last few. e.g. show -- shows all raised alerts @@ -493,11 +494,11 @@ EOF items = case type when "acknowledged" - Alert.all_acknowledged + Alert.all_acknowledged.all(:order => [: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 |