From bad279e6bdd0cb06325c7a07ba38156ff52da68c Mon Sep 17 00:00:00 2001
From: Patrick J Cherry <patrick@bytemark.co.uk>
Date: Fri, 23 Nov 2012 15:04:27 +0000
Subject: AlertGroup is no longer looked for on raise/clear/ack.  It is looked
 up on notification. Made Alert#alert_group a bit clearer.

---
 lib/mauve/alert.rb | 29 +++++++----------------------
 1 file changed, 7 insertions(+), 22 deletions(-)

(limited to 'lib/mauve')

diff --git a/lib/mauve/alert.rb b/lib/mauve/alert.rb
index 703f54a..fb4587e 100644
--- a/lib/mauve/alert.rb
+++ b/lib/mauve/alert.rb
@@ -160,19 +160,19 @@ module Mauve
       # 
       # Find the AlertGroup by name if we've got a cached value
       #
-      alert_group = AlertGroup.find{|a| self.cached_alert_group == a.name} if self.cached_alert_group
+      ag = AlertGroup.find{|a| self.cached_alert_group == a.name} if self.cached_alert_group
 
-      if alert_group.nil?
+      if ag.nil?
         #
         # If we've not found the alert group by name look for it again, the
         # proper way.
         #
-        alert_group = AlertGroup.find{|a| a.includes?(self)}
-        alert_group = AlertGroup.all.last if alert_group.nil?
-        self.cached_alert_group = alert_group.name unless alert_group.nil?
+        ag = AlertGroup.find{|a| a.includes?(self)}
+        ag = AlertGroup.all.last if ag.nil?
+        self.cached_alert_group = ag.name unless ag.nil?
       end
       
-      alert_group 
+      ag 
     end
 
     # Pick out the source lists that match this alert by subject.
@@ -314,6 +314,7 @@ module Mauve
     #
     # @return [Boolean] 
     def notify_if_needed
+      # puts "Saved #{self.inspect}"
       #
       # Make sure we don't barf
       #
@@ -413,12 +414,6 @@ module Mauve
       self.will_unacknowledge_at = ack_until
       self.update_type = "acknowledged"
 
-      #
-      # Re-cache the alert group.
-      #
-      self.cached_alert_group = nil
-      self.alert_group
-
       unless save
         logger.error("Couldn't save #{self}") 
         false
@@ -478,12 +473,6 @@ module Mauve
         self.cleared_at = nil
         # Don't clear will_clear_at
         self.update_type = "raised" if self.update_type.nil? or self.update_type != "changed" or self.original_attributes[Alert.properties[:update_type]] == "cleared"
-
-        #
-        # Find the alert group to allow it to be cached.
-        #
-        self.cached_alert_group = nil
-        self.alert_group
       end
 
       unless save
@@ -520,10 +509,6 @@ module Mauve
         self.cleared_at = at if self.cleared_at.nil?
         self.will_clear_at = nil
         self.update_type = "cleared"
-        #
-        # Un-cache the alert group
-        #
-        self.cached_alert_group = nil
       end
 
       if save
-- 
cgit v1.2.3