ansible-roles/nagios-nrpe/files/plugins/check_redis_instances

56 lines
1.7 KiB
Bash
Executable file

#!/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]*")
socket=$(grep "unixsocket " "${instance}"|awk '{ print $2 }')
if [ -h "/etc/systemd/system/multi-user.target.wants/redis-server@${name}.service" ]; then
if [ "${port}" -ne 0 ]; then
/usr/lib/nagios/plugins/check_tcp -p "${port}" >/dev/null 2>&1
ret="${?}"
else
/usr/lib/nagios/plugins/check_tcp -H "${socket}" >/dev/null 2>&1
ret="${?}"
fi
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}"