From c61f9735c8b5be297c6114d8f2067adf42566b9e Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Mon, 26 Nov 2012 16:02:00 +0000 Subject: Updated so that each alert-type has its dedicated alert-target. --- lib/custodian/settings.rb | 26 +++++++++++++++++--------- lib/custodian/worker.rb | 13 +++++++++++-- 2 files changed, 28 insertions(+), 11 deletions(-) (limited to 'lib') diff --git a/lib/custodian/settings.rb b/lib/custodian/settings.rb index 48adcc0..b601d79 100644 --- a/lib/custodian/settings.rb +++ b/lib/custodian/settings.rb @@ -54,6 +54,7 @@ module Custodian val = $2.dup key.strip! val.strip! + @settings[key] = val end end @@ -125,24 +126,31 @@ module Custodian # # When the alerter is "mauve" the target is the destination for the alerts. # - def alerter_target + def alerter_target( alert ) _load() unless( _loaded? ) + + # + # Find the alerting method. + # # if we have something setup then use it. - if ( @settings['alerter_target'] ) - return( @settings['alerter_target'] ) + if ( @settings["#{alert}_target"] ) + return( @settings["#{alert}_target"] ) + else end # otherwise per-test defaults. - case alerter() - when "smtp": + case alert + when "smtp": "root" - when "mauve": + when "mauve": "alert.bytemark.co.uk" - when "file": + when "file": "alerts.log" - else - nil + when "redis": + "127.0.0.1:6379" + else + nil end end diff --git a/lib/custodian/worker.rb b/lib/custodian/worker.rb index 57c55f7..79dab1e 100644 --- a/lib/custodian/worker.rb +++ b/lib/custodian/worker.rb @@ -213,9 +213,14 @@ module Custodian # def do_raise( test ) @alerter.split( "," ).each do |alerter| + log_message( "Creating alerter: #{alerter}" ) alert = Custodian::AlertFactory.create( alerter, test ) - alert.set_target( Custodian::Settings.instance().alerter_target() ) + + target = Custodian::Settings.instance().alerter_target( alerter ) + puts "Target for alert is #{target}" + + alert.set_target( target ) alert.raise() end end @@ -228,7 +233,11 @@ module Custodian @alerter.split( "," ).each do |alerter| log_message( "Creating alerter: #{alerter}" ) alert = Custodian::AlertFactory.create( alerter, test ) - alert.set_target( Custodian::Settings.instance().alerter_target() ) + + target = Custodian::Settings.instance().alerter_target( alerter ) + puts "Target for alert is #{target}" + + alert.set_target( target ) alert.clear() end end -- cgit v1.2.1