bin/check-redis-info.rb in sensu-plugins-redis-1.2.2 vs bin/check-redis-info.rb in sensu-plugins-redis-1.3.0
- old
+ new
@@ -18,10 +18,16 @@
require 'sensu-plugin/check/cli'
require 'redis'
class RedisSlaveCheck < Sensu::Plugin::Check::CLI
+ option :socket,
+ short: '-s SOCKET',
+ long: '--socket SOCKET',
+ description: 'Redis socket to connect to (overrides Host and Port)',
+ required: false
+
option :host,
short: '-h HOST',
long: '--host HOST',
description: 'Redis Host to connect to',
required: false,
@@ -53,19 +59,23 @@
description: 'Redis info key value to trigger alarm',
required: false,
default: 'master'
def run
- options = { host: config[:host], port: config[:port] }
+ options = if config[:socket]
+ { path: socket }
+ else
+ { host: config[:host], port: config[:port] }
+ end
+
options[:password] = config[:password] if config[:password]
redis = Redis.new(options)
if redis.info.fetch(config[:redis_info_key].to_s) == config[:redis_info_value].to_s
ok "Redis #{config[:redis_info_key]} is #{config[:redis_info_value]}"
else
critical "Redis #{config[:redis_info_key]} is #{redis.info.fetch(config[:redis_info_key].to_s)}!"
end
-
rescue
message "Could not connect to Redis server on #{config[:host]}:#{config[:port]}"
exit 1
end
end