From d6627ffe6accb567fdd2e52223d81d033dd9b2eb Mon Sep 17 00:00:00 2001 From: Patrick Van der Veken Date: Wed, 3 Apr 2019 11:55:45 +0200 Subject: [PATCH] Added additional RC handling for --flip-rc with introduction of the --with-rc cmdline option --- opt/hc/bin/check_health.sh | 22 ++++++++++++++++------ opt/hc/lib/core/include_core.sh | 26 ++++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/opt/hc/bin/check_health.sh b/opt/hc/bin/check_health.sh index 826774b..c72c44a 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-03-22" +typeset -r SCRIPT_VERSION="2019-04-03" # location of parent directory containing KSH functions/HC plugins typeset -r FPATH_PARENT="/opt/hc/lib" # location of custom HC configuration files @@ -145,6 +145,7 @@ typeset ARG_TIME_OUT=0 # custom timeout is off by default typeset ARG_TERSE=0 # show terse help is off by default typeset ARG_TODAY=0 # report today's events typeset ARG_VERBOSE=1 # STDOUT is on by default +typeset ARG_WITH_RC="" set +o bgnice @@ -546,7 +547,7 @@ Execute/report simple health checks (HC) on UNIX hosts. Syntax: ${SCRIPT_DIR}/${SCRIPT_NAME} [--help] | [--help-terse] | [--version] | [--list=] | [--list-core] | [--list-include] | [--fix-symlinks] | [--show-stats] | (--archive-all | --disable-all | --enable-all) | [--fix-logs [--with-history]] | (--check-host | ((--archive | --check | --enable | --disable | --run [--timeout=] | --show) --hc= [--config-file=] [hc-args="])) - [--display=] ([--debug] [--debug-level=]) [--log-healthy] [--no-monitor] [--no-log] [--no-lock] [--flip-rc] + [--display=] ([--debug] [--debug-level=]) [--log-healthy] [--no-monitor] [--no-log] [--no-lock] [[--flip-rc] [--with-rc=]]] [--notify=] [--mail-to=] [--sms-to= --sms-provider=] [--report= [--with-history] ( ([--last] | [--today]) | [(--older|--newer)=] | [--reverse] [--id= [--detail]] )] @@ -607,6 +608,7 @@ Parameters: --today : show today's (failed) events (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 EOT fi @@ -865,10 +867,6 @@ do --hc-args=*) ARG_HC_ARGS="${CMD_PARAMETER#--hc-args=}" ;; - -with-history|--with-history) - # shellcheck disable=SC2034 - ARG_HISTORY=1 - ;; -id=*) # shellcheck disable=SC2034 ARG_FAIL_ID="${CMD_PARAMETER#-id=}" @@ -1071,6 +1069,18 @@ do print "INFO: $0: ${SCRIPT_VERSION}" exit 0 ;; + -with-history|--with-history) + # shellcheck disable=SC2034 + ARG_HISTORY=1 + ;; + -with-rc=*) + # shellcheck disable=SC2034 + ARG_WITH_RC="${CMD_PARAMETER#-with-rc=}" + ;; + --with-rc=*) + # shellcheck disable=SC2034 + ARG_WITH_RC="${CMD_PARAMETER#--with-rc=}" + ;; \?|-h|-help|--help) display_usage exit 0 diff --git a/opt/hc/lib/core/include_core.sh b/opt/hc/lib/core/include_core.sh index 83e2408..68e92c5 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-03-16" # YYYY-MM-DD +typeset _VERSION="2019-04-03" # YYYY-MM-DD print "INFO: $0: ${_VERSION#version_*}" @@ -625,6 +625,11 @@ if (( DO_REPORT_STD == 0 )) && [[ -n "${ARG_NEWER}" ]] then die "you cannot specify '--newer' without '--report'" fi +# --flip-rc/--with-rc +if (( ARG_FLIP_RC == 0 )) && [[ -n "${ARG_WITH_RC}" ]] +then + die "you cannot specify '--with-rc' without '--flip-rc'" +fi return 0 } @@ -1133,7 +1138,24 @@ then then # shellcheck disable=SC1117 printf "%s${LOG_SEP}\n" "${HC_FAIL_ID}" >>${HC_LOG} - HC_STC_RC=$(( HC_STC_RC + 1 )) + # RC handling (max/sum/count) + if (( ARG_FLIP_RC > 0 )) + then + case "${ARG_WITH_RC}" in + max|MAX|Max) + (( ONE_MSG_STC > HC_STC_RC )) && HC_STC_RC=${ONE_MSG_STC} + ;; + sum|SUM|Sum) + HC_STC_RC=$(( HC_STC_RC + ONE_MSG_STC )) + ;; + *) + # count option (default) + HC_STC_RC=$(( HC_STC_RC + 1 )) + ;; + esac + else + HC_STC_RC=$(( HC_STC_RC + 1 )) + fi else # shellcheck disable=SC1117 printf "\n" >>${HC_LOG}