diff options
| author | Steve Kemp <steve@steve.org.uk> | 2012-11-26 10:56:27 +0000 | 
|---|---|---|
| committer | Steve Kemp <steve@steve.org.uk> | 2012-11-26 10:56:27 +0000 | 
| commit | f6b134149b469751d318cc1bbd72d29b735d3acb (patch) | |
| tree | d0227ad3bcc356a6da041d1c853b2b49b3010450 /lib/custodian/alerts | |
| parent | 1bc00fe308b4d6de3faddb1bfc1e7529f3ba6f40 (diff) | |
  Added the redis-alerter.
Diffstat (limited to 'lib/custodian/alerts')
| -rw-r--r-- | lib/custodian/alerts/redis-state.rb | 89 | 
1 files changed, 89 insertions, 0 deletions
| diff --git a/lib/custodian/alerts/redis-state.rb b/lib/custodian/alerts/redis-state.rb new file mode 100644 index 0000000..0c0b6a0 --- /dev/null +++ b/lib/custodian/alerts/redis-state.rb @@ -0,0 +1,89 @@ + +require 'rubygems' +require 'redis' + + +# +#  The redis-alerter. +# +#  This doesn't raise/clear alerts in the traditional sense, instead it just +# stores results in a redis database where you can poll them from a status-panel, +# or similar. +# +#  There is a global set called "hosts" which has the hostname-test-type lists +# and the individual results can be pulled by simple key-fetches on those. +# +module Custodian + +  module Alerter + +    class AlertRedis < AlertFactory + +      # +      # The test this alerter cares about +      # +      attr_reader :test + +      # +      # The redis-object +      # +      attr_reader :redis + + +      # +      # Constructor - save the test-object away & instantiate +      # the redis connection. +      # +      def initialize( obj ) +        @test = obj +        @redis = Redis.new +      end + + + +      # +      # Store an alert in redis +      # +      def raise + +        # hostname + test-type +        host = @test.target +        test = @test.get_type + +        # store the error +        @redis.set( "#{host}-#{test}", "ERR") +        @redis.set( "#{host}-#{test}-reason", @test.error() ) + +        # make sure this alert is discoverable +        @redis.sadd( "hosts", "#{host}-#{test}" ) +      end + + + +      # +      # Clear an alert in redis +      # +      def clear + +        # hostname + test-type +        host = @test.target +        test = @test.get_type + +        # store the OK +        @redis.set( "#{host}-#{test}", "OK") +        @redis.set( "#{host}-#{test}-reason", "") + +        # make sure this alert is discoverable +        @redis.sadd( "hosts", "#{host}-#{test}" ) +      end + + + +      register_alert_type "redis" + + + + +    end +  end +end | 
