From ddd3e1aa065cea6f51555878e7b80654446dec93 Mon Sep 17 00:00:00 2001 From: Ludovic Poujol Date: Wed, 17 Feb 2021 17:23:11 +0100 Subject: [PATCH] nagios-nrpe: new script check_phpfpm_multi --- CHANGELOG.md | 1 + nagios-nrpe/files/plugins/check_phpfpm_multi | 82 ++++++++++++++++++++ nagios-nrpe/templates/evolix.cfg.j2 | 5 ++ 3 files changed, 88 insertions(+) create mode 100644 nagios-nrpe/files/plugins/check_phpfpm_multi diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a883ccd..6dc8eba9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ The **patch** part changes incrementally at each release. * apache: new variables for logrotate + server-status * filebeat: package can be upgraded to latest (default: False) * metricbeat: package can be upgraded to latest (default: False) +* nagios-nrpe: new script check_phpfpm_multi * nginx: add access to server status on default VHost * postfix: add smtpd_relay_restrictions in configuration diff --git a/nagios-nrpe/files/plugins/check_phpfpm_multi b/nagios-nrpe/files/plugins/check_phpfpm_multi new file mode 100644 index 00000000..b2788d86 --- /dev/null +++ b/nagios-nrpe/files/plugins/check_phpfpm_multi @@ -0,0 +1,82 @@ +#!/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="" + +readonly POOL_FOLDER=${1:-$(detect_pool_dir)} + +if [[ ! -d "$POOL_FOLDER" ]]; then + echo "CRITICAL - $POOL_FOLDER does not exists" + exit 2 +fi; + +readonly POOL_FILES=$(find "$POOL_FOLDER" -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') + + 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 "${target[@]}" -u "$pool_status_path") + 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}$(echo "$result" | cut -d '|' -f1)\n" + [ "${return}" -le 0 ] && return=0 + 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 "%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}" diff --git a/nagios-nrpe/templates/evolix.cfg.j2 b/nagios-nrpe/templates/evolix.cfg.j2 index 3fda958f..3d7eea77 100644 --- a/nagios-nrpe/templates/evolix.cfg.j2 +++ b/nagios-nrpe/templates/evolix.cfg.j2 @@ -70,6 +70,11 @@ command[check_haproxy]=sudo {{ nagios_plugins_directory }}/check_haproxy_stats - command[check_minifirewall]=sudo {{ nagios_plugins_directory }}/check_minifirewall command[check_redis_instances]={{ nagios_plugins_directory }}/check_redis_instances command[check_hpraid]={{ nagios_plugins_directory }}/check_hpraid +command[check_php-fpm]={{ nagios_plugins_directory }}/check_phpfpm_multi +command[check_php-fpm56]={{ nagios_plugins_directory }}/check_phpfpm_multi /var/lib/lxc/php56/rootfs/etc/php5/fpm/pool.d/ +command[check_php-fpm70]={{ nagios_plugins_directory }}/check_phpfpm_multi /var/lib/lxc/php70/rootfs/etc/php/7.0/fpm/pool.d/ +command[check_php-fpm73]={{ nagios_plugins_directory }}/check_phpfpm_multi /var/lib/lxc/php73/rootfs/etc/php/7.3/fpm/pool.d/ +command[check_php-fpm74]={{ nagios_plugins_directory }}/check_phpfpm_multi /var/lib/lxc/php74/rootfs/etc/php/7.4/fpm/pool.d/ # 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!