Added additional RC handling for --flip-rc with introduction of the --with-rc cmdline option

This commit is contained in:
Patrick Van der Veken 2019-04-03 11:55:45 +02:00
parent 816cf34811
commit d6627ffe6a
2 changed files with 40 additions and 8 deletions

View File

@ -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=<needle>] | [--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=<secs>] | --show) --hc=<list_of_checks> [--config-file=<configuration_file>] [hc-args="<arg1,arg2=val,arg3">]))
[--display=<method>] ([--debug] [--debug-level=<level>]) [--log-healthy] [--no-monitor] [--no-log] [--no-lock] [--flip-rc]
[--display=<method>] ([--debug] [--debug-level=<level>]) [--log-healthy] [--no-monitor] [--no-log] [--no-lock] [[--flip-rc] [--with-rc=<count|max|sum>]]]
[--notify=<method_list>] [--mail-to=<address_list>] [--sms-to=<sms_rcpt> --sms-provider=<name>]
[--report=<method> [--with-history] ( ([--last] | [--today]) | [(--older|--newer)=<date>] | [--reverse] [--id=<fail_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

View File

@ -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}