From 442e97f45ca582fdfbdd57f558e9fa82c8dfd4d3 Mon Sep 17 00:00:00 2001 From: Patrick J Cherry Date: Thu, 3 May 2012 18:35:59 +0100 Subject: Notify anyone who has contributed to an alert's history since its last raise, either by acknowledging, or by being notified about it. --- lib/mauve/alert.rb | 29 +++++++++++++++++++++++++++++ lib/mauve/alert_group.rb | 15 +++++++++++++++ 2 files changed, 44 insertions(+) (limited to 'lib/mauve') diff --git a/lib/mauve/alert.rb b/lib/mauve/alert.rb index a5cb885..d3bcf7a 100644 --- a/lib/mauve/alert.rb +++ b/lib/mauve/alert.rb @@ -622,6 +622,35 @@ module Mauve !raised? end + # Work out an array of extra people to notify. + # + # @return [Array] array of persons + def extra_people_to_notify + last_raised_at = self.raised_at + + if last_raised_at.nil? + last_raise = self.histories(:event => "RAISED", :limit => 1, :order => :created_at.desc).first + last_raised_at = last_raise.created_at unless last_raise.nil? + end + + + return [] if last_raised_at.nil? + + notifications = [] + + # + # Find all the people who've been involved with this alert since it was + # last raised. + # + users = histories.all(:created_at.gte => last_raised_at).collect do |h| + h.user + end + [self.acknowledged_by] + + users.compact.sort.uniq.collect do |user| + person = Configuration.current.people[user] + end.compact + end + class << self # Removes or cleans HTML from a string diff --git a/lib/mauve/alert_group.rb b/lib/mauve/alert_group.rb index 31d9cc8..05488fd 100644 --- a/lib/mauve/alert_group.rb +++ b/lib/mauve/alert_group.rb @@ -212,6 +212,21 @@ module Mauve sent_to << notification.notify(alert, sent_to, during_runners.shift) end + # + # If the alert is ack'd or cleared, notify anyone who has contributed to + # its history since it was raised. + # + alert.extra_people_to_notify.each do |person| + person.notifications.each do |n| + notification = Mauve::Notification.new(person) + notification.level = self.level + notification.every = n.every + notification.during = n.during + notification + sent_to << notification.notify(alert, sent_to, DuringRunner.new(at, alert, ¬ification.during)) + end + end if alert.acknowledged? or alert.cleared? + return (sent_to.length > 0) end -- cgit v1.2.1