From 6b25df930e28b437b111c4ce12998c66d3d44158 Mon Sep 17 00:00:00 2001 From: patvdv Date: Mon, 25 Mar 2019 14:48:42 +0100 Subject: [PATCH] * check_linux_fs_usage(): exclude /dev/loop* + rationalization * check_linux_postfix_status(): fix for older Debian & Ubuntu --- .../platform/linux/check_linux_fs_usage.sh | 38 ++++++++----------- .../linux/check_linux_postfix_status.sh | 16 +++++++- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/sources/lib/platform/linux/check_linux_fs_usage.sh b/sources/lib/platform/linux/check_linux_fs_usage.sh index ecbbb54..4fef31e 100644 --- a/sources/lib/platform/linux/check_linux_fs_usage.sh +++ b/sources/lib/platform/linux/check_linux_fs_usage.sh @@ -26,8 +26,9 @@ # @(#) 2019-01-27: regex fix [Patrick Van der Veken] # @(#) 2019-01-30: refactored to support custom definitions with all # filesystems check [Patrick Van der Veken] -# @(#) 2019-02-04: fix in cleanup -# @(#) 2019-02-18: fixes + help update +# @(#) 2019-02-04: fix in cleanup [Patrick Van der Veken] +# @(#) 2019-02-18: fixes + help update [Patrick Van der Veken] +# @(#) 2019-03-25: exclude /dev/loop* + rationalization [Patrick Van der Veken] # ----------------------------------------------------------------------------- # DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! #****************************************************************************** @@ -37,7 +38,7 @@ function check_linux_fs_usage { # ------------------------- CONFIGURATION starts here ------------------------- typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" -typeset _VERSION="2019-02-18" # YYYY-MM-DD +typeset _VERSION="2019-03-25" # YYYY-MM-DD typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match # ------------------------- CONFIGURATION ends here --------------------------- @@ -59,14 +60,10 @@ typeset _CFG_SPACE_THRESHOLD="" typeset _FS="" typeset _DO_INODES=0 typeset _DO_SPACE=0 +typeset _INODES_LIST="" +typeset _SPACE_LIST="" typeset _INODES_USAGE=1 typeset _SPACE_USAGE=1 -typeset _INODES_FILE="${TMP_DIR}/.$0.inodes.$$" -typeset _SPACE_FILE="${TMP_DIR}/.$0.space.$$" - -# set local trap for cleanup -# shellcheck disable=SC2064 -trap "rm -f ${_SPACE_FILE} ${_INODES_FILE} >/dev/null 2>&1; return 1" 1 2 3 15 # handle arguments (originally comma-separated) for _ARG in ${_ARGS} @@ -159,7 +156,7 @@ fi # collect data (POSIX format) if (( _DO_INODES > 0 )) then - df -Pil >>${_INODES_FILE} 2>>${HC_STDERR_LOG} + _INODES_LIST=$(df -Pil 2>>${HC_STDERR_LOG}) if (( $? > 0 )) then # df exits >0 if there are issues with some filesystems, consider non-fatal @@ -168,7 +165,7 @@ then fi if (( _DO_SPACE > 0 )) then - df -Pl >>${_SPACE_FILE} 2>>${HC_STDERR_LOG} + _SPACE_LIST=$(df -Pl 2>>${HC_STDERR_LOG}) if (( $? > 0 )) then # df exits >0 if there are issues with some filesystems, consider non-fatal @@ -180,12 +177,12 @@ fi if (( _DO_INODES > 0 )) then (( ARG_DEBUG > 0 )) && debug "checking inodes..." - grep '^\/' ${_INODES_FILE} 2>/dev/null | awk '{print $6}' 2>/dev/null |\ - while read _FS + print -r "${_INODES_LIST}" | grep '^\/' 2>/dev/null | grep -v -E -e '^/dev/loop' 2>/dev/null | awk '{print $6}' 2>/dev/null |\ + while read -r _FS do (( ARG_DEBUG > 0 )) && debug "parsing inodes data for filesystem: ${_FS}" # add space to grep; must be non-greedy! - _INODES_USAGE=$(grep -E -e " ${_FS}$" ${_INODES_FILE} 2>/dev/null | awk '{gsub(/%/,"",$5);print $5}' 2>/dev/null) + _INODES_USAGE=$(print -r "${_INODES_LIST}" | grep -E -e " ${_FS}$" 2>/dev/null | awk '{gsub(/%/,"",$5);print $5}' 2>/dev/null) data_is_numeric "${_INODES_USAGE}" if (( $? > 0 )) then @@ -237,19 +234,19 @@ then done # add df output to stdout log_hc print "==== df -Pil ====" >>${HC_STDOUT_LOG} - cat ${_INODES_FILE} >>${HC_STDOUT_LOG} + print -r "${_INODES_LIST}" >>${HC_STDOUT_LOG} fi # 2) validate space (df -Pl) if (( _DO_SPACE > 0 )) then (( ARG_DEBUG > 0 )) && debug "checking space..." - grep '^\/' ${_SPACE_FILE} 2>/dev/null | awk '{print $6}' 2>/dev/null |\ - while read _FS + print -r "${_SPACE_LIST}" | grep '^\/' 2>/dev/null | grep -v -E -e '^/dev/loop' 2>/dev/null | awk '{print $6}' 2>/dev/null |\ + while read -r _FS do (( ARG_DEBUG > 0 )) && debug "parsing space data for filesystem: ${_FS}" # add space to grep; must be non-greedy! - _SPACE_USAGE=$(grep -E -e " ${_FS}$" ${_SPACE_FILE} 2>/dev/null | awk '{gsub(/%/,"",$5);print $5}' 2>/dev/null) + _SPACE_USAGE=$(print -r "${_SPACE_LIST}" | grep -E -e " ${_FS}$" 2>/dev/null | awk '{gsub(/%/,"",$5);print $5}' 2>/dev/null) data_is_numeric "${_SPACE_USAGE}" if (( $? > 0 )) then @@ -301,12 +298,9 @@ then done # add df output to stdout log_hc print "==== df -Pl ====" >>${HC_STDOUT_LOG} - cat ${_SPACE_FILE} >>${HC_STDOUT_LOG} + print -r "${_SPACE_LIST}" >>${HC_STDOUT_LOG} fi -# do cleanup -rm -f ${_INODES_FILE} ${_SPACE_FILE} >/dev/null 2>&1 - return 0 } diff --git a/sources/lib/platform/linux/check_linux_postfix_status.sh b/sources/lib/platform/linux/check_linux_postfix_status.sh index bb05758..c06f495 100644 --- a/sources/lib/platform/linux/check_linux_postfix_status.sh +++ b/sources/lib/platform/linux/check_linux_postfix_status.sh @@ -30,6 +30,7 @@ # @(#) 2019-01-24: arguments fix [Patrick Van der Veken] # @(#) 2019-03-09: added support for --log-healthy [Patrick Van der Veken] # @(#) 2019-03-16: replace 'which' [Patrick Van der Veken] +# @(#) 2019-03-25: fix for older Debian & Ubuntu [Patrick Van der Veken] # ----------------------------------------------------------------------------- # DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! #****************************************************************************** @@ -40,7 +41,7 @@ function check_linux_postfix_status # ------------------------- CONFIGURATION starts here ------------------------- typeset _POSTFIX_INIT_SCRIPT="/etc/init.d/postfix" typeset _POSTFIX_SYSTEMD_SERVICE="postfix.service" -typeset _VERSION="2019-03-16" # YYYY-MM-DD +typeset _VERSION="2019-03-25" # YYYY-MM-DD typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match # ------------------------- CONFIGURATION ends here --------------------------- @@ -84,7 +85,18 @@ fi linux_get_init case "${LINUX_INIT}" in 'systemd') - _CHECK_SYSTEMD_SERVICE=$(linux_has_systemd_service "${_POSTFIX_SYSTEMD_SERVICE}") + # Debian8/Ubuntu16 do not correctly report a unit file for postfix, + # do not check for it and instead just query systemd service + linux_get_distro + if [[ "${LINUX_DISTRO}" = "Debian" ]] && (( ${LINUX_RELEASE%%.*} < 9 )) + then + _CHECK_SYSTEMD_SERVICE=1 + elif [[ "${LINUX_DISTRO}" = "Ubuntu" ]] && (( ${LINUX_RELEASE%%.*} < 17 )) + then + _CHECK_SYSTEMD_SERVICE=1 + else + _CHECK_SYSTEMD_SERVICE=$(linux_has_systemd_service "${_POSTFIX_SYSTEMD_SERVICE}") + fi if (( _CHECK_SYSTEMD_SERVICE > 0 )) then systemctl --quiet is-active ${_POSTFIX_SYSTEMD_SERVICE} 2>>${HC_STDERR_LOG} || _STC=1