nagios-nrpe: update check_redis_instances
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
174bfa5ba0
commit
26dd244ae0
|
@ -46,6 +46,7 @@ The **patch** part changes incrementally at each release.
|
||||||
* lxc: remove useless loop in apt execution
|
* lxc: remove useless loop in apt execution
|
||||||
* lxc: update our default template to be compatible with Debian 10
|
* lxc: update our default template to be compatible with Debian 10
|
||||||
* minifirewall: no http filtering by default
|
* minifirewall: no http filtering by default
|
||||||
|
* nagios-nrpe: update check_redis_instances (same as redis role)
|
||||||
* php: By default, allow 128M for OpCache (instead of 64M)
|
* php: By default, allow 128M for OpCache (instead of 64M)
|
||||||
* php: Don't set a chroot for the default fpm pool
|
* php: Don't set a chroot for the default fpm pool
|
||||||
* rbenv: install Ruby 2.6.5 by default
|
* rbenv: install Ruby 2.6.5 by default
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
|
# {{ ansible_managed }}
|
||||||
|
|
||||||
set -u
|
set -u
|
||||||
|
|
||||||
return=0
|
return=0
|
||||||
|
@ -9,35 +11,66 @@ nb_ok=0
|
||||||
nb_unchk=0
|
nb_unchk=0
|
||||||
output=""
|
output=""
|
||||||
|
|
||||||
instances=$(ls /etc/redis/redis-*.conf)
|
packaged_check=/usr/lib/nagios/plugins/check_redis
|
||||||
for instance in ${instances}; do
|
vendored_check=/usr/local/lib/nagios/plugins/check_redis
|
||||||
name=$(basename "${instance}"| sed '{s/redis-//;s/.conf//}')
|
|
||||||
port=$(grep "port" "${instance}"|grep -oE "[0-9]*")
|
if [ -x $packaged_check ]; then
|
||||||
socket=$(grep "unixsocket " "${instance}"|awk '{ print $2 }')
|
check_bin=$packaged_check
|
||||||
if [ -h "/etc/systemd/system/multi-user.target.wants/redis-server@${name}.service" ]; then
|
elif [ -x $vendored_check ]; then
|
||||||
if [ "${port}" -ne 0 ]; then
|
check_bin=$vendored_check
|
||||||
/usr/lib/nagios/plugins/check_tcp -p "${port}" >/dev/null 2>&1
|
else
|
||||||
ret="${?}"
|
echo "UNCHK - can't find check_redis"
|
||||||
else
|
exit 3
|
||||||
/usr/lib/nagios/plugins/check_tcp -H "${socket}" >/dev/null 2>&1
|
fi
|
||||||
ret="${?}"
|
|
||||||
fi
|
check_server() {
|
||||||
if [ "${ret}" -ge 2 ]; then
|
name=$1
|
||||||
nb_crit=$((nb_crit + 1))
|
conf_file=$2
|
||||||
output="${output}CRITICAL - ${name} (${port})\n"
|
|
||||||
[ "${return}" -le 2 ] && return=2
|
host=$(config_var "bind" "${conf_file}")
|
||||||
elif [ "${ret}" -ge 1 ]; then
|
port=$(config_var "port" "${conf_file}")
|
||||||
nb_warn=$((nb_warn + 1))
|
pass=$(config_var "requirepass" "${conf_file}")
|
||||||
output="${output}WARNING - ${name} (${port})\n"
|
|
||||||
[ "${return}" -le 1 ] && return=1
|
cmd="${check_bin} -H ${host} -p ${port}"
|
||||||
else
|
if [ -n "${pass}" ]; then
|
||||||
nb_ok=$((nb_ok + 1))
|
cmd="${cmd} -x ${pass}"
|
||||||
output="${output}OK - ${name} (${port})\n"
|
fi
|
||||||
[ "${return}" -le 0 ] && return=0
|
result=$($cmd)
|
||||||
fi
|
ret="${?}"
|
||||||
|
if [ "${ret}" -ge 2 ]; then
|
||||||
|
nb_crit=$((nb_crit + 1))
|
||||||
|
output="${output}${result}\n"
|
||||||
|
[ "${return}" -le 2 ] && return=2
|
||||||
|
elif [ "${ret}" -ge 1 ]; then
|
||||||
|
nb_warn=$((nb_warn + 1))
|
||||||
|
output="${output}${result}\n"
|
||||||
|
[ "${return}" -le 1 ] && return=1
|
||||||
|
else
|
||||||
|
nb_ok=$((nb_ok + 1))
|
||||||
|
output="${output}${result}\n"
|
||||||
|
[ "${return}" -le 0 ] && return=0
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
config_var() {
|
||||||
|
variable=$1
|
||||||
|
file=$2
|
||||||
|
test -f $file && grep -E "^${variable}\s+.+$" $file | awk '{ print $2 }'
|
||||||
|
}
|
||||||
|
|
||||||
|
# default instance
|
||||||
|
if systemctl is-enabled -q redis-server; then
|
||||||
|
check_server "default" "/etc/redis/redis.conf"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# additional instances
|
||||||
|
conf_files=$(ls -1 /etc/redis-*/redis.conf)
|
||||||
|
for conf_file in ${conf_files}; do
|
||||||
|
name=$(dirname ${conf_file} | sed '{s|/etc/redis-||}')
|
||||||
|
if systemctl is-enabled -q "redis-server@${name}.service"; then
|
||||||
|
check_server $name $conf_file
|
||||||
else
|
else
|
||||||
nb_unchk=$((nb_unchk + 1))
|
nb_unchk=$((nb_unchk + 1))
|
||||||
output="${output}UNCHK - ${name} (${port})\n"
|
output="${output}UNCHK - ${name} (unit is disabled or missing)\n"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
@ -47,9 +80,9 @@ done
|
||||||
|
|
||||||
printf "%s - %s UNCHK / %s CRIT / %s WARN / %s OK\n\n" "${header}" "${nb_unchk}" "${nb_crit}" "${nb_warn}" "${nb_ok}"
|
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 "%s" "${output}" | grep -E "^CRITICAL"
|
||||||
printf "${output}" | grep -E "^WARNING"
|
printf "%s" "${output}" | grep -E "^WARNING"
|
||||||
printf "${output}" | grep -E "^OK"
|
printf "%s" "${output}" | grep -E "^OK"
|
||||||
printf "${output}" | grep -E "^UNCHK"
|
printf "%s" "${output}" | grep -E "^UNCHK"
|
||||||
|
|
||||||
exit "${return}"
|
exit "${return}"
|
||||||
|
|
Loading…
Reference in a new issue