From 23515b58e0d4b64127db3391d9e02756a1deff53 Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Mon, 26 Nov 2012 11:04:54 +0000 Subject: Allow multiple alerters. --- lib/custodian/worker.rb | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/lib/custodian/worker.rb b/lib/custodian/worker.rb index bdafb9d..57c55f7 100644 --- a/lib/custodian/worker.rb +++ b/lib/custodian/worker.rb @@ -155,22 +155,6 @@ module Custodian test = Custodian::TestFactory.create( body ) - # - # As a result of this test we'll either raise/clear with one - # of our alerter classes. - # - # Here we create one of the correct type. - # - alert = Custodian::AlertFactory.create( @alerter, test ) - - # - # Set the target for the alert, which might be nil. - # - alert.set_target( Custodian::Settings.instance().alerter_target() ) - - - - # # We'll run no more than MAX times. @@ -189,8 +173,8 @@ module Custodian if ( result ) log_message( "Test succeeed - clearing alert" ) + do_clear( test ) success = true - alert.clear() end count += 1 end @@ -204,7 +188,7 @@ module Custodian # Raise the alert, passing the error message. # log_message( "Test failed - alerting with #{test.error()}" ) - alert.raise() + do_raise( test ) end rescue => ex @@ -224,6 +208,31 @@ module Custodian end + # + # Raise an alert, with each registered alerter. + # + 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() ) + alert.raise() + end + end + + + # + # Clear an alert, with each registered alerter. + # + def do_clear( 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() ) + alert.clear() + end + end + # -- cgit v1.2.1