ansible-roles/nagios-nrpe/files/plugins/check_phpfpm_multi
Brice Waegeneire 72727a8332
All checks were successful
Ansible Lint |Total|New|Outstanding|Fixed|Trend |:-:|:-:|:-:|:-:|:-: |2674|8|2666|7|:-1: Reference build: <a href="https://jenkins.evolix.org/job/gitea/job/ansible-roles/job/unstable/448//ansiblelint">Evolix » ansible-roles » unstable #448</a>
gitea/ansible-roles/pipeline/head This commit looks good
nagios-nrpe: check_phpfpm_multi expand globing of args
2024-01-12 13:38:17 +01:00

95 lines
2.8 KiB
Bash

#!/bin/bash
function detect_pool_dir() {
# Try to autodetect pool directory
php_version=$(php --version |head -n1 | sed -E 's/^PHP ([0-9]\.[0-9]).*/\1/g')
if [[ $php_version =~ ^5. ]]; then
echo "/etc/php5/fpm/pool.d/";
else
echo "/etc/php/$php_version/fpm/pool.d/";
fi
}
return=0
nb_crit=0
nb_warn=0
nb_ok=0
nb_unchk=0
output=""
# We want globbing to be expanded here
# shellcheck disable=SC2206
readonly POOL_FOLDER=( ${1:-$(detect_pool_dir)} )
if [ "${#POOL_FOLDER[@]}" -gt 1 ]; then
echo "CRITICAL - '${POOL_FOLDER[*]}' contains more than one directories"
exit 2
fi;
if [[ ! -d "${POOL_FOLDER[0]}" ]]; then
echo "CRITICAL - ${POOL_FOLDER[0]} does not exists"
exit 2
fi;
readonly POOL_FILES=$(find "${POOL_FOLDER[0]}" -name "*.conf")
for pool_file in $POOL_FILES; do
pool_name=$(grep "^\[" "$pool_file" | sed -E 's/^\[(.*)\].*$/\1/g')
pool_status_path=$(grep -E "^pm.status_path\s?=" "$pool_file" | sed -E "s/.*=\s?'?([^']*)'?\s?$/\1/g")
pool_listen=$(grep -E "^listen\s?=" "$pool_file" | sed -E 's/.*=\s?(.*)\s?$/\1/g')
pool_max_children=$(grep -E "^pm.max_children" "$pool_file" | sed -E 's/.*=\s?(.*)\s?$/\1/g' )
pool_crit_procs=$(expr $pool_max_children \* 85 / 100)
pool_warn_procs=$(expr $pool_max_children \* 55 / 100)
if [[ "$pool_status_path" == '' ]]; then
nb_unchk=$((nb_unchk + 1))
output="${output}UNCHK - ${pool_name} (missing pm.status_path definition)\n"
continue;
fi;
if [[ -S "$pool_listen" ]] || [[ ! "$pool_listen" =~ ':' ]]; then
target=(-H 127.0.0.1 --unix "$pool_listen")
else
target=(-H "$(echo "$pool_listen" | cut -d':' -f1)" -p "$(echo "$pool_listen" | cut -d':' -f2 )")
fi
result=$(perl /usr/local/lib/nagios/plugins/check_phpfpm_status.pl -t 5 "${target[@]}" -u "$pool_status_path" -c "$pool_crit_procs" -w "$pool_warn_procs" )
ret="${?}"
if [ "${ret}" -ge 2 ]; then
nb_crit=$((nb_crit + 1))
[ "${return}" -le 2 ] && return=2
elif [ "${ret}" -ge 1 ]; then
nb_warn=$((nb_warn + 1))
[ "${return}" -le 1 ] && return=1
else
nb_ok=$((nb_ok + 1))
[ "${return}" -le 0 ] && return=0
fi
result_status=$(echo ${result} | awk -F' - ' '{ print $1}')
result_content=$(echo ${result} | awk -F' - ' '{ print $2}')
output="${output}${result_status} - ${pool_file} - ${result_content}\n"
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 "%b" "${output}" | grep -E "(CRITICAL|UNKNOWN)"
printf "%b" "${output}" | grep -E "WARNING"
printf "%b" "${output}" | grep -E "OK"
printf "%b" "${output}" | grep -E "^UNCHK"
exit "${return}"