* Changed processing of messages file from ARRAY -> VAR (since ksh88 has max array size of 1023)

* Renamed $SEP to $LOG_SEP, added $MSG_SEP
* Fix in --check--host routine: avoid duplicate calls to display_init() for HC that fail in execution
* Fix for check_hpux_drd_status plugin
* Other fixes
This commit is contained in:
Patrick Van der Veken 2018-05-15 21:39:57 +02:00
parent 1ab55020d0
commit 18f69fa8ad
13 changed files with 219 additions and 204 deletions

View File

@ -37,7 +37,7 @@
# ------------------------- CONFIGURATION starts here ------------------------- # ------------------------- CONFIGURATION starts here -------------------------
# define the version (YYYY-MM-DD) # define the version (YYYY-MM-DD)
typeset -r SCRIPT_VERSION="2018-05-12" typeset -r SCRIPT_VERSION="2018-05-14"
# 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
@ -58,7 +58,8 @@ typeset -r HOST_NAME="$(hostname)"
typeset -r OS_NAME="$(uname -s)" typeset -r OS_NAME="$(uname -s)"
typeset -r LOCK_DIR="${TMP_DIR}/.${SCRIPT_NAME}.lock" typeset -r LOCK_DIR="${TMP_DIR}/.${SCRIPT_NAME}.lock"
typeset -r HC_MSG_FILE="${TMP_DIR}/.${SCRIPT_NAME}.hc.msg.$$" # plugin messages files typeset -r HC_MSG_FILE="${TMP_DIR}/.${SCRIPT_NAME}.hc.msg.$$" # plugin messages files
typeset -r SEP="|" typeset -r LOG_SEP="|"
typeset -r MSG_SEP="%%"
typeset -r LOG_DIR="/var/opt/hc" typeset -r LOG_DIR="/var/opt/hc"
typeset -r LOG_FILE="${LOG_DIR}/${SCRIPT_NAME}.log" typeset -r LOG_FILE="${LOG_DIR}/${SCRIPT_NAME}.log"
typeset -r ARCHIVE_DIR="${LOG_DIR}/archive" typeset -r ARCHIVE_DIR="${LOG_DIR}/archive"
@ -81,6 +82,7 @@ typeset HC_FILE_LINE=""
typeset HC_NOW="" typeset HC_NOW=""
typeset HC_TIME_OUT=60 typeset HC_TIME_OUT=60
typeset HC_MIN_TIME_OUT=30 typeset HC_MIN_TIME_OUT=30
typeset HC_MSG_VAR=""
typeset HC_STDOUT_LOG="" typeset HC_STDOUT_LOG=""
typeset HC_STDERR_LOG="" typeset HC_STDERR_LOG=""
typeset LINUX_DISTRO="" typeset LINUX_DISTRO=""
@ -1039,7 +1041,7 @@ case ${ARG_ACTION} in
RUN_TIME_OUT=$(grep -i -E -e "^hc:${HC_RUN}:" ${HOST_CONFIG_FILE} 2>/dev/null | cut -f5 -d':') RUN_TIME_OUT=$(grep -i -E -e "^hc:${HC_RUN}:" ${HOST_CONFIG_FILE} 2>/dev/null | cut -f5 -d':')
if [[ -n "${RUN_TIME_OUT}" ]] if [[ -n "${RUN_TIME_OUT}" ]]
then then
(( RUN_TIME_OUT > HC_TIME_OUT )) && HC_TIME_OUT=${RUN_TIME_OUT} (( RUN_TIME_OUT > HC_TIME_OUT )) && HC_TIME_OUT=${RUN_TIME_OUT}
else else
# reset for next HC # reset for next HC
HC_TIME_OUT=60 HC_TIME_OUT=60
@ -1063,6 +1065,7 @@ case ${ARG_ACTION} in
else else
warn "failed to execute HC: ${HC_RUN} [RC=${RUN_RC}]" warn "failed to execute HC: ${HC_RUN} [RC=${RUN_RC}]"
fi fi
continue
fi fi
else else
# set trap on SIGUSR1 # set trap on SIGUSR1
@ -1097,6 +1100,7 @@ case ${ARG_ACTION} in
else else
warn "failed to execute HC: ${HC_RUN} [RC=${RUN_RC}]" warn "failed to execute HC: ${HC_RUN} [RC=${RUN_RC}]"
fi fi
continue
else else
if (( CHILD_ERROR == 0 )) if (( CHILD_ERROR == 0 ))
then then
@ -1109,6 +1113,7 @@ case ${ARG_ACTION} in
else else
warn "failed to execute HC as background process" warn "failed to execute HC as background process"
fi fi
continue
fi fi
fi fi
fi fi

View File

