aboutsummaryrefslogtreecommitdiff
path: root/lib/mauve/alert_group.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/mauve/alert_group.rb')
-rw-r--r--lib/mauve/alert_group.rb76
1 files changed, 62 insertions, 14 deletions
diff --git a/lib/mauve/alert_group.rb b/lib/mauve/alert_group.rb
index 7ea7ffb..31d9cc8 100644
--- a/lib/mauve/alert_group.rb
+++ b/lib/mauve/alert_group.rb
@@ -26,7 +26,7 @@ module Mauve
#
# @return [Array] AlertGroups that match
def matches(alert)
- grps = all.select { |alert_group| alert_group.includes?(alert) }
+ grps = find_all { |alert_group| alert_group.includes?(alert) }
#
# Make sure we always match the last (and therefore default) group.
@@ -36,6 +36,28 @@ module Mauve
grps
end
+ #
+ #
+ #
+ def find_all(&block)
+ return all unless block_given?
+
+ all.find_all do |alert_group|
+ yield(alert_group)
+ end
+ end
+
+ #
+ #
+ #
+ def find(&block)
+ return nil unless block_given?
+
+ all.find do |alert_group|
+ yield(alert_group)
+ end
+ end
+
# @return [Log4r::Logger]
def logger
Log4r::Logger.new self.to_s
@@ -113,13 +135,16 @@ module Mauve
# @return [Log4r::Logger]
def logger ; self.class.logger ; end
- # Signals that a given alert (which is assumed to belong in this group)
- # has undergone a significant change. We resend this to every notify list.
+ # Signals that a given alert (which is assumed to belong in this group) has
+ # undergone a significant change. We resend this to every notify list.
+ # The time is used to determine the time to be used when evaluating
+ # "during" blocks in the notifier clauses.
#
# @param [Mauve::Alert] alert
+ # @param [Time] at
#
# @return [Boolean] indicates success or failure of alert.
- def notify(alert)
+ def notify(alert, at=Time.now)
#
# If there are no notifications defined.
#
@@ -128,16 +153,39 @@ module Mauve
return false
end
+ during_runners = []
+
#
# This is where we set the reminder -- i.e. on a per-alert-group basis.
- #
- remind_at = notifications.inject(nil) do |reminder_time, notification|
- this_time = notification.remind_at_next(alert)
- if reminder_time.nil? or (!this_time.nil? and reminder_time > this_time)
- this_time
- else
- reminder_time
- end
+
+ remind_at = nil
+ notifications.each do |notification|
+ #
+ # Create a new during_runner for this notification clause, and keep it
+ # handy.
+ #
+ during_runner = DuringRunner.new(at, alert, &notification.during)
+ during_runners << during_runner
+
+ #
+ # Work out the next reminder time
+ #
+ this_remind_at = notification.remind_at_next(alert, during_runner)
+
+ #
+ # Skip this one if no reminder time can be found
+ #
+ next if this_remind_at.nil?
+
+ #
+ # Set the next reminder time if we've not had one already.
+ #
+ remind_at = this_remind_at if remind_at.nil?
+
+ #
+ # We need the next soonest reminder time.
+ #
+ remind_at = this_remind_at if remind_at > this_remind_at
end
#
@@ -148,7 +196,7 @@ module Mauve
:level => level.to_s,
:alert_id => alert.id,
:person => self.name,
- :at => Time.now,
+ :at => at,
:update_type => alert.update_type,
:remind_at => remind_at,
:was_relevant => true)
@@ -161,7 +209,7 @@ module Mauve
#
sent_to = []
notifications.each do |notification|
- sent_to << notification.notify(alert, sent_to)
+ sent_to << notification.notify(alert, sent_to, during_runners.shift)
end
return (sent_to.length > 0)