* Add caching to reporting features
* Fixed a problem with LOG_HEALTHY="Yes" and check_params() * Other smaller fixes * Whitespace fixes
This commit is contained in:
parent
8976184b45
commit
c8aa4aad79
@ -21,6 +21,16 @@ HC_LOG_HEALTHY="No"
|
|||||||
# [values: Yes|No]
|
# [values: Yes|No]
|
||||||
HC_WILL_FIX="Yes"
|
HC_WILL_FIX="Yes"
|
||||||
|
|
||||||
|
# cache "last" reporting entries. Set to 'Yes' to speed up reporting of the last
|
||||||
|
# registered HC events
|
||||||
|
# [values: Yes|No]
|
||||||
|
HC_REPORT_CACHE_LAST="No"
|
||||||
|
|
||||||
|
# cache "today" reporting entries. Set to 'Yes' to speed up reporting of today's
|
||||||
|
# registered HC events
|
||||||
|
# [values: Yes|No]
|
||||||
|
HC_REPORT_CACHE_TODAY="No"
|
||||||
|
|
||||||
|
|
||||||
#******************************************************************************
|
#******************************************************************************
|
||||||
# End of FILE
|
# End of 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="2020-03-12"
|
typeset -r SCRIPT_VERSION="2020-04-07"
|
||||||
# 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
|
||||||
@ -104,6 +104,10 @@ typeset HC_STDOUT_LOG=""
|
|||||||
typeset HC_STDERR_LOG=""
|
typeset HC_STDERR_LOG=""
|
||||||
typeset HC_WILL_FIX=""
|
typeset HC_WILL_FIX=""
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
|
typeset HC_REPORT_CACHE_LAST=""
|
||||||
|
# shellcheck disable=SC2034
|
||||||
|
typeset HC_REPORT_CACHE_TODAY=""
|
||||||
|
# shellcheck disable=SC2034
|
||||||
typeset LINUX_DISTRO=""
|
typeset LINUX_DISTRO=""
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
typeset LINUX_RELEASE=""
|
typeset LINUX_RELEASE=""
|
||||||
@ -255,8 +259,8 @@ case "${KSH_VERSION}" in
|
|||||||
. ${FPATH_PARENT}/core/include_core.sh
|
. ${FPATH_PARENT}/core/include_core.sh
|
||||||
if [[ -r ${FPATH_PARENT}/core/include_data.sh && -h ${FPATH_PARENT}/core/include_data ]]
|
if [[ -r ${FPATH_PARENT}/core/include_data.sh && -h ${FPATH_PARENT}/core/include_data ]]
|
||||||
then
|
then
|
||||||
# shellcheck source=/dev/null
|
|
||||||
(( ARG_DEBUG > 0 )) && print -u2 "DEBUG: including ${FPATH_PARENT}/core/include_data.sh"
|
(( ARG_DEBUG > 0 )) && print -u2 "DEBUG: including ${FPATH_PARENT}/core/include_data.sh"
|
||||||
|
# shellcheck source=/dev/null
|
||||||
. ${FPATH_PARENT}/core/include_data.sh
|
. ${FPATH_PARENT}/core/include_data.sh
|
||||||
else
|
else
|
||||||
print -u2 "ERROR: library file ${FPATH_PARENT}/core/include_data.sh is not present (tip: run --fix-symlinks)"
|
print -u2 "ERROR: library file ${FPATH_PARENT}/core/include_data.sh is not present (tip: run --fix-symlinks)"
|
||||||
@ -264,8 +268,8 @@ case "${KSH_VERSION}" in
|
|||||||
fi
|
fi
|
||||||
if [[ -r ${FPATH_PARENT}/core/include_os.sh && -h ${FPATH_PARENT}/core/include_os ]]
|
if [[ -r ${FPATH_PARENT}/core/include_os.sh && -h ${FPATH_PARENT}/core/include_os ]]
|
||||||
then
|
then
|
||||||
# shellcheck source=/dev/null
|
|
||||||
(( ARG_DEBUG > 0 )) && print -u2 "DEBUG: including ${FPATH_PARENT}/core/include_os.sh"
|
(( ARG_DEBUG > 0 )) && print -u2 "DEBUG: including ${FPATH_PARENT}/core/include_os.sh"
|
||||||
|
# shellcheck source=/dev/null
|
||||||
. ${FPATH_PARENT}/core/include_os.sh
|
. ${FPATH_PARENT}/core/include_os.sh
|
||||||
else
|
else
|
||||||
print -u2 "ERROR: library file ${FPATH_PARENT}/core/include_os.sh is not present (tip: run --fix-symlinks)"
|
print -u2 "ERROR: library file ${FPATH_PARENT}/core/include_os.sh is not present (tip: run --fix-symlinks)"
|
||||||
@ -274,7 +278,7 @@ case "${KSH_VERSION}" in
|
|||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
# include include_*
|
# include include_*
|
||||||
find ${FPATH_PARENT}/core -name "include_*.sh" -type f -print 2>/dev/null | while read INCLUDE_FILE
|
find ${FPATH_PARENT}/core -name "include_*.sh" -type f -print 2>/dev/null | while read -r INCLUDE_FILE
|
||||||
do
|
do
|
||||||
if [[ -h ${INCLUDE_FILE%%.sh} ]]
|
if [[ -h ${INCLUDE_FILE%%.sh} ]]
|
||||||
then
|
then
|
||||||
@ -330,7 +334,7 @@ function check_lock_dir
|
|||||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||||
if (( ARG_LOCK > 0 ))
|
if (( ARG_LOCK > 0 ))
|
||||||
then
|
then
|
||||||
mkdir ${LOCK_DIR} >/dev/null || {
|
mkdir ${LOCK_DIR} >/dev/null 2>/dev/null || {
|
||||||
print -u2 "ERROR: unable to acquire lock ${LOCK_DIR}"
|
print -u2 "ERROR: unable to acquire lock ${LOCK_DIR}"
|
||||||
ARG_VERBOSE=0 warn "unable to acquire lock ${LOCK_DIR}"
|
ARG_VERBOSE=0 warn "unable to acquire lock ${LOCK_DIR}"
|
||||||
if [[ -f ${LOCK_DIR}/.pid ]]
|
if [[ -f ${LOCK_DIR}/.pid ]]
|
||||||
@ -465,12 +469,6 @@ then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
# --log-healthy
|
|
||||||
if (( ARG_LOG_HEALTHY > 0 && ARG_ACTION != 4 ))
|
|
||||||
then
|
|
||||||
print -u2 "ERROR: you can only use '--log-healthy' in combination with '--run'"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
# check log location
|
# check log location
|
||||||
if (( ARG_LOG > 0 ))
|
if (( ARG_LOG > 0 ))
|
||||||
then
|
then
|
||||||
@ -959,6 +957,7 @@ do
|
|||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
-list-details|--list-details)
|
-list-details|--list-details)
|
||||||
|
# shellcheck disable=SC2034
|
||||||
ARG_LIST_DETAILS=1
|
ARG_LIST_DETAILS=1
|
||||||
ARG_ACTION=9
|
ARG_ACTION=9
|
||||||
;;
|
;;
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -30,7 +30,7 @@
|
|||||||
function report_std
|
function report_std
|
||||||
{
|
{
|
||||||
# ------------------------- CONFIGURATION starts here -------------------------
|
# ------------------------- CONFIGURATION starts here -------------------------
|
||||||
typeset _VERSION="2019-05-19" # YYYY-MM-DD
|
typeset _VERSION="2020-04-07" # YYYY-MM-DD
|
||||||
typeset _SUPPORTED_PLATFORMS="AIX,HP-UX,Linux" # uname -s match
|
typeset _SUPPORTED_PLATFORMS="AIX,HP-UX,Linux" # uname -s match
|
||||||
# ------------------------- CONFIGURATION ends here ---------------------------
|
# ------------------------- CONFIGURATION ends here ---------------------------
|
||||||
|
|
||||||
@ -59,8 +59,13 @@ typeset _OLDER_MONTH=""
|
|||||||
typeset _OLDER_YEAR=""
|
typeset _OLDER_YEAR=""
|
||||||
typeset _NEWER_MONTH=""
|
typeset _NEWER_MONTH=""
|
||||||
typeset _NEWER_YEAR=""
|
typeset _NEWER_YEAR=""
|
||||||
|
typeset _HC_REPORT_CACHE_LAST_STUB="${STATE_PERM_DIR}/cache.report-last"
|
||||||
|
typeset _HC_REPORT_CACHE_LAST_FILE=""
|
||||||
|
typeset _HC_REPORT_CACHE_TODAY_FILE="${STATE_PERM_DIR}/cache.report-today"
|
||||||
|
typeset _USE_CACHE=0
|
||||||
|
typeset _CACHE_NOTE_BIT=""
|
||||||
|
|
||||||
# set archive log stash
|
# set archive log stash (never use cache files)
|
||||||
if (( ARG_HISTORY > 0 )) || [[ -n "${ARG_OLDER}" ]] || [[ -n "${ARG_NEWER}" ]]
|
if (( ARG_HISTORY > 0 )) || [[ -n "${ARG_OLDER}" ]] || [[ -n "${ARG_NEWER}" ]]
|
||||||
then
|
then
|
||||||
set +f # file globbing must be on
|
set +f # file globbing must be on
|
||||||
@ -148,10 +153,45 @@ then
|
|||||||
_HC_LAST_TIME=""
|
_HC_LAST_TIME=""
|
||||||
_HC_LAST_STC=0
|
_HC_LAST_STC=0
|
||||||
_HC_LAST_FAIL_ID="-"
|
_HC_LAST_FAIL_ID="-"
|
||||||
# find last event or block of events (same timestamp)
|
_USE_CACHE=0
|
||||||
# (but unfortunately this is only accurate to events within the SAME second!)
|
|
||||||
# shellcheck disable=SC2086
|
# check for cache usage
|
||||||
_HC_LAST_TIME="$(grep -h ${_HC_LAST} ${_LOG_STASH} 2>/dev/null | sort -n 2>/dev/null | cut -f1 -d${LOG_SEP} 2>/dev/null | uniq 2>/dev/null | tail -1 2>/dev/null)"
|
if (( ARG_HISTORY == 0 ))
|
||||||
|
then
|
||||||
|
case "${HC_REPORT_CACHE_LAST}" in
|
||||||
|
Yes|yes|YES)
|
||||||
|
_HC_REPORT_CACHE_LAST_FILE="${_HC_REPORT_CACHE_LAST_STUB}-${_HC_LAST}"
|
||||||
|
# check if cache file exists
|
||||||
|
if [[ -s "${_HC_REPORT_CACHE_LAST_FILE}" ]]
|
||||||
|
then
|
||||||
|
_LOG_STASH="${_HC_REPORT_CACHE_LAST_FILE}"
|
||||||
|
_USE_CACHE=1
|
||||||
|
(( ARG_DEBUG > 0 )) && debug "setting log stash to cache file at ${_HC_REPORT_CACHE_LAST_FILE}"
|
||||||
|
else
|
||||||
|
(( ARG_DEBUG > 0 )) && debug "HC_REPORT_CACHE_LAST is enabled but unable to find cache file at ${_HC_REPORT_CACHE_LAST_FILE}"
|
||||||
|
# reset log stash to current log
|
||||||
|
_LOG_STASH="${HC_LOG} ${_LOG_STASH}"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
# no caching: reset log stash to current log
|
||||||
|
(( ARG_DEBUG > 0 )) && debug "HC_REPORT_CACHE_LAST is disabled"
|
||||||
|
_LOG_STASH="${HC_LOG} ${_LOG_STASH}"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
|
# determine LAST_TIME from cache or log(s)
|
||||||
|
if (( ARG_HISTORY == 0 )) && (( _USE_CACHE > 1 ))
|
||||||
|
then
|
||||||
|
_HC_LAST_TIME="$(tail -n 1 ${_LOG_STASH} 2>/dev/null | cut -f1 -d${LOG_SEP} 2>/dev/null)"
|
||||||
|
else
|
||||||
|
# find last event or block of events (same timestamp)
|
||||||
|
# (but unfortunately this is only accurate to events within the SAME second!)
|
||||||
|
# shellcheck disable=SC2086
|
||||||
|
_HC_LAST_TIME="$(grep -h ${_HC_LAST} ${_LOG_STASH} 2>/dev/null | sort -n 2>/dev/null | cut -f1 -d${LOG_SEP} 2>/dev/null | uniq 2>/dev/null | tail -1 2>/dev/null)"
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ -z "${_HC_LAST_TIME}" ]]
|
if [[ -z "${_HC_LAST_TIME}" ]]
|
||||||
then
|
then
|
||||||
_HC_LAST_TIME="-"
|
_HC_LAST_TIME="-"
|
||||||
@ -181,12 +221,26 @@ then
|
|||||||
fi
|
fi
|
||||||
# report on findings
|
# report on findings
|
||||||
# shellcheck disable=SC1117
|
# shellcheck disable=SC1117
|
||||||
printf "| %-40s | %-20s | %-14s | %-4s\n" \
|
if (( _USE_CACHE > 0 ))
|
||||||
"${_HC_LAST}" "${_HC_LAST_TIME}" "${_HC_LAST_FAIL_ID}" "${_HC_LAST_STC}"
|
then
|
||||||
|
printf "| %-40s | %-20s | %-14s | %-4s (C)\n" \
|
||||||
|
"${_HC_LAST}" "${_HC_LAST_TIME}" "${_HC_LAST_FAIL_ID}" "${_HC_LAST_STC}"
|
||||||
|
else
|
||||||
|
printf "| %-40s | %-20s | %-14s | %-4s\n" \
|
||||||
|
"${_HC_LAST}" "${_HC_LAST_TIME}" "${_HC_LAST_FAIL_ID}" "${_HC_LAST_STC}"
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
# disclaimer
|
# spacer
|
||||||
print "NOTE: this report only shows the overall combined status of all events of each HC within exactly"
|
print
|
||||||
print " the *same* time stamp (seconds precise). It may therefore fail to report certain FAIL IDs."
|
# disclaimer & note(s)
|
||||||
|
if (( _USE_CACHE > 0 ))
|
||||||
|
then
|
||||||
|
print "NOTE: entries suffixed by (C) indicate results were retrieved from a cache file. If you wish to use "
|
||||||
|
print " the real log files then disable HC_REPORT_CACHE_LAST in ${CONFIG_FILE}"
|
||||||
|
fi
|
||||||
|
(( ARG_HISTORY == 0 )) && _CACHE_NOTE_BIT="for non-cached entries: "
|
||||||
|
print "NOTE: ${_CACHE_NOTE_BIT}this report only shows the overall combined status of all events of each HC"
|
||||||
|
print " within exactly the *same* time stamp (seconds precise). It may therefore fail to report certain FAIL IDs."
|
||||||
print " Use '--report' to get the exact list of failure events."
|
print " Use '--report' to get the exact list of failure events."
|
||||||
# other reports
|
# other reports
|
||||||
else
|
else
|
||||||
@ -198,7 +252,31 @@ else
|
|||||||
(( _IS_VALID_ID > 0 )) || die "invalid ID specified"
|
(( _IS_VALID_ID > 0 )) || die "invalid ID specified"
|
||||||
_ID_NEEDLE="${ARG_FAIL_ID}"
|
_ID_NEEDLE="${ARG_FAIL_ID}"
|
||||||
fi
|
fi
|
||||||
(( ARG_TODAY > 0 )) && _ID_NEEDLE="$(date '+%Y%m%d')" # refers to timestamp of HC FAIL_ID
|
# set today's needle and check cache usage
|
||||||
|
if (( ARG_TODAY > 0 ))
|
||||||
|
then
|
||||||
|
_ID_NEEDLE="$(date '+%Y%m%d')" # refers to timestamp of HC FAIL_ID
|
||||||
|
# do not use a cache file when --with-history
|
||||||
|
if (( ARG_HISTORY == 0 ))
|
||||||
|
then
|
||||||
|
case "${HC_REPORT_CACHE_TODAY}" in
|
||||||
|
Yes|yes|YES)
|
||||||
|
# check if cache file exists
|
||||||
|
if [[ -s "${_HC_REPORT_CACHE_TODAY_FILE}" ]]
|
||||||
|
then
|
||||||
|
_LOG_STASH="${_HC_REPORT_CACHE_TODAY_FILE}"
|
||||||
|
_USE_CACHE=1
|
||||||
|
(( ARG_DEBUG > 0 )) && debug "setting log stash to today's cache file at ${_HC_REPORT_CACHE_TODAY_FILE}"
|
||||||
|
else
|
||||||
|
(( ARG_DEBUG > 0 )) && debug "HC_REPORT_CACHE_TODAY is enabled but unable to find cache file at ${_HC_REPORT_CACHE_TODAY_FILE}"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
(( ARG_DEBUG > 0 )) && debug "HC_REPORT_CACHE_TODAY is disabled"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# reverse?
|
# reverse?
|
||||||
if (( ARG_REVERSE == 0 ))
|
if (( ARG_REVERSE == 0 ))
|
||||||
@ -262,9 +340,9 @@ else
|
|||||||
split (events[i], event, "|");
|
split (events[i], event, "|");
|
||||||
printf ("\n| %-20s | %-14s | %-40s | %-s", event[1], event[5], event[2], event[4]);
|
printf ("\n| %-20s | %-14s | %-40s | %-s", event[1], event[5], event[2], event[4]);
|
||||||
}
|
}
|
||||||
printf ("\n\nSUMMARY: %s failed HC event(s) found.\n", event_count);
|
printf ("\n\nSUMMARY: %s failed HC event(s) found.\n\n", event_count);
|
||||||
} else {
|
} else {
|
||||||
printf ("\nSUMMARY: 0 failed HC events found.\n");
|
printf ("\nSUMMARY: 0 failed HC events found.\n\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
' 2>/dev/null
|
' 2>/dev/null
|
||||||
@ -316,14 +394,23 @@ else
|
|||||||
# shellcheck disable=SC2183,SC1117
|
# shellcheck disable=SC2183,SC1117
|
||||||
printf "%80s\n" | tr ' ' -
|
printf "%80s\n" | tr ' ' -
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# add notes
|
||||||
|
# cache or not?
|
||||||
|
if (( _USE_CACHE > 0 ))
|
||||||
|
then
|
||||||
|
print "NOTE: results were retrieved from a cache file. If you wish to use the real log files then"
|
||||||
|
print " remove ${_HC_REPORT_CACHE_TODAY_FILE} and/or disable HC_REPORT_CACHE_TODAY in ${CONFIG_FILE}"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# general note: history or not?
|
# add general notes
|
||||||
|
# history or not?
|
||||||
if (( ARG_HISTORY > 0 ))
|
if (( ARG_HISTORY > 0 ))
|
||||||
then
|
then
|
||||||
print "NOTE: showing results with all history (archive) included (--with-history)"
|
print "NOTE: showing results with all history (archive) included (--with-history)"
|
||||||
else
|
else
|
||||||
print "NOTE: showing results only of current log entries (use --with-history to view all entries)"
|
print "NOTE: showing only results of current entries (use --with-history to view all entries)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# check consistency of log(s)
|
# check consistency of log(s)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user