@ -30,9 +30,9 @@
function display_csv function display_csv
{ {
# ------------------------- CONFIGURATION starts here ------------------------- # ------------------------- CONFIGURATION starts here -------------------------
typeset _VERSION="2017-05-06" # YYYY-MM-DD typeset _VERSION="2018-05-14" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="AIX,HP-UX,Linux" # uname -s match typeset _SUPPORTED_PLATFORMS="AIX,HP-UX,Linux" # uname -s match
typeset _SEP=";" typeset _DISPLAY_SEP=";"
# ------------------------- CONFIGURATION ends here --------------------------- # ------------------------- CONFIGURATION ends here ---------------------------
# set defaults # set defaults
@ -42,51 +42,42 @@ init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _DISPLAY_HC="$1" typeset _DISPLAY_HC="$1"
typeset _DISPLAY_FAIL_ID="$2" typeset _DISPLAY_FAIL_ID="$2"
set -A _DISPLAY_MSG_STC typeset _HC_MSG_ENTRY=""
set -A _DISPLAY_MSG_TIME typeset _DISPLAY_MSG_STC=""
set -A _DISPLAY_MSG_TEXT typeset _DISPLAY_MSG_TIME=""
set -A _DISPLAY_MSG_CUR_VAL typeset _DISPLAY_MSG_TEXT=""
set -A _DISPLAY_MSG_EXP_VAL typeset _DISPLAY_MSG_CUR_VAL=""
typeset _I=0 typeset _DISPLAY_MSG_EXP_VAL=""
typeset _MAX_I=0
typeset _ID_BIT="" typeset _ID_BIT=""
# read HC_MSG_FILE into an arrays # parse $HC_MSG_VAR
# note: this is less efficient but provides more flexibility for future extensions if [[ -n "${HC_MSG_VAR}" ]]
# max array size: 1023 in ksh88f, plugins spawning more than >1K messages are crazy :-)
while read HC_MSG_ENTRY
do
_DISPLAY_MSG_STC[${_I}]=$(print "${HC_MSG_ENTRY}" | awk -F "%%" '{ print $1'})
_DISPLAY_MSG_TIME[${_I}]=$(print "${HC_MSG_ENTRY}" | awk -F "%%" '{ print $2'})
_DISPLAY_MSG_TEXT[${_I}]=$(print "${HC_MSG_ENTRY}" | awk -F "%%" '{ print $3'})
_DISPLAY_MSG_CUR_VAL[${_I}]=$(print "${HC_MSG_ENTRY}" | awk -F "%%" '{ print $4'})
_DISPLAY_MSG_EXP_VAL[${_I}]=$(print "${HC_MSG_ENTRY}" | awk -F "%%" '{ print $5'})
_I=$(( _I + 1 ))
done <${HC_MSG_FILE} 2>/dev/null
# display HC results
_MAX_I=${#_DISPLAY_MSG_STC[*]}
_I=0
if (( _MAX_I > 0 ))
then then
printf "%s${_SEP}%s${_SEP}%s${_SEP}%s${_SEP}%s${_SEP}%s\n" "Health Check" "STC" "Message" "FAIL ID" \ printf "%s${_DISPLAY_SEP}%s${_DISPLAY_SEP}%s${_DISPLAY_SEP}%s${_DISPLAY_SEP}%s${_DISPLAY_SEP}%s\n" "Health Check" "STC" "Message" "FAIL ID" \
"Current Value" "Expected Value" "Current Value" "Expected Value"
while (( _I < _MAX_I ))
print "${HC_MSG_VAR}" | while read _HC_MSG_ENTRY
do do
if (( _DISPLAY_MSG_STC[${_I}] != 0 )) # split fields (awk is required for multi-char delimiter)
_DISPLAY_MSG_STC=$(print "${_HC_MSG_ENTRY}" | awk -F "%%" '{ print $1'})
_DISPLAY_MSG_TIME=$(print "${_HC_MSG_ENTRY}" | awk -F "%%" '{ print $2'})
_DISPLAY_MSG_TEXT=$(print "${_HC_MSG_ENTRY}" | awk -F "%%" '{ print $3'})
_DISPLAY_MSG_CUR_VAL=$(print "${_HC_MSG_ENTRY}" | awk -F "%%" '{ print $4'})
_DISPLAY_MSG_EXP_VAL=$(print "${_HC_MSG_ENTRY}" | awk -F "%%" '{ print $5'})
if (( _DISPLAY_MSG_STC > 0 ))
then then
_ID_BIT="${_DISPLAY_FAIL_ID}" _ID_BIT="${_DISPLAY_FAIL_ID}"
else else
_ID_BIT="" _ID_BIT=""
fi fi
printf "%s${_SEP}%s${_SEP}%s${_SEP}%s${_SEP}%s${_SEP}%s\n" \ printf "%s${_DISPLAY_SEP}%s${_DISPLAY_SEP}%s${_DISPLAY_SEP}%s${_DISPLAY_SEP}%s${_DISPLAY_SEP}%s\n" \
"${_DISPLAY_HC}" \ "${_DISPLAY_HC}" \
"${_DISPLAY_MSG_STC[${_I}]}" \ "${_DISPLAY_MSG_STC}" \
"${_ID_BIT}" \ "${_ID_BIT}" \
"${_DISPLAY_MSG_TEXT[${_I}]}" \ "${_DISPLAY_MSG_TEXT}" \
"${_DISPLAY_MSG_CUR_VAL[${_I}]}" \ "${_DISPLAY_MSG_CUR_VAL}" \
"${_DISPLAY_MSG_EXP_VAL[${_I}]}" "${_DISPLAY_MSG_EXP_VAL}"
_I=$(( _I + 1 ))
done done
else else
ARG_LOG=0 ARG_VERBOSE=1 log "INFO: no HC results to display" ARG_LOG=0 ARG_VERBOSE=1 log "INFO: no HC results to display"

View File

@ -31,7 +31,7 @@
function display_init function display_init
{ {
# ------------------------- CONFIGURATION starts here ------------------------- # ------------------------- CONFIGURATION starts here -------------------------
typeset _VERSION="2017-06-29" # YYYY-MM-DD typeset _VERSION="2018-05-14" # 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 ---------------------------
@ -51,7 +51,7 @@ typeset -R8 _DISPLAY_CODE=""
typeset _DISPLAY_ID="" typeset _DISPLAY_ID=""
# check for terminal support (no ((...)) here) # check for terminal support (no ((...)) here)
if [[ $(tput colors 2>/dev/null) -gt 0 ]] if (( $(tput colors 2>/dev/null) > 0 ))
then then
typeset _RED=$(tput setaf 1) typeset _RED=$(tput setaf 1)
typeset _GREEN=$(tput setaf 2) typeset _GREEN=$(tput setaf 2)
@ -74,7 +74,7 @@ else
typeset _NORMAL="" typeset _NORMAL=""
fi fi
# read HC_MSG_FILE for STC # parse $HC_MSG_VAR
if [[ -n "${_DISPLAY_MSG_CODE}" ]] if [[ -n "${_DISPLAY_MSG_CODE}" ]]
then then
case "${_DISPLAY_MSG_CODE}" in case "${_DISPLAY_MSG_CODE}" in
@ -93,13 +93,14 @@ then
esac esac
_DISPLAY_CODE="${_DISPLAY_MSG_CODE}" _DISPLAY_CODE="${_DISPLAY_MSG_CODE}"
else else
if [[ -s ${HC_MSG_FILE} ]] if [[ -n "${HC_MSG_VAR}" ]]
then then
while read HC_MSG_ENTRY print "${HC_MSG_VAR}" | while read _HC_MSG_ENTRY
do do
_DISPLAY_MSG_STC=$(( $(print "${HC_MSG_ENTRY}" | awk -F "%%" '{ print $1'}) + _DISPLAY_MSG_STC )) # determine _DISPLAY_MSG_STC (sum of all STCs)
done <${HC_MSG_FILE} 2>/dev/null _DISPLAY_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)
done
# display HC results # display HC results
if (( _DISPLAY_MSG_STC == 0 )) if (( _DISPLAY_MSG_STC == 0 ))
then then

View File

