Code cleanup
This commit is contained in:
@@ -36,7 +36,7 @@ typeset _DISPLAY_SEP=";"
|
||||
# ------------------------- CONFIGURATION ends here ---------------------------
|
||||
|
||||
# set defaults
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
|
||||
|
||||
typeset _DISPLAY_HC="$1"
|
||||
|
||||
@@ -36,7 +36,7 @@ typeset _SUPPORTED_PLATFORMS="AIX,HP-UX,Linux" # uname -s match
|
||||
# ------------------------- CONFIGURATION ends here ---------------------------
|
||||
|
||||
# set defaults
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
|
||||
|
||||
typeset _DISPLAY_HC="$1"
|
||||
|
||||
@@ -35,7 +35,7 @@ typeset _SUPPORTED_PLATFORMS="AIX,HP-UX,Linux" # uname -s match
|
||||
# ------------------------- CONFIGURATION ends here ---------------------------
|
||||
|
||||
# set defaults
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
|
||||
|
||||
typeset _DISPLAY_HC="$1"
|
||||
|
||||
@@ -35,7 +35,7 @@ typeset _SUPPORTED_PLATFORMS="AIX,HP-UX,Linux" # uname -s match
|
||||
# ------------------------- CONFIGURATION ends here ---------------------------
|
||||
|
||||
# set defaults
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
|
||||
|
||||
typeset _DISPLAY_HC="$1"
|
||||
|
||||
@@ -37,7 +37,7 @@ typeset _SUPPORTED_PLATFORMS="AIX,HP-UX,Linux" # uname -s match
|
||||
# ------------------------- CONFIGURATION ends here ---------------------------
|
||||
|
||||
# set defaults
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
|
||||
|
||||
typeset _DISPLAY_HC="$1"
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
# REQUIRES: ${HC_LOG}
|
||||
function archive_hc
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
typeset HC_NAME="${1}"
|
||||
typeset ARCHIVE_FILE=""
|
||||
typeset ARCHIVE_RC=0
|
||||
@@ -108,7 +108,7 @@ return ${ARCHIVE_RC}
|
||||
# REQUIRES: n/a
|
||||
function count_log_errors
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
typeset LOG_STASH="${1}"
|
||||
typeset ERROR_COUNT=0
|
||||
|
||||
@@ -152,13 +152,13 @@ return 0
|
||||
# REQUIRES: n/a
|
||||
function die
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
typeset NOW="$(date '+%d-%h-%Y %H:%M:%S')"
|
||||
typeset LOG_LINE=""
|
||||
|
||||
if [[ -n "${1}" ]]
|
||||
then
|
||||
if (( ARG_LOG != 0 ))
|
||||
if (( ARG_LOG > 0 ))
|
||||
then
|
||||
print - "$*" | while read -r LOG_LINE
|
||||
do
|
||||
@@ -186,7 +186,7 @@ exit 1
|
||||
# REQUIRES: die()
|
||||
function discover_core
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
typeset NOTIFY_OPTS=""
|
||||
|
||||
# init global flags for core plugins (no typeset!)
|
||||
@@ -236,75 +236,75 @@ do
|
||||
case "${FFILE}" in
|
||||
*display_csv.sh)
|
||||
HAS_DISPLAY_CSV=1
|
||||
(( ARG_DEBUG != 0 )) && debug "display_csv plugin is available"
|
||||
(( ARG_DEBUG > 0 )) && debug "display_csv plugin is available"
|
||||
;;
|
||||
*display_init.sh)
|
||||
HAS_DISPLAY_INIT=1
|
||||
(( ARG_DEBUG != 0 )) && debug "display_init plugin is available"
|
||||
(( ARG_DEBUG > 0 )) && debug "display_init plugin is available"
|
||||
;;
|
||||
*display_json.sh)
|
||||
HAS_DISPLAY_JSON=1
|
||||
(( ARG_DEBUG != 0 )) && debug "display_json plugin is available"
|
||||
(( ARG_DEBUG > 0 )) && debug "display_json plugin is available"
|
||||
;;
|
||||
*display_terse.sh)
|
||||
HAS_DISPLAY_TERSE=1
|
||||
(( ARG_DEBUG != 0 )) && debug "display_terse plugin is available"
|
||||
(( ARG_DEBUG > 0 )) && debug "display_terse plugin is available"
|
||||
;;
|
||||
*display_zenoss.sh)
|
||||
HAS_DISPLAY_ZENOSS=1
|
||||
(( ARG_DEBUG != 0 )) && debug "display_zenoss plugin is available"
|
||||
(( ARG_DEBUG > 0 )) && debug "display_zenoss plugin is available"
|
||||
;;
|
||||
*display_custom1.sh)
|
||||
HAS_DISPLAY_CUSTOM1=1
|
||||
(( ARG_DEBUG != 0 )) && debug "display_custom1 plugin is available"
|
||||
(( ARG_DEBUG > 0 )) && debug "display_custom1 plugin is available"
|
||||
;;
|
||||
*display_custom2.sh)
|
||||
HAS_DISPLAY_CUSTOM2=1
|
||||
(( ARG_DEBUG != 0 )) && debug "display_custom2 plugin is available"
|
||||
(( ARG_DEBUG > 0 )) && debug "display_custom2 plugin is available"
|
||||
;;
|
||||
*display_custom3.sh)
|
||||
HAS_DISPLAY_CUSTOM3=1
|
||||
(( ARG_DEBUG != 0 )) && debug "display_custom3 plugin is available"
|
||||
(( ARG_DEBUG > 0 )) && debug "display_custom3 plugin is available"
|
||||
;;
|
||||
*display_custom4.sh)
|
||||
HAS_DISPLAY_CUSTOM4=1
|
||||
(( ARG_DEBUG != 0 )) && debug "display_custom4 plugin is available"
|
||||
(( ARG_DEBUG > 0 )) && debug "display_custom4 plugin is available"
|
||||
;;
|
||||
*display_custom5.sh)
|
||||
HAS_DISPLAY_CUSTOM5=1
|
||||
(( ARG_DEBUG != 0 )) && debug "display_custom5 plugin is available"
|
||||
(( ARG_DEBUG > 0 )) && debug "display_custom5 plugin is available"
|
||||
;;
|
||||
*display_custom6.sh)
|
||||
HAS_DISPLAY_CUSTOM6=1
|
||||
(( ARG_DEBUG != 0 )) && debug "display_custom6 plugin is available"
|
||||
(( ARG_DEBUG > 0 )) && debug "display_custom6 plugin is available"
|
||||
;;
|
||||
*display_custom7.sh)
|
||||
HAS_DISPLAY_CUSTOM7=1
|
||||
(( ARG_DEBUG != 0 )) && debug "display_custom7 plugin is available"
|
||||
(( ARG_DEBUG > 0 )) && debug "display_custom7 plugin is available"
|
||||
;;
|
||||
*display_custom8.sh)
|
||||
HAS_DISPLAY_CUSTOM8=1
|
||||
(( ARG_DEBUG != 0 )) && debug "display_custom8 plugin is available"
|
||||
(( ARG_DEBUG > 0 )) && debug "display_custom8 plugin is available"
|
||||
;;
|
||||
*display_custom9.sh)
|
||||
HAS_DISPLAY_CUSTOM9=1
|
||||
(( ARG_DEBUG != 0 )) && debug "display_custom9 plugin is available"
|
||||
(( ARG_DEBUG > 0 )) && debug "display_custom9 plugin is available"
|
||||
;;
|
||||
*notify_mail.sh)
|
||||
HAS_NOTIFY_MAIL=1
|
||||
(( ARG_DEBUG != 0 )) && debug "notify_mail plugin is available"
|
||||
(( ARG_DEBUG > 0 )) && debug "notify_mail plugin is available"
|
||||
;;
|
||||
*notify_sms.sh)
|
||||
HAS_NOTIFY_SMS=1
|
||||
(( ARG_DEBUG != 0 )) && debug "notify_sms plugin is available"
|
||||
(( ARG_DEBUG > 0 )) && debug "notify_sms plugin is available"
|
||||
;;
|
||||
*notify_eif.sh)
|
||||
HAS_NOTIFY_EIF=1
|
||||
(( ARG_DEBUG != 0 )) && debug "notify_eif plugin is available"
|
||||
(( ARG_DEBUG > 0 )) && debug "notify_eif plugin is available"
|
||||
;;
|
||||
*report_std.sh)
|
||||
HAS_REPORT_STD=1
|
||||
(( ARG_DEBUG != 0 )) && debug "report_std plugin is available"
|
||||
(( ARG_DEBUG > 0 )) && debug "report_std plugin is available"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
@@ -489,7 +489,7 @@ if [[ -n "${ARG_MAIL_TO}" ]] && (( DO_NOTIFY_MAIL == 0 ))
|
||||
then
|
||||
die "you cannot specify '--mail-to' without '--notify=mail'"
|
||||
fi
|
||||
if (( DO_NOTIFY_MAIL != 0 )) && [[ -z "${ARG_MAIL_TO}" ]]
|
||||
if (( DO_NOTIFY_MAIL > 0 )) && [[ -z "${ARG_MAIL_TO}" ]]
|
||||
then
|
||||
die "you cannot specify '--notify=mail' without '--mail-to'"
|
||||
fi
|
||||
@@ -502,64 +502,64 @@ if [[ -n "${ARG_SMS_PROVIDER}" ]] && (( DO_NOTIFY_SMS == 0 ))
|
||||
then
|
||||
die "you cannot specify '--sms-provider' without '--notify=sms'"
|
||||
fi
|
||||
if (( DO_NOTIFY_SMS != 0 )) && [[ -z "${ARG_SMS_TO}" ]]
|
||||
if (( DO_NOTIFY_SMS > 0 )) && [[ -z "${ARG_SMS_TO}" ]]
|
||||
then
|
||||
die "you cannot specify '--notify=sms' without '--sms-to'"
|
||||
fi
|
||||
if (( DO_NOTIFY_SMS != 0 )) && [[ -z "${ARG_SMS_PROVIDER}" ]]
|
||||
if (( DO_NOTIFY_SMS > 0 )) && [[ -z "${ARG_SMS_PROVIDER}" ]]
|
||||
then
|
||||
die "you cannot specify '--notify=sms' without '--sms-provider'"
|
||||
fi
|
||||
# --report/--detail/--id/--reverse/--last/--today/--with-history
|
||||
if (( DO_REPORT_STD != 0 ))
|
||||
if (( DO_REPORT_STD > 0 ))
|
||||
then
|
||||
if (( ARG_DETAIL != 0 )) && [[ -z "${ARG_FAIL_ID}" ]]
|
||||
if (( ARG_DETAIL > 0 )) && [[ -z "${ARG_FAIL_ID}" ]]
|
||||
then
|
||||
die "you must specify an unique value for '--id' when using '--detail'"
|
||||
fi
|
||||
if (( ARG_LAST != 0 )) && (( ARG_TODAY != 0 ))
|
||||
if (( ARG_LAST > 0 )) && (( ARG_TODAY > 0 ))
|
||||
then
|
||||
die "you cannot specify '--last' with '--today'"
|
||||
fi
|
||||
if (( ARG_LAST != 0 )) && (( ARG_DETAIL != 0 ))
|
||||
if (( ARG_LAST > 0 )) && (( ARG_DETAIL > 0 ))
|
||||
then
|
||||
die "you cannot specify '--last' with '--detail'"
|
||||
fi
|
||||
if (( ARG_LAST != 0 )) && (( ARG_REVERSE != 0 ))
|
||||
if (( ARG_LAST > 0 )) && (( ARG_REVERSE > 0 ))
|
||||
then
|
||||
die "you cannot specify '--last' with '--detail'"
|
||||
fi
|
||||
if (( ARG_LAST != 0 )) && [[ -n "${ARG_FAIL_ID}" ]]
|
||||
if (( ARG_LAST > 0 )) && [[ -n "${ARG_FAIL_ID}" ]]
|
||||
then
|
||||
die "you cannot specify '--last' with '--id'"
|
||||
fi
|
||||
if (( ARG_TODAY != 0 )) && (( ARG_DETAIL != 0 ))
|
||||
if (( ARG_TODAY > 0 )) && (( ARG_DETAIL > 0 ))
|
||||
then
|
||||
die "you cannot specify '--today' with '--detail'"
|
||||
fi
|
||||
if (( ARG_TODAY != 0 )) && (( ARG_REVERSE != 0 ))
|
||||
if (( ARG_TODAY > 0 )) && (( ARG_REVERSE > 0 ))
|
||||
then
|
||||
die "you cannot specify '--today' with '--detail'"
|
||||
fi
|
||||
if (( ARG_TODAY != 0 )) && [[ -n "${ARG_FAIL_ID}" ]]
|
||||
if (( ARG_TODAY > 0 )) && [[ -n "${ARG_FAIL_ID}" ]]
|
||||
then
|
||||
die "you cannot specify '--today' with '--id'"
|
||||
fi
|
||||
# switch on history for --last & --today
|
||||
if (( ARG_LAST != 0 )) || (( ARG_TODAY != 0 ))
|
||||
if (( ARG_LAST > 0 )) || (( ARG_TODAY > 0 ))
|
||||
then
|
||||
ARG_HISTORY=1
|
||||
fi
|
||||
fi
|
||||
if (( DO_REPORT_STD == 0 )) && (( ARG_LAST != 0 ))
|
||||
if (( DO_REPORT_STD == 0 )) && (( ARG_LAST > 0 ))
|
||||
then
|
||||
die "you cannot specify '--last' without '--report'"
|
||||
fi
|
||||
if (( DO_REPORT_STD == 0 )) && (( ARG_REVERSE != 0 ))
|
||||
if (( DO_REPORT_STD == 0 )) && (( ARG_REVERSE > 0 ))
|
||||
then
|
||||
die "you cannot specify '--reverse' without '--report'"
|
||||
fi
|
||||
if (( DO_REPORT_STD == 0 )) && (( ARG_DETAIL != 0 ))
|
||||
if (( DO_REPORT_STD == 0 )) && (( ARG_DETAIL > 0 ))
|
||||
then
|
||||
die "you cannot specify '--detail' without '--report'"
|
||||
fi
|
||||
@@ -595,7 +595,7 @@ return 0
|
||||
# REQUIRES: n/a
|
||||
function exists_hc
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
typeset EXISTS_HC="${1}"
|
||||
typeset FDIR=""
|
||||
typeset EXISTS_RC=0
|
||||
@@ -622,7 +622,7 @@ return ${EXISTS_RC}
|
||||
# REQUIRES: n/a
|
||||
function find_hc
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
typeset FIND_HC="${1}"
|
||||
typeset FDIR=""
|
||||
|
||||
@@ -645,7 +645,7 @@ return 0
|
||||
# the rewrite operation!!
|
||||
function fix_logs
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
typeset FIX_FILE=""
|
||||
typeset FIX_RC=0
|
||||
typeset LOG_STASH=""
|
||||
@@ -656,7 +656,7 @@ typeset TMP_COUNT=0
|
||||
typeset SAVE_TMP_FILE="${TMP_DIR}/.$0.save.log.$$"
|
||||
typeset TMP_FILE="${TMP_DIR}/.$0.tmp.log.$$"
|
||||
|
||||
if (( ARG_HISTORY != 0 ))
|
||||
if (( ARG_HISTORY > 0 ))
|
||||
then
|
||||
set +f # file globbing must be on
|
||||
LOG_STASH="${HC_LOG} ${ARCHIVE_DIR}/hc.*.log"
|
||||
@@ -812,7 +812,7 @@ return ${FIX_RC}
|
||||
# REQUIRES: die(), display_*(), notify_*(), warn()
|
||||
function handle_hc
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
typeset HC_NAME="${1}"
|
||||
typeset HC_STDOUT_LOG_SHORT=""
|
||||
typeset HC_STDERR_LOG_SHORT=""
|
||||
@@ -831,7 +831,7 @@ then
|
||||
HC_MSG_VAR=$(<${HC_MSG_FILE})
|
||||
|
||||
# DEBUG: dump TMP file
|
||||
if (( ARG_DEBUG != 0 ))
|
||||
if (( ARG_DEBUG > 0 ))
|
||||
then
|
||||
debug "begin dumping plugin messages file (${HC_MSG_FILE})"
|
||||
print "${HC_MSG_VAR}"
|
||||
@@ -840,7 +840,7 @@ then
|
||||
|
||||
# determine ALL_MSG_STC (sum of all STCs)
|
||||
ALL_MSG_STC=$(print "${HC_MSG_VAR}" | awk -F"${MSG_SEP}" 'BEGIN { stc = 0 } { for (i=1;i<=NF;i++) { stc = stc + $1 }} END { print stc }' 2>/dev/null)
|
||||
(( ARG_DEBUG != 0 )) && debug "HC all STC: ${ALL_MSG_STC}"
|
||||
(( ARG_DEBUG > 0 )) && debug "HC all STC: ${ALL_MSG_STC}"
|
||||
data_is_numeric ${ALL_MSG_STC} || die "HC all STC computes to a non-numeric value"
|
||||
else
|
||||
# nothing to do
|
||||
@@ -978,7 +978,7 @@ then
|
||||
fi
|
||||
else
|
||||
# default STDOUT
|
||||
if (( ARG_VERBOSE != 0 ))
|
||||
if (( ARG_VERBOSE > 0 ))
|
||||
then
|
||||
print "${HC_MSG_VAR}" | while IFS=${MSG_SEP} read ONE_MSG_STC ONE_MSG_TIME ONE_MSG_TEXT ONE_MSG_CUR_VAL ONE_MSG_EXP_VAL
|
||||
do
|
||||
@@ -1008,7 +1008,7 @@ then
|
||||
fi
|
||||
fi
|
||||
printf "%s" "INFO: ${HC_NAME} [STC=${ONE_MSG_STC}]: ${ONE_MSG_TEXT}"
|
||||
if (( ONE_MSG_STC != 0 ))
|
||||
if (( ONE_MSG_STC > 0 ))
|
||||
then
|
||||
printf " %s\n" "[FAIL_ID=${HC_FAIL_ID}]"
|
||||
else
|
||||
@@ -1020,7 +1020,7 @@ then
|
||||
fi
|
||||
|
||||
# log & notify routines
|
||||
if (( ARG_LOG != 0 ))
|
||||
if (( ARG_LOG > 0 ))
|
||||
then
|
||||
# log routine (combined STC=0 or <>0)
|
||||
print "${HC_MSG_VAR}" | while IFS=${MSG_SEP} read ONE_MSG_STC ONE_MSG_TIME ONE_MSG_TEXT ONE_MSG_CUR_VAL ONE_MSG_EXP_VAL
|
||||
@@ -1143,7 +1143,7 @@ fi
|
||||
# REQUIRES: warn()
|
||||
function handle_timeout
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
[[ -n "${CHILD_PID}" ]] && kill -s TERM ${CHILD_PID}
|
||||
warn "child process with PID ${CHILD_PID} has been forcefully stopped"
|
||||
# shellcheck disable=SC2034
|
||||
@@ -1160,7 +1160,7 @@ return 0
|
||||
# REQUIRES: die()
|
||||
function init_check_host
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
typeset HC_EXEC=""
|
||||
typeset DISPLAY_STYLE=""
|
||||
|
||||
@@ -1290,20 +1290,20 @@ return 0
|
||||
# REQUIRES: die()
|
||||
function init_hc
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
typeset HC_PLATFORMS="${2}"
|
||||
typeset HC_VERSION="${3}"
|
||||
typeset HC_OK=0
|
||||
|
||||
# check platform (don't use a pattern comparison here (~! mksh/pdksh))
|
||||
HC_OK=$(print "${HC_PLATFORMS}" | grep -c "${OS_NAME}" 2>/dev/null)
|
||||
(( HC_OK != 0 )) || die "may only run on platform(s): ${HC_PLATFORMS}"
|
||||
(( HC_OK > 0 )) || die "may only run on platform(s): ${HC_PLATFORMS}"
|
||||
|
||||
# check version of HC plugin
|
||||
case "${HC_VERSION}" in
|
||||
[0-2][0-9][0-9][0-9]-[0-1][0-9]-[0-3][0-9])
|
||||
# OK
|
||||
(( ARG_DEBUG != 0 )) && debug "HC plugin ${1} has version ${HC_VERSION}"
|
||||
(( ARG_DEBUG > 0 )) && debug "HC plugin ${1} has version ${HC_VERSION}"
|
||||
;;
|
||||
*)
|
||||
die "version of the HC plugin ${1} is not in YYYY-MM-DD format (${HC_VERSION})"
|
||||
@@ -1321,7 +1321,7 @@ return 0
|
||||
# REQUIRES: n/a
|
||||
function is_scheduled
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
typeset CRON_HC="${1}"
|
||||
typeset CRON_COUNT=0
|
||||
typeset CRON_SYS_LOCATIONS='/etc/crontab /etc/cron.d/*'
|
||||
@@ -1359,7 +1359,7 @@ return ${CRON_COUNT}
|
||||
# REQUIRES: n/a
|
||||
function list_core
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
typeset FACTION="${1}"
|
||||
typeset FCONFIG=""
|
||||
typeset FDIR=""
|
||||
@@ -1392,7 +1392,7 @@ do
|
||||
FVERSION=$(grep '^typeset _VERSION=' "${FFILE}" 2>&1 | tr -d '\"' | tr -d ' \t' | cut -f1 -d'#' | cut -f2 -d'=')
|
||||
# look for configuration file string
|
||||
HAS_FCONFIG=$(grep -c '^typeset _CONFIG_FILE=' "${FFILE}" 2>&1)
|
||||
if (( HAS_FCONFIG != 0 ))
|
||||
if (( HAS_FCONFIG > 0 ))
|
||||
then
|
||||
FCONFIG="Yes"
|
||||
else
|
||||
@@ -1450,7 +1450,7 @@ return 0
|
||||
# REQUIRES: is_scheduled()
|
||||
function list_hc
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
typeset FACTION="${1}"
|
||||
typeset FNEEDLE="${2}"
|
||||
typeset FCONFIG=""
|
||||
@@ -1492,7 +1492,7 @@ do
|
||||
FVERSION=$(grep '^typeset _VERSION=' "${FFILE}" 2>&1 | tr -d '\"' | tr -d ' \t' | cut -f1 -d'#' | cut -f2 -d'=')
|
||||
# look for configuration file string
|
||||
HAS_FCONFIG=$(grep -c '^typeset _CONFIG_FILE=' "${FFILE}" 2>&1)
|
||||
if (( HAS_FCONFIG != 0 ))
|
||||
if (( HAS_FCONFIG > 0 ))
|
||||
then
|
||||
FCONFIG="Yes"
|
||||
# *.conf.dist first
|
||||
@@ -1619,20 +1619,20 @@ return 0
|
||||
# REQUIRES: n/a
|
||||
function log
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
typeset NOW="$(date '+%d-%h-%Y %H:%M:%S')"
|
||||
typeset LOG_LINE=""
|
||||
|
||||
if [[ -n "${1}" ]]
|
||||
then
|
||||
if (( ARG_LOG != 0 ))
|
||||
if (( ARG_LOG > 0 ))
|
||||
then
|
||||
print - "$*" | while read -r LOG_LINE
|
||||
do
|
||||
print "${NOW}: INFO: [$$]:" "${LOG_LINE}" >>${LOG_FILE}
|
||||
done
|
||||
fi
|
||||
if (( ARG_VERBOSE != 0 ))
|
||||
if (( ARG_VERBOSE > 0 ))
|
||||
then
|
||||
print - "$*" | while read -r LOG_LINE
|
||||
do
|
||||
@@ -1654,7 +1654,7 @@ return 0
|
||||
# REQUIRES: n/a
|
||||
function log_hc
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
typeset HC_NAME="${1}"
|
||||
typeset HC_STC=${2}
|
||||
typeset HC_NOW="$(date '+%Y-%m-%d %H:%M:%S' 2>/dev/null)"
|
||||
@@ -1708,7 +1708,7 @@ return 0
|
||||
# REQUIRES: n/a
|
||||
function show_statistics
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
typeset _ARCHIVE_FILE=""
|
||||
|
||||
# current events
|
||||
@@ -1806,7 +1806,7 @@ return 0
|
||||
# REQUIRES: n/a
|
||||
function stat_hc
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
typeset STAT_HC="${1}"
|
||||
typeset STAT_RC=1 # default: enabled
|
||||
|
||||
@@ -1823,20 +1823,20 @@ return ${STAT_RC}
|
||||
# REQUIRES: n/a
|
||||
function warn
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
typeset NOW="$(date '+%d-%h-%Y %H:%M:%S')"
|
||||
typeset LOG_LINE=""
|
||||
|
||||
if [[ -n "${1}" ]]
|
||||
then
|
||||
if (( ARG_LOG != 0 ))
|
||||
if (( ARG_LOG > 0 ))
|
||||
then
|
||||
print - "$*" | while read -r LOG_LINE
|
||||
do
|
||||
print "${NOW}: WARN: [$$]:" "${LOG_LINE}" >>${LOG_FILE}
|
||||
done
|
||||
fi
|
||||
if (( ARG_VERBOSE != 0 ))
|
||||
if (( ARG_VERBOSE > 0 ))
|
||||
then
|
||||
print - "$*" | while read -r LOG_LINE
|
||||
do
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
# REQUIRES: n/a
|
||||
function data_get_lvalue_from_config
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
typeset _PARAMETER="${1}"
|
||||
typeset _LVALUE=""
|
||||
typeset _RC=0
|
||||
@@ -58,7 +58,7 @@ return ${_RC}
|
||||
# REQUIRES: n/a
|
||||
function data_chop
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
|
||||
print -R "${1%?}" 2>/dev/null
|
||||
|
||||
@@ -74,7 +74,7 @@ return 0
|
||||
# REQUIRES: n/a
|
||||
function data_contains_string
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
|
||||
typeset _HAYSTACK="${1}"
|
||||
typeset _NEEDLE="${2}"
|
||||
@@ -94,7 +94,7 @@ return ${_RC}
|
||||
# REQUIRES: n/a
|
||||
function data_magic_quote
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
typeset _SEP="${2:-%}"
|
||||
typeset _MAGIC="${MAGIC:-!_!}"
|
||||
|
||||
@@ -112,7 +112,7 @@ return 0
|
||||
# REQUIRES: n/a
|
||||
function data_magic_unquote
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
typeset _SEP="${2:-%}"
|
||||
typeset _MAGIC="${MAGIC:-!_!}"
|
||||
|
||||
@@ -130,7 +130,7 @@ return 0
|
||||
# REQUIRES: n/a
|
||||
function data_escape_csv
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
|
||||
print -R "${1}" 2>/dev/null | sed 's#\([;]\)#\\\1#g' 2>/dev/null
|
||||
|
||||
@@ -146,7 +146,7 @@ return 0
|
||||
# REQUIRES: n/a
|
||||
function data_escape_json
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
typeset _NEEDLE='[\"]'
|
||||
|
||||
print -R "${1}" 2>/dev/null | sed 's#\(["\]\)#\\\1#g' 2>/dev/null
|
||||
@@ -163,7 +163,7 @@ return 0
|
||||
# REQUIRES: n/a
|
||||
function data_decomma
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
|
||||
print -R "${1}" 2>/dev/null | tr -d ',' 2>/dev/null
|
||||
|
||||
@@ -179,7 +179,7 @@ return 0
|
||||
# REQUIRES: n/a
|
||||
function data_decomma_last
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
|
||||
print -R "${1%*,}" 2>/dev/null
|
||||
|
||||
@@ -195,7 +195,7 @@ return 0
|
||||
# REQUIRES: n/a
|
||||
function data_decomma_first
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
|
||||
print -R "${1#,*}" 2>/dev/null
|
||||
|
||||
@@ -211,7 +211,7 @@ return 0
|
||||
# REQUIRES: n/a
|
||||
function data_dequote
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
|
||||
print -R "${1}" 2>/dev/null | tr -d '\"' 2>/dev/null | tr -d "'" 2>/dev/null
|
||||
|
||||
@@ -227,7 +227,7 @@ return 0
|
||||
# REQUIRES: n/a
|
||||
function data_comma2space
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
|
||||
print -R "${1}" 2>/dev/null | tr ',' ' ' 2>/dev/null
|
||||
|
||||
@@ -243,7 +243,7 @@ return 0
|
||||
# REQUIRES: n/a
|
||||
function data_comma2pipe
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
|
||||
print -R "${1}" 2>/dev/null | tr ',' '|' 2>/dev/null
|
||||
|
||||
@@ -259,7 +259,7 @@ return 0
|
||||
# REQUIRES: n/a
|
||||
function data_comma2newline
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
|
||||
print -R "${1}" 2>/dev/null | tr ',' '\n' 2>/dev/null
|
||||
|
||||
@@ -275,7 +275,7 @@ return 0
|
||||
# REQUIRES: n/a
|
||||
function data_newline2comma
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
|
||||
print -R "${1}" 2>/dev/null | tr '\n' ',' 2>/dev/null
|
||||
|
||||
@@ -291,7 +291,7 @@ return 0
|
||||
# REQUIRES: n/a
|
||||
function data_newline2hash
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
|
||||
print -R "${1}" 2>/dev/null | tr '\r' '#' 2>/dev/null
|
||||
|
||||
@@ -307,7 +307,7 @@ return 0
|
||||
# REQUIRES: n/a
|
||||
function data_space2comma
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
|
||||
print -R "${1}" 2>/dev/null | tr -s ' ' 2>/dev/null | tr ' ' ',' 2>/dev/null
|
||||
|
||||
@@ -323,7 +323,7 @@ return 0
|
||||
# REQUIRES: n/a
|
||||
function data_pipe2comma
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
|
||||
print -R "${1}" 2>/dev/null | tr -s '|' 2>/dev/null | tr ' '|',' 2>/dev/null
|
||||
|
||||
@@ -339,7 +339,7 @@ return 0
|
||||
# REQUIRES: n/a
|
||||
function data_space2hash
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
|
||||
print -R "${1}" 2>/dev/null | tr -s ' ' 2>/dev/null | tr ' ' '#' 2>/dev/null
|
||||
|
||||
@@ -355,7 +355,7 @@ return 0
|
||||
# REQUIRES: n/a
|
||||
function data_strip_newline
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
|
||||
print -R "${1}" 2>/dev/null | tr -d '\n' 2>/dev/null | tr -d '\r' 2>/dev/null
|
||||
|
||||
@@ -371,7 +371,7 @@ return 0
|
||||
# REQUIRES: n/a
|
||||
function data_strip_space
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
|
||||
print -R "${1}" 2>/dev/null | tr -d '[:space:]' 2>/dev/null
|
||||
|
||||
@@ -387,7 +387,7 @@ return 0
|
||||
# REQUIRES: n/a
|
||||
function data_strip_leading_space
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
|
||||
print -R "${1}" | sed 's/^[[:blank:]]*//' 2>/dev/null
|
||||
|
||||
@@ -403,7 +403,7 @@ return 0
|
||||
# REQUIRES: n/a
|
||||
function data_strip_trailing_space
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
|
||||
print -R "${1}" | sed 's/[[:blank:]]*$//' 2>/dev/null
|
||||
|
||||
@@ -419,7 +419,7 @@ return 0
|
||||
# REQUIRES: n/a
|
||||
function data_strip_outer_space
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
|
||||
print -R "${1}" | sed 's/^[[:blank:]]*//;s/[[:blank:]]*$//' 2>/dev/null
|
||||
|
||||
@@ -435,7 +435,7 @@ return 0
|
||||
# REQUIRES: n/a
|
||||
function data_lc
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
|
||||
print -R "${1}" 2>/dev/null | tr '[:upper:]' '[:lower:]' 2>/dev/null
|
||||
|
||||
@@ -451,7 +451,7 @@ return 0
|
||||
# REQUIRES: n/a
|
||||
function data_uc
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
|
||||
print -R "${1}" 2>/dev/null | tr '[:lower:]' '[:upper:]' 2>/dev/null
|
||||
|
||||
@@ -467,7 +467,7 @@ return 0
|
||||
# REQUIRES: n/a
|
||||
function data_is_numeric
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
|
||||
case "${1}" in
|
||||
+([0-9])*(.)*([0-9]))
|
||||
@@ -492,7 +492,7 @@ return 0
|
||||
# REFERENCE: added from http://www.shelldorado.com/scripts/cmds/urlencode
|
||||
function data_encode_url
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
typeset _EncodeEOL=0
|
||||
|
||||
LANG=C awk '
|
||||
@@ -546,7 +546,7 @@ return 0
|
||||
# REFERENCE: https://raw.githubusercontent.com/dualbus/tutorial_nmap/master/iprange
|
||||
function data_dot2ip
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
typeset _DOT="${1}"
|
||||
typeset _IP=0
|
||||
typeset _OLD_IFS="${IFS}"
|
||||
@@ -575,7 +575,7 @@ return 0
|
||||
# REFERENCE: https://raw.githubusercontent.com/dualbus/tutorial_nmap/master/iprange
|
||||
function data_ip2dot
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
typeset _IP="${1}"
|
||||
typeset _W=""
|
||||
typeset _X=""
|
||||
@@ -602,7 +602,7 @@ return 0
|
||||
# REFERENCE: https://raw.githubusercontent.com/dualbus/tutorial_nmap/master/iprange
|
||||
function data_bits2mask
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
typeset _BITS=${1}
|
||||
typeset _MAX=4294967296
|
||||
typeset _OFFSET=0
|
||||
@@ -658,7 +658,7 @@ return 0
|
||||
# REFERENCE: https://raw.githubusercontent.com/dualbus/tutorial_nmap/master/iprange
|
||||
function data_mask2bits
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
typeset _MASK="${1}"
|
||||
typeset -i _I=32
|
||||
|
||||
@@ -679,7 +679,7 @@ return 0
|
||||
# REQUIRES: n/a
|
||||
function data_is_ipv4
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
typeset _IP="${1}"
|
||||
typeset _RC=0
|
||||
|
||||
@@ -704,7 +704,7 @@ return ${_RC}
|
||||
# REFERENCE: https://groups.google.com/forum/#!topic/comp.unix.shell/aPoPzFWP2Og
|
||||
function data_date2epoch
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
typeset _YEAR="${1}"
|
||||
typeset _MONTH="${2}"
|
||||
typeset _DAY="${3}"
|
||||
|
||||
@@ -31,11 +31,11 @@
|
||||
# REQUIRES: n/a
|
||||
function linux_get_distro
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
|
||||
# linux only
|
||||
check_platform 'Linux' || {
|
||||
(( ARG_DEBUG != 0 )) && debug "may only run on platform(s): Linux"
|
||||
(( ARG_DEBUG > 0 )) && debug "may only run on platform(s): Linux"
|
||||
return 1
|
||||
}
|
||||
|
||||
@@ -86,11 +86,11 @@ return 0
|
||||
# REQUIRES: n/a
|
||||
function linux_get_init
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
|
||||
# linux only
|
||||
check_platform 'Linux' || {
|
||||
(( ARG_DEBUG != 0 )) && debug "may only run on platform(s): Linux"
|
||||
(( ARG_DEBUG > 0 )) && debug "may only run on platform(s): Linux"
|
||||
return 1
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ return 0
|
||||
# REQUIRES: n/a
|
||||
function linux_has_crm
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
typeset _CRM_BIN=""
|
||||
typeset _HAS_CRM=0
|
||||
|
||||
@@ -134,7 +134,7 @@ then
|
||||
crm status >/dev/null 2>/dev/null
|
||||
(( $? == 0 )) && _HAS_CRM=1
|
||||
else
|
||||
(( ARG_DEBUG != 0 )) && debug "corosync (crm) is not active here"
|
||||
(( ARG_DEBUG > 0 )) && debug "corosync (crm) is not active here"
|
||||
return 1
|
||||
fi
|
||||
|
||||
@@ -152,7 +152,7 @@ return 0
|
||||
# REQUIRES: n/a
|
||||
function linux_has_docker
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
typeset _DOCKER_BIN=""
|
||||
typeset _HAS_DOCKER=0
|
||||
|
||||
@@ -169,7 +169,7 @@ then
|
||||
docker ps >/dev/null 2>/dev/null
|
||||
(( $? == 0 )) && _HAS_DOCKER=1
|
||||
else
|
||||
(( ARG_DEBUG != 0 )) && debug "docker is not active here"
|
||||
(( ARG_DEBUG > 0 )) && debug "docker is not active here"
|
||||
return 1
|
||||
fi
|
||||
|
||||
@@ -187,7 +187,7 @@ return 0
|
||||
# REQUIRES: n/a
|
||||
function linux_has_nm
|
||||
{
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
typeset _NMCLI_BIN=""
|
||||
typeset _HAS_NM=0
|
||||
|
||||
@@ -203,7 +203,7 @@ then
|
||||
# check for active
|
||||
_HAS_NM=$(nmcli networking 2>/dev/null | grep -c -i "enabled")
|
||||
else
|
||||
(( ARG_DEBUG != 0 )) && debug "NetworkManager is not active here"
|
||||
(( ARG_DEBUG > 0 )) && debug "NetworkManager is not active here"
|
||||
return 1
|
||||
fi
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ typeset _SUPPORTED_PLATFORMS="AIX,HP-UX,Linux" # uname -s match
|
||||
# ------------------------- CONFIGURATION ends here ---------------------------
|
||||
|
||||
# set defaults
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
|
||||
|
||||
typeset _EIF_MESSAGE="$1 alert with ID ${HC_FAIL_ID}"
|
||||
@@ -105,7 +105,7 @@ then
|
||||
_CHILD_RC=$?
|
||||
kill -s TERM ${_SLEEP_PID} >/dev/null 2>&1
|
||||
# process return codes
|
||||
if (( _CHILD_RC != 0 ))
|
||||
if (( _CHILD_RC > 0 ))
|
||||
then
|
||||
warn "problem in sending alert via EIF [RC=${_CHILD_RC}]"
|
||||
else
|
||||
|
||||
@@ -35,7 +35,7 @@ typeset _SUPPORTED_PLATFORMS="AIX,HP-UX,Linux" # uname -s match
|
||||
# ------------------------- CONFIGURATION ends here ---------------------------
|
||||
|
||||
# set defaults
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
|
||||
|
||||
typeset _MAIL_HC="$1"
|
||||
|
||||
@@ -36,7 +36,7 @@ typeset _SUPPORTED_PLATFORMS="AIX,HP-UX,Linux" # uname -s match
|
||||
# ------------------------- CONFIGURATION ends here ---------------------------
|
||||
|
||||
# set defaults
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
|
||||
|
||||
typeset _SMS_HC="$1"
|
||||
|
||||
@@ -35,7 +35,7 @@ typeset _SUPPORTED_PLATFORMS="AIX,HP-UX,Linux" # uname -s match
|
||||
# ------------------------- CONFIGURATION ends here ---------------------------
|
||||
|
||||
# set defaults
|
||||
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
|
||||
|
||||
typeset _DIR_PREFIX=""
|
||||
@@ -52,7 +52,7 @@ typeset _LOG_STASH=""
|
||||
typeset _SORT_CMD=""
|
||||
|
||||
# which files do we need to examine
|
||||
if (( ARG_HISTORY != 0 ))
|
||||
if (( ARG_HISTORY > 0 ))
|
||||
then
|
||||
set +f # file globbing must be on
|
||||
_LOG_STASH="${HC_LOG} ${ARCHIVE_DIR}/hc.*.log"
|
||||
@@ -61,7 +61,7 @@ else
|
||||
fi
|
||||
|
||||
# --last report
|
||||
if (( ARG_LAST != 0 ))
|
||||
if (( ARG_LAST > 0 ))
|
||||
then
|
||||
printf "\n| %-30s | %-20s | %-14s | %-4s\n" "HC" "Timestamp" "FAIL ID" "STC (combined value)"
|
||||
# shellcheck disable=SC2183
|
||||
@@ -113,14 +113,14 @@ then
|
||||
else
|
||||
_ID_NEEDLE="[0-9][0-9]*"
|
||||
[[ -n "${ARG_FAIL_ID}" ]] && _ID_NEEDLE="${ARG_FAIL_ID}"
|
||||
(( ARG_TODAY != 0 )) && _ID_NEEDLE="$(date '+%Y%m%d')" # refers to timestamp of HC FAIL_ID
|
||||
(( ARG_TODAY > 0 )) && _ID_NEEDLE="$(date '+%Y%m%d')" # refers to timestamp of HC FAIL_ID
|
||||
|
||||
# check fail count (look for unique IDs in the 5th field of the HC log)
|
||||
_FAIL_COUNT=$(cut -f5 -d"${LOG_SEP}" ${_LOG_STASH} 2>/dev/null | grep -E -e "${_ID_NEEDLE}" | uniq | wc -l)
|
||||
if (( _FAIL_COUNT != 0 ))
|
||||
if (( _FAIL_COUNT > 0 ))
|
||||
then
|
||||
# check for detail or not?
|
||||
if (( ARG_DETAIL != 0 )) && (( _FAIL_COUNT != 1 ))
|
||||
if (( ARG_DETAIL > 0 )) && (( _FAIL_COUNT > 1 ))
|
||||
then
|
||||
ARG_LOG=1 die "you must specify a unique FAIL_ID value"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user