forked from sensu/sensu-community-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck-redis-slave-status.rb
executable file
·54 lines (44 loc) · 1.43 KB
/
check-redis-slave-status.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env ruby
#
# Checks Redis Slave Replication
require 'rubygems' if RUBY_VERSION < '1.9.0'
require 'sensu-plugin/check/cli'
require 'redis'
class RedisSlaveCheck < Sensu::Plugin::Check::CLI
option :host,
:short => "-h HOST",
:long => "--host HOST",
:description => "Redis Host to connect to",
:required => false,
:default => '127.0.0.1'
option :port,
:short => "-p PORT",
:long => "--port PORT",
:description => "Redis Port to connect to",
:proc => proc { |p| p.to_i },
:required => false,
:default => 6379
option :password,
:short => "-P PASSWORD",
:long => "--password PASSWORD",
:description => "Redis Password to connect with"
def run
begin
options = {:host => config[:host], :port => config[:port]}
options[:password] = config[:password] if config[:password]
redis = Redis.new(options)
if redis.info.fetch('master_link_status') == 'up'
ok 'The redis master links status is up!'
else
msg = ''
msg += "The redis master link status to: #{redis.info.fetch('master_host')} is down!"
msg += " It has been down for #{redis.info.fetch('master_link_down_since_seconds')}."
critical msg
end
rescue KeyError
critical "Redis server on #{config[:host]}:#{config[:port]} is master"
rescue
critical "Could not connect to Redis server on #{config[:host]}:#{config[:port]}"
end
end
end