From 9cd0426d2b5233740803fdbd9abc5040ff2575a0 Mon Sep 17 00:00:00 2001 From: Jeremy Lecour Date: Tue, 26 Sep 2023 10:40:06 +0200 Subject: [PATCH] nagios-nrpe: sync Redis check from redis roles --- CHANGELOG.md | 1 + .../files/plugins/check_redis_instances | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c22c28b2..a197cf09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -75,6 +75,7 @@ The **patch** part changes is incremented if multiple releases happen the same m * lxc-php: fix APT keyring path inside containers * nagios-nrpe: `check_ssl_local` now has an output that nrpe can understand when it isn't OK * nagios-nrpe: remount `/usr` **after** installing the packages +* nagios-nrpe: sync Redis check from redis roles * nginx: set default server directive in default vhost * opendkim: update apt cache before install * packweb-apache,nagios-nrpe: add missing task and config for PHP 8.2 container diff --git a/nagios-nrpe/files/plugins/check_redis_instances b/nagios-nrpe/files/plugins/check_redis_instances index 5923eef7..32580486 100755 --- a/nagios-nrpe/files/plugins/check_redis_instances +++ b/nagios-nrpe/files/plugins/check_redis_instances @@ -30,11 +30,21 @@ check_server() { host=$(config_var "bind" "${conf_file}") port=$(config_var "port" "${conf_file}") pass=$(config_var "requirepass" "${conf_file}") + maxmemory=$(config_var "maxmemory" "${conf_file}") + maxmemory_policy=$(config_var "maxmemory-policy" "${conf_file}") cmd="${check_bin} -H ${host} -p ${port}" + # If "requirepass" is set we add the password to the check if [ -n "${pass}" ]; then cmd="${cmd} -x ${pass}" fi + # If "maxmemory" is set and "maxmemory-policy" is missing or set to "noeviction" + # then we enforce the "maxmemory" limit + if [ -n "${maxmemory}" ]; then + if [ -z "${maxmemory_policy}" ] || [ "${maxmemory_policy}" = "noeviction" ]; then + cmd="${cmd} --total_memory ${maxmemory} --memory_utilization 80,90" + fi + fi result=$($cmd) ret="${?}" if [ "${ret}" -ge 2 ]; then @@ -54,7 +64,7 @@ check_server() { config_var() { variable=$1 file=$2 - test -f $file && grep -E "^${variable}\s+.+$" $file | awk '{ print $2 }' + test -f "${file}" && grep -E "^${variable}\s+.+$" "${file}" | awk '{ print $2 }' | sed -e "s/^[\"']//" -e "s/[\"']$//" } # default instance @@ -63,11 +73,11 @@ if systemctl is-enabled -q redis-server; then fi # additional instances -conf_files=$(ls -1 /etc/redis-*/redis.conf) +conf_files=$(ls -1 /etc/redis-*/redis.conf 2> /dev/null) for conf_file in ${conf_files}; do - name=$(dirname ${conf_file} | sed '{s|/etc/redis-||}') + name=$(dirname "${conf_file}" | sed '{s|/etc/redis-||}') if systemctl is-enabled -q "redis-server@${name}.service"; then - check_server $name $conf_file + check_server "${name}" "${conf_file}" else nb_unchk=$((nb_unchk + 1)) output="${output}UNCHK - ${name} (unit is disabled or missing)\n"