From d79f8f76d1b8a0940814f41760f1387d0e1364d9 Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Mon, 26 Nov 2012 15:05:18 +0000 Subject: Don't attempt to raise/clear with redis/mauve unless they were loaded. --- lib/custodian/alerts/mauve.rb | 14 ++++++++++++-- lib/custodian/alerts/redis-state.rb | 37 ++++++++++++++++++++++--------------- 2 files changed, 34 insertions(+), 17 deletions(-) (limited to 'lib/custodian/alerts') diff --git a/lib/custodian/alerts/mauve.rb b/lib/custodian/alerts/mauve.rb index 37ed539..417a1f2 100644 --- a/lib/custodian/alerts/mauve.rb +++ b/lib/custodian/alerts/mauve.rb @@ -29,6 +29,11 @@ module Custodian # attr_reader :test + # + # Was this class loaded correctly? + # + attr_reader :loaded + @@ -41,8 +46,10 @@ module Custodian begin require 'mauve/sender' require 'mauve/proto' - rescue LoadError - raise "ERROR Loading mauvealert libraries!" + @loaded = true + rescue + puts "ERROR Loading mauve libraries!" + @loaded = false end end @@ -54,6 +61,7 @@ module Custodian # def raise() + return unless( @loaded ) # # Get ready to send to mauve. @@ -88,6 +96,8 @@ module Custodian # def clear + return unless( @loaded ) + # # Get ready to send to mauve. # diff --git a/lib/custodian/alerts/redis-state.rb b/lib/custodian/alerts/redis-state.rb index b2243f7..38b592e 100644 --- a/lib/custodian/alerts/redis-state.rb +++ b/lib/custodian/alerts/redis-state.rb @@ -14,35 +14,38 @@ module Custodian class RedisAlert < AlertFactory + # # The test this alerter cares about # attr_reader :test + # # The redis-object # attr_reader :redis - attr_reader :available + + # # Constructor - save the test-object away & instantiate # the redis connection. # def initialize( obj ) - @available = true - - begin - require 'rubygems' - require 'redis' - rescue - puts "LOADING redis failed" - @available = false - end - - @test = obj - @redis = Redis.new( ) if ( @available ) + + begin + require 'rubygems' + require 'redis' + + @redis = Redis.new() + + rescue + puts "ERROR Loading redis rubygem!" + end + + @test = obj end @@ -51,7 +54,9 @@ module Custodian # Store an alert in redis # def raise - return if ( ! @available ) + + return unless( @redis ) + # hostname + test-type host = @test.target @@ -71,7 +76,9 @@ module Custodian # Clear an alert in redis # def clear - return if ( ! @available ) + + return unless( @redis ) + # hostname + test-type host = @test.target -- cgit v1.2.1