aboutsummaryrefslogtreecommitdiff
path: root/lib/mauve/alert.rb
diff options
context:
space:
mode:
authorPatrick J Cherry <patrick@bytemark.co.uk>2011-06-15 19:44:07 +0100
committerPatrick J Cherry <patrick@bytemark.co.uk>2011-06-15 19:44:07 +0100
commit42f14de6ab50d0e05f49f038e40b94b686701bf1 (patch)
tree33dc459cf3ae32de8956690a990f080321a67a83 /lib/mauve/alert.rb
parent92e5d4e652aae161640359b41c0ba8dcaedac0ad (diff)
* Added Alert#subject to return source when subject unspecified
* Added extra arg to acknowledge! * Alert#all_raised / all_cleared does not returned ack'd alerts * Added sanitising for source/subject * Catch empty alert_group notifications in AlertChanged * Tidied up alert_group * Added skip bytemark_auth when RACK_ENV is development * Tidied up logging in MauveThread, Timer, UdpServer * Added extra convenience methods to Time and Date * Moved working/daylight/dead_zone hours into Time
Diffstat (limited to 'lib/mauve/alert.rb')
-rw-r--r--lib/mauve/alert.rb56
1 files changed, 40 insertions, 16 deletions
diff --git a/lib/mauve/alert.rb b/lib/mauve/alert.rb
index d0f134b..9cb2521 100644
--- a/lib/mauve/alert.rb
+++ b/lib/mauve/alert.rb
@@ -164,14 +164,19 @@ module Mauve
end
+ #
+ # AlertGroup.matches must always return a an array of groups.
+ #
def alert_group
- AlertGroup.matches(self)[0]
+ AlertGroup.matches(self).first
end
def level
self.alert_group.level
end
-
+
+ def subject; attribute_get(:subject) || attribute_get(:source) ; end
+
def subject=(subject); set_changed_if_different( :subject, subject ); end
def summary=(summary); set_changed_if_different( :summary, summary ); end
@@ -188,11 +193,11 @@ module Mauve
public
- def acknowledge!(person)
+ def acknowledge!(person, ack_until = Time.now+3600)
self.acknowledged_by = person.username
self.acknowledged_at = MauveTime.now
self.update_type = :acknowledged
- self.will_unacknowledge_at = MauveTime.parse(acknowledged_at.to_s) +
+ self.will_unacknowledge_at = ack_until
logger.error("Couldn't save #{self}") unless save
AlertGroup.notify([self])
end
@@ -252,7 +257,21 @@ module Mauve
def cleared?
!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
#
@@ -277,7 +296,7 @@ module Mauve
#
#
def all_raised
- all(:raised_at.not => nil, :cleared_at => nil)
+ all(:raised_at.not => nil, :cleared_at => nil) - all_acknowledged
end
def all_acknowledged
@@ -285,7 +304,7 @@ module Mauve
end
def all_cleared
- all(:cleared_at.not => nil)
+ all(:cleared_at.not => nil) - all_acknowledged
end
# Returns a hash of all the :urgent, :normal and :low alerts.
@@ -303,6 +322,7 @@ module Mauve
return hash
end
+ #
# Returns the next Alert that will have a timed action due on it, or nil
# if none are pending.
#
@@ -317,6 +337,7 @@ module Mauve
end
end
+ #
# Receive an AlertUpdate buffer from the wire.
#
def receive_update(update, reception_time = MauveTime.now)
@@ -340,9 +361,15 @@ module Mauve
logger.debug("Update received from a host #{time_offset}s behind") if time_offset.abs > 5
+ #
+ # Make sure there is no HTML in the update source.
+ #
+ update.source = Alert.remove_html(update.source)
+
# Update each alert supplied
#
update.alert.each do |alert|
+ #
# Infer some actions from our pure data structure (hmm, wonder if
# this belongs in our protobuf-derived class?
#
@@ -368,7 +395,7 @@ module Mauve
alert_db = first(:alert_id => alert.id, :source => update.source) ||
new(:alert_id => alert.id, :source => update.source)
-
+
#
# Work out what state the alert was in before receiving this update.
#
@@ -416,15 +443,12 @@ module Mauve
alert_db.update_type = :raised
end
- #
- # Changing any of these attributes causes the alert to be sent back
- # out to the notification system with an update_type of :changed.
- #
- # Each of these should be just text, no HTML, so remove any tags we
- # find.
- #
+ if alert.subject and !alert.subject.empty?
+ alert_db.subject = Alert.remove_html(alert.subject)
+ else
+ alert_db.subject = alert_db.source
+ end
- alert_db.subject = Alert.remove_html(alert.subject) if alert.subject && !alert.subject.empty?
alert_db.summary = Alert.remove_html(alert.summary) if alert.summary && !alert.summary.empty?
#