From ef266c72e6c97d36bc762e6aa240d5116b01fd90 Mon Sep 17 00:00:00 2001 From: Patrick Van der Veken Date: Wed, 13 Feb 2019 14:02:46 +0100 Subject: [PATCH] * Added feature for mass archiving (--archive-all) * Smaller fixes in HP-UX plugins --- sources/bin/check_health.sh | 53 ++++++++++++++++--- .../platform/hp-ux/check_hpux_cron_status.sh | 7 ++- .../hp-ux/check_hpux_syslogd_status.sh | 5 +- 3 files changed, 54 insertions(+), 11 deletions(-) diff --git a/sources/bin/check_health.sh b/sources/bin/check_health.sh index 4e56937..9779e82 100644 --- a/sources/bin/check_health.sh +++ b/sources/bin/check_health.sh @@ -38,7 +38,7 @@ # ------------------------- CONFIGURATION starts here ------------------------- # define the version (YYYY-MM-DD) -typeset -r SCRIPT_VERSION="2019-02-10" +typeset -r SCRIPT_VERSION="2019-02-13" # location of parent directory containing KSH functions/HC plugins typeset -r FPATH_PARENT="/opt/hc/lib" # location of custom HC configuration files @@ -86,6 +86,11 @@ typeset EXIT_CODE=0 typeset FDIR="" typeset FFILE="" typeset FPATH="" +typeset HC_ARCHIVE="" +typeset HC_CHECK="" +typeset HC_DISABLE="" +typeset HC_ENABLE="" +typeset HC_RUN="" typeset HC_FAIL_ID="" # shellcheck disable=SC2034 typeset HC_FILE_LINE="" @@ -370,14 +375,14 @@ if (( ARG_CHECK_HOST == 0 )) then if (( ARG_ACTION < 6 || ARG_ACTION == 10 )) && [[ -z "${ARG_HC}" ]] then - print -u2 "ERROR: you specify a value for parameter '--hc'" + print -u2 "ERROR: you must specify a value for the '--hc' parameter" exit 1 fi if (( ARG_ACTION == 5 )) || [[ -n "${ARG_HC_ARGS}" ]] then case "${ARG_HC}" in *,*) - print -u2 "ERROR: you can only specify a value for '--hc' in combination with '--show'" + print -u2 "ERROR: you can only specify a single value for '--hc' in combination with '--show'" exit 1 ;; esac @@ -386,7 +391,7 @@ then then case "${ARG_HC}" in *,*) - print -u2 "ERROR: you can only specify a value for '--hc' in combination with '--archive'" + print -u2 "ERROR: you can only specify a single value for '--hc' in combination with '--archive'" exit 1 ;; esac @@ -534,7 +539,7 @@ cat << EOT Execute/report simple health checks (HC) on UNIX hosts. Syntax: ${SCRIPT_DIR}/${SCRIPT_NAME} [--help] | [--help-terse] | [--version] | - [--list=] | [--list-core] | [--fix-symlinks] | [--show-stats] | (--disable-all | enable-all) | [--fix-logs [--with-history]] | + [--list=] | [--list-core] | [--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] [--notify=] [--mail-to=] [--sms-to= --sms-provider=] @@ -547,7 +552,8 @@ then cat << EOT Parameters: ---archive : move events from the HC log file into archive log files +--archive : move events from the HC log file into archive log files (one HC) +--archive-all : move events for all HCs from the HC log file into archive log files --check : display HC state. --check-host : execute all configured HC(s) (see check_host.conf) --config-file : custom configuration file for a HC (may only be specified when executing a single HC plugin) @@ -726,6 +732,15 @@ do fi ARG_LOCK=1 ;; + -archive-all|--archive-all) + if (( ARG_ACTION > 0 )) + then + print -u2 "ERROR: you cannot request two actions at the same time" + exit 1 + else + ARG_ACTION=13 + fi + ;; -check|--check) ARG_ACTION=1 ;; @@ -1351,9 +1366,9 @@ case ${ARG_ACTION} in 9) # list HC plugins list_hc "" "${ARG_LIST}" ;; - 10) # archive log entries + 10) # archive current log entries for a HC exists_hc "${ARG_HC}" && die "cannot find HC: ${ARG_HC}" - log "archiving log entries for ${ARG_HC}..." + log "archiving current log entries for ${ARG_HC}..." archive_hc "${ARG_HC}" ARCHIVE_RC=$? case ${ARCHIVE_RC} in @@ -1389,6 +1404,28 @@ case ${ARG_ACTION} in ;; esac ;; + 13) # archive current log entries for all HCs + list_hc "list" | while read -r HC_ARCHIVE + do + # check for HC (function) + exists_hc "${HC_ARCHIVE}" && die "cannot find HC: ${HC_ARCHIVE}" + log "archiving current log entries for HC: ${HC_ARCHIVE}" + archive_hc "${HC_ARCHIVE}" + ARCHIVE_RC=$? + case ${ARCHIVE_RC} in + 0) + log "no archiving needed for ${HC_ARCHIVE}" + ;; + 1) + log "successfully archived log entries for ${HC_ARCHIVE}" + ;; + 2) + log "failed to archive log entries for ${HC_ARCHIVE} [RC=${ARCHIVE_RC}]" + EXIT_CODE=1 + ;; + esac + done + ;; esac # finish up work diff --git a/sources/lib/platform/hp-ux/check_hpux_cron_status.sh b/sources/lib/platform/hp-ux/check_hpux_cron_status.sh index 24b487a..8358171 100644 --- a/sources/lib/platform/hp-ux/check_hpux_cron_status.sh +++ b/sources/lib/platform/hp-ux/check_hpux_cron_status.sh @@ -22,7 +22,8 @@ # REQUIRES: data_comma2space(), init_hc(), log_hc() # # @(#) HISTORY: -# @(#) 2018-02-08: initial version [Patrick Van der Veken] +# @(#) 2018-02-08: initial version [Patrick Van der Veken]ยต +# @(#) 2018-02-13: fix to avoid log check if cron is not active [Patrick Van der Veken] # ----------------------------------------------------------------------------- # DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! #****************************************************************************** @@ -33,7 +34,7 @@ function check_hpux_cron_status # ------------------------- CONFIGURATION starts here ------------------------- typeset _CRON_LOG_FILE="/var/adm/cron/log" typeset _WAIT_TIME=10 -typeset _VERSION="2019-02-08" # YYYY-MM-DD +typeset _VERSION="2019-02-13" # YYYY-MM-DD typeset _SUPPORTED_PLATFORMS="HP-UX" # uname -s match # ------------------------- CONFIGURATION ends here --------------------------- @@ -92,6 +93,8 @@ esac if (( _LOG_HEALTHY > 0 || _STC > 0 )) then log_hc "$0" ${_STC} "${_MSG}" + # return if cron is not running + (( _STC > 0 )) && return 1 fi # ---- log state ---- diff --git a/sources/lib/platform/hp-ux/check_hpux_syslogd_status.sh b/sources/lib/platform/hp-ux/check_hpux_syslogd_status.sh index afdcb4c..53f3d09 100644 --- a/sources/lib/platform/hp-ux/check_hpux_syslogd_status.sh +++ b/sources/lib/platform/hp-ux/check_hpux_syslogd_status.sh @@ -23,6 +23,7 @@ # # @(#) HISTORY: # @(#) 2018-02-08: initial version [Patrick Van der Veken] +# @(#) 2018-02-13: fix to avoid log check if syslogd is not active [Patrick Van der Veken] # ----------------------------------------------------------------------------- # DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! #****************************************************************************** @@ -33,7 +34,7 @@ function check_hpux_syslogd_status # ------------------------- CONFIGURATION starts here ------------------------- typeset _SYSLOGD_PID_FILE="/var/run/syslog.pid" typeset _SYSLOGD_LOG_FILE="/var/adm/syslog.log" -typeset _VERSION="2019-02-08" # YYYY-MM-DD +typeset _VERSION="2019-02-13" # YYYY-MM-DD typeset _SUPPORTED_PLATFORMS="HP-UX" # uname -s match # ------------------------- CONFIGURATION ends here --------------------------- @@ -113,6 +114,8 @@ esac if (( _LOG_HEALTHY > 0 || _STC > 0 )) then log_hc "$0" ${_STC} "${_MSG}" + # return if syslogd is not running + (( _STC > 0 )) && return 1 fi # ---- log state ----