From 42f14de6ab50d0e05f49f038e40b94b686701bf1 Mon Sep 17 00:00:00 2001 From: Patrick J Cherry Date: Wed, 15 Jun 2011 19:44:07 +0100 Subject: * 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 --- lib/mauve/alert_group.rb | 58 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 46 insertions(+), 12 deletions(-) (limited to 'lib/mauve/alert_group.rb') diff --git a/lib/mauve/alert_group.rb b/lib/mauve/alert_group.rb index adb9909..a8b1482 100644 --- a/lib/mauve/alert_group.rb +++ b/lib/mauve/alert_group.rb @@ -4,13 +4,26 @@ require 'log4r' module Mauve class AlertGroup < Struct.new(:name, :includes, :acknowledgement_time, :level, :notifications) - def to_s - "#" - end + + # + # Define some constants, and the ordering. + # + URGENT = :urgent + NORMAL = :normal + LOW = :low + LEVELS = [LOW, NORMAL, URGENT] class << self + def matches(alert) - all.select { |alert_group| alert_group.matches_alert?(alert) } + grps = all.select { |alert_group| alert_group.matches_alert?(alert) } + + # + # Make sure we always match the last (and therefore default) group. + # + grps << all.last unless grps.include?(all.last) + + grps end # If there is any significant change to a set of alerts, the Alert @@ -26,18 +39,19 @@ module Mauve # # Make sure we've got a matching group # - logger.warn "no groups found for #{alert.id}" if groups.empty? + if groups.empty? + logger.warn "no groups found for #{alert}" + next + end # # Notify just the group that thinks this alert is the most urgent. # - %w(urgent normal low).each do |lvl| - this_group = groups.find{|grp| grp.level.to_s == lvl} - next if this_group.nil? - logger.info("notifying group #{this_group} of AlertID.#{alert.id} (matching #{lvl})") - this_group.notify(alert) - break - end + logger.warn "Found #{groups.length} matching groups for #{alert}" if groups.length > 1 + + this_group = groups.first + logger.info("notifying group #{this_group} of #{alert} (matching #{this_group.level})") + this_group.notify(alert) end end @@ -70,6 +84,10 @@ module Mauve self.level = :normal self.includes = Proc.new { true } end + + def to_s + "#" + end # The list of current raised alerts in this group. # @@ -97,6 +115,14 @@ module Mauve # has undergone a significant change. We resend this to every notify list. # def notify(alert) + # + # If there are no notifications defined. + # + if notifications.nil? + logger.warn("No notifications found for #{alert}") + return + end + # # The notifications are specified in the config file. # @@ -105,6 +131,14 @@ module Mauve end end + # + # This sorts by priority (urgent first), and then alphabetically, so the + # first match is the most urgent. + # + def <=>(other) + [LEVELS.index(self.level), self.name] <=> [LEVELS.index(other.level), other.name] + end + end end -- cgit v1.2.1