Fixed (linter) issues

This commit is contained in:
patvdv
2018-10-27 22:16:08 +02:00
parent 1249e2ccd6
commit f27d7aa07b
54 changed files with 458 additions and 376 deletions
+5 -5
View File
@@ -30,7 +30,7 @@
function display_csv
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _VERSION="2018-05-20" # YYYY-MM-DD
typeset _VERSION="2018-10-28" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="AIX,HP-UX,Linux" # uname -s match
typeset _DISPLAY_SEP=";"
# ------------------------- CONFIGURATION ends here ---------------------------
@@ -42,11 +42,10 @@ init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _DISPLAY_HC="$1"
typeset _DISPLAY_FAIL_ID="$2"
typeset _HC_MSG_ENTRY=""
typeset _DISPLAY_MSG_STC=""
typeset _DISPLAY_MSG_TIME=""
typeset _DISPLAY_MSG_TEXT=""
typeset _DISPLAY_MSG_CUR_VAL=""
typeset _DISPLAY_MSG_CUR_VAL=""
typeset _DISPLAY_MSG_EXP_VAL=""
typeset _ID_BIT=""
@@ -56,6 +55,7 @@ then
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"
# shellcheck disable=SC2034
print "${HC_MSG_VAR}" | while IFS=${MSG_SEP} read _DISPLAY_MSG_STC _DISPLAY_MSG_TIME _DISPLAY_MSG_TEXT _DISPLAY_MSG_CUR_VAL _DISPLAY_MSG_EXP_VAL
do
# magically unquote if needed
@@ -82,8 +82,8 @@ then
then
_DISPLAY_MSG_EXP_VAL=$(data_magic_unquote "${_DISPLAY_MSG_EXP_VAL}")
fi
fi
if (( _DISPLAY_MSG_STC > 0 ))
fi
if (( _DISPLAY_MSG_STC > 0 ))
then
_ID_BIT="${_DISPLAY_FAIL_ID}"
else
+4 -6
View File
@@ -31,7 +31,7 @@
function display_init
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _VERSION="2018-05-14" # YYYY-MM-DD
typeset _VERSION="2018-10-28" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="AIX,HP-UX,Linux" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
@@ -59,7 +59,6 @@ then
typeset _BLUE=$(tput setaf 4)
typeset _MAGENTA=$(tput setaf 5)
typeset _CYAN=$(tput setaf 6)
typeset _WHITE=$(tput setaf 7)
typeset _BOLD=$(tput bold)
typeset _NORMAL=$(tput sgr0)
else
@@ -69,7 +68,6 @@ else
typeset _BLUE=""
typeset _MAGENTA=""
typeset _CYAN=""
typeset _WHITE=""
typeset _BOLD=""
typeset _NORMAL=""
fi
@@ -98,9 +96,9 @@ else
print "${HC_MSG_VAR}" | while read _HC_MSG_ENTRY
do
# determine _DISPLAY_MSG_STC (sum of all STCs)
_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)
_DISPLAY_MSG_STC=$(print "${_HC_MSG_ENTRY}" | 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
if (( _DISPLAY_MSG_STC == 0 ))
then
@@ -114,7 +112,7 @@ else
then
_DISPLAY_ID=" (${_BOLD}${_DISPLAY_FAIL_ID}${_NORMAL})"
else
_DISPLAY_ID=" (${_BOLD}not logged${_NORMAL})"
_DISPLAY_ID=" (${_BOLD}not logged${_NORMAL})"
fi
fi
else
+5 -7
View File
@@ -30,9 +30,8 @@
function display_json
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _VERSION="2018-05-20" # YYYY-MM-DD
typeset _VERSION="2018-10-28" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="AIX,HP-UX,Linux" # uname -s match
typeset _DISPLAY_SEP=";"
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
@@ -42,11 +41,10 @@ init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _DISPLAY_HC="$1"
typeset _DISPLAY_FAIL_ID="$2"
typeset _HC_MSG_ENTRY=""
typeset _DISPLAY_MSG_STC=""
typeset _DISPLAY_MSG_TIME=""
typeset _DISPLAY_MSG_TEXT=""
typeset _DISPLAY_MSG_CUR_VAL=""
typeset _DISPLAY_MSG_CUR_VAL=""
typeset _DISPLAY_MSG_EXP_VAL=""
typeset _ID_BIT=""
@@ -79,8 +77,8 @@ then
then
_DISPLAY_MSG_EXP_VAL=$(data_magic_unquote "${_DISPLAY_MSG_EXP_VAL}")
fi
fi
if (( _DISPLAY_MSG_STC > 0 ))
fi
if (( _DISPLAY_MSG_STC > 0 ))
then
_ID_BIT="${_DISPLAY_FAIL_ID}"
else
@@ -90,7 +88,7 @@ then
_DISPLAY_MSG_TEXT=$(data_escape_json "${_DISPLAY_MSG_TEXT}")
_DISPLAY_MSG_CUR_VAL=$(data_escape_json "${_DISPLAY_MSG_CUR_VAL}")
_DISPLAY_MSG_EXP_VAL=$(data_escape_json "${_DISPLAY_MSG_EXP_VAL}")
printf '{"hc":"%s","stc":"%s","time":"%s","fail_id":"%s","text":"%s","current_value":"%s","expected_value":"%s"}\n' \
"${_DISPLAY_HC}" \
+6 -6
View File
@@ -41,11 +41,10 @@ init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _DISPLAY_HC="$1"
typeset _DISPLAY_FAIL_ID="$2"
typeset _HC_MSG_ENTRY=""
typeset _DISPLAY_MSG_STC=""
typeset _DISPLAY_MSG_TIME=""
typeset _DISPLAY_MSG_TEXT=""
typeset _DISPLAY_MSG_CUR_VAL=""
typeset _DISPLAY_MSG_CUR_VAL=""
typeset _DISPLAY_MSG_EXP_VAL=""
typeset _ID_BIT=""
@@ -54,6 +53,7 @@ if [[ -n "${HC_MSG_VAR}" ]]
then
printf "%-30s\t%s\t%-16s\t%s\n" "HC" "STC" "FAIL ID" "Message"
# shellcheck disable=SC2034
print "${HC_MSG_VAR}" | while IFS=${MSG_SEP} read _DISPLAY_MSG_STC _DISPLAY_MSG_TIME _DISPLAY_MSG_TEXT _DISPLAY_MSG_CUR_VAL _DISPLAY_MSG_EXP_VAL
do
# magically unquote if needed
@@ -80,8 +80,8 @@ then
then
_DISPLAY_MSG_EXP_VAL=$(data_magic_unquote "${_DISPLAY_MSG_EXP_VAL}")
fi
fi
if (( _DISPLAY_MSG_STC > 0 ))
fi
if (( _DISPLAY_MSG_STC > 0 ))
then
_ID_BIT="${_DISPLAY_FAIL_ID}"
else
@@ -91,8 +91,8 @@ then
"${_DISPLAY_HC}" \
"${_DISPLAY_MSG_STC}" \
"${_ID_BIT}" \
"${_DISPLAY_MSG_TEXT}"
done
"${_DISPLAY_MSG_TEXT}"
done
else
ARG_LOG=0 ARG_VERBOSE=1 log "INFO: no HC results to display"
fi
+6 -6
View File
@@ -32,7 +32,7 @@
function display_zenoss
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _VERSION="2018-05-20" # YYYY-MM-DD
typeset _VERSION="2018-10-28" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="AIX,HP-UX,Linux" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
@@ -43,16 +43,16 @@ init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _DISPLAY_HC="$1"
typeset _DISPLAY_FAIL_ID="$2"
typeset _HC_MSG_ENTRY=""
typeset _DISPLAY_MSG_STC=""
typeset _DISPLAY_MSG_TIME=""
typeset _DISPLAY_MSG_TEXT=""
typeset _DISPLAY_MSG_CUR_VAL=""
typeset _DISPLAY_MSG_CUR_VAL=""
typeset _DISPLAY_MSG_EXP_VAL=""
# parse $HC_MSG_VAR
if [[ -n "${HC_MSG_VAR}" ]]
then
# shellcheck disable=SC2034
print "${HC_MSG_VAR}" | while IFS=${MSG_SEP} read _DISPLAY_MSG_STC _DISPLAY_MSG_TIME _DISPLAY_MSG_TEXT _DISPLAY_MSG_CUR_VAL _DISPLAY_MSG_EXP_VAL
do
# magically unquote if needed
@@ -79,8 +79,8 @@ then
then
_DISPLAY_MSG_EXP_VAL=$(data_magic_unquote "${_DISPLAY_MSG_EXP_VAL}")
fi
fi
if (( _DISPLAY_MSG_STC > 0 ))
fi
if (( _DISPLAY_MSG_STC > 0 ))
then
printf "NOK|data1=%s data2=%s data3=%s data4=\"%s\" data5=%s data6=%s\n" \
"${_DISPLAY_HC}" \
@@ -97,7 +97,7 @@ then
"${_DISPLAY_MSG_TEXT}" \
"${_DISPLAY_MSG_CUR_VAL}" \
"${_DISPLAY_MSG_EXP_VAL}"
fi
fi
done
fi
+17 -14
View File
@@ -153,6 +153,7 @@ then
then
print - "$*" | while read -r LOG_LINE
do
# shellcheck disable=SC2153
print "${NOW}: ERROR: [$$]:" "${LOG_LINE}" >>${LOG_FILE}
done
fi
@@ -220,6 +221,7 @@ HAS_REPORT_STD=0
# check which core display/notification plugins are installed
# do not use a while-do loop here because mksh/pdksh does not pass updated
# variables back from the sub shell (only works for true ksh88/ksh93)
# shellcheck disable=SC2010
for FFILE in $(ls -1 ${FPATH_PARENT}/core/*.sh 2>/dev/null | grep -v "include_" 2>/dev/null)
do
case "${FFILE}" in
@@ -593,7 +595,7 @@ typeset EXISTS_RC=0
# variables back from the sub shell (only works for true ksh88/ksh93)
for FDIR in $(print "${FPATH}" | tr ':' ' ' 2>/dev/null)
do
$(data_contains_string "${FDIR}" "core")
data_contains_string "${FDIR}" "core"
if (( $? == 0 ))
then
ls "${FDIR}/${EXISTS_HC}" >/dev/null 2>&1 && EXISTS_RC=1
@@ -613,7 +615,6 @@ function find_hc
{
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
typeset FIND_HC="${1}"
typeset FIND_PATH=""
typeset FDIR=""
print "${FPATH}" | tr ':' '\n' | grep -v "core$" | while read -r FDIR
@@ -670,6 +671,7 @@ do
# rewrite if needed
if (( ERROR_COUNT > 0 ))
then
# shellcheck disable=SC2188
>${TMP_FILE} 2>/dev/null
cat ${FIX_FILE} 2>/dev/null | awk -F"${LOG_SEP}" -v OFS="${LOG_SEP}" '
@@ -797,7 +799,6 @@ function handle_hc
typeset HC_NAME="${1}"
typeset HC_STDOUT_LOG_SHORT=""
typeset HC_STDERR_LOG_SHORT=""
typeset HC_MSG_ENTRY=""
typeset HC_STC_RC=0
typeset ONE_MSG_STC=0
typeset ONE_MSG_TIME=""
@@ -823,7 +824,7 @@ then
# determine ALL_MSG_STC (sum of all STCs)
ALL_MSG_STC=$(print "${HC_MSG_VAR}" | awk -F"${MSG_SEP}" 'BEGIN { stc = 0 } { for (i=1;i<=NF;i++) { stc = stc + $1 }} END { print stc }' 2>/dev/null)
(( ARG_DEBUG != 0 )) && debug "HC all STC: ${ALL_MSG_STC}"
$(data_is_numeric ${ALL_MSG_STC}) || die "HC all STC computes to a non-numeric value"
data_is_numeric ${ALL_MSG_STC} || die "HC all STC computes to a non-numeric value"
else
# nothing to do
return 0
@@ -1128,6 +1129,7 @@ function handle_timeout
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
[[ -n "${CHILD_PID}" ]] && kill -s TERM ${CHILD_PID}
warn "child process with PID ${CHILD_PID} has been forcefully stopped"
# shellcheck disable=SC2034
CHILD_ERROR=1
return 0
@@ -1142,9 +1144,6 @@ return 0
function init_check_host
{
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
typeset DUMMY=""
typeset HC_CONFIG=""
typeset HC_DESC=""
typeset HC_EXEC=""
typeset DISPLAY_STYLE=""
@@ -1152,7 +1151,7 @@ typeset DISPLAY_STYLE=""
# read required config values
DISPLAY_STYLE=$(_CONFIG_FILE="${HOST_CONFIG_FILE}" data_get_lvalue_from_config 'display_style')
case "${REPORT_STYLE}" in
case "${DISPLAY_STYLE}" in
csv|CSV) # csv format
if (( HAS_DISPLAY_CSV == 1 ))
then
@@ -1258,7 +1257,7 @@ esac
# mangle $ARG_HC to build the full list of HCs to be executed
ARG_HC=""
grep -i '^hc:' ${HOST_CONFIG_FILE} 2>/dev/null |\
while IFS=':' read DUMMY HC_EXEC HC_CONFIG HC_DESC
while IFS=':' read _ HC_EXEC _ _
do
ARG_HC="${ARG_HC},${HC_EXEC}"
done
@@ -1359,11 +1358,13 @@ typeset HC_VERSION=""
if [[ "${FACTION}" != "list" ]]
then
printf "%-30s\t%-8s\t%s\t\t%s\n" "Core plugin" "State" "Version" "Config?"
# shellcheck disable=SC2183
printf "%80s\n" | tr ' ' -
fi
print "${FPATH}" | tr ':' '\n' | grep "core$" | sort 2>/dev/null | while read -r FDIR
do
# exclude core helper librar(y|ies)
# shellcheck disable=SC2010
ls -1 ${FDIR}/*.sh 2>/dev/null | grep -v "include_" | sort 2>/dev/null | while read -r FFILE
do
# reset state
@@ -1405,6 +1406,7 @@ then
print "${FPATH}" | tr ':' '\n' | grep "core$" | while read -r FDIR
do
# do not use 'find -type l' here!
# shellcheck disable=SC2010
ls ${FDIR} 2>/dev/null | grep -v "\." | while read -r FFILE
do
if [[ -h "${FDIR}/${FFILE}" ]] && [[ ! -f "${FDIR}/${FFILE}" ]]
@@ -1460,6 +1462,7 @@ fi
if [[ "${FACTION}" != "list" ]]
then
printf "%-30s\t%-8s\t%s\t\t%s\t%s\t%s\n" "Health Check" "State" "Version" "Config?" "Sched?" "H+?"
# shellcheck disable=SC2183
printf "%100s\n" | tr ' ' -
fi
print "${FPATH}" | tr ':' '\n' | grep -v "core$" | sort 2>/dev/null | while read -r FDIR
@@ -1492,8 +1495,8 @@ do
;;
esac
else
FHEALTHY="N/S"
fi
FHEALTHY="N/S"
fi
# *.conf next
if [[ -r ${CONFIG_DIR}/${FNAME#function *}.conf ]]
then
@@ -1509,7 +1512,7 @@ do
*)
FHEALTHY="N/S"
;;
esac
esac
fi
# check for log_healthy support through --hc-args (plugin)
elif (( $(grep -c -E -e "_LOG_HEALTHY" "${FFILE}" 2>/dev/null) > 0 ))
@@ -1562,6 +1565,7 @@ then
print "${FPATH}" | tr ':' '\n' | grep -v "core" | while read -r FDIR
do
# do not use 'find -type l' here!
# shellcheck disable=SC2010
ls ${FDIR} 2>/dev/null | grep -v "\." | while read -r FFILE
do
if [[ -h "${FDIR}/${FFILE}" ]] && [[ ! -f "${FDIR}/${FFILE}" ]]
@@ -1635,7 +1639,6 @@ function log_hc
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
typeset HC_NAME="${1}"
typeset HC_STC=${2}
typeset HC_MSG="${3}"
typeset HC_NOW="$(date '+%Y-%m-%d %H:%M:%S' 2>/dev/null)"
typeset HC_MSG_CUR_VAL=""
typeset HC_MSG_EXP_VAL=""
@@ -1823,4 +1826,4 @@ return 0
#******************************************************************************
# END of script
#******************************************************************************
#******************************************************************************
+33 -33
View File
@@ -41,7 +41,7 @@ _LVALUE=$(grep -i "^${_PARAMETER} *=" ${_CONFIG_FILE} | cut -f2- -d'=')
if [[ -n "${_LVALUE}" ]]
then
print $(data_dequote "${_LVALUE}")
print "$(data_dequote \"${_LVALUE}\")"
else
_RC=1
fi
@@ -88,7 +88,7 @@ return ${_RC}
# -----------------------------------------------------------------------------
# @(#) FUNCTION: data_magic_quote()
# DOES: magically quotes a needle in a string (default needle is: %)
# EXPECTS: to be magically quoted [string]; $2=needle [string]
# EXPECTS: to be magically quoted [string]; $2=needle [string]
# OUTPUTS: magically quoted [string]
# RETURNS: n/a
# REQUIRES: n/a
@@ -106,7 +106,7 @@ return 0
# -----------------------------------------------------------------------------
# @(#) FUNCTION: data_magic_unquote()
# DOES: magically unquotes a needle in a string (default needle is: %)
# EXPECTS: to be magically unquoted [string]; $2=needle [string]
# EXPECTS: to be magically unquoted [string]; $2=needle [string]
# OUTPUTS: magically unquoted [string]
# RETURNS: n/a
# REQUIRES: n/a
@@ -473,9 +473,9 @@ case "${1}" in
+([0-9])*(.)*([0-9]))
# numeric, OK
;;
*)
*)
# not numeric
return 1
return 1
;;
esac
@@ -544,7 +544,7 @@ return 0
# OUTPUTS: 32 bit number [string]
# REQUIRES: n/a
# REFERENCE: https://raw.githubusercontent.com/dualbus/tutorial_nmap/master/iprange
function data_dot2ip
function data_dot2ip
{
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
typeset _DOT="${1}"
@@ -553,7 +553,7 @@ typeset _OLD_IFS="${IFS}"
IFS="."
set -A _COMPS ${_DOT}
IFS="${OLD_IFS}"
IFS="${_OLD_IFS}"
_IP=$((_IP | ((_COMPS[0] & 255) << 24) ))
_IP=$((_IP | ((_COMPS[1] & 255) << 16) ))
@@ -573,13 +573,13 @@ return 0
# RETURNS: 0
# REQUIRES: n/a
# REFERENCE: https://raw.githubusercontent.com/dualbus/tutorial_nmap/master/iprange
function data_ip2dot
function data_ip2dot
{
(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
typeset _IP="${1}"
typeset _W=""
typeset _X=""
typeset _Y=""
typeset _W=""
typeset _X=""
typeset _Y=""
typeset _Z=""
_W=$(( (_IP >> 24) & 255 ))
@@ -617,21 +617,21 @@ case "${_BITS}" in
6) _OFFSET=67108864 ;;
7) _OFFSET=33554432 ;;
8) _OFFSET=16777216 ;;
9) _OFFSET=8388608 ;;
10) _OFFSET=4194304 ;;
9) _OFFSET=8388608 ;;
10) _OFFSET=4194304 ;;
11) _OFFSET=2097152 ;;
12) _OFFSET=1048576 ;;
13) _OFFSET=524288 ;;
14) _OFFSET=262144 ;;
15) _OFFSET=131072 ;;
16) _OFFSET=65536 ;;
14) _OFFSET=262144 ;;
15) _OFFSET=131072 ;;
16) _OFFSET=65536 ;;
17) _OFFSET=32768 ;;
18) _OFFSET=16384 ;;
19) _OFFSET=8192 ;;
20) _OFFSET=4096 ;;
21) _OFFSET=2048 ;;
20) _OFFSET=4096 ;;
21) _OFFSET=2048 ;;
22) _OFFSET=1024 ;;
23) _OFFSET=512 ;;
23) _OFFSET=512 ;;
24) _OFFSET=256 ;;
25) _OFFSET=128 ;;
26) _OFFSET=64 ;;
@@ -691,11 +691,11 @@ return ${_RC}
# -----------------------------------------------------------------------------
# @(#) FUNCTION: data_date2epoch()
# DOES: converts a given date into UNIX epoch seconds
# EXPECTS: date formatted as individual parameters (in UTC time):
# EXPECTS: date formatted as individual parameters (in UTC time):
# $1 : YYYY
# $2 : MM
# $3 : DD
# $4 : HH
# $4 : HH
# $5 : MM
# $6 : SS
# OUTPUTS: UNIX epoch seconds [number]
@@ -711,25 +711,25 @@ typeset _DAY="${3}"
typeset _HOUR="${4}"
typeset _MINUTE="${5}"
typeset _SECOND="${6}"
typeset _DAYS_ACC
typeset _YEAR_DAY
typeset _EPOCH
typeset _DAYS_ACC
typeset _YEAR_DAY
typeset _EPOCH
typeset _LEAP_YEARS
set -A _DAYS_ACC 0 0 31 59 90 120 151 181 212 243 273 304 334 365
# calculate day of year (counting from 0)
_YEAR_DAY=$(( (${_DAY} - 1) + ${_DAYS_ACC[${_MONTH}]} ))
_YEAR_DAY=$(( (_DAY - 1) + _DAYS_ACC[_MONTH] ))
# calculate number of leap years
_LEAP_YEARS=$(( (${_YEAR} - 1968) / 4 ))
_LEAP_YEARS=$(( ${_LEAP_YEARS} - ${_YEAR} / 100 + ${_YEAR} / 400 + 15 ))
_LEAP_YEARS=$(( (_YEAR - 1968) / 4 ))
_LEAP_YEARS=$(( _LEAP_YEARS - _YEAR / 100 + _YEAR / 400 + 15 ))
# adjust if we are still in Jan/Feb of leap year
[[ $((${_YEAR} % 4)) = 0 && ${_MONTH} < 3 ]] && _LEAP_YEARS=$(( ${_LEAP_YEARS} - 1 ))
[[ $((_YEAR % 4)) = 0 && ${_MONTH} -lt 3 ]] && _LEAP_YEARS=$(( _LEAP_YEARS - 1 ))
# calculate the time since epoch
_EPOCH=$(( ((${_YEAR} - 1970) * 365 + ${_YEAR_DAY} + ${_LEAP_YEARS}) * 86400
+ ${_HOUR} * 3600 + ${_MINUTE} * 60 + ${_SECOND} ))
_EPOCH=$(( ((_YEAR - 1970) * 365 + _YEAR_DAY + _LEAP_YEARS) * 86400
+ _HOUR * 3600 + _MINUTE * 60 + _SECOND ))
print ${_EPOCH}
}
@@ -759,10 +759,10 @@ then
print "${_UNIX_EPOCH}"
return 1
else
print "${_CONVERT_DATE}"
fi
print "${_CONVERT_DATE}"
fi
else
print "${CONVERT_DATE}"
print "${_CONVERT_DATE}"
fi
return 0
+1
View File
@@ -101,6 +101,7 @@ then
LINUX_INIT="systemd"
elif [[ -r /usr/share/upstart ]]
then
# shellcheck disable=SC2034
LINUX_INIT="upstart"
fi
+4 -4
View File
@@ -33,7 +33,7 @@ function notify_eif
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/core/providers/$0.conf"
typeset _VERSION="2018-05-12" # YYYY-MM-DD
typeset _VERSION="2018-10-28" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="AIX,HP-UX,Linux" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
@@ -53,7 +53,7 @@ typeset _SLEEP_PID=0
typeset _CHILD_RC=0
# handle config file
if [[ ! -r ${_CONFIG_FILE} ]]
if [[ ! -r ${_CONFIG_FILE} ]]
then
warn "unable to read configuration file at ${_CONFIG_FILE}"
return 1
@@ -79,7 +79,7 @@ then
fi
# send EIF
if [[ -x ${EIF_BIN} ]]
if [[ -x ${_EIF_BIN} ]]
then
# set trap on SIGUSR1
trap "handle_timeout" USR1
@@ -95,7 +95,7 @@ then
_SLEEP_PID=$!
# do POSTEIFMSG in the background
${EIF_BIN} -f ${EIF_ETC} -r ${EIF_SEVERITY} -m "${_EIF_MESSAGE}" \
${_EIF_BIN} -f ${_EIF_ETC} -r ${_EIF_SEVERITY} -m "${_EIF_MESSAGE}" \
hostname=${HOST_NAME} sub_origin=part1 ${_EIF_CLASS} POST &
CHILD_PID=$!
log "spawning child process with time-out of ${_TIME_OUT} secs for EIF notify [PID=${CHILD_PID}]"
+12 -7
View File
@@ -30,7 +30,7 @@
function notify_mail
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _VERSION="2018-05-20" # YYYY-MM-DD
typeset _VERSION="2018-10-28" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="AIX,HP-UX,Linux" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
@@ -44,9 +44,7 @@ typeset _MAIL_FAIL_ID="$2"
typeset _HC_BODY=""
typeset _HC_STDOUT_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_HEADER_TPL="${CONFIG_DIR}/core/templates/mail_header.tpl"
@@ -67,10 +65,13 @@ typeset _TMP1_MAIL_FILE="${TMP_DIR}/.${SCRIPT_NAME}.mail.tmp1.$$"
typeset _TMP2_MAIL_FILE="${TMP_DIR}/.${SCRIPT_NAME}.mail.tmp2.$$"
typeset _NOW="$(date '+%d-%h-%Y %H:%M:%S')"
typeset _SUBJ_MSG="[${HOST_NAME}] HC ${_MAIL_HC} failed (${_NOW})"
# shellcheck disable=SC2034
typeset _FROM_MSG="${EXEC_USER}@${HOST_NAME}"
typeset _dummy=""
# set local trap for cleanup
# shellcheck disable=SC2064
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 0" 0
# shellcheck disable=SC2064
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
# set short paths for STDOUT/STDERR logs
@@ -133,7 +134,7 @@ $(sed 's/[\$`]/\\&/g;s/<## @\([^ ]*\) ##>/${\1}/g' <${_MAIL_HEADER_TPL})
__EOT" >>${_TMP1_MAIL_FILE}
# create body part (from $HC_MSG_VAR)
print "${HC_MSG_VAR}" | while IFS=${MSG_SEP} read _MAIL_MSG_STC _MAIL_MSG_TIME _MAIL_MSG_TEXT _MAIL_MSG_CUR_VAL _MAIL_MSG_EXP_VAL
print "${HC_MSG_VAR}" | while IFS=${MSG_SEP} read _MAIL_MSG_STC _ _MAIL_MSG_TEXT _MAIL_MSG_CUR_VAL _MAIL_MSG_EXP_VAL
do
# magically unquote if needed
if [[ -n "${_MAIL_MSG_TEXT}" ]]
@@ -159,7 +160,7 @@ do
then
_MAIL_MSG_EXP_VAL=$(data_magic_unquote "${_MAIL_MSG_EXP_VAL}")
fi
fi
fi
if (( _MAIL_MSG_STC > 0 ))
then
_HC_BODY=$(printf "%s\n%s\n" "${_HC_BODY}" "${_MAIL_MSG_TEXT}")
@@ -177,18 +178,22 @@ __EOT" >>${_TMP1_MAIL_FILE}
_MAIL_STDOUT_LOG="${EVENTS_DIR}/${DIR_PREFIX}/${_MAIL_FAIL_ID}/${_HC_STDOUT_LOG_SHORT%.*}"
if [[ -s "${_MAIL_STDOUT_LOG}" ]]
then
# shellcheck disable=SC2034
_MAIL_STDOUT_MSG="${_MAIL_STDOUT_LOG}"
_MAIL_ATTACH_BIT="-a ${_MAIL_STDOUT_LOG}"
else
# shellcheck disable=SC2034
_MAIL_STDOUT_MSG="no log file available"
fi
# HC STDERR? (drop the .$$ bit)
_MAIL_STDERR_LOG="${EVENTS_DIR}/${DIR_PREFIX}/${_MAIL_FAIL_ID}/${_HC_STDERR_LOG_SHORT%.*}"
if [[ -s "${_MAIL_STDERR_LOG}" ]]
then
# shellcheck disable=SC2034
_MAIL_STDERR_MSG="${_MAIL_STDERR_LOG}"
_MAIL_ATTACH_BIT="${_MAIL_ATTACH_BIT} -a ${_MAIL_STDERR_LOG}"
else
# shellcheck disable=SC2034
_MAIL_STDERR_MSG="no log file available"
fi
@@ -235,7 +240,7 @@ fi
# clean up temporary files
[[ -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 0
}
+6 -6
View File
@@ -31,7 +31,7 @@ function notify_sms
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/core/providers/$0.conf"
typeset _VERSION="2018-05-14" # YYYY-MM-DD
typeset _VERSION="2018-10-28" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="AIX,HP-UX,Linux" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
@@ -48,10 +48,10 @@ typeset _CURL_BIN=""
typeset _SMS_PROVIDERS=""
typeset _SMS_KAPOW_SEND_URL=""
typeset _SMS_KAPOW_USER=""
typeset _SMS_KAPOW_PASSWORD=""
typeset _SMS_KAPOW_PASS=""
# handle config file
if [[ ! -r ${_CONFIG_FILE} ]]
if [[ ! -r ${_CONFIG_FILE} ]]
then
warn "unable to read configuration file at ${_CONFIG_FILE}"
return 1
@@ -84,8 +84,8 @@ then
then
warn "no value set for 'SMS_KAPOW_USER' in ${_CONFIG_FILE}"
return 1
fi
_SMS_KAPOW_PASS=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'SMS_KAPOW_PASS')
fi
_SMS_KAPOW_PASS=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'SMS_KAPOW_PASS')
if [[ -z "${_SMS_KAPOW_PASS}" ]]
then
warn "no value set for 'SMS_KAPOW_PASS' in ${_CONFIG_FILE}"
@@ -108,7 +108,7 @@ case "${ARG_SMS_PROVIDER}" in
then
${_CURL_BIN} -s --url "${_SMS_KAPOW_SEND_URL}?username=${_SMS_KAPOW_USER}&password=${_SMS_KAPOW_PASS}&mobile=${ARG_SMS_TO}&sms=${_SMS_TEXT}" >/dev/null 2>&1
else
${_CURL_BIN} --url "${_SMS_KAPOW_SEND_URL}?username=${_SMS_KAPOW_USER}&password=${_SMS_KAPOW_PASS}&mobile=${ARG_SMS_TO}&sms=${_SMS_TEXT}"
${_CURL_BIN} --url "${_SMS_KAPOW_SEND_URL}?username=${_SMS_KAPOW_USER}&password=${_SMS_KAPOW_PASS}&mobile=${ARG_SMS_TO}&sms=${_SMS_TEXT}"
fi
else
die "unable to send SMS - curl is not installed here"
+6 -2
View File
@@ -30,7 +30,7 @@
function report_std
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _VERSION="2018-05-27" # YYYY-MM-DD
typeset _VERSION="2018-10-28" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="AIX,HP-UX,Linux" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
@@ -49,7 +49,6 @@ typeset _HC_LAST_FAIL_ID="-"
typeset _ID_NEEDLE=""
typeset _CHECK_FILE=""
typeset _LOG_STASH=""
typeset _REPORT_LINE=""
typeset _SORT_CMD=""
# which files do we need to examine
@@ -65,6 +64,7 @@ fi
if (( ARG_LAST != 0 ))
then
printf "\n| %-30s | %-20s | %-14s | %-4s\n" "HC" "Timestamp" "FAIL ID" "STC (combined value)"
# shellcheck disable=SC2183
printf "%100s\n" | tr ' ' -
# loop over all HCs
list_hc "list" | while read -r _HC_LAST
@@ -136,6 +136,7 @@ else
then
printf "\n| %-20s | %-14s | %-30s | %-s\n" \
"Timestamp" "FAIL ID" "HC" "Message"
# shellcheck disable=SC2183
printf "%120s\n" | tr ' ' -
# print failed events
@@ -169,6 +170,7 @@ else
' 2>/dev/null
_DIR_PREFIX="$(expr substr ${ARG_FAIL_ID} 1 4)-$(expr substr ${ARG_FAIL_ID} 5 2)"
# shellcheck disable=SC2183
printf "%37sSTDOUT%37s\n" | tr ' ' -;
# display non-empty STDOUT file(s)
if [[ -n "$(du -a ${EVENTS_DIR}/${_DIR_PREFIX}/${ARG_FAIL_ID}/*.stdout.log 2>/dev/null | awk '$1*512 > 0 {print $2}')" ]]
@@ -178,6 +180,7 @@ else
printf "%-s\n" "No STDOUT found"
fi
# shellcheck disable=SC2183
printf "%37sSTDERR%37s\n" | tr ' ' -;
# display non-empty STDERR file(s)
if [[ -n "$(du -a ${EVENTS_DIR}/${_DIR_PREFIX}/${ARG_FAIL_ID}/*.stderr.log 2>/dev/null | awk '$1*512 > 0 {print $2}')" ]]
@@ -187,6 +190,7 @@ else
printf "%-s\n" "No STDERR found"
fi
# shellcheck disable=SC2183
printf "%80s\n" | tr ' ' -
fi
else