@ -30,7 +30,7 @@
function display_terse function display_terse
{ {
# ------------------------- CONFIGURATION starts here ------------------------- # ------------------------- CONFIGURATION starts here -------------------------
typeset _VERSION="2017-05-06" # YYYY-MM-DD typeset _VERSION="2018-05-14" # 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 ---------------------------
@ -41,33 +41,29 @@ init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _DISPLAY_HC="$1" typeset _DISPLAY_HC="$1"
typeset _DISPLAY_FAIL_ID="$2" typeset _DISPLAY_FAIL_ID="$2"
set -A _DISPLAY_MSG_STC typeset _HC_MSG_ENTRY=""
set -A _DISPLAY_MSG_TIME typeset _DISPLAY_MSG_STC=""
set -A _DISPLAY_MSG_TEXT typeset _DISPLAY_MSG_TIME=""
typeset _I=0 typeset _DISPLAY_MSG_TEXT=""
typeset _MAX_I=0 typeset _DISPLAY_MSG_CUR_VAL=""
typeset _DISPLAY_MSG_EXP_VAL=""
typeset _ID_BIT="" typeset _ID_BIT=""
# read HC_MSG_FILE into an arrays # parse $HC_MSG_VAR
# note: this is less efficient but provides more flexibility for future extensions if [[ -n "${HC_MSG_VAR}" ]]
# max array size: 1023 in ksh88f, plugins spawning more than >1K messages are crazy :-)
while read HC_MSG_ENTRY
do
_DISPLAY_MSG_STC[${_I}]=$(print "${HC_MSG_ENTRY}" | awk -F "%%" '{ print $1'})
_DISPLAY_MSG_TIME[${_I}]=$(print "${HC_MSG_ENTRY}" | awk -F "%%" '{ print $2'})
_DISPLAY_MSG_TEXT[${_I}]=$(print "${HC_MSG_ENTRY}" | awk -F "%%" '{ print $3'})
_I=$(( _I + 1 ))
done <${HC_MSG_FILE} 2>/dev/null
# display HC results
_MAX_I=${#_DISPLAY_MSG_STC[*]}
_I=0
if (( _MAX_I > 0 ))
then then
printf "%-30s\t%s\t%-16s\t%s\n" "HC" "STC" "FAIL ID" "Message" printf "%-30s\t%s\t%-16s\t%s\n" "HC" "STC" "FAIL ID" "Message"
while (( _I < _MAX_I ))
print "${HC_MSG_VAR}" | while read _HC_MSG_ENTRY
do do
if (( _DISPLAY_MSG_STC[${_I}] != 0 )) # split fields (awk is required for multi-char delimiter)
_DISPLAY_MSG_STC=$(print "${_HC_MSG_ENTRY}" | awk -F "%%" '{ print $1'})
_DISPLAY_MSG_TIME=$(print "${_HC_MSG_ENTRY}" | awk -F "%%" '{ print $2'})
_DISPLAY_MSG_TEXT=$(print "${_HC_MSG_ENTRY}" | awk -F "%%" '{ print $3'})
_DISPLAY_MSG_CUR_VAL=$(print "${_HC_MSG_ENTRY}" | awk -F "%%" '{ print $4'})
_DISPLAY_MSG_EXP_VAL=$(print "${_HC_MSG_ENTRY}" | awk -F "%%" '{ print $5'})
if (( _DISPLAY_MSG_STC > 0 ))
then then
_ID_BIT="${_DISPLAY_FAIL_ID}" _ID_BIT="${_DISPLAY_FAIL_ID}"
else else
@ -75,11 +71,10 @@ then
fi fi
printf "%-30s\t%s\t%-16s\t%s\n" \ printf "%-30s\t%s\t%-16s\t%s\n" \
"${_DISPLAY_HC}" \ "${_DISPLAY_HC}" \
"${_DISPLAY_MSG_STC[${_I}]}" \ "${_DISPLAY_MSG_STC}" \
"${_ID_BIT}" \ "${_ID_BIT}" \
"${_DISPLAY_MSG_TEXT[${_I}]}" "${_DISPLAY_MSG_TEXT}"
_I=$(( _I + 1 )) done
done
else else
ARG_LOG=0 ARG_VERBOSE=1 log "INFO: no HC results to display" ARG_LOG=0 ARG_VERBOSE=1 log "INFO: no HC results to display"
fi fi

View File

@ -32,7 +32,7 @@
function display_zenoss function display_zenoss
{ {
# ------------------------- CONFIGURATION starts here ------------------------- # ------------------------- CONFIGURATION starts here -------------------------
typeset _VERSION="2017-12-20" # YYYY-MM-DD typeset _VERSION="2018-05-14" # 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 ---------------------------
@ -43,53 +43,43 @@ init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _DISPLAY_HC="$1" typeset _DISPLAY_HC="$1"
typeset _DISPLAY_FAIL_ID="$2" typeset _DISPLAY_FAIL_ID="$2"
set -A _DISPLAY_MSG_STC typeset _HC_MSG_ENTRY=""
set -A _DISPLAY_MSG_TIME typeset _DISPLAY_MSG_STC=""
set -A _DISPLAY_MSG_TEXT typeset _DISPLAY_MSG_TIME=""
set -A _DISPLAY_MSG_CUR_VAL typeset _DISPLAY_MSG_TEXT=""
set -A _DISPLAY_MSG_EXP_VAL typeset _DISPLAY_MSG_CUR_VAL=""
typeset _I=0 typeset _DISPLAY_MSG_EXP_VAL=""
typeset _MAX_I=0
# read HC_MSG_FILE into an arrays # parse $HC_MSG_VAR
# note: this is less efficient but provides more flexibility for future extensions if [[ -n "${HC_MSG_VAR}" ]]
# max array size: 1023 in ksh88f, plugins spawning more than >1K messages are crazy :-)
while read HC_MSG_ENTRY
do
_DISPLAY_MSG_STC[${_I}]=$(print "${HC_MSG_ENTRY}" | awk -F "%%" '{ print $1'})
_DISPLAY_MSG_TIME[${_I}]=$(print "${HC_MSG_ENTRY}" | awk -F "%%" '{ print $2'})
_DISPLAY_MSG_TEXT[${_I}]=$(print "${HC_MSG_ENTRY}" | awk -F "%%" '{ print $3'})
_DISPLAY_MSG_CUR_VAL[${_I}]=$(print "${HC_MSG_ENTRY}" | awk -F "%%" '{ print $4'})
_DISPLAY_MSG_EXP_VAL[${_I}]=$(print "${HC_MSG_ENTRY}" | awk -F "%%" '{ print $5'})
_I=$(( _I + 1 ))
done <${HC_MSG_FILE} 2>/dev/null
# display HC results
_MAX_I=${#_DISPLAY_MSG_STC[*]}
_I=0
if (( _MAX_I > 0 ))
then then
while (( _I < _MAX_I )) print "${HC_MSG_VAR}" | while read _HC_MSG_ENTRY
do do
if (( _DISPLAY_MSG_STC[${_I}] != 0 )) # split fields (awk is required for multi-char delimiter)
_DISPLAY_MSG_STC=$(print "${_HC_MSG_ENTRY}" | awk -F "%%" '{ print $1'})
_DISPLAY_MSG_TIME=$(print "${_HC_MSG_ENTRY}" | awk -F "%%" '{ print $2'})
_DISPLAY_MSG_TEXT=$(print "${_HC_MSG_ENTRY}" | awk -F "%%" '{ print $3'})
_DISPLAY_MSG_CUR_VAL=$(print "${_HC_MSG_ENTRY}" | awk -F "%%" '{ print $4'})
_DISPLAY_MSG_EXP_VAL=$(print "${_HC_MSG_ENTRY}" | awk -F "%%" '{ print $5'})
if (( _DISPLAY_MSG_STC > 0 ))
then then
printf "NOK|data1=%s data2=%s data3=%s data4=\"%s\" data5=%s data6=%s\n" \ printf "NOK|data1=%s data2=%s data3=%s data4=\"%s\" data5=%s data6=%s\n" \
"${_DISPLAY_HC}" \ "${_DISPLAY_HC}" \
"${_DISPLAY_MSG_STC[${_I}]}" \ "${_DISPLAY_MSG_STC}" \
"${_DISPLAY_FAIL_ID}" \ "${_DISPLAY_FAIL_ID}" \
"${_DISPLAY_MSG_TEXT[${_I}]}" \ "${_DISPLAY_MSG_TEXT}" \
"${_DISPLAY_MSG_CUR_VAL[${_I}]}" \ "${_DISPLAY_MSG_CUR_VAL}" \
"${_DISPLAY_MSG_EXP_VAL[${_I}]}" "${_DISPLAY_MSG_EXP_VAL}"
else else
printf "OK|data1=%s data2=%s data3=%s data4=\"%s\" data5=%s data6=%s\n" \ printf "OK|data1=%s data2=%s data3=%s data4=\"%s\" data5=%s data6=%s\n" \
"${_DISPLAY_HC}" \ "${_DISPLAY_HC}" \
"${_DISPLAY_MSG_STC[${_I}]}" \ "${_DISPLAY_MSG_STC}" \
"0" \ "0" \
"${_DISPLAY_MSG_TEXT[${_I}]}" \ "${_DISPLAY_MSG_TEXT}" \
"${_DISPLAY_MSG_CUR_VAL[${_I}]}" \ "${_DISPLAY_MSG_CUR_VAL}" \
"${_DISPLAY_MSG_EXP_VAL[${_I}]}" "${_DISPLAY_MSG_EXP_VAL}"
fi fi
_I=$(( _I + 1 ))
done done
fi fi

View File

@ -45,12 +45,12 @@ typeset TMP2_FILE="${TMP_DIR}/.$0.tmp2.archive.$$"
trap "rm -f ${TMP1_FILE} ${TMP2_FILE} ${SAVE_LOG_FILE} >/dev/null 2>&1; return 1" 1 2 3 15 trap "rm -f ${TMP1_FILE} ${TMP2_FILE} ${SAVE_LOG_FILE} >/dev/null 2>&1; return 1" 1 2 3 15
# isolate messages from HC, find unique %Y-%m combinations # isolate messages from HC, find unique %Y-%m combinations
grep ".*${SEP}${HC_NAME}${SEP}" ${HC_LOG} 2>/dev/null |\ grep ".*${LOG_SEP}${HC_NAME}${LOG_SEP}" ${HC_LOG} 2>/dev/null |\
cut -f1 -d"${SEP}" | cut -f1 -d' ' | cut -f1-2 -d'-' | sort -u |\ cut -f1 -d"${LOG_SEP}" | cut -f1 -d' ' | cut -f1-2 -d'-' | sort -u |\
while read YEAR_MONTH while read YEAR_MONTH
do do
# find all messages for that YEAR-MONTH combination # find all messages for that YEAR-MONTH combination
grep "${YEAR_MONTH}.*${SEP}${HC_NAME}${SEP}" ${HC_LOG} >${TMP1_FILE} grep "${YEAR_MONTH}.*${LOG_SEP}${HC_NAME}${LOG_SEP}" ${HC_LOG} >${TMP1_FILE}
LOG_COUNT=$(wc -l ${TMP1_FILE} | cut -f1 -d' ') LOG_COUNT=$(wc -l ${TMP1_FILE} | cut -f1 -d' ')
log "# of entries in ${YEAR_MONTH} to archive: ${LOG_COUNT}" log "# of entries in ${YEAR_MONTH} to archive: ${LOG_COUNT}"
@ -583,43 +583,39 @@ 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_NAME="$1"
typeset HC_STC_COUNT=0
typeset I=0
typeset MAX_I=0
typeset HC_STDOUT_LOG_SHORT="" typeset HC_STDOUT_LOG_SHORT=""
typeset HC_STDERR_LOG_SHORT="" typeset HC_STDERR_LOG_SHORT=""
typeset HC_MSG_ENTRY=""
typeset HC_STC_RC=0 typeset HC_STC_RC=0
set -A HC_MSG_STC typeset ONE_MSG_STC=""
set -A HC_MSG_TIME typeset ONE_MSG_TIME=""
set -A HC_MSG_TEXT typeset ONE_MSG_TEXT=""
set -A HC_MSG_CUR_VAL # optional typeset ONE_MSG_CUR_VAL=""
set -A HC_MSG_EXP_VAL # optional typeset ONE_MSG_EXP_VAL=""
typeset ALL_MSG_STC=0
if [[ -s ${HC_MSG_FILE} ]] if [[ -s ${HC_MSG_FILE} ]]
then then
# load messages file into memory
# do not use array: max 1024 items in ksh88; regular variable is only 32-bit memory limited
HC_MSG_VAR=$(<${HC_MSG_FILE})
# DEBUG: dump TMP file # DEBUG: dump TMP file
if (( ARG_DEBUG != 0 )) if (( ARG_DEBUG != 0 ))
then then
debug "begin dumping plugin messages file (${HC_MSG_FILE})" debug "begin dumping plugin messages file (${HC_MSG_FILE})"
cat ${HC_MSG_FILE} 2>/dev/null print "${HC_MSG_VAR}"
debug "end dumping plugin messages file (${HC_MSG_FILE})" debug "end dumping plugin messages file (${HC_MSG_FILE})"
fi fi
# process message file into arrays # determine ALL_MSG_STC (sum of all STCs)
while read HC_MSG_ENTRY 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)
do (( ARG_DEBUG != 0 )) && debug "HC all STC: ${ALL_MSG_STC}"
HC_MSG_STC[${I}]=$(print "${HC_MSG_ENTRY}" | awk -F "%%" '{ print $1'}) $(data_is_numeric ${ALL_MSG_STC}) || die "HC all STC computes to a non-numeric value"
HC_MSG_TIME[${I}]=$(print "${HC_MSG_ENTRY}" | awk -F "%%" '{ print $2'})
HC_MSG_TEXT[${I}]=$(print "${HC_MSG_ENTRY}" | awk -F "%%" '{ print $3'})
HC_MSG_CUR_VAL[${I}]=$(print "${HC_MSG_ENTRY}" | awk -F "%%" '{ print $4'})
HC_MSG_EXP_VAL[${I}]=$(print "${HC_MSG_ENTRY}" | awk -F "%%" '{ print $5'})
I=$(( I + 1 ))
done <${HC_MSG_FILE} 2>/dev/null
fi fi
# display routines # display routines
if (( ${#HC_MSG_STC[*]} > 0 )) if [[ -n "${HC_MSG_VAR}" ]]
then then
if (( DO_DISPLAY_CSV == 1 )) if (( DO_DISPLAY_CSV == 1 ))
then then
@ -742,49 +738,56 @@ then
# default STDOUT # default STDOUT
if (( ARG_VERBOSE != 0 )) if (( ARG_VERBOSE != 0 ))
then then
I=0 print "${HC_MSG_VAR}" | while read HC_MSG_ENTRY
MAX_I=${#HC_MSG_STC[*]}
while (( I < MAX_I ))
do do
printf "%s" "INFO: ${HC_NAME} [STC=${HC_MSG_STC[${I}]}]: ${HC_MSG_TEXT[${I}]}" # split fields (awk is required for mult-char delimiter)
if (( HC_MSG_STC[${I}] != 0 )) ONE_MSG_STC=$(print "${HC_MSG_ENTRY}" | awk -F "${MSG_SEP}" '{ print $1'})
ONE_MSG_TIME=$(print "${HC_MSG_ENTRY}" | awk -F "${MSG_SEP}" '{ print $2'})
ONE_MSG_TEXT=$(print "${HC_MSG_ENTRY}" | awk -F "${MSG_SEP}" '{ print $3'})
ONE_MSG_CUR_VAL=$(print "${HC_MSG_ENTRY}" | awk -F "${MSG_SEP}" '{ print $4'})
ONE_MSG_EXP_VAL=$(print "${HC_MSG_ENTRY}" | awk -F "${MSG_SEP}" '{ print $5'})
printf "%s" "INFO: ${HC_NAME} [STC=${ONE_MSG_STC}]: ${ONE_MSG_TEXT}"
if (( ONE_MSG_STC != 0 ))
then then
printf " %s\n" "[FAIL_ID=${HC_FAIL_ID}]" printf " %s\n" "[FAIL_ID=${HC_FAIL_ID}]"
else else
printf "\n" printf "\n"
fi fi
I=$(( I + 1 ))
done done
fi fi
fi fi
fi fi
# log & notify routines # log & notify routines
if (( ARG_LOG != 0 )) && (( ${#HC_MSG_STC[*]} > 0 )) if (( ARG_LOG != 0 )) && (( ALL_MSG_STC > 0 ))
then then
# log routine (combined STC=0 or <>0) # log routine (combined STC=0 or <>0)
I=0 print "${HC_MSG_VAR}" | while read HC_MSG_ENTRY
MAX_I=${#HC_MSG_STC[*]}
while (( I < MAX_I ))
do do
printf "%s${SEP}%s${SEP}%s${SEP}%s${SEP}" \ # split fields (awk is required for multi-char delimiter)
"${HC_MSG_TIME[${I}]}" \ ONE_MSG_STC=$(print "${HC_MSG_ENTRY}" | awk -F "${MSG_SEP}" '{ print $1'})
ONE_MSG_TIME=$(print "${HC_MSG_ENTRY}" | awk -F "${MSG_SEP}" '{ print $2'})
ONE_MSG_TEXT=$(print "${HC_MSG_ENTRY}" | awk -F "${MSG_SEP}" '{ print $3'})
ONE_MSG_CUR_VAL=$(print "${HC_MSG_ENTRY}" | awk -F "${MSG_SEP}" '{ print $4'})
ONE_MSG_EXP_VAL=$(print "${HC_MSG_ENTRY}" | awk -F "${MSG_SEP}" '{ print $5'})
printf "%s${LOG_SEP}%s${LOG_SEP}%s${LOG_SEP}%s${LOG_SEP}" \
"${ONE_MSG_TIME}" \
"${HC_NAME}" \ "${HC_NAME}" \
${HC_MSG_STC[${I}]} \ ${ONE_MSG_STC} \
"${HC_MSG_TEXT[${I}]}" >>${HC_LOG} "${ONE_MSG_TEXT}" >>${HC_LOG}
if (( HC_MSG_STC[${I}] != 0 )) if (( ONE_MSG_STC > 0 ))
then then
printf "%s${SEP}\n" "${HC_FAIL_ID}" >>${HC_LOG} printf "%s${LOG_SEP}\n" "${HC_FAIL_ID}" >>${HC_LOG}
HC_STC_RC=$(( HC_STC_RC + 1 )) HC_STC_RC=$(( HC_STC_RC + 1 ))
else else
printf "\n" >>${HC_LOG} printf "\n" >>${HC_LOG}
fi fi
HC_STC_COUNT=$(( HC_STC_COUNT + HC_MSG_STC[${I}] ))
I=$(( I + 1 ))
done done
# notify routine (combined STC > 0) # notify routine (combined STC > 0)
if (( HC_STC_COUNT > 0 )) if (( ALL_MSG_STC > 0 ))
then then
# save stdout/stderr to HC events location # save stdout/stderr to HC events location
if [[ -s ${HC_STDOUT_LOG} ]] || [[ -s ${HC_STDERR_LOG} ]] if [[ -s ${HC_STDOUT_LOG} ]] || [[ -s ${HC_STDERR_LOG} ]]
@ -853,7 +856,7 @@ else
return ${HC_STC_RC} return ${HC_STC_RC}
fi fi
} }
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# @(#) FUNCTION: handle_timeout() # @(#) FUNCTION: handle_timeout()
# DOES: kill long running background jobs # DOES: kill long running background jobs
@ -1315,18 +1318,19 @@ typeset HC_MSG_CUR_VAL=""
typeset HC_MSG_EXP_VAL="" typeset HC_MSG_EXP_VAL=""
# assign optional parameters # assign optional parameters
[[ -n "$3" ]] && HC_MSG_TEXT=$(data_newline2hash "$3")
[[ -n "$4" ]] && HC_MSG_CUR_VAL=$(data_newline2hash "$4") [[ -n "$4" ]] && HC_MSG_CUR_VAL=$(data_newline2hash "$4")
[[ -n "$5" ]] && HC_MSG_EXP_VAL=$(data_newline2hash "$5") [[ -n "$5" ]] && HC_MSG_EXP_VAL=$(data_newline2hash "$5")
# save the HC failure message for now # save the HC failure message for now
print "${HC_STC}%%${HC_NOW}%%${HC_MSG}%%${HC_MSG_CUR_VAL}%%${HC_MSG_EXP_VAL}" \ print "${HC_STC}${MSG_SEP}${HC_NOW}${MSG_SEP}${HC_MSG}${MSG_SEP}${HC_MSG_CUR_VAL}${MSG_SEP}${HC_MSG_EXP_VAL}" \
>>${HC_MSG_FILE} >>${HC_MSG_FILE}
return 0 return 0
} }
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# @(#) FUNCTION: show_statistics) # @(#) FUNCTION: show_statistics
# DOES: show statistics about HC events # DOES: show statistics about HC events
# EXPECTS: n/a # EXPECTS: n/a
# RETURNS: n/a # RETURNS: n/a
@ -1341,7 +1345,7 @@ print
print -R "--- CURRENT events --" print -R "--- CURRENT events --"
print print
print "${HC_LOG}:" print "${HC_LOG}:"
awk -F"${SEP}" '{ awk -F"${LOG_SEP}" '{
# all entries # all entries
total_count[$2]++ total_count[$2]++
# set zero when empty # set zero when empty
@ -1381,7 +1385,7 @@ print
find ${ARCHIVE_DIR} -type f -name "hc.*.log" 2>/dev/null | while read _ARCHIVE_FILE find ${ARCHIVE_DIR} -type f -name "hc.*.log" 2>/dev/null | while read _ARCHIVE_FILE
do do
print "${_ARCHIVE_FILE}:" print "${_ARCHIVE_FILE}:"
awk -F"${SEP}" '{ awk -F"${LOG_SEP}" '{
# all entries # all entries
total_count[$2]++ total_count[$2]++
# set zero when empty # set zero when empty

View File

@ -389,6 +389,30 @@ print -R "${1}" 2>/dev/null | tr '[:lower:]' '[:upper:]' 2>/dev/null
return 0 return 0
} }
# -----------------------------------------------------------------------------
# @(#) FUNCTION: data_is_numeric()
# DOES: check if input is numeric
# EXPECTS: [string]
# OUTPUTS: n/a
# RETURNS: 0=numeric; <>0=not numeric
# REQUIRES: n/a
function data_is_numeric
{
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
case "${1}" in
+([0-9])*(.)*([0-9]))
# numeric, OK
;;
*)
# not numeric
return 1
;;
esac
return 0
}
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# @(#) FUNCTION: data_encode_url # @(#) FUNCTION: data_encode_url
# DOES: encode URL data # DOES: encode URL data

View File

@ -20,7 +20,8 @@
# DOES: send alert via posteifmsg # DOES: send alert via posteifmsg
# EXPECTS: HC name [string] # EXPECTS: HC name [string]
# RETURNS: 0 # RETURNS: 0
# REQUIRES: handle_timeout(), init_hc(), log(), warn() # REQUIRES: data_get_lvalue_from_config(), handle_timeout(), init_hc(), log()
# warn()
# INFO: https://www-01.ibm.com/support/knowledgecenter/SSSHTQ_8.1.0/com.ibm.netcool_OMNIbus.doc_8.1.0/omnibus/wip/eifsdk/reference/omn_eif_posteifmsg.html # INFO: https://www-01.ibm.com/support/knowledgecenter/SSSHTQ_8.1.0/com.ibm.netcool_OMNIbus.doc_8.1.0/omnibus/wip/eifsdk/reference/omn_eif_posteifmsg.html
# #
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
@ -32,13 +33,14 @@ function notify_eif
{ {
# ------------------------- CONFIGURATION starts here ------------------------- # ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/core/providers/$0.conf" typeset _CONFIG_FILE="${CONFIG_DIR}/core/providers/$0.conf"
typeset _VERSION="2016-03-04" # YYYY-MM-DD typeset _VERSION="2018-05-12" # 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 ---------------------------
# set defaults # 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}" init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _EIF_MESSAGE="$1 alert with ID ${HC_FAIL_ID}" typeset _EIF_MESSAGE="$1 alert with ID ${HC_FAIL_ID}"
typeset _EIF_CLASS="${SCRIPT_NAME}" typeset _EIF_CLASS="${SCRIPT_NAME}"
typeset _EIF_BIN="" typeset _EIF_BIN=""
@ -57,19 +59,19 @@ then
return 1 return 1
fi fi
# read required config values # read required config values
_EIF_BIN="$(grep -i '^EIF_BIN=' ${_CONFIG_FILE} | cut -f2 -d'=' | tr -d '\"')" _EIF_BIN=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config '_EIF_BIN')
if [[ -z "${_EIF_BIN}" ]] if [[ -z "${_EIF_BIN}" ]]
then then
warn "no value set for 'EIF_BIN' in ${_CONFIG_FILE}" warn "no value set for 'EIF_BIN' in ${_CONFIG_FILE}"
return 1 return 1
fi fi
_EIF_ETC="$(grep -i '^EIF_ETC=' ${_CONFIG_FILE} | cut -f2 -d'=' | tr -d '\"')" _EIF_ETC=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config '_EIF_ETC')
if [[ -z "${_EIF_ETC}" ]] if [[ -z "${_EIF_ETC}" ]]
then then
warn "no value set for 'EIF_ETC' in ${_CONFIG_FILE}" warn "no value set for 'EIF_ETC' in ${_CONFIG_FILE}"
return 1 return 1
fi fi
_EIF_SEVERITY="$(grep -i '^EIF_SEVERITY=' ${_CONFIG_FILE} | cut -f2 -d'=' | tr -d '\"')" _EIF_SEVERITY=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config '_EIF_SEVERITY')
if [[ -z "${_EIF_SEVERITY}" ]] if [[ -z "${_EIF_SEVERITY}" ]]
then then
warn "no value set for 'EIF_SEVERITY' in ${_CONFIG_FILE}" warn "no value set for 'EIF_SEVERITY' in ${_CONFIG_FILE}"
@ -85,7 +87,7 @@ then
# $PID is PID of the owner shell # $PID is PID of the owner shell
_OWNER_PID=$$ _OWNER_PID=$$
( (
# sleep for $_TIME_OUT seconds. If the sleep subshell is then still alive, send a SIGUSR1 to the owner # sleep for $_TIME_OUT seconds. If the sleep sub-shell is then still alive, send a SIGUSR1 to the owner
sleep ${_TIME_OUT} sleep ${_TIME_OUT}
kill -s USR1 ${_OWNER_PID} >/dev/null 2>&1 kill -s USR1 ${_OWNER_PID} >/dev/null 2>&1
) & ) &

View File

@ -30,7 +30,7 @@
function notify_mail function notify_mail
{ {
# ------------------------- CONFIGURATION starts here ------------------------- # ------------------------- CONFIGURATION starts here -------------------------
typeset _VERSION="2017-05-17" # YYYY-MM-DD typeset _VERSION="2018-05-14" # 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 ---------------------------
@ -42,13 +42,12 @@ typeset _MAIL_HC="$1"
typeset _MAIL_FAIL_ID="$2" typeset _MAIL_FAIL_ID="$2"
typeset _HC_BODY="" typeset _HC_BODY=""
set -A _MAIL_MSG_STC
set -A _MAIL_MSG_TIME
set -A _MAIL_MSG_TEXT
typeset _I=0
typeset _MAX_I=0
typeset _HC_STDOUT_LOG_SHORT="" typeset _HC_STDOUT_LOG_SHORT=""
typeset _HC_STDERR_LOG_SHORT="" typeset _HC_STDERR_LOG_SHORT=""
typeset _HC_MSG_ENTRY=""
typeset _MAIL_MSG_STC=""
typeset _MAIL_MSG_TIME=""
typeset _MAIL_MSG_TEXT=""
typeset _MAIL_INFO_TPL="${CONFIG_DIR}/core/templates/mail_info.tpl" typeset _MAIL_INFO_TPL="${CONFIG_DIR}/core/templates/mail_info.tpl"
typeset _MAIL_HEADER_TPL="${CONFIG_DIR}/core/templates/mail_header.tpl" typeset _MAIL_HEADER_TPL="${CONFIG_DIR}/core/templates/mail_header.tpl"
typeset _MAIL_BODY_TPL="${CONFIG_DIR}/core/templates/mail_body.tpl" typeset _MAIL_BODY_TPL="${CONFIG_DIR}/core/templates/mail_body.tpl"
@ -69,6 +68,7 @@ typeset _TMP2_MAIL_FILE="${TMP_DIR}/.${SCRIPT_NAME}.mail.tmp2.$$"
typeset _NOW="$(date '+%d-%h-%Y %H:%M:%S')" typeset _NOW="$(date '+%d-%h-%Y %H:%M:%S')"
typeset _SUBJ_MSG="[${HOST_NAME}] HC ${_MAIL_HC} failed (${_NOW})" typeset _SUBJ_MSG="[${HOST_NAME}] HC ${_MAIL_HC} failed (${_NOW})"
typeset _FROM_MSG="${EXEC_USER}@${HOST_NAME}" typeset _FROM_MSG="${EXEC_USER}@${HOST_NAME}"
typeset _dummy=""
# set local trap for cleanup # set local trap for cleanup
trap "[[ -f ${_TMP1_MAIL_FILE} ]] && rm -f ${_TMP1_MAIL_FILE} >/dev/null 2>&1; [[ -f ${_TMP2_MAIL_FILE} ]] && rm -f ${_TMP2_MAIL_FILE} >/dev/null 2>&1; return 1" 1 2 3 15 trap "[[ -f ${_TMP1_MAIL_FILE} ]] && rm -f ${_TMP1_MAIL_FILE} >/dev/null 2>&1; [[ -f ${_TMP2_MAIL_FILE} ]] && rm -f ${_TMP2_MAIL_FILE} >/dev/null 2>&1; return 1" 1 2 3 15
@ -132,21 +132,22 @@ eval "cat << __EOT
$(sed 's/[\$`]/\\&/g;s/<## @\([^ ]*\) ##>/${\1}/g' <${_MAIL_HEADER_TPL}) $(sed 's/[\$`]/\\&/g;s/<## @\([^ ]*\) ##>/${\1}/g' <${_MAIL_HEADER_TPL})
__EOT" >>${_TMP1_MAIL_FILE} __EOT" >>${_TMP1_MAIL_FILE}
# create body part (max array size: 1023 in ksh88f, plugins spawning more than >1K messages are crazy :-)) # create body part (from $HC_MSG_VAR)
while read HC_MSG_ENTRY print "${HC_MSG_VAR}" | while read _HC_MSG_ENTRY
do do
_MAIL_MSG_STC[${_I}]=$(print "${HC_MSG_ENTRY}" | awk -F "%%" '{ print $1'}) # split fields (awk is required for multi-char delimiter)
_MAIL_MSG_TIME[${_I}]=$(print "${HC_MSG_ENTRY}" | awk -F "%%" '{ print $2'}) _MAIL_MSG_STC=$(print "${_HC_MSG_ENTRY}" | awk -F "%%" '{ print $1'})
_MAIL_MSG_TEXT[${_I}]=$(print "${HC_MSG_ENTRY}" | awk -F "%%" '{ print $3'}) _MAIL_MSG_TIME=$(print "${_HC_MSG_ENTRY}" | awk -F "%%" '{ print $2'})
_I=$(( _I + 1 )) _MAIL_MSG_TEXT=$(print "${_HC_MSG_ENTRY}" | awk -F "%%" '{ print $3'})
done <${HC_MSG_FILE} 2>/dev/null _MAIL_MSG_CUR_VAL=$(print "${_HC_MSG_ENTRY}" | awk -F "%%" '{ print $4'})
_MAX_I=${#_MAIL_MSG_STC[*]} _MAIL_MSG_EXP_VAL=$(print "${_HC_MSG_ENTRY}" | awk -F "%%" '{ print $5'})
_I=0
while (( _I < _MAX_I )) if (( _MAIL_MSG_STC > 0 ))
do then
(( _MAIL_MSG_STC[${_I}] > 0 )) && _HC_BODY=$(printf "%s\n%s\n" "${_HC_BODY}" "${_MAIL_MSG_TEXT[${_I}]}") _HC_BODY=$(printf "%s\n%s\n" "${_HC_BODY}" "${_MAIL_MSG_TEXT}")
_I=$(( _I + 1 )) fi
done done
# check for custom template # check for custom template
[[ -r "${_MAIL_BODY_TPL}-${_MAIL_HC}" ]] && _MAIL_BODY_TPL="${_MAIL_BODY_TPL}-${_MAIL_HC}" [[ -r "${_MAIL_BODY_TPL}-${_MAIL_HC}" ]] && _MAIL_BODY_TPL="${_MAIL_BODY_TPL}-${_MAIL_HC}"
[[ -r "${_MAIL_BODY_TPL}" ]] || die "cannot read mail body template at ${_MAIL_BODY_TPL}" [[ -r "${_MAIL_BODY_TPL}" ]] || die "cannot read mail body template at ${_MAIL_BODY_TPL}"

View File

@ -20,7 +20,7 @@
# DOES: send sms alert # DOES: send sms alert
# EXPECTS: 1=HC name [string], 2=HC FAIL_ID [string] # EXPECTS: 1=HC name [string], 2=HC FAIL_ID [string]
# RETURNS: 0 # RETURNS: 0
# REQUIRES: init_hc(), log(), warn() # REQUIRES: data_get_lvalue_from_config(), init_hc(), log(), warn()
# #
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! # DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
@ -31,15 +31,17 @@ function notify_sms
{ {
# ------------------------- CONFIGURATION starts here ------------------------- # ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/core/providers/$0.conf" typeset _CONFIG_FILE="${CONFIG_DIR}/core/providers/$0.conf"
typeset _VERSION="2017-04-27" # YYYY-MM-DD typeset _VERSION="2018-05-14" # 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 ---------------------------
# set defaults # 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}" init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _SMS_HC="$1" typeset _SMS_HC="$1"
typeset _SMS_FAIL_ID="$2" typeset _SMS_FAIL_ID="$2"
typeset _SMS_TEXT="" typeset _SMS_TEXT=""
typeset _FROM_MSG="${EXEC_USER}@${HOST_NAME}" typeset _FROM_MSG="${EXEC_USER}@${HOST_NAME}"
typeset _CURL_BIN="" typeset _CURL_BIN=""
@ -55,7 +57,7 @@ then
return 1 return 1
fi fi
# read required config values # read required config values
_SMS_PROVIDERS="$(grep -i '^SMS_PROVIDERS=' ${_CONFIG_FILE} | cut -f2 -d'=' | tr -d '\"')" _SMS_PROVIDERS=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'SMS_PROVIDERS')
if [[ -z "${_SMS_PROVIDERS}" ]] if [[ -z "${_SMS_PROVIDERS}" ]]
then then
warn "no value set for 'SMS_PROVIDERS' in ${_CONFIG_FILE}" warn "no value set for 'SMS_PROVIDERS' in ${_CONFIG_FILE}"
@ -71,19 +73,19 @@ then
case "${_PROVIDER_OPTS}" in case "${_PROVIDER_OPTS}" in
*kapow*|*KAPOW*|*Kapow*) *kapow*|*KAPOW*|*Kapow*)
# read required config values # read required config values
_SMS_KAPOW_SEND_URL="$(grep -i '^SMS_KAPOW_SEND_URL=' ${_CONFIG_FILE} | cut -f2 -d'=' | tr -d '\"')" _SMS_KAPOW_SEND_URL=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'SMS_KAPOW_SEND_URL')
if [[ -z "${_SMS_KAPOW_SEND_URL}" ]] if [[ -z "${_SMS_KAPOW_SEND_URL}" ]]
then then
warn "no value set for 'SMS_KAPOW_SEND_URL' in ${_CONFIG_FILE}" warn "no value set for 'SMS_KAPOW_SEND_URL' in ${_CONFIG_FILE}"
return 1 return 1
fi fi
_SMS_KAPOW_USER="$(grep -i '^SMS_KAPOW_USER=' ${_CONFIG_FILE} | cut -f2 -d'=' | tr -d '\"')" _SMS_KAPOW_USER=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'SMS_KAPOW_USER')
if [[ -z "${_SMS_KAPOW_USER}" ]] if [[ -z "${_SMS_KAPOW_USER}" ]]
then then
warn "no value set for 'SMS_KAPOW_USER' in ${_CONFIG_FILE}" warn "no value set for 'SMS_KAPOW_USER' in ${_CONFIG_FILE}"
return 1 return 1
fi fi
_SMS_KAPOW_PASS="$(grep -i '^SMS_KAPOW_PASS=' ${_CONFIG_FILE} | cut -f2 -d'=' | tr -d '\"')" _SMS_KAPOW_PASS=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'SMS_KAPOW_PASS')
if [[ -z "${_SMS_KAPOW_PASS}" ]] if [[ -z "${_SMS_KAPOW_PASS}" ]]
then then
warn "no value set for 'SMS_KAPOW_PASS' in ${_CONFIG_FILE}" warn "no value set for 'SMS_KAPOW_PASS' in ${_CONFIG_FILE}"

