aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick J Cherry <patrick@bytemark.co.uk>2012-12-04 14:08:22 +0000
committerPatrick J Cherry <patrick@bytemark.co.uk>2012-12-04 14:08:22 +0000
commit145b3a64114e74844528071956355472408012ba (patch)
treea16aa7417087768e190901d37ad4af297d2577f2
parent01653303f63df05ca877a30255ff92b708cae977 (diff)
Fixed up alert notification suppression to notify when alerts get re-raised.
-rw-r--r--lib/mauve/alert_group.rb10
-rw-r--r--test/tc_mauve_alert_group.rb71
2 files changed, 79 insertions, 2 deletions
diff --git a/lib/mauve/alert_group.rb b/lib/mauve/alert_group.rb
index 554c560..fe78ad9 100644
--- a/lib/mauve/alert_group.rb
+++ b/lib/mauve/alert_group.rb
@@ -171,9 +171,15 @@ module Mauve
this_reminder.level = level.to_s
this_reminder.at = at
+ #
+ # Set a reminder if
+ # * there was no existing reminder
+ # * the alert now is raised, but the reminder was set when the alert was cleared, or the alert was ack'd.
+ # * the alert now is cleared, but the reminder was set when the alert was raised/re-raised/ack'd
+ #
if this_reminder.update_type.nil? or
- (alert.raised? and this_reminder.update_type == "CLEARED") or
- (alert.cleared? and %w(RE-RAISED RAISED ACKNOWLEDGED).include?(this_reminder.update_type))
+ (alert.raised? and %w(cleared acknowledged).include?(this_reminder.update_type.to_s.downcase)) or
+ (alert.cleared? and %w(re-raised raised acknowledged).include?(this_reminder.update_type.to_s.downcase))
this_reminder.update_type = alert.update_type
this_reminder.remind_at = alert.suppress_until
diff --git a/test/tc_mauve_alert_group.rb b/test/tc_mauve_alert_group.rb
index fd451dd..7ef7e40 100644
--- a/test/tc_mauve_alert_group.rb
+++ b/test/tc_mauve_alert_group.rb
@@ -318,6 +318,8 @@ EOF
:subject => "test"
)
+ # raise, acknowledge, suppress, unsuppress, unacknowledge
+
#
# Raise the alert.
#
@@ -362,6 +364,75 @@ EOF
AlertChanged.all.each{|ac| ac.poll}
assert_equal(1,notification_buffer.length)
notification_buffer.pop
+
+ AlertChanged.all.destroy
+
+ #
+ # Now do the same, but suppress before the ack.
+ #
+ a = Alert.new(
+ :alert_id => "test2",
+ :source => "test",
+ :subject => "test",
+ :suppress_until => Time.now + 1.minutes
+ )
+
+ #
+ # Raise the alert.
+ #
+ a.raise!
+ assert(a.suppressed?)
+ assert_equal(0,notification_buffer.length)
+
+ #
+ #
+ # It unsupresses
+ #
+ Timecop.freeze(Time.now + 1.minutes)
+ assert(!a.suppressed?)
+ a.poll
+ AlertChanged.all.each{|ac| ac.poll}
+ assert_equal(1,notification_buffer.length)
+ notification_buffer.pop
+
+ #
+ # Now suppress again
+ #
+ Timecop.freeze(Time.now + 1.minutes)
+ a.suppress_until = Time.now + 3.minutes
+ assert(a.save!)
+
+ #
+ # And acknowledge it
+ #
+ Timecop.freeze(Time.now + 1.minutes)
+ assert(a.acknowledge!(Configuration.current.people["test1"],Time.now + 1.minutes))
+ a.poll
+ AlertChanged.all.each{|ac| ac.poll}
+ assert_equal(0,notification_buffer.length)
+
+ #
+ # Now the alert will unacknowlege in 1 minute, but no notifications should
+ # be sent.
+ #
+ Timecop.freeze(Time.now + 1.minutes)
+ a.poll
+ AlertChanged.all.each{|ac| ac.poll}
+ assert(a.suppressed?)
+ assert(!a.acknowledged?)
+ assert(a.raised?)
+ assert_equal(0,notification_buffer.length)
+ #
+ # A minute later, it should no longer be suppressed, and a re-raised
+ # notification should get sent
+ #
+ Timecop.freeze(Time.now + 1.minutes)
+ assert(!a.suppressed?)
+ a.poll
+ AlertChanged.all.each{|ac| ac.poll}
+ assert(a.raised?)
+ assert_equal(1,notification_buffer.length)
+
end
def test_alert_suppression_during_non_notification_period