From c3cc87609d2244067998f4f8cca8718c08ec41f1 Mon Sep 17 00:00:00 2001 From: patvdv Date: Sun, 10 Mar 2019 16:31:15 +0100 Subject: [PATCH] Added support for --log-healthy (AIX plugins) --- configs/etc/check_aix_file_age.conf.dist | 15 +++- configs/etc/check_aix_file_change.conf.dist | 5 ++ configs/etc/check_aix_root_crontab.conf.dist | 15 +++- configs/etc/check_aix_subsystems.conf.dist | 53 +++++++----- configs/etc/check_aix_sysbackup.conf.dist | 6 ++ sources/lib/platform/aix/check_aix_errpt.sh | 37 ++++++-- .../lib/platform/aix/check_aix_file_age.sh | 84 +++++++++++++------ .../lib/platform/aix/check_aix_file_change.sh | 68 +++++++++++---- .../lib/platform/aix/check_aix_fs_mounts.sh | 33 ++++++-- sources/lib/platform/aix/check_aix_lppchk.sh | 33 ++++++-- sources/lib/platform/aix/check_aix_paths.sh | 33 ++++++-- .../platform/aix/check_aix_root_crontab.sh | 61 ++++++++++++-- .../lib/platform/aix/check_aix_subsystems.sh | 48 ++++++++--- .../lib/platform/aix/check_aix_sysbackup.sh | 67 +++++++++++---- .../lib/platform/aix/check_aix_topasrec.sh | 33 ++++++-- 15 files changed, 449 insertions(+), 142 deletions(-) diff --git a/configs/etc/check_aix_file_age.conf.dist b/configs/etc/check_aix_file_age.conf.dist index a229f1f..5ff3ad2 100644 --- a/configs/etc/check_aix_file_age.conf.dist +++ b/configs/etc/check_aix_file_age.conf.dist @@ -6,9 +6,18 @@ # [default: indicates hardcoded script values if no value is defined here] #****************************************************************************** -# file (full path); maximum age in minutes since last change -/var/adm/ras/syslog.caa;600 -/var/log/ntp.log;30 +# specify whether to also log passed health checks +# (warning: this may rapidly grow the HC log) +# [default: no] +log_healthy="no" + +# specify file details +# Format: +# file:: +# Examples: +#file:/var/log/messages:60 +#file:/var/log/ntp.log:30 + #****************************************************************************** # End of FILE diff --git a/configs/etc/check_aix_file_change.conf.dist b/configs/etc/check_aix_file_change.conf.dist index e90b740..40f9756 100644 --- a/configs/etc/check_aix_file_change.conf.dist +++ b/configs/etc/check_aix_file_change.conf.dist @@ -6,6 +6,11 @@ # [default: indicates hardcoded script values if no value is defined here] #****************************************************************************** +# specify whether to also log passed health checks +# (warning: this may rapidly grow the HC log) +# [default: no] +log_healthy="no" + # name of the state file to use (will be relative to /var/opt/hc/state/persistent # [default: discovered.file_change] state_file=discovered.file_change diff --git a/configs/etc/check_aix_root_crontab.conf.dist b/configs/etc/check_aix_root_crontab.conf.dist index 5cb0ca9..c34de73 100644 --- a/configs/etc/check_aix_root_crontab.conf.dist +++ b/configs/etc/check_aix_root_crontab.conf.dist @@ -6,10 +6,19 @@ # [default: indicates hardcoded script values if no value is defined here] #****************************************************************************** +# specify whether to also log passed health checks +# (warning: this may rapidly grow the HC log) +# [default: no] +log_healthy="no" + # list of commands (or strings) that should appear in active cron entries -/opt/cfg2html/bin/cfg2html_aix.sh -/usr/local/bin/run_aix_system_backup.sh -/usr/bin/nmon +# Format: +# cron: +# Examples: +#cron:/opt/cfg2html/bin/cfg2html_aix.sh +#cron:/usr/local/bin/run_aix_system_backup.sh +#cron:/usr/bin/nmon + #****************************************************************************** # End of FILE diff --git a/configs/etc/check_aix_subsystems.conf.dist b/configs/etc/check_aix_subsystems.conf.dist index 9606027..5f94eef 100644 --- a/configs/etc/check_aix_subsystems.conf.dist +++ b/configs/etc/check_aix_subsystems.conf.dist @@ -6,29 +6,38 @@ # [default: indicates hardcoded script values if no value is defined here] #****************************************************************************** +# specify whether to also log passed health checks +# (warning: this may rapidly grow the HC log) +# [default: no] +log_healthy="no" + # list of required active subsystems -sendmail -syslogd -portmap -inetd -snmpd -hostmibd -snmpmibd -aixmibd -#nimsh -biod -rpc.statd -rpc.lockd -automountd -qdaemon -writesrv -sshd -xntpd -cimsys -ctrmc -IBM.ServiceRM -IBM.DRM -IBM.CSMAgentRM +# Format: +# subsys: +# Examples: +#subsys:sendmail +#subsys:syslogd +#subsys:portmap +#subsys:inetd +#subsys:snmpd +#subsys:hostmibd +#subsys:snmpmibd +#subsys:aixmibd +#subsys:nimsh +#subsys:biod +#subsys:rpc.statd +#subsys:rpc.lockd +#subsys:qdaemon +#subsys:automountd +#subsys:writesrv +#subsys:sshd +#subsys:xntpd +#subsys:cimsys +#subsys:ctrmc +#subsys:IBM.ServiceRM +#subsys:IBM.DRM +#subsys:IBM.CSMAgentRM + #****************************************************************************** # End of FILE diff --git a/configs/etc/check_aix_sysbackup.conf.dist b/configs/etc/check_aix_sysbackup.conf.dist index 2fdbb04..9b90870 100644 --- a/configs/etc/check_aix_sysbackup.conf.dist +++ b/configs/etc/check_aix_sysbackup.conf.dist @@ -6,6 +6,11 @@ # [default: indicates hardcoded script values if no value is defined here] #****************************************************************************** +# specify whether to also log passed health checks +# (warning: this may rapidly grow the HC log) +# [default: no] +log_healthy="no" + # full path to the location of mksysb images, the tool expects sub-directories # per host underneath this location backup_path=/export/images @@ -17,6 +22,7 @@ mksysb_log=mksysb.log # [default: 14] backup_age=14 + #****************************************************************************** # End of FILE #****************************************************************************** diff --git a/sources/lib/platform/aix/check_aix_errpt.sh b/sources/lib/platform/aix/check_aix_errpt.sh index aca1cd1..3309108 100644 --- a/sources/lib/platform/aix/check_aix_errpt.sh +++ b/sources/lib/platform/aix/check_aix_errpt.sh @@ -27,6 +27,7 @@ # @(#) 2013-06-24: big fix errpt last check time [Patrick Van der Veken] # @(#) 2018-10-28: fixed (linter) errors [Patrick Van der Veken] # @(#) 2019-01-24: arguments fix [Patrick Van der Veken] +# @(#) 2019-03-09: added support for --log-healthy [Patrick Van der Veken] # ----------------------------------------------------------------------------- # DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! #****************************************************************************** @@ -35,7 +36,7 @@ function check_aix_errpt { # ------------------------- CONFIGURATION starts here ------------------------- -typeset _VERSION="2019-01-24" # YYYY-MM-DD +typeset _VERSION="2019-03-09" # YYYY-MM-DD typeset _SUPPORTED_PLATFORMS="AIX" # uname -s match # ------------------------- CONFIGURATION ends here --------------------------- @@ -46,6 +47,7 @@ typeset _ARGS=$(data_comma2space "$*") typeset _ARG="" typeset _MSG="" typeset _STC=0 +typeset _LOG_HEALTHY=0 typeset _LAST_TIME_CHECK="" typeset _LAST_TIME_FILE="" typeset _LABEL="" @@ -61,6 +63,20 @@ do esac done +# log_healthy +(( ARG_LOG_HEALTHY > 0 )) && _LOG_HEALTHY=1 +if (( _LOG_HEALTHY > 0 )) +then + if (( ARG_LOG > 0 )) + then + log "logging/showing passed health checks" + else + log "showing passed health checks (but not logging)" + fi +else + log "not logging/showing passed health checks" +fi + # check for last known check date _LAST_TIME_FILE="${STATE_DIR}/$0.lasttime" if [[ -r ${_LAST_TIME_FILE} ]] @@ -79,8 +95,8 @@ then errpt -A >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG} else errpt -s "${_LAST_TIME_CHECK}" |\ - grep -v "${_LAST_TIME_CHECK}" | grep -v "_IDENTIFIER" |\ - awk '{ print $1}' | uniq | while read _LABEL + grep -v "${_LAST_TIME_CHECK}" 2>/dev/null | grep -v "_IDENTIFIER" 2>/dev/null |\ + awk '{ print $1}' 2>/dev/null | uniq 2>/dev/null | while read _LABEL do errpt -a -j ${_LABEL} -s "${_LAST_TIME_CHECK}" \ >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG} @@ -99,7 +115,7 @@ fi # update last known check date/time (potential race condition here, # but we can live it :-)) -_NEW_CHECK_TIME="$(errpt 2>/dev/null | head -n 2 | tail -n 1 | awk '{print $2}')" +_NEW_CHECK_TIME="$(errpt 2>/dev/null | head -n 2 2>/dev/null | tail -n 1 2>/dev/null | awk '{print $2}' 2>/dev/null)" # blank result indicates either no errpt entries or exist the time call failed if [[ -n "${_NEW_CHECK_TIME}" ]] then @@ -110,7 +126,10 @@ else fi # handle results -log_hc "$0" ${_STC} "${_MSG}" +if (( _LOG_HEALTHY > 0 || _STC > 0 )) +then + log_hc "$0" ${_STC} "${_MSG}" +fi return 0 } @@ -119,10 +138,10 @@ return 0 function _show_usage { cat <<- EOT -NAME : $1 -VERSION : $2 -CONFIG : $3 -PURPOSE : Checks AIX errpt for new error(s) +NAME : $1 +VERSION : $2 +PURPOSE : Checks AIX errpt for new error(s) +LOG HEALTHY : Supported EOT diff --git a/sources/lib/platform/aix/check_aix_file_age.sh b/sources/lib/platform/aix/check_aix_file_age.sh index 81ea23d..58a4e32 100644 --- a/sources/lib/platform/aix/check_aix_file_age.sh +++ b/sources/lib/platform/aix/check_aix_file_age.sh @@ -25,6 +25,8 @@ # @(#) 2013-05-27: initial version [Patrick Van der Veken] # @(#) 2018-10-28: fixed (linter) errors [Patrick Van der Veken] # @(#) 2019-01-24: arguments fix [Patrick Van der Veken] +# @(#) 2019-03-09: added code for data_is_numeric(), changed format of configuration +# @(#) file (; -> :) & added support for --log-healthy [Patrick Van der Veken] # ----------------------------------------------------------------------------- # DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! #****************************************************************************** @@ -34,7 +36,7 @@ function check_aix_file_age { # ------------------------- CONFIGURATION starts here ------------------------- typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" -typeset _VERSION="2019-01-24" # YYYY-MM-DD +typeset _VERSION="2019-03-09" # YYYY-MM-DD typeset _SUPPORTED_PLATFORMS="AIX" # uname -s match # ------------------------- CONFIGURATION ends here --------------------------- @@ -45,12 +47,14 @@ typeset _ARGS=$(data_comma2space "$*") typeset _ARG="" typeset _MSG="" typeset _STC=0 -typeset _ENTRY="" +typeset _CFG_HEALTHY="" +typeset _LOG_HEALTHY=0 typeset _AGE_CHECK="" typeset _FILE_PATH="" typeset _FILE_AGE="" typeset _FILE_NAME="" typeset _FILE_DIR="" +typeset _IS_OLD_STYLE=0 # handle arguments (originally comma-separated) for _ARG in ${_ARGS} @@ -69,14 +73,42 @@ then warn "unable to read configuration file at ${_CONFIG_FILE}" return 1 fi +_CFG_HEALTHY=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'log_healthy') +case "${_CFG_HEALTHY}" in + yes|YES|Yes) + _LOG_HEALTHY=1 + ;; + *) + # do not override hc_arg + (( _LOG_HEALTHY > 0 )) || _LOG_HEALTHY=0 + ;; +esac + +# check for old-style configuration file (non-prefixed stanzas) +_IS_OLD_STYLE=$(grep -c -E -e "^file:" ${_CONFIG_FILE} 2>/dev/null) +if (( _IS_OLD_STYLE == 0 )) +then + warn "no 'file:' stanza(s) found in ${_CONFIG_FILE}; possibly an old-style configuration?" + return 1 +fi + +# log_healthy +(( ARG_LOG_HEALTHY > 0 )) && _LOG_HEALTHY=1 +if (( _LOG_HEALTHY > 0 )) +then + if (( ARG_LOG > 0 )) + then + log "logging/showing passed health checks" + else + log "showing passed health checks (but not logging)" + fi +else + log "not logging/showing passed health checks" +fi # perform check -grep -v -E -e '^$' -e '^#' ${_CONFIG_FILE} 2>/dev/null | while read _ENTRY +grep -E -e "^file:" ${_CONFIG_FILE} 2>/dev/null | while IFS=":" read -r _ _FILE_PATH _FILE_AGE do - # field split - _FILE_PATH="$(print ${_ENTRY%%;*})" - _FILE_AGE="$(print ${_ENTRY##*;})" - # split file/dir _FILE_NAME="$(print ${_FILE_PATH##*/})" _FILE_DIR="$(print ${_FILE_PATH%/*})" @@ -87,16 +119,12 @@ do warn "missing values in configuration file at ${_CONFIG_FILE}" return 1 fi - case "${_FILE_AGE}" in - +([0-9])*(.)*([0-9])) - # numeric, OK - ;; - *) - # not numeric - warn "invalid file age value '${_FILE_AGE}' in configuration file at ${_CONFIG_FILE}" - return 1 - ;; - esac + data_is_numeric "${_FILE_AGE}" + if (( $? > 0 )) + then + warn "invalid file age value '${_FILE_AGE}' in configuration file at ${_CONFIG_FILE}" + return 1 + fi # perform check if [[ ! -r "${_FILE_PATH}" ]] @@ -119,8 +147,11 @@ do fi fi - # handle unit result - log_hc "$0" ${_STC} "${_MSG}" + # report result + if (( _LOG_HEALTHY > 0 || _STC > 0 )) + then + log_hc "$0" ${_STC} "${_MSG}" + fi _STC=0 done @@ -131,12 +162,15 @@ return 0 function _show_usage { cat <<- EOT -NAME : $1 -VERSION : $2 -CONFIG : $3 with: - ; -PURPOSE : Checks whether given files have been changed in the last n minutes - Requires {find -mmin}. +NAME : $1 +VERSION : $2 +CONFIG : $3 with parameters: + log_healthy= + and formatted stanzas: + file:: +PURPOSE : Checks whether given files have been changed in the last n minutes + Requires {find -mmin}. +LOG HEALTHY : Supported EOT diff --git a/sources/lib/platform/aix/check_aix_file_change.sh b/sources/lib/platform/aix/check_aix_file_change.sh index 0c9f129..defd768 100644 --- a/sources/lib/platform/aix/check_aix_file_change.sh +++ b/sources/lib/platform/aix/check_aix_file_change.sh @@ -27,6 +27,7 @@ # @(#) 2018-10-28: fixed (linter) errors [Patrick Van der Veken] # @(#) 2018-11-18: do not trap on signal 0 [Patrick Van der Veken] # @(#) 2019-01-24: arguments fix [Patrick Van der Veken] +# @(#) 2019-03-09: added support for --log-healthy [Patrick Van der Veken] # ----------------------------------------------------------------------------- # DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! #****************************************************************************** @@ -36,7 +37,7 @@ function check_aix_file_change { # ------------------------- CONFIGURATION starts here ------------------------- typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" -typeset _VERSION="2019-01-24" # YYYY-MM-DD +typeset _VERSION="2019-03-09" # YYYY-MM-DD typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match # ------------------------- CONFIGURATION ends here --------------------------- @@ -47,6 +48,8 @@ typeset _ARGS=$(data_comma2space "$*") typeset _ARG="" typeset _MSG="" typeset _STC=0 +typeset _CFG_HEALTHY="" +typeset _LOG_HEALTHY=0 typeset _DO_META_CHECK=0 typeset _CFG_STATE_FILE="" typeset _STATE_FILE="" @@ -111,6 +114,30 @@ case "${_DO_META_CHECK}" in log "check for meta characters is enabled" ;; esac +_CFG_HEALTHY=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'log_healthy') +case "${_CFG_HEALTHY}" in + yes|YES|Yes) + _LOG_HEALTHY=1 + ;; + *) + # do not override hc_arg + (( _LOG_HEALTHY > 0 )) || _LOG_HEALTHY=0 + ;; +esac + +# log_healthy +(( ARG_LOG_HEALTHY > 0 )) && _LOG_HEALTHY=1 +if (( _LOG_HEALTHY > 0 )) +then + if (( ARG_LOG > 0 )) + then + log "logging/showing passed health checks" + else + log "showing passed health checks (but not logging)" + fi +else + log "not logging/showing passed health checks" +fi # check for checksum tools _OPENSSL_BIN="$(which openssl 2>>${HC_STDERR_LOG})" @@ -293,7 +320,7 @@ do fi # bounce failures back and jump to next file - if (( _STC > 0 )) + if (( _LOG_HEALTHY > 0 || _STC > 0 )) then log_hc "$0" ${_STC} "${_MSG}" continue @@ -319,7 +346,11 @@ do printf "%s|%s|%s\n" "${_FILE_TO_CHECK}" "${_FILE_TYPE}" "${_FILE_CKSUM}" >>${_TMP2_FILE} # report with curr/exp values - log_hc "$0" ${_STC} "${_MSG}" "${_FILE_CKSUM}" "${_STATE_FILE_CKSUM}" + if (( _LOG_HEALTHY > 0 )) + then + log_hc "$0" ${_STC} "${_MSG}" "${_FILE_CKSUM}" "${_STATE_FILE_CKSUM}" + continue + fi done <${_TMP1_FILE} # update state file (also if TMP2_FILE is empty) @@ -348,23 +379,26 @@ return 0 function _show_usage { cat <<- EOT -NAME : $1 -VERSION : $2 -CONFIG : $3 with formatted stanzas: - incl: - excl: -PURPOSE : a KISS file integrity checker (like AIDE). Supports includes and excludes - of files and directories (automatically expanded). Excludes have a higher - priority than includes. Integrity checks will only be performed on files. - Will detect changed, new & deleted files (but not when deleted files - occur in an expanded directory tree). If you wish to detect deleted files: - use only direct file references in the configuration file. Uses by preference - openssl for hash calculation, with cksum as fall-back). - Updated and deleted files will cause a HC failure, new files will not. - CAVEAT EMPTOR: use only to check a relatively small number of files. +NAME : $1 +VERSION : $2 +CONFIG : $3 with parameters: + log_healthy= + and formatted stanzas: + incl: + excl: +PURPOSE : a KISS file integrity checker (like AIDE). Supports includes and excludes + of files and directories (automatically expanded). Excludes have a higher + priority than includes. Integrity checks will only be performed on files. + Will detect changed, new & deleted files (but not when deleted files + occur in an expanded directory tree). If you wish to detect deleted files: + use only direct file references in the configuration file. Uses by preference + openssl for hash calculation, with cksum as fall-back). + Updated and deleted files will cause a HC failure, new files will not. + CAVEAT EMPTOR: use only to check a relatively small number of files. Processing a big number of files is likely to take ages and probably will cause the plugin to time out (see HC_TIME_OUT). YMMV. +LOG HEALTHY : Supported EOT diff --git a/sources/lib/platform/aix/check_aix_fs_mounts.sh b/sources/lib/platform/aix/check_aix_fs_mounts.sh index 379f054..336a41c 100644 --- a/sources/lib/platform/aix/check_aix_fs_mounts.sh +++ b/sources/lib/platform/aix/check_aix_fs_mounts.sh @@ -24,6 +24,7 @@ # @(#) HISTORY: # @(#) 2013-05-15: initial version [Patrick Van der Veken] # @(#) 2019-01-24: arguments fix [Patrick Van der Veken] +# @(#) 2019-03-09: added support for --log-healthy [Patrick Van der Veken] # ----------------------------------------------------------------------------- # DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! #****************************************************************************** @@ -32,7 +33,7 @@ function check_aix_fs_mounts { # ------------------------- CONFIGURATION starts here ------------------------- -typeset _VERSION="2019-01-24" # YYYY-MM-DD +typeset _VERSION="2019-03-09" # YYYY-MM-DD typeset _SUPPORTED_PLATFORMS="AIX" # uname -s match # ------------------------- CONFIGURATION ends here --------------------------- @@ -43,6 +44,7 @@ typeset _ARGS=$(data_comma2space "$*") typeset _ARG="" typeset _MSG="" typeset _STC=0 +typeset _LOG_HEALTHY=0 typeset _FS="" typeset _FS_COUNT="" @@ -56,6 +58,20 @@ do esac done +# log_healthy +(( ARG_LOG_HEALTHY > 0 )) && _LOG_HEALTHY=1 +if (( _LOG_HEALTHY > 0 )) +then + if (( ARG_LOG > 0 )) + then + log "logging/showing passed health checks" + else + log "showing passed health checks (but not logging)" + fi +else + log "not logging/showing passed health checks" +fi + # collect data (mount & lsfs output may be safely merged) mount >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG} (( $? == 0)) || return $? @@ -83,8 +99,11 @@ do ;; esac - # handle unit result - log_hc "$0" ${_STC} "${_MSG}" + # report result + if (( _LOG_HEALTHY > 0 || _STC > 0 )) + then + log_hc "$0" ${_STC} "${_MSG}" + fi _STC=0 done @@ -95,10 +114,10 @@ return 0 function _show_usage { cat <<- EOT -NAME : $1 -VERSION : $2 -CONFIG : $3 -PURPOSE : Checks whether file systems are mounted or not {lsfs/mount} +NAME : $1 +VERSION : $2 +PURPOSE : Checks whether file systems are mounted or not {lsfs/mount} +LOG HEALTHY : Supported EOT diff --git a/sources/lib/platform/aix/check_aix_lppchk.sh b/sources/lib/platform/aix/check_aix_lppchk.sh index 2fba6b8..45223fd 100644 --- a/sources/lib/platform/aix/check_aix_lppchk.sh +++ b/sources/lib/platform/aix/check_aix_lppchk.sh @@ -24,6 +24,7 @@ # @(#) HISTORY: # @(#) 2013-05-17: initial version [Patrick Van der Veken] # @(#) 2019-01-24: arguments fix [Patrick Van der Veken] +# @(#) 2019-03-09: added support for --log-healthy [Patrick Van der Veken] # ----------------------------------------------------------------------------- # DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! #****************************************************************************** @@ -32,7 +33,7 @@ function check_aix_lppchk { # ------------------------- CONFIGURATION starts here ------------------------- -typeset _VERSION="2019-01-24" # YYYY-MM-DD +typeset _VERSION="2019-03-09" # YYYY-MM-DD typeset _SUPPORTED_PLATFORMS="AIX" # uname -s match # ------------------------- CONFIGURATION ends here --------------------------- @@ -43,6 +44,7 @@ typeset _ARGS=$(data_comma2space "$*") typeset _ARG="" typeset _MSG="" typeset _STC=0 +typeset _LOG_HEALTHY=0 # handle arguments (originally comma-separated) for _ARG in ${_ARGS} @@ -54,6 +56,20 @@ do esac done +# log_healthy +(( ARG_LOG_HEALTHY > 0 )) && _LOG_HEALTHY=1 +if (( _LOG_HEALTHY > 0 )) +then + if (( ARG_LOG > 0 )) + then + log "logging/showing passed health checks" + else + log "showing passed health checks (but not logging)" + fi +else + log "not logging/showing passed health checks" +fi + # collect data lppchk -v -m1 >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG} (( $? == 0)) || return $? @@ -67,8 +83,11 @@ else _MSG="lppchk passed without errors" fi -# handle results -log_hc "$0" ${_STC} "${_MSG}" +# report result +if (( _LOG_HEALTHY > 0 || _STC > 0 )) +then + log_hc "$0" ${_STC} "${_MSG}" +fi return 0 } @@ -77,10 +96,10 @@ return 0 function _show_usage { cat <<- EOT -NAME : $1 -VERSION : $2 -CONFIG : $3 -PURPOSE : Run {lppchk -v} +NAME : $1 +VERSION : $2 +PURPOSE : Run {lppchk -v} +LOG HEALTHY : Supported EOT diff --git a/sources/lib/platform/aix/check_aix_paths.sh b/sources/lib/platform/aix/check_aix_paths.sh index 0bd7c61..241eb58 100644 --- a/sources/lib/platform/aix/check_aix_paths.sh +++ b/sources/lib/platform/aix/check_aix_paths.sh @@ -24,6 +24,7 @@ # @(#) HISTORY: # @(#) 2013-05-07: initial version [Patrick Van der Veken] # @(#) 2019-01-24: arguments fix [Patrick Van der Veken] +# @(#) 2019-03-09: added support for --log-healthy [Patrick Van der Veken] # ----------------------------------------------------------------------------- # DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! #****************************************************************************** @@ -32,7 +33,7 @@ function check_aix_paths { # ------------------------- CONFIGURATION starts here ------------------------- -typeset _VERSION="2019-01-24" # YYYY-MM-DD +typeset _VERSION="2019-03-09" # YYYY-MM-DD typeset _SUPPORTED_PLATFORMS="AIX" # uname -s match # ------------------------- CONFIGURATION ends here --------------------------- @@ -43,6 +44,7 @@ typeset _ARGS=$(data_comma2space "$*") typeset _ARG="" typeset _MSG="" typeset _STC=0 +typeset _LOG_HEALTHY=0 typeset _PATH="" # handle arguments (originally comma-separated) @@ -55,6 +57,20 @@ do esac done +# log_healthy +(( ARG_LOG_HEALTHY > 0 )) && _LOG_HEALTHY=1 +if (( _LOG_HEALTHY > 0 )) +then + if (( ARG_LOG > 0 )) + then + log "logging/showing passed health checks" + else + log "showing passed health checks (but not logging)" + fi +else + log "not logging/showing passed health checks" +fi + # collect data lspath >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG} (( $? == 0)) || return $? @@ -71,8 +87,11 @@ case ${_PATH} in ;; esac -# handle results -log_hc "$0" ${_STC} "${_MSG}" +# report result +if (( _LOG_HEALTHY > 0 || _STC > 0 )) +then + log_hc "$0" ${_STC} "${_MSG}" +fi return 0 } @@ -81,10 +100,10 @@ return 0 function _show_usage { cat <<- EOT -NAME : $1 -VERSION : $2 -CONFIG : $3 -PURPOSE : Checks whether any hardware paths are missing {lspath} +NAME : $1 +VERSION : $2 +PURPOSE : Checks whether any hardware paths are missing {lspath} +LOG HEALTHY : Supported EOT diff --git a/sources/lib/platform/aix/check_aix_root_crontab.sh b/sources/lib/platform/aix/check_aix_root_crontab.sh index a47ed5e..fffa3d8 100644 --- a/sources/lib/platform/aix/check_aix_root_crontab.sh +++ b/sources/lib/platform/aix/check_aix_root_crontab.sh @@ -24,6 +24,8 @@ # @(#) HISTORY: # @(#) 2013-09-19: initial version [Patrick Van der Veken] # @(#) 2019-01-24: arguments fix [Patrick Van der Veken] +# @(#) 2019-03-09: changed format of stanzas in configuration file & +# @(#) added support for --log-healthy [Patrick Van der Veken] # ----------------------------------------------------------------------------- # DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! #****************************************************************************** @@ -33,7 +35,7 @@ function check_aix_root_crontab { # ------------------------- CONFIGURATION starts here ------------------------- typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" -typeset _VERSION="2019-01-24" # YYYY-MM-DD +typeset _VERSION="2019-03-09" # YYYY-MM-DD typeset _SUPPORTED_PLATFORMS="AIX" # uname -s match # ------------------------- CONFIGURATION ends here --------------------------- @@ -44,8 +46,11 @@ typeset _ARGS=$(data_comma2space "$*") typeset _ARG="" typeset _MSG="" typeset _STC=0 +typeset _CFG_HEALTHY="" +typeset _LOG_HEALTHY=0 typeset _CRON_ENTRY="" typeset _CRON_MATCH=0 +typeset _IS_OLD_STYLE=0 # handle arguments (originally comma-separated) for _ARG in ${_ARGS} @@ -57,7 +62,6 @@ do esac done - # handle configuration file [[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}" if [[ ! -r ${_CONFIG_FILE} ]] @@ -65,12 +69,44 @@ then warn "unable to read configuration file at ${_CONFIG_FILE}" return 1 fi +_CFG_HEALTHY=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'log_healthy') +case "${_CFG_HEALTHY}" in + yes|YES|Yes) + _LOG_HEALTHY=1 + ;; + *) + # do not override hc_arg + (( _LOG_HEALTHY > 0 )) || _LOG_HEALTHY=0 + ;; +esac + +# check for old-style configuration file (non-prefixed stanzas) +_IS_OLD_STYLE=$(grep -c -E -e "^cron:" ${_CONFIG_FILE} 2>/dev/null) +if (( _IS_OLD_STYLE == 0 )) +then + warn "no 'cron:' stanza(s) found in ${_CONFIG_FILE}; possibly an old-style configuration?" + return 1 +fi + +# log_healthy +(( ARG_LOG_HEALTHY > 0 )) && _LOG_HEALTHY=1 +if (( _LOG_HEALTHY > 0 )) +then + if (( ARG_LOG > 0 )) + then + log "logging/showing passed health checks" + else + log "showing passed health checks (but not logging)" + fi +else + log "not logging/showing passed health checks" +fi # collect data crontab -l >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG} # perform check -grep -v -E -e '^$' -e '^#' ${_CONFIG_FILE} 2>/dev/null | while read _CRON_ENTRY +grep -E -e "^cron:" ${_CONFIG_FILE} 2>/dev/null | while IFS=":" read -r _ _CRON_ENTRY do _CRON_MATCH=$(grep -v '^#' ${HC_STDOUT_LOG} 2>/dev/null |\ grep -c -E -e "${_CRON_ENTRY}") @@ -87,8 +123,11 @@ do ;; esac - # handle unit result - log_hc "$0" ${_STC} "${_MSG}" + # report result + if (( _LOG_HEALTHY > 0 || _STC > 0 )) + then + log_hc "$0" ${_STC} "${_MSG}" + fi _STC=0 done @@ -99,10 +138,14 @@ return 0 function _show_usage { cat <<- EOT -NAME : $1 -VERSION : $2 -CONFIG : $3 -PURPOSE : Checks the content of the 'root' user crontab for required entries +NAME : $1 +VERSION : $2 +CONFIG : $3 with parameters: + log_healthy= + and formatted stanzas: + cron: +PURPOSE : Checks the content of the 'root' user crontab for required entries +LOG HEALTHY : Supported EOT diff --git a/sources/lib/platform/aix/check_aix_subsystems.sh b/sources/lib/platform/aix/check_aix_subsystems.sh index 341659e..c92f2da 100644 --- a/sources/lib/platform/aix/check_aix_subsystems.sh +++ b/sources/lib/platform/aix/check_aix_subsystems.sh @@ -24,6 +24,8 @@ # @(#) HISTORY: # @(#) 2013-05-07: initial version [Patrick Van der Veken] # @(#) 2019-01-24: arguments fix [Patrick Van der Veken] +# @(#) 2019-03-09: changed format of stanzas in configuration file & +# @(#) added support for --log-healthy [Patrick Van der Veken] # ----------------------------------------------------------------------------- # DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! #****************************************************************************** @@ -33,7 +35,7 @@ function check_aix_subsystems { # ------------------------- CONFIGURATION starts here ------------------------- typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" -typeset _VERSION="2019-01-24" # YYYY-MM-DD +typeset _VERSION="2019-03-09" # YYYY-MM-DD typeset _SUPPORTED_PLATFORMS="AIX" # uname -s match # ------------------------- CONFIGURATION ends here --------------------------- @@ -44,7 +46,10 @@ typeset _ARGS=$(data_comma2space "$*") typeset _ARG="" typeset _MSG="" typeset _STC=0 +typeset _CFG_HEALTHY="" +typeset _LOG_HEALTHY=0 typeset _STATUS="" +typeset _IS_OLD_STYLE=0 # handle arguments (originally comma-separated) for _ARG in ${_ARGS} @@ -64,13 +69,31 @@ then warn "unable to read configuration file at ${_CONFIG_FILE}" return 1 fi +_CFG_HEALTHY=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'log_healthy') +case "${_CFG_HEALTHY}" in + yes|YES|Yes) + _LOG_HEALTHY=1 + ;; + *) + # do not override hc_arg + (( _LOG_HEALTHY > 0 )) || _LOG_HEALTHY=0 + ;; +esac + +# check for old-style configuration file (non-prefixed stanzas) +_IS_OLD_STYLE=$(grep -c -E -e "^subsys:" ${_CONFIG_FILE} 2>/dev/null) +if (( _IS_OLD_STYLE == 0 )) +then + warn "no 'subsys:' stanza(s) found in ${_CONFIG_FILE}; possibly an old-style configuration?" + return 1 +fi # collect data lssrc -a >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG} (( $? == 0)) || return $? # perform check -grep -v -E -e '^$' -e '^#' ${_CONFIG_FILE} 2>/dev/null | while read _SUBSYS +grep -E -e "^subsys:" ${_CONFIG_FILE} 2>/dev/null | while IFS=":" read -r _ _SUBSYS do _STATUS="$(grep -E -e ${_SUBSYS} ${HC_STDOUT_LOG} 2>/dev/null)" case "${_STATUS}" in @@ -86,8 +109,11 @@ do ;; esac - # handle unit result - log_hc "$0" ${_STC} "${_MSG}" + # report result + if (( _LOG_HEALTHY > 0 || _STC > 0 )) + then + log_hc "$0" ${_STC} "${_MSG}" + fi _STC=0 done @@ -98,12 +124,14 @@ return 0 function _show_usage { cat <<- EOT -NAME : $1 -VERSION : $2 -CONFIG : $3 with: - subsys1 - subsys2 -PURPOSE : Checks whether subsystem(s) are active/operative {lssrc} +NAME : $1 +VERSION : $2 +CONFIG : $3 with parameters: + log_healthy= + and formatted stanzas: + subsys: +PURPOSE : Checks whether subsystem(s) are active/operative {lssrc} +LOG HEALTHY : Supported EOT diff --git a/sources/lib/platform/aix/check_aix_sysbackup.sh b/sources/lib/platform/aix/check_aix_sysbackup.sh index d6c89b7..f60dee0 100644 --- a/sources/lib/platform/aix/check_aix_sysbackup.sh +++ b/sources/lib/platform/aix/check_aix_sysbackup.sh @@ -24,6 +24,7 @@ # @(#) HISTORY: # @(#) 2013-05-28: initial version [Patrick Van der Veken] # @(#) 2019-01-24: arguments fix [Patrick Van der Veken] +# @(#) 2019-03-09: added support for --log-healthy [Patrick Van der Veken] # ----------------------------------------------------------------------------- # DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! #****************************************************************************** @@ -35,7 +36,7 @@ function check_aix_sysbackup typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" # mksysb identifier prefix of error code(s) typeset _MKSYSB_NEEDLE="^0512" -typeset _VERSION="2019-01-24" # YYYY-MM-DD +typeset _VERSION="2019-03-09" # YYYY-MM-DD typeset _SUPPORTED_PLATFORMS="AIX" # uname -s match # ------------------------- CONFIGURATION ends here --------------------------- @@ -46,6 +47,8 @@ typeset _ARGS=$(data_comma2space "$*") typeset _ARG="" typeset _MSG="" typeset _STC=0 +typeset _CFG_HEALTHY="" +typeset _LOG_HEALTHY=0 typeset _BACKUP_PATH="" typeset _BACKUP_HOST="" typeset _BACKUP_LOG="" @@ -99,9 +102,33 @@ case "${_BACKUP_AGE}" in _BACKUP_AGE=14 ;; esac +_CFG_HEALTHY=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'log_healthy') +case "${_CFG_HEALTHY}" in + yes|YES|Yes) + _LOG_HEALTHY=1 + ;; + *) + # do not override hc_arg + (( _LOG_HEALTHY > 0 )) || _LOG_HEALTHY=0 + ;; +esac + +# log_healthy +(( ARG_LOG_HEALTHY > 0 )) && _LOG_HEALTHY=1 +if (( _LOG_HEALTHY > 0 )) +then + if (( ARG_LOG > 0 )) + then + log "logging/showing passed health checks" + else + log "showing passed health checks (but not logging)" + fi +else + log "not logging/showing passed health checks" +fi # perform state check on mksysb log files -ls -1 ${_BACKUP_PATH} | while read _BACKUP_HOST +ls -1 ${_BACKUP_PATH} 2>>${HC_STDERR_LOG} | while read -r _BACKUP_HOST do _BACKUP_LOG="${_BACKUP_PATH}/${_BACKUP_HOST}/curr/${_MKSYSB_LOG}" if [[ -r "${_BACKUP_LOG}" ]] @@ -134,13 +161,16 @@ do continue fi - # handle unit result - log_hc "$0" ${_STC} "${_MSG}" + # report result + if (( _LOG_HEALTHY > 0 || _STC > 0 )) + then + log_hc "$0" ${_STC} "${_MSG}" + fi _STC=0 done # perform age check on mksysb log files -ls -1 ${_BACKUP_PATH} | while read _BACKUP_HOST +ls -1 ${_BACKUP_PATH} 2>>${HC_STDERR_LOG} | while read -r _BACKUP_HOST do _BACKUP_LOG="${_BACKUP_PATH}/${_BACKUP_HOST}/curr/${_MKSYSB_LOG}" if [[ -r "${_BACKUP_LOG}" ]] @@ -163,8 +193,11 @@ do continue fi - # handle unit result - log_hc "$0" ${_STC} "${_MSG}" + # report result + if (( _LOG_HEALTHY > 0 || _STC > 0 )) + then + log_hc "$0" ${_STC} "${_MSG}" + fi _STC=0 done @@ -175,15 +208,17 @@ return 0 function _show_usage { cat <<- EOT -NAME : $1 -VERSION : $2 -CONFIG : $3 with: - backup_path= - mksysb_log= - backup_age= -PURPOSE : Checks the state of saved mksysb client backups (should typically be - run only on the NIM master or server that is acting as mksysb repo, - do NOT run on a typical client LPAR) +NAME : $1 +VERSION : $2 +CONFIG : $3 with parameters: + log_healthy= + backup_path= + mksysb_log= + backup_age= +PURPOSE : Checks the state of saved mksysb client backups (should typically be + run only on the NIM master or server that is acting as mksysb repo, + do NOT run on a typical client LPAR) +LOG HEALTHY : Supported EOT diff --git a/sources/lib/platform/aix/check_aix_topasrec.sh b/sources/lib/platform/aix/check_aix_topasrec.sh index 95d29b0..3894cc6 100644 --- a/sources/lib/platform/aix/check_aix_topasrec.sh +++ b/sources/lib/platform/aix/check_aix_topasrec.sh @@ -25,6 +25,7 @@ # @(#) 2013-05-07: initial version [Patrick Van der Veken] # @(#) 2013-08-16: comparison fix [Patrick Van der Veken] # @(#) 2019-01-24: arguments fix [Patrick Van der Veken] +# @(#) 2019-03-09: added support for --log-healthy [Patrick Van der Veken] # ----------------------------------------------------------------------------- # DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! #****************************************************************************** @@ -33,7 +34,7 @@ function check_aix_topasrec { # ------------------------- CONFIGURATION starts here ------------------------- -typeset _VERSION="2019-01-24" # YYYY-MM-DD +typeset _VERSION="2019-03-09" # YYYY-MM-DD typeset _SUPPORTED_PLATFORMS="AIX" # uname -s match # ------------------------- CONFIGURATION ends here --------------------------- @@ -44,6 +45,7 @@ typeset _ARGS=$(data_comma2space "$*") typeset _ARG="" typeset _MSG="" typeset _STC=0 +typeset _LOG_HEALTHY=0 typeset _TOPAS=0 typeset _NMON=0 @@ -57,6 +59,20 @@ do esac done +# log_healthy +(( ARG_LOG_HEALTHY > 0 )) && _LOG_HEALTHY=1 +if (( _LOG_HEALTHY > 0 )) +then + if (( ARG_LOG > 0 )) + then + log "logging/showing passed health checks" + else + log "showing passed health checks (but not logging)" + fi +else + log "not logging/showing passed health checks" +fi + # collect data topasrec -l >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG} (( $? == 0 )) || return $? @@ -70,8 +86,11 @@ then _STC=1 fi -# handle results -log_hc "$0" ${_STC} "${_MSG}" +# report result +if (( _LOG_HEALTHY > 0 || _STC > 0 )) +then + log_hc "$0" ${_STC} "${_MSG}" +fi return 0 } @@ -80,10 +99,10 @@ return 0 function _show_usage { cat <<- EOT -NAME : $1 -VERSION : $2 -CONFIG : $3 -PURPOSE : Checks on the active topasrec/nmon processes (only 1 should be running) +NAME : $1 +VERSION : $2 +PURPOSE : Checks on the active topasrec/nmon processes (only 1 should be running) +LOG HEALTHY : Supported EOT