View File

@ -71,7 +71,7 @@ then
_HC_LAST_FAIL_ID="-" _HC_LAST_FAIL_ID="-"
# find last event or block of events (same timestamp) # find last event or block of events (same timestamp)
# (but unfortunately this is only accurate to events within the SAME second!) # (but unfortunately this is only accurate to events within the SAME second!)
_HC_LAST_TIME="$(grep -h ${_HC_LAST} ${_LOG_STASH} 2>/dev/null | sort -n | cut -f1 -d${SEP} | uniq | tail -1)" _HC_LAST_TIME="$(grep -h ${_HC_LAST} ${_LOG_STASH} 2>/dev/null | sort -n | cut -f1 -d${LOG_SEP} | uniq | tail -1)"
if [[ -z "${_HC_LAST_TIME}" ]] if [[ -z "${_HC_LAST_TIME}" ]]
then then
_HC_LAST_TIME="-" _HC_LAST_TIME="-"
@ -79,7 +79,7 @@ then
else else
# use of cat is not useless here, makes sure END {} gets executed even # use of cat is not useless here, makes sure END {} gets executed even
# if $_LOG STASH contains non-existing files (because of * wildcard) # if $_LOG STASH contains non-existing files (because of * wildcard)
cat ${_LOG_STASH} 2>/dev/null | awk -F "${SEP}" -v needle_time="${_HC_LAST_TIME}" -v needle_hc="${_HC_LAST}" \ cat ${_LOG_STASH} 2>/dev/null | awk -F "${LOG_SEP}" -v needle_time="${_HC_LAST_TIME}" -v needle_hc="${_HC_LAST}" \
' '
BEGIN { BEGIN {
last_stc = 0 last_stc = 0
@ -113,7 +113,7 @@ else
(( 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) # check fail count (look for unique IDs in the 5th field of the HC log)
_FAIL_COUNT=$(cut -f5 -d"${SEP}" ${_LOG_STASH} 2>/dev/null | grep -E -e "${_ID_NEEDLE}" | uniq | wc -l) _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 then
# check for detail or not? # check for detail or not?
@ -138,7 +138,7 @@ else
# print failed events # print failed events
# not a useless use of cat here # not a useless use of cat here
# (sort baulks if $_LOG STASH contains non-existing files (because of * wildcard)) # (sort baulks if $_LOG STASH contains non-existing files (because of * wildcard))
cat ${_LOG_STASH} 2>/dev/null | ${_SORT_CMD} 2>/dev/null | awk -F"${SEP}" -v id_needle="${_ID_NEEDLE}" \ cat ${_LOG_STASH} 2>/dev/null | ${_SORT_CMD} 2>/dev/null | awk -F"${LOG_SEP}" -v id_needle="${_ID_NEEDLE}" \
' '
{ {
if ($5 ~ id_needle) { if ($5 ~ id_needle) {
@ -151,7 +151,7 @@ else
# print failed events (we may have multiple events for 1 FAIL ID) # print failed events (we may have multiple events for 1 FAIL ID)
# not a useless use of cat here # not a useless use of cat here
# (sort baulks if $_LOG STASH contains non-existing files (because of * wildcard)) # (sort baulks if $_LOG STASH contains non-existing files (because of * wildcard))
cat ${_LOG_STASH} 2>/dev/null | ${_SORT_CMD} 2>/dev/null | awk -F"${SEP}" -v id_needle="${_ID_NEEDLE}" \ cat ${_LOG_STASH} 2>/dev/null | ${_SORT_CMD} 2>/dev/null | awk -F"${LOG_SEP}" -v id_needle="${_ID_NEEDLE}" \
' BEGIN { ' BEGIN {
event_count = 1 event_count = 1
dashes = sprintf("%36s",""); gsub (/ /, "-", dashes); dashes = sprintf("%36s",""); gsub (/ /, "-", dashes);

View File

@ -117,11 +117,11 @@ else
log "executing {${_DRD_BIN}} ..." log "executing {${_DRD_BIN}} ..."
# drd outputs on STDERR # drd outputs on STDERR
${_DRD_BIN} status >${HC_STDOUT_LOG} 2>&1 ${_DRD_BIN} status >${HC_STDOUT_LOG} 2>&1
_RC=$? # RC of drd is unreliable
fi fi
# check drd status # check drd status
if (( _RC == 0 )) && (( $(grep -c -E -e ".*Displaying.*succeeded" ${HC_STDOUT_LOG} 2>/dev/null) > 0 )) if (( $(grep -c -E -e ".*Displaying.*succeeded" ${HC_STDOUT_LOG} 2>/dev/null) > 0 ))
then then
# convert NOW to epoch (pass date values as unquoted parameters) # convert NOW to epoch (pass date values as unquoted parameters)
#_NOW_EPOCH=$(data_date2epoch "$(date '+%Y')" "$(date '+%m')" "$(date '+%d')" "$(date '+%H')" "$(date '+%M')" "$(date '+%S')") #_NOW_EPOCH=$(data_date2epoch "$(date '+%Y')" "$(date '+%m')" "$(date '+%d')" "$(date '+%H')" "$(date '+%M')" "$(date '+%S')")
@ -242,7 +242,7 @@ then
else else
_MSG="unable to run command: {${_DRD_BIN}}" _MSG="unable to run command: {${_DRD_BIN}}"
log_hc "$0" 1 "${_MSG}" log_hc "$0" 1 "${_MSG}"
return 0 return 1
fi fi
return 0 return 0

View File

@ -107,9 +107,9 @@ then
log_hc "$0" 1 "${_MSG}" log_hc "$0" 1 "${_MSG}"
fi fi
else else
_MSG="unable to run command: {${_SWLLST_BIN}}" _MSG="unable to run command: {${_SWLIST_BIN}}"
log_hc "$0" 1 "${_MSG}" log_hc "$0" 1 "${_MSG}"
return 0 return 1
fi fi
else else
warn "required OE will not be checked (not configured in ${_CONFIG_FILE})" warn "required OE will not be checked (not configured in ${_CONFIG_FILE})"
@ -150,7 +150,7 @@ then
else else
_MSG="unable to run command: {${_SHOW_PATCHES_BIN}}" _MSG="unable to run command: {${_SHOW_PATCHES_BIN}}"
log_hc "$0" 1 "${_MSG}" log_hc "$0" 1 "${_MSG}"
return 0 return 1
fi fi
else else
warn "required patches will not be checked (not configured in ${_CONFIG_FILE})" warn "required patches will not be checked (not configured in ${_CONFIG_FILE})"