From 9c91dfd76ef88d3edd9358fb52895025c2193c21 Mon Sep 17 00:00:00 2001 From: Jan Wagner Date: Mon, 6 Oct 2014 13:50:32 +0200 Subject: [PATCH] Adding check_sentinel --- check_sentinel/Makefile | 4 ++ check_sentinel/check_sentinel | 84 +++++++++++++++++++++++++++++++ check_sentinel/check_sentinel.cfg | 6 +++ check_sentinel/control | 6 +++ check_sentinel/copyright | 21 ++++++++ debian/README.Debian.plugins | 3 ++ debian/control | 3 +- debian/copyright | 30 +++++++++++ 8 files changed, 156 insertions(+), 1 deletion(-) create mode 100644 check_sentinel/Makefile create mode 100644 check_sentinel/check_sentinel create mode 100644 check_sentinel/check_sentinel.cfg create mode 100644 check_sentinel/control create mode 100644 check_sentinel/copyright diff --git a/check_sentinel/Makefile b/check_sentinel/Makefile new file mode 100644 index 0000000..52de70c --- /dev/null +++ b/check_sentinel/Makefile @@ -0,0 +1,4 @@ +#/usr/bin/make -f + +include ../common.mk + diff --git a/check_sentinel/check_sentinel b/check_sentinel/check_sentinel new file mode 100644 index 0000000..ffc5164 --- /dev/null +++ b/check_sentinel/check_sentinel @@ -0,0 +1,84 @@ +#!/usr/bin/env ruby +# +# Nagios plugin to monitor Redis sentinel +# +# Checks general connectivity to a Redis sentinel server and will go critical +# for any of the following conditions: +# * Inability to connect to the sentinel server +# * Sentinel reports it isn't monitoring any masters +# * Sentinel has entered TILT mode +# +# Arguments: +# -H --host HOSTNAME to connect to (defaults to 127.0.0.1) +# -p --port PORT to connect to (defaults to 26379) +# +# Requires the "redis" Rubygem +# +# Author: Chris Boulton +# License: MIT (http://www.opensource.org/licenses/mit-license.php) +# + +require 'redis' +require 'optparse' + +STATES = { + :ok => 0, + :warning => 1, + :critical => 2, + :unknown => 3, +} + +options = { + :host => '127.0.0.1', + :port => 26379, + :timeout => 2, +} + +$results = [] +$exit_status = :ok + +def add_state(status, msg, should_exit = false) + $results.push(msg) + $exit_status = status if STATES[status] > STATES[$exit_status] + if should_exit + do_exit + end +end + +def add_info(msg) + $results.push(msg) +end + +def do_exit + puts "#{$exit_status.upcase} - #{$results.join('. ')}" + exit STATES[$exit_status] +end + +optparse = OptionParser.new do |opts| + opts.on('-H', '--host HOST', 'Hostname') do |h| + options[:host] = h + end + + opts.on('-p', '--port PORT', 'Port') do |p| + options[:port] = p.to_i + end +end +optparse.parse! + +begin + redis = Redis.new(:host => options[:host], :port => options[:port], :timeout => options[:timeout]) + + info = redis.info + add_state(:critical, "Redis instance is not configured as a sentinel", true) unless info['sentinel_masters'] + add_state(:critical, "Sentinel has entered TILT mode", true) if info['sentinel_tilt'] != '0' + + if info['sentinel_masters'] == '0' + add_state(:critical, "Sentinel is not monitoring any masters", true) + else + add_info("Monitoring #{info['sentinel_masters']} masters") + end +rescue Redis::CannotConnectError => e + add_state(:critical, e, true) +end + +do_exit diff --git a/check_sentinel/check_sentinel.cfg b/check_sentinel/check_sentinel.cfg new file mode 100644 index 0000000..f78e24e --- /dev/null +++ b/check_sentinel/check_sentinel.cfg @@ -0,0 +1,6 @@ +# 'check_sentinel' command definition +define command { + command_name check_sentinel + command_line /usr/lib/monitoring-plugins/check_sentinel -H '$HOSTADDRESS$' -p '$ARG1$' +} + diff --git a/check_sentinel/control b/check_sentinel/control new file mode 100644 index 0000000..e7031b1 --- /dev/null +++ b/check_sentinel/control @@ -0,0 +1,6 @@ +Homepage: https://raw.github.com/reedox/check_sentinel/master/check_sentinel +Watch: https://github.com/reedox/check_sentinel ([0-9a-f]+) +Recommends: ruby-redis +Version: 0b8e0e388a +Uploaders: Jan Wagner +Description: plugin to monitor Redis sentinel diff --git a/check_sentinel/copyright b/check_sentinel/copyright new file mode 100644 index 0000000..58cf134 --- /dev/null +++ b/check_sentinel/copyright @@ -0,0 +1,21 @@ +Copyright Chris Boulton + +License: MIT + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/debian/README.Debian.plugins b/debian/README.Debian.plugins index 2962fba..216f963 100644 --- a/debian/README.Debian.plugins +++ b/debian/README.Debian.plugins @@ -34,6 +34,9 @@ check_phpfpm_status: check_redis: Required Packages: libredis-perl +check_sentinel: + Required Packages: ruby-redis + check_tftp: Required Packages: libnet-tftp-perl diff --git a/debian/control b/debian/control index 4d26f87..0a01aae 100644 --- a/debian/control +++ b/debian/control @@ -11,7 +11,7 @@ Vcs-Browser: http://github.com/waja/monitoring-plugins-cyconet Package: monitoring-plugins-cyconet Architecture: any Depends: ${misc:Depends} -Recommends: ${shlibs:Depends}, ${python:Depends}, libnet-snmp-perl, nagios-plugins-common, libtime-modules-perl, libwww-perl, python-argparse, libredis-perl, libnet-tftp-perl, libxml-xpath-perl, ${perl:Depends} +Recommends: ${shlibs:Depends}, ${python:Depends}, libnet-snmp-perl, nagios-plugins-common, libtime-modules-perl, libwww-perl, python-argparse, libredis-perl, ruby-redis, libnet-tftp-perl, libxml-xpath-perl, ${perl:Depends} Suggests: Enhances: nagios-plugins, nagios-plugins-basic, nagios-plugins-standard Description: Plugins for nagios compatible monitoring systems @@ -29,6 +29,7 @@ Description: Plugins for nagios compatible monitoring systems * check_openvpn (20130904): plugin to check if an OpenVPN server runs on a given port * check_phpfpm_status (0.9): plugin to check the fpm-status page report from php-fpm * check_redis (0.72): plugin that verifies redis server is working. + * check_sentinel (0b8e0e388a): plugin to monitor Redis sentinel * check_tftp (0.11): plugin that verifies TFTP server is working. * check_tomcat (1.4): plugin to check the tomcat status page. . diff --git a/debian/copyright b/debian/copyright index 6fee32b..eadac19 100644 --- a/debian/copyright +++ b/debian/copyright @@ -169,6 +169,36 @@ http://william.leibzon.org/nagios/ +------------------------------------------------------------------------------ + +check_sentinel: + +The plugin was downloaded from: +https://raw.github.com/reedox/check_sentinel/master/check_sentinel + + Copyright Chris Boulton + + License: MIT + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + + ------------------------------------------------------------------------------ check_tftp: