summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSteve Kemp <steve@steve.org.uk>2015-02-12 09:13:43 +0000
committerSteve Kemp <steve@steve.org.uk>2015-02-12 09:13:43 +0000
commit129e956c5aeae94213397a0cd3b0b2dae8d72037 (patch)
tree224c673f1cc93d97be0b28355b5faf929411f2c7 /lib
parente8ddd65738b62c016569d0f0ba1b00b1c19d7e80 (diff)
Updated to store the test results in a set.
The redis-state "alerter" saves state in a useful way for the future, and will now save an array of hashes - each has corresponding to a useful result.
Diffstat (limited to 'lib')
-rw-r--r--lib/custodian/alerts/redis-state.rb79
1 files changed, 20 insertions, 59 deletions
diff --git a/lib/custodian/alerts/redis-state.rb b/lib/custodian/alerts/redis-state.rb
index b2bd0ab..e77d53a 100644
--- a/lib/custodian/alerts/redis-state.rb
+++ b/lib/custodian/alerts/redis-state.rb
@@ -1,12 +1,9 @@
#
# 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.
+# This doesn't raise/clear alerts in the traditional sense, instead
+# it just saves the results in a "recent tests" set inside Redis.
#
-# 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
@@ -14,7 +11,6 @@ module Custodian
class RedisAlert < AlertFactory
-
#
# The test this alerter cares about
#
@@ -57,21 +53,16 @@ module Custodian
return unless( @redis )
+ tmp = {}
+ tmp["time"] = Time.now.to_i
+ tmp["type"] = @test.get_type
+ tmp["target"] = @test.target
+ tmp["result"] = "RAISE"
+ tmp["reason"] = @test.error()
- # hostname + test-type
- host = @test.target
- test = @test.get_type
-
- # store the error - set an expiry time of 5 minutes
- @redis.set( "#{host}-#{test}", "ERR")
- @redis.expireat( "#{host}-#{test}", Time.now.to_i + 5 * 60 )
-
- # Set the reason
- @redis.set( "#{host}-#{test}-reason", @test.error() )
- @redis.expireat( "#{host}-#{test}-reason", Time.now.to_i + 5 * 60 )
+ @redis.lpush( "recent-tests", tmp.to_json)
+ @redis.ltrim( "recent-tests", 0, 100 )
- # make sure this alert is discoverable
- @redis.sadd( "hosts", "#{host}-#{test}" )
end
@@ -84,21 +75,15 @@ module Custodian
return unless( @redis )
- # hostname + test-type
- host = @test.target
- test = @test.get_type
-
- # store the OK - set the expiry time of five minutes
- @redis.set( "#{host}-#{test}", "OK")
- @redis.expireat( "#{host}-#{test}", Time.now.to_i + 5 * 60 )
-
- # clear the reason
- @redis.set( "#{host}-#{test}-reason", "")
- @redis.expireat( "#{host}-#{test}-reason", Time.now.to_i + 5 * 60 )
+ tmp = {}
+ tmp["time"] = Time.now.to_i
+ tmp["type"] = @test.get_type
+ tmp["target"] = @test.target
+ tmp["result"] = "OK"
+ tmp["reason"] = ""
-
- # make sure this alert is discoverable
- @redis.sadd( "hosts", "#{host}-#{test}" )
+ @redis.lpush( "recent-tests", tmp.to_json)
+ @redis.ltrim( "recent-tests", 0, 100 )
end
@@ -110,35 +95,11 @@ module Custodian
return unless( @redis )
- #
- # hostname + test-type
- #
- host = @test.target
- test = @test.get_type
-
- #
- # Store the host.
- #
- # make sure this alert is discoverable
- @redis.sadd( "duration-hosts", host )
-
- #
- # Store the test.
- #
- @redis.sadd( "duration-host-#{host}", test )
-
- #
- # Now store the duration, and trim it to the most recent
- # 1000 entries.
- #
- @redis.lpush( "duration-#{host}-#{test}", ms )
- @redis.ltrim( "duration-#{host}-#{test}", "0", "1200" )
+ # NOP
end
- register_alert_type "redis"
-
-
+ register_alert_type "redis"
end
end