From 5f4601f61123dda84f26b6e45fe12cd17749e918 Mon Sep 17 00:00:00 2001 From: Victor LABORIE Date: Thu, 20 Sep 2018 10:21:49 +0200 Subject: [PATCH] nagios-nrpe: add check_redis_instances --- CHANGELOG.md | 1 + .../files/plugins/check_redis_instances | 49 +++++++++++++++++++ nagios-nrpe/templates/evolix.cfg.j2 | 1 + 3 files changed, 51 insertions(+) create mode 100755 nagios-nrpe/files/plugins/check_redis_instances diff --git a/CHANGELOG.md b/CHANGELOG.md index 54ac7ed5..341ed6d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ The **patch** part changes incrementally at each release. * networkd-to-ifconfig: add a role to switch from networkd to ifconfig * webapps/evoadmin-web: add users to /etc/aliases * redis: add support for multi instances +* nagios-nrpe: add check_redis_instances ### Changed * dovecot: stronger TLS configuration diff --git a/nagios-nrpe/files/plugins/check_redis_instances b/nagios-nrpe/files/plugins/check_redis_instances new file mode 100755 index 00000000..829cd81e --- /dev/null +++ b/nagios-nrpe/files/plugins/check_redis_instances @@ -0,0 +1,49 @@ +#!/bin/sh + +set -u + +return=0 +nb_crit=0 +nb_warn=0 +nb_ok=0 +nb_unchk=0 +output="" + +instances=$(ls /etc/redis/redis-*.conf) +for instance in ${instances}; do + name=$(basename "${instance}"| sed '{s/redis-//;s/.conf//}') + port=$(grep "port" "${instance}"|grep -oE "[0-9]*") + if [ -h "/etc/systemd/system/multi-user.target.wants/redis-server@${name}.service" ]; then + /usr/lib/nagios/plugins/check_tcp -p "${port}" >/dev/null 2>&1 + ret="${?}" + if [ "${ret}" -ge 2 ]; then + nb_crit=$((nb_crit + 1)) + output="${output}CRITICAL - ${name} (${port})\n" + [ "${return}" -le 2 ] && return=2 + elif [ "${ret}" -ge 1 ]; then + nb_warn=$((nb_warn + 1)) + output="${output}WARNING - ${name} (${port})\n" + [ "${return}" -le 1 ] && return=1 + else + nb_ok=$((nb_ok + 1)) + output="${output}OK - ${name} (${port})\n" + [ "${return}" -le 0 ] && return=0 + fi + else + nb_unchk=$((nb_unchk + 1)) + output="${output}UNCHK - ${name} (${port})\n" + fi +done + +[ "${return}" -ge 0 ] && header="OK" +[ "${return}" -ge 1 ] && header="WARNING" +[ "${return}" -ge 2 ] && header="CRITICAL" + +printf "%s - %s UNCHK / %s CRIT / %s WARN / %s OK\n\n" "${header}" "${nb_unchk}" "${nb_crit}" "${nb_warn}" "${nb_ok}" + +printf "${output}" | grep -E "^CRITICAL" +printf "${output}" | grep -E "^WARNING" +printf "${output}" | grep -E "^OK" +printf "${output}" | grep -E "^UNCHK" + +exit "${return}" diff --git a/nagios-nrpe/templates/evolix.cfg.j2 b/nagios-nrpe/templates/evolix.cfg.j2 index 845bae33..bab8b681 100644 --- a/nagios-nrpe/templates/evolix.cfg.j2 +++ b/nagios-nrpe/templates/evolix.cfg.j2 @@ -68,6 +68,7 @@ command[check_supervisord_status]={{ nagios_plugins_directory }}/check_superviso command[check_varnish]={{ nagios_plugins_directory }}/check_varnish_health -i 127.0.0.1 -p 6082 -s /etc/varnish/secret -w 2 -c 4 command[check_haproxy]={{ nagios_plugins_directory }}/check_haproxy_stats -s /var/run/haproxy.sock -w 80 -c 90 command[check_minifirewall]=sudo {{ nagios_plugins_directory }}/check_minifirewall +command[check_redis_instances]={{ nagios_plugins_directory }}/check_redis_instances # Check HTTP "many". Use this to check many websites (http, https, ports, sockets and SSL certificates). # Beware! All checks must not take more than 10s!