From 446d9c97effa2ca4e2e6bde3d2f0e22773321fe9 Mon Sep 17 00:00:00 2001 From: Patrick Van der Veken Date: Sat, 19 Oct 2019 19:40:54 +0200 Subject: [PATCH 01/10] Comments update --- etc/opt/hc/check_hpux_autofs.conf.dist | 2 +- etc/opt/hc/check_linux_autofs.conf.dist | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/etc/opt/hc/check_hpux_autofs.conf.dist b/etc/opt/hc/check_hpux_autofs.conf.dist index ab481fb..c59c10c 100644 --- a/etc/opt/hc/check_hpux_autofs.conf.dist +++ b/etc/opt/hc/check_hpux_autofs.conf.dist @@ -11,7 +11,7 @@ # [default: no] log_healthy="no" -# specify whether to extend the current ELDO FS (if needed) +# specify whether to fix autofs (if needed) # [default: no] fix_autofs="no" diff --git a/etc/opt/hc/check_linux_autofs.conf.dist b/etc/opt/hc/check_linux_autofs.conf.dist index ab481fb..c59c10c 100644 --- a/etc/opt/hc/check_linux_autofs.conf.dist +++ b/etc/opt/hc/check_linux_autofs.conf.dist @@ -11,7 +11,7 @@ # [default: no] log_healthy="no" -# specify whether to extend the current ELDO FS (if needed) +# specify whether to fix autofs (if needed) # [default: no] fix_autofs="no" From b60f383f48b78a941457c02c227a1e0771ea1b14 Mon Sep 17 00:00:00 2001 From: Patrick Van der Veken Date: Wed, 23 Oct 2019 19:56:36 +0200 Subject: [PATCH 02/10] Added HC_LOG_HEALTHY & HC_WILL_FIX as global settings Fixed missing error checking in check_linux_autofs --- etc/opt/hc/core/check_health.conf.dist | 11 +++++++ opt/hc/bin/check_health.sh | 27 +++++++++++++++-- .../lib/platform/linux/check_linux_autofs.sh | 30 ++++++++++++++++++- 3 files changed, 64 insertions(+), 4 deletions(-) diff --git a/etc/opt/hc/core/check_health.conf.dist b/etc/opt/hc/core/check_health.conf.dist index 92617b6..361b65c 100644 --- a/etc/opt/hc/core/check_health.conf.dist +++ b/etc/opt/hc/core/check_health.conf.dist @@ -10,6 +10,17 @@ # maximum timeout for HC calls/plugins (seconds) [default: 60] HC_TIME_OUT=60 +# enable/disable logging of passed health checks (warning: this may rapidly grow the HC log) +# see also: '--log-healthy' command-line parameter +# 'log_healthy' setting in HC plugin configuration file(s) +# [values: Yes|No] +HC_LOG_HEALTHY="No" + +# enable/disable healing logic if available in HC plugin(s) +# see also: '--no-fix' command-line parameter +# [values: Yes|No] +HC_WILL_FIX="Yes" + #****************************************************************************** # End of FILE diff --git a/opt/hc/bin/check_health.sh b/opt/hc/bin/check_health.sh index 6df0e0c..2662951 100755 --- a/opt/hc/bin/check_health.sh +++ b/opt/hc/bin/check_health.sh @@ -38,7 +38,7 @@ # ------------------------- CONFIGURATION starts here ------------------------- # define the version (YYYY-MM-DD) -typeset -r SCRIPT_VERSION="2019-07-16" +typeset -r SCRIPT_VERSION="2019-10-24" # location of parent directory containing KSH functions/HC plugins typeset -r FPATH_PARENT="/opt/hc/lib" # location of custom HC configuration files @@ -94,6 +94,7 @@ typeset HC_RUN="" typeset HC_FAIL_ID="" # shellcheck disable=SC2034 typeset HC_FILE_LINE="" +typeset HC_LOG_HEALTHY="" typeset HC_NOW="" typeset HC_TIME_OUT=60 typeset HC_MIN_TIME_OUT=30 @@ -101,6 +102,7 @@ typeset HC_MIN_TIME_OUT=30 typeset HC_MSG_VAR="" typeset HC_STDOUT_LOG="" typeset HC_STDERR_LOG="" +typeset HC_WILL_FIX="" # shellcheck disable=SC2034 typeset LINUX_DISTRO="" # shellcheck disable=SC2034 @@ -613,10 +615,11 @@ Parameters: --list-core : show the available core plugins (mail,SMS,...) --list-include : show the available includes/libraries --log-healthy : log/show also passed health checks. By default this is off when the plugin support this feature. - (can be overridden by --no-log to disable all logging) + (overrides \$HC_LOG_HEALTHY and can itself be overridden by --no-log to disable all logging) --mail-to : list of e-mail address(es) to which an e-mail alert will be send to [requires mail core plugin] --newer : show the (failed) events for each HC that are newer than the given date --no-fix : do not apply fix/healing logic for failed health checks (if available) + (overrides \$HC_WILL_FIX) --no-lock : disable locking to allow concurrent script executions --no-log : do not log any messages to the script log file or health check results. --no-monitor : do not stop the execution of a HC after \$HC_TIME_OUT seconds @@ -630,7 +633,7 @@ Parameters: --sms-provider : name of a supported SMS provider (see \$SMS_PROVIDERS) [requires SMS core plugin] --sms-to : name of person or group to which a sms alert will be send to [requires SMS core plugin] --timeout : maximum runtime of a HC plugin in seconds (overrides \$HC_TIME_OUT) ---today : show today's (failed) events (HC and their combined STC value) +--today : show (failed) events of today (HC and their combined STC value) --version : show the timestamp of the script. --with-history : also include events that have been archived already (reporting) --with-rc : define RC handling (plugin) when --flip-rc is used @@ -743,6 +746,24 @@ else . "${CONFIG_FILE}" fi +# reconcile global settings w/ cmd-line parameters +if (( ARG_LOG_HEALTHY == 0 )) +then + case "${HC_LOG_HEALTHY}" in + yes|YES|Yes) + ARG_LOG_HEALTHY=1 + ;; + esac +fi +if (( ARG_NO_FIX == 0 )) +then + case "${HC_WILL_FIX}" in + no|NO|No) + ARG_NO_FIX=1 + ;; + esac +fi + return 0 } diff --git a/opt/hc/lib/platform/linux/check_linux_autofs.sh b/opt/hc/lib/platform/linux/check_linux_autofs.sh index 7c617d9..c1e180a 100644 --- a/opt/hc/lib/platform/linux/check_linux_autofs.sh +++ b/opt/hc/lib/platform/linux/check_linux_autofs.sh @@ -33,7 +33,7 @@ function check_linux_autofs { # ------------------------- CONFIGURATION starts here ------------------------- typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" -typeset _VERSION="2019-07-14" # YYYY-MM-DD +typeset _VERSION="2019-10-24" # YYYY-MM-DD typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match # shellcheck disable=SC2034 typeset _HC_CAN_FIX=1 # plugin has fix/healing logic? @@ -136,6 +136,13 @@ fi # check if autofs is enabled log "checking if autofs daemon is enabled" _HAS_SERVICE=$(linux_has_service "autofs") +(( $? > 0)) && { + _MSG="error in function {linux_has_service}" + log_hc "$0" 1 "${_MSG}" + # dump debug info + (( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs + return 1 +} if (( _HAS_SERVICE == 2 )) then _MSG="autofs service is enabled" @@ -147,6 +154,13 @@ then # check if autofs is running log "checking if autofs daemon is active" _IS_ACTIVE=$(linux_runs_service autofs) + (( $? > 0)) && { + _MSG="error in function {linux_runs_service }" + log_hc "$0" 1 "${_MSG}" + # dump debug info + (( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs + return 1 + } if (( _IS_ACTIVE > 0 )) then _MSG="autofs daemon is running" @@ -170,9 +184,23 @@ then sleep ${_SLEEP_TIME} _RETRY_COUNT=$(( _RETRY_COUNT + 1 )) _IS_ACTIVE=$(linux_runs_service "autofs") + (( $? > 0)) && { + _MSG="error in function {linux_runs_service }" + log_hc "$0" 1 "${_MSG}" + # dump debug info + (( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs + return 1 + } done # check again if autofs is running _IS_ACTIVE=$(linux_runs_service "autofs") + (( $? > 0)) && { + _MSG="error in function {linux_runs_service }" + log_hc "$0" 1 "${_MSG}" + # dump debug info + (( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs + return 1 + } if (( _IS_ACTIVE > 0 )) then _MSG="autofs daemon is running" From bb703e2964ccf9131a5c5dea277a4c4b539256bc Mon Sep 17 00:00:00 2001 From: Patrick Van der Veken Date: Wed, 23 Oct 2019 20:42:11 +0200 Subject: [PATCH 03/10] Fixed post-install logic for Debian --- build/linux/DEBIAN/hc-linux/postinst | 42 ++++++++++++++--------- build/linux/DEBIAN/hc-notify-eif/postinst | 19 ++++++---- build/linux/DEBIAN/hc-notify-sms/postinst | 19 ++++++---- 3 files changed, 50 insertions(+), 30 deletions(-) diff --git a/build/linux/DEBIAN/hc-linux/postinst b/build/linux/DEBIAN/hc-linux/postinst index 2419d98..d7f56bc 100755 --- a/build/linux/DEBIAN/hc-linux/postinst +++ b/build/linux/DEBIAN/hc-linux/postinst @@ -16,25 +16,35 @@ chown -R root:root /opt/hc /etc/opt/hc 2>/dev/null chown root:root /etc/logrotate.d/check_health 2>/dev/null chmod 644 /etc/logrotate.d/check_health 2>/dev/null # copy configuration files -if [[ ! -f ${HC_ETC_DIR}/core/check_health.conf ]] +if [[ -f ${HC_ETC_DIR}/core/check_health.conf.dist ]] then - # copy main configuration file - cp -p ${HC_ETC_DIR}/core/check_health.conf.dist ${HC_ETC_DIR}/core/check_health.conf >/dev/null - (( $? == 0 )) || \ - { - echo "ERROR: could not copy main config file in ${HC_ETC_DIR}/core" - exit 1 - } + if [[ ! -f ${HC_ETC_DIR}/core/check_health.conf ]] + then + # copy main configuration file + cp -p ${HC_ETC_DIR}/core/check_health.conf.dist ${HC_ETC_DIR}/core/check_health.conf >/dev/null + (( $? == 0 )) || \ + { + echo "ERROR: could not copy main config file in ${HC_ETC_DIR}/core" + exit 1 + } + fi +else + echo "WARN: could not check_health config .dist file in ${HC_ETC_DIR}/core" fi -if [[ ! -f ${HC_ETC_DIR}/check_host.conf ]] +if [[ -f ${HC_ETC_DIR}/check_host.conf.dist ]] then - # copy host check configuration file - cp -p ${HC_ETC_DIR}/check_host.conf.dist ${HC_ETC_DIR}/check_host.conf >/dev/null - (( $? == 0 )) || \ - { - echo "ERROR: could not copy host check config file in ${HC_ETC_DIR}" - exit 1 - } + if [[ ! -f ${HC_ETC_DIR}/check_host.conf ]] + then + # copy host check configuration file + cp -p ${HC_ETC_DIR}/check_host.conf.dist ${HC_ETC_DIR}/check_host.conf >/dev/null + (( $? == 0 )) || \ + { + echo "ERROR: could not copy host check config file in ${HC_ETC_DIR}" + exit 1 + } + fi +else + echo "WARN: could not find check_host config .dist file in ${HC_ETC_DIR}" fi # refresh symbolic FPATH links for core includes & plugins if [[ -x ${HC_BIN} ]] diff --git a/build/linux/DEBIAN/hc-notify-eif/postinst b/build/linux/DEBIAN/hc-notify-eif/postinst index 48a8319..9dfa0d1 100755 --- a/build/linux/DEBIAN/hc-notify-eif/postinst +++ b/build/linux/DEBIAN/hc-notify-eif/postinst @@ -10,14 +10,19 @@ echo "INFO: starting post-install script ..." # debian: reset ownerships chown -R root:root /opt/hc /etc/opt/hc 2>/dev/null # copy plugin configuration file -if [[ ! -f ${HC_ETC_DIR}/core/providers/notify_eif.conf ]] +if [[ -f ${HC_ETC_DIR}/core/providers/notify_eif.conf.dist ]] then - cp -p ${HC_ETC_DIR}/core/providers/notify_eif.conf.dist ${HC_ETC_DIR}/core/providers/notify_eif.conf >/dev/null - (( $? == 0 )) || \ - { - echo "ERROR: could not copy plugin config file in ${HC_ETC_DIR}/core/providers" - exit 1 - } + if [[ ! -f ${HC_ETC_DIR}/core/providers/notify_eif.conf ]] + then + cp -p ${HC_ETC_DIR}/core/providers/notify_eif.conf.dist ${HC_ETC_DIR}/core/providers/notify_eif.conf >/dev/null + (( $? == 0 )) || \ + { + echo "ERROR: could not copy plugin config file in ${HC_ETC_DIR}/core/providers" + exit 1 + } + fi +else + echo "WARN: could not find plugin config .dist file in ${HC_ETC_DIR}/core/providers" fi # refresh symbolic FPATH links if [[ -x ${HC_BIN} ]] diff --git a/build/linux/DEBIAN/hc-notify-sms/postinst b/build/linux/DEBIAN/hc-notify-sms/postinst index 4c1ca26..5d64c00 100755 --- a/build/linux/DEBIAN/hc-notify-sms/postinst +++ b/build/linux/DEBIAN/hc-notify-sms/postinst @@ -10,14 +10,19 @@ echo "INFO: starting post-install script ..." # debian: reset ownerships chown -R root:root /opt/hc /etc/opt/hc 2>/dev/null # copy plugin configuration file -if [[ ! -f ${HC_ETC_DIR}/core/providers/notify_sms.conf ]] +if [[ -f ${HC_ETC_DIR}/core/providers/notify_sms.conf.dist ]] then - cp -p ${HC_ETC_DIR}/core/providers/notify_sms.conf.dist ${HC_ETC_DIR}/core/providers/notify_sms.conf >/dev/null - (( $? == 0 )) || \ - { - echo "ERROR: could not copy plugin config file in ${HC_ETC_DIR}/core/providers" - exit 1 - } + if [[ ! -f ${HC_ETC_DIR}/core/providers/notify_sms.conf ]] + then + cp -p ${HC_ETC_DIR}/core/providers/notify_sms.conf.dist ${HC_ETC_DIR}/core/providers/notify_sms.conf >/dev/null + (( $? == 0 )) || \ + { + echo "ERROR: could not copy plugin config file in ${HC_ETC_DIR}/core/providers" + exit 1 + } + fi +else + echo "WARN: could not find plugin config .dist file in ${HC_ETC_DIR}/core/providers" fi # refresh symbolic FPATH links if [[ -x ${HC_BIN} ]] From 5425a44afb7fc15e1034cff1622d46e3f035876c Mon Sep 17 00:00:00 2001 From: Patrick Van der Veken Date: Thu, 24 Oct 2019 20:37:29 +0200 Subject: [PATCH 04/10] Strip post-install for Debian --- build/linux/DEBIAN/hc-linux/postrm | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/build/linux/DEBIAN/hc-linux/postrm b/build/linux/DEBIAN/hc-linux/postrm index 98e28d5..f434b99 100755 --- a/build/linux/DEBIAN/hc-linux/postrm +++ b/build/linux/DEBIAN/hc-linux/postrm @@ -8,26 +8,6 @@ HC_ETC_DIR="/etc/opt/hc" HC_VAR_DIR="/var/opt/hc" # ------------------------- CONFIGURATION ends here --------------------------- echo "INFO: starting post-uninstall script ..." -if [[ -d ${HC_DIR} ]] -then - rm -rf ${HC_DIR} 2>/dev/null - (( $? == 0 )) || echo "WARN: failed to remove ${HC_DIR}" -fi -if [[ -d ${HC_ETC_DIR} ]] -then - rm -rf ${HC_ETC_DIR}/*.dist >/dev/null - (( $? == 0 )) || echo "WARN: could not remove .dist files in directory ${HC_ETC_DIR}" -fi -if [[ -d ${HC_ETC_DIR}/core ]] -then - rm -rf ${HC_ETC_DIR}/core/*.dist >/dev/null - (( $? == 0 )) || echo "WARN: could not remove .dist files in directory ${HC_ETC_DIR}/core" -fi -if [[ -d ${HC_ETC_DIR}/core/providers ]] -then - rm -rf ${HC_ETC_DIR}/core/providers/*.dist >/dev/null - (( $? == 0 )) || echo "WARN: could not remove .dist files in directory ${HC_ETC_DIR}/core/providers" -fi if [[ -d ${HC_VAR_DIR} ]] then rm -rf ${HC_VAR_DIR}/state/temporary 2>/dev/null From f91efc65205b7ce13ac4714579040df123cdb32a Mon Sep 17 00:00:00 2001 From: Patrick Van der Veken Date: Tue, 29 Oct 2019 20:20:55 +0100 Subject: [PATCH 05/10] Build updates for Debian --- build/linux/DEBIAN/hc-display-csv/control | 2 +- build/linux/DEBIAN/hc-display-init/control | 2 +- build/linux/DEBIAN/hc-display-json/control | 2 +- build/linux/DEBIAN/hc-display-terse/control | 2 +- build/linux/DEBIAN/hc-display-zenoss/control | 2 +- build/linux/DEBIAN/hc-linux-platform/control | 2 +- build/linux/DEBIAN/hc-notify-eif/control | 2 +- build/linux/DEBIAN/hc-notify-sms/control | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/build/linux/DEBIAN/hc-display-csv/control b/build/linux/DEBIAN/hc-display-csv/control index 6709252..dfa50ba 100644 --- a/build/linux/DEBIAN/hc-display-csv/control +++ b/build/linux/DEBIAN/hc-display-csv/control @@ -4,7 +4,7 @@ Architecture: all Maintainer: Patrick Van der Veken Essential: no Installed-Size: 50 -Depends: hc-linux +Pre-Depends: hc-linux Section: tools Priority: extra Description: The KUDOS Health Checker (HC) for UNIX (CSV display core plugin). diff --git a/build/linux/DEBIAN/hc-display-init/control b/build/linux/DEBIAN/hc-display-init/control index 6d8033d..0c24fb9 100644 --- a/build/linux/DEBIAN/hc-display-init/control +++ b/build/linux/DEBIAN/hc-display-init/control @@ -4,7 +4,7 @@ Architecture: all Maintainer: Patrick Van der Veken Essential: no Installed-Size: 50 -Depends: hc-linux +Pre-Depends: hc-linux Section: tools Priority: extra Description: The KUDOS Health Checker (HC) for UNIX (init display core plugin). diff --git a/build/linux/DEBIAN/hc-display-json/control b/build/linux/DEBIAN/hc-display-json/control index 0d14bcf..dc5a35b 100644 --- a/build/linux/DEBIAN/hc-display-json/control +++ b/build/linux/DEBIAN/hc-display-json/control @@ -4,7 +4,7 @@ Architecture: all Maintainer: Patrick Van der Veken Essential: no Installed-Size: 50 -Depends: hc-linux +Pre-Depends: hc-linux Section: tools Priority: extra Description: The KUDOS Health Checker (HC) for UNIX (JSON display core plugin). diff --git a/build/linux/DEBIAN/hc-display-terse/control b/build/linux/DEBIAN/hc-display-terse/control index 677bfe4..6b8d2e4 100644 --- a/build/linux/DEBIAN/hc-display-terse/control +++ b/build/linux/DEBIAN/hc-display-terse/control @@ -4,7 +4,7 @@ Architecture: all Maintainer: Patrick Van der Veken Essential: no Installed-Size: 50 -Depends: hc-linux +Pre-Depends: hc-linux Section: tools Priority: extra Description: The KUDOS Health Checker (HC) for UNIX (terse display core plugin). diff --git a/build/linux/DEBIAN/hc-display-zenoss/control b/build/linux/DEBIAN/hc-display-zenoss/control index a627656..7266957 100644 --- a/build/linux/DEBIAN/hc-display-zenoss/control +++ b/build/linux/DEBIAN/hc-display-zenoss/control @@ -4,7 +4,7 @@ Architecture: all Maintainer: Patrick Van der Veken Essential: no Installed-Size: 50 -Depends: hc-linux +Pre-Depends: hc-linux Section: tools Priority: extra Description: The KUDOS Health Checker (HC) for UNIX (Zenoss display core plugin). diff --git a/build/linux/DEBIAN/hc-linux-platform/control b/build/linux/DEBIAN/hc-linux-platform/control index 142e860..c9a14c1 100644 --- a/build/linux/DEBIAN/hc-linux-platform/control +++ b/build/linux/DEBIAN/hc-linux-platform/control @@ -4,7 +4,7 @@ Architecture: all Maintainer: Patrick Van der Veken Essential: no Installed-Size: 300 -Depends: hc-linux +Pre-Depends: hc-linux Section: tools Priority: extra Description: The KUDOS Health Checker (HC) for UNIX (platform plugins). diff --git a/build/linux/DEBIAN/hc-notify-eif/control b/build/linux/DEBIAN/hc-notify-eif/control index f0fd2e5..74765b2 100644 --- a/build/linux/DEBIAN/hc-notify-eif/control +++ b/build/linux/DEBIAN/hc-notify-eif/control @@ -4,7 +4,7 @@ Architecture: all Maintainer: Patrick Van der Veken Essential: no Installed-Size: 50 -Depends: hc-linux +Pre-Depends: hc-linux Section: tools Priority: extra Description: The KUDOS Health Checker (HC) for UNIX (EIF notify core plugin). diff --git a/build/linux/DEBIAN/hc-notify-sms/control b/build/linux/DEBIAN/hc-notify-sms/control index 7d4da21..e92f0ea 100644 --- a/build/linux/DEBIAN/hc-notify-sms/control +++ b/build/linux/DEBIAN/hc-notify-sms/control @@ -4,7 +4,7 @@ Architecture: all Maintainer: Patrick Van der Veken Essential: no Installed-Size: 50 -Depends: hc-linux +Pre-Depends: hc-linux Section: tools Priority: extra Description: The KUDOS Health Checker (HC) for UNIX (SMS notify core plugin). From 048e7bd7580d072223e90a9006159b3cbdbd0dd9 Mon Sep 17 00:00:00 2001 From: Patrick Van der Veken Date: Tue, 29 Oct 2019 20:32:56 +0100 Subject: [PATCH 06/10] Fix Debian postrm --- build/linux/DEBIAN/hc-linux/postrm | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/build/linux/DEBIAN/hc-linux/postrm b/build/linux/DEBIAN/hc-linux/postrm index f434b99..b5f03f6 100755 --- a/build/linux/DEBIAN/hc-linux/postrm +++ b/build/linux/DEBIAN/hc-linux/postrm @@ -8,6 +8,27 @@ HC_ETC_DIR="/etc/opt/hc" HC_VAR_DIR="/var/opt/hc" # ------------------------- CONFIGURATION ends here --------------------------- echo "INFO: starting post-uninstall script ..." +if [[ -d ${HC_DIR} ]] +then + # remove all symlinks + find ${HC_DIR} -type l -exec rm -f {} \; 2>/dev/null + (( $? == 0 )) || echo "WARN: failed to remove symlinks in ${HC_DIR}" +fi +if [[ -d ${HC_ETC_DIR} ]] +then + rm -rf ${HC_ETC_DIR}/*.dist >/dev/null + (( $? == 0 )) || echo "WARN: could not remove .dist files in directory ${HC_ETC_DIR}" +fi +if [[ -d ${HC_ETC_DIR}/core ]] +then + rm -rf ${HC_ETC_DIR}/core/*.dist >/dev/null + (( $? == 0 )) || echo "WARN: could not remove .dist files in directory ${HC_ETC_DIR}/core" +fi +if [[ -d ${HC_ETC_DIR}/core/providers ]] +then + rm -rf ${HC_ETC_DIR}/core/providers/*.dist >/dev/null + (( $? == 0 )) || echo "WARN: could not remove .dist files in directory ${HC_ETC_DIR}/core/providers" +fi if [[ -d ${HC_VAR_DIR} ]] then rm -rf ${HC_VAR_DIR}/state/temporary 2>/dev/null From b460eca52cc3d7d54cd630cdec2ca9a70d7c0a38 Mon Sep 17 00:00:00 2001 From: Patrick Van der Veken Date: Tue, 29 Oct 2019 20:42:35 +0100 Subject: [PATCH 07/10] Update Debian conffiles --- build/linux/DEBIAN/hc-linux/conffiles | 1 + 1 file changed, 1 insertion(+) diff --git a/build/linux/DEBIAN/hc-linux/conffiles b/build/linux/DEBIAN/hc-linux/conffiles index 1202498..bab44ac 100644 --- a/build/linux/DEBIAN/hc-linux/conffiles +++ b/build/linux/DEBIAN/hc-linux/conffiles @@ -1,3 +1,4 @@ +/etc/opt/hc/core/templates/check_health.conf /etc/opt/hc/core/templates/mail_body.tpl /etc/opt/hc/core/templates/mail_footer.tpl /etc/opt/hc/core/templates/mail_header.tpl From f2b49709774d1a63d20700369b3fd43dd103909b Mon Sep 17 00:00:00 2001 From: Patrick Van der Veken Date: Fri, 1 Nov 2019 16:40:17 +0100 Subject: [PATCH 08/10] Added configuration parameters for the check_linux_httpd_status() plugin to support httpd that were compiled from source (no sysv or systemd) --- build/linux/ARCH/hc-linux-platform/PKGBUILD | 1 + build/linux/SPECS/hc-linux-platform.spec | 4 + etc/opt/hc/check_linux_httpd_status.conf.dist | 28 ++++ .../linux/check_linux_httpd_status.sh | 154 ++++++++++++------ 4 files changed, 137 insertions(+), 50 deletions(-) create mode 100644 etc/opt/hc/check_linux_httpd_status.conf.dist diff --git a/build/linux/ARCH/hc-linux-platform/PKGBUILD b/build/linux/ARCH/hc-linux-platform/PKGBUILD index 9717c14..53cfc6a 100644 --- a/build/linux/ARCH/hc-linux-platform/PKGBUILD +++ b/build/linux/ARCH/hc-linux-platform/PKGBUILD @@ -55,6 +55,7 @@ package() { install -D -m 644 etc/opt/hc/check_linux_hpacucli.conf.dist ${pkgdir}/etc/opt/hc/check_linux_hpacucli.conf.dist install -D -m 644 etc/opt/hc/check_linux_hplog.conf.dist ${pkgdir}/etc/opt/hc/check_linux_hplog.conf.dist install -D -m 644 etc/opt/hc/check_linux_hpssacli.conf.dist ${pkgdir}/etc/opt/hc/check_linux_hpssacli.conf.dist + install -D -m 644 etc/opt/hc/check_linux_httpd_status.conf.dist ${pkgdir}/etc/opt/hc/check_linux_httpd_status.conf.dist install -D -m 644 etc/opt/hc/check_linux_mysqld_status.conf.dist ${pkgdir}/etc/opt/hc/check_linux_mysqld_status.conf.dist install -D -m 644 etc/opt/hc/check_linux_ntp_status.conf.dist ${pkgdir}/etc/opt/hc/check_linux_ntp_status.conf.dist install -D -m 644 etc/opt/hc/check_linux_process_limits.conf.dist ${pkgdir}/etc/opt/hc/check_linux_process_limits.conf.dist diff --git a/build/linux/SPECS/hc-linux-platform.spec b/build/linux/SPECS/hc-linux-platform.spec index c146363..ab3e33d 100644 --- a/build/linux/SPECS/hc-linux-platform.spec +++ b/build/linux/SPECS/hc-linux-platform.spec @@ -63,6 +63,7 @@ cp ../SOURCES/etc/opt/hc/check_linux_hpasmcli.conf.dist $RPM_BUILD_ROOT/etc/opt/ cp ../SOURCES/etc/opt/hc/check_linux_hpacucli.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/check_linux_hpacucli.conf.dist cp ../SOURCES/etc/opt/hc/check_linux_hplog.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/check_linux_hplog.conf.dist cp ../SOURCES/etc/opt/hc/check_linux_hpssacli.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/check_linux_hpssacli.conf.dist +cp ../SOURCES/etc/opt/hc/check_linux_httpd_status.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/check_linux_httpd_status.conf.dist cp ../SOURCES/etc/opt/hc/check_linux_mysqld_status.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/check_linux_mysqld_status.conf.dist cp ../SOURCES/etc/opt/hc/check_linux_ntp_status.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/check_linux_ntp_status.conf.dist cp ../SOURCES/etc/opt/hc/check_linux_process_limits.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/check_linux_process_limits.conf.dist @@ -145,6 +146,7 @@ echo "INFO: finished post-uninstall script" %attr(644, root, root) /etc/opt/hc/check_linux_hpacucli.conf.dist %attr(644, root, root) /etc/opt/hc/check_linux_hplog.conf.dist %attr(644, root, root) /etc/opt/hc/check_linux_hpssacli.conf.dist +%attr(644, root, root) /etc/opt/hc/check_linux_httpd_status.conf.dist %attr(644, root, root) /etc/opt/hc/check_linux_mysqld_status.conf.dist %attr(644, root, root) /etc/opt/hc/check_linux_ntp_status.conf.dist %attr(644, root, root) /etc/opt/hc/check_linux_process_limits.conf.dist @@ -157,6 +159,8 @@ echo "INFO: finished post-uninstall script" %attr(644, root, root) /etc/opt/hc/core/templates/mail_body.tpl-check_linux_root_crontab %changelog +* Fri Nov 1 2019 - 0.3.2 +- Added configuration file for check_linux_httpd_status plugin * Sun Jul 14 2019 - 0.3.1 - Removed check_linux_autofs plugin * Sat Apr 20 2019 - 0.3.0 diff --git a/etc/opt/hc/check_linux_httpd_status.conf.dist b/etc/opt/hc/check_linux_httpd_status.conf.dist new file mode 100644 index 0000000..fb95fb6 --- /dev/null +++ b/etc/opt/hc/check_linux_httpd_status.conf.dist @@ -0,0 +1,28 @@ +#****************************************************************************** +# @(#) check_linux_httpd_status.conf +#****************************************************************************** +# This is a configuration file for the check_linux_httpd_status HC plugin. +# All lines starting with a '#' are comment lines. +# [default: indicates hardcoded script values if no value is defined here] +#****************************************************************************** + +# specify whether to also log passed health checks +# (warning: this may rapidly grow the HC log) +# [default: no] +log_healthy="no" + +# specify which type of process check to use +# Format: . NULL value equals to "auto" +# [default: auto] +# Compatibility: >=2019-11-01 +check_type="auto" + +# specify custom path to the httpd binary +# [default: null] +# Compatibility: >=2019-11-01 +httpd_bin="" + + +#****************************************************************************** +# End of FILE +#****************************************************************************** diff --git a/opt/hc/lib/platform/linux/check_linux_httpd_status.sh b/opt/hc/lib/platform/linux/check_linux_httpd_status.sh index 9958465..c022a1e 100755 --- a/opt/hc/lib/platform/linux/check_linux_httpd_status.sh +++ b/opt/hc/lib/platform/linux/check_linux_httpd_status.sh @@ -30,6 +30,8 @@ # @(#) 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-11-01: added support for configuration parameters 'check_type' and +# @(#) 'httpd_bin' [Patrick Van der Veken] # ----------------------------------------------------------------------------- # DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! #****************************************************************************** @@ -38,9 +40,10 @@ function check_linux_httpd_status { # ------------------------- CONFIGURATION starts here ------------------------- +typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" typeset _HTTPD_INIT_SCRIPT="/etc/init.d/httpd" typeset _HTTPD_SYSTEMD_SERVICE="httpd.service" -typeset _VERSION="2019-03-16" # YYYY-MM-DD +typeset _VERSION="2019-11-01" # YYYY-MM-DD typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match # ------------------------- CONFIGURATION ends here --------------------------- @@ -49,11 +52,15 @@ typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}" typeset _ARGS=$(data_comma2space "$*") typeset _ARG="" -typeset _CHECK_SYSTEMD_SERVICE=0 -typeset _HTTPD_BIN="" typeset _MSG="" typeset _STC=0 +typeset _CHECK_SYSTEMD_SERVICE=0 +typeset _CFG_HEALTHY="" typeset _LOG_HEALTHY=0 +typeset _CFG_HTTPD_BIN="" +typeset _HTTPD_BIN="" +typeset _CFG_CHECK_TYPE="" +typeset _DO_PGREP=0 typeset _RC=0 # handle arguments (originally comma-separated) @@ -66,6 +73,40 @@ do esac done +# handle configuration file +[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}" +if [[ ! -r ${_CONFIG_FILE} ]] +then + warn "unable to read configuration file at ${_CONFIG_FILE}" + return 1 +fi +# read configuration values +_CFG_CHECK_TYPE=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'check_type') +case "${_CFG_CHECK_TYPE}" in + pgrep|Pgrep|PGREP) + _DO_PGREP=1 + log "using pgrep process check (config override)" + ;; + sysv|Sysv|SYSV) + LINUX_INIT="sysv" + log "using init based process check (config override)" + ;; + systemd|Systemd|SYSTEMD) + LINUX_INIT="systemd" + log "using systemd based process check (config override)" + ;; + *) + # no overrides + : + ;; +esac +_CFG_HTTPD_BIN=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'httpd_bin') +if [[ -n "${_CFG_HTTPD_BIN}" ]] +then + _HTTPD_BIN="${_CFG_HTTPD_BIN}" + log "setting httpd path to {${_HTTPD_BIN}} (config override)" +fi + # log_healthy (( ARG_LOG_HEALTHY > 0 )) && _LOG_HEALTHY=1 if (( _LOG_HEALTHY > 0 )) @@ -80,44 +121,58 @@ else log "not logging/showing passed health checks" fi +# check httpd (if specified) +if [[ -z "${_HTTPD_BIN}" ]] +then + _HTTPD_BIN="$(command -v httpd 2>>${HC_STDERR_LOG})" +fi +if [[ ! -x ${_HTTPD_BIN} || -z "${_HTTPD_BIN}" ]] +then + warn "httpd (apache) is not installed here" + return 1 +fi + # ---- process state ---- # 1) try using the init ways -linux_get_init -case "${LINUX_INIT}" in - 'systemd') - _CHECK_SYSTEMD_SERVICE=$(linux_has_systemd_service "${_HTTPD_SYSTEMD_SERVICE}") - if (( _CHECK_SYSTEMD_SERVICE > 0 )) - then - systemctl --quiet is-active ${_HTTPD_SYSTEMD_SERVICE} 2>>${HC_STDERR_LOG} || _STC=1 - else - warn "systemd unit file not found {${_HTTPD_SYSTEMD_SERVICE}}" - _RC=1 - fi - ;; - 'upstart') - warn "code for upstart managed systems not implemented, NOOP" - _RC=1 - ;; - 'sysv') - # check running SysV - if [[ -x ${_HTTPD_INIT_SCRIPT} ]] - then - if (( $(${_HTTPD_INIT_SCRIPT} status 2>>${HC_STDERR_LOG} | grep -c -i 'is running' 2>/dev/null) == 0 )) +if (( _DO_PGREP == 0 )) +then + [[ -n "${LINUX_INIT}" ]] || linux_get_init + case "${LINUX_INIT}" in + 'systemd') + _CHECK_SYSTEMD_SERVICE=$(linux_has_systemd_service "${_HTTPD_SYSTEMD_SERVICE}") + if (( _CHECK_SYSTEMD_SERVICE > 0 )) then - _STC=1 + systemctl --quiet is-active ${_HTTPD_SYSTEMD_SERVICE} 2>>${HC_STDERR_LOG} || _STC=1 + else + warn "systemd unit file not found {${_HTTPD_SYSTEMD_SERVICE}}" + _RC=1 fi - else - warn "sysv init script not found {${_HTTPD_INIT_SCRIPT}}" + ;; + 'upstart') + warn "code for upstart managed systems not implemented, NOOP" _RC=1 - fi - ;; - *) - _RC=1 - ;; -esac + ;; + 'sysv') + # check running SysV + if [[ -x ${_HTTPD_INIT_SCRIPT} ]] + then + if (( $(${_HTTPD_INIT_SCRIPT} status 2>>${HC_STDERR_LOG} | grep -c -i 'is running' 2>/dev/null) == 0 )) + then + _STC=1 + fi + else + warn "sysv init script not found {${_HTTPD_INIT_SCRIPT}}" + _RC=1 + fi + ;; + *) + _RC=1 + ;; + esac +fi # 2) try the pgrep way (note: old pgreps do not support '-c') -if (( _RC > 0 )) +if (( _DO_PGREP > 0 || _RC > 0 )) then (( $(pgrep -u root httpd 2>>${HC_STDERR_LOG} | wc -l 2>/dev/null) == 0 )) && _STC=1 fi @@ -140,23 +195,18 @@ then fi # ---- config state ---- -_HTTPD_BIN="$(command -v httpd 2>>${HC_STDERR_LOG})" -if [[ -x ${_HTTPD_BIN} && -n "${_HTTPD_BIN}" ]] +${_HTTPD_BIN} -t >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG} +if (( $? == 0 )) then - # validate main configuration - ${_HTTPD_BIN} -t >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG} - if (( $? == 0 )) - then - _MSG="httpd configuration files are syntactically correct" - _STC=0 - else - _MSG="httpd configuration files have syntax error(s) {httpd -s}" - _STC=1 - fi - if (( _LOG_HEALTHY > 0 || _STC > 0 )) - then - log_hc "$0" ${_STC} "${_MSG}" - fi + _MSG="httpd configuration files are syntactically correct" + _STC=0 +else + _MSG="httpd configuration files have syntax error(s) {httpd -s}" + _STC=1 +fi +if (( _LOG_HEALTHY > 0 || _STC > 0 )) +then + log_hc "$0" ${_STC} "${_MSG}" fi return 0 @@ -168,6 +218,10 @@ function _show_usage cat <<- EOT NAME : $1 VERSION : $2 +CONFIG : $3 with parameters: + log_healthy= + check_type= [compt. >=2019-11-01] + httpd_bin= [compt. >=2019-11-01] PURPOSE : Checks whether httpd (apache service) is running and whether the httpd configuration files are syntactically correct LOG HEALTHY : Supported From 6184a1a061037503da781dc42d04a6d98f8e6a48 Mon Sep 17 00:00:00 2001 From: Patrick Van der Veken Date: Fri, 1 Nov 2019 16:47:49 +0100 Subject: [PATCH 09/10] Fix in check_linux_httpd_status plugin --- opt/hc/lib/platform/linux/check_linux_httpd_status.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/opt/hc/lib/platform/linux/check_linux_httpd_status.sh b/opt/hc/lib/platform/linux/check_linux_httpd_status.sh index c022a1e..e16669e 100755 --- a/opt/hc/lib/platform/linux/check_linux_httpd_status.sh +++ b/opt/hc/lib/platform/linux/check_linux_httpd_status.sh @@ -106,6 +106,16 @@ then _HTTPD_BIN="${_CFG_HTTPD_BIN}" log "setting httpd path to {${_HTTPD_BIN}} (config override)" fi +_CFG_HEALTHY=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'log_healthy') +case "${_CFG_HEALTHY}" in + yes|YES|Yes) + _LOG_HEALTHY=1 + ;; + *) + # do not override hc_arg + (( _LOG_HEALTHY > 0 )) || _LOG_HEALTHY=0 + ;; +esac # log_healthy (( ARG_LOG_HEALTHY > 0 )) && _LOG_HEALTHY=1 From 2481032360daaec79f79f34aaddda4469bc7cbe3 Mon Sep 17 00:00:00 2001 From: Patrick Van der Veken Date: Sun, 3 Nov 2019 19:33:30 +0100 Subject: [PATCH 10/10] Fix in archiving routine for bogus messages --- opt/hc/lib/core/include_core.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/opt/hc/lib/core/include_core.sh b/opt/hc/lib/core/include_core.sh index e0f6c87..1c36131 100755 --- a/opt/hc/lib/core/include_core.sh +++ b/opt/hc/lib/core/include_core.sh @@ -30,7 +30,7 @@ # RETURNS: 0 function version_include_core { -typeset _VERSION="2019-06-18" # YYYY-MM-DD +typeset _VERSION="2019-11-03" # YYYY-MM-DD print "INFO: $0: ${_VERSION#version_*}" @@ -76,6 +76,13 @@ grep ".*${LOG_SEP}${HC_NAME}${LOG_SEP}" ${HC_LOG} 2>/dev/null |\ cut -f1-2 -d'-' 2>/dev/null | sort -u 2>/dev/null |\ while read -r YEAR_MONTH do + # skip messages with bogus date + if [[ -z "${YEAR_MONTH}" ]] + then + warn "skipping bogus log lines (lines without proper datestamp)" + continue + fi + # find all messages for that YEAR-MONTH combination grep "${YEAR_MONTH}.*${LOG_SEP}${HC_NAME}${LOG_SEP}" ${HC_LOG} >${TMP1_FILE} TODO_LOG_COUNT=$(wc -l ${TMP1_FILE} 2>/dev/null | cut -f1 -d' ' 2>/dev/null)