From 0b553879d0606b3f24047302e8958f9610341f2b Mon Sep 17 00:00:00 2001 From: Patrick J Cherry Date: Thu, 16 Jun 2011 13:41:04 +0100 Subject: Added alert sorting and grouping in the web interface. --- lib/mauve/alert.rb | 36 ++++++++++++++++++------------------ lib/mauve/processor.rb | 2 +- lib/mauve/web_interface.rb | 9 +++++++-- 3 files changed, 26 insertions(+), 21 deletions(-) (limited to 'lib') diff --git a/lib/mauve/alert.rb b/lib/mauve/alert.rb index df10741..c234f03 100644 --- a/lib/mauve/alert.rb +++ b/lib/mauve/alert.rb @@ -120,13 +120,24 @@ module Mauve # AlertGroup.matches must always return a an array of groups. # def alert_group - AlertGroup.matches(self).first + @alert_group ||= AlertGroup.matches(self).first end + # + # + # def level - self.alert_group.level + @level ||= self.alert_group.level end - + + def sort_tuple + [AlertGroup::LEVELS.index(self.level), (self.raised_at.to_time || self.cleared_at.to_time || Time.now)] + end + + def <=>(other) + other.sort_tuple <=> self.sort_tuple + end + def subject; attribute_get(:subject) || attribute_get(:source) ; end def detail; attribute_get(:detail) || "_No detail set._" ; end @@ -147,8 +158,11 @@ module Mauve public def acknowledge!(person, ack_until = Time.now+3600) + raise ArgumentError unless person.is_a?(Person) + raise ArgumentError unless ack_until.is_a?(Time) + self.acknowledged_by = person.username - self.acknowledged_at = MauveTime.now + self.acknowledged_at = Time.now self.update_type = :acknowledged self.will_unacknowledge_at = ack_until logger.error("Couldn't save #{self}") unless save @@ -211,20 +225,6 @@ module Mauve !raised? end - def sort_tuple - # - # raised > cleared - # unacknowldged > acknowledged - # raise / clear time - # level - # - [(self.raised? ? 1 : 0), AlertGroup::LEVELS.index(self.level), (self.raised? ? self.raised_at : self.cleared_at), self.subject, self.summary].collect{|x| x.nil? ? "" : x } - end - - def <=>(other) - self.sort_tuple <=> other.sort_tuple - end - class << self # diff --git a/lib/mauve/processor.rb b/lib/mauve/processor.rb index 9a5c84b..034ba34 100644 --- a/lib/mauve/processor.rb +++ b/lib/mauve/processor.rb @@ -65,7 +65,7 @@ module Mauve DataObjects::IntegrityError => ex @logger.error "#{ex} (#{ex.class}) while parsing #{data.length} bytes "+ - "starting '#{data[0..16].inspect}' from #{ip_source}" + "starting '#{data[0..15].inspect}' from #{ip_source}" @logger.debug ex.backtrace.join("\n") diff --git a/lib/mauve/web_interface.rb b/lib/mauve/web_interface.rb index 2d67957..721fc3f 100644 --- a/lib/mauve/web_interface.rb +++ b/lib/mauve/web_interface.rb @@ -163,6 +163,7 @@ module Mauve @title += " Alerts " + case @alert_type when "raised" @grouped_alerts = group_by(@alerts_raised, @group_by) @@ -359,17 +360,21 @@ module Mauve results = Hash.new{|h,k| h[k] = Array.new} - things.each do |thing| + things.sort.each do |thing| + self.class._logger.debug [AlertGroup::LEVELS.index(thing.level), (thing.raised_at || thing.cleared_at) ].inspect results[thing.__send__(meth)] << thing end - results + results.sort do |a,b| + [a[1].first, a[0]] <=> [b[1].first, b[0]] + end end def find_active_alerts @alerts_raised = Alert.all_raised @alerts_cleared = Alert.all_cleared @alerts_ackd = Alert.all_acknowledged + # # Tot up the levels for raised alerts. # -- cgit v1.2.1