Added HC_LOG_HEALTHY & HC_WILL_FIX as global settings

Fixed missing error checking in check_linux_autofs
This commit is contained in:
Patrick Van der Veken 2019-10-23 19:56:36 +02:00
parent f392c884bb
commit b60f383f48
3 changed files with 64 additions and 4 deletions

View File

@ -10,6 +10,17 @@
# maximum timeout for HC calls/plugins (seconds) [default: 60] # maximum timeout for HC calls/plugins (seconds) [default: 60]
HC_TIME_OUT=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 # End of FILE

View File

@ -38,7 +38,7 @@
# ------------------------- CONFIGURATION starts here ------------------------- # ------------------------- CONFIGURATION starts here -------------------------
# define the version (YYYY-MM-DD) # 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 # location of parent directory containing KSH functions/HC plugins
typeset -r FPATH_PARENT="/opt/hc/lib" typeset -r FPATH_PARENT="/opt/hc/lib"
# location of custom HC configuration files # location of custom HC configuration files
@ -94,6 +94,7 @@ typeset HC_RUN=""
typeset HC_FAIL_ID="" typeset HC_FAIL_ID=""
# shellcheck disable=SC2034 # shellcheck disable=SC2034
typeset HC_FILE_LINE="" typeset HC_FILE_LINE=""
typeset HC_LOG_HEALTHY=""
typeset HC_NOW="" typeset HC_NOW=""
typeset HC_TIME_OUT=60 typeset HC_TIME_OUT=60
typeset HC_MIN_TIME_OUT=30 typeset HC_MIN_TIME_OUT=30
@ -101,6 +102,7 @@ typeset HC_MIN_TIME_OUT=30
typeset HC_MSG_VAR="" typeset HC_MSG_VAR=""
typeset HC_STDOUT_LOG="" typeset HC_STDOUT_LOG=""
typeset HC_STDERR_LOG="" typeset HC_STDERR_LOG=""
typeset HC_WILL_FIX=""
# shellcheck disable=SC2034 # shellcheck disable=SC2034
typeset LINUX_DISTRO="" typeset LINUX_DISTRO=""
# shellcheck disable=SC2034 # shellcheck disable=SC2034
@ -613,10 +615,11 @@ Parameters:
--list-core : show the available core plugins (mail,SMS,...) --list-core : show the available core plugins (mail,SMS,...)
--list-include : show the available includes/libraries --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. --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] --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 --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) --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-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-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 --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-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] --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) --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. --version : show the timestamp of the script.
--with-history : also include events that have been archived already (reporting) --with-history : also include events that have been archived already (reporting)
--with-rc : define RC handling (plugin) when --flip-rc is used --with-rc : define RC handling (plugin) when --flip-rc is used
@ -743,6 +746,24 @@ else
. "${CONFIG_FILE}" . "${CONFIG_FILE}"
fi 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 return 0
} }

View File

@ -33,7 +33,7 @@ function check_linux_autofs
{ {
# ------------------------- CONFIGURATION starts here ------------------------- # ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" 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 typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
# shellcheck disable=SC2034 # shellcheck disable=SC2034
typeset _HC_CAN_FIX=1 # plugin has fix/healing logic? typeset _HC_CAN_FIX=1 # plugin has fix/healing logic?
@ -136,6 +136,13 @@ fi
# check if autofs is enabled # check if autofs is enabled
log "checking if autofs daemon is enabled" log "checking if autofs daemon is enabled"
_HAS_SERVICE=$(linux_has_service "autofs") _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 )) if (( _HAS_SERVICE == 2 ))
then then
_MSG="autofs service is enabled" _MSG="autofs service is enabled"
@ -147,6 +154,13 @@ then
# check if autofs is running # check if autofs is running
log "checking if autofs daemon is active" log "checking if autofs daemon is active"
_IS_ACTIVE=$(linux_runs_service autofs) _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 )) if (( _IS_ACTIVE > 0 ))
then then
_MSG="autofs daemon is running" _MSG="autofs daemon is running"
@ -170,9 +184,23 @@ then
sleep ${_SLEEP_TIME} sleep ${_SLEEP_TIME}
_RETRY_COUNT=$(( _RETRY_COUNT + 1 )) _RETRY_COUNT=$(( _RETRY_COUNT + 1 ))
_IS_ACTIVE=$(linux_runs_service "autofs") _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 done
# check again if autofs is running # check again if autofs is running
_IS_ACTIVE=$(linux_runs_service "autofs") _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 )) if (( _IS_ACTIVE > 0 ))
then then
_MSG="autofs daemon is running" _MSG="autofs daemon is running"