diff options
-rw-r--r-- | etc/custodian/custodian.cfg | 13 | ||||
-rw-r--r-- | lib/custodian/settings.rb | 26 | ||||
-rw-r--r-- | lib/custodian/worker.rb | 13 |
3 files changed, 38 insertions, 14 deletions
diff --git a/etc/custodian/custodian.cfg b/etc/custodian/custodian.cfg index 1a22239..5299fed 100644 --- a/etc/custodian/custodian.cfg +++ b/etc/custodian/custodian.cfg @@ -25,14 +25,21 @@ ## # The target of the alert is alerter-specific. # +# A target is based upon the name of the alerter with "_target" +# suffixed. +# +# # For alerter=smtp the target is the email address to notify. -# alerter_target = root@localhost +# smtp_target = root@localhost # # For alerter=mauve the target is the host to notify -# alerter_target = alert.bytemark.co.uk +# mauve_target = alert.bytemark.co.uk # # For alerter=file the target is the logfile to write to. -# alerter_target = /tmp/alerts.log +# file_target = /tmp/alerts.log +# +# For alerter=redis the target is the redis server to talk to. +# redis_target = 127.0.0.1 # ## 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 |