diff options
author | Steve Kemp <steve@steve.org.uk> | 2012-11-26 11:04:54 +0000 |
---|---|---|
committer | Steve Kemp <steve@steve.org.uk> | 2012-11-26 11:04:54 +0000 |
commit | c6e8287abf523721b855e0878380c2fc12df9a8c (patch) | |
tree | 21688449e1f18f2dbfbae3856110322966711da1 | |
parent | fd80dc9a045e9c939bfb722d2d74a0c379aa4ac8 (diff) |
Allow multiple alerters.
-rw-r--r-- | lib/custodian/worker.rb | 45 |
1 files 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 + # |