Re-org of tree

This commit is contained in:
patvdv
2019-03-26 11:18:24 +01:00
parent 084c30b541
commit e2b47db3c6
155 changed files with 0 additions and 0 deletions
+153
View File
@@ -0,0 +1,153 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_aix_errpt.sh
#******************************************************************************
# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_aix_errpt
# DOES: see _show_usage()
# EXPECTS: n/a
# REQUIRES: data_comma2space(), init_hc(), log_hc()
#
# @(#) HISTORY:
# @(#) 2013-05-15: initial version [Patrick Van der Veken]
# @(#) 2013-05-29: small fix errpt last check time [Patrick Van der Veken]
# @(#) 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!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_aix_errpt
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="AIX" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
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=""
typeset _NEW_CHECK_TIME=""
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
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} ]]
then
if [[ -s ${_LAST_TIME_FILE} ]]
then
_LAST_TIME_CHECK="<${_LAST_TIME_FILE})"
else
warn "$0: no last known check date/time"
fi
fi
# collect data
if [[ -z "${_LAST_TIME_CHECK}" ]]
then
errpt -A >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG}
else
errpt -s "${_LAST_TIME_CHECK}" |\
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}
done
(( $? == 0)) || return $?
fi
# do we have errors?
if [[ -s ${HC_STDOUT_LOG} ]]
then
_MSG="new entries found in errpt: {$(grep -c '^LABEL' ${HC_STDOUT_LOG} 2>/dev/null)}"
_STC=1
else
_MSG="no new entries found in {errpt}"
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 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
print "${_NEW_CHECK_TIME}" >${_LAST_TIME_FILE}
(( $? == 0)) || warn "$0: unable to write last check time to ${_LAST_TIME_FILE}"
else
warn "$0: no last check time received from errpt (no entries)"
fi
# handle results
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
PURPOSE : Checks AIX errpt for new error(s)
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+182
View File
@@ -0,0 +1,182 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_aix_file_age.sh
#******************************************************************************
# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_aix_file_age
# DOES: see _show_usage()
# EXPECTS: see _show_usage()
# REQUIRES: data_comma2space(), init_hc(), log_hc()
#
# @(#) HISTORY:
# @(#) 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!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_aix_file_age
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="AIX" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
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}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
esac
done
# handle configuration file
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
if [[ ! -r ${_CONFIG_FILE} ]]
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 -E -e "^file:" ${_CONFIG_FILE} 2>/dev/null | while IFS=":" read -r _ _FILE_PATH _FILE_AGE
do
# split file/dir
_FILE_NAME="$(print ${_FILE_PATH##*/})"
_FILE_DIR="$(print ${_FILE_PATH%/*})"
# check config
if [[ -z "${_FILE_PATH}" ]] && [[ -z "${_FILE_AGE}" ]]
then
warn "missing values in configuration file at ${_CONFIG_FILE}"
return 1
fi
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}" ]]
then
_MSG="unable to read or access requested file at ${_FILE_PATH}"
_STC=1
else
_AGE_CHECK=$(find "${_FILE_DIR}" -type f -name "${_FILE_NAME}" -mmin -"${_FILE_AGE}")
if (( $? > 0 ))
then
warn "unable to execute file age test for ${_FILE_PATH}"
return 1
fi
if [[ -z "${_AGE_CHECK}" ]]
then
_MSG="file age of ${_FILE_AGE} has expired on ${_FILE_PATH}"
_STC=1
else
_MSG="file age of ${_FILE_AGE} has not expired on ${_FILE_PATH}"
fi
fi
# report result
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
_STC=0
done
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with parameters:
log_healthy=<yes|no>
and formatted stanzas:
file:<file_path>:<max_age_in_minutes>
PURPOSE : Checks whether given files have been changed in the last n minutes
Requires {find -mmin}.
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+411
View File
@@ -0,0 +1,411 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_aix_file_change.sh
#******************************************************************************
# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_aix_file_change
# DOES: see _show_usage()
# EXPECTS: see _show_usage()
# REQUIRES: data_comma2space(), init_hc(), log_hc(), warn(),
# openssl (sha256 digest) OR cksum (CRC32 digest)
#
# @(#) HISTORY:
# @(#) 2017-05-18: initial version [Patrick Van der Veken]
# @(#) 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]
# @(#) 2019-03-16: replace 'which' [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_aix_file_change
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _VERSION="2019-03-16" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
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=""
typeset _STATE_FILE_LINE=""
typeset _FILE_TO_CHECK=""
typeset _EXCL_OBJECT=""
typeset _INCL_OBJECT=""
typeset _HAS_OPENSSL=0
typeset _HAS_CKSUM=0
typeset _OPENSSL_BIN=""
typeset _CKSUM_BIN=""
typeset _USE_OPENSSL=0
typeset _USE_CKSUM=0
typeset _TMP1_FILE="${TMP_DIR}/.$0.tmp1.$$"
typeset _TMP2_FILE="${TMP_DIR}/.$0.tmp2.$$"
typeset _TMP_INCL_FILE="${TMP_DIR}/.$0.tmp_incl.$$"
typeset _TMP_EXCL_FILE="${TMP_DIR}/.$0.tmp_excl.$$"
set -o noglob # no file globbing
# set local trap for clean-up
# shellcheck disable=SC2064
trap "[[ -f ${_TMP1_FILE} ]] && rm -f ${_TMP1_FILE} >/dev/null 2>&1;
[[ -f ${_TMP2_FILE} ]] && rm -f ${_TMP2_FILE} >/dev/null 2>&1;
[[ -f ${_TMP_INCL_FILE} ]] && rm -f ${_TMP_INCL_FILE} >/dev/null 2>&1;
[[ -f ${_TMP_EXCL_FILE} ]] && rm -f ${_TMP_EXCL_FILE} >/dev/null 2>&1;
return 1" 1 2 3 15
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
esac
done
# handle configuration file
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
if [[ ! -r ${_CONFIG_FILE} ]]
then
warn "unable to read configuration file at ${_CONFIG_FILE}"
return 1
fi
# read required configuration values
_CFG_STATE_FILE=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'state_file')
if [[ -z "${_CFG_STATE_FILE}" ]]
then
_STATE_FILE="${STATE_PERM_DIR}/discovered.file_change"
else
_STATE_FILE="${STATE_PERM_DIR}/${_CFG_STATE_FILE}"
fi
log "using state file ${_STATE_FILE}"
_DO_META_CHECK=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'do_meta_check')
case "${_DO_META_CHECK}" in
no|NO|No)
_DO_META_CHECK=0
log "check for meta characters is disabled"
;;
*)
_DO_META_CHECK=1
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="$(command -v openssl 2>>${HC_STDERR_LOG})"
[[ -x ${_OPENSSL_BIN} && -n "${_OPENSSL_BIN}" ]] && _HAS_OPENSSL=1
_CKSUM_BIN="$(command -v cksum 2>>${HC_STDERR_LOG})"
[[ -x ${_CKSUM_BIN} && -n "${_CKSUM_BIN}" ]] && _HAS_CKSUM=1
# prefer openssl (for sha256)
if (( _HAS_OPENSSL == 1 ))
then
_USE_OPENSSL=1
elif (( _HAS_CKSUM == 1 ))
then
_USE_CKSUM=1
else
warn "unable to find the 'openssl/cksum' tools"
return 1
fi
# check state file & TMP_FILEs
[[ -r ${_STATE_FILE} ]] || {
: >${_STATE_FILE}
(( $? > 0 )) && {
warn "failed to create new state file at ${_STATE_FILE}"
return 1
}
log "created new state file at ${_STATE_FILE}"
}
: >${_TMP_INCL_FILE}
(( $? > 0 )) && {
warn "failed to create temporary file at ${_TMP_INCL_FILE}"
return 1
}
: >${_TMP_EXCL_FILE}
(( $? > 0 )) && {
warn "failed to create temporary file at ${_TMP_EXCL_FILE}"
return 1
}
: >${_TMP1_FILE}
(( $? > 0 )) && {
warn "failed to create temporary file at ${_TMP1_FILE}"
return 1
}
: >${_TMP2_FILE}
(( $? > 0 )) && {
warn "failed to create temporary file at ${_TMP2_FILE}"
return 1
}
# build list of configured objects: inclusion
grep -i '^incl:' ${_CONFIG_FILE} 2>/dev/null |\
while IFS=':' read _ _INCL_OBJECT
do
# check for meta & globbing characters (*?[]{}|)
if (( _DO_META_CHECK == 1 ))
then
case "${_INCL_OBJECT}" in
*\**|*\?*|*\[*|*\]*|*\{*|*\}*|*\|*)
warn "meta characters are not supported in the entry (incl:${_INCL_OBJECT})"
continue
;;
esac
fi
# expand directories
if [[ -d ${_INCL_OBJECT} ]]
then
find ${_INCL_OBJECT} -type f -xdev >>${_TMP_INCL_FILE} 2>>${HC_STDERR_LOG}
else
print ${_INCL_OBJECT} >>${_TMP_INCL_FILE}
fi
done
# build list of configured objects: exclusion
grep -i '^excl:' ${_CONFIG_FILE} 2>/dev/null |\
while IFS=':' read _ _EXCL_OBJECT
do
# check for meta & globbing characters (*?[]{}|)
if (( _DO_META_CHECK == 1 ))
then
case "${_EXCL_OBJECT}" in
*\**|*\?*|*\[*|*\]*|*\{*|*\}*|*\|*)
warn "meta characters are not supported in the entry (excl:${_EXCL_OBJECT})"
continue
;;
esac
fi
# expand directories
if [[ -d ${_EXCL_OBJECT} ]]
then
find ${_EXCL_OBJECT} -type f -xdev >>${_TMP_EXCL_FILE} 2>>${HC_STDERR_LOG}
else
print ${_EXCL_OBJECT} >>${_TMP_EXCL_FILE}
fi
done
# subtract exclusion from inclusion (exclusion has higher priority)
sort ${_TMP_INCL_FILE} -o ${_TMP_INCL_FILE} 2>>${HC_STDERR_LOG}
sort ${_TMP_EXCL_FILE} -o ${_TMP_EXCL_FILE} 2>>${HC_STDERR_LOG}
comm -23 ${_TMP_INCL_FILE} ${_TMP_EXCL_FILE} 2>>${HC_STDERR_LOG} >${_TMP1_FILE}
# check discovered objects
while read _FILE_TO_CHECK
do
# reset variables
_STC=0
_MSG=""
_IS_NEW=0
# object to check must be a file (and be present)
if [[ ! -f ${_FILE_TO_CHECK} ]]
then
_MSG="${_FILE_TO_CHECK} is not a file or has disappeared"
_STC=1
log_hc "$0" ${_STC} "${_MSG}"
continue
fi
# read entry from state file
_STATE_FILE_LINE=$(grep -E -e "^${_FILE_TO_CHECK}\|" ${_STATE_FILE})
if [[ -n "${_STATE_FILE_LINE}" ]]
then
# field 1 is the file name
_STATE_FILE_TYPE=$(print "${_STATE_FILE_LINE}" | cut -f2 -d'|')
_STATE_FILE_CKSUM=$(print "${_STATE_FILE_LINE}" | cut -f3 -d'|')
else
_IS_NEW=1
fi
# compute new checksum (keep the same type as before)
if (( _IS_NEW == 0 ))
then
case "${_STATE_FILE_TYPE}" in
openssl-sha256)
if (( _USE_OPENSSL == 1 ))
then
_FILE_CKSUM=$(${_OPENSSL_BIN} dgst -sha256 ${_FILE_TO_CHECK} 2>>${HC_STDERR_LOG} | cut -f2 -d'=' | tr -d ' ')
_FILE_TYPE="openssl-sha256"
else
_MSG="cannot compute checksum [${_FILE_TYPE}] for ${_FILE_TO_CHECK}"
_STC=1
fi
;;
cksum-crc32)
if (( _USE_CKSUM == 1 ))
then
_FILE_CKSUM=$(${_CKSUM_BIN} ${_FILE_TO_CHECK} 2>>${HC_STDERR_LOG} | cut -f1 -d' ')
_FILE_TYPE="cksum-crc32"
else
_MSG="cannot compute checksum [${_FILE_TYPE}] for ${_FILE_TO_CHECK}"
_STC=1
fi
;;
*)
_MSG="cannot compute checksum (unknown checksum type) for ${_FILE_TO_CHECK}"
_STC=1
;;
esac
else
# new file
if (( _USE_OPENSSL == 1 ))
then
_FILE_CKSUM=$(${_OPENSSL_BIN} dgst -sha256 ${_FILE_TO_CHECK} 2>>${HC_STDERR_LOG} | cut -f2 -d'=' | tr -d ' ')
_FILE_TYPE="openssl-sha256"
elif (( _USE_CKSUM == 1 ))
then
_FILE_CKSUM=$(${_CKSUM_BIN} ${_FILE_TO_CHECK} 2>>${HC_STDERR_LOG} | cut -f1 -d' ')
_FILE_TYPE="cksum-crc32"
else
_MSG="cannot compute checksum (openssl/cksum) for ${_FILE_TO_CHECK}"
_STC=1
fi
fi
# check for failed checksums
if [[ -z "${_FILE_CKSUM}" ]]
then
_MSG="did not receive checksum (openssl/cksum) for ${_FILE_TO_CHECK}"
_STC=1
fi
# bounce failures back and jump to next file
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
continue
fi
if (( _IS_NEW == 0 ))
then
# compare old vs new checksums
if [[ "${_STATE_FILE_CKSUM}" != "${_FILE_CKSUM}" ]]
then
_MSG="${_FILE_TO_CHECK} has a changed checksum [${_FILE_TYPE}]"
_STC=1
else
_MSG="${_FILE_TO_CHECK} has the same checksum [${_FILE_TYPE}]"
_STC=0
fi
else
_MSG="${_FILE_TO_CHECK} is a new file [${_FILE_TYPE}]"
_STC=0
fi
# save entry to temp file
printf "%s|%s|%s\n" "${_FILE_TO_CHECK}" "${_FILE_TYPE}" "${_FILE_CKSUM}" >>${_TMP2_FILE}
# report with curr/exp values
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)
if (( ARG_LOG > 0 ))
then
[[ -s ${_TMP2_FILE} ]] || {
warn "no files found to check, zeroing new state file"
}
mv ${_TMP2_FILE} ${_STATE_FILE} >/dev/null 2>&1
(( $? > 0 )) && {
warn "failed to move temporary state file"
return 1
}
fi
# do cleanup
[[ -f ${_TMP1_FILE} ]] && rm -f ${_TMP1_FILE} >/dev/null 2>&1
[[ -f ${_TMP2_FILE} ]] && rm -f ${_TMP2_FILE} >/dev/null 2>&1
[[ -f ${_TMP_INCL_FILE} ]] && rm -f ${_TMP_INCL_FILE} >/dev/null 2>&1
[[ -f ${_TMP_EXCL_FILE} ]] && rm -f ${_TMP_EXCL_FILE} >/dev/null 2>&1
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with parameters:
log_healthy=<yes|no>
and formatted stanzas:
incl:<full path>
excl:<full path>
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
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+129
View File
@@ -0,0 +1,129 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_aix_fs_mounts.sh
#******************************************************************************
# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_aix_fs_mounts
# DOES: see _show_usage()
# EXPECTS: n/a
# REQUIRES: data_comma2space(), init_hc(), log_hc()
#
# @(#) 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!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_aix_fs_mounts
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="AIX" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _LOG_HEALTHY=0
typeset _FS=""
typeset _FS_COUNT=""
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
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 $?
lsfs -ac >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG}
(( $? == 0)) || return $?
# check for each configured file system (except /)
lsfs -ac 2>/dev/null |\
grep -v -E -e '^#' -e '^\/:' |\
grep -E -e '.*:.*:.*:.*:.*:.*:.*:yes:.*' |\
cut -f1 -d':' |\
while read _FS
do
_FS_COUNT=$(grep -c -E -e ".*[ \t]*+${_FS}[ \t].*" ${HC_STDOUT_LOG} 2>/dev/null)
case ${_FS_COUNT} in
0)
_MSG="${_FS} is not mounted"
_STC=1
;;
1)
_MSG="${_FS} is mounted"
;;
*)
_MSG="${_FS} is multiple times mounted?"
;;
esac
# report result
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
_STC=0
done
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
PURPOSE : Checks whether file systems are mounted or not {lsfs/mount}
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+111
View File
@@ -0,0 +1,111 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_aix_lppchk.sh
#******************************************************************************
# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_aix_lppchk
# DOES: see _show_usage()
# EXPECTS: n/a
# REQUIRES: data_comma2space(), init_hc(), log_hc()
#
# @(#) 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!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_aix_lppchk
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="AIX" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _LOG_HEALTHY=0
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
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 $?
# perform check
if [[ -s ${HC_STDOUT_LOG} ]]
then
_MSG="lppchk detected errors {lppchk -v -m1}"
_STC=1
else
_MSG="lppchk passed without errors"
fi
# report result
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
PURPOSE : Run {lppchk -v}
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+115
View File
@@ -0,0 +1,115 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_aix_paths.sh
#******************************************************************************
# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_aix_paths
# DOES: see _show_usage()
# EXPECTS: n/a
# REQUIRES: data_comma2space(), init_hc(), log_hc()
#
# @(#) 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!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_aix_paths
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="AIX" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _LOG_HEALTHY=0
typeset _PATH=""
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
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 $?
# perform check
_PATH=$(grep -v -c "Enabled" ${HC_STDOUT_LOG} 2>/dev/null)
case ${_PATH} in
0)
_MSG="all paths are enabled"
;;
*)
_MSG="failure in some paths detected {lspath}"
_STC=1
;;
esac
# report result
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
PURPOSE : Checks whether any hardware paths are missing {lspath}
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+157
View File
@@ -0,0 +1,157 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_aix_root_crontab
#******************************************************************************
# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_aix_root_crontab
# DOES: see _show_usage()
# EXPECTS: n/a
# REQUIRES: data_comma2space(), init_hc(), log_hc()
#
# @(#) 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!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_aix_root_crontab
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="AIX" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
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}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
esac
done
# handle configuration file
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
if [[ ! -r ${_CONFIG_FILE} ]]
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 -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}")
case ${_CRON_MATCH} in
0)
_MSG="'${_CRON_ENTRY}' is not configured in cron"
_STC=1
;;
1)
_MSG="'${_CRON_ENTRY}' is configured in cron"
;;
+([0-9])*([0-9]))
_MSG="'${_CRON_ENTRY}' is configured multiple times in cron"
;;
esac
# report result
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
_STC=0
done
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with parameters:
log_healthy=<yes|no>
and formatted stanzas:
cron:<cron_entry>
PURPOSE : Checks the content of the 'root' user crontab for required entries
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+143
View File
@@ -0,0 +1,143 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_aix_subsystems.sh
#******************************************************************************
# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_aix_subsystems
# DOES: see _show_usage()
# EXPECTS: see _show_usage()
# REQUIRES: data_comma2space(), init_hc(), log_hc()
#
# @(#) 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!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_aix_subsystems
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="AIX" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
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}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
esac
done
# handle configuration file
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
if [[ ! -r ${_CONFIG_FILE} ]]
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 -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
*active*)
_MSG="${_SUBSYS} is running"
;;
*inoperative*)
_MSG="${_SUBSYS} is not running"
_STC=1
;;
*)
_MSG="${_SUBSYS} is not on file"
;;
esac
# report result
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
_STC=0
done
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with parameters:
log_healthy=<yes|no>
and formatted stanzas:
subsys:<subsystem_name>
PURPOSE : Checks whether subsystem(s) are active/operative {lssrc}
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+230
View File
@@ -0,0 +1,230 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_aix_sysbackup.sh
#******************************************************************************
# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_aix_sysbackup
# DOES: see _show_usage()
# EXPECTS: see _show_usage()
# REQUIRES: data_comma2space(), init_hc(), log_hc()
#
# @(#) 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!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_aix_sysbackup
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
# mksysb identifier prefix of error code(s)
typeset _MKSYSB_NEEDLE="^0512"
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="AIX" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
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=""
typeset _BACKUP_AGE=0
typeset _MKSYSB_LOG=""
typeset _MKSYSB_CODE=""
typeset _COUNT=0
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
esac
done
# handle configuration file
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
if [[ ! -r ${_CONFIG_FILE} ]]
then
warn "unable to read configuration file at ${_CONFIG_FILE}"
return 1
fi
# read required configuration values
_BACKUP_PATH=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'backup_path')
if [[ -z "${_BACKUP_PATH}" ]]
then
warn "ERROR: no value for the _BACKUP_PATH setting in ${_CONFIG_FILE}"
return 1
fi
if [[ ! -d ${_BACKUP_PATH} ]]
then
warn "ERROR: ${_BACKUP_PATH} does not exist"
return 1
fi
_MKSYSB_LOG=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'mksysb_log')
if [[ -z "${_MKSYSB_LOG}" ]]
then
warn "ERROR: no value for the _MKSYSB_LOG setting in ${_CONFIG_FILE}"
return 1
fi
_BACKUP_AGE=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'backup_age')
case "${_BACKUP_AGE}" in
+([0-9])*(.)*([0-9]))
# numeric, OK
;;
*)
# not numeric, set default
_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} 2>>${HC_STDERR_LOG} | while read -r _BACKUP_HOST
do
_BACKUP_LOG="${_BACKUP_PATH}/${_BACKUP_HOST}/curr/${_MKSYSB_LOG}"
if [[ -r "${_BACKUP_LOG}" ]]
then
# read status from log file
_MKSYSB_CODE=$(grep -E -e "${_MKSYSB_NEEDLE}" ${_BACKUP_LOG} 2>/dev/null)
case "${_MKSYSB_CODE}" in
# 0512-038 mksysb: Backup Completed Successfully
0512-038*)
_MSG="sysbackup status for ${_BACKUP_HOST}: completed successfully"
;;
# 0512-003 mksysb may not have been able to archive some files
0512-003*)
_MSG="sysbackup status for ${_BACKUP_HOST}: completed with warnings"
# save log
print "=== ${_BACKUP_HOST} ===" >>${HC_STDOUT_LOG}
cat ${_BACKUP_LOG} >>${HC_STDOUT_LOG}
;;
*)
_MSG="sysbackup status for ${_BACKUP_HOST}: failed"
_STC=1
print "=== ${_BACKUP_HOST} ===" >>${HC_STDOUT_LOG}
cat ${_BACKUP_LOG} >>${HC_STDOUT_LOG}
;;
esac
else
# don't flag this as erroneous, we could drop into this fork for
# VIO servers for example without mksysb but having backupios instead
# caveat emptor: also means that hosts *without* backup go undetected
continue
fi
# 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} 2>>${HC_STDERR_LOG} | while read -r _BACKUP_HOST
do
_BACKUP_LOG="${_BACKUP_PATH}/${_BACKUP_HOST}/curr/${_MKSYSB_LOG}"
if [[ -r "${_BACKUP_LOG}" ]]
then
_COUNT=$(find "${_BACKUP_LOG}" -mtime +${_BACKUP_AGE} | wc -l)
if (( _COUNT == 0 ))
then
_MSG="sysbackup age for ${_BACKUP_HOST}: <=${_BACKUP_AGE} days"
_STC=0
else
_MSG="sysbackup age for ${_BACKUP_HOST}: >${_BACKUP_AGE} days"
_STC=1
print "=== ${_BACKUP_HOST} ===" >>${HC_STDOUT_LOG}
print "age: $(ls -l ${_BACKUP_LOG})" >>${HC_STDOUT_LOG}
fi
else
# don't flag this as erroneous, we could drop into this fork for
# VIO servers for example without mksysb but having backupios instead
# caveat emptor: also means that hosts *without* backup go undetected
continue
fi
# report result
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
_STC=0
done
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with parameters:
log_healthy=<yes|no>
backup_path=<location_of_mksysb_images>
mksysb_log=<name_of_standard_standard_mksysb_log>
backup_age=<days_till_last_backup>
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
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+114
View File
@@ -0,0 +1,114 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_aix_topasrec.sh
#******************************************************************************
# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_aix_topasrec
# DOES: see _show_usage()
# EXPECTS: n/a
# REQUIRES: data_comma2space(), init_hc(), log_hc()
#
# @(#) HISTORY:
# @(#) 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!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_aix_topasrec
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="AIX" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _LOG_HEALTHY=0
typeset _TOPAS=0
typeset _NMON=0
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
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 $?
# perform check
_TOPAS=$(grep -c "bin" ${HC_STDOUT_LOG} 2>/dev/null)
_NMON=$(grep -c "nmon" ${HC_STDOUT_LOG} 2>/dev/null)
_MSG="process checks: nmon=${_NMON}; topasrec=${_TOPAS}"
if (( _NMON > 1 || _TOPAS > 1 ))
then
_STC=1
fi
# report result
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
PURPOSE : Checks on the active topasrec/nmon processes (only 1 should be running)
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+477
View File
@@ -0,0 +1,477 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_exadata_zfs_logs.sh
#******************************************************************************
# @(#) Copyright (C) 2019 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_exadata_zfs_logs
# DOES: see _show_usage()
# EXPECTS: see _show_usage()
# REQUIRES: data_comma2space(), dump_logs(), init_hc(), linux_exec_ssh(),
# log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2019-02-18: initial version [Patrick Van der Veken]
# @(#) 2019-03-16: replace 'which' [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_exadata_zfs_logs
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _VERSION="2019-03-16" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _AWK_RC=""
typeset _FILTER=""
typeset _FILTERS=""
typeset _CFG_HEALTHY=""
typeset _LOG_HEALTHY=0
typeset _CFG_SSH_KEY_FILE=""
typeset _CFG_SSH_OPTS=""
typeset _CFG_SSH_USER=""
typeset _CFG_ZFS_HOSTS=""
typeset _CFG_ZFS_HOST=""
typeset _LAST_LOG_ENTRY=""
typeset _MSG_DESC=""
typeset _MSG_ID=""
typeset _MSG_MODULE=""
typeset _MSG_PRIO=""
typeset _MSG_RESULT=""
typeset _MSG_TEXT=""
typeset _MSG_TYPE=""
typeset _NEW_LAST_LOG_ENTRY=""
typeset _SSH_BIN=""
typeset _SSH_OUTPUT=""
typeset _STATE_FILE=""
typeset _ZFS_SCRIPT=""
typeset _ZFS_LOG=""
typeset _ZFS_DATA=""
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
esac
done
# handle configuration file
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
if [[ ! -r ${_CONFIG_FILE} ]]
then
warn "unable to read configuration file at ${_CONFIG_FILE}"
return 1
fi
# read configuration values
_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
_CFG_SSH_USER=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'ssh_user')
if [[ -z "${_CFG_SSH_USER}" ]]
then
_CFG_SSH_USER="root"
fi
_CFG_SSH_KEY_FILE=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'ssh_key_file')
_CFG_SSH_OPTS=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'ssh_opts')
# add quiet mode
_CFG_SSH_OPTS="${_CFG_SSH_OPTS} -q"
if [[ -n "${_CFG_SSH_KEY_FILE}" ]]
then
if [[ -r "${_CFG_SSH_KEY_FILE}" ]]
then
log "will use SSH key ${_CFG_SSH_KEY_FILE}"
_CFG_SSH_OPTS="${_CFG_SSH_OPTS} -i ${_CFG_SSH_KEY_FILE}"
else
warn "will use SSH key ${_CFG_SSH_KEY_FILE}, but file does not exist"
return 1
fi
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
# check ssh
_SSH_BIN="$(command -v ssh 2>>${HC_STDERR_LOG})"
if [[ ! -x ${_SSH_BIN} || -z "${_SSH_BIN}" ]]
then
warn "SSH is not installed here"
return 1
fi
# gather ZFS hostnames
_CFG_ZFS_HOSTS=$(grep -i -E -e '^zfs:' ${_CONFIG_FILE} 2>/dev/null | cut -f2 -d':' 2>/dev/null | sort -u 2>/dev/null)
if [[ -z "${_CFG_ZFS_HOSTS}" ]]
then
warn "no monitoring rules defined in ${_CONFIG_FILE}"
return 1
fi
# gather ZFS log data
print "${_CFG_ZFS_HOSTS}" | while read -r _CFG_ZFS_HOST
do
# for which log(s)?
grep -i -E -e "^zfs:${_CFG_ZFS_HOST}:" ${_CONFIG_FILE} 2>/dev/null |\
while IFS=':' read -r _ _ _ZFS_LOG _FILTERS
do
# validate _ZFS_LOG & define script settings
case "${_ZFS_LOG}" in
alert|ALERT|Alert)
# define log query script -- DO NOT CHANGE --
_ZFS_SCRIPT="
script
run('maintenance logs select alert');
entries = list();
for (i = 0; i < entries.length; i++) {
try { run('select ' + entries[i]);
printf('%s|%s|%s|%s|%s\n', entries[i], get('timestamp'),
get('uuid'), get('description'), get('type'));
run('cd ..');
} catch (err) { }
}"
# validate _FILTERS
for _FILTER in $(data_comma2space "${_FILTERS}")
do
case "${_FILTER}" in
minor|MINOR|major|MAJOR|CRITICAL|critical)
:
;;
*)
warn "filter value is incorrect for ${_CFG_ZFS_HOST}/${_ZFS_LOG} in configuration file ${_CONFIG_FILE} "
return 1
;;
esac
done
;;
FLTLOG|fltlog|Fltlog)
# define log query script -- DO NOT CHANGE --
_ZFS_SCRIPT="
script
run('maintenance logs select fltlog');
entries = list();
for (i = 0; i < entries.length; i++) {
try { run('select ' + entries[i]);
printf('%s|%s|%s|%s|%s\n', entries[i], get('timestamp'),
get('uuid'), get('desc'), get('type'));
run('cd ..');
} catch (err) { }
}"
# validate _FILTERS
for _FILTER in $(data_comma2space "${_FILTERS}")
do
case "${_FILTER}" in
minor|MINOR|major|MAJOR|CRITICAL|critical)
:
;;
*)
warn "filter value is incorrect for ${_CFG_ZFS_HOST}/${_ZFS_LOG} in configuration file ${_CONFIG_FILE} "
return 1
;;
esac
done
;;
SCRK|scrk|Scrk)
# define log query script -- DO NOT CHANGE --
_ZFS_SCRIPT="
script
run('maintenance logs select scrk');
entries = list();
for (i = 0; i < entries.length; i++) {
try { run('select ' + entries[i]);
printf('%s|%s|%s|%s\n', entries[i], get('timestamp'),
get('description'), get('result'));
run('cd ..');
} catch (err) { }
}"
# validate _FILTERS
for _FILTER in $(data_comma2space "${_FILTERS}")
do
case "${_FILTER}" in
failed|FAILED|OK|ok)
:
;;
*)
warn "filter value is incorrect for ${_CFG_ZFS_HOST}/${_ZFS_LOG} in configuration file ${_CONFIG_FILE} "
return 1
;;
esac
done
;;
SYSTEM|system|System)
# define log query script -- DO NOT CHANGE --
_ZFS_SCRIPT="
script
run('maintenance logs select system');
entries = list();
for (i = 0; i < entries.length; i++) {
try { run('select ' + entries[i]);
printf('%s|%s|%s|%s|%s\n', entries[i], get('timestamp'),
get('module'), get('priority'), get('text'));
run('cd ..');
} catch (err) { }
}"
_FILTERS="error"
;;
*)
warn "log name value is incorrect for ${_CFG_ZFS_HOST}/${_ZFS_LOG} in configuration file ${_CONFIG_FILE} "
return 1
;;
esac
# check state file
_STATE_FILE="${STATE_PERM_DIR}/${_CFG_ZFS_HOST}.${_ZFS_LOG}.logs"
(( ARG_DEBUG > 0 )) && debug "checking/reading state file at ${_STATE_FILE}"
if [[ -r ${_STATE_FILE} ]]
then
_LAST_LOG_ENTRY=$(<"${_STATE_FILE}")
if [[ -z "${_LAST_LOG_ENTRY}" ]]
then
(( ARG_DEBUG > 0 )) && debug "no recorded last log entry for ${_CFG_ZFS_HOST}/${_ZFS_LOG}"
else
(( ARG_DEBUG > 0 )) && debug "recorded last log entry for ${_CFG_ZFS_HOST}/${_ZFS_LOG}: ${_LAST_LOG_ENTRY}"
fi
else
: >${_STATE_FILE}
(( $? > 0 )) && {
warn "failed to create new state file at ${_STATE_FILE}"
return 1
}
log "created new state file at ${_STATE_FILE}"
fi
(( ARG_DEBUG > 0 )) && debug "executing remote ZFS script on ${_CFG_ZFS_HOST} for log ${_ZFS_LOG}"
_SSH_OUTPUT=$(linux_exec_ssh "${_CFG_SSH_OPTS}" "${_CFG_SSH_USER}" "${_CFG_ZFS_HOST}" "${_ZFS_SCRIPT}" 2>>${HC_STDERR_LOG})
if (( $? > 0 )) || [[ -z "${_SSH_OUTPUT}" ]]
then
warn "unable to discover ${_ZFS_LOG} log data on ${_CFG_ZFS_HOST}"
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
continue
else
# parse log lines based on the log source they originated from
_ZFS_DATA=$(print -R "${_SSH_OUTPUT}" |\
awk -F'|' -v zfs_log="${_ZFS_LOG}" -v filters="${_FILTERS}" -v last_entry="${_LAST_LOG_ENTRY}" '
BEGIN {
found_last_entry = 0;
# build search needles/regexes
split (filters, filter_array, ",");
for (word in filter_array) {
filter_needle = filter_needle filter_array[word]"|";
}
# chop last "|"
gsub (/\|$/, "", filter_needle);
zfs_log = tolower(zfs_log);
}
{
# match log data against needle & $_LAST_LOG_ENTRY pointer
if (last_entry == "") {
# match against needle
if (zfs_log == "alert" || zfs_log == "fltlog") {
if (tolower ($5) ~ filter_needle) { print $0 };
}
if (zfs_log == "scrk" || zfs_log == "system") {
if (tolower ($4) ~ filter_needle) { print $0 };
}
} else {
# match against the $_LAST_LOG_ENTRY pointer
if ($1 ~ last_entry) {
found_last_entry = 1;
next;
}
if (found_last_entry > 0) {
# match against needle
if (zfs_log == "alert" || zfs_log == "fltlog") {
if (tolower ($5) ~ filter_needle) { print $0 };
}
if (zfs_log == "scrk" || zfs_log == "system") {
if (tolower ($4) ~ filter_needle) { print $0 };
}
}
}
}
END {
# when we had a log pointer at the start but did not
# encounter it, then we have a problematic situation (could
# be that the log pointer got rotated past the 100 lines query)
# flag this by RC=255 and reset the log pointer to last
# discovered entry (which is only a stopgap solution but the
# best we can come up with)
if (last_entry != "" && found_last_entry == 0) {
exit 255;
}
}' 2>>${HC_STDERR_LOG})
_AWK_RC=$?
# check and reports results
if (( _AWK_RC == 255 ))
then
warn "lost the current log pointer for ${_CFG_ZFS_HOST}/${_ZFS_LOG}"
# rewrite log pointer from the last log entry we discovered
_NEW_LAST_LOG_ENTRY=$(print "${_SSH_OUTPUT}" | tail -1 2>/dev/null | awk -F'|' '{ print $1 }' 2>/dev/null)
if [[ -n "${_NEW_LAST_LOG_ENTRY}" ]]
then
if (( ARG_LOG > 0 ))
then
warn "resetting the current log pointer for ${_CFG_ZFS_HOST}/${_ZFS_LOG} to ${_NEW_LAST_LOG_ENTRY}"
print "${_NEW_LAST_LOG_ENTRY}" >${_STATE_FILE} 2>>${HC_STDERR_LOG}
fi
else
# zero the state file
if (( ARG_LOG > 0 ))
then
warn "null resetting the current log pointer for ${_CFG_ZFS_HOST}/${_ZFS_LOG}"
: >${_STATE_FILE} 2>>${HC_STDERR_LOG}
fi
fi
continue
elif (( _AWK_RC > 0 ))
then
warn "unable to parse log data from ${_CFG_ZFS_HOST}/${_ZFS_LOG}"
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
return 1
else
if [[ -n "${_ZFS_DATA}" ]]
then
# save data to STDOUT
print "${_ZFS_DATA}" >>${HC_STDOUT_LOG}
# filter data based on logs
case "${_ZFS_LOG}" in
alert|ALERT|Alert)
print -R "${_ZFS_DATA}" | while IFS='|' read -r _MSG_ID _ _ _MSG_DESC _MSG_TYPE
do
_MSG="${_MSG_ID} (${_MSG_TYPE}) ${_MSG_DESC}"
log_hc "$0" 1 "${_CFG_ZFS_HOST}/${_ZFS_LOG}: ${_MSG}"
done
;;
FLTLOG|fltlog|Fltlog)
print -R "${_ZFS_DATA}" | while IFS='|' read -r _MSG_ID _ _ _MSG_DESC _MSG_TYPE
do
_MSG="${_MSG_ID} (${_MSG_TYPE}) ${_MSG_DESC}"
log_hc "$0" 1 "${_CFG_ZFS_HOST}/${_ZFS_LOG}: ${_MSG}"
done
;;
SCRK|scrk|Scrk)
print -R "${_ZFS_DATA}" | while IFS='|' read -r _MSG_ID _ _MSG_DESC _MSG_RESULT
do
if [[ "${_MSG_RESULT}" = "OK" ]]
then
_STC=0
else
_STC=1
fi
_MSG="${_MSG_ID} (${_MSG_RESULT}) ${_MSG_DESC}"
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_CFG_ZFS_HOST}/${_ZFS_LOG}: ${_MSG}"
fi
done
;;
SYSTEM|system|System)
print -R "${_ZFS_DATA}" | while IFS='|' read -r _MSG_ID _ _MSG_MODULE _MSG_PRIO _MSG_TEXT
do
_MSG="${_MSG_ID} (${_MSG_PRIO}) ${_MSG_MODULE}: ${_MSG_TEXT}"
log_hc "$0" 1 "${_CFG_ZFS_HOST}/${_ZFS_LOG}: ${_MSG}"
done
;;
esac
else
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
_MSG="no (new) messages discovered from ${_CFG_ZFS_HOST}:/${_ZFS_LOG}"
log_hc "$0" 0 "${_MSG}"
fi
fi
# rewrite log pointer from the last log entry we discovered
_NEW_LAST_LOG_ENTRY=$(print "${_SSH_OUTPUT}" | tail -1 2>/dev/null | awk -F'|' '{ print $1 }' 2>/dev/null )
if (( ARG_LOG > 0 )) && [[ -n "${_NEW_LAST_LOG_ENTRY}" ]]
then
(( ARG_DEBUG > 0 )) && debug "updating last log entry for ${_CFG_ZFS_HOST}/${_ZFS_LOG} to ${_NEW_LAST_LOG_ENTRY}"
print "${_NEW_LAST_LOG_ENTRY}" >${_STATE_FILE} 2>>${HC_STDERR_LOG}
fi
fi
fi
done
done
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with parameters:
log_healthy=<yes|no>
ssh_user=<ssh_user_account>
ssh_key_file=<ssh_private_key_file>
and formatted stanzas of:
zfs:<host_name>:<alert|fltlog|scrk|system>:<filters>
PURPOSE : checks the ZFS logs for (new) entries with particular alert level(s)
Following logs are supported (filters in brackets):
* alert (critical,major,minor)
* fltlog (critical,major,minor)
* system (error)
* scrk (failed)
CLI: zfs > maintenance > logs > select (log) > show
CAVEAT: plugin will use state files to track 'seen' messages. However each
check will only retrieve the default 100 last log entries. So it
is possible that log entries are lost between health checks (this
can be avoided by scheduling the check quicker than the likely
rotation time for 100 log entries).
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+258
View File
@@ -0,0 +1,258 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_exadata_zfs_services.sh
#******************************************************************************
# @(#) Copyright (C) 2019 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_exadata_zfs_services
# DOES: see _show_usage()
# EXPECTS: see _show_usage()
# REQUIRES: data_comma2space(), dump_logs(), init_hc(), linux_exec_ssh(),
# log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2019-02-18: initial version [Patrick Van der Veken]
# @(#) 2019-03-16: replace 'which' [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_exadata_zfs_services
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _VERSION="2019-03-16" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
# usage query script -- DO NOT CHANGE --
# svc1:online
# svc2:disabled
typeset _ZFS_SCRIPT="
script
run('configuration services');
var svcs = children();
for (var i = 0; i < svcs.length; ++i) {
run(svcs[i]);
try {
printf('%0s:%s\n', svcs[i], get('<status>'));
} catch (err) { };
run('done');
}"
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _CFG_HEALTHY=""
typeset _LOG_HEALTHY=0
typeset _CFG_SSH_KEY_FILE=""
typeset _CFG_SSH_OPTS=""
typeset _CFG_SSH_USER=""
typeset _CFG_ZFS_HOSTS=""
typeset _CFG_ZFS_HOST=""
typeset _CFG_ZFS_LINE=""
typeset _SERVICE_NAME=""
typeset _SERVICE_STATE=""
typeset _SSH_BIN=""
typeset _SSH_OUTPUT=""
typeset _ZFS_DATA=""
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
esac
done
# handle configuration file
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
if [[ ! -r ${_CONFIG_FILE} ]]
then
warn "unable to read configuration file at ${_CONFIG_FILE}"
return 1
fi
# read configuration values
_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
_CFG_SSH_USER=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'ssh_user')
if [[ -z "${_CFG_SSH_USER}" ]]
then
_CFG_SSH_USER="root"
fi
_CFG_SSH_KEY_FILE=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'ssh_key_file')
_CFG_SSH_OPTS=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'ssh_opts')
# add quiet mode
_CFG_SSH_OPTS="${_CFG_SSH_OPTS} -q"
if [[ -n "${_CFG_SSH_KEY_FILE}" ]]
then
if [[ -r "${_CFG_SSH_KEY_FILE}" ]]
then
log "will use SSH key ${_CFG_SSH_KEY_FILE}"
_CFG_SSH_OPTS="${_CFG_SSH_OPTS} -i ${_CFG_SSH_KEY_FILE}"
else
warn "will use SSH key ${_CFG_SSH_KEY_FILE}, but file does not exist"
return 1
fi
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
# check ssh
_SSH_BIN="$(command -v ssh 2>>${HC_STDERR_LOG})"
if [[ ! -x ${_SSH_BIN} || -z "${_SSH_BIN}" ]]
then
warn "SSH is not installed here"
return 1
fi
# gather ZFS hostnames (for this we need at least one data line, possibly with wildcards)
_CFG_ZFS_HOSTS=$(grep -i -E -e '^zfs:' ${_CONFIG_FILE} 2>/dev/null | cut -f2 -d':' 2>/dev/null | sort -u 2>/dev/null)
if [[ -z "${_CFG_ZFS_HOSTS}" ]]
then
warn "no monitoring rules defined in ${_CONFIG_FILE}"
return 1
fi
# gather ZFS usage data
print "${_CFG_ZFS_HOSTS}" | while read -r _CFG_ZFS_HOST
do
(( ARG_DEBUG > 0 )) && debug "executing remote ZFS script on ${_CFG_ZFS_HOST}"
_SSH_OUTPUT=$(linux_exec_ssh "${_CFG_SSH_OPTS}" "${_CFG_SSH_USER}" "${_CFG_ZFS_HOST}" "${_ZFS_SCRIPT}" 2>>${HC_STDERR_LOG})
if (( $? > 0 )) || [[ -z "${_SSH_OUTPUT}" ]]
then
warn "unable to discover services data on ${_CFG_ZFS_HOST}"
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
continue
else
# mangle SSH output by prefixing with hostname
print "${_SSH_OUTPUT}" | while read -r _SSH_LINE
do
if [[ -z "${_ZFS_DATA}" ]]
then
_ZFS_DATA="${_CFG_ZFS_HOST}:${_SSH_LINE}"
else
# shellcheck disable=SC1117
_ZFS_DATA="${_ZFS_DATA}\n${_CFG_ZFS_HOST}:${_SSH_LINE}"
fi
done
fi
done
# process usage status data
if [[ -z "${_ZFS_DATA}" ]]
then
_MSG="did not discover any ZFS services data"
_STC=2
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
return 1
fi
grep -E -e '^zfs:' ${_CONFIG_FILE} 2>/dev/null |\
while IFS=':' read -r _ _CFG_ZFS_HOST _CFG_SERVICE_NAME _CFG_SERVICE_STATE
do
if [[ -z "${_CFG_SERVICE_NAME}" ]]
then
warn "value of <service_name> for ${_CFG_ZFS_HOST} is not defined in configuration file ${_CONFIG_FILE}"
continue
fi
case "${_CFG_SERVICE_STATE}" in
online|ONLINE|Online|disabled|DISABLED|Disabled)
:
;;
*)
warn "value of <service_state> for ${_CFG_ZFS_HOST}/${_CFG_SERVICE_NAME} is not correct in configuration file ${_CONFIG_FILE}"
continue
esac
(( ARG_DEBUG > 0 )) && debug "parsing services data for service: ${_CFG_ZFS_HOST}/${_CFG_SERVICE_NAME}"
# perform check
_SERVICE_STATE=$(print "${_ZFS_DATA}" | grep -E -e "^${_CFG_ZFS_HOST}:${_CFG_SERVICE_NAME}:" 2>/dev/null | cut -f3 -d':' 2>/dev/null)
if [[ -n "${_SERVICE_STATE}" ]]
then
if [[ $(data_lc "${_SERVICE_STATE}") != $(data_lc "${_CFG_SERVICE_STATE}") ]]
then
_MSG="state of ${_CFG_ZFS_HOST}/${_CFG_SERVICE_NAME} is incorrect (${_SERVICE_STATE}!=${_CFG_SERVICE_STATE})"
_STC=1
else
_MSG="state of ${_CFG_ZFS_HOST}/${_CFG_SERVICE_NAME} is correct (${_SERVICE_STATE}=${_CFG_SERVICE_STATE})"
_STC=0
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
else
warn "did not find services data for ${_CFG_ZFS_HOST}/${_CFG_SERVICE_NAME}"
continue
fi
done
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with parameters:
log_healthy=<yes|no>
ssh_user=<ssh_user_account>
ssh_key_file=<ssh_private_key_file>
and formatted stanzas of:
zfs:<host_name>:<service_name>:<service_state>
PURPOSE : Checks the state of services for the configured ZFS hosts/shares
CLI: zfs > status > services > show
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
@@ -0,0 +1,339 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_exadata_zfs_share_replication.sh
#******************************************************************************
# @(#) Copyright (C) 2019 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_exadata_zfs_share_replication
# DOES: see _show_usage()
# EXPECTS: see _show_usage()
# REQUIRES: data_comma2space(), data_contains_string(), data_get_lvalue_from_config(),
# dump_logs(), init_hc(), linux_exec_ssh(), log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2019-02-18: initial version [Patrick Van der Veken]
# @(#) 2019-02-19: fix for <unknown> replication value [Patrick Van der Veken]
# @(#) 2019-03-16: replace 'which' [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_exadata_zfs_share_replication
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _VERSION="2019-03-16" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
# replication query script -- DO NOT CHANGE --
# prj1/share1:true:idle:success:111
# prj2/share2:true:idle:success:51
typeset _ZFS_SCRIPT="
script
run('shares replication actions');
actions = list();
for (i = 0; i < actions.length; i++) {
try { run('select ' + actions[i]);
printf('%s:%s:%s:%s\n', get('replication_of'),
get('enabled'),
get('last_result'),
get('replica_lag'));
run('cd ..');
} catch (err) { }
}"
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _CFG_HEALTHY=""
typeset _LOG_HEALTHY=0
typeset _CFG_MAX_REPLICA_LAG=""
typeset _CFG_REPLICATION_LAG=""
typeset _CFG_SSH_KEY_FILE=""
typeset _CFG_SSH_OPTS=""
typeset _CFG_SSH_USER=""
typeset _CFG_ZFS_HOSTS=""
typeset _CFG_ZFS_HOST=""
typeset _CFG_ZFS_LINE=""
typeset _REPLICATION_ENABLED=""
typeset _REPLICATION_LAG=""
typeset _REPLICATION_RESULT=""
typeset _SSH_BIN=""
typeset _SSH_OUTPUT=""
typeset _ZFS_DATA=""
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
esac
done
# handle configuration file
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
if [[ ! -r ${_CONFIG_FILE} ]]
then
warn "unable to read configuration file at ${_CONFIG_FILE}"
return 1
fi
# read configuration values
_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
_CFG_SSH_USER=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'ssh_user')
if [[ -z "${_CFG_SSH_USER}" ]]
then
_CFG_SSH_USER="root"
fi
_CFG_SSH_KEY_FILE=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'ssh_key_file')
_CFG_SSH_OPTS=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'ssh_opts')
# add quiet mode
_CFG_SSH_OPTS="${_CFG_SSH_OPTS} -q"
if [[ -n "${_CFG_SSH_KEY_FILE}" ]]
then
if [[ -r "${_CFG_SSH_KEY_FILE}" ]]
then
log "will use SSH key ${_CFG_SSH_KEY_FILE}"
_CFG_SSH_OPTS="${_CFG_SSH_OPTS} -i ${_CFG_SSH_KEY_FILE}"
else
warn "will use SSH key ${_CFG_SSH_KEY_FILE}, but file does not exist"
return 1
fi
fi
_CFG_MAX_REPLICA_LAG=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'max_replica_lag')
if [[ -z "${_CFG_MAX_REPLICA_LAG}" ]]
then
# default
_CFG_MAX_REPLICA_LAG=90
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
# check ssh
_SSH_BIN="$(command -v ssh 2>>${HC_STDERR_LOG})"
if [[ ! -x ${_SSH_BIN} || -z "${_SSH_BIN}" ]]
then
warn "SSH is not installed here"
return 1
fi
# gather ZFS hostnames
_CFG_ZFS_HOSTS=$(grep -i -E -e '^zfs:' ${_CONFIG_FILE} 2>/dev/null | cut -f2 -d':' 2>/dev/null | sort -u 2>/dev/null)
if [[ -z "${_CFG_ZFS_HOSTS}" ]]
then
warn "no monitoring rules defined in ${_CONFIG_FILE}"
return 1
fi
# gather ZFS replication data
print "${_CFG_ZFS_HOSTS}" | while read -r _CFG_ZFS_HOST
do
(( ARG_DEBUG > 0 )) && debug "executing remote ZFS script on ${_CFG_ZFS_HOST}"
_SSH_OUTPUT=$(linux_exec_ssh "${_CFG_SSH_OPTS}" "${_CFG_SSH_USER}" "${_CFG_ZFS_HOST}" "${_ZFS_SCRIPT}" 2>>${HC_STDERR_LOG})
if (( $? > 0 )) || [[ -z "${_SSH_OUTPUT}" ]]
then
warn "unable to discover replication data on ${_CFG_ZFS_HOST}"
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
continue
else
# mangle SSH output by prefixing with hostname
print "${_SSH_OUTPUT}" | while read -r _SSH_LINE
do
if [[ -z "${_ZFS_DATA}" ]]
then
_ZFS_DATA="${_CFG_ZFS_HOST}:${_SSH_LINE}"
else
# shellcheck disable=SC1117
_ZFS_DATA="${_ZFS_DATA}\n${_CFG_ZFS_HOST}:${_SSH_LINE}"
fi
done
fi
done
# process replication status data
if [[ -z "${_ZFS_DATA}" ]]
then
_MSG="did not discover any ZFS replication data"
_STC=2
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
return 1
fi
print "${_ZFS_DATA}" | while IFS=':' read -r _ZFS_HOST _REPLICATION_NAME _REPLICATION_ENABLED _REPLICATION_RESULT _REPLICATION_LAG
do
(( ARG_DEBUG > 0 )) && debug "parsing replication data for share: ${_ZFS_HOST}:${_REPLICATION_NAME}"
_CFG_REPLICATION_ENABLED=""
_CFG_REPLICATION_RESULT=""
_CFG_REPLICATION_LAG=""
# which values to use (general or custom?), keep in mind wildcards (custom will overrule wildcard entry)
_CFG_ZFS_LINE=$(grep -E -e "^zfs:${_ZFS_HOST}:[*]:" ${_CONFIG_FILE} 2>/dev/null)
if [[ -n "${_CFG_ZFS_LINE}" ]]
then
(( ARG_DEBUG > 0 )) && debug "found wilcard definition for ${_ZFS_HOST} in configuration file ${_CONFIG_FILE}"
_CFG_REPLICATION_ENABLED=$(print "${_CFG_ZFS_LINE}" | cut -f4 -d':' 2>/dev/null)
_CFG_REPLICATION_RESULT=$(print "${_CFG_ZFS_LINE}" | cut -f5 -d':' 2>/dev/null)
_CFG_REPLICATION_LAG=$(print "${_CFG_ZFS_LINE}" | cut -f6 -d':' 2>/dev/null)
# null value means general threshold
if [[ -z "${_CFG_REPLICATION_LAG}" ]]
then
(( ARG_DEBUG > 0 )) && debug "found empty lag threshold for ${_ZFS_HOST}, using general threshold"
_CFG_REPLICATION_LAG=${_CFG_MAX_REPLICATION_LAG}
fi
fi
_CFG_ZFS_LINE=$(grep -E -e "^zfs:${_ZFS_HOST}:${_REPLICATION_NAME}:" ${_CONFIG_FILE} 2>/dev/null)
if [[ -n "${_CFG_ZFS_LINE}" ]]
then
(( ARG_DEBUG > 0 )) && debug "found custom definition for ${_ZFS_HOST}:${_REPLICATION_NAME} in configuration file ${_CONFIG_FILE}"
_CFG_REPLICATION_ENABLED=$(print "${_CFG_ZFS_LINE}" | cut -f4 -d':' 2>/dev/null)
_CFG_REPLICATION_RESULT=$(print "${_CFG_ZFS_LINE}" | cut -f5 -d':' 2>/dev/null)
_CFG_REPLICATION_LAG=$(print "${_CFG_ZFS_LINE}" | cut -f6 -d':' 2>/dev/null)
# null value means general threshold
if [[ -z "${_CFG_REPLICATION_LAG}" ]]
then
(( ARG_DEBUG > 0 )) && debug "found empty lag threshold for ${_ZFS_HOST}, using general threshold"
_CFG_REPLICATION_LAG=${_CFG_MAX_REPLICATION_LAG}
fi
fi
if [[ -n "${_CFG_REPLICATION_LAG}" ]]
then
data_is_numeric "${_CFG_REPLICATION_LAG}"
if (( $? > 0 ))
then
warn "value for <max_replication_lag> is not numeric in configuration file ${_CONFIG_FILE}"
continue
fi
# zero value means disabled check
if (( _CFG_REPLICATION_LAG == 0 ))
then
(( ARG_DEBUG > 0 )) && debug "found zero lag threshold, disabling check"
continue
fi
else
(( ARG_DEBUG > 0 )) && debug "no custom space threshold for ${_ZFS_HOST}:${_REPLICATION_NAME}, using general threshold"
_CFG_REPLICATION_LAG=${_CFG_MAX_REPLICATION_LAG}
fi
# fixed defaults if missing
[[ -z "${_CFG_REPLICATION_ENABLED}" || "${_CFG_REPLICATION_ENABLED}" = '*' ]] && _CFG_REPLICATION_ENABLED="true"
[[ -z "${_CFG_REPLICATION_RESULT}" || "${_CFG_REPLICATION_RESULT}" = '*' ]] && _CFG_REPLICATION_RESULT="success"
# perform checks
# check replication enabled state (active or not?)
if [[ $(data_lc "${_REPLICATION_ENABLED}") != $(data_lc "${_CFG_REPLICATION_ENABLED}") ]]
then
_MSG="state for ${_ZFS_HOST}:${_REPLICATION_NAME} is incorrect [${_REPLICATION_ENABLED}!=${_CFG_REPLICATION_ENABLED}]"
_STC=1
else
_MSG="state for ${_ZFS_HOST}:${_REPLICATION_NAME} is correct [${_REPLICATION_ENABLED}=${_CFG_REPLICATION_ENABLED}]"
_STC=0
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}" "${_REPLICATION_ENABLED}" "${_CFG_REPLICATION_ENABLED}"
fi
# check replication last result (success or not?)
if [[ $(data_lc "${_REPLICATION_RESULT}") != $(data_lc "${_CFG_REPLICATION_RESULT}") ]]
then
_MSG="result for ${_ZFS_HOST}:${_REPLICATION_NAME} is incorrect [${_REPLICATION_RESULT}!=${_CFG_REPLICATION_RESULT}]"
_STC=1
else
_MSG="result for ${_ZFS_HOST}:${_REPLICATION_NAME} is correct [${_REPLICATION_RESULT}=${_CFG_REPLICATION_RESULT}]"
_STC=0
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}" "${_REPLICATION_RESULT}" "${_CFG_REPLICATION_RESULT}"
fi
# check replication lag
# caveat: replication lag is <unknown> at initial replication
data_contains_string "${_REPLICATION_LAG}" "unknown"
if (( $? > 0 ))
then
_MSG="lag for ${_ZFS_HOST}:${_REPLICATION_NAME} is unknown"
_REPLICATION_LAG=-1
_STC=1
else
if (( _REPLICATION_LAG > _CFG_REPLICATION_LAG ))
then
_MSG="lag for ${_ZFS_HOST}:${_REPLICATION_NAME} is too big [${_REPLICATION_LAG}>${_CFG_REPLICATION_LAG}]"
_STC=1
else
_MSG="lag for ${_ZFS_HOST}:${_REPLICATION_NAME} is OK [${_REPLICATION_LAG}<=${_CFG_REPLICATION_LAG}]"
_STC=0
fi
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}" "${_REPLICATION_LAG}" "${_CFG_REPLICATION_LAG}"
fi
done
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with parameters:
log_healthy=<yes|no>
ssh_user=<ssh_user_account>
ssh_key_file=<ssh_private_key_file>
max_replication_lag=<general_max_replication>
and formatted stanzas of:
zfs:<host_name>:<replication_name>:<replication_enabled>:<replication_result>:<max_replication_lag>
PURPOSE : Checks the replication state, sync status and maximum lag of the configured ZFS hosts/shares
CLI: zfs > shares > replications > packages > select (action) > show
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
@@ -0,0 +1,301 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_exadata_zfs_share_usage.sh
#******************************************************************************
# @(#) Copyright (C) 2019 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_exadata_zfs_share_usage
# DOES: see _show_usage()
# EXPECTS: see _show_usage()
# REQUIRES: data_comma2space(), dump_logs(), init_hc(), linux_exec_ssh(),
# log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2019-02-18: initial version [Patrick Van der Veken]
# @(#) 2019-03-16: replace 'which' [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_exadata_zfs_share_usage
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _VERSION="2019-03-16" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
# usage query script -- DO NOT CHANGE --
# prj1:share1:16
# prj2:share1:85
typeset _ZFS_SCRIPT="
script
run('shares');
projects = list();
for (i = 0; i < projects.length; i++) {
try { run('select ' + projects[i]);
shares = list();
for (j = 0; j < shares.length; j++) {
try { run('select ' + shares[j]);
printf('%s:%s:%d\n', projects[i], shares[j],
get('space_data')/get('space_available')*100);
run('cd ..');
} catch (err) { }
}
run('cd ..');
} catch (err) {
throw ('unexpected error occurred');
}
}"
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _CFG_HEALTHY=""
typeset _LOG_HEALTHY=0
typeset _CFG_MAX_SPACE_USAGE=""
typeset _CFG_SSH_KEY_FILE=""
typeset _CFG_SSH_OPTS=""
typeset _CFG_SSH_USER=""
typeset _CFG_SPACE_THRESHOLD=""
typeset _CFG_ZFS_HOSTS=""
typeset _CFG_ZFS_HOST=""
typeset _CFG_ZFS_LINE=""
typeset _PROJECT_NAME=""
typeset _SHARE_NAME=""
typeset _SPACE_USAGE=""
typeset _SSH_BIN=""
typeset _SSH_OUTPUT=""
typeset _ZFS_DATA=""
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
esac
done
# handle configuration file
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
if [[ ! -r ${_CONFIG_FILE} ]]
then
warn "unable to read configuration file at ${_CONFIG_FILE}"
return 1
fi
# read configuration values
_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
_CFG_SSH_USER=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'ssh_user')
if [[ -z "${_CFG_SSH_USER}" ]]
then
_CFG_SSH_USER="root"
fi
_CFG_SSH_KEY_FILE=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'ssh_key_file')
_CFG_SSH_OPTS=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'ssh_opts')
# add quiet mode
_CFG_SSH_OPTS="${_CFG_SSH_OPTS} -q"
if [[ -n "${_CFG_SSH_KEY_FILE}" ]]
then
if [[ -r "${_CFG_SSH_KEY_FILE}" ]]
then
log "will use SSH key ${_CFG_SSH_KEY_FILE}"
_CFG_SSH_OPTS="${_CFG_SSH_OPTS} -i ${_CFG_SSH_KEY_FILE}"
else
warn "will use SSH key ${_CFG_SSH_KEY_FILE}, but file does not exist"
return 1
fi
fi
_CFG_MAX_SPACE_USAGE=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'max_space_usage')
if [[ -z "${_CFG_MAX_SPACE_USAGE}" ]]
then
# default
_CFG_MAX_SPACE_USAGE=90
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
# check ssh
_SSH_BIN="$(command -v ssh 2>>${HC_STDERR_LOG})"
if [[ ! -x ${_SSH_BIN} || -z "${_SSH_BIN}" ]]
then
warn "SSH is not installed here"
return 1
fi
# gather ZFS hostnames (for this we need at least one data line, possibly with wildcards)
_CFG_ZFS_HOSTS=$(grep -i -E -e '^zfs:' ${_CONFIG_FILE} 2>/dev/null | cut -f2 -d':' 2>/dev/null | sort -u 2>/dev/null)
if [[ -z "${_CFG_ZFS_HOSTS}" ]]
then
warn "no monitoring rules defined in ${_CONFIG_FILE}"
return 1
fi
# gather ZFS usage data
print "${_CFG_ZFS_HOSTS}" | while read -r _CFG_ZFS_HOST
do
(( ARG_DEBUG > 0 )) && debug "executing remote ZFS script on ${_CFG_ZFS_HOST}"
_SSH_OUTPUT=$(linux_exec_ssh "${_CFG_SSH_OPTS}" "${_CFG_SSH_USER}" "${_CFG_ZFS_HOST}" "${_ZFS_SCRIPT}" 2>>${HC_STDERR_LOG})
if (( $? > 0 )) || [[ -z "${_SSH_OUTPUT}" ]]
then
warn "unable to discover usage data on ${_CFG_ZFS_HOST}"
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
continue
else
# mangle SSH output by prefixing with hostname
print "${_SSH_OUTPUT}" | while read -r _SSH_LINE
do
if [[ -z "${_ZFS_DATA}" ]]
then
_ZFS_DATA="${_CFG_ZFS_HOST}:${_SSH_LINE}"
else
# shellcheck disable=SC1117
_ZFS_DATA="${_ZFS_DATA}\n${_CFG_ZFS_HOST}:${_SSH_LINE}"
fi
done
fi
done
# process usage status data
if [[ -z "${_ZFS_DATA}" ]]
then
_MSG="did not discover any ZFS share data"
_STC=2
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
return 1
fi
print "${_ZFS_DATA}" | while IFS=':' read -r _ZFS_HOST _PROJECT_NAME _SHARE_NAME _SPACE_USAGE
do
(( ARG_DEBUG > 0 )) && debug "parsing space data for share: ${_ZFS_HOST}:${_PROJECT_NAME}/${_SHARE_NAME}"
_CFG_SPACE_THRESHOLD=""
# which threshold to use (general or custom?), keep in mind wildcards (custom will overrule wildcard entry)
_CFG_ZFS_LINE=$(grep -E -e "^zfs:${_ZFS_HOST}:[*]:[*]:" ${_CONFIG_FILE} 2>/dev/null)
if [[ -n "${_CFG_ZFS_LINE}" ]]
then
(( ARG_DEBUG > 0 )) && debug "found wilcard definition for ${_ZFS_HOST} in configuration file ${_CONFIG_FILE}"
_CFG_SPACE_THRESHOLD=$(print "${_CFG_ZFS_LINE}" | cut -f5 -d':' 2>/dev/null)
# null value means general threshold
if [[ -z "${_CFG_SPACE_THRESHOLD}" ]]
then
(( ARG_DEBUG > 0 )) && debug "found empty space threshold for ${_ZFS_HOST}, using general threshold"
_CFG_SPACE_THRESHOLD=${_CFG_MAX_SPACE_USAGE}
fi
fi
_CFG_ZFS_LINE=$(grep -E -e "^zfs:${_ZFS_HOST}:${_PROJECT_NAME}:${_SHARE_NAME}:" ${_CONFIG_FILE} 2>/dev/null)
if [[ -n "${_CFG_ZFS_LINE}" ]]
then
(( ARG_DEBUG > 0 )) && debug "found custom definition for ${_ZFS_HOST}:${_PROJECT_NAME}/${_SHARE_NAME} in configuration file ${_CONFIG_FILE}"
_CFG_SPACE_THRESHOLD=$(print "${_CFG_ZFS_LINE}" | cut -f5 -d':' 2>/dev/null)
# null value means general threshold
if [[ -z "${_CFG_SPACE_THRESHOLD}" ]]
then
(( ARG_DEBUG > 0 )) && debug "found empty space threshold for ${_ZFS_HOST}:${_PROJECT_NAME}:${_SHARE_NAME}, using general threshold"
_CFG_SPACE_THRESHOLD=${_CFG_MAX_SPACE_USAGE}
fi
fi
if [[ -n "${_CFG_SPACE_THRESHOLD}" ]]
then
data_is_numeric "${_CFG_SPACE_THRESHOLD}"
if (( $? > 0 ))
then
warn "value for <max_space_threshold> is not numeric in configuration file ${_CONFIG_FILE}"
continue
fi
# zero value means disabled check
if (( _CFG_SPACE_THRESHOLD == 0 ))
then
(( ARG_DEBUG > 0 )) && debug "found zero space threshold, disabling check"
continue
fi
else
(( ARG_DEBUG > 0 )) && debug "no custom space threshold for ${_ZFS_HOST}:${_PROJECT_NAME}:${_SHARE_NAME}, using general threshold"
_CFG_SPACE_THRESHOLD=${_CFG_MAX_SPACE_USAGE}
fi
# perform check
if (( _SPACE_USAGE > _CFG_SPACE_THRESHOLD ))
then
_MSG="${_ZFS_HOST}:${_PROJECT_NAME}/${_SHARE_NAME} exceeds its space threshold (${_SPACE_USAGE}%>${_CFG_SPACE_THRESHOLD}%)"
_STC=1
else
_MSG="${_ZFS_HOST}:${_PROJECT_NAME}/${_SHARE_NAME} does not exceed its space threshold (${_SPACE_USAGE}%>${_CFG_SPACE_THRESHOLD}%)"
_STC=0
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}" "${_SPACE_USAGE}" "${_CFG_SPACE_THRESHOLD}"
fi
done
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with parameters:
log_healthy=<yes|no>
ssh_user=<ssh_user_account>
ssh_key_file=<ssh_private_key_file>
max_space_usage=<general_max_space_treshold>
and formatted stanzas of:
zfs:<host_name>:<replication_name>:<replication_enabled>:<replication_result>:<max_space_threshold>
PURPOSE : Checks the space usage for the configured ZFS hosts/shares
CLI: zfs > shares > select (project) > (select share) > show
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+141
View File
@@ -0,0 +1,141 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_hpux_autopath.sh
#******************************************************************************
# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_hpux_autopath
# DOES: see _show_usage().
# EXPECTS: n/a
# REQUIRES: data_comma2space(), init_hc(), log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2013-08-29: initial version [Patrick Van der Veken]
# @(#) 2018-05-20: added dump_logs() [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!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_hpux_autopath
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _AUTOPATH_BIN="/sbin/autopath"
typeset _AUTOPATH_NEEDLE="Failed"
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="HP-UX" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _STC_COUNT=0
typeset _LOG_HEALTHY=0
typeset _AUTOPATH_LINE=""
typeset _DEVICE=""
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
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 autopath presence
if [[ ! -x ${_AUTOPATH_BIN} ]]
then
warn "${_AUTOPATH_BIN} is not installed here"
return 1
fi
# collect autopath info
log "collecting autopath information, this may take a while ..."
${_AUTOPATH_BIN} display >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG}
(( $? > 0 )) && {
_MSG="unable to run {${_AUTOPATH_BIN}}"
log_hc "$0" 1 "${_MSG}"
# dump debug info
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
return 0
}
# check for device failures
grep -E -e "${_AUTOPATH_NEEDLE}" ${HC_STDOUT_LOG} 2>/dev/null |\
while read _AUTOPATH_LINE
do
_DEVICE="$(print ${_AUTOPATH_LINE} | cut -f1 -d' ')"
_MSG="failed path for device '${_DEVICE}'"
_STC=1
_STC_COUNT=$(( _STC_COUNT + 1 ))
# report result
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
_STC=0
done
# report OK situation
if (( _LOG_HEALTHY > 0 && _STC_COUNT == 0 ))
then
_MSG="no failed paths detected by {${_AUTOPATH_BIN}}"
log_hc "$0" 0 "${_MSG}"
fi
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
PURPOSE : Checks whether failed paths exist for StorageWorks disk arrays
using the 'autopath' utility.
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+127
View File
@@ -0,0 +1,127 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_hpux_cdsf_cluster
#******************************************************************************
# @(#) Copyright (C) 2018 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_hpux_cdsf_cluster
# DOES: see _show_usage()
# EXPECTS: n/a
# REQUIRES: data_comma2space(), init_hc(), log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2016-07-21: initial version [Patrick Van der Veken]
# @(#) 2019-01-24: arguments fix [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_hpux_cdsf_cluster
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _VERSION="2019-01-24" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="HP-UX" # uname -s match
typeset _CDSF_BIN="/usr/sbin/io_cdsf_config"
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _LOG_HEALTHY=0
typeset _CDSF_CONFLICTS=""
typeset _CDSF_DEV=""
typeset _CDSF_ENTRY=""
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
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 & get cDSF status
if [[ ! -x ${_CDSF_BIN} ]]
then
warn "${_CDSF_BIN} is not installed here"
return 1
else
# io_cdsf_config outputs on STDERR (run status & check)
# stable cluster: RC=0
${_CDSF_BIN} -s >${HC_STDOUT_LOG} 2>${HC_STDOUT_LOG}
(( $? > 0 )) && {
log_hc "$0" 1 "cDSF cluster has not yet been initialized or is not stable"
return 0
}
# get device conflicts
${_CDSF_BIN} -c >>${HC_STDOUT_LOG} 2>>${HC_STDOUT_LOG}
fi
# do cDSF checks
_CDSF_CONFLICTS=$(grep 'uniq_name:' ${HC_STDOUT_LOG} 2>/dev/null | sort -u 2>/dev/null)
if [[ -n "${_CDSF_CONFLICTS}" ]]
then
print "${_CDSF_CONFLICTS}" | while read -r _CDSF_ENTRY
do
_CDSF_DEV=$(print "${_CDSF_ENTRY}" | cut -f2 -d':' 2>/dev/null | cut -f4 -d'.' 2>/dev/null)
log_hc "$0" 1 "cDSF conflict found for ${_CDSF_DEV}"
done
else
if (( _LOG_HEALTHY > 0 ))
then
log_hc "$0" 0 "no cDSF conflicts found"
fi
fi
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3
PURPOSE : Checks the health of the cDSF cluster (state/conflicts).
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+164
View File
@@ -0,0 +1,164 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_hpux_cron_status.sh
#******************************************************************************
# @(#) Copyright (C) 2019 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_hpux_cron_status
# DOES: see _show_usage()
# EXPECTS: n/a
# REQUIRES: data_comma2space(), init_hc(), log_hc()
#
# @(#) HISTORY:
# @(#) 2018-02-08: initial version [Patrick Van der Veken]µ
# @(#) 2018-02-13: fix to avoid log check if cron is not active [Patrick Van der Veken]
# @(#) 2019-03-16: replace 'which' [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_hpux_cron_status
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CRON_LOG_FILE="/var/adm/cron/log"
typeset _WAIT_TIME=10
typeset _VERSION="2019-02-16" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="HP-UX" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _LOG_HEALTHY=0
typeset _JOB_ID=""
typeset _AT_BIN=""
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
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
# ---- process state ----
# try the pgrep way (note: old pgreps do not support '-c')
(( ARG_DEBUG > 0 )) && debug "checking cron service via pgrep"
(( $(pgrep -u root cron 2>>${HC_STDERR_LOG} | wc -l 2>/dev/null) == 0 )) && _STC=1
# evaluate results
case ${_STC} in
0)
_MSG="cron is running"
;;
1)
_MSG="cron is not running"
;;
*)
_MSG="could not determine status of cron"
;;
esac
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
# return if cron is not running
(( _STC > 0 )) && return 1
fi
# ---- log state ----
_AT_BIN="$(command -v at 2>>${HC_STDERR_LOG})"
if [[ -x ${_AT_BIN} && -n "${_AT_BIN}" ]]
then
# start test job
(( ARG_DEBUG > 0 )) && debug "checking cron log via {${_AT_BIN}}"
(echo "*** CHECK LOG ***" >/dev/null | ${_AT_BIN} now) >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG}
sleep ${_WAIT_TIME}
if (( $(grep -c 'cron may not be running' ${HC_STDERR_LOG} 2>/dev/null) == 0 ))
then
# find job results
_JOB_ID=$(grep -E -e '^job' ${HC_STDERR_LOG} 2>/dev/null | awk '{ print $2}' 2>/dev/null)
if [[ -n "${_JOB_ID}" ]] && (( $(grep -c "${_JOB_ID}" ${_CRON_LOG_FILE} 2>/dev/null) > 0 ))
then
_MSG="cron is logging correctly, schedule via {${_AT_BIN}} OK"
_STC=0
else
_MSG="cron is not logging (correctly), schedule via {${_AT_BIN}} NOK"
_STC=1
fi
else
_MSG="cron is not logging (correctly), schedule via {${_AT_BIN}} NOK"
_STC=1
fi
else
# check cron log itself
(( ARG_DEBUG > 0 )) && debug "checking cron log via file check"
if [[ -r ${_CRON_LOG_FILE} ]] && [[ -s ${_CRON_LOG_FILE} ]]
then
_MSG="cron is logging correctly (${_CRON_LOG_FILE})"
_STC=0
else
_MSG="cron is not logging (correctly) (${_CRON_LOG_FILE})"
_STC=1
fi
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3
PURPOSE : Checks whether cron (CRON) service is running and whether cron is
actually logging to ${_CRON_LOG_FILE}.
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+327
View File
@@ -0,0 +1,327 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_hpux_drd_status.sh
#******************************************************************************
# @(#) Copyright (C) 2018 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_hpux_drd_status
# DOES: see _show_usage()
# EXPECTS: see _show_usage()
# REQUIRES: data_comma2space(), data_get_lvalue_from_config(), data_date2epoch(),
# data_lc(), data_strip_space(), data_strip_outer_space(),
# dump_logs(), init_hc(), log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2018-05-11: initial version [Patrick Van der Veken]
# @(#) 2018-05-20: added dump_logs() [Patrick Van der Veken]
# @(#) 2018-10-18: changed boot status [Patrick Van der Veken]
# @(#) 2018-10-28: fixed (linter) errors [Patrick Van der Veken]
# @(#) 2018-10-31: better result check for DRD output [Patrick Van der Veken]
# @(#) 2019-02-08: fix for mirrored boot disks [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!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_hpux_drd_status
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _DRD_BIN="/opt/drd/bin/drd"
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="HP-UX" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _CFG_HEALTHY=""
typeset _LOG_HEALTHY=0
typeset _RC=0
typeset _CHECK_CLONE=""
typeset _CHECK_SYNC=""
typeset _CLONE_MAX_AGE=30
typeset _SYNC_MAX_AGE=30
typeset _CLONE_DISK=""
typeset _ORIGINAL_DISK=""
typeset _ACTIVE_DISK=""
typeset _BOOTED_DISK=""
typeset _NOW_EPOCH=""
typeset _EFI_CLONE=""
typeset _EFI_ORIGINAL=""
typeset _CLONE_DATE=""
typeset _CLONE_YEAR=""
typeset _CLONE_MONTH=""
typeset _CLONE_DAY=""
typeset _CLONE_HOUR=""
typeset _CLONE_MINUTE=""
typeset _CLONE_SECOND=""
typeset _CLONE_EPOCH=""
typeset _SYNC_DATE=""
typeset _SYNC_YEAR=""
typeset _SYNC_MONTH=""
typeset _SYNC_DAY=""
typeset _SYNC_HOUR=""
typeset _SYNC_MINUTE=""
typeset _SYNC_SECOND=""
typeset _SYNC_EPOCH=""
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
esac
done
# handle configuration file
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
if [[ ! -r ${_CONFIG_FILE} ]]
then
warn "unable to read configuration file at ${_CONFIG_FILE}"
return 1
fi
# read required configuration values
_CHECK_CLONE=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'check_clone')
if [[ -z "${_CHECK_CLONE}" ]]
then
# default
_CHECK_CLONE="yes"
fi
_CLONE_MAX_AGE=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'clone_age')
_CHECK_SYNC=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'check_sync')
if [[ -z "${_CHECK_SYNC}" ]]
then
# default
_CHECK_SYNC="yes"
fi
_SYNC_MAX_AGE=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'sync_age')
_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
# get drd status
if [[ ! -x ${_DRD_BIN} ]]
then
warn "${_DRD_BIN} is not installed here"
return 1
else
log "executing {${_DRD_BIN}} ..."
# drd outputs on STDERR
${_DRD_BIN} status >${HC_STDOUT_LOG} 2>&1
_RC=$?
# check for result in output since _RC is not reliable
grep -q -E -e "succeeded" ${HC_STDOUT_LOG} 2>/dev/null || _RC=1
fi
# check drd status
if (( _RC == 0 ))
then
# convert NOW to epoch (pass date values as quoted parameters)
_NOW_EPOCH=$(data_date2epoch "$(date '+%Y' 2>/dev/null)" "$(date '+%m' 2>/dev/null)" "$(date '+%d' 2>/dev/null)" "$(date '+%H' 2>/dev/null)" "$(date '+%M' 2>/dev/null)" "$(date '+%S' 2>/dev/null)")
# get devices
_ORIGINAL_DISK=$(data_strip_space "$(grep "Original Disk:" ${HC_STDOUT_LOG} 2>/dev/null | cut -f2 -d':')")
_CLONE_DISK=$(data_strip_space "$(grep 'Clone Disk:' ${HC_STDOUT_LOG} 2>/dev/null | cut -f2 -d':')")
_BOOTED_DISK=$(grep "Booted Disk[s]*:" ${HC_STDOUT_LOG} 2>/dev/null | cut -f2 -d'(' | cut -f1 -d ')')
_ACTIVE_DISK=$(grep "Activated Disk:" ${HC_STDOUT_LOG} 2>/dev/null | cut -f2 -d'(' | cut -f1 -d ')')
# check boot status: after a fresh clone -> booted == activated == original
if [[ "${_ORIGINAL_DISK}" = "${_BOOTED_DISK}" ]] &&
[[ "${_ORIGINAL_DISK}" = "${_ACTIVE_DISK}" ]] &&
[[ "${_BOOTED_DISK}" = "${_ACTIVE_DISK}" ]]
then
_MSG="host was booted from original disk (${_ACTIVE_DISK})"
if (( _LOG_HEALTHY > 0 ))
then
log_hc "$0" 0 "${_MSG}"
fi
else
_MSG="host was booted from clone disk (${_ACTIVE_DISK})"
if (( _LOG_HEALTHY > 0 ))
then
log_hc "$0" 0 "${_MSG}"
fi
fi
# check EFI status
_EFI_CLONE=$(data_strip_outer_space "$(grep 'Clone EFI Partition:' ${HC_STDOUT_LOG} 2>/dev/null | cut -f2 -d':')")
if [[ "${_EFI_CLONE}" = "AUTO file present, Boot loader present" ]]
then
_MSG="clone disk ${_CLONE_DISK} has a bootable EFI partition"
if (( _LOG_HEALTHY > 0 ))
then
log_hc "$0" 0 "${_MSG}"
fi
else
_MSG="clone disk ${_CLONE_DISK} does not have a bootable EFI partition"
log_hc "$0" 1 "${_MSG}"
fi
_EFI_ORIGINAL=$(data_strip_outer_space "$(grep 'Original EFI Partition:' ${HC_STDOUT_LOG} 2>/dev/null | cut -f2 -d':')")
if [[ "${_EFI_ORIGINAL}" = "AUTO file present, Boot loader present" ]]
then
_MSG="original disk ${_ORIGINAL_DISK} has a bootable EFI partition"
if (( _LOG_HEALTHY > 0 ))
then
log_hc "$0" 0 "${_MSG}"
fi
else
_MSG="original disk ${_ORIGINAL_DISK} does not have a bootable EFI partition"
log_hc "$0" 1 "${_MSG}"
fi
# check clone age
if [[ $(data_lc "${_CHECK_CLONE}") = "yes" ]]
then
# e.g.: 05/10/18 16:52:21 METDST (always in US format)
_CLONE_DATE=$(data_strip_outer_space "$(grep 'Clone Creation Date:' ${HC_STDOUT_LOG} 2>/dev/null | cut -f2- -d':')")
if [[ "${_CLONE_DATE}" != "None" ]]
then
# split into year/month/day/hour/minute/second
_CLONE_YEAR=$(print "${_CLONE_DATE}" | awk '{ print $1 }' 2>/dev/null | cut -f3 -d'/')
_CLONE_MONTH=$(print "${_CLONE_DATE}" | awk '{ print $1 }' 2>/dev/null | cut -f1 -d'/')
_CLONE_DAY=$(print "${_CLONE_DATE}" | awk '{ print $1 }' 2>/dev/null | cut -f2 -d'/')
_CLONE_HOUR=$(print "${_CLONE_DATE}" | awk '{ print $2 }' 2>/dev/null | cut -f1 -d':')
_CLONE_MINUTE=$(print "${_CLONE_DATE}" | awk '{ print $2 }' 2>/dev/null | cut -f2 -d':')
_CLONE_SECOND=$(print "${_CLONE_DATE}" | awk '{ print $2 }' 2>/dev/null | cut -f3 -d':')
# convert _CLONE_DATE to epoch
_CLONE_EPOCH=$(data_date2epoch "20${_CLONE_YEAR}" "${_CLONE_MONTH}" "${_CLONE_DAY}" "${_CLONE_HOUR}" "${_CLONE_MINUTE}" "${_CLONE_SECOND}")
# check age
if (( _CLONE_EPOCH > (_NOW_EPOCH - (_CLONE_MAX_AGE * 24 * 60 * 60)) ))
then
_MSG="clone age is younger than ${_CLONE_MAX_AGE} days [${_CLONE_DATE}]"
if (( _LOG_HEALTHY > 0 ))
then
log_hc "$0" 0 "${_MSG}"
fi
else
_MSG="clone age is older than ${_CLONE_MAX_AGE} days [${_CLONE_DATE}]"
log_hc "$0" 1 "${_MSG}"
fi
else
_MSG="clone has not yet been created"
log_hc "$0" 1 "${_MSG}"
fi
else
log "not checking age of clone (see ${_CONFIG_FILE})"
fi
# check sync age
if [[ $(data_lc "${_CHECK_SYNC}") = "yes" ]]
then
# e.g.: 05/10/18 16:52:21 METDST (always in US format)
_SYNC_DATE=$(data_strip_outer_space "$(grep 'Last Sync Date:' ${HC_STDOUT_LOG} 2>/dev/null | cut -f2- -d':')")
if [[ "${_SYNC_DATE}" != "None" ]]
then
# split into year/month/day/hour/minute/second
_SYNC_YEAR=$(print "${_SYNC_DATE}" | awk '{ print $1 }' 2>/dev/null | cut -f3 -d'/')
_SYNC_MONTH=$(print "${_SYNC_DATE}" | awk '{ print $1 }' 2>/dev/null | cut -f1 -d'/')
_SYNC_DAY=$(print "${_SYNC_DATE}" | awk '{ print $1 }' 2>/dev/null | cut -f2 -d'/')
_SYNC_HOUR=$(print "${_SYNC_DATE}" | awk '{ print $2 }' 2>/dev/null | cut -f1 -d':')
_SYNC_MINUTE=$(print "${_SYNC_DATE}" | awk '{ print $2 }' 2>/dev/null | cut -f2 -d':')
_SYNC_SECOND=$(print "${_SYNC_DATE}" | awk '{ print $2 }' 2>/dev/null | cut -f3 -d':')
# convert _SYNC_DATE to epoch
_SYNC_EPOCH=$(data_date2epoch "20${_SYNC_YEAR}" "${_SYNC_MONTH}" "${_SYNC_DAY}" "${_SYNC_HOUR}" "${_SYNC_MINUTE}" "${_SYNC_SECOND}")
# check age
if (( _SYNC_EPOCH > (_NOW_EPOCH - (_SYNC_MAX_AGE * 24 * 60 * 60)) ))
then
_MSG="sync age is younger than ${_SYNC_MAX_AGE} days [${_SYNC_DATE}]"
if (( _LOG_HEALTHY > 0 ))
then
log_hc "$0" 0 "${_MSG}"
fi
else
_MSG="sync age is older than ${_SYNC_MAX_AGE} days [${_SYNC_DATE}]"
log_hc "$0" 1 "${_MSG}"
fi
else
_MSG="sync has not yet been executed"
log_hc "$0" 1 "${_MSG}"
fi
else
log "not checking age of sync (see ${_CONFIG_FILE})"
fi
else
_MSG="unable to run command: {${_DRD_BIN}}"
log_hc "$0" 1 "${_MSG}"
# dump debug info
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
return 1
fi
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with parameters:
log_healthy=<yes|no>
check_clone=<yes|no>
clone_age=<max_age_of_clone_in_days>
check_sync=<yes|no>
sync_age=<max_age_of_sync_in_days>
PURPOSE : Checks whether the DRD clone was correctly created
Checks for correct EFI partitions
Checks the age of the DRD clone and/or sync
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+213
View File
@@ -0,0 +1,213 @@
>#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_hpux_file_age.sh
#******************************************************************************
# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_hpux_file_age
# DOES: see _show_usage()
# EXPECTS: see _show_usage()
# REQUIRES: Perl, data_comma2space(), data_is_numeric(), init_hc(),
# log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2013-05-27: initial version [Patrick Van der Veken]
# @(#) 2013-05-29: added local trap for cleanup [Patrick Van der Veken]
# @(#) 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 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!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_hpux_file_age
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="HP-UX" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _CFG_HEALTHY=""
typeset _LOG_HEALTHY=0
typeset _REF_FILE="${TMP_DIR}/.$0.ref.$$"
typeset _DO_REF=0
typeset _ENTRY=""
typeset _FILE_PATH=""
typeset _FILE_AGE=""
typeset _FILE_NAME=""
typeset _FILE_DIR=""
typeset _IS_OLD_STYLE=0
# set local trap for cleanup
# shellcheck disable=SC2064
trap "[[ -f ${_REF_FILE} ]] && rm -f ${_REF_FILE} >/dev/null 2>&1; return 1" 1 2 3 15
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
esac
done
# handle configuration file
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
if [[ ! -r ${_CONFIG_FILE} ]]
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 -E -e "^file:" ${_CONFIG_FILE} 2>/dev/null | while IFS=":" read -r _ _FILE_PATH _FILE_AGE
do
# split file/dir
_FILE_NAME=$(print "${_FILE_PATH##*/}")
_FILE_DIR=$(print "${_FILE_PATH%/*}")
# check config
if [[ -z "${_FILE_PATH}" ]] && [[ -z "${_FILE_AGE}" ]]
then
warn "missing values in configuration file at ${_CONFIG_FILE}"
return 1
fi
data_is_numeric "${_FILE_AGE}"
if (( $? > 0 ))
then
warn "invalid file age value '${_FILE_AGE}' in configuration file at ${_CONFIG_FILE}"
return 1
fi
# calculate reference timestamp & set reference file (once only)
if (( _DO_REF == 0 ))
then
REF_TIME=$(perl -e "use POSIX;\$t=time-(${_FILE_AGE}*60);print(strftime '%m%d%H%M',localtime(\$t))")
if (( $? > 0 ))
then
warn "failed to query reference time (Perl)"
return 1
fi
touch -amt "${REF_TIME}" ${_REF_FILE} >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG}
if (( $? > 0 ))
then
warn "failed to create reference time ${TMP_DIR}"
return 1
fi
_DO_REF=1
fi
sleep 60
# perform check
if [[ ! -r "${_FILE_PATH}" ]]
then
_MSG="unable to read or access requested file at ${_FILE_PATH}"
_STC=1
else
# age check
AGE_CHECK=$(find "${_FILE_DIR}" -type f -name "${_FILE_NAME}" -newer ${_REF_FILE})
if (( $? != 0 ))
then
warn "unable to execute file age test for ${_FILE_PATH}"
return 1
fi
if [[ -z "${AGE_CHECK}" ]]
then
_MSG="file age of ${_FILE_AGE} has expired on ${_FILE_PATH}"
_STC=1
else
_MSG="file age of ${_FILE_AGE} has not expired on ${_FILE_PATH}"
fi
fi
# report result
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
_STC=0
done
# remove reference file
[[ -f ${_REF_FILE} ]] & rm -f ${_REF_FILE} >/dev/null 2>&1
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with parameters:
log_healthy=<yes|no>
and formatted stanzas:
file:<file_path>:<max_age_in_minutes>
PURPOSE : Checks whether given files have been changed in the last n minutes
(requires perl!)
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+411
View File
@@ -0,0 +1,411 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_hpux_file_change.sh
#******************************************************************************
# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_hpux_file_change
# DOES: see _show_usage()
# EXPECTS: see _show_usage()
# REQUIRES: data_comma2space(), init_hc(), log_hc(), warn(),
# openssl (sha256 digest) OR cksum (CRC32 digest)
#
# @(#) HISTORY:
# @(#) 2017-05-18: initial version [Patrick Van der Veken]
# @(#) 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]
# @(#) 2019-03-16: replace 'which' [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_hpux_file_change
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _VERSION="2019-03-16" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="HP-UX" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
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=""
typeset _STATE_FILE_LINE=""
typeset _FILE_TO_CHECK=""
typeset _EXCL_OBJECT=""
typeset _INCL_OBJECT=""
typeset _HAS_OPENSSL=0
typeset _HAS_CKSUM=0
typeset _OPENSSL_BIN=""
typeset _CKSUM_BIN=""
typeset _USE_OPENSSL=0
typeset _USE_CKSUM=0
typeset _TMP1_FILE="${TMP_DIR}/.$0.tmp1.$$"
typeset _TMP2_FILE="${TMP_DIR}/.$0.tmp2.$$"
typeset _TMP_INCL_FILE="${TMP_DIR}/.$0.tmp_incl.$$"
typeset _TMP_EXCL_FILE="${TMP_DIR}/.$0.tmp_excl.$$"
set -o noglob # no file globbing
# set local trap for clean-up
# shellcheck disable=SC2064
trap "[[ -f ${_TMP1_FILE} ]] && rm -f ${_TMP1_FILE} >/dev/null 2>&1;
[[ -f ${_TMP2_FILE} ]] && rm -f ${_TMP2_FILE} >/dev/null 2>&1;
[[ -f ${_TMP_INCL_FILE} ]] && rm -f ${_TMP_INCL_FILE} >/dev/null 2>&1;
[[ -f ${_TMP_EXCL_FILE} ]] && rm -f ${_TMP_EXCL_FILE} >/dev/null 2>&1;
return 1" 1 2 3 15
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
esac
done
# handle configuration file
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
if [[ ! -r ${_CONFIG_FILE} ]]
then
warn "unable to read configuration file at ${_CONFIG_FILE}"
return 1
fi
# read required configuration values
_CFG_STATE_FILE=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'state_file')
if [[ -z "${_CFG_STATE_FILE}" ]]
then
_STATE_FILE="${STATE_PERM_DIR}/discovered.file_change"
else
_STATE_FILE="${STATE_PERM_DIR}/${_CFG_STATE_FILE}"
fi
log "using state file ${_STATE_FILE}"
_DO_META_CHECK=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'do_meta_check')
case "${_DO_META_CHECK}" in
no|NO|No)
_DO_META_CHECK=0
log "check for meta characters is disabled"
;;
*)
_DO_META_CHECK=1
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="$(command -v openssl 2>>${HC_STDERR_LOG})"
[[ -x ${_OPENSSL_BIN} && -n "${_OPENSSL_BIN}" ]] && _HAS_OPENSSL=1
_CKSUM_BIN="$(command -v cksum 2>>${HC_STDERR_LOG})"
[[ -x ${_CKSUM_BIN} && -n "${_CKSUM_BIN}" ]] && _HAS_CKSUM=1
# prefer openssl (for sha256)
if (( _HAS_OPENSSL == 1 ))
then
_USE_OPENSSL=1
elif (( _HAS_CKSUM == 1 ))
then
_USE_CKSUM=1
else
warn "unable to find the 'openssl/cksum' tools"
return 1
fi
# check state file & TMP_FILEs
[[ -r ${_STATE_FILE} ]] || {
: >${_STATE_FILE}
(( $? > 0 )) && {
warn "failed to create new state file at ${_STATE_FILE}"
return 1
}
log "created new state file at ${_STATE_FILE}"
}
: >${_TMP_INCL_FILE}
(( $? > 0 )) && {
warn "failed to create temporary file at ${_TMP_INCL_FILE}"
return 1
}
: >${_TMP_EXCL_FILE}
(( $? > 0 )) && {
warn "failed to create temporary file at ${_TMP_EXCL_FILE}"
return 1
}
: >${_TMP1_FILE}
(( $? > 0 )) && {
warn "failed to create temporary file at ${_TMP1_FILE}"
return 1
}
: >${_TMP2_FILE}
(( $? > 0 )) && {
warn "failed to create temporary file at ${_TMP2_FILE}"
return 1
}
# build list of configured objects: inclusion
grep -i '^incl:' ${_CONFIG_FILE} 2>/dev/null |\
while IFS=':' read _ _INCL_OBJECT
do
# check for meta & globbing characters (*?[]{}|)
if (( _DO_META_CHECK == 1 ))
then
case "${_INCL_OBJECT}" in
*\**|*\?*|*\[*|*\]*|*\{*|*\}*|*\|*)
warn "meta characters are not supported in the entry (incl:${_INCL_OBJECT})"
continue
;;
esac
fi
# expand directories
if [[ -d ${_INCL_OBJECT} ]]
then
find ${_INCL_OBJECT} -type f -xdev >>${_TMP_INCL_FILE} 2>>${HC_STDERR_LOG}
else
print ${_INCL_OBJECT} >>${_TMP_INCL_FILE}
fi
done
# build list of configured objects: exclusion
grep -i '^excl:' ${_CONFIG_FILE} 2>/dev/null |\
while IFS=':' read _ _EXCL_OBJECT
do
# check for meta & globbing characters (*?[]{}|)
if (( _DO_META_CHECK == 1 ))
then
case "${_EXCL_OBJECT}" in
*\**|*\?*|*\[*|*\]*|*\{*|*\}*|*\|*)
warn "meta characters are not supported in the entry (excl:${_EXCL_OBJECT})"
continue
;;
esac
fi
# expand directories
if [[ -d ${_EXCL_OBJECT} ]]
then
find ${_EXCL_OBJECT} -type f -xdev >>${_TMP_EXCL_FILE} 2>>${HC_STDERR_LOG}
else
print ${_EXCL_OBJECT} >>${_TMP_EXCL_FILE}
fi
done
# subtract exclusion from inclusion (exclusion has higher priority)
sort ${_TMP_INCL_FILE} -o ${_TMP_INCL_FILE} 2>>${HC_STDERR_LOG}
sort ${_TMP_EXCL_FILE} -o ${_TMP_EXCL_FILE} 2>>${HC_STDERR_LOG}
comm -23 ${_TMP_INCL_FILE} ${_TMP_EXCL_FILE} 2>>${HC_STDERR_LOG} >${_TMP1_FILE}
# check discovered objects
while read _FILE_TO_CHECK
do
# reset variables
_STC=0
_MSG=""
_IS_NEW=0
# object to check must be a file (and be present)
if [[ ! -f ${_FILE_TO_CHECK} ]]
then
_MSG="${_FILE_TO_CHECK} is not a file or has disappeared"
_STC=1
log_hc "$0" ${_STC} "${_MSG}"
continue
fi
# read entry from state file
_STATE_FILE_LINE=$(grep -E -e "^${_FILE_TO_CHECK}\|" ${_STATE_FILE})
if [[ -n "${_STATE_FILE_LINE}" ]]
then
# field 1 is the file name
_STATE_FILE_TYPE=$(print "${_STATE_FILE_LINE}" | cut -f2 -d'|')
_STATE_FILE_CKSUM=$(print "${_STATE_FILE_LINE}" | cut -f3 -d'|')
else
_IS_NEW=1
fi
# compute new checksum (keep the same type as before)
if (( _IS_NEW == 0 ))
then
case "${_STATE_FILE_TYPE}" in
openssl-sha256)
if (( _USE_OPENSSL == 1 ))
then
_FILE_CKSUM=$(${_OPENSSL_BIN} dgst -sha256 ${_FILE_TO_CHECK} 2>>${HC_STDERR_LOG} | cut -f2 -d'=' | tr -d ' ')
_FILE_TYPE="openssl-sha256"
else
_MSG="cannot compute checksum [${_FILE_TYPE}] for ${_FILE_TO_CHECK}"
_STC=1
fi
;;
cksum-crc32)
if (( _USE_CKSUM == 1 ))
then
_FILE_CKSUM=$(${_CKSUM_BIN} ${_FILE_TO_CHECK} 2>>${HC_STDERR_LOG} | cut -f1 -d' ')
_FILE_TYPE="cksum-crc32"
else
_MSG="cannot compute checksum [${_FILE_TYPE}] for ${_FILE_TO_CHECK}"
_STC=1
fi
;;
*)
_MSG="cannot compute checksum (unknown checksum type) for ${_FILE_TO_CHECK}"
_STC=1
;;
esac
else
# new file
if (( _USE_OPENSSL == 1 ))
then
_FILE_CKSUM=$(${_OPENSSL_BIN} dgst -sha256 ${_FILE_TO_CHECK} 2>>${HC_STDERR_LOG} | cut -f2 -d'=' | tr -d ' ')
_FILE_TYPE="openssl-sha256"
elif (( _USE_CKSUM == 1 ))
then
_FILE_CKSUM=$(${_CKSUM_BIN} ${_FILE_TO_CHECK} 2>>${HC_STDERR_LOG} | cut -f1 -d' ')
_FILE_TYPE="cksum-crc32"
else
_MSG="cannot compute checksum (openssl/cksum) for ${_FILE_TO_CHECK}"
_STC=1
fi
fi
# check for failed checksums
if [[ -z "${_FILE_CKSUM}" ]]
then
_MSG="did not receive checksum (openssl/cksum) for ${_FILE_TO_CHECK}"
_STC=1
fi
# bounce failures back and jump to next file
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
continue
fi
if (( _IS_NEW == 0 ))
then
# compare old vs new checksums
if [[ "${_STATE_FILE_CKSUM}" != "${_FILE_CKSUM}" ]]
then
_MSG="${_FILE_TO_CHECK} has a changed checksum [${_FILE_TYPE}]"
_STC=1
else
_MSG="${_FILE_TO_CHECK} has the same checksum [${_FILE_TYPE}]"
_STC=0
fi
else
_MSG="${_FILE_TO_CHECK} is a new file [${_FILE_TYPE}]"
_STC=0
fi
# save entry to temp file
printf "%s|%s|%s\n" "${_FILE_TO_CHECK}" "${_FILE_TYPE}" "${_FILE_CKSUM}" >>${_TMP2_FILE}
# report with curr/exp values
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)
if (( ARG_LOG > 0 ))
then
[[ -s ${_TMP2_FILE} ]] || {
warn "no files found to check, zeroing new state file"
}
mv ${_TMP2_FILE} ${_STATE_FILE} >/dev/null 2>&1
(( $? > 0 )) && {
warn "failed to move temporary state file"
return 1
}
fi
# do cleanup
[[ -f ${_TMP1_FILE} ]] && rm -f ${_TMP1_FILE} >/dev/null 2>&1
[[ -f ${_TMP2_FILE} ]] && rm -f ${_TMP2_FILE} >/dev/null 2>&1
[[ -f ${_TMP_INCL_FILE} ]] && rm -f ${_TMP_INCL_FILE} >/dev/null 2>&1
[[ -f ${_TMP_EXCL_FILE} ]] && rm -f ${_TMP_EXCL_FILE} >/dev/null 2>&1
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with parameters:
log_healthy=<yes|no>
and formatted stanzas:
incl:<full path>
excl:<full path>
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
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+135
View File
@@ -0,0 +1,135 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_hpux_fs_mounts.sh
#******************************************************************************
# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_hpux_fs_mounts
# DOES: see _show_usage()
# EXPECTS: n/a
# REQUIRES: data_comma2space(), init_hc(), log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2013-05-27: initial version [Patrick Van der Veken]
# @(#) 2016-04-04: exclude dump/swap spaces (...) [Patrick Van der Veken]
# @(#) 2016-07-04: fix for nfs exclusion [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!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_hpux_fs_mounts
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="HP-UX" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _LOG_HEALTHY=0
typeset _FS=""
typeset _FS_COUNT=0
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
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 only)
mount >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG}
if (( $? > 0 ))
then
warn "unable to execute {mount} command"
return 1
fi
# check for each configured file system (except / and dump/swap)
grep -v -E -e '^#' -e '^$' \
-e '[[:space:]]*\/[[:space:]]+' -e '\.\.\.' /etc/fstab 2>/dev/null |\
awk '{print $2}' 2>/dev/null |\
while read _FS
do
_FS_COUNT=$(grep -c -E -e "^${_FS}[ \t]+on.*[ \t]+" ${HC_STDOUT_LOG} 2>/dev/null)
case ${_FS_COUNT} in
0)
_MSG="${_FS} is not mounted"
_STC=1
;;
1)
_MSG="${_FS} is mounted"
;;
*)
_MSG="${_FS} is multiple times mounted?"
;;
esac
# report result
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
_STC=0
done
# add /etc/fstab to STDOUT log
cat /etc/fstab >>${HC_STDOUT_LOG}
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
PURPOSE : Checks whether file systems are mounted or not
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+179
View File
@@ -0,0 +1,179 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_hpux_fs_mounts_options.sh
#******************************************************************************
# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_hpux_fs_mounts_options
# DOES: see _show_usage()
# EXPECTS: see _show_usage()
# REQUIRES: data_comma2space(), init_hc(), log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2016-04-04: original version [Patrick Van der Veken]
# @(#) 2016-12-02: add support for ignore_missing_fs option [Patrick Van der Veken]
# @(#) 2017-07-31: added support for current/expected value output [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!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_hpux_fs_mounts_options
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="HP-UX" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _CFG_HEALTHY=""
typeset _LOG_HEALTHY=0
typeset _CONFIG_FS=""
typeset _CONFIG_OPTS=""
typeset _CURR_OPTS=""
typeset _IGNORE_FS=""
typeset _IS_ACTIVE=0
typeset _FS_ENTRY=""
typeset _CFG_SORTED_OPTS=""
typeset _CURR_SORTED_OPTS=""
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
esac
done
# handle configuration file
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
if [[ ! -r ${_CONFIG_FILE} ]]
then
warn "unable to read configuration file at ${_CONFIG_FILE}"
return 1
fi
# read required configuration values
_IGNORE_FS=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'ignore_missing_fs')
if [[ -z "${_IGNORE_FS}" ]]
then
# default
_IGNORE_FS="yes"
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
# 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 only)
mount >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG}
(( $? == 0)) || return $?
# check for each configured file system
grep -i '^fs:' ${_CONFIG_FILE} 2>/dev/null |\
while IFS=':' read _ _CONFIG_FS _CONFIG_OPTS
do
# check for active FS
_IS_ACTIVE=$(grep -c -E -e "^${_CONFIG_FS}[ \t].*" ${HC_STDOUT_LOG} 2>/dev/null)
if (( _IS_ACTIVE == 0 )) && [[ "${_IGNORE_FS}" = "yes" ]]
then
# ignore event
warn "${_CONFIG_FS} is not active, ignoring in the HC"
continue
else
# find needle in mount output
_FS_ENTRY=$(grep -E -e "^${_CONFIG_FS}[ \t]+on.*" ${HC_STDOUT_LOG} 2>/dev/null)
# get real mount options
_CURR_OPTS=$(print "${_FS_ENTRY}" | awk '{ print $4 }' | sed s'/dev=.*//g')
# get real mount options: compressed & sorted (comma's + 'dev=' deleted)
_CURR_SORTED_OPTS=$(print "${_CURR_OPTS}" | tr -d ',' | sed 's/./&\n/g'| sort | tr -d '\n')
# get options to match: compressed & sorted (comma's deleted)
_CFG_SORTED_OPTS=$(print "${_CONFIG_OPTS}" | tr -d ',' | sed 's/./&\n/g'| sort | tr -d '\n')
# compare strings (also flags FS that are not mounted)
if [[ "${_CURR_SORTED_OPTS}" != "${_CFG_SORTED_OPTS}" ]]
then
_MSG="${_CONFIG_FS} is not mounted with the correct options"
_STC=1
else
_MSG="${_CONFIG_FS} is mounted with the correct options"
fi
fi
# report result
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}" "${_CURR_OPTS}" "${_CONFIG_OPTS}"
fi
_STC=0
done
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with parameters:
log_healthy=<yes|no>
ignore_missing_fs=<yes|no>
and formatted stanzas:
fs:<my_fs1>:<my_fs_opts1>
PURPOSE : Checks whether file systems are mounted with correct options
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+314
View File
@@ -0,0 +1,314 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_hpux_fs_usage.sh
#******************************************************************************
# @(#) Copyright (C) 2019 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_hpux_fs_usage
# DOES: see _show_usage()
# EXPECTS: n/a
# REQUIRES: data_comma2space(), init_hc(), log_hc(), data_is_numeric(), warn()
#
# @(#) HISTORY:
# @(#) 2019-01-24: initial version [Patrick Van der Veken]
# @(#) 2019-01-27: regex fix [Patrick Van der Veken]
# @(#) 2019-01-30: refactored to support custom defintions with all
# filesystems check [Patrick Van der Veken]
# @(#) 2019-02-18: fixes + help update
# @(#) 2019-03-09: text fixes
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_hpux_fs_usage
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="HP-UX" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _CFG_HEALTHY=""
typeset _LOG_HEALTHY=0
typeset _CFG_CHECK_INODES_USAGE=""
typeset _CFG_CHECK_SPACE_USAGE=""
typeset _CFG_MAX_INODES_USAGE=""
typeset _CFG_MAX_SPACE_USAGE=""
typeset _CFG_INODES_THRESHOLD=""
typeset _CFG_SPACE_THRESHOLD=""
typeset _FS=""
typeset _DO_INODES=0
typeset _DO_SPACE=0
typeset _INODES_USAGE=1
typeset _SPACE_USAGE=1
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
check_inodes)
log "enabled check of inodes usage via cmd-line option"
_DO_INODES=1
;;
check_space)
log "enabled check of space usage via cmd-line option"
_DO_SPACE=1
;;
esac
done
# handle configuration file
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
if [[ ! -r ${_CONFIG_FILE} ]]
then
warn "unable to read configuration file at ${_CONFIG_FILE}"
return 1
fi
# read configuration values
_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
_CFG_CHECK_INODES_USAGE=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'check_inodes_usage')
case "${_CFG_CHECK_INODES_USAGE}" in
yes|YES|Yes)
log "enabled check of inodes usage via configuration file"
_DO_INODES=1
;;
*)
: # not set
;;
esac
_CFG_CHECK_SPACE_USAGE=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'check_space_usage')
case "${_CFG_CHECK_SPACE_USAGE}" in
yes|YES|Yes)
log "enabled check of space usage via configuration file"
_DO_SPACE=1
;;
*)
: # not set
;;
esac
_CFG_MAX_INODES_USAGE=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'max_inodes_usage')
if [[ -z "${_CFG_MAX_INODES_USAGE}" ]]
then
# default
_CFG_MAX_INODES_USAGE=90
fi
_CFG_MAX_SPACE_USAGE=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'max_space_usage')
if [[ -z "${_CFG_MAX_SPACE_USAGE}" ]]
then
# default
_CFG_MAX_SPACE_USAGE=90
fi
if (( _DO_INODES == 0 && _DO_SPACE == 0 ))
then
warn "you must enable at least one check (inode and/or space)"
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 (use a rewritten one-liner bdf, remove % signs and invalidate the
# result if we get non-empty STDERR). Output will be FS<space>INODES_%<space>SPACE_%
bdf -il 2>${HC_STDERR_LOG} |\
awk '{gsub(/%/,"");if ($0~/^\//&&NF>2){print $9, $5, $8;};if($0!~/^\//&&NF>2){print $8, $4, $7;}}' >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG}
if [[ -s ${HC_STDERR_LOG} ]]
then
warn "error(s) occurred executing {bdf -il}"
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
return 1
fi
# 1) validate inodes (df -Pil)
if (( _DO_INODES > 0 ))
then
(( ARG_DEBUG > 0 )) && debug "checking inodes..."
grep '^\/' ${HC_STDOUT_LOG} 2>/dev/null | awk '{print $1}' 2>/dev/null |\
while read _FS
do
(( ARG_DEBUG > 0 )) && debug "parsing inodes data for filesystem: ${_FS}"
# add space to grep; must be non-greedy!
_INODES_USAGE=$(grep "^${_FS} " ${HC_STDOUT_LOG} 2>/dev/null | awk '{print $2}' 2>/dev/null)
data_is_numeric "${_INODES_USAGE}"
if (( $? > 0 ))
then
warn "discovered value for inodes usage is incorrect [${_FS}:${_INODES_USAGE}]"
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
continue
fi
# which threshold to use (general or custom?)
_CFG_FS_LINE=$(grep -E -e "^fs:${_FS}:" ${_CONFIG_FILE} 2>/dev/null)
if [[ -n "${_CFG_FS_LINE}" ]]
then
(( ARG_DEBUG > 0 )) && debug "found custom definition for ${_FS} in configuration file ${_CONFIG_FILE}"
_CFG_INODES_THRESHOLD=$(print "${_CFG_FS_LINE}" | cut -f3 -d':' 2>/dev/null)
# null value means general threshold
if [[ -z "${_CFG_INODES_THRESHOLD}" ]]
then
(( ARG_DEBUG > 0 )) && debug "found empty inodes threshold for ${_FS}, using general threshold"
_CFG_INODES_THRESHOLD=${_CFG_MAX_INODES_USAGE}
fi
data_is_numeric "${_CFG_INODES_THRESHOLD}"
if (( $? > 0 ))
then
warn "inodes parameter is not numeric for ${_FS} in configuration file ${_CONFIG_FILE}"
continue
fi
# zero value means disabled check
if (( _CFG_INODES_THRESHOLD == 0 ))
then
(( ARG_DEBUG > 0 )) && debug "found zero inodes threshold for ${_FS}, disabling check"
continue
fi
else
(( ARG_DEBUG > 0 )) && debug "no custom inodes threshold for ${_FS}, using general threshold"
_CFG_INODES_THRESHOLD=${_CFG_MAX_INODES_USAGE}
fi
# check against the tresholdd
if (( _INODES_USAGE > _CFG_INODES_THRESHOLD ))
then
_MSG="${_FS} exceeds its inode threshold (${_INODES_USAGE}%>${_CFG_INODES_THRESHOLD}%)"
_STC=1
else
_MSG="${_FS} does not exceed its inode threshold (${_INODES_USAGE}%<=${_CFG_INODES_THRESHOLD}%)"
_STC=0
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}" "${_INODES_USAGE}" "${_CFG_INODES_THRESHOLD}"
fi
done
fi
# 2) validate space (df -Pl)
if (( _DO_SPACE > 0 ))
then
(( ARG_DEBUG > 0 )) && debug "checking space..."
grep '^\/' ${HC_STDOUT_LOG} 2>/dev/null | awk '{print $1}' 2>/dev/null |\
while read _FS
do
(( ARG_DEBUG > 0 )) && debug "parsing space data for filesystem: ${_FS}"
# add space to grep; must be non-greedy!
_SPACE_USAGE=$(grep -E -e "^${_FS} " ${HC_STDOUT_LOG} 2>/dev/null | awk '{print $3}' 2>/dev/null)
data_is_numeric "${_SPACE_USAGE}"
if (( $? > 0 ))
then
warn "discovered value for space usage is incorrect [${_FS}:${_SPACE_USAGE}]"
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
continue
fi
# which threshold to use (general or custom?)
_CFG_FS_LINE=$(grep -E -e "^fs:${_FS}:" ${_CONFIG_FILE} 2>/dev/null)
if [[ -n "${_CFG_FS_LINE}" ]]
then
(( ARG_DEBUG > 0 )) && debug "found custom definition for ${_FS} in configuration file ${_CONFIG_FILE}"
_CFG_SPACE_THRESHOLD=$(print "${_CFG_FS_LINE}" | cut -f4 -d':' 2>/dev/null)
# null value means general threshold
if [[ -z "${_CFG_SPACE_THRESHOLD}" ]]
then
(( ARG_DEBUG > 0 )) && debug "found empty space threshold for ${_FS}, using general threshold"
_CFG_SPACE_THRESHOLD=${_CFG_MAX_SPACE_USAGE}
fi
data_is_numeric "${_CFG_SPACE_THRESHOLD}"
if (( $? > 0 ))
then
warn "space parameter is not numeric for ${_FS} in configuration file ${_CONFIG_FILE}"
continue
fi
# zero value means disabled check
if (( _CFG_SPACE_THRESHOLD == 0 ))
then
(( ARG_DEBUG > 0 )) && debug "found zero space threshold for ${_FS}, disabling check"
continue
fi
else
(( ARG_DEBUG > 0 )) && debug "no custom space threshold for ${_FS}, using general threshold"
_CFG_SPACE_THRESHOLD=${_CFG_MAX_SPACE_USAGE}
fi
# check against the treshold
if (( _SPACE_USAGE > _CFG_SPACE_THRESHOLD ))
then
_MSG="${_FS} exceeds its space threshold (${_SPACE_USAGE}%>${_CFG_SPACE_THRESHOLD}%)"
_STC=1
else
_MSG="${_FS} does not exceed its space threshold (${_SPACE_USAGE}%<=${_CFG_SPACE_THRESHOLD}%)"
_STC=0
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}" "${_SPACE_USAGE}" "${_CFG_SPACE_THRESHOLD}"
fi
done
fi
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with parameters:
log_healthy=<yes|no>
check_inodes_usage=<yes|no>
check_space_usage=<yes|no>
max_inodes_usage=<general_inodes_usage_treshold>
max_space_usage=<general_space_usage_treshold>
with formatted stanzas (optional):
fs:<fs_name>:<max_inodes_usage_%>:<max_space_usage_%>
EXT OPTIONS : --hc-args=check_inodes, --hc-args=check_space
PURPOSE : Checks the inodes & space usage for the configured or all (local) filesystems
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+145
View File
@@ -0,0 +1,145 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_hpux_guid_status.sh
#******************************************************************************
# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_hpux_guid_status
# DOES: see _show_usage()
# EXPECTS: n/a
# REQUIRES: data_comma2space(), init_hc(), log_hc()
#
# @(#) HISTORY:
# @(#) 2017-05-18: 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 support for --log-healthy [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_hpux_guid_status
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="HP-UX" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _GUID_PID=""
typeset _MSG=""
typeset _STC=0
typeset _LOG_HEALTHY=0
typeset _RC=0
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
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
# ---- process state ----
# 1) try using the PID way
if [[ -r "${_GUID_PID_FILE}" ]]
then
_GUID_PID=$(<${_GUID_PID_FILE})
if [[ -n "${_GUID_PID}" ]]
then
# get PID list without heading
(( $(UNIX95='' ps -o pid= -p ${_GUID_PID}| wc -l) == 0 )) && _STC=1
else
# not running
_RC=1
fi
else
_RC=1
fi
# 2) try the pgrep way (note: old pgreps do not support '-c')
if (( _RC > 0 ))
then
# we need guidkeyd & guidd
(( $(pgrep -P 1 -u root guidd 2>>${HC_STDERR_LOG} | wc -l) == 0 )) && _STC=1
(( $(pgrep -P 1 -u root guidkeyd 2>>${HC_STDERR_LOG} | wc -l) == 0 )) && _STC=$(( _STC + 2 ))
fi
# evaluate results
case ${_STC} in
0)
_MSG="guidd/guidkeyd are running"
;;
1)
_MSG="guidd is not running"
;;
2)
_MSG="guidkeyd is not running"
;;
3)
_MSG="guidd/guidkeyd are not running"
;;
*)
_MSG="could not determine status of GUID daemons"
;;
esac
# report result
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
PURPOSE : Checks whether guid daemons (VSP GUID) are running
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+222
View File
@@ -0,0 +1,222 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_hpux_hpvm_vpar_status.sh
#******************************************************************************
# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_hpux_hpvm_vpar_status
# DOES: see _show_usage()
# EXPECTS: see _show_usage()
# REQUIRES: data_comma2space(), dump_logs(), init_hc(), log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2017-06-01: initial version [Patrick Van der Veken]
# @(#) 2017-06-08: return 1 on error [Patrick Van der Veken]
# @(#) 2018-05-20: added dump_logs() [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!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_hpux_hpvm_vpar_status
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _HPVMSTATUS_BIN="/opt/hpvm/bin/hpvmstatus"
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="HP-UX" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _LINE_COUNT=1
typeset _PAR_ENTRY=""
typeset _PAR_ID=""
typeset _PAR_CFG_STATUS=""
typeset _PAR_RUN_STATUS=""
typeset _PAR_CFG_BOOT=""
typeset _PAR_RUN_BOOT=""
typeset _PAR_ENTRY=""
typeset _PAR_MATCH=""
typeset _MSG=""
typeset _STC=0
typeset _CFG_HEALTHY=""
typeset _LOG_HEALTHY=0
typeset _RC=0
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
esac
done
# handle configuration file
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
if [[ ! -r ${_CONFIG_FILE} ]]
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 "^vpar:" ${_CONFIG_FILE} 2>/dev/null)
if (( _IS_OLD_STYLE == 0 ))
then
warn "no 'vpar:' 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
# check HPVM
if [[ ! -x ${_HPVMSTATUS_BIN} || -z "${_HPVMSTATUS_BIN}" ]]
then
warn "HPVM is not installed here"
return 1
fi
${_HPVMSTATUS_BIN} -M >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG}
(( $? > 0 )) && {
_MSG="unable to run command: {${_HPVMSTATUS_BIN}}"
log_hc "$0" 1 "${_MSG}"
# dump debug info
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
return 0
}
# check configuration values
grep -E -e "^vpar:" ${_CONFIG_FILE} 2>/dev/null | while IFS=":" read -r _ _PAR_ID _PAR_CFG_STATUS _PAR_CFG_BOOT
do
# check configuration
data_is_numeric "${_PAR_ID}"
if (( $? > 0 ))
then
warn "invalid partition ID '${_PAR_ID}' in configuration file ${_CONFIG_FILE} at data line ${_LINE_COUNT}"
fi
case "${_PAR_CFG_STATUS}" in
on|off)
;;
*)
warn "invalid partition status '${_PAR_CFG_STATUS}' in configuration file ${_CONFIG_FILE} at data line ${_LINE_COUNT}"
return 1
;;
esac
case "${_PAR_CFG_BOOT}" in
auto|manual)
;;
*)
warn "invalid partition boot value '${_PAR_CFG_BOOT}' in configuration file ${_CONFIG_FILE} at data line ${_LINE_COUNT}"
return 1
;;
esac
_LINE_COUNT=$(( _LINE_COUNT + 1 ))
done
# perform checks
grep -E -e "^vpar:" ${_CONFIG_FILE} 2>/dev/null | while IFS=":" read -r _ _PAR_ID _PAR_CFG_STATUS _PAR_CFG_BOOT
do
# check run-time values (we need to make the needle sufficiently less greedy)
_PAR_MATCH=$(grep -i "^.*:.*:${_PAR_ID}::Integrity" ${HC_STDOUT_LOG} 2>/dev/null)
if [[ -n "${_PAR_MATCH}" ]]
then
# field split
_PAR_RUN_STATUS=$(data_lc "$(print \"${_PAR_MATCH}\" | cut -f11 -d':')")
_PAR_RUN_BOOT=$(data_lc "$(print \"${_PAR_MATCH}\" | cut -f12 -d':')")
if [[ "${_PAR_RUN_STATUS}" = "${_PAR_CFG_STATUS}" ]]
then
_MSG="partition ${_PAR_ID} has a correct status [${_PAR_RUN_STATUS}]"
_STC=0
else
_MSG="partition ${_PAR_ID} has a wrong status [${_PAR_RUN_STATUS}]"
_STC=1
fi
log_hc "$0" ${_STC} "${_MSG}" "${_PAR_RUN_STATUS}" "${_PAR_CFG_STATUS}"
if [[ "${_PAR_RUN_BOOT}" = "${_PAR_CFG_BOOT}" ]]
then
_MSG="partition ${_PAR_ID} has a correct boot flag [${_PAR_RUN_BOOT}]"
_STC=0
else
_MSG="partition ${_PAR_ID} has a wrong boot flag [${_PAR_RUN_BOOT}]"
_STC=1
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}" "${_PAR_RUN_BOOT}" "${_PAR_CFG_BOOT}"
fi
else
warn "could not determine status for partition ${_PAR_ID} from command output {${_HPVMSTATUS_BIN}}"
_RC=1
fi
done
return ${_RC}
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with parameters:
log_healthy=<yes|no>
and formatted stanzas:
vpar:<parid>:<runtime_status>:<boot_status>
PURPOSE : Checks the status of vPars (on a VSP)
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+160
View File
@@ -0,0 +1,160 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_hpux_httpd_status.sh
#******************************************************************************
# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_hpux_httpd_status
# DOES: see _show_usage()
# EXPECTS: n/a
# REQUIRES: data_comma2space(), init_hc(), log_hc()
#
# @(#) HISTORY:
# @(#) 2017-04-23: 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 support for --log-healthy [Patrick Van der Veken]
# @(#) 2019-03-16: replace 'which' [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_hpux_httpd_status
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _HTTPD_PID_FILE="/var/run/httpd/httpd.pid"
typeset _VERSION="2019-03-16" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="HP-UX" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _HTTPD_BIN=""
typeset _HTTPD_PID=""
typeset _MSG=""
typeset _STC=0
typeset _LOG_HEALTHY=0
typeset _RC=0
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
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
# ---- process state ----
# 1) try using the PID way
if [[ -r "${_HTTPD_PID_FILE}" ]]
then
_HTTPD_PID=$(<${_HTTPD_PID_FILE})
if [[ -n "${_HTTPD_PID}" ]]
then
# get PID list without heading
(( $(UNIX95='' ps -o pid= -p ${_HTTPD_PID}| wc -l) == 0 )) && _STC=1
else
# not running
_RC=1
fi
else
_RC=1
fi
# 2) try the pgrep way (note: old pgreps do not support '-c')
if (( _RC > 0 ))
then
(( $(pgrep -u root httpd 2>>${HC_STDERR_LOG} | wc -l) == 0 )) && _STC=1
fi
# evaluate results
case ${_STC} in
0)
_MSG="httpd is running"
;;
1)
_MSG="httpd is not running"
;;
*)
_MSG="could not determine status of httpd"
;;
esac
# report result
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
# ---- config state ----
_HTTPD_BIN="$(command -v httpd 2>>${HC_STDERR_LOG})"
if [[ -x ${_HTTPD_BIN} && -n "${_HTTPD_BIN}" ]]
then
# validate main configuration
${_HTTPD_BIN} -t >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG}
if (( $? == 0 ))
then
_MSG="httpd configuration files are syntactically correct"
_STC=0
else
_MSG="httpd configuration files have syntax error(s) {httpd -s}"
_STC=1
fi
# report result
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
fi
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
PURPOSE : Checks whether httpd (apache) is running
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+266
View File
@@ -0,0 +1,266 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_hpux_ignite_backup.sh
#******************************************************************************
# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_hpux_ignite_backup
# DOES: see _show_usage()
# EXPECTS: see _show_usage()
# REQUIRES: data_comma2space(), init_hc(), log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2013-05-28: initial version [Patrick Van der Veken]
# @(#) 2016-05-26: added a simple exclusion list for hosts as configurable
# @(#) parameter [Patrick Van der Veken]
# @(#) 2016-06-03: small fix [Patrick Van der Veken]
# @(#) 2018-10-28: fixed (linter) errors [Patrick Van der Veken]
# @(#) 2019-01-24: arguments fix [Patrick Van der Veken]
# @(#) 2019-01-31: improve discovery routine + add log_healthy [Patrick Van der Veken]
# @(#) 2019-03-09: text updates [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_hpux_ignite_backup
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
# backup DONE identifier
typeset _IGNITE_NEEDLE="^DONE"
typeset _IGNITE_SERVER_FILE="/var/opt/ignite/server/ignite.defs"
typeset _IGNITE_CLIENTS_DIR="/var/opt/ignite/clients"
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="HP-UX" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _CFG_HEALTHY=""
typeset _LOG_HEALTHY=0
typeset _BACKUP_AGE=0
typeset _EXCLUDE_HOSTS=""
typeset _IGNITE_HOST=""
typeset _IGNITE_LOG=""
typeset _IGNITE_STATUS=""
typeset _COUNT=0
typeset _OLD_PWD=""
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
esac
done
# handle configuration file
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
if [[ ! -r ${_CONFIG_FILE} ]]
then
warn "unable to read configuration file at ${_CONFIG_FILE}"
return 1
fi
# read required configuration values
_BACKUP_AGE=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'backup_age')
case "${_BACKUP_AGE}" in
+([0-9])*(.)*([0-9]))
# numeric, OK
;;
*)
# not numeric, set default
_BACKUP_AGE=14
;;
esac
log "backup age to check: ${_BACKUP_AGE} days"
_EXCLUDE_HOSTS=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'exclude_hosts')
[[ -n "${_EXCLUDE_HOSTS}" ]] && log "excluding hosts: $(print ${_EXCLUDE_HOSTS})"
_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 if this host is an Ignite-UX server
if [[ ! -f ${_IGNITE_SERVER_FILE} ]]
then
warn "host is not an Ignite-UX server"
return 1
fi
# perform check on Ignite 'client_status' files
if [[ -d ${_IGNITE_CLIENTS_DIR} ]]
then
_OLD_PWD="$(pwd)"
# shellcheck disable=SC2164
cd ${_IGNITE_CLIENTS_DIR}
# shellcheck disable=SC2181
if (( $? > 0 ))
then
warn "unable to run command: {cd ${_IGNITE_CLIENTS_DIR}}"
# dump debug info
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
return 1
fi
# check backup states
find -- * -prune -type l 2>/dev/null | while read -r _IGNITE_HOST
do
# check exclude
[[ "${_EXCLUDE_HOSTS#*${_IGNITE_HOST}}" != "${_EXCLUDE_HOSTS}" ]] && continue
_IGNITE_LOG="${_IGNITE_HOST}/recovery/client_status"
if [[ -r "${_IGNITE_LOG}" ]]
then
# read status from log file
_IGNITE_STATUS=$(grep -E -e "${_IGNITE_NEEDLE}" ${_IGNITE_LOG} 2>/dev/null)
case "${_IGNITE_STATUS}" in
*Complete*)
_MSG="ignite backup status for ${_IGNITE_HOST}: completed successfully"
;;
*Warning*)
_MSG="ignite backup status for ${_IGNITE_HOST}: completed with warnings"
# save log
print "=== ${_IGNITE_HOST} ===" >>${HC_STDOUT_LOG}
cat ${_IGNITE_LOG} >>${HC_STDOUT_LOG}
;;
*Error*)
_MSG="ignite backup status for ${_IGNITE_HOST}: failed"
_STC=1
# save log
print "=== ${_IGNITE_HOST} ===" >>${HC_STDOUT_LOG}
cat ${_IGNITE_LOG} >>${HC_STDOUT_LOG}
;;
*)
_MSG="ignite backup status for ${_IGNITE_HOST}: failed"
_STC=1
# save log
print "=== ${_IGNITE_HOST} ===" >>${HC_STDOUT_LOG}
cat ${_IGNITE_LOG} >>${HC_STDOUT_LOG}
;;
esac
else
_MSG="ignite backup status for ${_IGNITE_HOST}: unknown"
_STC=1
fi
# handle unit result
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
_STC=0
fi
done
# check backup ages
find -- * -prune -type l 2>/dev/null | while read -r _IGNITE_HOST
do
# check exclude
[[ "${_EXCLUDE_HOSTS#*${_IGNITE_HOST}}" != "${_EXCLUDE_HOSTS}" ]] && continue
_IGNITE_LOG="${_IGNITE_HOST}/recovery/client_status"
if [[ -r "${_IGNITE_LOG}" ]]
then
_COUNT=$(find "${_IGNITE_LOG}" -mtime +${_BACKUP_AGE} | wc -l)
if (( _COUNT == 0 ))
then
_MSG="ignite backup age for ${_IGNITE_HOST}: <=${_BACKUP_AGE} days"
_STC=0
else
_MSG="ignite backup age for ${_IGNITE_HOST}: >${_BACKUP_AGE} days"
_STC=1
print "=== ${_IGNITE_HOST} ===" >>${HC_STDOUT_LOG}
print "age: $(ls -l ${_IGNITE_LOG})" >>${HC_STDOUT_LOG}
fi
else
_MSG="ignite backup age for ${_IGNITE_HOST}: unknown"
_STC=1
fi
# handle unit result
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
_STC=0
fi
done
# shellcheck disable=SC2164
cd "${_OLD_PWD}"
# shellcheck disable=SC2181
if (( $? > 0 ))
then
_MSG="unable to run command: {cd ${_IGNITE_CLIENTS_DIR}}"
log_hc "$0" 1 "${_MSG}"
# dump debug info
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
return 1
fi
else
warn "could not access/find the Ignite-UX's clients directory at ${_IGNITE_CLIENTS_DIR}"
return 1
fi
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with parameters:
log_healthy=<yes|no>
backup_age=<days_till_last_backup>
exclude_hosts=<list_of_hosts>
PURPOSE : Checks the state and age of saved Ignite-UX client backups (should only be
run only on the Ignite-UX server). Backups with warnings are considered
to OK. Backups older than \$backup_age will not pass the health check.
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+233
View File
@@ -0,0 +1,233 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_hpux_ioscan.sh
#******************************************************************************
# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_hpux_ioscan
# DOES: see _show_usage()
# EXPECTS: see _show_usage()
# REQUIRES: data_comma2space(), data_comma2pipe(), data_dequote(), dump_logs(),
# init_hc(), log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2013-08-28: initial version [Patrick Van der Veken]
# @(#) 2013-08-29: more verbosity & kernel_mode setting [Patrick Van der Veken]
# @(#) 2016-06-08: introduced _AGILE_VIEW parameter [Patrick Van der Veken]
# @(#) 2016-12-01: more standardized error handling [Patrick Van der Veken]
# @(#) 2018-05-11: small optimizations [Patrick Van der Veken]
# @(#) 2018-05-20: added dump_logs() [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!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_hpux_ioscan
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _IOSCAN_BIN="/usr/sbin/ioscan"
typeset _IOSCAN_OPTS="-Fn"
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="HP-UX" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _STC_COUNT=0
typeset _CFG_HEALTHY=""
typeset _LOG_HEALTHY=0
typeset _CLASS_LINE=""
typeset _IOSCAN_CLASSES=""
typeset _AGILE_VIEW=""
typeset _KERNEL_MODE=""
typeset _IOSCAN_LINE=""
typeset _HW_CLASS=""
typeset _HW_PATH=""
typeset _HW_STATE=""
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
esac
done
# handle configuration file
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
if [[ ! -r ${_CONFIG_FILE} ]]
then
warn "unable to read configuration file at ${_CONFIG_FILE}"
return 1
fi
# read required configuration values
_CLASS_LINE=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'ioscan_classes')
if [[ -z "${_CLASS_LINE}" ]]
then
# default
_IOSCAN_CLASSES="ctl|diag|disk|ext_bus|fc|fcp|i2o|ipmi|lan|lvm|olar|vm"
else
# convert commas and strip quotes
_IOSCAN_CLASSES=$(data_comma2pipe "$(data_dequote \"${_CLASS_LINE}\")")
fi
_KERNEL_MODE=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'kernel_mode')
if [[ -z "${_KERNEL_MODE}" ]]
then
# default
_KERNEL_MODE="yes"
fi
_AGILE_VIEW=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'agile_view')
if [[ -z "${_AGILE_VIEW}" ]]
then
# default
_AGILE_VIEW="yes"
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
# 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 and get ioscan stuff
if [[ ! -x ${_IOSCAN_BIN} ]]
then
warn "${_IOSCAN_BIN} is not installed here"
return 1
else
log "collecting ioscan information, this is may take a while ..."
if [[ "${_KERNEL_MODE}" = "yes" ]] && [[ "${_AGILE_VIEW}" = "yes" ]]
then
_IOSCAN_OPTS="${_IOSCAN_OPTS}Nk"
fi
if [[ "${_KERNEL_MODE}" = "yes" ]] && [[ "${_AGILE_VIEW}" = "no" ]]
then
_IOSCAN_OPTS="${_IOSCAN_OPTS}k"
fi
if [[ "${_KERNEL_MODE}" = "no" ]] && [[ "${_AGILE_VIEW}" = "yes" ]]
then
_IOSCAN_OPTS="${_IOSCAN_OPTS}Nu"
fi
if [[ "${_KERNEL_MODE}" = "no" ]] && [[ "${_AGILE_VIEW}" = "no" ]]
then
_IOSCAN_OPTS="${_IOSCAN_OPTS}u"
fi
log "executing ioscan with options: ${_IOSCAN_OPTS}"
${_IOSCAN_BIN} ${_IOSCAN_OPTS} >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG}
if (( $? > 0 ))
then
_MSG="unable to run command: {${_IOSCAN_BIN}}"
log_hc "$0" 1 "${_MSG}"
# dump debug info
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
return 1
fi
fi
# check for requested device classes
grep -E -e ".*:.*:.*:.*:.*:.*:.*:.*:${_IOSCAN_CLASSES}:.*" ${HC_STDOUT_LOG} 2>/dev/null |\
while read _IOSCAN_LINE
do
# possible states are: CLAIMED, UNCLAIMED, DIFF_HW, NO_HW, ERROR, SCAN
_HW_CLASS="$(print ${_IOSCAN_LINE} | cut -f9 -d':')"
_HW_PATH="$(print ${_IOSCAN_LINE} | cut -f11 -d':')"
_HW_STATE="$(print ${_IOSCAN_LINE} | cut -f16 -d':')"
case "${_HW_STATE}" in
NO_HW)
_MSG="detected NO_HW for device on path '${_HW_PATH}', class '${_HW_CLASS}'"
_STC=1
_STC_COUNT=$(( _STC_COUNT + 1 ))
;;
ERROR)
_MSG="detected ERROR for device on HW path '${_HW_PATH}', class '${_HW_CLASS}'"
_STC=1
_STC_COUNT=$(( _STC_COUNT + 1 ))
;;
*)
# everything else is considered non-fatal (do not report)
continue
esac
# report result
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
_STC=0
done
# report OK situation
if (( _LOG_HEALTHY > 0 && _STC_COUNT == 0 ))
then
_MSG="no problems detected by {${_IOSCAN_BIN}}"
log_hc "$0" 0 "${_MSG}"
fi
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with:
CONFIG : $3 with parameters:
log_healthy=<yes|no>
ioscan_classes=<list_of_device_classes_to_check>
kernel_mode=<yes|no>
agile_view=<yes|no>
PURPOSE : Checks whether 'ioscan' returns errors or not (NO_HW, ERROR)
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+201
View File
@@ -0,0 +1,201 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_hpux_kernel_params.sh
#******************************************************************************
# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_hpux_kernel_params
# DOES: see _show_usage()
# EXPECTS: see _show_usage()
# REQUIRES: data_comma2space(), dump_logs(), init_hc(), log_hc()
#
# @(#) HISTORY:
# @(#) 2017-12-22: original version [Patrick Van der Veken]
# @(#) 2018-01-05: added validation on config values [Patrick Van der Veken]
# @(#) 2018-05-20: added dump_logs() [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!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_hpux_kernel_params
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _KCTUNE_BIN="/usr/sbin/kctune"
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="HP-UX" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _CFG_HEALTHY=""
typeset _LOG_HEALTHY=0
typeset _PARAM_NAME=""
typeset _CONFIG_VALUE=""
typeset _CURR_VALUE=""
typeset _EXPR_VALUE=""
typeset _REPORTED_VALUE=""
typeset _FOUND_PARAM=0
typeset _LINE_COUNT=1
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
esac
done
# handle configuration file
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
if [[ ! -r ${_CONFIG_FILE} ]]
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
# 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 & get kctune information
if [[ ! -x ${_KCTUNE_BIN} ]]
then
warn "kctune is not installed here (not HP-UX 11.31?)"
return 1
else
${_KCTUNE_BIN} >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG}
if (( $? > 0 ))
then
_MSG="unable to gather kctune information"
log_hc "$0" 1 "${_MSG}"
# dump debug info
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
return 0
fi
fi
# check configuration values
grep -i '^param:' ${_CONFIG_FILE} 2>/dev/null |\
while IFS=':' read _ _PARAM_NAME _CONFIG_VALUE
do
# check for empties
if [[ -z "${_PARAM_NAME}" || -z "${_CONFIG_VALUE}" ]]
then
warn "missing parameter name and/or value in configuration file ${_CONFIG_FILE} at data line ${_LINE_COUNT}"
return 1
fi
# check if the kernel parameter is valid
_FOUND_PARAM=$(awk '{ print $1 }' ${HC_STDOUT_LOG} 2>/dev/null | grep -c -E -e "^${_PARAM_NAME}$")
if (( _FOUND_PARAM == 0 ))
then
warn "parameter '${_PARAM_NAME}' in configuration file ${_CONFIG_FILE} at data line ${_LINE_COUNT} is not an existing kernel parameter"
return 1
fi
_LINE_COUNT=$(( _LINE_COUNT + 1 ))
done
# perform checks
grep -i '^param:' ${_CONFIG_FILE} 2>/dev/null |\
while IFS=':' read _ _PARAM_NAME _CONFIG_VALUE
do
# check for actual values and expression values
_CURR_VALUE=$(grep -E -e "^${_PARAM_NAME}[ \t].*" ${HC_STDOUT_LOG} 2>/dev/null | awk '{ print $2 }')
_EXPR_VALUE=$(grep -E -e "^${_PARAM_NAME}[ \t].*" ${HC_STDOUT_LOG} 2>/dev/null | awk '{ print $3 }')
if [[ "${_EXPR_VALUE}" = @(Default|default) ]]
then
if [[ "${_CONFIG_VALUE}" = "${_CURR_VALUE}" ]]
then
_MSG="${_PARAM_NAME} is set with the right value (${_CURR_VALUE})"
else
_MSG="${_PARAM_NAME} has a wrong value (${_CONFIG_VALUE} != ${_CURR_VALUE})"
_STC=1
fi
_REPORTED_VALUE="${_CURR_VALUE}"
else
if [[ "${_CONFIG_VALUE}" = "${_EXPR_VALUE}" ]]
then
_MSG="${_PARAM_NAME} is set with the right expression (${_EXPR_VALUE})"
else
_MSG="${_PARAM_NAME} has a wrong expression (${_CONFIG_VALUE} != ${_EXPR_VALUE})"
_STC=1
fi
_REPORTED_VALUE="${_EXPR_VALUE}"
fi
# report result
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}" "${_REPORTED_VALUE}" "${_CONFIG_VALUE}"
fi
_STC=0
done
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with parameters:
log_healthy=<yes|no>
and formatted stanzas:
param:<param_name>:<param_value>
PURPOSE : Checks kernel parameters have a correct run-time value/expression
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+265
View File
@@ -0,0 +1,265 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_hpux_kernel_usage.sh
#******************************************************************************
# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_hpux_kernel_usage
# DOES: see _show_usage()
# EXPECTS: see _show_usage()
# REQUIRES: data_comma2space(), data_is_numeric(), dump_logs(), init_hc(),
# log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2017-12-22: original version [Patrick Van der Veken]
# @(#) 2018-01-08: extra config checks [Patrick Van der Veken]
# @(#) 2018-01-09: bug fix [Patrick Van der Veken]
# @(#) 2018-05-20: added dump_logs() [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() &
# @(#) support for --log-healthy [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_hpux_kernel_usage
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _KCUSAGE_BIN="/usr/sbin/kcusage"
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="HP-UX" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _CFG_HEALTHY=""
typeset _LOG_HEALTHY=0
typeset _MAX_KCUSAGE=0
typeset _EXCLUDED_PARAMS=""
typeset _HANDLED_PARAMS=""
typeset _PARAM_NAME=""
typeset _CONFIG_VALUE=""
typeset _CEIL_VALUE=""
typeset _CHECK_VALUE=""
typeset _CURR_VALUE=""
typeset _FOUND_PARAM=0
typeset _KCUSAGE_LINE=""
typeset _LINE_COUNT=1
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
esac
done
# handle configuration file
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
if [[ ! -r ${_CONFIG_FILE} ]]
then
warn "unable to read configuration file at ${_CONFIG_FILE}"
return 1
fi
# read required configuration values
_MAX_KCUSAGE=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'max_kcusage')
if [[ -z "${_MAX_KCUSAGE}" ]]
then
# default
_MAX_KCUSAGE=90
fi
_EXCLUDED_PARAMS=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'exclude_params')
if [[ -n "${_EXCLUDED_PARAMS}" ]]
then
log "excluding following kernel parameters: ${_EXCLUDED_PARAMS}"
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
# 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 & get kcusage information
if [[ ! -x ${_KCUSAGE_BIN} ]]
then
warn "kcusage is not installed here (not HP-UX 11.31?)"
return 1
else
${_KCUSAGE_BIN} >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG}
if (( $? > 0 ))
then
_MSG="unable to gather kcusage information"
# dump debug info
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
log_hc "$0" 1 "${_MSG}"
return 0
fi
fi
# check configuration values
grep -i '^param:' ${_CONFIG_FILE} 2>/dev/null |\
while IFS=':' read _ _PARAM_NAME _CONFIG_VALUE
do
# check for empties
if [[ -z "${_PARAM_NAME}" || -z "${_CONFIG_VALUE}" ]]
then
warn "missing parameter name and/or value in configuration file ${_CONFIG_FILE} at data line ${_LINE_COUNT}"
return 1
fi
# check if the kernel parameter is valid
_FOUND_PARAM=$(awk '{ print $1 }' ${HC_STDOUT_LOG} 2>/dev/null | grep -c -E -e "^${_PARAM_NAME}$")
if (( _FOUND_PARAM == 0 ))
then
warn "parameter '${_PARAM_NAME}' in configuration file ${_CONFIG_FILE} at data line ${_LINE_COUNT} is not an existing kernel parameter"
return 1
fi
# check if the threshold value is correct (integer)
data_is_numeric "${_CONFIG_VALUE}"
if (( $? == 0 ))
then
if (( _CONFIG_VALUE < 1 || _CONFIG_VALUE > 99 ))
then
warn "incorrect threshold value '${_CONFIG_VALUE}' in configuration file ${_CONFIG_FILE} at data line ${_LINE_COUNT}"
return 1
fi
else
# not numeric
warn "invalid threshold value '${_CONFIG_VALUE}' in configuration file ${_CONFIG_FILE} at data line ${_LINE_COUNT}"
return 1
fi
_LINE_COUNT=$(( _LINE_COUNT + 1 ))
done
# 1) perform checks (first the invidually configured ones)
grep -i '^param:' ${_CONFIG_FILE} 2>/dev/null |\
while IFS=':' read _ _PARAM_NAME _CONFIG_VALUE
do
# check for actual values and ceilings
_CURR_VALUE=$(grep -E -e "^${_PARAM_NAME}[ \t].*" ${HC_STDOUT_LOG} 2>/dev/null | awk '{ print $2 }')
_CEIL_VALUE=$(grep -E -e "^${_PARAM_NAME}[ \t].*" ${HC_STDOUT_LOG} 2>/dev/null | awk '{ print $4 }')
_CHECK_VALUE=$(( (_CURR_VALUE * 100 ) / _CEIL_VALUE ))
if (( _CHECK_VALUE > _CONFIG_VALUE ))
then
_MSG="${_PARAM_NAME} has exceeded its individual threshold (${_CHECK_VALUE}% > ${_CONFIG_VALUE}%)"
_STC=1
else
_MSG="${_PARAM_NAME} is below its individual threshold (${_CHECK_VALUE}% <= ${_CONFIG_VALUE}%)"
fi
# push to handled list
_HANDLED_PARAMS="${_HANDLED_PARAMS}\n${_PARAM_NAME}"
# report result
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}" "${_CHECK_VALUE}" "${_CONFIG_VALUE}"
fi
_STC=0
done
# perform checks (second the ones mapping the general threshold)
cat ${HC_STDOUT_LOG} 2>/dev/null | tail -n +3 | while read _KCUSAGE_LINE
do
_PARAM_NAME=$(print "${_KCUSAGE_LINE}" | awk '{ print $1 }')
# parameter excluded?
if (( $(print "${_EXCLUDED_PARAMS}" | tr ',' '\n' | grep -c -E -e "${_PARAM_NAME}") != 0 ))
then
(( ARG_DEBUG > 0 )) && debug "excluding kernel parameter ${_PARAM_NAME} ..."
continue
fi
# parameter already handled?
if (( $(print "${_HANDLED_PARAMS}" | grep -c -E -e "${_PARAM_NAME}") == 0 ))
then
# check for actual values and ceilings
_CURR_VALUE=$(print "${_KCUSAGE_LINE}" | awk '{ print $2 }')
_CEIL_VALUE=$(print "${_KCUSAGE_LINE}" | awk '{ print $4 }')
_CHECK_VALUE=$(( (_CURR_VALUE * 100 ) / _CEIL_VALUE ))
if (( _CHECK_VALUE > _MAX_KCUSAGE ))
then
_MSG="${_PARAM_NAME} has exceeded the general threshold (${_CHECK_VALUE}% > ${_MAX_KCUSAGE}%)"
_STC=1
else
_MSG="${_PARAM_NAME} is below the general threshold (${_CHECK_VALUE}% <= ${_MAX_KCUSAGE}%)"
fi
# report result
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}" "${_CHECK_VALUE}" "${_MAX_KCUSAGE}"
fi
_STC=0
fi
done
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with parameters:
log_healthy=<yes|no>
max_kcusage=<threshold_%>
exclude_params=<list_of_excluded_parameters>
and formatted stanzas:
param:<param_name>:<param_value>
PURPOSE : Checks the current usage of kernel paremeter resources
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+274
View File
@@ -0,0 +1,274 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_hpux_lunpaths.sh
#******************************************************************************
# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_hpux_lunpaths
# DOES: see _show_usage()
# EXPECTS: see _show_usage()
# REQUIRES: data_comma2space(), init_hc(), log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2017-12-20: initial version [Patrick Van der Veken]
# @(#) 2018-18-22: reworked discovery routine (accommdate large number of LUNS)
# @(#) [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-09-03: small variable fix [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_hpux_lunpaths
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _IOSCAN_BIN="/usr/sbin/ioscan"
typeset _IOSCAN_OPTS="-C disk -P wwid"
typeset _SCSIMGR_BIN="/usr/sbin/scsimgr"
typeset _SCSIMGR_OPTS="-v get_info all_lun"
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="HP-UX" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _LOG_HEALTHY=0
typeset _TMP1_FILE="${TMP_DIR}/.$0.ioscan_tmp.$$"
typeset _TMP2_FILE="${TMP_DIR}/.$0.scsimgr_tmp.$$"
typeset _HW_PATH=""
typeset _ACTIVE_PATH_COUNT=""
typeset _ALL_PATH_COUNT=""
typeset _FAILED_PATH_COUNT=""
typeset _STANDBY_PATH_COUNT=""
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
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
# set local trap for cleanup
# shellcheck disable=SC2064
trap "[[ -f ${_TMP1_FILE} ]] && rm -f ${_TMP1_FILE} >/dev/null 2>&1;
[[ -f ${_TMP2_FILE} ]] && rm -f ${_TMP2_FILE} >/dev/null 2>&1;
return 1" 1 2 3 15
# check required tools
if [[ ! -x ${_IOSCAN_BIN} ]]
then
warn "${_IOSCAN_BIN} is not installed here"
return 1
fi
if [[ ! -x ${_SCSIMGR_BIN} ]]
then
warn "${_SCSIMGR_BIN} is not installed here"
return 1
fi
# check TMP_FILEs
: >${_TMP1_FILE}
(( $? > 0 )) && {
warn "failed to create temporary file at ${_TMP1_FILE}"
return 1
}
: >${_TMP2_FILE}
(( $? > 0 )) && {
warn "failed to create temporary file at ${_TMP2_FILE}"
return 1
}
# get all disk LUNs
(( ARG_DEBUG > 0 )) && debug "collecting ioscan information"
print "=== ioscan ===" >>${HC_STDOUT_LOG}
${_IOSCAN_BIN} ${_IOSCAN_OPTS} >${_TMP1_FILE} 2>>${HC_STDERR_LOG}
if (( $? > 0 ))
then
_MSG="unable to gather ioscan information"
log_hc "$0" 1 "${_MSG}"
# dump debug info
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
return 1
fi
# collect scsimgr info for all LUNs
(( ARG_DEBUG > 0 )) && debug "collecting scsimgr information"
${_SCSIMGR_BIN} ${_SCSIMGR_OPTS} >${_TMP2_FILE} 2>>${HC_STDERR_LOG}
if (( $? > 0 ))
then
_MSG="unable to gather scsimgr information"
log_hc "$0" 1 "${_MSG}"
# dump debug info
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
return 1
fi
# parse ioscan + scsimgr results (WWID is the glue)
(( ARG_DEBUG > 0 )) && debug "glueing ioscan & scsimgr information together"
awk 'BEGIN { wwid = ""; active_paths = ""; all_paths = ""; failed_paths = ""; standby_paths = ""; }
{
# parse ioscan file (build disks[] array)
#Class I H/W Path wwid
#===============================
#disk 4 64000/0xfa00/0x2 0x60060e8007e2b1000030e2b10000bb68
#disk 5 64000/0xfa00/0x3 0x60060e8007e2b1000030e2b100006040
if (FILENAME ~ /ioscan/) {
if ($0 ~ /^disk/) {
disks[$4] = $3;
}
}
# parse scsimgr file (build paths_*[] arrays)
if (FILENAME ~ /scsimgr/) {
# parse until end of stanza (=empty line)
if ($0 ~ /^World Wide Identifier/ ) {
split ($0, line, "=");
wwid = line[2];
gsub (/ /,"", wwid);
getline;
while ($0 !~ /^$/) {
if ($0 ~ /^LUN path count/) {
split ($0, line, "=");
all_paths = line[2];
gsub (/ /,"", all_paths);
}
if ($0 ~ /^Active LUN paths/) {
split ($0, line, "=");
active_paths = line[2];
gsub (/ /,"", active_paths);
}
if ($0 ~ /^Failed LUN paths/) {
split ($0, line, "=");
failed_paths = line[2];
gsub (/ /,"", failed_paths);
}
if ($0 ~ /^Standby LUN paths/) {
split ($0, line, "=");
standby_paths = line[2];
gsub (/ /,"", standby_paths);
}
if (wwid != "" &&
active_paths != "" &&
all_paths != "" &&
failed_paths != "" &&
standby_paths != "") {
paths_active[wwid] = active_paths;
paths_all[wwid] = all_paths;
paths_failed[wwid] = failed_paths;
paths_standby[wwid] = standby_paths;
# reset variables
wwid = ""; active_paths = "";
all_paths = ""; failed_paths = "";
standby_paths = "";
}
getline;
}
}
}
}
END {
# loop over all disk LUNs to display their SCSI attributes
for (wwid in disks) {
print wwid "|" disks[wwid] "|" paths_active[wwid] "|" paths_all[wwid] "|" paths_failed[wwid] "|" paths_standby[wwid]
}
}' ${_TMP1_FILE} ${_TMP2_FILE} 2>/dev/null |\
while IFS='|' read -r _ _HW_PATH _ACTIVE_PATH_COUNT _ALL_PATH_COUNT _FAILED_PATH_COUNT _STANDBY_PATH_COUNT
do
if [[ -z "${_ACTIVE_PATH_COUNT}" ]] ||
[[ -z "${_ALL_PATH_COUNT}" ]] ||
[[ -z "${_FAILED_PATH_COUNT}" ]] ||
[[ -z "${_STANDBY_PATH_COUNT}" ]]
then
warn "missing info for ${_HW_PATH}, skipping LUN"
continue
fi
# take standby paths out of the total path count (non-cabled FC ports)
_ALL_PATH_COUNT=$(( _ALL_PATH_COUNT - _STANDBY_PATH_COUNT ))
# check for failed paths
if (( _FAILED_PATH_COUNT > 0 ))
then
_MSG="${_HW_PATH}: ${_FAILED_PATH_COUNT} failed lunpath(s)"
_STC=1
else
_MSG="${_HW_PATH}: 0 failed lunpath(s)"
_STC=0
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}" ${_FAILED_PATH_COUNT} ${_ALL_PATH_COUNT}
fi
done
# save ioscan info for posterity
printf "=== ioscan ===" >>${HC_STDOUT_LOG}
cat ${_TMP1_FILE} >>${HC_STDOUT_LOG}
# save scsimgr info for posterity
printf "\n\n=== scsimgr ===" >>${HC_STDOUT_LOG}
cat ${_TMP2_FILE} >>${HC_STDOUT_LOG}
# do cleanup
[[ -f ${_TMP1_FILE} ]] && rm -f ${_TMP1_FILE} >/dev/null 2>&1
[[ -f ${_TMP2_FILE} ]] && rm -f ${_TMP2_FILE} >/dev/null 2>&1
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
PURPOSE : Check the active and failed (non-active) lunpaths of DISK devices
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+161
View File
@@ -0,0 +1,161 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_hpux_named_status.sh
#******************************************************************************
# @(#) Copyright (C) 2016 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_hpux_named_status
# DOES: see _show_usage()
# EXPECTS: n/a
# REQUIRES: data_comma2space(), init_hc(), log_hc()
#
# @(#) HISTORY:
# @(#) 2017-01-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]
# @(#) 2019-03-16: replace 'which' [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_hpux_named_status
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _NAMED_PID_FILE="/var/run/named/named.pid"
typeset _VERSION="2019-03-16" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="HP-UX" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _NAMED_CHECKCONF_BIN=""
typeset _NAMED_PID=""
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _LOG_HEALTHY=0
typeset _RC=0
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
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
# ---- process state ----
# 1) try using the PID way
if [[ -r "${_NAMED_PID_FILE}" ]]
then
_NAMED_PID=$(<${_NAMED_PID_FILE})
if [[ -n "${_NAMED_PID}" ]]
then
# get PID list without heading
(( $(UNIX95='' ps -o pid= -p ${_NAMED_PID}| wc -l) == 0 )) && _STC=1
else
# not running
_RC=1
fi
else
_RC=1
fi
# 2) try the pgrep way (note: old pgreps do not support '-c')
if (( _RC > 0 ))
then
(( $(pgrep -u root named 2>>${HC_STDERR_LOG} | wc -l) == 0 )) && _STC=1
fi
# evaluate results
case ${_STC} in
0)
_MSG="named is running"
;;
1)
_MSG="named is not running"
;;
*)
_MSG="could not determine status of named"
;;
esac
# report result
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
# ---- config state ----
_NAMED_CHECKCONF_BIN="$(command -v named-checkconf 2>>${HC_STDERR_LOG})"
if [[ -x ${_NAMED_CHECKCONF_BIN} && -n "${_NAMED_CHECKCONF_BIN}" ]]
then
# validate main configuration and test load zones
${_NAMED_CHECKCONF_BIN} -z >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG}
if (( $? == 0 ))
then
_MSG="named & zones configuration files are syntactically correct"
_STC=0
else
_MSG="named configuration and/or zone files have syntax error(s) {named-checkconf -z}"
_STC=1
fi
# report result
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
fi
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
PURPOSE : Checks whether named (BIND) service is running and whether the named
zone files are syntactically correct.
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+207
View File
@@ -0,0 +1,207 @@
#!/usr/bin/env ksh
#------------------------------------------------------------------------------
# @(#) check_hpux_ntp_status
#------------------------------------------------------------------------------
# @(#) Copyright (C) 2016 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#------------------------------------------------------------------------------
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_hpux_ntp_status
# DOES: see _show_usage()
# EXPECTS: see _show_usage()
# REQUIRES: data_comma2space(), init_hc(), log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2016-12-01: initial version [Patrick Van der Veken]
# @(#) 2016-12-29: added threshold & config file [Patrick Van der Veken]
# @(#) 2018-10-28: fixed (linter) errors [Patrick Van der Veken]
# @(#) 2018-10-31: added support for --log-healthy [Patrick Van der Veken]
# @(#) 2019-01-10: added configuration option 'ntpq_use_ipv4', fixed problem
# @(#) with offset calculation [Patrick Van der Veken]
# @(#) 2019-01-24: arguments fix [Patrick Van der Veken]
# @(#) 2019-03-09: Text updates [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#------------------------------------------------------------------------------
# -----------------------------------------------------------------------------
function check_hpux_ntp_status
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="HP-UX" # uname -s match
typeset _NTPQ_BIN="/usr/sbin/ntpq"
typeset _NTPQ_OPTS="-pn"
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _CFG_HEALTHY=""
typeset _CFG_NTPQ_IPV4=""
typeset _LOG_HEALTHY=0
typeset _CURR_OFFSET=0
typeset _MAX_OFFSET=0
typeset _NTP_PEER=""
typeset _CHECK_OFFSET=0
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
esac
done
# handle config file
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
if [[ ! -r ${_CONFIG_FILE} ]]
then
warn "unable to read configuration file at ${_CONFIG_FILE}"
return 1
fi
# read required config values
_MAX_OFFSET=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'max_offset')
if [[ -z "${_MAX_OFFSET}" ]]
then
# default
_MAX_OFFSET=500
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
_CFG_NTPQ_IPV4=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'ntpq_use_ipv4')
case "${_CFG_NTPQ_IPV4}" in
yes|YES|Yes)
log "forcing ntpq to use IPv4"
_NTPQ_OPTS="${_NTPQ_OPTS}4"
;;
*)
: # not set
;;
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 & get NTP status
if [[ ! -x ${_NTPQ_BIN} ]]
then
warn "${_NTPQ_BIN} is not installed here"
return 1
else
${_NTPQ_BIN} ${_NTPQ_OPTS} 2>>${HC_STDERR_LOG} >>${HC_STDOUT_LOG}
# RC is always 0
fi
# evaluate ntpq results
# 1) active server
_NTP_PEER="$(grep -E -e '^\*' 2>/dev/null ${HC_STDOUT_LOG} | awk '{ print $1 }')"
if [[ -z "${_NTP_PEER}" ]]
then
_MSG="NTP is not synchronizing"
log_hc "$0" 1 "${_MSG}"
return 0
fi
case "${_NTP_PEER}" in
\*127.127.1.0*)
_MSG="NTP is synchronizing against its internal clock"
_STC=1
;;
*)
# some valid server
_MSG="NTP is synchronizing against ${_NTP_PEER##*\*}"
;;
esac
log_hc "$0" ${_STC} "${_MSG}"
# 2) offset value
if (( _STC == 0 ))
then
_CURR_OFFSET="$(grep -E -e '^\*' 2>/dev/null ${HC_STDOUT_LOG} | awk '{ print $9 }')"
case ${_CURR_OFFSET} in
+([-0-9])*(.)*([0-9]))
# numeric, OK (negatives are OK, force awk into casting c as a float)
_CHECK_OFFSET=$(awk -v c="${_CURR_OFFSET}" -v m="${_MAX_OFFSET}" 'BEGIN { sub (/^-/, "", c); print ((c+0.0)>m) }' 2>/dev/null)
if (( _CHECK_OFFSET > 0 ))
then
_MSG="NTP offset of ${_CURR_OFFSET} is bigger than the configured maximum of ${_MAX_OFFSET}"
_STC=1
else
_MSG="NTP offset of ${_CURR_OFFSET} is within the acceptable range"
fi
log_hc "$0" ${_STC} "${_MSG}"
;;
*)
# not numeric
warn "invalid offset value of ${_CURR_OFFSET} found for ${_NTP_PEER}?"
return 1
;;
esac
fi
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with parameters:
log_healthy=<yes|no>
max_offset=<max_offset (ms)>
force_chrony=<yes|no>
force_ntp=<yes|no>
ntpq_use_ipv4=<yes|no>
EXTRA OPTS : --hc-args=force_chrony, --hc-args=force_ntp
PURPOSE : Checks the status of NTP service & synchronization.
Supports chronyd & ntpd.
Assumes chronyd is the preferred time synchronization.
LOG HEALTHY : Supported
EOT
return 0
}
#------------------------------------------------------------------------------
# END of script
#------------------------------------------------------------------------------
+179
View File
@@ -0,0 +1,179 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_hpux_ovpa_status
#******************************************************************************
# @(#) Copyright (C) 2016 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_hpux_ovpa_status
# DOES: see _show_usage()
# EXPECTS: n/a
# REQUIRES: data_comma2space(), init_hc(), log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2016-04-08: initial version [Patrick Van der Veken]
# @(#) 2016-12-01: more standardized error handling [Patrick Van der Veken]
# @(#) 2018-07-10: added log_healthy hc_arg [Patrick Van der Veken]
# @(#) 2018-08-30: added config file + check list for daemons [Patrick Van der Veken]
# @(#) 2018-10-22: small fixes [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: text updates [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_hpux_ovpa_status
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="HP-UX" # uname -s match
typeset _OVPA_BIN="/opt/perf/bin/perfstat"
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _CFG_HEALTHY=""
typeset _LOG_HEALTHY=0
typeset _OVPA_MATCH=0
typeset _OVPA_VERSION=""
typeset _OVPA_DAEMONS=""
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
esac
done
# handle configuration file
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
if [[ ! -r ${_CONFIG_FILE} ]]
then
warn "unable to read configuration file at ${_CONFIG_FILE}"
return 1
fi
# read required configuration values
_OVPA_DAEMONS=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'ovpa_daemons')
if [[ -z "${_OVPA_DAEMONS}" ]]
then
# default
# get ovpa version (<12.x: scopeux; >=12.x: oacore, no coda)
_OVPA_VERSION="$(${_OVPA_BIN} -v 2>>${HC_STDERR_LOG} | grep "HP Performance Agent" 2>/dev/null | awk '{ print $NF }') 2>/dev/null"
case "${_OVPA_VERSION}" in
12.*)
log "running HP Operations Agent v12"
_OVPA_DAEMONS="oacore midaemon perfalarm ttd ovcd ovbbccb perfd"
;;
*)
log "running HP Operations Agent v11 or lower ..."
_OVPA_DAEMONS="scopeux midaemon perfalarm ttd ovcd ovbbccb coda perfd"
;;
esac
else
# convert commas and strip quotes
_OVPA_DAEMONS=$(data_comma2space "$(data_dequote \"${_OVPA_DAEMONS}\")")
fi
log "will check daemons: ${_OVPA_DAEMONS}"
_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 & get ovpa status
if [[ ! -x ${_OVPA_BIN} ]]
then
warn "${_OVPA_BIN} is not installed here"
return 1
else
${_OVPA_BIN} -p >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG}
# no RC check here because perfstat will throw <>0 when procs are down
fi
# do OVPA status checks
for _OVPA_DAEMON in ${_OVPA_DAEMONS}
do
# anchored grep here!
_OVPA_MATCH=$(grep -c -E -e "[ \t]*Running[ \t]*${_OVPA_DAEMON}" 2>/dev/null ${HC_STDOUT_LOG})
case ${_OVPA_MATCH} in
0)
_MSG="${_OVPA_DAEMON} is not running"
_STC=1
;;
*)
_MSG="${_OVPA_DAEMON} is running"
;;
esac
# report result
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
_STC=0
fi
done
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with parameters:
log_healthy=<yes|no>
ovpa_daemons=<list_of_ovpa_processes_to_check>
PURPOSE : Checks the status of OVPA processes (OpenView Performance Agent)
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+280
View File
@@ -0,0 +1,280 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_hpux_patch_version.sh
#******************************************************************************
# @(#) Copyright (C) 2018 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_hpux_patch_version
# DOES: see _show_usage()
# EXPECTS: see _show_usage()
# REQUIRES: data_comma2space(), data_contains_string(), data_get_lvalue_from_config(),
# data_dequote(), dump_logs(), init_hc(), log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2018-05-11: initial version [Patrick Van der Veken]
# @(#) 2018-05-20: added dump_logs() [Patrick Van der Veken]
# @(#) 2018-10-22: added check on fileset state [Patrick Van der Veken]
# @(#) 2018-10-28: fixed (linter) errors [Patrick Van der Veken]
# @(#) 2019-01-24: arguments fix [Patrick Van der Veken]
# @(#) 2019-02-19: fix in exclude checking [Patrick Van der Veken]
# @(#) 2019-03-09: text updates [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_hpux_patch_version
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _SWLIST_BIN="/usr/sbin/swlist"
typeset _SWLIST_OPTS=""
typeset _SHOW_PATCHES_BIN="/usr/contrib/bin/show_patches"
typeset _SHOW_PATCHES_OPTS=""
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="HP-UX" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _CFG_HEALTHY=""
typeset _LOG_HEALTHY=0
typeset _OE_VERSION=""
typeset _PATCH_LINE=""
typeset _CHECK_FILESETS=""
typeset _FILESET=""
typeset _FILESET_LINE=""
typeset _PATCHES=""
typeset _PATCH=""
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
esac
done
# handle configuration file
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
if [[ ! -r ${_CONFIG_FILE} ]]
then
warn "unable to read configuration file at ${_CONFIG_FILE}"
return 1
fi
# read required configuration values
_OE_VERSION=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'required_oe')
_PATCH_LINE=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'required_patches')
if [[ -n "${_PATCH_LINE}" ]]
then
# convert commas and strip quotes
_PATCHES=$(data_comma2space "$(data_dequote \"${_PATCH_LINE}\")")
fi
if [[ -z "${_CHECK_FILESETS}" ]]
then
# default
_CHECK_FILESETS="yes"
fi
_EXCLUDE_FILESETS=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'exclude_filesets')
[[ -n "${_EXCLUDE_FILESETS}" ]] && log "excluding filesets: $(print ${_EXCLUDE_FILESETS})"
_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 required tools
if [[ ! -x ${_SWLIST_BIN} ]]
then
warn "${_SWLIST_BIN} is not installed here"
return 1
fi
if [[ ! -x ${_SHOW_PATCHES_BIN} ]]
then
warn "${_SHOW_PATCHES_BIN} is not installed here"
return 1
fi
# get and check OE version
if [[ -n "${_OE_VERSION}" ]]
then
if [[ ! -x ${_SWLIST_BIN} ]]
then
warn "${_SWLIST_BIN} is not installed here"
return 1
else
if [[ -n "${_SWLIST_OPTS}" ]]
then
log "executing {${_SWLIST_BIN}} with options: ${_SWLIST_OPTS}"
${_SWLIST_BIN} ${_SWLIST_OPTS} >${HC_STDOUT_LOG} 2>${HC_STDERR_LOG}
else
log "executing {${_SWLIST_BIN}}"
${_SWLIST_BIN} >${HC_STDOUT_LOG} 2>${HC_STDERR_LOG}
fi
fi
if (( $? == 0 ))
then
if (( $(grep -c -E -e "${_OE_VERSION}.*Operating Environment" ${HC_STDOUT_LOG} 2>/dev/null) > 0 ))
then
if (( _LOG_HEALTHY > 0 ))
then
_MSG="required OE with version ${_OE_VERSION} is installed"
log_hc "$0" 0 "${_MSG}"
fi
else
_MSG="required OE with version ${_OE_VERSION} is not installed"
log_hc "$0" 1 "${_MSG}"
fi
else
_MSG="unable to run command: {${_SWLIST_BIN}}"
log_hc "$0" 1 "${_MSG}"
# dump debug info
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
return 1
fi
else
warn "required OE will not be checked (not configured in ${_CONFIG_FILE})"
fi
# get and check patches
if [[ -n "${_PATCHES}" ]]
then
if [[ ! -x ${_SHOW_PATCHES_BIN} ]]
then
warn "${_SHOW_PATCHES_BIN} is not installed here"
return 1
else
if [[ -n "${_SHOW_PATCHES_OPTS}" ]]
then
log "executing {${_SHOW_PATCHES_BIN}} with options: ${_SHOW_PATCHES_OPTS}"
print "=== show_patches ===" >>${HC_STDOUT_LOG}
${_SHOW_PATCHES_BIN} ${_SHOW_PATCHES_OPTS} >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG}
else
log "executing {${_SHOW_PATCHES_BIN}}"
print "=== show_patches ===" >>${HC_STDOUT_LOG}
${_SHOW_PATCHES_BIN} ${_SHOW_PATCHES_OPTS} >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG}
fi
fi
if (( $? == 0 ))
then
for _PATCH in ${_PATCHES}
do
if (( $(grep -c "${_PATCH}" ${HC_STDOUT_LOG} 2>/dev/null) > 0 ))
then
if (( _LOG_HEALTHY > 0 ))
then
_MSG="required patch ${_PATCH} is installed"
log_hc "$0" 0 "${_MSG}"
fi
else
_MSG="required patch ${_PATCH} is not installed"
log_hc "$0" 1 "${_MSG}"
fi
done
else
_MSG="unable to run command: {${_SHOW_PATCHES_BIN}}"
log_hc "$0" 1 "${_MSG}"
# dump debug info
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
return 1
fi
else
warn "required patches will not be checked (not configured in ${_CONFIG_FILE})"
fi
# get and check (all) filesets
if [[ "${_CHECK_FILESETS}" = "yes" ]]
then
_SWLIST_OPTS="-a state -l fileset"
log "executing {${_SWLIST_BIN}} with options: ${_SWLIST_OPTS}"
print "=== swlist (${_SWLIST_OPTS}) ===" >>${HC_STDOUT_LOG}
${_SWLIST_BIN} ${_SWLIST_OPTS} >>${HC_STDOUT_LOG} 2>${HC_STDERR_LOG}
if (( $? == 0 ))
then
grep -E -e "installed[[:space:]]*$" ${HC_STDOUT_LOG} 2>/dev/null |\
while read _FILESET_LINE
do
_FILESET=$(print "${_FILESET_LINE}" | awk '{print $1}' 2>/dev/null)
# check exclude(s)
data_contains_string "${_EXCLUDE_FILESETS}" "${_FILESET}"
if (( $? == 0 ))
then
_MSG="fileset ${_FILESET} is not in a configured state"
log_hc "$0" 1 "${_MSG}"
fi
done
else
_MSG="unable to run command: {${_SWLIST_BIN}}"
log_hc "$0" 1 "${_MSG}"
# dump debug info
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
return 1
fi
fi
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with parameters:
log_healthy=<yes|no>
required_patches=<list_of_patches_to_check>
required_oe=<OE_version>
check_filesets=<yes|no>
exclude_filesets=<list_of_filesets_to_exclude>
PURPOSE : Checks whether the required OE (Operating Environment) version is installed
Checks whether the required patches are installed
Checks whether filesets are in a configured state
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+116
View File
@@ -0,0 +1,116 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_hpux_postfix_status.sh
#******************************************************************************
# @(#) Copyright (C) 2016 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_hpux_postfix_status
# DOES: see _show_usage()
# EXPECTS: n/a
# REQUIRES: data_comma2space(), init_hc(), log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2016-12-01: 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]
# @(#) 2019-03-16: replace 'which' [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_hpux_postfix_status
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="HP-UX" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _POSTFIX_BIN=""
typeset _MSG=""
typeset _STC=0
typeset _LOG_HEALTHY=0
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
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
_POSTFIX_BIN="$(command -v postfix 2>>${HC_STDERR_LOG})"
if [[ -x ${_POSTFIX_BIN} && -n "${_POSTFIX_BIN}" ]]
then
${_POSTFIX_BIN} status >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG}
if (( $? == 0 ))
then
_MSG="postfix is running"
else
_MSG="postfix is not running"
_STC=1
fi
else
warn "postfix is not installed here"
return 1
fi
# report result
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
PURPOSE : Checks whether postfix (mail system) is running
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+157
View File
@@ -0,0 +1,157 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_hpux_root_crontab
#******************************************************************************
# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_hpux_root_crontab
# DOES: see _show_usage()
# EXPECTS: n/a
# REQUIRES: data_comma2space(), init_hc(), log_hc(), warn()
#
# @(#) 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!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_hpux_root_crontab
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="HP-UX" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
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}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
esac
done
# handle configuration file
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
if [[ ! -r ${_CONFIG_FILE} ]]
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 -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}")
case ${_CRON_MATCH} in
0)
_MSG="'${_CRON_ENTRY}' is not configured in cron"
_STC=1
;;
1)
_MSG="'${_CRON_ENTRY}' is configured in cron"
;;
+([0-9])*([0-9]))
_MSG="'${_CRON_ENTRY}' is configured multiple times in cron"
;;
esac
# report result
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
_STC=0
done
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with parameters:
log_healthy=<yes|no>
and formatted stanzas:
cron:<cron_entry>
PURPOSE : Checks the content of the 'root' crontab for required entries
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+423
View File
@@ -0,0 +1,423 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_hpux_sfm_status.sh
#******************************************************************************
# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_hpux_sfm_statuss
# DOES: see _show_usage()
# EXPECTS: see _show_usage()
# REQUIRES: data_comma2space(), data_contains_string(), data_is_numeric(),
# init_hc(), log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2018-10-28: initial version [Patrick Van der Veken]
# @(#) 2019-01-27: arguments fix [Patrick Van der Veken]
# @(#) 2019-03-09: text updates [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_hpux_sfm_status
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _SFMCONFIG_BIN="/opt/sfm/bin/sfmconfig"
typeset _EVWEB_BIN="/opt/sfm/bin/evweb"
typeset _CIMPROVIDER_BIN="/opt/wbem/bin/cimprovider"
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="HP-UX" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _CFG_HEALTHY=""
typeset _LOG_HEALTHY=0
typeset _CFG_CHECK_EVENTS=""
typeset _CHECK_EVENTS=1
typeset _CFG_EVENTS_AGE=""
typeset _EVENTS_AGE="1:dd"
typeset _CFG_EVENTS_SEVERITY=""
typeset _CFG_SEND_TEST_EVENT=""
typeset _SEND_TEST_EVENT=0
typeset _CFG_WAIT_TEST_EVENT=""
typeset _WAIT_TEST_EVENT=60
typeset _CFG_EVENT_SUBSCRIBER_CIMOM=""
typeset _CFG_EVENT_SUBSCRIBER_WBEM=""
typeset _CHECK_EVENT_SUBSCRIBER=0
typeset _CHECK_CIM_OUTPUT=""
typeset _CHECK_CIM_MODULE=""
typeset _CHECK_SFM_OUTPUT=""
typeset _CHECK_EVWEB_OUTPUT=""
typeset _COUNT_SUBS_CIMOM=0
typeset _COUNT_SUBS_WBEM=0
typeset _EVWEB_LINE=""
typeset _EVENT_ID=""
typeset _EVENT_SUMMARY=""
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
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
# handle configuration file
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
if [[ ! -r ${_CONFIG_FILE} ]]
then
warn "unable to read configuration file at ${_CONFIG_FILE}"
return 1
fi
# read required configuration values
_CFG_CHECK_EVENTS=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'check_events')
case "${_CFG_CHECK_EVENTS}" in
No|NO|no)
_CHECK_EVENTS=0
log "will not check current events"
;;
*)
log "will check current events"
;;
esac
_CFG_EVENTS_AGE=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'events_age')
case "${_CFG_EVENTS_AGE}" in
*:dd|*:mm|*:yy)
_EVENTS_AGE="${_CFG_EVENTS_AGE}"
log "will use following age for current events: ${_CFG_EVENTS_AGE}"
;;
*)
warn "invalid event age value '${_CFG_EVENTS_AGE}' in configuration file at ${_CONFIG_FILE}"
return 1
;;
esac
_CFG_EVENTS_SEVERITY=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'events_severity')
if [[ -n "${_CFG_EVENTS_SEVERITY}" ]] && (( _CHECK_EVENTS > 0 ))
then
log "will use following severities for current events: ${_CFG_EVENTS_SEVERITY}"
fi
_CFG_SEND_TEST_EVENT=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'send_test_event')
case "${_CFG_SEND_TEST_EVENT}" in
Yes|YES|yes)
if (( ARG_LOG > 0 ))
then
_SEND_TEST_EVENT=1
else
warn "--no-log is enabled, skipping the generation of a test event"
fi
log "will send & check a test event"
;;
*)
log "will not send & check a test event"
;;
esac
_CFG_WAIT_TEST_EVENT=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'wait_test_event')
if (( _SEND_TEST_EVENT > 0 ))
then
if [[ -z "${_CFG_WAIT_TEST_EVENT}" ]]
then
_WAIT_TEST_EVENT=60
else
data_is_numeric "${_WAIT_TEST_EVENT}"
if (( $? > 0 ))
then
warn "invalid wait test event value '${_WAIT_TEST_EVENT}' in configuration file at ${_CONFIG_FILE}"
return 1
fi
fi
fi
_CFG_EVENT_SUBSCRIBER_CIMOM=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'event_subscriber_cimom')
_CFG_EVENT_SUBSCRIBER_WBEM=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'event_subscriber_wbem')
if [[ -n "${_CFG_EVENT_SUBSCRIBER_CIMOM}" ]] || [[ -n "${_CFG_EVENT_SUBSCRIBER_WBEM}" ]]
then
_CHECK_EVENT_SUBSCRIBER=1
log "will check external subscriber (cimom and/or wbem)"
else
log "will not check external subscriber (cimom and/or wbem)"
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 timeout (_WAIT_TEST_EVENT must be at least 30 secs smaller than health check timeout)
if (( _SEND_TEST_EVENT > 0 ))
then
if (( (_WAIT_TEST_EVENT + 30) > HC_TIME_OUT ))
then
warn "wait test event value will conflict with health check timeout. Specify a (larger) --timeout value"
return 1
fi
fi
# check required tools
if [[ ! -x ${_SFMCONFIG_BIN} ]]
then
warn "${_SFMCONFIG_BIN} is not installed here"
return 1
fi
if [[ ! -x ${_EVWEB_BIN} ]]
then
warn "${_EVWEB_BIN} is not installed here"
return 1
fi
if [[ ! -x ${_CIMPROVIDER_BIN} ]]
then
warn "${_CIMPROVIDER_BIN} is not installed here"
return 1
fi
# 1. is SFM active?
log "checking whether SFM is configured as default monitoring mode ..."
print "=== ${_SFMCONFIG_BIN} -w -q ===" >>${HC_STDOUT_LOG}
_CHECK_SFM_OUTPUT=$(${_SFMCONFIG_BIN} -w -q 2>>${HC_STDERR_LOG})
# RC for sfmconfig -w -q is meaningless so no check here
data_contains_string "${_CHECK_SFM_OUTPUT}" "SysFaultMgmt is the default monitoring mode"
if (( $? == 0 ))
then
_MSG="SysFaultMgmt is not configured as default monitoring mode {${_SFMCONFIG_BIN} -w -q}"
_STC=1
else
_MSG="SysFaultMgmt is configured as default monitoring mode"
_STC=0
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
# save sfmconfig OUTPUT for posterity
print "${_CHECK_SFM_OUTPUT}" >>${HC_STDOUT_LOG}
# 2. is SFM provider module active in CIM?
log "checking whether SFM provider is active ..."
print "=== ${_CIMPROVIDER_BIN} -ls ===" >>${HC_STDOUT_LOG}
_CHECK_CIM_OUTPUT=$(${_CIMPROVIDER_BIN} -ls 2>>${HC_STDERR_LOG})
if (( $? > 0 ))
then
_MSG="unable to execute {${_CIMPROVIDER_BIN} -ls}, cimserver is probably not running"
log_hc "$0" 1 "${_MSG}"
# save cimprovider OUTPUT
print "${_CHECK_CIM_OUTPUT}" >>${HC_STDOUT_LOG}
# dump debug info
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
return 1
else
# find module
_CHECK_CIM_MODULE=$(print "${_CHECK_CIM_OUTPUT}" | grep -c -E -e 'SFMProviderModule[[:space:]]*OK' 2>/dev/null)
if (( _CHECK_CIM_MODULE > 0 ))
then
_MSG="SFM CIM provider is active"
_STC=0
else
_MSG="SFM CIM provider is not active {${_CIMPROVIDER_BIN} -ls}"
_STC=0
fi
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
# save sfmconfig OUTPUT for posterity
print "${_CHECK_CIM_OUTPUT}" >>${HC_STDOUT_LOG}
# 3. check if there is an external SIM/IRS subscriber
if (( _CHECK_EVENT_SUBSCRIBER > 0 ))
then
log "checking external SIM/IRS subscriber ..."
print "=== ${_EVWEB_BIN} subscribe -L -b external ===" >>${HC_STDOUT_LOG}
_CHECK_EVWEB_OUTPUT=$(${_EVWEB_BIN} subscribe -L -b external)
_COUNT_SUBS_CIMOM=$(print "${_CHECK_EVWEB_OUTPUT}" | grep -c "${_CFG_EVENT_SUBSCRIBER_CIMOM}" 2>/dev/null)
_COUNT_SUBS_WBEM=$(print "${_CHECK_EVWEB_OUTPUT}" | grep -c "${_CFG_EVENT_SUBSCRIBER_WBEM}" 2>/dev/null)
if (( _COUNT_SUBS_CIMOM > 0 || _COUNT_SUBS_WBEM > 0 ))
then
case ${_COUNT_SUBS_CIMOM} in
0)
:
;;
3)
_MSG="found external subscriber for CIMOM with ${_COUNT_SUBS_CIMOM} subscriptions"
_STC=0
;;
*)
_MSG="found external subscriber for CIMOM but not with sufficient number of subscriptions: ${_COUNT_SUBS_CIMOM}"
_STC=1
;;
esac
if (( _COUNT_SUBS_WBEM > 0 ))
then
_MSG="found external subscriber for WBEM"
_STC=0
fi
else
_MSG="did not find any external subscribers for CIMOM or WBEM"
_STC=1
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
# save evweb OUTPUT for posterity
print "${_CHECK_EVWEB_OUTPUT}" >>${HC_STDOUT_LOG}
fi
# 4. send a test event?
if (( _SEND_TEST_EVENT > 0 ))
then
log "generating SFM test event ..."
print "=== ${_SFMCONFIG_BIN} -t -a ===" >>${HC_STDOUT_LOG}
${_SFMCONFIG_BIN} -t -a >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG}
if (( $? > 0 ))
then
_MSG="unable to execute {${_SFMCONFIG_BIN} -t -a}, cimserver is probably not running"
log_hc "$0" 1 "${_MSG}"
# dump debug info
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
return 1
else
# wait for test event to showing
log "waiting for SFM test event to show (${_WAIT_TEST_EVENT} seconds) ..."
sleep ${_WAIT_TEST_EVENT}
# run event viewer
print "=== ${_EVWEB_BIN} eventviewer -L -a 1:dd ===" >>${HC_STDOUT_LOG}
_CHECK_EVWEB_OUTPUT=$(${_EVWEB_BIN} eventviewer -L -a 1:dd | grep "Test event" 2>/dev/null)
if (( $? > 0 ))
then
_MSG="unable to execute {${_EVWEB_BIN} eventviewer -L -a 1:dd}"
log_hc "$0" 1 "${_MSG}"
# save evweb OUTPUT
print "${_CHECK_EVWEB_OUTPUT}" >>${HC_STDOUT_LOG}
# dump debug info
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
return 1
else
if [[ -n "${_CHECK_EVWEB_OUTPUT}" ]]
then
_MSG="at least one test event was successfully generated in the last 24hrs"
_STC=0
else
_MSG="found no test event in the last 24hrs"
_STC=1
fi
fi
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
# save evweb OUTPUT for posterity
print "${_CHECK_EVWEB_OUTPUT}" >>${HC_STDOUT_LOG}
fi
# 5. check events
if (( _CHECK_EVENTS > 0 ))
then
_CHECK_EVWEB_OUTPUT=""
log "checking for current events (age: ${_EVENTS_AGE}) ..."
print "=== ${_EVWEB_BIN} eventviewer -L -a ${_EVENTS_AGE} ===" >>${HC_STDOUT_LOG}
_CHECK_EVWEB_OUTPUT=$(${_EVWEB_BIN} eventviewer -L -a ${_EVENTS_AGE} | grep -v "Test event" 2>/dev/null)
if (( $? > 0 ))
then
_MSG="unable to execute {${_EVWEB_BIN} eventviewer -L -a ${_EVENTS_AGE}}"
log_hc "$0" 1 "${_MSG}"
# save evweb OUTPUT
print "${_CHECK_EVWEB_OUTPUT}" >>${HC_STDOUT_LOG}
# dump debug info
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
return 1
else
_CFG_EVENTS_SEVERITY=$(data_lc "${_CFG_EVENTS_SEVERITY}")
print "${_CHECK_EVWEB_OUTPUT}" | grep -v -E -e "^$" -e "^=" -e "^Ev" 2>/dev/null |\
while read -r _EVWEB_LINE
do
_EVENT_ID=$(print "${_EVWEB_LINE}" | awk '{ print $1}' 2>/dev/null)
_EVENT_SEVERITY=$(print "${_EVWEB_LINE}" | awk '{ print $2}' 2>/dev/null)
_EVENT_SEVERITY=$(data_lc "${_EVENT_SEVERITY}")
_EVENT_SUMMARY=$(print "${_EVWEB_LINE}" | awk '{$1=$2=$3=$4=$5=$6=$7=$8=$9=$10=""; gsub (/^ */,"",$0); print $0}' 2>/dev/null)
# check severity
data_contains_string "${_CFG_EVENTS_SEVERITY}" "${_EVENT_SEVERITY}"
if (( $? > 0 ))
then
_MSG="found SFM event (ID=${_EVENT_ID}/SUMMARY=${_EVENT_SUMMARY})"
log_hc "$0" 1 "${_MSG}"
fi
done
fi
# save evweb OUTPUT for posterity
print "${_CHECK_EVWEB_OUTPUT}" >>${HC_STDOUT_LOG}
fi
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with parameters:
log_healthy=<yes|no>
check_events=<yes|no>
events_age=<age_of_open_events>
events_severity=<severities_of_open_events>
send_test_event=<yes|no>
wait_test_event=<interval_to_wait>
event_subscriber=<url_of_external_subscriber>
PURPOSE : Checks the heath of SFM (System Fault Management)
* checks default monitoring mode
* checks CIM provider module
* checks external event subscriber (optional)
* sends & checks a test event (optional)
* checks current events (optional)
LOG HEALTHY : Supported
NOTE : Test events should not be generated more than once a day
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+195
View File
@@ -0,0 +1,195 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_hpux_sg_cluster_config
#******************************************************************************
# @(#) Copyright (C) 2016 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_hpux_sg_cluster_status
# DOES: see _show_usage()
# EXPECTS: see _show_usage()
# REQUIRES: data_comma2space(), init_hc(), log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2016-03-08: initial version [Patrick Van der Veken]
# @(#) 2016-12-01: more standardized error handling [Patrick Van der Veken]
# @(#) 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]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_hpux_sg_cluster_config
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _VERSION="2019-01-24" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="HP-UX" # uname -s match
typeset _SG_DAEMON="/usr/lbin/cmcld"
# rubbish that cmgetconf outputs to STDOUT instead of STDERR
typeset _SG_CMGETCONF_FILTER="Permission denied|Number of configured"
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _CLUSTER_RUN_FILE="${TMP_DIR}/.$0.cluster_run.$$"
typeset _CLUSTER_CFG_FILE="${TMP_DIR}/.$0.cluster_cfg.$$"
typeset _CLUSTER_INSTANCE=""
typeset _CLUSTER_INSTANCES=""
typeset _CLUSTER_ENTRY=""
typeset _CLUSTER_CFG_ENTRY=""
typeset _CLUSTER_MATCH=""
typeset _CLUSTER_PARAM=""
typeset _CLUSTER_VALUE=""
# set local trap for cleanup
# shellcheck disable=SC2064
trap "rm -f ${_CLUSTER_RUN_FILE}.* ${_CLUSTER_CFG_FILE}.* >/dev/null 2>&1; return 1" 1 2 3 15
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
esac
done
# handle configuration file
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
if [[ ! -r ${_CONFIG_FILE} ]]
then
warn "unable to read configuration file at ${_CONFIG_FILE}"
return 1
fi
# look for cluster instance names
grep -E -e '^\[' ${_CONFIG_FILE} 2>/dev/null | cut -f1 -d']' | cut -f2 -d'[' |\
while read _CLUSTER_INSTANCE
do
_CLUSTER_INSTANCES="${_CLUSTER_INSTANCES} ${_CLUSTER_INSTANCE}"
done
if [[ -z "${_CLUSTER_INSTANCES}" ]]
then
warn "no cluster information configured in ${_CONFIG_FILE}"
return 1
fi
# check serviceguard status & gather cluster information from running cluster (compressed lines)
if [[ ! -x ${_SG_DAEMON} ]]
then
warn "${_SG_DAEMON} is not installed here"
return 1
else
for _CLUSTER_INSTANCE in ${_CLUSTER_INSTANCES}
do
cmgetconf -c ${_CLUSTER_INSTANCE} 2>>${HC_STDERR_LOG} |\
grep -v -E -e "${_SG_CMGETCONF_FILTER}" | tr -d ' \t' >${_CLUSTER_RUN_FILE}.${_CLUSTER_INSTANCE}
[[ -s ${_CLUSTER_RUN_FILE}.${_CLUSTER_INSTANCE} ]] || {
_MSG="unable to gather cluster configuration"
log_hc "$0" 1 "${_MSG}"
return 0
}
done
fi
# gather cluster information from healthcheck configuration
for _CLUSTER_INSTANCE in ${_CLUSTER_INSTANCES}
do
awk -v cluster="${_CLUSTER_INSTANCE}" '
BEGIN { found = 0; needle = "^\["cluster"\]" }
# skip blank lines
/^\s*$/ { next; }
# skip comment lines
/^#/ { next; }
# end marker
( $0 ~ /^\[.*\]/ && found ) {
found = 0;
}
# start marker
$0 ~ needle {
found = 1;
};
# stanza body
( found && $0 !~ /^\[.*\]/ ) {
# print non-compressed and compressed version
printf "%s|", $0;
gsub(" |\t", "", $0);
printf "%s\n", $0;
}' < ${_CONFIG_FILE} 2>>${HC_STDERR_LOG} >${_CLUSTER_CFG_FILE}.${_CLUSTER_INSTANCE}
done
# do cluster configuration checks (using the compressed strings)
for _CLUSTER_INSTANCE in ${_CLUSTER_INSTANCES}
do
while read _CLUSTER_ENTRY
do
# split entry to get the compressed version
_CLUSTER_CFG_ENTRY=$(print "${_CLUSTER_ENTRY}" | cut -f2 -d'|')
# get parameter name from non-compressed version
_CLUSTER_PARAM=$(print "${_CLUSTER_ENTRY}" | cut -f1 -d'|' | awk '{ print $1 }')
# get parameter value from non-compressed version
_CLUSTER_VALUE=$(print "${_CLUSTER_ENTRY}" | cut -f1 -d'|' | awk '{ print substr($2,1,30)}')
# is it present?
_CLUSTER_MATCH=$(grep -c "${_CLUSTER_CFG_ENTRY}" ${_CLUSTER_RUN_FILE}.${_CLUSTER_INSTANCE} 2>/dev/null)
if (( _CLUSTER_MATCH == 0 ))
then
# get parameter name from non-compressed version
_MSG="'${_CLUSTER_PARAM} (${_CLUSTER_VALUE} ...)' is not correctly configured for ${_CLUSTER_INSTANCE}"
_STC=1
else
_MSG="'${_CLUSTER_PARAM} (${_CLUSTER_VALUE} ...)' is configured for ${_CLUSTER_INSTANCE}"
fi
# handle unit result
log_hc "$0" ${_STC} "${_MSG}"
_STC=0
done <${_CLUSTER_CFG_FILE}.${_CLUSTER_INSTANCE}
done
# do cleanup
rm -f ${_CLUSTER_RUN_FILE}.* ${_CLUSTER_CFG_FILE}.* >/dev/null 2>&1
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3
PURPOSE : Checks the configuration of Serviceguard cluster (SG 11.16+) (comparing
serialized strings from the plugin configuration file to the running cluster
configuration)
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+184
View File
@@ -0,0 +1,184 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_hpux_sg_cluster_status
#******************************************************************************
# @(#) Copyright (C) 2016 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_hpux_sg_cluster_status
# DOES: see _show_usage()
# EXPECTS: see _show_usage()
# REQUIRES: data_comma2space(), dump_logs(), init_hc(), log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2016-03-25: initial version [Patrick Van der Veken]
# @(#) 2016-12-01: more standardized error handling [Patrick Van der Veken]
# @(#) 2017-05-07: made checks more detailed for log_hc() [Patrick Van der Veken]
# @(#) 2018-05-20: added dump_logs() [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: 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!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_hpux_sg_cluster_status
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="HP-UX" # uname -s match
typeset _SG_DAEMON="/usr/lbin/cmcld"
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _CFG_HEALTHY=""
typeset _LOG_HEALTHY=0
typeset _SG_ENTRY=""
typeset _SG_MATCH=""
typeset _SG_CFG_PARAM=""
typeset _SG_CFG_VALUE=""
typeset _SG_RUN_VALUE=""
typeset _IS_OLD_STYLE=0
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
esac
done
# handle configuration file
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
if [[ ! -r ${_CONFIG_FILE} ]]
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 "^sg:" ${_CONFIG_FILE} 2>/dev/null)
if (( _IS_OLD_STYLE == 0 ))
then
warn "no 'sg:' 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
# check & get serviceguard status
if [[ ! -x ${_SG_DAEMON} ]]
then
warn "${_SG_DAEMON} is not installed here"
return 1
else
cmviewcl -v -f line 2>>${HC_STDERR_LOG} | tr '|' ':' >>${HC_STDOUT_LOG}
(( $? > 0 )) && {
_MSG="unable to run command: {cmviewcl}"
log_hc "$0" 1 "${_MSG}"
# dump debug info
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
return 0
}
fi
# do cluster status checks
# (replace ':' by '|' for cmcviewcl output)
grep -E -e "^sg:" ${_CONFIG_FILE} 2>/dev/null | tr '|' ':' 2>/dev/null |\
while read -r _ _SG_ENTRY
do
# field split
_SG_CFG_PARAM="$(print ${_SG_ENTRY} | cut -f1 -d'=')" # field 1
_SG_CFG_VALUE="$(print ${_SG_ENTRY} | cut -f2 -d'=')" # field 2
# check run-time values (anchored grep here!)
_SG_MATCH=$(grep -i "^${_SG_CFG_PARAM}" ${HC_STDOUT_LOG} 2>/dev/null)
if [[ -n "${_SG_MATCH}" ]]
then
_SG_RUN_VALUE=$(print "${_SG_MATCH}" | cut -f2 -d'=') # field 2
if [[ "${_SG_CFG_VALUE}" = "${_SG_RUN_VALUE}" ]]
then
_MSG="cluster parameter ${_SG_CFG_PARAM} has a correct value [${_SG_RUN_VALUE}]"
_STC=0
else
_MSG="cluster parameter ${_SG_CFG_PARAM} has a wrong value [${_SG_RUN_VALUE}]"
_STC=1
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}" "${_SG_RUN_VALUE}" "${_SG_CFG_VALUE}"
fi
else
warn "could not determine status for ${_SG_CFG_PARAM} from command output {cmviewcl}"
fi
done
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with parameters:
log_healthy=<yes|no>
and formatted stanzas:
sg:<param>=<value>
PURPOSE : Checks the status of Serviceguard cluster parameters (SG 11.16+)
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+195
View File
@@ -0,0 +1,195 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_hpux_sg_package_config
#******************************************************************************
# @(#) Copyright (C) 2016 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_hpux_sg_package_config
# DOES: see _show_usage()
# EXPECTS: see _show_usage()
# REQUIRES: data_comma2space(), init_hc(), log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2016-03-08: initial version [Patrick Van der Veken]
# @(#) 2016-12-01: more standardized error handling [Patrick Van der Veken]
# @(#) 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]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_hpux_sg_package_config
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _VERSION="2019-01-24" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="HP-UX" # uname -s match
typeset _SG_DAEMON="/usr/lbin/cmcld"
# rubbish that cmgetconf outputs to STDOUT instead of STDERR
typeset _SG_CMGETCONF_FILTER="Permission denied|Number of configured"
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _PKG_RUN_FILE="${TMP_DIR}/.$0.pkg_run.$$"
typeset _PKG_CFG_FILE="${TMP_DIR}/.$0.pkg_cfg.$$"
typeset _PKG_INSTANCE=""
typeset _PKG_INSTANCES=""
typeset _PKG_ENTRY=""
typeset _PKG_CFG_ENTRY=""
typeset _PKG_MATCH=""
typeset _PKG_PARAM=""
typeset _PKG_VALUE=""
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
esac
done
# set local trap for cleanup
# shellcheck disable=SC2064
trap "rm -f ${_PKG_RUN_FILE}.* ${_PKG_CFG_FILE}.* >/dev/null 2>&1; return 1" 1 2 3 15
# handle configuration file
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
if [[ ! -r ${_CONFIG_FILE} ]]
then
warn "unable to read configuration file at ${_CONFIG_FILE}"
return 1
fi
# look for package instance names
grep -E -e '^\[' ${_CONFIG_FILE} 2>/dev/null | cut -f1 -d']' | cut -f2 -d'[' |\
while read _PKG_INSTANCE
do
_PKG_INSTANCES="${_PKG_INSTANCES} ${_PKG_INSTANCE}"
done
if [[ -z "${_PKG_INSTANCES}" ]]
then
warn "no package information configured in ${_CONFIG_FILE}"
return 1
fi
# check serviceguard status & gather package information from running cluster (compressed lines)
if [[ ! -x ${_SG_DAEMON} ]]
then
warn "${_SG_DAEMON} is not installed here"
return 1
else
for _PKG_INSTANCE in ${_PKG_INSTANCES}
do
cmgetconf -p ${_PKG_INSTANCE} -v 0 2>>${HC_STDERR_LOG} |\
grep -v -E -e "${_SG_CMGETCONF_FILTER}" | tr -d ' \t' >${_PKG_RUN_FILE}.${_PKG_INSTANCE}
[[ -s ${_PKG_RUN_FILE}.${_PKG_INSTANCE} ]] || {
_MSG="unable to gather package configuration for at least one cluster package"
log_hc "$0" 1 "${_MSG}"
return 0
}
done
fi
# gather package information from healthcheck configuration
for _PKG_INSTANCE in ${_PKG_INSTANCES}
do
awk -v package="${_PKG_INSTANCE}" '
BEGIN { found = 0; needle = "^\["package"\]" }
# skip blank lines
/^\s*$/ { next; }
# skip comment lines
/^#/ { next; }
# end marker
( $0 ~ /^\[.*\]/ && found ) {
found = 0;
}
# start marker
$0 ~ needle {
found = 1;
};
# stanza body
( found && $0 !~ /^\[.*\]/ ) {
# print non-compressed and compressed version
printf "%s|", $0;
gsub(" |\t", "", $0);
printf "%s\n", $0;
}' < ${_CONFIG_FILE} 2>>${HC_STDERR_LOG} >${_PKG_CFG_FILE}.${_PKG_INSTANCE}
done
# do package configuration checks (using the compressed strings)
for _PKG_INSTANCE in ${_PKG_INSTANCES}
do
while read _PKG_ENTRY
do
# split entry to get the compressed version
_PKG_CFG_ENTRY=$(print "${_PKG_ENTRY}" | cut -f2 -d'|')
# get parameter name from non-compressed version
_PKG_PARAM=$(print "${_PKG_ENTRY}" | awk '{ print $1 }')
# get parameter value from non-compressed version
_PKG_VALUE=$(print "${_PKG_ENTRY}" | cut -f1 -d'|' | awk '{ print substr($2,1,30)}')
# is it present?
_PKG_MATCH=$(grep -c "${_PKG_CFG_ENTRY}" ${_PKG_RUN_FILE}.${_PKG_INSTANCE} 2>/dev/null)
if (( _PKG_MATCH == 0 ))
then
# get parameter name from non-compressed version
_MSG="'${_PKG_PARAM} (${_PKG_VALUE} ...)' is not correctly configured for ${_PKG_INSTANCE}"
_STC=1
else
_MSG="'${_PKG_PARAM} (${_PKG_VALUE} ...)' is configured for ${_PKG_INSTANCE}"
fi
# handle unit result
log_hc "$0" ${_STC} "${_MSG}"
_STC=0
done <${_PKG_CFG_FILE}.${_PKG_INSTANCE}
done
# do cleanup
rm -f ${_PKG_RUN_FILE}.* ${_PKG_CFG_FILE}.* >/dev/null 2>&1
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3
PURPOSE : Checks the configuration of Serviceguard packages (SG 11.16+) (comparing
serialized strings from the HC configuration file to the running cluster
configuration)
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+186
View File
@@ -0,0 +1,186 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_hpux_sg_package_status
#******************************************************************************
# @(#) Copyright (C) 2016 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_hpux_sg_package_status
# DOES: see _show_usage()
# EXPECTS: see _show_usage()
# REQUIRES: data_comma2space(), dump_logs(), init_hc(), log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2016-03-08: initial version [Patrick Van der Veken]
# @(#) 2016-12-01: more standardized error handling [Patrick Van der Veken]
# @(#) 2017-05-07: made checks more detailed for log_hc() [Patrick Van der Veken]
# @(#) 2018-05-20: added dump_logs() [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: 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!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_hpux_sg_package_status
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="HP-UX" # uname -s match
typeset _SG_DAEMON="/usr/lbin/cmcld"
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _CFG_HEALTHY=""
typeset _LOG_HEALTHY=0
typeset _SG_ENTRY=""
typeset _SG_MATCH=""
typeset _SG_PACKAGE=""
typeset _SG_CFG_PARAM=""
typeset _SG_CFG_VALUE=""
typeset _SG_RUN_VALUE=""
typeset _IS_OLD_STYLE=0
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
esac
done
# handle configuration file
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
if [[ ! -r ${_CONFIG_FILE} ]]
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 "^sg:" ${_CONFIG_FILE} 2>/dev/null)
if (( _IS_OLD_STYLE == 0 ))
then
warn "no 'sg:' 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
# check & get serviceguard status
if [[ ! -x ${_SG_DAEMON} ]]
then
warn "${_SG_DAEMON} is not installed here"
return 1
else
cmviewcl -v -f line -l package 2>>${HC_STDERR_LOG} | tr '|' ':' >>${HC_STDOUT_LOG}
(( $? > 0)) && {
_MSG="unable to run command: {cmviewcl}"
log_hc "$0" 1 "${_MSG}"
# dump debug info
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
return 0
}
fi
# do package status checks
# (replace ':' by '|' for cmcviewcl output)
grep -E -e "^sg:" ${_CONFIG_FILE} 2>/dev/null | tr '|' ':' 2>/dev/null |\
while read -r _ _SG_ENTRY
do
# field split
_SG_PACKAGE="$(print ${_SG_ENTRY} | cut -f1 -d':')"
_SG_CFG_PARAM="$(print ${_SG_ENTRY} | cut -f2- -d':' | cut -f1 -d'=')" # field 2-,1
_SG_CFG_VALUE="$(print ${_SG_ENTRY} | cut -f2- -d':' | cut -f2 -d'=')" # field 2-,2
# check run-time values (anchored grep here!)
_SG_MATCH=$(grep -i "^package:${_SG_PACKAGE}:${_SG_CFG_PARAM}" ${HC_STDOUT_LOG} 2>/dev/null)
if [[ -n "${_SG_MATCH}" ]]
then
_SG_RUN_VALUE=$(print "${_SG_MATCH}" | cut -f3- -d':' | cut -f2 -d'=') # field3-,2
if [[ "${_SG_CFG_VALUE}" = "${_SG_RUN_VALUE}" ]]
then
_MSG="package ${_SG_PACKAGE} parameter ${_SG_CFG_PARAM} has a correct value [${_SG_RUN_VALUE}]"
_STC=0
else
_MSG="package ${_SG_PACKAGE} parameter ${_SG_CFG_PARAM} has a wrong value [${_SG_RUN_VALUE}]"
_STC=1
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}" "${_SG_RUN_VALUE}" "${_SG_CFG_VALUE}"
fi
else
warn "could not determine status for ${_SG_PACKAGE}/${_SG_CFG_PARAM} from command output {cmviewcl}"
fi
done
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with parameters:
log_healthy=<yes|no>
and formatted stanzas:
sg:<package_name>:<parameter>=<value>
PURPOSE : Checks the status of Serviceguard package parameters (SG 11.16+)
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+137
View File
@@ -0,0 +1,137 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_hpux_sg_qs_status.sh
#******************************************************************************
# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_hpux_sg_qs_status
# DOES: see _show_usage()
# EXPECTS: n/a
# REQUIRES: data_comma2space(), init_hc(), log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2017-05-01: 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 support for --log-healthy [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_hpux_sg_qs_status
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="HP-UX" # uname -s match
typeset _QS_BIN="/usr/lbin/qsc"
typeset _QS_AUTH_FILE="/etc/cmcluster/qs_authfile"
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _LOG_HEALTHY=0
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
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 QS presence
if [[ ! -x ${_QS_BIN} ]]
then
warn "${_QS_BIN} is not installed here"
return 1
fi
# ---- process state ----
(( $(pgrep -u root -f ${_QS_BIN} 2>>${HC_STDERR_LOG} | wc -l) == 0 )) && _STC=1
# evaluate results
case ${_STC} in
0)
_MSG="QS is running"
;;
1)
_MSG="QS is not running"
;;
*)
_MSG="could not determine status of QS"
;;
esac
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
# ---- config state ----
if [[ -s ${_QS_AUTH_FILE} ]]
then
_MSG="QS authorizations file has been configured"
_STC=0
else
_MSG="QS authorizations file is missing or empty (${_QS_AUTH_FILE})"
_STC=1
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
PURPOSE : Checks whether the Serviceguard quorum server is running
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+140
View File
@@ -0,0 +1,140 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_hpux_sshd_status.sh
#******************************************************************************
# @(#) Copyright (C) 2016 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_hpux_sshd_status
# DOES: see _show_usage()
# EXPECTS: n/a
# REQUIRES: datadata_comma2spacespace2comma(), init_hc(), log_hc()
#
# @(#) HISTORY:
# @(#) 2017-04-01: 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 support for --log-healthy [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_hpux_sshd_status
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _SSHD_PID_FILE="/var/run/sshd/sshd.pid"
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="HP-UX" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _SSHD_PID=""
typeset _MSG=""
typeset _STC=0
typeset _LOG_HEALTHY=0
typeset _RC=0
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
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
# ---- process state ----
# 1) try using the PID way
if [[ -r "${_SSHD_PID_FILE}" ]]
then
_SSHD_PID=$(<${_SSHD_PID_FILE})
if [[ -n "${_SSHD_PID}" ]]
then
# get PID list without heading
(( $(UNIX95='' ps -o pid= -p ${_SSHD_PID}| wc -l) == 0 )) && _STC=1
else
# not running
_RC=1
fi
else
_RC=1
fi
# 2) try the pgrep way (note: old pgreps do not support '-c')
if (( _RC > 0 ))
then
(( $(pgrep -P 1 -u root sshd 2>>${HC_STDERR_LOG} | wc -l) == 0 )) && _STC=1
fi
# evaluate results
case ${_STC} in
0)
_MSG="sshd is running"
;;
1)
_MSG="sshd is not running"
;;
*)
_MSG="could not determine status of sshd"
;;
esac
# report results
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
NAME : $1
VERSION : $2
PURPOSE : Checks whether sshd (Secure Shell daemon) is running
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+209
View File
@@ -0,0 +1,209 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_hpux_syslog.sh
#******************************************************************************
# @(#) Copyright (C) 2016 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_hpux_syslog
# DOES: see _show_usage()
# EXPECTS: see _show_usage()
# REQUIRES: data_comma2space(), init_hc(), log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2016-06-20: initial version [Patrick Van der Veken]
# @(#) 2017-05-18: do not update the state file with --no-log [Patrick Van der Veken]
# @(#) 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!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_hpux_syslog
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _STATE_FILE="${STATE_PERM_DIR}/discovered.syslog"
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="HP-UX" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _STC_COUNT=0
typeset _CFG_HEALTHY=""
typeset _LOG_HEALTHY=0
typeset _TMP_FILE="${TMP_DIR}/.$0.tmp.$$"
typeset _CLASSES_LINE=""
typeset _SYSLOG_FILE=""
typeset _SYSLOG_CLASSES=""
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
esac
done
# set local trap for cleanup
# shellcheck disable=SC2064
trap "[[ -f ${_TMP_FILE} ]] && rm -f ${_TMP_FILE} >/dev/null 2>&1; return 1" 1 2 3 15
# handle configuration file
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
if [[ ! -r ${_CONFIG_FILE} ]]
then
warn "unable to read configuration file at ${_CONFIG_FILE}"
return 1
fi
# read required configuration values
_SYSLOG_FILE=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'syslog_file')
if [[ -z "${_SYSLOG_FILE}" ]]
then
# default
_SYSLOG_FILE="/var/adm/syslog/syslog.log"
fi
_CLASSES_LINE=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'syslog_classes')
if [[ -z "${_CLASSES_LINE}" ]]
then
# default (mind the complex regex!, support facility[PID])
_SYSLOG_CLASSES="vmunix(\[[0-9]+\])?:"
else
# convert comma's (mind the complex regex!, support facility[PID])
_SYSLOG_CLASSES=$(print "${_CLASSES_LINE}" | sed 's/,/(\\[[0-9]+\\])\?:\|/g')
# add PID qualifier to last item
_SYSLOG_CLASSES="${_SYSLOG_CLASSES}(\[[0-9]+\])?:"
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
# 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 SYSLOG file
[[ -r ${_SYSLOG_FILE} ]] || _MSG="SYSLOG file ${_SYSLOG_FILE} cannot be found"
if [[ -n "${_MSG}" ]]
then
# handle results
log_hc "$0" 1 "${_MSG}"
return 0
fi
# check state file
[[ -r ${_STATE_FILE} ]] || {
print "## this file is not date sorted! Do not edit manually!" >${_STATE_FILE}
(( $? > 0 )) && {
warn "failed to create new state file at ${_STATE_FILE}"
return 1
}
log "created new state file at ${_STATE_FILE}"
}
# filter current SYSLOG messages (must be uniquely sorted for 'comm')
log "searching SYSLOG with filter: ${_SYSLOG_CLASSES}"
grep -E -e "${_SYSLOG_CLASSES}" ${_SYSLOG_FILE} | sort -u >${_TMP_FILE} 2>/dev/null
# compare results to already discovered messages
comm -13 ${_STATE_FILE} ${_TMP_FILE} 2>/dev/null | sed 's/^ //g' >${HC_STDOUT_LOG}
# report results
_STC_COUNT=$(wc -l ${HC_STDOUT_LOG} 2>/dev/null | cut -f1 -d' ')
if (( _STC_COUNT > 0 ))
then
_MSG="found ${_STC_COUNT} new SYSLOG messages"
_STC=1
# add results to state file (must be sorted; re-use TMP_FILE)
sort -u ${HC_STDOUT_LOG} ${_STATE_FILE} >${_TMP_FILE}
(( $? > 0 )) && {
warn "failed to sort temporary state file"
return 1
}
if (( ARG_LOG > 0 ))
then
mv ${_TMP_FILE} ${_STATE_FILE} >/dev/null 2>&1
(( $? > 0 )) && {
warn "failed to move temporary state file to permanent state file ${_STATE_FILE}"
return 1
}
fi
else
_MSG="no new SYSLOG messages found"
fi
# report results
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
# do cleanup
[[ -f ${_TMP_FILE} ]] && rm -f ${_TMP_FILE} >/dev/null 2>&1
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with parameters:
log_healthy=<yes|no>
syslog_file=<path_to_syslog_file>
syslog_classes=<list_of_facility_classes_to_search_for>
PURPOSE : Provides a KISS syslog monitor (keep tracks of already discovered messages in
a state file and compares new lines in SYSLOG to the ones kept in the
state file. The plugin will sort both state & SYSLOG data before doing
the comparison.
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+176
View File
@@ -0,0 +1,176 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_hpux_syslogd_status.sh
#******************************************************************************
# @(#) Copyright (C) 2019 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_hpux_syslogd_status
# DOES: see _show_usage()
# EXPECTS: n/a
# REQUIRES: data_comma2space(), init_hc(), log_hc()
#
# @(#) HISTORY:
# @(#) 2018-02-08: initial version [Patrick Van der Veken]
# @(#) 2018-02-13: fix to avoid log check if syslogd is not active [Patrick Van der Veken]
# @(#) 2019-03-09: text updates [Patrick Van der Veken]
# @(#) 2019-03-16: replace 'which' [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_hpux_syslogd_status
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _SYSLOGD_PID_FILE="/var/run/syslog.pid"
typeset _SYSLOGD_LOG_FILE="/var/adm/syslog.log"
typeset _VERSION="2019-03-16" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="HP-UX" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _SYSLOGD_PID=""
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _RC=0
typeset _LOGGER_BIN=""
typeset _LOG_HEALTHY=0
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
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
# ---- process state ----
# 1) try using the PID way
if [[ -r "${_SYSLOGD_PID_FILE}" ]]
then
(( ARG_DEBUG > 0 )) && debug "checking syslogd service via PID file"
_SYSLOGD_PID=$(<${_SYSLOGD_PID_FILE})
if [[ -n "${_SYSLOGD_PID}" ]]
then
# get PID list without heading
(( $(UNIX95='' ps -o pid= -p ${_SYSLOGD_PID} 2>>${HC_STDERR_LOG} | wc -l 2>/dev/null) == 0 )) && _STC=1
else
# not running
_RC=1
fi
else
_RC=1
fi
# 2) try the pgrep way (note: old pgreps do not support '-c')
if (( _RC > 0 ))
then
(( ARG_DEBUG > 0 )) && debug "checking syslogd service via pgrep"
(( $(pgrep -u root syslogd 2>>${HC_STDERR_LOG} | wc -l 2>/dev/null) == 0 )) && _STC=1
fi
# evaluate results
case ${_STC} in
0)
_MSG="syslogd is running"
;;
1)
_MSG="syslogd is not running"
;;
*)
_MSG="could not determine status of syslogd"
;;
esac
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
# return if syslogd is not running
(( _STC > 0 )) && return 1
fi
# ---- log state ----
_LOGGER_BIN="$(command -v logger 2>>${HC_STDERR_LOG})"
if [[ -x ${_LOGGER_BIN} && -n "${_LOGGER_BIN}" ]]
then
# write test entry
(( ARG_DEBUG > 0 )) && debug "checking syslogd log via {${_LOGGER_BIN}}"
${_LOGGER_BIN} -i -t "check_health" "*** LOG CHECK ***" >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG}
if (( $? == 0 ))
then
_MSG="syslogd is logging correctly, write via {${_LOGGER_BIN}} OK"
_STC=0
else
_MSG="syslogd is not logging (correctly), write via {${_LOGGER_BIN}} NOK"
_STC=1
fi
else
# check the syslog itself
(( ARG_DEBUG > 0 )) && debug "checking syslogd log via file check"
if [[ -r ${_SYSLOGD_LOG_FILE} ]] && [[ -s ${_SYSLOGD_LOG_FILE} ]]
then
_MSG="syslogd is logging correctly (${_CRON_LOG_FILE})"
_STC=0
else
_MSG="syslogd is not logging (correctly) (${_SYSLOGD_LOG_FILE})"
_STC=1
fi
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
PURPOSE : Checks whether syslogd service is running and whether syslogd
is actually logging to ${_SYSLOGD_LOG_FILE}.
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+128
View File
@@ -0,0 +1,128 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_hpux_vg_minor_number
#******************************************************************************
# @(#) Copyright (C) 2016 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_hpux_vg_minor_number
# DOES: see _show_usage()
# EXPECTS: n/a
# REQUIRES: data_comma2space(), init_hc(), log_hc()
#
# @(#) HISTORY:
# @(#) 2016-04-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!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_hpux_vg_minor_number
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="HP-UX" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _LOG_HEALTHY=0
typeset _VG=""
typeset _VG_DUPE=""
typeset _VG_DUPES=""
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
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
# get list of major and minor numbers for vgs
vgdisplay -F 2>>${HC_STDERR_LOG} | cut -f1 -d':' 2>/dev/null | cut -f2 -d'=' 2>/dev/null |\
while read -r _VG
do
ls -l ${_VG}/group >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG}
done
# check unique combination of major/minor numbers
_VG_DUPES="$(awk '{ print $5":"$6 }' ${HC_STDOUT_LOG} | sort | uniq -d)"
if [[ -n ${_VG_DUPES} ]]
then
print "${_VG_DUPES}" | while read -r _VG_DUPE
do
_MSG="MAJ/MIN numbers combination '${_VG_DUPE}' is not unique"
_STC=1
# report result
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
done
else
_MSG="no VGs with duplicate MAJ/MIN numbers detected"
# report result
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
fi
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
PURPOSE : Checks whether all volume groups have a unique minor number
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+372
View File
@@ -0,0 +1,372 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_linux_burp_backup.sh
#******************************************************************************
# @(#) Copyright (C) 2016 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_linux_burp_backup
# DOES: see _show_usage()
# EXPECTS: see _show_usage()
# REQUIRES: data_comma2space(), data_is_numeric(), data_strip_outer_space(),
# init_hc(), log_hc(), warn()
# GNU date that can calculate UNIX epoch seconds from given date,
# BURP server must be be able to impersonate configured clients
#
# @(#) HISTORY:
# @(#) 2016-12-01: initial version [Patrick Van der Veken]
# @(#) 2018-05-21: STDERR fixes [Patrick Van der Veken]
# @(#) 2018-08-25: support for burp v2 [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: changed format of stanzas in configuration file &
# @(#) added support for --log-healthy [Patrick Van der Veken]
# @(#) 2019-03-10: fix for burp v2
# @(#) 2019-03-16: replace 'which' [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_linux_burp_backup
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _BURP_SERVER_CONFIG_FILE="/etc/burp/burp-server.conf"
typeset _BURP_CLIENT_CONFIG_FILE="/etc/burp/burp.conf"
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _VERSION="2019-03-16" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _CFG_HEALTHY=""
typeset _LOG_HEALTHY=0
typeset _BURP_BIN=""
typeset _BURP_AGE=""
typeset _BURP_BACKUP_DIR=""
typeset _BURP_CLIENTCONF_DIR=""
typeset _BURP_CLIENT=""
typeset _BURP_VERSION=""
typeset _BURP_WARNINGS=""
typeset _GNU_DATE=""
typeset _COUNT=1
typeset _IS_OLD_STYLE=0
typeset _NOW="$(date '+%Y%m%d %H%M' 2>/dev/null)" # format: YYYYMMDD HHMM
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
esac
done
# handle configuration file
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
if [[ ! -r ${_CONFIG_FILE} ]]
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 "^client:" ${_CONFIG_FILE} 2>/dev/null)
if (( _IS_OLD_STYLE == 0 ))
then
warn "no 'client:' 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
# check for capable GNU date
_GNU_DATE=$(date --date="1 day ago" '+%s' 2>/dev/null)
data_is_numeric "${_GNU_DATE}"
if (( $? > 0 ))
then
warn "no capable GNU date found here"
return 1
fi
# find burp
_BURP_BIN="$(command -v burp 2>/dev/null)"
if [[ ! -x ${_BURP_BIN} || -z "${_BURP_BIN}" ]]
then
warn "burp is not installed here"
return 1
fi
# burp v1 or v2?
_BURP_VERSION="$(${_BURP_BIN} -v 2>/dev/null)"
(( ARG_DEBUG > 0 )) && debug "burp version: ${_BURP_VERSION}"
case "${_BURP_VERSION}" in
burp-2*)
# check for burp server
if [[ ! -r ${_BURP_SERVER_CONFIG_FILE} ]]
then
warn "burp server configuration file not found ($_BURP_SERVER_CONFIG_FILE)"
return 1
fi
# check for burp client
if [[ ! -r ${_BURP_CLIENT_CONFIG_FILE} ]]
then
warn "burp client configuration file not found ($_BURP_SERVER_CONFIG_FILE)"
return 1
fi
# burp v2 does not support yet the 'burp -a S -C <client> -z backup_stats' action
# so we need to find the backup_stats file ourselves
_BURP_BACKUP_DIR=$(_CONFIG_FILE="${_BURP_SERVER_CONFIG_FILE}" data_get_lvalue_from_config 'directory')
if [[ -z "${_BURP_BACKUP_DIR}" ]]
then
_BURP_CLIENTCONF_DIR=$(_CONFIG_FILE="${_BURP_SERVER_CONFIG_FILE}" data_get_lvalue_from_config 'clientconfdir')
if [[ -z "${_BURP_CLIENTCONF_DIR}" ]]
then
warn "could not determine backup directory from 'directory' or 'clientconfdir' directives'"
return 1
fi
fi
;;
burp-1*)
# check for burp server
if [[ ! -r ${_BURP_SERVER_CONFIG_FILE} ]]
then
warn "burp server configuration file not found ($_BURP_SERVER_CONFIG_FILE)"
return 1
fi
;;
*)
warn "incorrect burp version reported: ${_BURP_VERSION}"
return 1
;;
esac
# check backup runs of clients
grep -E -e "^client:" ${_CONFIG_FILE} 2>/dev/null |\
while IFS=':' read _ _BURP_CLIENT _BURP_WARNINGS _BURP_AGE
do
typeset _BACKUP_AGING=""
typeset _BACKUP_DATE=""
typeset _BACKUP_RUN=""
typeset _BACKUP_STATS=""
typeset _BACKUP_WARNINGS="" # set empty string, not 0!
typeset _CUR_BACKUP_TIME=""
typeset _MIN_BACKUP_TIME=""
typeset _STC=0
if [[ -n "${_BURP_CLIENT}" ]] && [[ -n "${_BURP_WARNINGS}" ]] && [[ -n "${_BURP_AGE}" ]]
then
# convert backup aging (UNIX seconds)
case "${_BURP_AGE}" in
*h)
_BACKUP_AGING="${_BURP_AGE%%h}"
_MIN_BACKUP_TIME=$(( $(date -d "${_NOW}" '+%s' 2>/dev/null) - (_BACKUP_AGING * 60 * 60) ))
;;
*d)
_BACKUP_AGING="${_BURP_AGE%%d}"
_MIN_BACKUP_TIME=$(( $(date -d "${_NOW}" '+%s' 2>/dev/null) - (_BACKUP_AGING * 60 * 60 * 24) ))
;;
*w)
_BACKUP_AGING="${_BURP_AGE%%w}"
_MIN_BACKUP_TIME=$(( $(date -d "${_NOW}" '+%s' 2>/dev/null) - (_BACKUP_AGING * 60 * 60 * 24 * 7) ))
;;
*)
warn "no correct backup age specified for client ${_BURP_CLIENT}"
_COUNT=$(( _COUNT + 1 ))
continue
;;
esac
# get the most recent burp backup of the client
# ex.:
# Backup: 0000078 2016-11-27 03:39:03 (deletable)
# Backup: 0000079 2016-12-04 03:59:04
_BACKUP_STATS="$(${_BURP_BIN} -a l -C ${_BURP_CLIENT} 2>>${HC_STDERR_LOG} | grep '^Backup' | tail -n 1 | cut -f2- -d':')"
if [[ -n "${_BACKUP_STATS}" ]]
then
_BACKUP_RUN="$(print ${_BACKUP_STATS} | awk '{print $1}')"
# output format: YYYYMMDD HHMM
_BACKUP_DATE=$(print "${_BACKUP_STATS}" | awk '{gsub(/-/,"",$2); gsub(/:/,"",$3); print $2" "substr($3,0,4)}' 2>/dev/null)
# convert to UNIX seconds
_CUR_BACKUP_TIME=$(date -d "${_BACKUP_DATE}" '+%s' 2>/dev/null)
else
warn "no backup found for client ${_BURP_CLIENT}. Check client impersonation?"
_COUNT=$(( _COUNT + 1 ))
continue
fi
# get backup warnings
case "${_BURP_VERSION}" in
burp-2*)
# burp v2 does not yet support the 'burp -a S -C <client> -z backup_stats' action
# so we need to find the backup_stats file ourselves
# first check client override
_BURP_BACKUP_DIR=""; _BURP_CLIENTCONF_DIR=""
_BURP_CLIENTCONF_DIR=$(_CONFIG_FILE="${_BURP_SERVER_CONFIG_FILE}" data_get_lvalue_from_config 'clientconfdir')
_BURP_CLIENTCONF_DIR=$(data_strip_outer_space "${_BURP_CLIENTCONF_DIR}")
if [[ -n "${_BURP_CLIENTCONF_DIR}" ]]
then
_BURP_CLIENTCONF_FILE=${_BURP_CLIENTCONF_DIR}/${_BURP_CLIENT}
if [[ -r ${_BURP_CLIENTCONF_FILE} ]]
then
_BURP_BACKUP_DIR=$(_CONFIG_FILE="${_BURP_CLIENTCONF_FILE}" data_get_lvalue_from_config 'directory')
_BURP_BACKUP_DIR=$(data_strip_outer_space "${_BURP_BACKUP_DIR}")
else
warn "no client configuration file for client ${_BURP_CLIENT}, trying server configuration next"
fi
fi
# check server setting
if [[ -z "${_BURP_BACKUP_DIR}" ]]
then
_BURP_BACKUP_DIR=$(_CONFIG_FILE="${_BURP_SERVER_CONFIG_FILE}" data_get_lvalue_from_config 'directory')
_BURP_BACKUP_DIR=$(data_strip_outer_space "${_BURP_BACKUP_DIR}")
if [[ -z "${_BURP_BACKUP_DIR}" ]]
then
warn "could not determine backup directory from 'clientconfdir' or 'directory' directives' for client ${_BURP_CLIENT}"
continue
fi
fi
if [[ -r ${_BURP_BACKUP_DIR}/${_BURP_CLIENT}/current/log.gz ]]
then
_BACKUP_WARNINGS=$(zcat ${_BURP_BACKUP_DIR}/${_BURP_CLIENT}/current/log.gz 2>/dev/null | grep -c "WARNING:" 2>/dev/null)
else
warn "could not find ${_BURP_BACKUP_DIR}/${_BURP_CLIENT}/current/log.gz"
continue
fi
;;
burp-1*)
_BACKUP_WARNINGS=$(${_BURP_BIN} -c ${_BURP_SERVER_CONFIG_FILE} -a S -C ${_BURP_CLIENT} -b ${_BACKUP_RUN} -z backup_stats 2>>${HC_STDERR_LOG} |\
grep '^warnings' 2>/dev/null | cut -f2 -d':' 2>/dev/null)
;;
esac
if [[ -z "${_BACKUP_WARNINGS}" ]]
then
warn "could not get warnings for backup ${_BACKUP_RUN} of client ${_BURP_CLIENT}"
_COUNT=$(( _COUNT + 1 ))
continue
fi
# check & evaluate the results
if (( _BACKUP_WARNINGS > _BURP_WARNINGS ))
then
_STC=$(( _STC + 1 ))
fi
if (( _CUR_BACKUP_TIME < _MIN_BACKUP_TIME ))
then
_STC=$(( _STC + 2 ))
fi
# report the results
case ${_STC} in
0)
_MSG="backup ${_BACKUP_RUN} of client ${_BURP_CLIENT} is OK"
;;
1)
_MSG="backup ${_BACKUP_RUN} of client ${_BURP_CLIENT} has too many warnings (${_BACKUP_WARNINGS}>${_BURP_WARNINGS})"
;;
2)
_MSG="backup ${_BACKUP_RUN} of client ${_BURP_CLIENT} is too old (>${_BURP_AGE})"
;;
3)
_MSG="backup ${_BACKUP_RUN} of client ${_BURP_CLIENT} is too old (>${_BURP_AGE}) and has too many warnings (${_BACKUP_WARNINGS}>${_BURP_WARNINGS})"
;;
*)
:
;;
esac
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
_COUNT=$(( _COUNT + 1 ))
# save STDOUT
if (( _STC > 0 ))
then
print "=== ${_BURP_CLIENT}: ${_BACKUP_RUN} ===" >>${HC_STDOUT_LOG}
case "${_BURP_VERSION}" in
burp-2*)
if [[ -r ${_BURP_BACKUP_DIR}/${_BURP_CLIENT}/current/log.gz ]]
then
zcat ${_BURP_BACKUP_DIR}/${_BURP_CLIENT}/current/log.gz >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG}
fi
;;
burp-1*)
${_BURP_BIN} -c ${_BURP_SERVER_CONFIG_FILE} -a S -C ${_BURP_CLIENT} -b ${_BACKUP_RUN} -z log.gz >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG}
;;
esac
fi
else
warn "bad entry in the configuration file ${_CONFIG_FILE} on data line ${_COUNT}"
_COUNT=$(( _COUNT + 1 ))
continue
fi
done
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with parameters:
log_healthy=<yes|no>
and formatted stanzas:
client:<client_name>:<max_warnings_allowed>:<max_backup_age>(d|h|w)
PURPOSE : Checks the status and age of saved burp client backups.
Should only be run only on a burp backup server (supports burp v1 and v2)
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+147
View File
@@ -0,0 +1,147 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_linux_burp_status.sh
#******************************************************************************
# @(#) Copyright (C) 2016 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_linux_burp_status
# DOES: see _show_usage()
# EXPECTS: n/a
# REQUIRES: data_comma2space(), linux_get_init(), init_hc(), log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2016-12-01: initial version [Patrick Van der Veken]
# @(#) 2017-05-08: fix fall-back for sysv->pgrep [Patrick Van der Veken]
# @(#) 2018-05-21: STDERR fixes [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!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_linux_burp_status
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _BURP_INIT_SCRIPT="/etc/init.d/burp"
typeset _BURP_SYSTEMD_SERVICE="burp.service"
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _LOG_HEALTHY=0
typeset _RC=0
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
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
# 1) try using the init ways
linux_get_init
case "${LINUX_INIT}" in
'systemd')
systemctl --quiet is-active ${_BURP_SYSTEMD_SERVICE} 2>>${HC_STDERR_LOG} || _STC=1
;;
'upstart')
warn "code for upstart managed systems not implemented, NOOP"
return 1
;;
'sysv')
if [[ -x ${_BURP_INIT_SCRIPT} ]]
then
if (( $(${_BURP_INIT_SCRIPT} status 2>>${HC_STDERR_LOG} | grep -c -i 'is running' 2>/dev/null) == 0 ))
then
_STC=1
fi
else
warn "sysv init script not found {${_BURP_INIT_SCRIPT}}"
_RC=1
fi
;;
*)
_RC=1
;;
esac
# 2) try the pgrep way (note: old pgreps do not support '-c')
if (( _RC > 0 ))
then
(( $(pgrep -u root burp 2>>${HC_STDERR_LOG} | wc -l 2>/dev/null) == 0 )) && _STC=1
fi
# evaluate results
case ${_STC} in
0)
_MSG="burp is running"
;;
1)
_MSG="burp is not running"
;;
*)
_MSG="could not determine status of burp"
;;
esac
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
PURPOSE : Checks whether a Burp (backup server daemon) is running
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+167
View File
@@ -0,0 +1,167 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_linux_es_status.sh
#******************************************************************************
# @(#) Copyright (C) 2019 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_linux_es_status
# DOES: see _show_usage()
# EXPECTS: n/a
# REQUIRES: curl, data_comma2space(), dump_logs(), init_hc(), log_hc()
#
# @(#) HISTORY:
# @(#) 2019-03-09: initial version [Patrick Van der Veken]
# @(#) 2019-03-16: replace 'which' [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_linux_es_status
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _VERSION="2019-03-16" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _CFG_HEALTHY=""
typeset _LOG_HEALTHY=0
typeset _CFG_ES_URL=""
typeset _API_URL=""
typeset _ES_STATUS=""
typeset _ES_URL=""
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
esac
done
# handle configuration file
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
if [[ ! -r ${_CONFIG_FILE} ]]
then
warn "unable to read configuration file at ${_CONFIG_FILE}"
return 1
fi
# read configuration values
_CFG_ES_URL=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'es_url')
if [[ -z "${_CFG_ES_URL}" ]]
then
warn "no value for 'es_url' specified in ${_CONFIG_FILE}, using localhost default"
_ES_URL="http://localhost:9200"
else
_ES_URL="${_CFG_ES_URL}"
fi
_API_URL="${_ES_URL}/_cat/health?h=status"
_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 curl
_CURL_BIN="$(command -v curl 2>>${HC_STDERR_LOG})"
if [[ ! -x ${_CURL_BIN} || -z "${_CURL_BIN}" ]]
then
warn "curl is not installed here"
return 1
fi
# get cluster check_linux_es_status
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && debug "curl command: ${_CURL_BIN} -XGET '${_API_URL}'"
_ES_STATUS=$(${_CURL_BIN} -XGET "${_API_URL}" 2>>${HC_STDERR_LOG})
if (( $? > 0 )) || [[ -z "${_ES_STATUS}" ]]
then
_MSG="unable to run command {${_CURL_BIN} -XGET '${_API_URL}'}"
log_hc "$0" 1 "${_MSG}"
# dump debug info
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
fi
# parse status results
case "${_ES_STATUS}" in
green)
_MSG="state of ES instance at ${_ES_URL} is OK [${_ES_STATUS}]"
_STC=0
;;
yellow|red)
_MSG="state of ES instance at ${_ES_URL} is NOK [${_ES_STATUS}]"
_STC=1
;;
*)
_MSG="state of ES instance at ${_ES_URL} is NOK [unknown]"
_STC=1
;;
esac
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}" "${_ES_STATUS}" "green"
fi
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with parameters:
log_healthy=<yes|no>
es_url=<url_of_es_api>
PURPOSE : Checks the status of an Elastich search instance (green)
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+184
View File
@@ -0,0 +1,184 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_linux_file_age.sh
#******************************************************************************
# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_linux_file_age
# DOES: see _show_usage()
# EXPECTS: see _show_usage()
# REQUIRES: GNU find, data_comma2space(), data_is_numeric(), init_hc(),
# log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2013-05-27: initial version [Patrick Van der Veken]
# @(#) 2018-05-21: STDERR fixes [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!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_linux_file_age
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
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}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
esac
done
# handle configuration file
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
if [[ ! -r ${_CONFIG_FILE} ]]
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 -E -e "^file:" ${_CONFIG_FILE} 2>/dev/null | while IFS=":" read -r _ _FILE_PATH _FILE_AGE
do
# split file/dir
_FILE_NAME=$(print "${_FILE_PATH##*/}")
_FILE_DIR=$(print "${_FILE_PATH%/*}")
# check config
if [[ -z "${_FILE_PATH}" ]] && [[ -z "${_FILE_AGE}" ]]
then
warn "missing values in configuration file at ${_CONFIG_FILE}"
return 1
fi
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}" ]]
then
_MSG="unable to read or access requested file at ${_FILE_PATH}"
_STC=1
else
_AGE_CHECK=$(find "${_FILE_DIR}" -type f -name "${_FILE_NAME}" -mmin -"${_FILE_AGE}" 2>/dev/null)
if (( $? > 0 ))
then
warn "unable to execute file age test for ${_FILE_PATH}"
return 1
fi
if [[ -z "${_AGE_CHECK}" ]]
then
_MSG="file age of ${_FILE_AGE} has expired on ${_FILE_PATH}"
_STC=1
else
_MSG="file age of ${_FILE_AGE} has not expired on ${_FILE_PATH}"
fi
fi
# report result
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
_STC=0
done
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with parameters:
log_healthy=<yes|no>
and formatted stanzas:
file:<file_path>:<max_age_in_minutes>
PURPOSE : Checks whether given files have been changed in the last n minutes
(requires GNU find)
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+412
View File
@@ -0,0 +1,412 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_linux_file_change.sh
#******************************************************************************
# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_linux_file_change
# DOES: see _show_usage()
# EXPECTS: see _show_usage()
# REQUIRES: data_comma2space(), init_hc(), log_hc(), warn(),
# openssl (sha256 digest) OR cksum (CRC32 digest)
#
# @(#) HISTORY:
# @(#) 2017-05-18: initial version [Patrick Van der Veken]
# @(#) 2018-05-21: STDERR fixes [Patrick Van der Veken]
# @(#) 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]
# @(#) 2019-03-16: replace 'which' [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_linux_file_change
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _VERSION="2019-03-16" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
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=""
typeset _STATE_FILE_LINE=""
typeset _FILE_TO_CHECK=""
typeset _EXCL_OBJECT=""
typeset _INCL_OBJECT=""
typeset _HAS_OPENSSL=0
typeset _HAS_CKSUM=0
typeset _OPENSSL_BIN=""
typeset _CKSUM_BIN=""
typeset _USE_OPENSSL=0
typeset _USE_CKSUM=0
typeset _TMP1_FILE="${TMP_DIR}/.$0.tmp1.$$"
typeset _TMP2_FILE="${TMP_DIR}/.$0.tmp2.$$"
typeset _TMP_INCL_FILE="${TMP_DIR}/.$0.tmp_incl.$$"
typeset _TMP_EXCL_FILE="${TMP_DIR}/.$0.tmp_excl.$$"
set -o noglob # no file globbing
# set local trap for clean-up
# shellcheck disable=SC2064
trap "[[ -f ${_TMP1_FILE} ]] && rm -f ${_TMP1_FILE} >/dev/null 2>&1;
[[ -f ${_TMP2_FILE} ]] && rm -f ${_TMP2_FILE} >/dev/null 2>&1;
[[ -f ${_TMP_INCL_FILE} ]] && rm -f ${_TMP_INCL_FILE} >/dev/null 2>&1;
[[ -f ${_TMP_EXCL_FILE} ]] && rm -f ${_TMP_EXCL_FILE} >/dev/null 2>&1;
return 1" 1 2 3 15
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
esac
done
# handle configuration file
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
if [[ ! -r ${_CONFIG_FILE} ]]
then
warn "unable to read configuration file at ${_CONFIG_FILE}"
return 1
fi
# read required configuration values
_CFG_STATE_FILE=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'state_file')
if [[ -z "${_CFG_STATE_FILE}" ]]
then
_STATE_FILE="${STATE_PERM_DIR}/discovered.file_change"
else
_STATE_FILE="${STATE_PERM_DIR}/${_CFG_STATE_FILE}"
fi
log "using state file ${_STATE_FILE}"
_DO_META_CHECK=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'do_meta_check')
case "${_DO_META_CHECK}" in
no|NO|No)
_DO_META_CHECK=0
log "check for meta characters is disabled"
;;
*)
_DO_META_CHECK=1
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="$(command -v openssl 2>>${HC_STDERR_LOG})"
[[ -x ${_OPENSSL_BIN} && -n "${_OPENSSL_BIN}" ]] && _HAS_OPENSSL=1
_CKSUM_BIN="$(command -v cksum 2>>${HC_STDERR_LOG})"
[[ -x ${_CKSUM_BIN} && -n "${_CKSUM_BIN}" ]] && _HAS_CKSUM=1
# prefer openssl (for sha256)
if (( _HAS_OPENSSL == 1 ))
then
_USE_OPENSSL=1
elif (( _HAS_CKSUM == 1 ))
then
_USE_CKSUM=1
else
warn "unable to find the 'openssl/cksum' tools"
return 1
fi
# check state file & TMP_FILEs
[[ -r ${_STATE_FILE} ]] || {
: >${_STATE_FILE}
(( $? > 0 )) && {
warn "failed to create new state file at ${_STATE_FILE}"
return 1
}
log "created new state file at ${_STATE_FILE}"
}
: >${_TMP_INCL_FILE}
(( $? > 0 )) && {
warn "failed to create temporary file at ${_TMP_INCL_FILE}"
return 1
}
: >${_TMP_EXCL_FILE}
(( $? > 0 )) && {
warn "failed to create temporary file at ${_TMP_EXCL_FILE}"
return 1
}
: >${_TMP1_FILE}
(( $? > 0 )) && {
warn "failed to create temporary file at ${_TMP1_FILE}"
return 1
}
: >${_TMP2_FILE}
(( $? > 0 )) && {
warn "failed to create temporary file at ${_TMP2_FILE}"
return 1
}
# build list of configured objects: inclusion
grep -i '^incl:' ${_CONFIG_FILE} 2>/dev/null |\
while IFS=':' read _ _INCL_OBJECT
do
# check for meta & globbing characters (*?[]{}|)
if (( _DO_META_CHECK == 1 ))
then
case "${_INCL_OBJECT}" in
*\**|*\?*|*\[*|*\]*|*\{*|*\}*|*\|*)
warn "meta characters are not supported in the entry (incl:${_INCL_OBJECT})"
continue
;;
esac
fi
# expand directories
if [[ -d ${_INCL_OBJECT} ]]
then
find ${_INCL_OBJECT} -type f -xdev >>${_TMP_INCL_FILE} 2>>${HC_STDERR_LOG}
else
print ${_INCL_OBJECT} >>${_TMP_INCL_FILE}
fi
done
# build list of configured objects: exclusion
grep -i '^excl:' ${_CONFIG_FILE} 2>/dev/null |\
while IFS=':' read _ _EXCL_OBJECT
do
# check for meta & globbing characters (*?[]{}|)
if (( _DO_META_CHECK == 1 ))
then
case "${_EXCL_OBJECT}" in
*\**|*\?*|*\[*|*\]*|*\{*|*\}*|*\|*)
warn "meta characters are not supported in the entry (excl:${_EXCL_OBJECT})"
continue
;;
esac
fi
# expand directories
if [[ -d ${_EXCL_OBJECT} ]]
then
find ${_EXCL_OBJECT} -type f -xdev >>${_TMP_EXCL_FILE} 2>>${HC_STDERR_LOG}
else
print ${_EXCL_OBJECT} >>${_TMP_EXCL_FILE}
fi
done
# subtract exclusion from inclusion (exclusion has higher priority)
sort ${_TMP_INCL_FILE} -o ${_TMP_INCL_FILE} 2>>${HC_STDERR_LOG}
sort ${_TMP_EXCL_FILE} -o ${_TMP_EXCL_FILE} 2>>${HC_STDERR_LOG}
comm -23 ${_TMP_INCL_FILE} ${_TMP_EXCL_FILE} 2>>${HC_STDERR_LOG} >${_TMP1_FILE}
# check discovered objects
while read _FILE_TO_CHECK
do
# reset variables
_STC=0
_MSG=""
_IS_NEW=0
# object to check must be a file (and be present)
if [[ ! -f ${_FILE_TO_CHECK} ]]
then
_MSG="${_FILE_TO_CHECK} is not a file or has disappeared"
_STC=1
log_hc "$0" ${_STC} "${_MSG}"
continue
fi
# read entry from state file
_STATE_FILE_LINE=$(grep -E -e "^${_FILE_TO_CHECK}\|" ${_STATE_FILE} 2>/dev/null)
if [[ -n "${_STATE_FILE_LINE}" ]]
then
# field 1 is the file name
_STATE_FILE_TYPE=$(print "${_STATE_FILE_LINE}" | cut -f2 -d'|' 2>/dev/null)
_STATE_FILE_CKSUM=$(print "${_STATE_FILE_LINE}" | cut -f3 -d'|' 2>/dev/null)
else
_IS_NEW=1
fi
# compute new checksum (keep the same type as before)
if (( _IS_NEW == 0 ))
then
case "${_STATE_FILE_TYPE}" in
openssl-sha256)
if (( _USE_OPENSSL == 1 ))
then
_FILE_CKSUM=$(${_OPENSSL_BIN} dgst -sha256 ${_FILE_TO_CHECK} 2>>${HC_STDERR_LOG} | cut -f2 -d'=' 2>/dev/null | tr -d ' ' 2>/dev/null)
_FILE_TYPE="openssl-sha256"
else
_MSG="cannot compute checksum [${_FILE_TYPE}] for ${_FILE_TO_CHECK}"
_STC=1
fi
;;
cksum-crc32)
if (( _USE_CKSUM == 1 ))
then
_FILE_CKSUM=$(${_CKSUM_BIN} ${_FILE_TO_CHECK} 2>>${HC_STDERR_LOG} | cut -f1 -d' ' 2>/dev/null)
_FILE_TYPE="cksum-crc32"
else
_MSG="cannot compute checksum [${_FILE_TYPE}] for ${_FILE_TO_CHECK}"
_STC=1
fi
;;
*)
_MSG="cannot compute checksum (unknown checksum type) for ${_FILE_TO_CHECK}"
_STC=1
;;
esac
else
# new file
if (( _USE_OPENSSL == 1 ))
then
_FILE_CKSUM=$(${_OPENSSL_BIN} dgst -sha256 ${_FILE_TO_CHECK} 2>>${HC_STDERR_LOG} | cut -f2 -d'=' 2>/dev/null | tr -d ' ' 2>/dev/null)
_FILE_TYPE="openssl-sha256"
elif (( _USE_CKSUM == 1 ))
then
_FILE_CKSUM=$(${_CKSUM_BIN} ${_FILE_TO_CHECK} 2>>${HC_STDERR_LOG} | cut -f1 -d' ' 2>/dev/null)
_FILE_TYPE="cksum-crc32"
else
_MSG="cannot compute checksum (openssl/cksum) for ${_FILE_TO_CHECK}"
_STC=1
fi
fi
# check for failed checksums
if [[ -z "${_FILE_CKSUM}" ]]
then
_MSG="did not receive checksum (openssl/cksum) for ${_FILE_TO_CHECK}"
_STC=1
fi
# bounce failures back and jump to next file
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
continue
fi
if (( _IS_NEW == 0 ))
then
# compare old vs new checksums
if [[ "${_STATE_FILE_CKSUM}" != "${_FILE_CKSUM}" ]]
then
_MSG="${_FILE_TO_CHECK} has a changed checksum [${_FILE_TYPE}]"
_STC=1
else
_MSG="${_FILE_TO_CHECK} has the same checksum [${_FILE_TYPE}]"
_STC=0
fi
else
_MSG="${_FILE_TO_CHECK} is a new file [${_FILE_TYPE}]"
_STC=0
fi
# save entry to temp file
printf "%s|%s|%s\n" "${_FILE_TO_CHECK}" "${_FILE_TYPE}" "${_FILE_CKSUM}" >>${_TMP2_FILE}
# report with curr/exp values
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)
if (( ARG_LOG > 0 ))
then
[[ -s ${_TMP2_FILE} ]] || {
warn "no files found to check, zeroing new state file"
}
mv ${_TMP2_FILE} ${_STATE_FILE} >/dev/null 2>&1
(( $? > 0 )) && {
warn "failed to move temporary state file"
return 1
}
fi
# do cleanup
[[ -f ${_TMP1_FILE} ]] && rm -f ${_TMP1_FILE} >/dev/null 2>&1
[[ -f ${_TMP2_FILE} ]] && rm -f ${_TMP2_FILE} >/dev/null 2>&1
[[ -f ${_TMP_INCL_FILE} ]] && rm -f ${_TMP_INCL_FILE} >/dev/null 2>&1
[[ -f ${_TMP_EXCL_FILE} ]] && rm -f ${_TMP_EXCL_FILE} >/dev/null 2>&1
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with parameters:
log_healthy=<yes|no>
and formatted stanzas:
incl:<full path>
excl:<full path>
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
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+139
View File
@@ -0,0 +1,139 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_linux_fs_mounts.sh
#******************************************************************************
# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_linux_fs_mounts
# DOES: see _show_usage()
# EXPECTS: n/a
# REQUIRES: data_comma2space(), init_hc(), log_hc()
#
# @(#) HISTORY:
# @(#) 2013-05-17: initial version [Patrick Van der Veken]
# @(#) 2018-05-21: STDERR fixes [Patrick Van der Veken]
# @(#) 2018-08-25: small fix [Patrick Van der Veken]
# @(#) 2018-10-02: regex 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!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_linux_fs_mounts
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _LOG_HEALTHY=0
typeset _FS=""
typeset _FS_COUNT=0
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
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 only)
mount >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG}
if (( $? > 0 ))
then
warn "unable to execute {mount} command"
return 1
fi
# check for each configured file system (except /)
grep -v -E -e '^#' -e '^$' \
-e '[[:space:]]*.*[[:space:]]+(proc|swap|sysfs|devpts|tmpfs).*' \
-e '(floppy|cdrom)' \
-e '[[:space:]]*\/[[:space:]]+' /etc/fstab 2>/dev/null |\
awk '{print $2}' 2>/dev/null |\
while read _FS
do
_FS_COUNT=$(grep -c -E -e ".*on[ \t]+${_FS}[ \t]+.*" ${HC_STDOUT_LOG} 2>/dev/null)
case ${_FS_COUNT} in
0)
_MSG="${_FS} is not mounted"
_STC=1
;;
1)
_MSG="${_FS} is mounted"
;;
*)
_MSG="${_FS} is multiple times mounted?"
;;
esac
# report result
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
_STC=0
done
# add /etc/fstab to STDOUT log
cat /etc/fstab >>${HC_STDOUT_LOG} 2>/dev/null
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
PURPOSE : Checks whether file systems are mounted or not, exclude following FS types:
proc, swap, sysfs, devpts, tmpfs, cdrom & floppy
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+332
View File
@@ -0,0 +1,332 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_linux_fs_usage.sh
#******************************************************************************
# @(#) Copyright (C) 2019 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_linux_fs_usage
# DOES: see _show_usage()
# EXPECTS: n/a
# REQUIRES: data_comma2space(), init_hc(), log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2019-01-24: initial version [Patrick Van der Veken]
# @(#) 2019-01-27: regex fix [Patrick Van der Veken]
# @(#) 2019-01-30: refactored to support custom definitions with all
# filesystems check [Patrick Van der Veken]
# @(#) 2019-02-04: fix in cleanup [Patrick Van der Veken]
# @(#) 2019-02-18: fixes + help update [Patrick Van der Veken]
# @(#) 2019-03-25: exclude /dev/loop* + rationalization [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_linux_fs_usage
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _VERSION="2019-03-25" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _CFG_HEALTHY=""
typeset _LOG_HEALTHY=0
typeset _CFG_CHECK_INODES_USAGE=""
typeset _CFG_CHECK_SPACE_USAGE=""
typeset _CFG_MAX_INODES_USAGE=""
typeset _CFG_MAX_SPACE_USAGE=""
typeset _CFG_INODES_THRESHOLD=""
typeset _CFG_SPACE_THRESHOLD=""
typeset _FS=""
typeset _DO_INODES=0
typeset _DO_SPACE=0
typeset _INODES_LIST=""
typeset _SPACE_LIST=""
typeset _INODES_USAGE=1
typeset _SPACE_USAGE=1
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
check_inodes)
log "enabled check of inodes usage via cmd-line option"
_DO_INODES=1
;;
check_space)
log "enabled check of space usage via cmd-line option"
_DO_SPACE=1
;;
esac
done
# handle configuration file
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
if [[ ! -r ${_CONFIG_FILE} ]]
then
warn "unable to read configuration file at ${_CONFIG_FILE}"
return 1
fi
# read configuration values
_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
_CFG_CHECK_INODES_USAGE=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'check_inodes_usage')
case "${_CFG_CHECK_INODES_USAGE}" in
yes|YES|Yes)
log "enabled check of inodes usage via configuration file"
_DO_INODES=1
;;
*)
: # not set
;;
esac
_CFG_CHECK_SPACE_USAGE=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'check_space_usage')
case "${_CFG_CHECK_SPACE_USAGE}" in
yes|YES|Yes)
log "enabled check of space usage via configuration file"
_DO_SPACE=1
;;
*)
: # not set
;;
esac
_CFG_MAX_INODES_USAGE=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'max_inodes_usage')
if [[ -z "${_CFG_MAX_INODES_USAGE}" ]]
then
# default
_CFG_MAX_INODES_USAGE=90
fi
_CFG_MAX_SPACE_USAGE=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'max_space_usage')
if [[ -z "${_CFG_MAX_SPACE_USAGE}" ]]
then
# default
_CFG_MAX_SPACE_USAGE=90
fi
if (( _DO_INODES == 0 && _DO_SPACE == 0 ))
then
warn "you must enable at least one check (inode and/or space)"
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 (POSIX format)
if (( _DO_INODES > 0 ))
then
_INODES_LIST=$(df -Pil 2>>${HC_STDERR_LOG})
if (( $? > 0 ))
then
# df exits >0 if there are issues with some filesystems, consider non-fatal
warn "error(s) occurred executing the {df -Pil}"
fi
fi
if (( _DO_SPACE > 0 ))
then
_SPACE_LIST=$(df -Pl 2>>${HC_STDERR_LOG})
if (( $? > 0 ))
then
# df exits >0 if there are issues with some filesystems, consider non-fatal
warn "error(s) occurred executing {df -Pl}"
fi
fi
# 1) validate inodes (df -Pil)
if (( _DO_INODES > 0 ))
then
(( ARG_DEBUG > 0 )) && debug "checking inodes..."
print -r "${_INODES_LIST}" | grep '^\/' 2>/dev/null | grep -v -E -e '^/dev/loop' 2>/dev/null | awk '{print $6}' 2>/dev/null |\
while read -r _FS
do
(( ARG_DEBUG > 0 )) && debug "parsing inodes data for filesystem: ${_FS}"
# add space to grep; must be non-greedy!
_INODES_USAGE=$(print -r "${_INODES_LIST}" | grep -E -e " ${_FS}$" 2>/dev/null | awk '{gsub(/%/,"",$5);print $5}' 2>/dev/null)
data_is_numeric "${_INODES_USAGE}"
if (( $? > 0 ))
then
warn "discovered value for inodes usage is incorrect [${_FS}:${_INODES_USAGE}]"
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
continue
fi
# which threshold to use (general or custom?)
_CFG_FS_LINE=$(grep -E -e "^fs:${_FS}:" ${_CONFIG_FILE} 2>/dev/null)
if [[ -n "${_CFG_FS_LINE}" ]]
then
(( ARG_DEBUG > 0 )) && debug "found custom definition for ${_FS} in configuration file ${_CONFIG_FILE}"
_CFG_INODES_THRESHOLD=$(print "${_CFG_FS_LINE}" | cut -f3 -d':' 2>/dev/null)
# null value means general threshold
if [[ -z "${_CFG_INODES_THRESHOLD}" ]]
then
(( ARG_DEBUG > 0 )) && debug "found empty inodes threshold for ${_FS}, using general threshold"
_CFG_INODES_THRESHOLD=${_CFG_MAX_INODES_USAGE}
fi
data_is_numeric "${_CFG_INODES_THRESHOLD}"
if (( $? > 0 ))
then
warn "inodes parameter is not numeric for ${_FS} in configuration file ${_CONFIG_FILE}"
continue
fi
# zero value means disabled check
if (( _CFG_INODES_THRESHOLD == 0 ))
then
(( ARG_DEBUG > 0 )) && debug "found zero inodes threshold for ${_FS}, disabling check"
continue
fi
else
(( ARG_DEBUG > 0 )) && debug "no custom inodes threshold for ${_FS}, using general threshold"
_CFG_INODES_THRESHOLD=${_CFG_MAX_INODES_USAGE}
fi
# check against the treshold
if (( _INODES_USAGE > _CFG_INODES_THRESHOLD ))
then
_MSG="${_FS} exceeds its inode threshold (${_INODES_USAGE}%>${_CFG_INODES_THRESHOLD}%)"
_STC=1
else
_MSG="${_FS} does not exceed its inode threshold (${_INODES_USAGE}%<=${_CFG_INODES_THRESHOLD}%)"
_STC=0
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}" "${_INODES_USAGE}" "${_CFG_MAX_INODES_USAGE}"
fi
done
# add df output to stdout log_hc
print "==== df -Pil ====" >>${HC_STDOUT_LOG}
print -r "${_INODES_LIST}" >>${HC_STDOUT_LOG}
fi
# 2) validate space (df -Pl)
if (( _DO_SPACE > 0 ))
then
(( ARG_DEBUG > 0 )) && debug "checking space..."
print -r "${_SPACE_LIST}" | grep '^\/' 2>/dev/null | grep -v -E -e '^/dev/loop' 2>/dev/null | awk '{print $6}' 2>/dev/null |\
while read -r _FS
do
(( ARG_DEBUG > 0 )) && debug "parsing space data for filesystem: ${_FS}"
# add space to grep; must be non-greedy!
_SPACE_USAGE=$(print -r "${_SPACE_LIST}" | grep -E -e " ${_FS}$" 2>/dev/null | awk '{gsub(/%/,"",$5);print $5}' 2>/dev/null)
data_is_numeric "${_SPACE_USAGE}"
if (( $? > 0 ))
then
warn "discovered value for space usage is incorrect [${_FS}:${_SPACE_USAGE}]"
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
continue
fi
# which threshold to use (general or custom?)
_CFG_FS_LINE=$(grep -E -e "^fs:${_FS}:" ${_CONFIG_FILE} 2>/dev/null)
if [[ -n "${_CFG_FS_LINE}" ]]
then
(( ARG_DEBUG > 0 )) && debug "found custom definition for ${_FS} in configuration file ${_CONFIG_FILE}"
_CFG_SPACE_THRESHOLD=$(print "${_CFG_FS_LINE}" | cut -f4 -d':' 2>/dev/null)
# null value means general threshold
if [[ -z "${_CFG_SPACE_THRESHOLD}" ]]
then
(( ARG_DEBUG > 0 )) && debug "found empty space threshold for ${_FS}, using general threshold"
_CFG_SPACE_THRESHOLD=${_CFG_MAX_SPACE_USAGE}
fi
data_is_numeric "${_CFG_SPACE_THRESHOLD}"
if (( $? > 0 ))
then
warn "space parameter is not numeric for ${_FS} in configuration file ${_CONFIG_FILE}"
continue
fi
# zero value means disabled check
if (( _CFG_SPACE_THRESHOLD == 0 ))
then
(( ARG_DEBUG > 0 )) && debug "found zero space threshold for ${_FS}, disabling check"
continue
fi
else
(( ARG_DEBUG > 0 )) && debug "no custom space threshold for ${_FS}, using general threshold"
_CFG_SPACE_THRESHOLD=${_CFG_MAX_SPACE_USAGE}
fi
# check against the treshold
if (( _SPACE_USAGE > _CFG_SPACE_THRESHOLD ))
then
_MSG="${_FS} exceeds its space threshold (${_SPACE_USAGE}%>${_CFG_SPACE_THRESHOLD}%)"
_STC=1
else
_MSG="${_FS} does not exceed its space threshold (${_SPACE_USAGE}%<=${_CFG_SPACE_THRESHOLD}%)"
_STC=0
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}" "${_SPACE_USAGE}" "${_CFG_SPACE_THRESHOLD}"
fi
done
# add df output to stdout log_hc
print "==== df -Pl ====" >>${HC_STDOUT_LOG}
print -r "${_SPACE_LIST}" >>${HC_STDOUT_LOG}
fi
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with parameters:
log_healthy=<yes|no>
check_inodes_usage=<yes|no>
check_space_usage=<yes|no>
max_inodes_usage=<general_inodes_usage_treshold>
max_space_usage=<general_space_usage_treshold>
with formatted stanzas (optional):
fs:<fs_name>:<max_inodes_usage_%>:<max_space_usage_%>
EXT OPTIONS : --hc-args=check_inodes, --hc-args=check_space
PURPOSE : Checks the inodes & space usage for the configured or all (local) filesystems
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+318
View File
@@ -0,0 +1,318 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_linux_hpacucli.sh
#******************************************************************************
# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_linux_hpacucli
# DOES: see _show_usage()
# EXPECTS: see _show_usage()
# REQUIRES: data_comma2space(), data_is_numeric(), init_hc(), log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2013-09-09: initial version [Patrick Van der Veken]
# @(#) 2018-05-21: STDERR fixes [Patrick Van der Veken]
# @(#) 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 code for data_is_numeric() & support for
# @(#) --log-healthy [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_linux_hpacucli
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC_COUNT=0
typeset _CFG_HEALTHY=""
typeset _LOG_HEALTHY=0
typeset _TMP_FILE="${TMP_DIR}/.$0.tmp.$$"
typeset _HPACUCLI_BIN=""
typeset _ACU_LINE=""
typeset _SLOT_NUM=""
typeset _SLOT_NUMS=""
typeset _DO_ACU_CTRL=1
typeset _DO_ACU_ENCL=1
typeset _DO_ACU_PHYS=1
typeset _DO_ACU_LOGL=1
typeset _DO_CHECK=0
# set local trap for cleanup
# shellcheck disable=SC2064
trap "[[ -f ${_TMP_FILE} ]] && rm -f ${_TMP_FILE} >/dev/null 2>&1; return 1" 1 2 3 15
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
esac
done
# handle configuration file
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
if [[ ! -r ${_CONFIG_FILE} ]]
then
warn "unable to read configuration file at ${_CONFIG_FILE}"
return 1
fi
# read required configuration values
_HPACUCLI_BIN=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'hpacucli_bin')
if [[ -z "${_HPACUCLI_BIN}" ]]
then
warn "no value set for 'hpacucli_bin' in ${_CONFIG_FILE}"
return 1
fi
_DO_ACU_CTRL=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'do_acu_controller')
case "${_DO_ACU_CTRL}" in
0|1)
# on/off, OK
;;
*)
# set default
warn "illegal value for 'do_acu_controller' in ${_CONFIG_FILE}, using default"
_DO_ACU_CTRL=1
;;
esac
_DO_ACU_ENCL=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'do_acu_enclosure')
case "${_DO_ACU_ENCL}" in
0|1)
# on/off, OK
;;
*)
# set default
warn "illegal value for 'do_acu_enclosure' in ${_CONFIG_FILE}, using default"
_DO_ACU_ENCL=1
;;
esac
_DO_ACU_PHYS=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'do_acu_physical')
case "${_DO_ACU_PHYS}" in
0|1)
# on/off, OK
;;
*)
# set default
warn "illegal value for 'do_acu_physical' in ${_CONFIG_FILE}, using default"
_DO_ACU_PHYS=1
;;
esac
_DO_ACU_LOGL=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'do_acu_logical')
case "${_DO_ACU_LOGL}" in
0|1)
# on/off, OK
;;
*)
# set default
warn "illegal value for 'do_acu_logical' in ${_CONFIG_FILE}, using default"
_DO_ACU_LOGL=1
;;
esac
# check for dependencies: we need to do DO_ACU_CTRL to have the slot info for all
# the other checks
_DO_CHECK=$(( _DO_ACU_ENCL + _DO_ACU_PHYS + _DO_ACU_LOGL ))
if (( _DO_CHECK > 0 && _DO_ACU_CTRL == 0 ))
then
log "switching setting 'do_acu_controller' to 1 to fetch slot info"
_DO_ACU_CTRL=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
# 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 HP tools
if [[ ! -x ${_HPACUCLI_BIN} || -z "${_HPACUCLI_BIN}" ]]
then
warn "${_HPACUCLI_BIN} is not installed here"
return 1
fi
# --- perform checks ---
# CONTROLLER(s)
if (( _DO_ACU_CTRL > 0 ))
then
${_HPACUCLI_BIN} controller all show status >${_TMP_FILE} 2>${_TMP_FILE}
(( $? > 0 )) && warn "'${_HPACUCLI_BIN} controller all show status' exited non-zero"
# look for failures
grep -i -E -e "(nok|fail.*)" ${_TMP_FILE} 2>/dev/null |\
while read _ACU_LINE
do
_MSG="failure in controller"
_STC_COUNT=$(( _STC_COUNT + 1 ))
log_hc "$0" 1 "${_MSG}"
done
print "=== ACU controller(s) ===" >>${HC_STDOUT_LOG}
cat ${_TMP_FILE} >>${HC_STDOUT_LOG}
# get all slot numbers for multiple raid controllers
cat ${_TMP_FILE} | grep "in Slot [0-9]" 2>/dev/null | while read _ACU_LINE
do
_SLOT_NUM="$(print ${_ACU_LINE} | cut -f6 -d' ' 2>/dev/null)"
data_is_numeric "${_SLOT_NUM}"
if (( $? == 0 ))
then
_SLOT_NUMS="${_SLOT_NUMS} ${_SLOT_NUM}"
else
warn "found RAID controller at illegal slot?: ${_SLOT_NUM}"
fi
done
else
warn "${_HPACUCLI_BIN}: do_acu_controller check is not enabled"
fi
# ENCLOSURE(s)
if (( _DO_ACU_ENCL > 0 ))
then
for _CTRL_SLOT in ${_SLOT_NUMS}
do
${_HPACUCLI_BIN} controller slot=${_CTRL_SLOT} enclosure all show \
>${_TMP_FILE} 2>${_TMP_FILE}
(( $? > 0 )) && \
warn "'${_HPACUCLI_BIN} controller slot=${_CTRL_SLOT} enclosure all show' exited non-zero"
# look for failures
grep -i -E -e "(nok|fail.*)" ${_TMP_FILE} 2>/dev/null |\
while read _ACU_LINE
do
_MSG="failure in enclosure for controller ${_CTRL_SLOT}"
_STC_COUNT=$(( _STC_COUNT + 1 ))
log_hc "$0" 1 "${_MSG}"
done
print "=== ACU enclosure(s) ===" >>${HC_STDOUT_LOG}
cat ${_TMP_FILE} >>${HC_STDOUT_LOG}
done
else
warn "${_HPACUCLI_BIN}: do_acu_enclosure check is not enabled"
fi
# PHYSICAL DRIVE(s)
if (( _DO_ACU_PHYS > 0 ))
then
for _CTRL_SLOT in ${_SLOT_NUMS}
do
${_HPACUCLI_BIN} controller slot=${_CTRL_SLOT} physicaldrive all show status \
>${_TMP_FILE} 2>${_TMP_FILE}
(( $? > 0 )) && \
warn "'${_HPACUCLI_BIN} controller slot=${_CTRL_SLOT} physicaldrive all show status' exited non-zero"
# look for failures
grep -i -E -e "(nok|fail.*)" ${_TMP_FILE} 2>/dev/null |\
while read _ACU_LINE
do
_MSG="failure in physical drive(s) for controller ${_CTRL_SLOT}"
_STC_COUNT=$(( _STC_COUNT + 1 ))
log_hc "$0" 1 "${_MSG}"
done
print "=== ACU physical drive(s) ===" >>${HC_STDOUT_LOG}
cat ${_TMP_FILE} >>${HC_STDOUT_LOG}
done
else
warn "${_HPACUCLI_BIN}: do_acu_physical check is not enabled"
fi
# LOGICAL DRIVE(s)
if (( _DO_ACU_LOGL > 0 ))
then
for _CTRL_SLOT in ${_SLOT_NUMS}
do
${_HPACUCLI_BIN} controller slot=${_CTRL_SLOT} logicaldrive all show status \
>${_TMP_FILE} 2>${_TMP_FILE}
(( $? > 0 )) && \
warn "'${_HPACUCLI_BIN} controller slot=${_CTRL_SLOT}logicaldrive all show status' exited non-zero"
# look for failures
grep -i -E -e "(nok|fail)" ${_TMP_FILE} 2>/dev/null |\
while read _ACU_LINE
do
_MSG="failure in logical drive(s) for controller ${_CTRL_SLOT}"
_STC_COUNT=$(( _STC_COUNT + 1 ))
log_hc "$0" 1 "${_MSG}"
done
print "=== ACU logical drive(s) ===" >>${HC_STDOUT_LOG}
cat ${_TMP_FILE} >>${HC_STDOUT_LOG}
done
else
warn "${_HPACUCLI_BIN}: do_acu_logical check is not enabled"
fi
# report OK situation
if (( _LOG_HEALTHY > 0 && _STC_COUNT == 0 ))
then
_MSG="no problems detected by {${_HPACUCLI_BIN}}"
log_hc "$0" 0 "${_MSG}"
fi
# do cleanup
[[ -f ${_TMP_FILE} ]] && rm -f ${_TMP_FILE} >/dev/null 2>&1
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with parameters:
log_healthy=<yes|no>
hpacucli_bin=<location_of_hpacucli_tool>
do_acu_controller=<0|1>
do_acu_enclosure=<0|1>
do_acu_physical=<0|1>
do_acu_logical=<0|1>
PURPOSE : Checks for errors from the HP Proliant 'hpacucli' tool (see HP Proliant
support pack (PSP))
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+332
View File
@@ -0,0 +1,332 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_linux_hpasmcli.sh
#******************************************************************************
# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_linux_hpasmcli
# DOES: see _show_usage()
# EXPECTS: see _show_usage()
# REQUIRES: data_comma2space(), init_hc(), log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2013-09-07: initial version [Patrick Van der Veken]
# @(#) 2017-04-06: bugfix in temperature checking [Patrick Van der Veken]
# @(#) 2018-05-21: STDERR fixes [Patrick Van der Veken]
# @(#) 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!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_linux_hpasmcli
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC_COUNT=0
typeset _CFG_HEALTHY=""
typeset _LOG_HEALTHY=0
typeset _TMP_FILE="${TMP_DIR}/.$0.tmp.$$"
typeset _HPASMCLI_BIN=""
typeset _ASM_LINE=""
typeset _DO_ASM_FANS=1
typeset _DO_ASM_DIMM=1
typeset _DO_ASM_POWR=1
typeset _DO_ASM_SRVR=1
typeset _DO_ASM_TEMP=1
typeset _FAN_UNIT=""
typeset _TEMP_FIELD=""
typeset _TEMP_VALUE=""
typeset _THRES_FIELD=""
typeset _THRES_VALUE=""
typeset _TEMP_UNIT=""
# set local trap for cleanup
# shellcheck disable=SC2064
trap "[[ -f ${_TMP_FILE} ]] && rm -f ${_TMP_FILE} >/dev/null 2>&1; return 1" 1 2 3 15
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
esac
done
# handle configuration file
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
if [[ ! -r ${_CONFIG_FILE} ]]
then
warn "unable to read configuration file at ${_CONFIG_FILE}"
return 1
fi
# read required configuration values
_HPASMCLI_BIN=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'hpasmcli_bin')
if [[ -z "${_HPASMCLI_BIN}" ]]
then
warn "no value set for 'hpasmcli_bin' in ${_CONFIG_FILE}"
return 1
fi
_DO_ASM_FANS=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'do_asm_fans')
case "${_DO_ASM_FANS}" in
0|1)
# on/off, OK
;;
*)
# set default
warn "illegal value for 'do_asm_fans' in ${_CONFIG_FILE}, using default"
_DO_ASM_FANS=1
;;
esac
_DO_ASM_DIMM=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'do_asm_dimm')
case "${_DO_ASM_DIMM}" in
0|1)
# on/off, OK
;;
*)
# set default
warn "illegal value for 'do_asm_dimm' in ${_CONFIG_FILE}, using default"
_DO_ASM_DIMM=1
;;
esac
_DO_ASM_POWR=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'do_asm_powersupply')
case "${_DO_ASM_POWR}" in
0|1)
# on/off, OK
;;
*)
# set default
warn "illegal value for 'do_asm_powersupply' in ${_CONFIG_FILE}, using default"
_DO_ASM_POWR=1
;;
esac
_DO_ASM_SRVR=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'do_asm_server')
case "${_DO_ASM_POWR}" in
0|1)
# on/off, OK
;;
*)
# set default
warn "illegal value for 'do_asm_server' in ${_CONFIG_FILE}, using default"
_DO_ASM_SRVR=1
;;
esac
_DO_ASM_TEMP=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'do_asm_temperature')
case "${_DO_ASM_TEMP}" in
0|1)
# on/off, OK
;;
*)
# set default
warn "illegal value for 'do_asm_temperature' in ${_CONFIG_FILE}, using default"
_DO_ASM_TEMP=1
;;
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 HP tools
if [[ ! -x ${_HPASMCLI_BIN} || -z "${_HPASMCLI_BIN}" ]]
then
warn "${_HPASMCLI_BIN} is not installed here"
return 1
fi
# --- perform checks ---
# SHOW FANS
if (( _DO_ASM_FANS > 0 ))
then
${_HPASMCLI_BIN} -s 'SHOW FANS' >${_TMP_FILE} 2>${_TMP_FILE}
(( $? > 0 )) && warn "'${_HPASMCLI_BIN} -s SHOW FANS' exited non-zero"
# look for failures
grep -E -e '^#' ${_TMP_FILE} 2>/dev/null | grep -vi 'normal' 2>/dev/null |\
while read _ASM_LINE
do
_FAN_UNIT="$(print ${_ASM_LINE} | cut -f1 -d' ')"
_MSG="failure in 'SHOW FANS', unit ${_FAN_UNIT}"
_STC_COUNT=$(( _STC_COUNT + 1 ))
log_hc "$0" 1 "${_MSG}"
done
print "=== ASM fans ===" >>${HC_STDOUT_LOG}
cat ${_TMP_FILE} >>${HC_STDOUT_LOG}
else
warn "${_HPASMCLI_BIN}: do_asm_fans check not enabled"
fi
# SHOW DIMM
if (( _DO_ASM_DIMM > 0 ))
then
${_HPASMCLI_BIN} -s 'SHOW DIMM' >${_TMP_FILE} 2>${_TMP_FILE}
(( $? > 0 )) && warn "'${_HPASMCLI_BIN} -s SHOW DIMM' exited non-zero"
# look for failures
grep -i -E -e "(nok|fail)" ${_TMP_FILE} 2>/dev/null |\
while read _ASM_LINE
do
_MSG="failure in 'SHOW DIMM'"
_STC_COUNT=$(( _STC_COUNT + 1 ))
log_hc "$0" 1 "${_MSG}"
done
print "=== ASM DIMMs ===" >>${HC_STDOUT_LOG}
cat ${_TMP_FILE} >>${HC_STDOUT_LOG}
else
warn "${_HPASMCLI_BIN}: do_asm_dimm check not enabled"
fi
# SHOW POWERSUPPLY
if (( _DO_ASM_POWR > 0 ))
then
${_HPASMCLI_BIN} -s 'SHOW POWERSUPPLY' >${_TMP_FILE} 2>${_TMP_FILE}
(( $? > 0 )) && warn "'${_HPASMCLI_BIN} -s SHOW POWERSUPPLY' exited non-zero"
# look for failures
grep -i -E -e "(nok|fail)" ${_TMP_FILE} 2>/dev/null |\
while read _ASM_LINE
do
_MSG="failure in 'SHOW POWERSUPPLY'"
_STC_COUNT=$(( _STC_COUNT + 1 ))
log_hc "$0" 1 "${_MSG}"
done
print "=== ASM power supply ===" >>${HC_STDOUT_LOG}
cat ${_TMP_FILE} >>${HC_STDOUT_LOG}
else
warn "${_HPASMCLI_BIN}: do_asm_powersupply check not enabled"
fi
# SHOW SERVER
if (( _DO_ASM_SRVR > 0 ))
then
${_HPASMCLI_BIN} -s 'SHOW SERVER' >${_TMP_FILE} 2>${_TMP_FILE}
(( $? > 0 )) && warn "'${_HPASMCLI_BIN} -s SHOW SERVER' exited non-zero"
# look for failures
grep -i -E -e "(nok|fail)" ${_TMP_FILE} 2>/dev/null |\
while read _ASM_LINE
do
_MSG="failure in 'SHOW SERVER'"
_STC_COUNT=$(( _STC_COUNT + 1 ))
log_hc "$0" 1 "${_MSG}"
done
print "=== ASM server ===" >>${HC_STDOUT_LOG}
cat ${_TMP_FILE} >>${HC_STDOUT_LOG}
else
warn "${_HPASMCLI_BIN}: do_asm_server check not enabled"
fi
# SHOW TEMP
if (( _DO_ASM_TEMP > 0 ))
then
${_HPASMCLI_BIN} -s 'SHOW TEMP' >${_TMP_FILE} 2>${_TMP_FILE}
(( $? > 0 )) && warn "'${_HPASMCLI_BIN} -s SHOW TEMP' exited non-zero"
# look for failures
grep -E -e '^#' ${_TMP_FILE} 2>/dev/null |\
while read _ASM_LINE
do
_TEMP_FIELD="$(print ${_ASM_LINE} | cut -f3 -d' ' 2>/dev/null)"
_TEMP_VALUE="${_TEMP_FIELD%%C/*}"
_THRES_FIELD="$(print ${_ASM_LINE} | cut -f4 -d' ' 2>/dev/null)"
_THRES_VALUE="${_THRES_FIELD%%C/*}"
if [[ "${_TEMP_VALUE}" != "-" ]] && [[ "${_THRES_VALUE}" != "-" ]]
then
if (( _TEMP_VALUE >= _THRES_VALUE ))
then
_TEMP_UNIT="$(print ${_ASM_LINE} | cut -f1 -d' ' 2>/dev/null)"
_MSG="failure in 'SHOW TEMP', unit ${_TEMP_UNIT}"
_MSG="${_MSG} has ${_TEMP_VALUE} >= ${_THRES_VALUE}"
_STC_COUNT=$(( _STC_COUNT + 1 ))
log_hc "$0" 1 "${_MSG}" "${_TEMP_VALUE}" "${_THRES_VALUE}"
fi
fi
done
print "=== ASM temperature ===" >>${HC_STDOUT_LOG}
cat ${_TMP_FILE} >>${HC_STDOUT_LOG}
else
warn "${_HPASMCLI_BIN}: do_asm_temperature check not enabled"
fi
# report OK situation
if (( _LOG_HEALTHY > 0 && _STC_COUNT == 0 ))
then
_MSG="no problems detected by {${_HPASMCLI_BIN}}"
log_hc "$0" 0 "${_MSG}"
fi
# do cleanup
[[ -f ${_TMP_FILE} ]] && rm -f ${_TMP_FILE} >/dev/null 2>&1
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with paramets:
log_healthy=<yes|no>
hpasmcli_bin=<location_of_hpasmcli_tool>
do_asm_fans=<0|1>
do_asm_dimm=<0|1>
do_asm_powersupply=<0|1>
do_asm_server=<0|1>
do_asm_temperature=<0|1>
PURPOSE : Checks for errors from the HP Proliant 'hpasmcli' tool (see HP Proliant
support pack (PSP))
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+220
View File
@@ -0,0 +1,220 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_linux_hplog.sh
#******************************************************************************
# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_linux_hplog
# DOES: see _show_usage()
# EXPECTS: see _show_usage()
# REQUIRES: data_comma2space(), dump_logs(), init_hc(), log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2017-04-22: initial version [Patrick Van der Veken]
# @(#) 2018-05-21: added dump_logs() & STDERR fixes [Patrick Van der Veken]
# @(#) 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!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_linux_hplog
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _STATE_FILE="${STATE_PERM_DIR}/discovered.hplog"
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _STC_COUNT=0
typeset _CFG_HEALTHY=""
typeset _LOG_HEALTHY=0
typeset _TMP1_FILE="${TMP_DIR}/.$0.tmp1.$$"
typeset _TMP2_FILE="${TMP_DIR}/.$0.tmp2.$$"
typeset _HPLOG_BIN=""
typeset _HPLOG_SEVERITIES=""
typeset _SEVERITIES_LINE=""
typeset _SEVERITY_ENTRY=""
typeset _EVENT_ENTRY=""
# set local trap for cleanup
# shellcheck disable=SC2064
trap "[[ -f ${_TMP1_FILE} ]] && rm -f ${_TMP1_FILE} >/dev/null 2>&1
[[ -f ${_TMP2_FILE} ]] && rm -f ${_TMP2_FILE} >/dev/null 2>&1
return 1" 1 2 3 15
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
esac
done
# handle configuration file
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
if [[ ! -r ${_CONFIG_FILE} ]]
then
warn "unable to read configuration file at ${_CONFIG_FILE}"
return 1
fi
# read required configuration values
_HPLOG_BIN=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'hplog_bin')
if [[ -z "${_HPLOG_BIN}" ]]
then
warn "no value set for 'hplog_bin' in ${_CONFIG_FILE}"
return 1
fi
_SEVERITIES_LINE=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'hplog_severities')
if [[ -z "${_SEVERITIES_LINE}" ]]
then
# set complex search regex (default)
_HPLOG_SEVERITIES="^([0-9]+)\s*(CRITICAL|CAUTION)"
else
# build the complex search regex
_HPLOG_SEVERITIES="^"
print "${_SEVERITIES_LINE}" | tr ',' '\n' 2>/dev/null | while read -r _SEVERITY_ENTRY
do
_HPLOG_SEVERITIES="${_HPLOG_SEVERITIES}(([0-9]+)\s*${_SEVERITY_ENTRY})|"
done
# delete last 'OR'
_HPLOG_SEVERITIES=${_HPLOG_SEVERITIES%?}
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
# 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 hplog utility
if [[ ! -x ${_HPLOG_BIN} || -z "${_HPLOG_BIN}" ]]
then
warn "${_HPLOG_BIN} is not installed here"
return 1
fi
# get hplog output
${_HPLOG_BIN} -v >${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG}
(( $? > 0 )) && {
_MSG="unable to run ${_HPLOG_BIN}"
log_hc "$0" 1 "${_MSG}"
# dump debug info
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
return 1
}
# check state file
[[ -r ${_STATE_FILE} ]] || {
print "## this file sorted! Do not edit manually!" >${_STATE_FILE}
(( $? > 0 )) && {
warn "failed to create new state file"
return 1
}
log "created new state file at ${_STATE_FILE}"
}
# filter current hplog messages (must be uniquely sorted for 'comm')
log "searching HPLOG with filter: ${_HPLOG_SEVERITIES}"
grep -i -E -e "${_HPLOG_SEVERITIES}" ${HC_STDOUT_LOG} >${_TMP1_FILE} 2>/dev/null
# compare results to already discovered messages
comm -13 ${_STATE_FILE} ${_TMP1_FILE} 2>/dev/null >${_TMP2_FILE}
# report results
while read -r _EVENT_ENTRY
do
_MSG="${_EVENT_ENTRY}"
_STC_COUNT=$(( _STC_COUNT + 1 ))
log_hc "$0" 1 "${_MSG}"
done <${_TMP2_FILE}
if (( _STC_COUNT > 0 ))
then
_MSG="found ${_STC_COUNT} new HPLOG messages {${_HPLOG_BIN} -v}"
_STC=1
# add results to state file (must be sorted; re-use TMP_FILE)
sort -u ${_TMP1_FILE} ${_TMP2_FILE} >${_STATE_FILE} 2>/dev/null
(( $? > 0 )) && {
warn "failed to sort temporary state file"
return 1
}
else
_MSG="no new HPLOG messages found"
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
# do cleanup
[[ -f ${_TMP1_FILE} ]] && rm -f ${_TMP1_FILE} >/dev/null 2>&1
[[ -f ${_TMP2_FILE} ]] && rm -f ${_TMP2_FILE} >/dev/null 2>&1
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with parameters:
log_healthy=<yes|no>
hplog_bin=<location_of_hplog_tool>
hplog_severities=<list_of_severities_to_search_for>
PURPOSE : Checks for errors from the HP Proliant 'hpacucli' tool (see HP Proliant
support pack (PSP))
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+317
View File
@@ -0,0 +1,317 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_linux_hpssacli.sh
#******************************************************************************
# @(#) Copyright (C) 2016 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_linux_hpssacli
# DOES: _show_usage()
# EXPECTS: _show_usage()
# REQUIRES: data_comma2space(), data_is_numeric(), init_hc(), log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2016-04-01: initial version [Patrick Van der Veken]
# @(#) 2018-05-21: STDERR fixes [Patrick Van der Veken]
# @(#) 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 code for data_is_numeric() & support for
# @(#) --log-healthy [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_linux_hpssacli
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC_COUNT=0
typeset _CFG_HEALTHY=""
typeset _LOG_HEALTHY=0
typeset _TMP_FILE="${TMP_DIR}/.$0.tmp.$$"
typeset _HPSSACLI_BIN=""
typeset _SSA_LINE=""
typeset _SLOT_NUM=""
typeset _SLOT_NUMS=""
typeset _DO_SSA_CTRL=1
typeset _DO_SSA_ENCL=1
typeset _DO_SSA_PHYS=1
typeset _DO_SSA_LOGL=1
typeset _DO_CHECK=0
# set local trap for cleanup
# shellcheck disable=SC2064
trap "[[ -f ${_TMP_FILE} ]] && rm -f ${_TMP_FILE} >/dev/null 2>&1; return 1" 1 2 3 15
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
esac
done
# handle configuration file
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
if [[ ! -r ${_CONFIG_FILE} ]]
then
warn "unable to read configuration file at ${_CONFIG_FILE}"
return 1
fi
# read required configuration values
_HPSSACLI_BIN=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'hpssacli_bin')
if [[ -z "${_HPSSACLI_BIN}" ]]
then
warn "no value set for 'hpssacli_bin' in ${_CONFIG_FILE}"
return 1
fi
_DO_SSA_CTRL=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'do_ssa_controller')
case "${_DO_SSA_CTRL}" in
0|1)
# on/off, OK
;;
*)
# set default
warn "illegal value for 'do_ssa_controller' in ${_CONFIG_FILE}, using default"
_DO_SSA_CTRL=1
;;
esac
_DO_SSA_ENCL=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'do_ssa_enclosure')
case "${_DO_SSA_ENCL}" in
0|1)
# on/off, OK
;;
*)
# set default
warn "illegal value for 'do_ssa_enclosure' in ${_CONFIG_FILE}, using default"
_DO_SSA_ENCL=1
;;
esac
_DO_SSA_PHYS=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'do_ssa_physical')
case "${_DO_SSA_PHYS}" in
0|1)
# on/off, OK
;;
*)
# set default
warn "illegal value for 'do_ssa_physical' in ${_CONFIG_FILE}, using default"
_DO_SSA_PHYS=1
;;
esac
_DO_SSA_LOGL=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'do_ssa_logical')
case "${_DO_SSA_LOGL}" in
0|1)
# on/off, OK
;;
*)
# set default
warn "illegal value for 'do_ssa_logical' in ${_CONFIG_FILE}, using default"
_DO_SSA_LOGL=1
;;
esac
# check for dependencies: we need to do DO_SSA_CTRL to have the slot info for all
# the other checks
_DO_CHECK=$(( _DO_SSA_ENCL + _DO_SSA_PHYS + _DO_SSA_LOGL ))
if (( _DO_CHECK > 0 && _DO_SSA_CTRL == 0 ))
then
log "switching setting 'do_ssa_controller' to 1 to fetch slot info"
_DO_SSA_CTRL=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
# 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 HP tools
if [[ ! -x ${_HPSSACLI_BIN} || -z "${_HPSSACLI_BIN}" ]]
then
warn "${_HPSSACLI_BIN} is not installed here"
return 1
fi
# --- perform checks ---
# CONTROLLER(s)
if (( _DO_SSA_CTRL > 0 ))
then
${_HPSSACLI_BIN} controller all show status >${_TMP_FILE} 2>${_TMP_FILE}
(( $? > 0 )) && warn "'${_HPSSACLI_BIN} controller all show status' exited non-zero"
# look for failures
grep -i -E -e "(nok|fail.*)" ${_TMP_FILE} 2>/dev/null |\
while read _SSA_LINE
do
_MSG="failure in controller"
_STC_COUNT=$(( _STC_COUNT + 1 ))
log_hc "$0" 1 "${_MSG}"
done
print "=== SSA controller(s) ===" >>${HC_STDOUT_LOG}
cat ${_TMP_FILE} >>${HC_STDOUT_LOG}
# get all slot numbers for multiple raid controllers
cat ${_TMP_FILE} | grep "in Slot [0-9]" 2>/dev/null | while read _SSA_LINE
do
_SLOT_NUM="$(print ${_SSA_LINE} | cut -f6 -d' ' 2>/dev/null)"
data_is_numeric "${_SLOT_NUM}"
if (( $? == 0 ))
then
_SLOT_NUMS="${_SLOT_NUMS} ${_SLOT_NUM}"
else
warn "found RAID controller at illegal slot?: ${_SLOT_NUM}"
fi
done
else
warn "${_HPSSACLI_BIN}: do_ssa_controller check is not enabled"
fi
# ENCLOSURE(s)
if (( _DO_SSA_ENCL > 0 ))
then
for _CTRL_SLOT in ${_SLOT_NUMS}
do
${_HPSSACLI_BIN} controller slot=${_CTRL_SLOT} enclosure all show \
>${_TMP_FILE} 2>${_TMP_FILE}
(( $? > 0 )) && \
warn "'${_HPSSACLI_BIN} controller slot=${_CTRL_SLOT} enclosure all show' exited non-zero"
# look for failures
grep -i -E -e "(nok|fail.*)" ${_TMP_FILE} 2>/dev/null |\
while read _SSA_LINE
do
_MSG="failure in enclosure for controller ${_CTRL_SLOT}"
_STC_COUNT=$(( _STC_COUNT + 1 ))
log_hc "$0" 1 "${_MSG}"
done
print "=== SSA enclosure(s) ===" >>${HC_STDOUT_LOG}
cat ${_TMP_FILE} >>${HC_STDOUT_LOG}
done
else
warn "${_HPSSACLI_BIN}: do_ssa_enclosure check is not enabled"
fi
# PHYSICAL DRIVE(s)
if (( _DO_SSA_PHYS > 0 ))
then
for _CTRL_SLOT in ${_SLOT_NUMS}
do
${_HPSSACLI_BIN} controller slot=${_CTRL_SLOT} physicaldrive all show status \
>${_TMP_FILE} 2>${_TMP_FILE}
(( $? > 0 )) && \
warn "'${_HPSSACLI_BIN} controller slot=${_CTRL_SLOT} physicaldrive all show status' exited non-zero"
# look for failures
grep -i -E -e "(nok|fail.*)" ${_TMP_FILE} 2>/dev/null |\
while read _SSA_LINE
do
_MSG="failure in physical drive(s) for controller ${_CTRL_SLOT}"
_STC_COUNT=$(( _STC_COUNT + 1 ))
log_hc "$0" 1 "${_MSG}"
done
print "=== SSA physical drive(s) ===" >>${HC_STDOUT_LOG}
cat ${_TMP_FILE} >>${HC_STDOUT_LOG}
done
else
warn "${_HPSSACLI_BIN}: do_ssa_physical check is not enabled"
fi
# LOGICAL DRIVE(s)
if (( _DO_SSA_LOGL > 0 ))
then
for _CTRL_SLOT in ${_SLOT_NUMS}
do
${_HPSSACLI_BIN} controller slot=${_CTRL_SLOT} logicaldrive all show status \
>${_TMP_FILE} 2>${_TMP_FILE}
(( $? > 0 )) && \
warn "'${_HPSSACLI_BIN} controller slot=${_CTRL_SLOT}logicaldrive all show status' exited non-zero"
# look for failures
grep -i -E -e "(nok|fail)" ${_TMP_FILE} 2>/dev/null |\
while read _SSA_LINE
do
_MSG="failure in logical drive(s) for controller ${_CTRL_SLOT}"
_STC_COUNT=$(( _STC_COUNT + 1 ))
log_hc "$0" 1 "${_MSG}"
done
print "=== SSA logical drive(s) ===" >>${HC_STDOUT_LOG}
cat ${_TMP_FILE} >>${HC_STDOUT_LOG}
done
else
warn "${_HPSSACLI_BIN}: do_ssa_logical check is not enabled"
fi
# report OK situation
if (( _LOG_HEALTHY > 0 && _STC_COUNT > 0 ))
then
_MSG="no problems detected by {${_HPSSACLI_BIN}}"
log_hc "$0" 0 "${_MSG}"
fi
[[ -f ${_TMP_FILE} ]] && rm -f ${_TMP_FILE} >/dev/null 2>&1
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with parameters:
log_healthy=<yes|no>
hpssacli_bin=<location_of_hpssacli_tool>
do_ssa_controller=<0|1>
do_ssa_enclosure=<0|1>
do_ssa_physical=<0|1>
do_ssa_logical=<0|1>
PURPOSE : Checks for errors from the HP Proliant 'hpssacli' tool (see HP Proliant
support pack (PSP))
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+182
View File
@@ -0,0 +1,182 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_linux_httpd_status.sh
#******************************************************************************
# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_linux_httpd_status
# DOES: see _show_usage()
# EXPECTS: n/a
# REQUIRES: data_comma2space(), linux_get_init(), init_hc(), log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2017-04-23: initial version [Patrick Van der Veken]
# @(#) 2017-05-08: fix fall-back for sysv->pgrep [Patrick Van der Veken]
# @(#) 2017-05-17: removed _MSG dupe [Patrick Van der Veken]
# @(#) 2018-05-21: STDERR fixes [Patrick Van der Veken]
# @(#) 2018-11-18: add linux_has_systemd_service() [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]
# @(#) 2019-03-16: replace 'which' [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_linux_httpd_status
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _HTTPD_INIT_SCRIPT="/etc/init.d/httpd"
typeset _HTTPD_SYSTEMD_SERVICE="httpd.service"
typeset _VERSION="2019-03-16" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _CHECK_SYSTEMD_SERVICE=0
typeset _HTTPD_BIN=""
typeset _MSG=""
typeset _STC=0
typeset _LOG_HEALTHY=0
typeset _RC=0
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
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
# ---- process state ----
# 1) try using the init ways
linux_get_init
case "${LINUX_INIT}" in
'systemd')
_CHECK_SYSTEMD_SERVICE=$(linux_has_systemd_service "${_HTTPD_SYSTEMD_SERVICE}")
if (( _CHECK_SYSTEMD_SERVICE > 0 ))
then
systemctl --quiet is-active ${_HTTPD_SYSTEMD_SERVICE} 2>>${HC_STDERR_LOG} || _STC=1
else
warn "systemd unit file not found {${_HTTPD_SYSTEMD_SERVICE}}"
_RC=1
fi
;;
'upstart')
warn "code for upstart managed systems not implemented, NOOP"
_RC=1
;;
'sysv')
# check running SysV
if [[ -x ${_HTTPD_INIT_SCRIPT} ]]
then
if (( $(${_HTTPD_INIT_SCRIPT} status 2>>${HC_STDERR_LOG} | grep -c -i 'is running' 2>/dev/null) == 0 ))
then
_STC=1
fi
else
warn "sysv init script not found {${_HTTPD_INIT_SCRIPT}}"
_RC=1
fi
;;
*)
_RC=1
;;
esac
# 2) try the pgrep way (note: old pgreps do not support '-c')
if (( _RC > 0 ))
then
(( $(pgrep -u root httpd 2>>${HC_STDERR_LOG} | wc -l 2>/dev/null) == 0 )) && _STC=1
fi
# evaluate results
case ${_STC} in
0)
_MSG="httpd is running"
;;
1)
_MSG="httpd is not running"
;;
*)
_MSG="could not determine status of httpd"
;;
esac
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
# ---- config state ----
_HTTPD_BIN="$(command -v httpd 2>>${HC_STDERR_LOG})"
if [[ -x ${_HTTPD_BIN} && -n "${_HTTPD_BIN}" ]]
then
# validate main configuration
${_HTTPD_BIN} -t >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG}
if (( $? == 0 ))
then
_MSG="httpd configuration files are syntactically correct"
_STC=0
else
_MSG="httpd configuration files have syntax error(s) {httpd -s}"
_STC=1
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
fi
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
PURPOSE : Checks whether httpd (apache service) is running and whether the
httpd configuration files are syntactically correct
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+398
View File
@@ -0,0 +1,398 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_linux_mysqld_status.sh
#******************************************************************************
# @(#) Copyright (C) 2019 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_linux_mysqld_status
# DOES: see _show_usage()
# EXPECTS: see _show_usage()
# REQUIRES: data_comma2space(), data_list_is_string(), dump_logs(),
# init_hc(), log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2019-02-10: initial version [Patrick Van der Veken]
# @(#) 2019-03-09: text files [Patrick Van der Veken]
# @(#) 2019-03-16: replace 'which' [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_linux_mysqld_status
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _MYSQLD_INIT_SCRIPT="/etc/init.d/mysqld"
typeset _MYSQLD_SYSTEMD_SERVICE="mysqld.service"
typeset _MARIADB_INIT_SCRIPT="/etc/init.d/mariadb"
typeset _MARIADB_SYSTEMD_SERVICE="mariadb.service"
typeset _VERSION="2019-03-16" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _CFG_HEALTHY=""
typeset _LOG_HEALTHY=0
typeset _CFG_MYSQL_USER=""
typeset _CFG_MYSQL_PASSWORD=""
typeset _CFG_MYSQL_HOST=""
typeset _CFG_MYSQL_PORT=""
typeset _CFG_EXCLUDE_DATABASES=""
typeset _CFG_EXCLUDE_TABLES=""
typeset _MYSQLADMIN_BIN=""
typeset _DO_MYSQLCHECK=1
typeset _DO_MYSQL_STATS=1
typeset _MYSQLCHECK_BIN=""
typeset _MYSQLCHECK_OPTS=""
typeset _MYSQLSHOW_BIN=""
typeset _MYSQLSHOW_OPTS=""
typeset _MYSQLADMIN_BIN=""
typeset _MYSQLADMIN_OPTS=""
typeset _MYSQL_BIN=""
typeset _MYSQL_DB_LIST=""
typeset _MYSQL_DB=""
typeset _MYSQLCHECK_OUTPUT=""
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
esac
done
# handle configuration file
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
if [[ ! -r ${_CONFIG_FILE} ]]
then
warn "unable to read configuration file at ${_CONFIG_FILE}"
return 1
fi
# read configuration values
_CFG_DO_CHECK=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'do_check')
case "${_CFG_DO_CHECK}" in
yes|YES|Yes)
_DO_MYSQLCHECK=1
;;
*)
_DO_MYSQLCHECK=0
;;
esac
_CFG_MYSQL_USER=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'mysql_user')
if [[ -z "${_CFG_MYSQL_USER}" ]]
then
warn "no value for 'mysql_user' specified in ${_CONFIG_FILE}"
_DO_MYSQLCHECK=0
else
_MYSQLCHECK_OPTS="${_MYSQLCHECK_OPTS} --user=${_CFG_MYSQL_USER}"
_MYSQLSHOW_OPTS="${_MYSQLSHOW_OPTS} --user=${_CFG_MYSQL_USER}"
_MYSQLADMIN_OPTS="${_MYSQLADMIN_OPTS} --user=${_CFG_MYSQL_USER}"
fi
_CFG_MYSQL_PASSWORD=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'mysql_password')
if [[ -z "${_CFG_MYSQL_PASSWORD}" ]]
then
warn "no value for 'mysql_password' specified in ${_CONFIG_FILE}"
_DO_MYSQLCHECK=0
else
_MYSQLCHECK_OPTS="${_MYSQLCHECK_OPTS} --password=${_CFG_MYSQL_PASSWORD}"
_MYSQLSHOW_OPTS="${_MYSQLSHOW_OPTS} --password=${_CFG_MYSQL_PASSWORD}"
_MYSQLADMIN_OPTS="${_MYSQLADMIN_OPTS} --password=${_CFG_MYSQL_PASSWORD}"
fi
_CFG_MYSQL_HOST=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'mysql_host')
if [[ -z "${_CFG_MYSQL_HOST}" ]]
then
warn "no value for 'mysql_host' specified in ${_CONFIG_FILE}, using localhost"
else
_MYSQLCHECK_OPTS="${_MYSQLCHECK_OPTS} --host=${_CFG_MYSQL_HOST}"
_MYSQLSHOW_OPTS="${_MYSQLSHOW_OPTS} --host=${_CFG_MYSQL_HOST}"
_MYSQLADMIN_OPTS="${_MYSQLADMIN_OPTS} --host=${_CFG_MYSQL_HOST}"
fi
_CFG_MYSQL_PORT=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'mysql_port')
if [[ -z "${_CFG_MYSQL_PORT}" ]]
then
warn "no value for 'mysql_port' specified in ${_CONFIG_FILE}, using 3306"
else
_MYSQLCHECK_OPTS="${_MYSQLCHECK_OPTS} --port=${_CFG_MYSQL_PORT}"
_MYSQLSHOW_OPTS="${_MYSQLSHOW_OPTS} --port=${_CFG_MYSQL_PORT}"
_MYSQLADMIN_OPTS="${_MYSQLADMIN_OPTS} --port=${_CFG_MYSQL_PORT}"
fi
_CFG_CHECK_TYPE=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'check_type')
case "${_CFG_CHECK_TYPE}" in
quick|QUICK|Quick)
_MYSQLCHECK_OPTS="${_MYSQLCHECK_OPTS} --quick"
;;
medium|MEDIUM|Medium)
_MYSQLCHECK_OPTS="${_MYSQLCHECK_OPTS} --medium-check"
;;
extended|EXTENDED|Extended)
_MYSQLCHECK_OPTS="${_MYSQLCHECK_OPTS} --extended"
;;
*)
_MYSQLCHECK_OPTS="${_MYSQLCHECK_OPTS} --quick"
;;
esac
_CFG_CHECK_DATABASES=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'check_databases')
_CFG_EXCLUDE_DATABASES=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'exclude_databases')
_CFG_EXCLUDE_TABLES=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'exclude_tables')
_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
(( _DO_MYSQLCHECK == 0 )) && warn "mysqlcheck is disabled (as configured or due to missing mysql settings)"
# 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 mysql
_MYSQL_BIN="$(command -v mysql 2>>${HC_STDERR_LOG})"
if [[ ! -x ${_MYSQL_BIN} || -z "${_MYSQL_BIN}" ]]
then
warn "MySQL/mariaDB is not installed here"
return 1
fi
# ---- process state ----
# 1) try using the init ways
linux_get_init
case "${LINUX_INIT}" in
'systemd')
# first try mysqld
_CHECK_SYSTEMD_SERVICE=$(linux_has_systemd_service "${_MYSQLD_SYSTEMD_SERVICE}")
if (( _CHECK_SYSTEMD_SERVICE > 0 ))
then
systemctl --quiet is-active ${_MYSQLD_SYSTEMD_SERVICE} 2>>${HC_STDERR_LOG} || _STC=1
else
# then try mariadb
_CHECK_SYSTEMD_SERVICE=$(linux_has_systemd_service "${_MARIADB_SYSTEMD_SERVICE}")
if (( _CHECK_SYSTEMD_SERVICE > 0 ))
then
systemctl --quiet is-active ${_MARIADB_SYSTEMD_SERVICE} 2>>${HC_STDERR_LOG} || _STC=1
else
warn "systemd unit file not found {${_MYSQLD_SYSTEMD_SERVICE}}/${_MARIADB_SYSTEMD_SERVICE}}"
_RC=1
fi
fi
;;
'upstart')
warn "code for upstart managed systems not implemented, NOOP"
return 1
;;
'sysv')
# first check running mysqld
if [[ -x ${_MYSQLD_INIT_SCRIPT} ]]
then
if (( $(${_MYSQLD_INIT_SCRIPT} status 2>>${HC_STDERR_LOG} | grep -c -i 'is running' 2>/dev/null) == 0 ))
then
_STC=1
fi
else
if [[ -x ${_MARIADB_INIT_SCRIPT} ]]
then
if (( $(${_MARIADB_INIT_SCRIPT} status 2>>${HC_STDERR_LOG} | grep -c -i 'is running' 2>/dev/null) == 0 ))
then
_STC=1
fi
else
warn "sysv init script not found {${_MYSQLD_INIT_SCRIPT}}/{${_MARIADB_INIT_SCRIPT}}"
_RC=1
fi
fi
;;
*)
_RC=1
;;
esac
# 2) try the pgrep way (note: old pgreps do not support '-c')
if (( _RC > 0 ))
then
(( $(pgrep -u root mysqld 2>>${HC_STDERR_LOG} | wc -l 2>/dev/null) == 0 )) && _STC=1
fi
# evaluate results
case ${_STC} in
0)
_MSG="mysqld/mariadb is running"
;;
1)
_MSG="mysqld/mariadb is not running"
;;
*)
_MSG="could not determine status of mysqld/mariadb"
;;
esac
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
# ---- table states (ISAM)----
# check mysqlcheck
_MYSQLCHECK_BIN="$(command -v mysqlcheck 2>>${HC_STDERR_LOG})"
if [[ ! -x ${_MYSQLCHECK_BIN} || -z "${_MYSQLCHECK_BIN}" ]]
then
warn "could not find {mysqlcheck}, skipping table checks"
_DO_MYSQLCHECK=0
fi
if (( _DO_MYSQLCHECK > 0 ))
then
# all databases or given ones? we run mysqlcheck on each database separately
# to make parsing of the results easier.
if [[ -z "${_CFG_CHECK_DATABASES}" ]]
then
# check mysqlshow
_MYSQLSHOW_BIN="$(command -v mysqlshow 2>>${HC_STDERR_LOG})"
if [[ ! -x ${_MYSQLSHOW_BIN} || -z "${_MYSQLSHOW_BIN}" ]]
then
warn "could not find {mysqlshow}, skipping table checks"
return 1
fi
# get all databases from mysqlshow
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && debug "mysqlshow command: ${_MYSQLSHOW_BIN} ${_MYSQLSHOW_OPTS}"
_DB_LIST=$(${_MYSQLSHOW_BIN} ${_MYSQLSHOW_OPTS} 2>>${HC_STDERR_LOG} |\
grep -v -E -e '+--' -e 'Databases' 2>/dev/null | awk '{ print $2}' 2>/dev/null)
else
_DB_LIST=$(data_comma2newline "${_CFG_CHECK_DATABASES}")
fi
# exclude databases
print "${_DB_LIST}" | while read -r _MYSQL_DB
do
data_list_is_string "${_CFG_EXCLUDE_DATABASES}" "${_MYSQL_DB}"
(( $? == 0 )) && _MYSQL_DB_LIST="${_MYSQL_DB_LIST} ${_MYSQL_DB}"
done
if [[ -z "${_MYSQL_DB_LIST}" ]]
then
warn "could not execute/parse {mysqlshow} or list of databases to check is empty, skipping table checks"
return 1
fi
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && debug "database list for mysqlcheck: ${_MYSQL_DB_LIST}"
# run check
for _MYSQL_DB in ${_MYSQL_DB_LIST}
do
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && debug "mysqlcheck command: ${_MYSQLCHECK_BIN} ${_MYSQLCHECK_OPTS} --database ${_MYSQL_DB}"
_MYSQLCHECK_OUTPUT=$(${_MYSQLCHECK_BIN} ${_MYSQLCHECK_OPTS} --database ${_MYSQL_DB} 2>>${HC_STDERR_LOG})
if (( $? > 0 )) || [[ -z "${_MYSQLCHECK_OUTPUT}" ]]
then
_MSG="unable to run command for {${_MYSQLCHECK_BIN} <hidden_opts> --database ${_MYSQL_DB}}"
log_hc "$0" 1 "${_MSG}"
# dump debug info
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
continue
fi
# verify table states
print "${_MYSQLCHECK_OUTPUT}" | grep -E -e "^${_MYSQL_DB}\." 2>/dev/null | while read -r _CHECK_LINE
do
_MYSQL_TABLE=$(print "${_CHECK_LINE}" | awk '{print $1}' 2>/dev/null)
data_list_is_string "${_CFG_EXCLUDE_TABLES}" "${_MYSQL_TABLE}"
if (( $? == 0 ))
then
if (( $(print "${_CHECK_LINE}" | grep -c -E -e "^${_MYSQL_TABLE}.*OK$" 2>/dev/null) > 0 ))
then
_MSG="state of table ${_MYSQL_TABLE} is OK"
_STC=0
else
_MSG="state of table ${_MYSQL_TABLE} is NOK"
_STC=1
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
else
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && debug "excluding table: ${_MYSQL_TABLE}"
fi
done
# add mysqlcheck output to stdout log_hc
print "==== {${_MYSQLCHECK_BIN} <hidden_opts> --database ${_MYSQL_DB}} ====" >>${HC_STDOUT_LOG}
print "${_MYSQLCHECK_OUTPUT}" >>${HC_STDOUT_LOG}
done
fi
# ---- statistics ----
# check mysqladmin
_MYSQLADMIN_BIN="$(command -v mysqladmin 2>>${HC_STDERR_LOG})"
if [[ ! -x ${_MYSQLADMIN_BIN} || -z "${_MYSQLADMIN_BIN}" ]]
then
warn "could not find {mysqladmin}, skipping statistics gathering"
_DO_MYSQL_STATS=0
fi
if (( _DO_MYSQL_STATS > 0 ))
then
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && debug "mysql command: ${_MYSQLADMIN_BIN} ${_MYSQLADMIN_OPTS}"
print "==== {${_MYSQLADMIN_BIN} <hidden_opts> extended-status} ====" >>${HC_STDOUT_LOG}
${_MYSQLADMIN_BIN} ${_MYSQLADMIN_OPTS} extended-status >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG}
fi
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with parameters:
log_healthy=<yes|no>
mysql_user=<mysql_user_account>
mysql_password=<mysql_user_password>
mysql_host=<database_host>
mysql_port=<host_port>
do_check=<yes|no>
check_type=<quick|fast|medium|extended>
check_databases=<list_of_databases>
exclude_databases=<list_of_databases>
exclude_tables=<list_of_tables>
do_stats=<yes|no>
PURPOSE : Checks the status of mysqld/mariadb & databases/table states. Can also
gather statistics on mysqld (extended-status) but these are only logged
when a health check fails.
MySQL privileges required: SHOW DATABASES, SELECT (global or per database)
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+194
View File
@@ -0,0 +1,194 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_linux_named_status.sh
#******************************************************************************
# @(#) Copyright (C) 2016 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_linux_named_status
# DOES: see _show_usage()
# EXPECTS: n/a
# REQUIRES: data_comma2space(), linux_get_init(), init_hc(), log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2013-12-01: initial version [Patrick Van der Veken]
# @(#) 2017-05-08: fix fall-back for sysv->pgrep [Patrick Van der Veken]
# @(#) 2018-05-21: STDERR fixes [Patrick Van der Veken]
# @(#) 2018-11-18: add linux_has_systemd_service() [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]
# @(#) 2019-03-16: replace 'which' [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_linux_named_status
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _VERSION="2019-03-16" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _LOG_HEALTHY=0
typeset _CHECK_SYSTEMD_SERVICE=0
typeset _NAMED_CHECKCONF_BIN=""
typeset _NAMED_INIT_SCRIPT=""
typeset _NAMED_SYSTEMD_SERVICE=""
typeset _RC=0
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
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
# set init script & systemd service
case "${LINUX_DISTRO}" in
Debian)
_NAMED_INIT_SCRIPT="/etc/init.d/bind9"
_NAMED_SYSTEMD_SERVICE="bind9.service"
;;
*)
_NAMED_INIT_SCRIPT="/etc/init.d/named"
_NAMED_SYSTEMD_SERVICE="named.service"
;;
esac
# ---- process state ----
# 1) try using the init ways
linux_get_init
case "${LINUX_INIT}" in
'systemd')
_CHECK_SYSTEMD_SERVICE=$(linux_has_systemd_service "${_NAMED_SYSTEMD_SERVICE}")
if (( _CHECK_SYSTEMD_SERVICE > 0 ))
then
systemctl --quiet is-active ${_NAMED_SYSTEMD_SERVICE} 2>>${HC_STDERR_LOG} || _STC=1
else
warn "systemd unit file not found {${_NAMED_SYSTEMD_SERVICE}}"
_RC=1
fi
;;
'upstart')
warn "code for upstart managed systems not implemented, NOOP"
return 1
;;
'sysv')
# check running named
if [[ -x ${_NAMED_INIT_SCRIPT} ]]
then
if (( $(${_NAMED_INIT_SCRIPT} status 2>>${HC_STDERR_LOG} | grep -c -i 'is running' 2>/dev/null) == 0 ))
then
_STC=1
fi
else
warn "sysv init script not found {${_NAMED_INIT_SCRIPT}}"
_RC=1
fi
;;
*)
_RC=1
;;
esac
# 2) try the pgrep way (note: old pgreps do not support '-c')
if (( _RC > 0 ))
then
(( $(pgrep -u root named 2>>${HC_STDERR_LOG} | wc -l 2>/dev/null) == 0 )) && _STC=1
fi
# evaluate results
case ${_STC} in
0)
_MSG="named is running"
;;
1)
_MSG="named is not running"
;;
*)
_MSG="could not determine status of named"
;;
esac
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
# ---- config state ----
_NAMED_CHECKCONF_BIN="$(command -v named-checkconf 2>>${HC_STDERR_LOG})"
if [[ -x ${_NAMED_CHECKCONF_BIN} && -n "${_NAMED_CHECKCONF_BIN}" ]]
then
# validate main configuration and test load zones
${_NAMED_CHECKCONF_BIN} -z >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG}
if (( $? == 0 ))
then
_MSG="named & zones configuration files are syntactically correct"
_STC=0
else
_MSG="named configuration and/or zone files have syntax error(s) {named-checkconf -z}"
_STC=1
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
fi
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
PURPOSE : Checks whether named (BIND) is running and whether the named zone
files are syntactically correct.
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+485
View File
@@ -0,0 +1,485 @@
#!/usr/bin/env ksh
#------------------------------------------------------------------------------
# @(#) check_linux_ntp_status
#------------------------------------------------------------------------------
# @(#) Copyright (C) 2016 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#------------------------------------------------------------------------------
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_linux_ntp_status
# DOES: see _show_usage()
# EXPECTS: see _show_usage()
# REQUIRES: data_comma2space(), init_hc(), log_hc(),
# linux_has_systemd_service(), warn()
#
# @(#) HISTORY:
# @(#) 2018-03-20: initial version [Patrick Van der Veken]
# @(#) 2018-05-21: STDERR + other small fixes [Patrick Van der Veken]
# @(#) 2018-10-28: fixed (linter) errors [Patrick Van der Veken]
# @(#) 2018-10-31: added support for chronyd, --dump-logs
# @(#) & --log-healthy [Patrick Van der Veken]
# @(#) 2018-11-18: add linux_has_systemd_service() [Patrick Van der Veken]
# @(#) 2019-01-10: add optional configuration+cmd-line parameters 'force_ntp' and
# @(#) 'force_chrony', added check on chronyd service alive, added
# @(#) run user for chronyd+ntpd, added forced IPv4 support for ntpq,
# @(#) fixed problem with offset calculation [Patrick Van der Veken]
# @(#) 2019-01-24: arguments fix [Patrick Van der Veken]
# @(#) 2019-03-24: set dynamic path to client tools [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#------------------------------------------------------------------------------
# -----------------------------------------------------------------------------
function check_linux_ntp_status
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _CHRONY_INIT_SCRIPT="/etc/init.d/chrony"
typeset _NTPD_INIT_SCRIPT="/etc/init.d/ntpd"
typeset _CHRONYD_SYSTEMD_SERVICE="chronyd.service"
typeset _NTPD_SYSTEMD_SERVICE="ntpd.service"
typeset _CHRONYD_USER="chrony"
typeset _NTPD_USER="ntp"
typeset _VERSION="2019-03-24" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
typeset _NTPQ_OPTS="-pn"
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _CFG_FORCE_CHRONY=""
typeset _CFG_FORCE_NTP=""
typeset _CFG_NTPQ_IPV4=""
typeset _CFG_HEALTHY=""
typeset _LOG_HEALTHY=0
typeset _CHECK_SYSTEMD_SERVICE=0
typeset _CURR_OFFSET=0
typeset _MAX_OFFSET=0
typeset _NTP_PEER=""
typeset _CHECK_OFFSET=0
typeset _USE_CHRONYD=0
typeset _USE_NTPD=0
typeset _CHRONYC_BIN=""
typeset _NTPQ_BIN=""
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
force_chrony)
log "forcing chrony since force_chrony was used"
_USE_CHRONYD=1
;;
force_ntp)
log "forcing ntp since force_ntp was used"
_USE_NTPD=1
;;
esac
done
# handle config file
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
if [[ ! -r ${_CONFIG_FILE} ]]
then
warn "unable to read configuration file at ${_CONFIG_FILE}"
return 1
fi
# read required config values
_MAX_OFFSET=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'max_offset')
if [[ -z "${_MAX_OFFSET}" ]]
then
# default
_MAX_OFFSET=500
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
_CFG_FORCE_CHRONY=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'force_chrony')
case "${_CFG_FORCE_CHRONY}" in
yes|YES|Yes)
log "forcing chrony since force_chrony was set"
_USE_CHRONYD=1
;;
*)
: # not set
;;
esac
# force_ntp (optional)
_CFG_FORCE_NTP=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'force_ntp')
case "${_CFG_FORCE_NTP}" in
yes|YES|Yes)
log "forcing ntp since force_ntp was set"
_USE_NTPD=1
;;
*)
: # not set
;;
esac
_CFG_NTPQ_IPV4=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'ntpq_use_ipv4')
case "${_CFG_NTPQ_IPV4}" in
yes|YES|Yes)
log "forcing ntpq to use IPv4"
_NTPQ_OPTS="${_NTPQ_OPTS}4"
;;
*)
: # not set
;;
esac
if (( _USE_CHRONYD > 0 && _USE_NTPD > 0 ))
then
warn "you cannot force chrony and ntp at the same time"
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
#------------------------------------------------------------------------------
# check for client tools
_CHRONYC_BIN="$(command -v chronyc 2>>${HC_STDERR_LOG})"
_NTPQ_BIN="$(command -v ntpq 2>>${HC_STDERR_LOG})"
#------------------------------------------------------------------------------
# chronyd (prefer) or ntpd (fallback)
# but do not check if _USE_CHRONYD or _USE_NTPD is already set
if (( _USE_CHRONYD == 0 && _USE_NTPD == 0 ))
then
linux_get_init
_CHRONYC_BIN="$(command -v chronyc 2>>${HC_STDERR_LOG})"
if [[ -n "${_CHRONYC_BIN}" && -x ${_CHRONYC_BIN} ]]
then
# check that chrony is actually enabled
(( ARG_DEBUG > 0 )) && debug "found ${_CHRONYC_BIN}, checking if the service is enabled"
case "${LINUX_INIT}" in
'systemd')
_CHECK_SYSTEMD_SERVICE=$(linux_has_systemd_service "${_CHRONYD_SYSTEMD_SERVICE}")
if (( _CHECK_SYSTEMD_SERVICE > 0 ))
then
systemctl --quiet is-enabled ${_CHRONYD_SYSTEMD_SERVICE} 2>>${HC_STDERR_LOG} && _USE_CHRONYD=1
else
warn "systemd unit file not found {${_CHRONYD_SYSTEMD_SERVICE}}"
_USE_CHRONYD=0
fi
;;
'sysv')
chkconfig chronyd >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG}
if (( $? == 0 ))
then
_USE_CHRONYD=1
else
_USE_CHRONYD=0
fi
;;
*)
_USE_CHRONYD=0
;;
esac
(( ARG_DEBUG > 0 )) && debug "chronyd service state: ${_USE_CHRONYD}"
fi
_NTPQ_BIN="$(command -v ntpq 2>>${HC_STDERR_LOG})"
if (( _USE_CHRONYD == 0 )) && [[ -n "${_NTPQ_BIN}" && -x ${_NTPQ_BIN} ]]
then
# shellcheck disable=SC2034
_USE_NTPD=1
(( ARG_DEBUG > 0 )) && debug "ntpd service state: ${_USE_NTPD}"
fi
if (( _USE_CHRONYD == 0 && _USE_NTPD == 0 ))
then
_MSG="unable to find chronyd or ntpd (or they are not enabled)"
log_hc "$0" 1 "${_MSG}"
# dump debug info
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
return 1
fi
fi
#------------------------------------------------------------------------------
# check ntp service
# 1) try using the init ways
linux_get_init
case "${LINUX_INIT}" in
'systemd')
if (( _USE_CHRONYD > 0 ))
then
_CHECK_SYSTEMD_SERVICE=$(linux_has_systemd_service "${_CHRONYD_SYSTEMD_SERVICE}")
if (( _CHECK_SYSTEMD_SERVICE > 0 ))
then
systemctl --quiet is-active ${_CHRONYD_SYSTEMD_SERVICE} 2>>${HC_STDERR_LOG} || _STC=1
else
warn "systemd unit file not found {${_CHRONYD_SYSTEMD_SERVICE}}"
_RC=1
fi
else
_CHECK_SYSTEMD_SERVICE=$(linux_has_systemd_service "${_NTPD_SYSTEMD_SERVICE}")
if (( _CHECK_SYSTEMD_SERVICE > 0 ))
then
systemctl --quiet is-active ${_NTPD_SYSTEMD_SERVICE} 2>>${HC_STDERR_LOG} || _STC=1
else
warn "systemd unit file not found {${_NTPD_SYSTEMD_SERVICE}}"
_RC=1
fi
fi
;;
'upstart')
warn "code for upstart managed systems not implemented, NOOP"
_RC=1
;;
'sysv')
# check running SysV
if (( _USE_CHRONYD > 0 ))
then
if [[ -x ${_CHRONY_INIT_SCRIPT} ]]
then
if (( $(${_CHRONY_INIT_SCRIPT} status 2>>${HC_STDERR_LOG} | grep -c -i 'is running' 2>/dev/null) == 0 ))
then
_STC=1
fi
else
warn "sysv init script not found {${_NTPD_INIT_SCRIPT}}"
_RC=1
fi
else
if [[ -x ${_NTPD_INIT_SCRIPT} ]]
then
if (( $(${_NTPD_INIT_SCRIPT} status 2>>${HC_STDERR_LOG} | grep -c -i 'is running' 2>/dev/null) == 0 ))
then
_STC=1
fi
else
warn "sysv init script not found {${_NTPD_INIT_SCRIPT}}"
_RC=1
fi
fi
;;
*)
_RC=1
;;
esac
# 2) try the pgrep way (note: old pgreps do not support '-c')
if (( _RC > 0 ))
then
if (( _USE_CHRONYD > 0 ))
then
(( $(pgrep -u "${_CHRONYD_USER}" 'chronyd' 2>>${HC_STDERR_LOG} | wc -l 2>/dev/null) == 0 )) && _STC=1
else
(( $(pgrep -u "${_NTPD_USER}" 'ntpd' 2>>${HC_STDERR_LOG} | wc -l 2>/dev/null) == 0 )) && _STC=1
fi
fi
# evaluate results
case ${_STC} in
0)
if (( _USE_CHRONYD > 0 ))
then
_MSG="chronyd is running"
else
_MSG="ntpd is running"
fi
;;
1)
if (( _USE_CHRONYD > 0 ))
then
_MSG="chronyd is not running"
else
_MSG="ntpd is not running"
fi
;;
*)
if (( _USE_CHRONYD > 0 ))
then
_MSG="could not determine status of chronyd"
else
_MSG="could not determine status of ntpd"
fi
;;
esac
log_hc "$0" ${_STC} "${_MSG}"
#------------------------------------------------------------------------------
# check chronyc/ntpq results
_STC=0
if (( _USE_CHRONYD > 0 ))
then
${_CHRONYC_BIN} -nc sources 2>>${HC_STDERR_LOG} >>${HC_STDOUT_LOG}
if (( $? > 0 ))
then
_MSG="unable to execute {${_CHRONYC_BIN}}"
log_hc "$0" 1 "${_MSG}"
# dump debug info
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
return 1
fi
# 1) active server
_CHRONY_PEER="$(grep -E -e '^\^,\*' 2>/dev/null ${HC_STDOUT_LOG} | cut -f3 -d',' 2>/dev/null)"
if [[ -z "${_CHRONY_PEER}" ]]
then
_MSG="chrony is not synchronizing"
log_hc "$0" 1 "${_MSG}"
return 0
fi
case ${_CHRONY_PEER} in
\*127.127.1.0*)
_MSG="chrony is synchronizing against its internal clock"
_STC=1
;;
*)
# some valid server
_MSG="chrony is synchronizing against ${_CHRONY_PEER}"
;;
esac
log_hc "$0" ${_STC} "${_MSG}"
# 2) offset value
if (( _STC == 0 ))
then
_CURR_OFFSET="$(grep -E -e '^\^,\*' 2>/dev/null ${HC_STDOUT_LOG} | cut -f9 -d',' 2>/dev/null)"
# convert from us to ms
case ${_CURR_OFFSET} in
+([-0-9])*(.)*([0-9]))
# numeric, OK (negatives are OK too!)
# convert from us to ms
_CURR_OFFSET=$(print -R "${_CURR_OFFSET} * 1000" | bc 2>/dev/null)
if (( $? > 0 )) || [[ -z "${_CURR_OFFSET}" ]]
then
:
fi
# force awk into casting c as a float
_CHECK_OFFSET=$(awk -v c="${_CURR_OFFSET}" -v m="${_MAX_OFFSET}" 'BEGIN { sub (/^-/, "", c); print ((c+0.0)>m) }' 2>/dev/null)
if (( _CHECK_OFFSET > 0 ))
then
_MSG="NTP offset of ${_CURR_OFFSET} is bigger than the configured maximum of ${_MAX_OFFSET}"
_STC=1
else
_MSG="NTP offset of ${_CURR_OFFSET} is within the acceptable range"
fi
log_hc "$0" ${_STC} "${_MSG}"
;;
*)
# not numeric
warn "invalid offset value of ${_CURR_OFFSET} found for ${_NTP_PEER}?"
return 1
;;
esac
fi
else
${_NTPQ_BIN} ${_NTPQ_OPTS} 2>>${HC_STDERR_LOG} >>${HC_STDOUT_LOG}
# RC is always 0
# 1) active server
_NTP_PEER="$(grep -E -e '^\*' 2>/dev/null ${HC_STDOUT_LOG} | awk '{ print $1 }' 2>/dev/null)"
if [[ -z "${_NTP_PEER}" ]]
then
_MSG="NTP is not synchronizing"
log_hc "$0" 1 "${_MSG}"
return 0
fi
case ${_NTP_PEER} in
\*127.127.1.0*)
_MSG="NTP is synchronizing against its internal clock"
_STC=1
;;
*)
# some valid server
_MSG="NTP is synchronizing against ${_NTP_PEER##*\*}"
;;
esac
log_hc "$0" ${_STC} "${_MSG}"
# 2) offset value
if (( _STC == 0 ))
then
_CURR_OFFSET="$(grep -E -e '^\*' 2>/dev/null ${HC_STDOUT_LOG} | awk '{ print $9 }' 2>/dev/null)"
case ${_CURR_OFFSET} in
+([-0-9])*(.)*([0-9]))
# numeric, OK (negatives are OK, force awk into casting c as a float)
_CHECK_OFFSET=$(awk -v c="${_CURR_OFFSET}" -v m="${_MAX_OFFSET}" 'BEGIN { sub (/^-/, "", c); print ((c+0.0)>m) }' 2>/dev/null)
if (( _CHECK_OFFSET > 0 ))
then
_MSG="NTP offset of ${_CURR_OFFSET} is bigger than the configured maximum of ${_MAX_OFFSET}"
_STC=1
else
_MSG="NTP offset of ${_CURR_OFFSET} is within the acceptable range"
fi
log_hc "$0" ${_STC} "${_MSG}"
;;
*)
# not numeric
warn "invalid offset value of ${_CURR_OFFSET} found for ${_NTP_PEER}?"
return 1
;;
esac
fi
fi
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with:
log_healthy=<yes|no>
max_offset=<max_offset (ms)>
force_chrony=<yes|no>
force_ntp=<yes|no>
ntpq_use_ipv4=<yes|no>
EXTRA OPTS : --hc-args=force_chrony, --hc-args=force_ntp
PURPOSE : Checks the status of NTP service & synchronization.
Supports chronyd & ntpd.
Assumes chronyd is the preferred time synchronization.
LOG HEALTHY : Supported
EOT
return 0
}
#------------------------------------------------------------------------------
# END of script
#------------------------------------------------------------------------------
+182
View File
@@ -0,0 +1,182 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_linux_postfix_status.sh
#******************************************************************************
# @(#) Copyright (C) 2016 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_linux_postfix_status
# DOES: see _show_usage()
# EXPECTS: n/a
# REQUIRES: data_comma2space(), linux_get_init(), init_hc(), log_hc(), warn')
#
# @(#) HISTORY:
# @(#) 2016-12-01: initial version [Patrick Van der Veken]
# @(#) 2017-05-08: suppress errors on postfix call + fix fall-back
# @(#) for sysv->pgrep[Patrick Van der Veken]
# @(#) 2018-05-21: STDERR fixes [Patrick Van der Veken]
# @(#) 2018-11-18: add linux_has_systemd_service() [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]
# @(#) 2019-03-16: replace 'which' [Patrick Van der Veken]
# @(#) 2019-03-25: fix for older Debian & Ubuntu [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_linux_postfix_status
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _POSTFIX_INIT_SCRIPT="/etc/init.d/postfix"
typeset _POSTFIX_SYSTEMD_SERVICE="postfix.service"
typeset _VERSION="2019-03-25" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _POSTFIX_BIN=""
typeset _MSG=""
typeset _STC=0
typeset _LOG_HEALTHY=0
typeset _RC=0
typeset _CHECK_SYSTEMD_SERVICE=0
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
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
# 1) try using the init ways
linux_get_init
case "${LINUX_INIT}" in
'systemd')
# Debian8/Ubuntu16 do not correctly report a unit file for postfix,
# do not check for it and instead just query systemd service
linux_get_distro
if [[ "${LINUX_DISTRO}" = "Debian" ]] && (( ${LINUX_RELEASE%%.*} < 9 ))
then
_CHECK_SYSTEMD_SERVICE=1
elif [[ "${LINUX_DISTRO}" = "Ubuntu" ]] && (( ${LINUX_RELEASE%%.*} < 17 ))
then
_CHECK_SYSTEMD_SERVICE=1
else
_CHECK_SYSTEMD_SERVICE=$(linux_has_systemd_service "${_POSTFIX_SYSTEMD_SERVICE}")
fi
if (( _CHECK_SYSTEMD_SERVICE > 0 ))
then
systemctl --quiet is-active ${_POSTFIX_SYSTEMD_SERVICE} 2>>${HC_STDERR_LOG} || _STC=1
else
warn "systemd unit file not found {${_POSTFIX_SYSTEMD_SERVICE}}"
_RC=1
fi
;;
'upstart')
warn "code for upstart managed systems not implemented, NOOP"
_RC=1
;;
'sysv')
# check running SysV
if [[ -x ${_POSTFIX_INIT_SCRIPT} ]]
then
if (( $(${_POSTFIX_INIT_SCRIPT} status 2>>${HC_STDERR_LOG} | grep -c -i 'is running' 2>/dev/null) == 0 ))
then
_STC=1
fi
else
warn "sysv init script not found {${_POSTFIX_INIT_SCRIPT}}"
_RC=1
fi
;;
*)
_RC=1
;;
esac
# 2) try the postfix way
if (( _RC > 0 ))
then
_POSTFIX_BIN="$(command -v postfix 2>>${HC_STDERR_LOG})"
if [[ -x ${_POSTFIX_BIN} && -n "${_POSTFIX_BIN}" ]]
then
if (( $(${_POSTFIX_BIN} status 2>>${HC_STDERR_LOG} | grep -c -i 'is running' 2>/dev/null) == 0 ))
then
_STC=1
fi
else
warn "postfix is not installed here"
return 1
fi
fi
# evaluate results
case ${_STC} in
0)
_MSG="postfix is running"
;;
1)
_MSG="postfix is not running"
;;
*)
_MSG="could not determine status of postfix"
;;
esac
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
PURPOSE : Checks whether postfix (mail system) is running
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+429
View File
@@ -0,0 +1,429 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_linux_process_limits.sh
#******************************************************************************
# @(#) Copyright (C) 2018 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_linux_process_limits
# DOES: see _show_usage()
# EXPECTS: see _show_usage()
# REQUIRES: data_comma2space(), data_is_numeric(), init_hc(), log_hc(), warn())
#
# @(#) HISTORY:
# @(#) 2018-07-10: original version [Patrick Van der Veken]
# @(#) 2018-07-12: better log_healthy handling [Patrick Van der Veken]
# @(#) 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-27: arguments fix [Patrick Van der Veken]
# @(#) 2019-03-13: fixes & optimizations (pdksh) [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_linux_process_limits
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _VERSION="2019-03-13" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _LINE_COUNT=1
typeset _CFG_HEALTHY=""
typeset _LOG_HEALTHY=0
typeset _MAX_OPEN_FILES=0
typeset _MAX_PROCESSES=0
typeset _PROCESS=""
typeset _PROCESS_LIMIT=""
typeset _PROCESS_SOFT_THRESHOLD=0
typeset _PROCESS_HARD_THRESHOLD=0
typeset _PROCESS_PS=""
typeset _PROCESS_PS_PID=""
typeset _PROCESS_PS_USER=""
typeset _USER=""
typeset _USER_LIMIT=""
typeset _USER_SOFT_THRESHOLD=0
typeset _USER_HARD_THRESHOLD=0
typeset _USER_PS=""
typeset _USER_PS_PID=""
typeset _USER_PS_COMM=""
# set local trap for cleanup
# shellcheck disable=SC2064
trap "rm -f ${_INSTANCE_RUN_FILE}.* >/dev/null 2>&1; return 1" 1 2 3 15
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
esac
done
# handle configuration file
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
if [[ ! -r ${_CONFIG_FILE} ]]
then
warn "unable to read configuration file at ${_CONFIG_FILE}"
return 1
fi
# read required configuration values
_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 PROCESS stanzas
grep -i '^process' ${_CONFIG_FILE} 2>/dev/null |\
while IFS=';' read -r _ _PROCESS _PROCESS_LIMIT _PROCESS_SOFT_THRESHOLD _PROCESS_HARD_THRESHOLD
do
# check for empties
if [[ -z "${_PROCESS}" || -z "${_PROCESS_LIMIT}" ]]
then
warn "missing parameter in configuration file ${_CONFIG_FILE} at data line ${_LINE_COUNT}"
return 1
fi
data_is_numeric "${_PROCESS_SOFT_THRESHOLD}"
# shellcheck disable=SC2181
if (( $? > 0 ))
then
warn "parameter is not numeric in configuration file ${_CONFIG_FILE} at data line ${_LINE_COUNT}"
return 1
fi
data_is_numeric "${_PROCESS_HARD_THRESHOLD}"
# shellcheck disable=SC2181
if (( $? > 0 ))
then
warn "parameter is not numeric in configuration file ${_CONFIG_FILE} at data line ${_LINE_COUNT}"
return 1
fi
# which limit to check?
case "${_PROCESS_LIMIT}" in
"Max open files")
# collect ps info
(( ARG_DEBUG > 0 )) && debug "${_PROCESS_LIMIT}: collecting information for process class ${_PROCESS}"
_PROCESS_PS=$(_get_psinfo_by_process "${_PROCESS}")
if [[ -z "${_PROCESS_PS}" ]]
then
warn "${_PROCESS_LIMIT}: could not find any matching processes for process ${_PROCESS}"
continue
fi
print "${_PROCESS_PS}" | while read -r _PROCESS_PS_PID _PROCESS_PS_USER
do
(( ARG_DEBUG > 0 )) && debug "${_PROCESS_LIMIT}: checking process ${_PROCESS_PS_PID}"
# get current values and check thresholds
_MAX_OPEN_FILES=$(_get_open_files ${_PROCESS_PS_PID})
# SOFT limit
_check_limit "${_PROCESS_LIMIT}" soft ${_PROCESS_PS_PID} ${_PROCESS_PS_USER} \
${_PROCESS} ${_PROCESS_SOFT_THRESHOLD} ${_MAX_OPEN_FILES} ${_LOG_HEALTHY}
# HARD limit
_check_limit "${_PROCESS_LIMIT}" hard ${_PROCESS_PS_PID} ${_PROCESS_PS_USER} \
${_PROCESS} ${_PROCESS_HARD_THRESHOLD} ${_MAX_OPEN_FILES} ${_LOG_HEALTHY}
done
;;
*)
# no other limits are supported yet ;-)
warn "'${_PROCESS_LIMIT}' is an unsupported limit check"
continue
;;
esac
_LINE_COUNT=$(( _LINE_COUNT + 1 ))
done
# check USER stanzas
_LINE_COUNT=0
grep -i '^user' ${_CONFIG_FILE} 2>/dev/null |\
while IFS=';' read -r _ _USER _USER_LIMIT _USER_SOFT_THRESHOLD _USER_HARD_THRESHOLD
do
# check for empties
if [[ -z "${_USER}" || -z "${_USER_LIMIT}" ]]
then
warn "missing parameter in configuration file ${_CONFIG_FILE} at data line ${_LINE_COUNT}"
return 1
fi
# check optional value
if [[ -n "${_USER_SOFT_THRESHOLD}" ]]
then
data_is_numeric "${_USER_SOFT_THRESHOLD}"
# shellcheck disable=SC2181
if (( $? > 0 ))
then
warn "parameter is not numeric in configuration file ${_CONFIG_FILE} at data line ${_LINE_COUNT}"
return 1
fi
fi
# check optional value
if [[ -n "${_USER_HARD_THRESHOLD}" ]]
then
data_is_numeric "${_USER_HARD_THRESHOLD}"
# shellcheck disable=SC2181
if (( $? > 0 ))
then
warn "parameter is not numeric in configuration file ${_CONFIG_FILE} at data line ${_LINE_COUNT}"
return 1
fi
fi
# which limit to check?
case "${_USER_LIMIT}" in
"Max open files")
# collect ps info
(( ARG_DEBUG > 0 )) && debug "${_USER_LIMIT}: collecting information for user ${_USER}"
_USER_PS=$(_get_psinfo_by_user "${_USER}")
if [[ -z "${_USER_PS}" ]]
then
warn "${_USER_LIMIT}: could not find any matching processes for user ${_USER}"
continue
fi
print "${_USER_PS}" | while read -r _USER_PS_PID _USER_PS_COMM
do
(( ARG_DEBUG > 0 )) && debug "${_USER_LIMIT}: checking process ${_USER_PS_PID}"
# get current values and check thresholds
_MAX_OPEN_FILES=$(_get_open_files ${_USER_PS_PID})
# SOFT limit
_check_limit "${_USER_LIMIT}" soft ${_USER_PS_PID} ${_USER} ${_USER_PS_COMM} \
${_USER_SOFT_THRESHOLD} ${_MAX_OPEN_FILES} ${_LOG_HEALTHY}
# HARD limit
_check_limit "${_USER_LIMIT}" hard ${_USER_PS_PID} ${_USER} ${_USER_PS_COMM} \
${_USER_HARD_THRESHOLD} ${_MAX_OPEN_FILES} ${_LOG_HEALTHY}
done
;;
"Max processes")
(( ARG_DEBUG > 0 )) && debug "${_USER_LIMIT}: collecting information for user ${_USER}"
_MAX_PROCESSES=$(_get_processes ${_USER})
# SOFT limit
_check_limit "${_USER_LIMIT}" soft 0 ${_USER} "" ${_USER_SOFT_THRESHOLD} \
${_MAX_PROCESSES} ${_LOG_HEALTHY}
# HARD limit
_check_limit "${_USER_LIMIT}" hard 0 ${_USER} "" ${_USER_HARD_THRESHOLD} \
${_MAX_PROCESSES} ${_LOG_HEALTHY}
;;
*)
# no other limits are supported yet ;-)
warn "'${_USER_LIMIT}' is an unsupported limit check"
continue
;;
esac
_LINE_COUNT=$(( _LINE_COUNT + 1 ))
done
return 0
}
# -----------------------------------------------------------------------------
# example:
#1991 root
#1992 root
function _get_psinfo_by_process
{
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
ps -C "${1}" -o pid:1,user:1 --no-headers 2>/dev/null
return 0
}
# -----------------------------------------------------------------------------
# example:
#7270 qmgr
#8539 pickup
function _get_psinfo_by_user
{
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
ps -U "${1}" -o pid:1,comm:1 --no-headers 2>/dev/null
return 0
}
# -----------------------------------------------------------------------------
function _check_limit
{
typeset _LIMIT_NAME="${1}"
typeset _LIMIT_TYPE="${2}"
typeset _LIMIT_PID=${3} # can be 0
typeset _LIMIT_USER="${4}"
typeset _LIMIT_PROCESS="${5}" # can be ""
typeset _LIMIT_THRESHOLD=${6}
typeset _CURR_VALUE=${7}
typeset _LOG_HEALTHY=${8}
typeset _LIMIT_COMMAND=""
typeset _LIMIT_ENTRY=""
typeset _LIMIT_FIELD=0
typeset _MSG_BIT=""
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
# check for empties
(( _LIMIT_PID == 0 )) && _LIMIT_PID="N/A"
[[ -z "${_LIMIT_PROCESS}" ]] && _LIMIT_PROCESS="N/A"
if [[ -n "${_LIMIT_THRESHOLD}" ]]
then
# get limit value
case "${_LIMIT_NAME}" in
"Max open files")
_LIMIT_ENTRY=$(grep -i "${_LIMIT_NAME}" /proc/${_LIMIT_PID}/limits 2>/dev/null)
if [[ -z "${_LIMIT_ENTRY}" ]]
then
warn "${_LIMIT_TYPE}: unable to gather limits information for 'Max open files' (${_LIMIT_PID}/${_LIMIT_USER}/${_LIMIT_PROCESS})"
return 1
fi
case "${_LIMIT_TYPE}" in
soft)
_LIMIT_FIELD=1
;;
hard)
_LIMIT_FIELD=2
;;
esac
_LIMIT_VALUE=$(print "${_LIMIT_ENTRY}" | sed -s "s/${_LIMIT_NAME}//g" 2>/dev/null |\
awk -v f="${_LIMIT_FIELD}" '{ print $f}' 2>/dev/null)
_MSG_BIT="${_LIMIT_PID}/${_LIMIT_USER}/${_LIMIT_PROCESS}"
;;
"Max processes")
case "${_LIMIT_TYPE}" in
soft)
_LIMIT_COMMAND="ulimit -u 2>/dev/null"
# workaround for cr@ppy pdksh/mirksh
if (( IS_PDKSH > 0 ))
then
_LIMIT_COMMAND="ulimit -a | grep 'processes' 2>/dev/null | awk '{print \$2}' 2>/dev/null"
fi
;;
hard)
_LIMIT_COMMAND="ulimit -Hu 2>/dev/null"
# workaround for cr@ppy pdksh/mirksh
if (( IS_PDKSH > 0 ))
then
_LIMIT_COMMAND="ulimit -Ha | grep 'processes' 2>/dev/null | awk '{print \$2}' 2>/dev/null"
fi
;;
esac
_LIMIT_VALUE=$(su - "${_LIMIT_USER}" -c "${_LIMIT_COMMAND}")
data_is_numeric "${_LIMIT_VALUE}"
# shellcheck disable=SC2181
if (( $? > 0 ))
then
warn "${_LIMIT_TYPE}: unable to gather limits information for 'Max processes' (${_LIMIT_USER})"
return 1
fi
_MSG_BIT="${_LIMIT_USER}"
;;
esac
# check limit value -> threshold
if [[ "${_LIMIT_VALUE}" = "unlimited" ]]
then
log "limit (${_LIMIT_TYPE} on '${_LIMIT_NAME}' is unlimited (${_MSG_BIT})"
return 0
else
if (( _CURR_VALUE > (_LIMIT_VALUE * _LIMIT_THRESHOLD / 100) ))
then
_MSG="(${_MSG_BIT}) limit (${_LIMIT_TYPE}) on '${_LIMIT_NAME}' has been surpassed (${_CURR_VALUE} > ${_LIMIT_VALUE} @${_LIMIT_THRESHOLD}%)"
log_hc "$0" 1 "${_MSG}" ${_CURR_VALUE} $(( _LIMIT_VALUE * _LIMIT_THRESHOLD / 100 ))
else
if (( _LOG_HEALTHY > 0 ))
then
_MSG="(${_MSG_BIT}) limit (${_LIMIT_TYPE}) on '${_LIMIT_NAME}' is safe (${_CURR_VALUE} <= ${_LIMIT_VALUE} @${_LIMIT_THRESHOLD}%)"
log_hc "$0" 0 "${_MSG}" ${_CURR_VALUE} $(( _LIMIT_VALUE * _LIMIT_THRESHOLD / 100 ))
fi
fi
fi
else
warn "limit on (${_LIMIT_TYPE} on '${_LIMIT_NAME}' was not checked (PID=${_LIMIT_PID})"
fi
# do cleanup
rm -f ${_INSTANCE_RUN_FILE}.* >/dev/null 2>&1
return 0
}
# -----------------------------------------------------------------------------
function _get_open_files
{
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
# shellcheck disable=SC2012
ls -f /proc/${1}/fd/ 2>/dev/null | wc -l 2>/dev/null
return 0
}
# -----------------------------------------------------------------------------
function _get_processes
{
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
ps -U "${1}" --no-headers 2>/dev/null | wc -l 2>/dev/null
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with:
log_healthy=<yes|no>
and formatted stanzas:
user:<user_name>:<limit_name>:<soft_limit_threshold_%>:<hard_limit_threshold_%>
process:<process_name>:<limit_name>:<soft_limit_threshold_%>:<hard_limit_threshold_%>
PURPOSE : Checks the value(s) of the process limits from /proc/*/limits or ulimit
Currenty following checks are supported:
* Max open files (/proc/*/limits)
* Max processes (ulimit)
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+183
View File
@@ -0,0 +1,183 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_linux_root_crontab
#******************************************************************************
# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#*******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_linux_root_crontab
# DOES: see _show_usage()
# EXPECTS: see _show_usage()
# REQUIRES: data_comma2space(), init_hc(), log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2013-09-19: initial version [Patrick Van der Veken]
# @(#) 2018-05-21: STDERR fixes [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!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_linux_root_crontab
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _CFG_HEALTHY=""
typeset _LOG_HEALTHY=0
typeset _CRON_LINE=""
typeset _CRON_ENTRY=""
typeset _CRON_MATCH=0
typeset _IS_OLD_STYLE=0
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
esac
done
# handle configuration file
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
if [[ ! -r ${_CONFIG_FILE} ]]
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, since Linux can have multiple cron sources we will
# squash them all together, standard cron, vixie, anacron, you name it :)
print "=== crontab -l ===" >>${HC_STDOUT_LOG}
crontab -l >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG}
print "=== /etc/crontab ===" >>${HC_STDOUT_LOG}
[[ -s /etc/crontab ]] && cat /etc/crontab >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG}
print "=== /etc/cron.(hourly|daily|weekly|monthly) ===" >>${HC_STDOUT_LOG}
[[ -d /etc/cron.hourly ]] && cat /etc/cron.hourly/* \
>>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG}
[[ -d /etc/cron.daily ]] && cat /etc/cron.daily/* \
>>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG}
[[ -d /etc/cron.weekly ]] && cat /etc/cron.weekly/* \
>>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG}
[[ -d /etc/cron.monthly ]] && cat /etc/cron.monthly/* \
>>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG}
print "=== /etc/cron.d ===" >>${HC_STDOUT_LOG}
if [[ -d /etc/cron.d ]]
then
cat /etc/cron.d/* 2>/dev/null | while read _CRON_LINE
do
if [[ $(print "${_CRON_LINE}" | awk '{print $6}' 2>/dev/null) == "root" ]]
then
print "${_CRON_LINE}" >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG}
fi
done
fi
# perform check
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}" 2>/dev/null)
case ${_CRON_MATCH} in
0)
_MSG="'${_CRON_ENTRY}' is not configured in cron"
_STC=1
;;
1)
_MSG="'${_CRON_ENTRY}' is configured in cron"
;;
+([0-9])*([0-9]))
_MSG="'${_CRON_ENTRY}' is configured multiple times in cron"
;;
esac
# report result
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
_STC=0
done
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with parameters:
log_healthy=<yes|no>
and formatted stanzas:
cron:<cron_entry>
PURPOSE : Checks the content of the 'root' user crontab for required entries
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+182
View File
@@ -0,0 +1,182 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_linux_samba_status.sh
#******************************************************************************
# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_linux_samba_status
# DOES: see _show_usage()
# EXPECTS: n/a
# REQUIRES: data_comma2space(), linux_get_init(), init_hc(), log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2013-05-17: initial version [Patrick Van der Veken]
# @(#) 2016-12-01: added systemd code [Patrick Van der Veken]
# @(#) 2017-05-08: fix fall-back for sysv->pgrep [Patrick Van der Veken]
# @(#) 2017-07-23: fix for systemd service names [Patrick Van der Veken]
# @(#) 2018-05-21: STDERR fixes [Patrick Van der Veken]
# @(#) 2018-11-18: add linux_has_systemd_service() [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!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_linux_samba_status
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _SMB_INIT_SCRIPT="/etc/init.d/samba"
typeset _SMB_SYSTEMD_SERVICE="smb.service"
typeset _NMB_SYSTEMD_SERVICE="nmb.service"
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _LOG_HEALTHY=0
typeset _RC=0
typeset _CHECK_SYSTEMD_SERVICE=0
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
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
# 1) try using the init ways
linux_get_init
case "${LINUX_INIT}" in
'systemd')
# check running NMB
_CHECK_SYSTEMD_SERVICE=$(linux_has_systemd_service "${_NMB_SYSTEMD_SERVICE}")
if (( _CHECK_SYSTEMD_SERVICE > 0 ))
then
systemctl --quiet is-active ${_NMB_SYSTEMD_SERVICE} 2>>${HC_STDERR_LOG} || _STC=1
else
warn "systemd unit file not found {${_NMB_SYSTEMD_SERVICE}}"
_RC=1
fi
# check running SMB
_CHECK_SYSTEMD_SERVICE=$(linux_has_systemd_service "${_SMB_SYSTEMD_SERVICE}")
if (( _CHECK_SYSTEMD_SERVICE > 0 ))
then
systemctl --quiet is-active ${_SMB_SYSTEMD_SERVICE} 2>>${HC_STDERR_LOG} || _STC=$(( _STC + 2 ))
else
warn "systemd unit file not found {${_SMB_SYSTEMD_SERVICE}}"
_RC=1
fi
;;
'upstart')
warn "code for upstart managed systems not implemented, NOOP"
return 1
;;
'sysv')
# check running NMB/SMB
if [[ -x ${_SMB_INIT_SCRIPT} ]]
then
if (( $(${_SMB_INIT_SCRIPT} status 2>>${HC_STDERR_LOG} | grep -c -i -E -e 'NMB.*is running.*' 2>/dev/null) == 0 ))
then
_STC=1
fi
# check running SMB
if (( $(${_SMB_INIT_SCRIPT} status 2>>${HC_STDERR_LOG} | grep -c -i -E -e 'SMB.*is running.*' 2>/dev/null) == 0 ))
then
_STC=$(( _STC + 2 ))
fi
else
warn "sysv init script not found {${_SMB_INIT_SCRIPT}}"
_RC=1
fi
;;
*)
_RC=1
;;
esac
# 2) try the pgrep way (note: old pgreps do not support '-c')
if (( _RC > 0 ))
then
(( $(pgrep -u root nmbd 2>>${HC_STDERR_LOG}| wc -l 2>/dev/null) == 0 )) && _STC=1
(( $(pgrep -u root smbd 2>>${HC_STDERR_LOG} | wc -l 2>/dev/null) == 0 )) && _STC=$(( _STC + 2 ))
fi
# evaluate results
case ${_STC} in
0)
_MSG="NMB/SMB are running"
;;
1)
_MSG="NMB is not running"
;;
2)
_MSG="SMB is not running"
;;
3)
_MSG="NMB/SMB are not running"
;;
*)
_MSG="could not determine status of NMB/SMB"
;;
esac
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
PURPOSE : Checks whether SAMBA daemons are running
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+198
View File
@@ -0,0 +1,198 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_hpux_sg_cluster_config
#******************************************************************************
# @(#) Copyright (C) 2016 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#*****************************************hpux*************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_linux_sg_cluster_status
# DOES: see _show_usage()
# EXPECTS: see _show_usage()
# REQUIRES: data_comma2space(), dump_logs(), init_hc(), log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2017-04-01: initial version [Patrick Van der Veken]
# @(#) 2018-05-21: added dump_logs() & other fixes [Patrick Van der Veken]
# @(#) 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]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_linux_sg_cluster_config
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _VERSION="2019-01-24" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
typeset _SG_DAEMON="/opt/cmcluster/bin/cmcld"
# rubbish that cmgetconf outputs to STDOUT instead of STDERR
typeset _SG_CMGETCONF_FILTER="Permission denied|Number of configured"
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
PATH=$PATH:/opt/cmcluster/bin
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _CLUSTER_RUN_FILE="${TMP_DIR}/.$0.cluster_run.$$"
typeset _CLUSTER_CFG_FILE="${TMP_DIR}/.$0.cluster_cfg.$$"
typeset _CLUSTER_INSTANCE=""
typeset _CLUSTER_INSTANCES=""
typeset _CLUSTER_ENTRY=""
typeset _CLUSTER_CFG_ENTRY=""
typeset _CLUSTER_MATCH=""
typeset _CLUSTER_PARAM=""
typeset _CLUSTER_VALUE=""
# set local trap for cleanup
# shellcheck disable=SC2064
trap "rm -f ${_CLUSTER_RUN_FILE}.* ${_CLUSTER_CFG_FILE}.* >/dev/null 2>&1; return 1" 1 2 3 15
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
esac
done
# handle configuration file
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
if [[ ! -r ${_CONFIG_FILE} ]]
then
warn "unable to read configuration file at ${_CONFIG_FILE}"
return 1
fi
# look for cluster instance names
grep -E -e '^\[' ${_CONFIG_FILE} 2>/dev/null | cut -f1 -d']' 2>/dev/null | cut -f2 -d'[' 2>/dev/null |\
while read _CLUSTER_INSTANCE
do
_CLUSTER_INSTANCES="${_CLUSTER_INSTANCES} ${_CLUSTER_INSTANCE}"
done
if [[ -z "${_CLUSTER_INSTANCES}" ]]
then
warn "no cluster information configured in ${_CONFIG_FILE}"
return 1
fi
# check serviceguard status & gather cluster information from running cluster (compressed lines)
if [[ ! -x ${_SG_DAEMON} ]]
then
warn "${_SG_DAEMON} is not installed here"
return 1
else
for _CLUSTER_INSTANCE in ${_CLUSTER_INSTANCES}
do
cmgetconf -c ${_CLUSTER_INSTANCE} 2>>${HC_STDERR_LOG} |\
grep -v -E -e "${_SG_CMGETCONF_FILTER}" | tr -d ' \t' >${_CLUSTER_RUN_FILE}.${_CLUSTER_INSTANCE}
[[ -s ${_CLUSTER_RUN_FILE}.${_CLUSTER_INSTANCE} ]] || {
_MSG="unable to gather cluster configuration"
log_hc "$0" 1 "${_MSG}"
# dump debug info
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
return 0
}
done
fi
# gather cluster information from healthcheck configuration
for _CLUSTER_INSTANCE in ${_CLUSTER_INSTANCES}
do
awk -v cluster="${_CLUSTER_INSTANCE}" '
BEGIN { found = 0; needle = "^\["cluster"\]" }
# skip blank lines
/^\s*$/ { next; }
# skip comment lines
/^#/ { next; }
# end marker
( $0 ~ /^\[.*\]/ && found ) {
found = 0;
}
# start marker
$0 ~ needle {
found = 1;
};
# stanza body
( found && $0 !~ /^\[.*\]/ ) {
# print non-compressed and compressed version
printf "%s|", $0;
gsub(" |\t", "", $0);
printf "%s\n", $0;
}' < ${_CONFIG_FILE} 2>>${HC_STDERR_LOG} >${_CLUSTER_CFG_FILE}.${_CLUSTER_INSTANCE}
done
# do cluster configuration checks (using the compressed strings)
for _CLUSTER_INSTANCE in ${_CLUSTER_INSTANCES}
do
while read _CLUSTER_ENTRY
do
# split entry to get the compressed version
_CLUSTER_CFG_ENTRY=$(print "${_CLUSTER_ENTRY}" | cut -f2 -d'|' 2>/dev/null)
# get parameter name from non-compressed version
_CLUSTER_PARAM=$(print "${_CLUSTER_ENTRY}" | cut -f1 -d'|' 2>/dev/null | awk '{ print $1 }' 2>/dev/null)
# get parameter value from non-compressed version
_CLUSTER_VALUE=$(print "${_CLUSTER_ENTRY}" | cut -f1 -d'|' 2>/dev/null | awk '{ print substr($2,1,30)}' 2>/dev/null)
# is it present?
_CLUSTER_MATCH=$(grep -c "${_CLUSTER_CFG_ENTRY}" ${_CLUSTER_RUN_FILE}.${_CLUSTER_INSTANCE} 2>/dev/null)
if (( _CLUSTER_MATCH == 0 ))
then
# get parameter name from non-compressed version
_MSG="'${_CLUSTER_PARAM} (${_CLUSTER_VALUE} ...)' is not correctly configured for ${_CLUSTER_INSTANCE}"
_STC=1
else
_MSG="'${_CLUSTER_PARAM} (${_CLUSTER_VALUE} ...)' is configured for ${_CLUSTER_INSTANCE}"
fi
# handle unit result
log_hc "$0" ${_STC} "${_MSG}"
_STC=0
done <${_CLUSTER_CFG_FILE}.${_CLUSTER_INSTANCE}
done
# do cleanup
rm -f ${_CLUSTER_RUN_FILE}.* ${_CLUSTER_CFG_FILE}.* >/dev/null 2>&1
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3
PURPOSE : Checks the configuration of a Serviceguard cluster (SG 11.16+) (comparing
serialized strings from the plugin configuration file with the running
cluster configuration)
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+185
View File
@@ -0,0 +1,185 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_linux_sg_cluster_status
#******************************************************************************
# @(#) Copyright (C) 2016 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_linux_sg_cluster_status
# DOES: see _show_usage()
# EXPECTS: see _show_usage()
# REQUIRES: data_comma2space(), dump_logs(), init_hc(), log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2017-04-01: initial version [Patrick Van der Veken]
# @(#) 2017-05-07: made checks more detailed for log_hc() [Patrick Van der Veken]
# @(#) 2018-05-20: added dump_logs() [Patrick Van der Veken]
# @(#) 2018-05-21: STDERR fixes [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: 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!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_linux_sg_cluster_status
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
typeset _SG_DAEMON="/opt/cmcluster/bin/cmcld"
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
PATH=$PATH:/opt/cmcluster/bin
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _CFG_HEALTHY=""
typeset _LOG_HEALTHY=0
typeset _SG_ENTRY=""
typeset _SG_MATCH=""
typeset _SG_CFG_PARAM=""
typeset _SG_CFG_VALUE=""
typeset _SG_RUN_VALUE=""
typeset _IS_OLD_STYLE=0
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
esac
done
# handle configuration file
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
if [[ ! -r ${_CONFIG_FILE} ]]
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 "^sg:" ${_CONFIG_FILE} 2>/dev/null)
if (( _IS_OLD_STYLE == 0 ))
then
warn "no 'sg:' 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
# check & get serviceguard status
if [[ ! -x ${_SG_DAEMON} ]]
then
warn "${_SG_DAEMON} is not installed here"
return 1
else
cmviewcl -v -f line 2>>${HC_STDERR_LOG} | tr '|' ':' >>${HC_STDOUT_LOG} 2>/dev/null
(( $? > 0 )) && {
_MSG="unable to run command: {cmviewcl}"
log_hc "$0" 1 "${_MSG}"
# dump debug info
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
return 1
}
fi
# do cluster status checks
# (replace ':' by '|' for cmcviewcl output)
grep -E -e "^sg:" ${_CONFIG_FILE} 2>/dev/null | tr '|' ':' 2>/dev/null |\
while read -r _ _SG_ENTRY
do
# field split
_SG_CFG_PARAM="$(print ${_SG_ENTRY} | cut -f1 -d'=' 2>/dev/null)" # field 1
_SG_CFG_VALUE="$(print ${_SG_ENTRY} | cut -f2 -d'=' 2>/dev/null)" # field 2
# check run-time values (anchored grep here!)
_SG_MATCH=$(grep -i "^${_SG_CFG_PARAM}" ${HC_STDOUT_LOG} 2>/dev/null)
if [[ -n "${_SG_MATCH}" ]]
then
_SG_RUN_VALUE=$(print "${_SG_MATCH}" | cut -f2 -d'=' 2>/dev/null) # field 2
if [[ "${_SG_CFG_VALUE}" = "${_SG_RUN_VALUE}" ]]
then
_MSG="cluster parameter ${_SG_CFG_PARAM} has a correct value [${_SG_RUN_VALUE}]"
_STC=0
else
_MSG="cluster parameter ${_SG_CFG_PARAM} has a wrong value [${_SG_RUN_VALUE}]"
_STC=1
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}" "${_SG_RUN_VALUE}" "${_SG_CFG_VALUE}"
fi
else
warn "could not determine status for ${_SG_CFG_PARAM} from command output {cmviewcl}"
fi
done
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with parameters:
log_healthy=<yes|no>
and formatted stanzas:
sg:<param>=<value>
PURPOSE : Checks the status of Serviceguard cluster parameters (SG 11.16+)
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+198
View File
@@ -0,0 +1,198 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_linux_sg_package_config
#******************************************************************************
# @(#) Copyright (C) 2016 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_linux_sg_package_config
# DOES: see _show_usage()
# EXPECTS: see _show_usage()
# REQUIRES: data_comma2space(), dump_logs(), init_hc(), log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2017-04-01: initial version [Patrick Van der Veken]
# @(#) 2018-05-21: added dump_logs() & other fixes [Patrick Van der Veken]
# @(#) 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]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_linux_sg_package_config
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _VERSION="2019-01-24" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
typeset _SG_DAEMON="/opt/cmcluster/bin/cmcld"
# rubbish that cmgetconf outputs to STDOUT instead of STDERR
typeset _SG_CMGETCONF_FILTER="Permission denied|Number of configured"
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
PATH=$PATH:/opt/cmcluster/bin
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _PKG_RUN_FILE="${TMP_DIR}/.$0.pkg_run.$$"
typeset _PKG_CFG_FILE="${TMP_DIR}/.$0.pkg_cfg.$$"
typeset _PKG_INSTANCE=""
typeset _PKG_INSTANCES=""
typeset _PKG_ENTRY=""
typeset _PKG_CFG_ENTRY=""
typeset _PKG_MATCH=""
typeset _PKG_PARAM=""
typeset _PKG_VALUE=""
# set local trap for cleanup
# shellcheck disable=SC2064
trap "rm -f ${_PKG_RUN_FILE}.* ${_PKG_CFG_FILE}.* >/dev/null 2>&1; return 1" 1 2 3 15
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
esac
done
# handle config file
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
if [[ ! -r ${_CONFIG_FILE} ]]
then
warn "unable to read configuration file at ${_CONFIG_FILE}"
return 1
fi
# look for package instance names
grep -E -e '^\[' ${_CONFIG_FILE} 2>/dev/null | cut -f1 -d']' 2>/dev/null | cut -f2 -d'[' 2>/dev/null |\
while read _PKG_INSTANCE
do
_PKG_INSTANCES="${_PKG_INSTANCES} ${_PKG_INSTANCE}"
done
if [[ -z "${_PKG_INSTANCES}" ]]
then
warn "no package information configured in ${_CONFIG_FILE}"
return 1
fi
# check serviceguard status & gather package information from running cluster (compressed lines)
if [[ ! -x ${_SG_DAEMON} ]]
then
warn "${_SG_DAEMON} is not installed here"
return 1
else
for _PKG_INSTANCE in ${_PKG_INSTANCES}
do
cmgetconf -p ${_PKG_INSTANCE} -v 0 2>>${HC_STDERR_LOG} |\
grep -v -E -e "${_SG_CMGETCONF_FILTER}" | tr -d ' \t' >${_PKG_RUN_FILE}.${_PKG_INSTANCE}
[[ -s ${_PKG_RUN_FILE}.${_PKG_INSTANCE} ]] || {
_MSG="unable to gather package configuration for at least one cluster package"
log_hc "$0" 1 "${_MSG}"
# dump debug info
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
return 0
}
done
fi
# gather package information from healthcheck configuration
for _PKG_INSTANCE in ${_PKG_INSTANCES}
do
awk -v package="${_PKG_INSTANCE}" '
BEGIN { found = 0; needle = "^\["package"\]" }
# skip blank lines
/^\s*$/ { next; }
# skip comment lines
/^#/ { next; }
# end marker
( $0 ~ /^\[.*\]/ && found ) {
found = 0;
}
# start marker
$0 ~ needle {
found = 1;
};
# stanza body
( found && $0 !~ /^\[.*\]/ ) {
# print non-compressed and compressed version
printf "%s|", $0;
gsub(" |\t", "", $0);
printf "%s\n", $0;
}' < ${_CONFIG_FILE} 2>>${HC_STDERR_LOG} >${_PKG_CFG_FILE}.${_PKG_INSTANCE}
done
# do package configuration checks (using the compressed strings)
for _PKG_INSTANCE in ${_PKG_INSTANCES}
do
while read _PKG_ENTRY
do
# split entry to get the compressed version
_PKG_CFG_ENTRY=$(print "${_PKG_ENTRY}" | cut -f2 -d'|' 2>/dev/null)
# get parameter name from non-compressed version
_PKG_PARAM=$(print "${_PKG_ENTRY}" | awk '{ print $1 }' 2>/dev/null)
# get parameter value from non-compressed version
_PKG_VALUE=$(print "${_PKG_ENTRY}" | cut -f1 -d'|' 2>/dev/null| awk '{ print substr($2,1,30)}' 2>/dev/null)
# is it present?
_PKG_MATCH=$(grep -c "${_PKG_CFG_ENTRY}" ${_PKG_RUN_FILE}.${_PKG_INSTANCE} 2>/dev/null)
if (( _PKG_MATCH == 0 ))
then
# get parameter name from non-compressed version
_MSG="'${_PKG_PARAM} (${_PKG_VALUE} ...)' is not correctly configured for ${_PKG_INSTANCE}"
_STC=1
else
_MSG="'${_PKG_PARAM} (${_PKG_VALUE} ...)' is configured for ${_PKG_INSTANCE}"
fi
# handle unit result
log_hc "$0" ${_STC} "${_MSG}"
_STC=0
done <${_PKG_CFG_FILE}.${_PKG_INSTANCE}
done
# do cleanup
rm -f ${_PKG_RUN_FILE}.* ${_PKG_CFG_FILE}.* >/dev/null 2>&1
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3
PURPOSE : Checks the configuration of Serviceguard package parameters (SG 11.16+)
(comparing serialized strings from the HC configuration file to the
running cluster configuration)
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+187
View File
@@ -0,0 +1,187 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_linux_sg_package_status
#******************************************************************************
# @(#) Copyright (C) 2016 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_linux_sg_package_status
# DOES: see _show_usage()
# EXPECTS: see _show_usage()
# REQUIRES: data_comma2space(), dump_logs(), init_hc(), log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2017-04-01: initial version [Patrick Van der Veken]
# @(#) 2017-05-07: made checks more detailed for log_hc() [Patrick Van der Veken]
# @(#) 2018-05-20: added dump_logs() [Patrick Van der Veken]
# @(#) 2018-05-21: STDERR fixes [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: 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!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_linux_sg_package_status
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
typeset _SG_DAEMON="/opt/cmcluster/bin/cmcld"
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
PATH=$PATH:/opt/cmcluster/bin
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _CFG_HEALTHY=""
typeset _LOG_HEALTHY=0
typeset _SG_ENTRY=""
typeset _SG_MATCH=""
typeset _SG_PACKAGE=""
typeset _SG_CFG_PARAM=""
typeset _SG_CFG_VALUE=""
typeset _SG_RUN_VALUE=""
typeset _IS_OLD_STYLE=0
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
esac
done
# handle configuration file
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
if [[ ! -r ${_CONFIG_FILE} ]]
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 "^sg:" ${_CONFIG_FILE} 2>/dev/null)
if (( _IS_OLD_STYLE == 0 ))
then
warn "no 'sg:' 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
# check & get serviceguard status
if [[ ! -x ${_SG_DAEMON} ]]
then
warn "${_SG_DAEMON} is not installed here"
return 1
else
cmviewcl -v -f line -l package 2>>${HC_STDERR_LOG} | tr '|' ':' >>${HC_STDOUT_LOG}
(( $? > 0)) && {
_MSG="unable to run command: {cmviewcl}"
log_hc "$0" 1 "${_MSG}"
# dump debug info
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
return 1
}
fi
# do package status checks
# (replace ':' by '|' for cmcviewcl output)
grep -E -e "^sg:" ${_CONFIG_FILE} 2>/dev/null | tr '|' ':' 2>/dev/null |\
while read -r _ _SG_ENTRY
do
# field split
_SG_PACKAGE="$(print ${_SG_ENTRY} | cut -f1 -d':')"
_SG_CFG_PARAM="$(print ${_SG_ENTRY} | cut -f2- -d':' 2>/dev/null | cut -f1 -d'=' 2>/dev/null)" # field 2-,1
_SG_CFG_VALUE="$(print ${_SG_ENTRY} | cut -f2- -d':' 2>/dev/null | cut -f2 -d'=' 2>/dev/null)" # field 2-,2
# check run-time values (anchored grep here!)
_SG_MATCH=$(grep -i "^package:${_SG_PACKAGE}:${_SG_CFG_PARAM}" ${HC_STDOUT_LOG} 2>/dev/null)
if [[ -n "${_SG_MATCH}" ]]
then
_SG_RUN_VALUE=$(print "${_SG_MATCH}" | cut -f3- -d':' 2>/dev/null | cut -f2 -d'=' 2>/dev/null) # field3-,2
if [[ "${_SG_CFG_VALUE}" = "${_SG_RUN_VALUE}" ]]
then
_MSG="package ${_SG_PACKAGE} parameter ${_SG_CFG_PARAM} has a correct value [${_SG_RUN_VALUE}]"
_STC=0
else
_MSG="package ${_SG_PACKAGE} parameter ${_SG_CFG_PARAM} has a wrong value [${_SG_RUN_VALUE}]"
_STC=1
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}" "${_SG_RUN_VALUE}" "${_SG_CFG_VALUE}"
fi
else
warn "could not determine status for ${_SG_PACKAGE}/${_SG_CFG_PARAM} from command output {cmviewcl}"
fi
done
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with parameters:
log_healthy=<yes|no>
and formatted stanzas:
sg:<package_name>:<parameter>=<value>
PURPOSE : Checks the status of Serviceguard package parameters (SG 11.16+)
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+136
View File
@@ -0,0 +1,136 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_linux_sg_qs_status.sh
#******************************************************************************
# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_linux_sg_qs_status
# DOES: see _show_usage()
# EXPECTS: n/a
# REQUIRES: data_comma2space(), init_hc(), log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2017-05-01: initial version [Patrick Van der Veken]
# @(#) 2018-05-21: STDERR fixes [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!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_linux_sg_qs_status
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
typeset _QS_BIN="/opt/qs/bin/qsc"
typeset _QS_AUTH_FILE="/opt/qs/conf/qs_authfile"
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _LOG_HEALTHY=0
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
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 QS presence
if [[ ! -x ${_QS_BIN} ]]
then
warn "${_QS_BIN} is not installed here"
return 1
fi
# ---- process state ----
(( $(pgrep -u root -f ${_QS_BIN} 2>>${HC_STDERR_LOG} | wc -l 2>/dev/null) == 0 )) && _STC=1
# evaluate results
case ${_STC} in
0)
_MSG="QS is running"
;;
1)
_MSG="QS is not running"
;;
*)
_MSG="could not determine status of QS"
;;
esac
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
# ---- config state ----
if [[ -s ${_QS_AUTH_FILE} ]]
then
_MSG="QS authorizations file has been configured"
_STC=0
else
_MSG="QS authorizations file is missing or empty (${_QS_AUTH_FILE})"
_STC=1
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
PURPOSE : Checks whether the Serviceguard quorum server is running
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+131
View File
@@ -0,0 +1,131 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_linux_shorewall_status.sh
#******************************************************************************
# @(#) Copyright (C) 2016 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_linux_shorewall_status
# DOES: see _show_usage()
# EXPECTS: n/a
# REQUIRES: data_comma2space(), init_hc(), log_hc()
#
# @(#) HISTORY:
# @(#) 2016-12-01: 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!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_linux_shorewall_status
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _SHOREWALL_BIN="/sbin/shorewall"
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _LOG_HEALTHY=0
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
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 status
if [[ -x ${_SHOREWALL_BIN} && -n "${_SHOREWALL_BIN}" ]]
then
# check status
${_SHOREWALL_BIN} status >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG}
if (( $? == 0 ))
then
_MSG="shorewall is running"
_STC=0
else
_MSG="shorewall is not running {shorewall status}"
_STC=1
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
# check compile
${_SHOREWALL_BIN} check >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG}
if (( $? == 0 ))
then
_MSG="shorewall rules compile correctly"
_STC=0
else
_MSG="shorewall rules do not compile correctly {shorewall check}"
_STC=1
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
else
warn "shorewall is not installed here"
return 1
fi
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
PURPOSE : Checks whether shorewall (firewall) service is running and whether
shorewall rules compile correctly
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+171
View File
@@ -0,0 +1,171 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_linux_sshd_status.sh
#******************************************************************************
# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_linux_sshd_status
# DOES: see _show_usage()
# EXPECTS: n/a
# REQUIRES: data_comma2space(), linux_get_init(), init_hc(), log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2016-12-01: initial version [Patrick Van der Veken]
# @(#) 2017-05-05: fix fall-back for sysv->pgrep [Patrick Van der Veken]
# @(#) 2017-05-08: set init/systemd based on distro [Patrick Van der Veken]
# @(#) 2018-05-21: STDERR fixes [Patrick Van der Veken]
# @(#) 2018-11-18: add linux_has_systemd_service() [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!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_linux_sshd_status
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _SSHD_INIT_SCRIPT=""
typeset _SSHD_SYSTEMD_SERVICE=""
typeset _CHECK_SYSTEMD_SERVICE=0
typeset _STC=0
typeset _LOG_HEALTHY=0
typeset _RC=0
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
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
# set init script & systemd service
case "${LINUX_DISTRO}" in
Debian)
_SSHD_INIT_SCRIPT="/etc/init.d/ssh"
_SSHD_SYSTEMD_SERVICE="ssh.service"
;;
*)
_SSHD_INIT_SCRIPT="/etc/init.d/sshd"
_SSHD_SYSTEMD_SERVICE="sshd.service"
;;
esac
# 1) try using the init ways
linux_get_init
case "${LINUX_INIT}" in
'systemd')
_CHECK_SYSTEMD_SERVICE=$(linux_has_systemd_service "${_SSHD_SYSTEMD_SERVICE}")
if (( _CHECK_SYSTEMD_SERVICE > 0 ))
then
systemctl --quiet is-active ${_SSHD_SYSTEMD_SERVICE} 2>>${HC_STDERR_LOG} || _STC=1
else
warn "systemd unit file not found {${_SSHD_SYSTEMD_SERVICE}}"
_RC=1
fi
;;
'upstart')
warn "code for upstart managed systems not implemented, NOOP"
return 1
;;
'sysv')
if [[ -x ${_SSHD_INIT_SCRIPT} ]]
then
if (( $(${_SSHD_INIT_SCRIPT} status 2>>${HC_STDERR_LOG} | grep -c -i 'is running' 2>/dev/null) == 0 ))
then
_STC=1
fi
else
warn "sysv init script not found {${_SSHD_INIT_SCRIPT}}"
_RC=1
fi
;;
*)
_RC=1
;;
esac
# 2) try the pgrep way (note: old pgreps do not support '-c')
if (( _RC > 0 ))
then
(( $(pgrep -P 1 -u root sshd 2>>${HC_STDERR_LOG} | wc -l 2>/dev/null) == 0 )) && _STC=1
fi
# evaluate results
case ${_STC} in
0)
_MSG="sshd is running"
;;
1)
_MSG="sshd is not running"
;;
*)
_MSG="could not determine status of sshd"
;;
esac
# report results
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
PURPOSE : Checks whether sshd (Secure Shell daemon) is running
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+180
View File
@@ -0,0 +1,180 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_linux_vz_ct_counters.sh
#******************************************************************************
# @(#) Copyright (C) 2019 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_linux_vz_ct_counters
# DOES: see _show_usage()
# EXPECTS: see _show_usage()
# REQUIRES: data_comma2space(), data_is_numeric(), data_strip_space(),
# dump_logs(), init_hc(), log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2019-02-08: initial version [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_linux_vz_ct_counters
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _VZUBC_BIN="/usr/sbin/vzubc"
typeset _VZUBC_OPTS="-q -i -r"
typeset _VERSION="2019-02-08" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _CFG_HEALTHY=""
typeset _LOG_HEALTHY=0
typeset _CT_ID=""
typeset _UBC_OUTPUT=""
typeset _UBC_NAME=""
typeset _UBC_FAIL=""
typeset _UBC_HELD=""
typeset _UBC_MAX_HELD=""
typeset _RC=0
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
esac
done
# handle configuration file
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
if [[ ! -r ${_CONFIG_FILE} ]]
then
warn "unable to read configuration file at ${_CONFIG_FILE}"
return 1
fi
# read configuration values
_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 openvz
if [[ ! -x ${_VZUBC_BIN} || -z "${_VZUBC_BIN}" ]]
then
warn "OpenVZ is not installed here"
return 1
fi
# check configuration values
grep -E -e '^ct:' ${_CONFIG_FILE} 2>/dev/null | cut -f2 -d':' 2>/dev/null |\
while read -r _CT_ID
do
data_is_numeric "${_CT_ID}"
if (( $? > 0 ))
then
warn "${_CT_ID} appears to be an incorrect value for CT ID"
continue
fi
# get bean counters
_UBC_OUTPUT=$(${_VZUBC_BIN} ${_VZUBC_OPTS} ${_CT_ID} 2>>${HC_STDERR_LOG})
if (( $? > 0 )) || [[ -z "${_UBC_OUTPUT}" ]]
then
warn "unable to run command {${_VZUBC_BIN}}. Container ${_CT_ID} does not exist?"
# dump debug info
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
_RC=1
continue
fi
# check values (data lines start with a space)
print "${_UBC_OUTPUT}" | grep "^ " 2>/dev/null | while read -r _UBC_LINE
do
_UBC_NAME=$(data_strip_space "$(print ${_UBC_LINE} | cut -f1 -d'|' 2>/dev/null)")
_UBC_FAIL=$(data_strip_space "$(print ${_UBC_LINE} | cut -f6 -d'|' 2>/dev/null)")
_UBC_HELD=$(data_strip_space "$(print ${_UBC_LINE} | cut -f2 -d'|' 2>/dev/null | awk '{print $1}')")
_UBC_MAX_HELD=$(data_strip_space "$(print ${_UBC_LINE} | cut -f3 -d'|' 2>/dev/null | awk '{print $1}')")
if [[ -z "${_UBC_FAIL}" ]] || [[ "${_UBC_FAIL}" = '-' ]]
then
_MSG="${_UBC_NAME} for CT ${_CT_ID} is unchanged [HELD:${_UBC_HELD}/MAX_HELD:${_UBC_MAX_HELD}]"
_STC=0
else
_MSG="${_UBC_NAME} for CT ${_CT_ID} increased with ${_UBC_FAIL} [HELD:${_UBC_HELD}/MAX_HELD:${_UBC_MAX_HELD}]"
_STC=1
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}" "${_UBC_HELD}" "${_UBC_MAX_HELD}"
fi
done
# add vzubc output to stdout log
print "==== ${_VZUBC_BIN} ${_VZUBC_OPTS} ${_CT_ID} ====" >>${HC_STDOUT_LOG}
print "${_UBC_OUTPUT}" >>${HC_STDOUT_LOG}
done
return ${_RC}
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with formatted stanzas:
ct:<ct_id>
PURPOSE : Checks whether UBC (User Bean Counters) for an OpenVZ containers have
increased (failures)
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+234
View File
@@ -0,0 +1,234 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_linux_vz_ct_status.sh
#******************************************************************************
# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_linux_vz_ct_status
# DOES: see _show_usage()
# EXPECTS: see _show_usage()
# REQUIRES: data_comma2space(), data_is_numeric(), data_lc(), dump_logs(),
# init_hc(), log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2017-04-01: initial version [Patrick Van der Veken]
# @(#) 2017-05-07: made checks more detailed for hc_log() [Patrick Van der Veken]
# @(#) 2017-06-08: return 1 on error [Patrick Van der Veken]
# @(#) 2018-04-30: fixes on variable names Patrick Van der Veken]
# @(#) 2018-05-20: added dump_logs() [Patrick Van der Veken]
# @(#) 2018-05-21: STDERR fixes [Patrick Van der Veken]
# @(#) 2018-10-28: fixed (linter) errors [Patrick Van der Veken]
# @(#) 2019-01-24: arguments fix [Patrick Van der Veken]
# @(#) 2019-02-08: added support for log_healthy + fixes [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_linux_vz_ct_status
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _VZLIST_BIN="/usr/sbin/vzlist"
typeset _VZLIST_OPTS="-a -H -o ctid,status,onboot"
typeset _VERSION="2019-02-08" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _CFG_HEALTHY=""
typeset _LOG_HEALTHY=0
typeset _LINE_COUNT=1
typeset _CT_ENTRY=""
typeset _CT_ID=""
typeset _CT_CFG_STATUS=""
typeset _CT_RUN_STATUS=""
typeset _CT_CFG_BOOT=""
typeset _CT_RUN_BOOT=""
typeset _CT_ENTRY=""
typeset _CT_MATCH=""
typeset _RC=0
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
esac
done
# handle configuration file
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
if [[ ! -r ${_CONFIG_FILE} ]]
then
warn "unable to read configuration file at ${_CONFIG_FILE}"
return 1
fi
# read configuration values
_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 openvz
if [[ ! -x ${_VZLIST_BIN} || -z "${_VZLIST_BIN}" ]]
then
warn "OpenVZ is not installed here"
return 1
fi
# get container stati
${_VZLIST_BIN} ${_VZLIST_OPTS} >${HC_STDOUT_LOG} 2>${HC_STDERR_LOG}
(( $? > 0 )) && {
_MSG="unable to run command {${_VZLIST_BIN} ${_VZLIST_OPTS}}"
log_hc "$0" 1 "${_MSG}"
# dump debug info
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
return 0
}
# check configuration values
grep -E -e '^ct:' ${_CONFIG_FILE} 2>/dev/null | cut -f2- -d':' 2>/dev/null |\
while read -r _CT_ENTRY
do
# field split
_CT_ID=$(print "${_CT_ENTRY}" | cut -f1 -d':' 2>/dev/null)
_CT_CFG_STATUS=$(data_lc "$(print ${_CT_ENTRY} | cut -f2 -d':' 2>/dev/null)")
_CT_CFG_BOOT=$(data_lc "$(print ${_CT_ENTRY} | cut -f3 -d':' 2>/dev/null)")
# check config
data_is_numeric "${_CT_ID}"
if (( $? > 0 ))
then
warn "invalid container ID '${_CT_ID}' in configuration file ${_CONFIG_FILE} at data line ${_LINE_COUNT}"
continue
fi
case "${_CT_CFG_STATUS}" in
running|stopped)
;;
*)
warn "invalid container status '${_CT_CFG_STATUS}' in configuration file ${_CONFIG_FILE} at data line ${_LINE_COUNT}"
continue
;;
esac
case "${_CT_CFG_BOOT}" in
yes|no)
;;
*)
warn "invalid container boot value '${_CT_CFG_BOOT}' in configuration file ${_CONFIG_FILE} at data line ${_LINE_COUNT}"
continue
;;
esac
_LINE_COUNT=$(( _LINE_COUNT + 1 ))
done
# perform checks
grep -E -e '^ct:' ${_CONFIG_FILE} 2>/dev/null | cut -f2- -d':' 2>/dev/null |\
while read -r _CT_ENTRY
do
# field split
_CT_ID=$(print "${_CT_ENTRY}" | cut -f1 -d':' 2>/dev/null)
_CT_CFG_STATUS=$(data_lc "$(print ${_CT_ENTRY} | cut -f2 -d':' 2>/dev/null)")
_CT_CFG_BOOT=$(data_lc "$(print ${_CT_ENTRY} | cut -f3 -d':' 2>/dev/null)")
# check run-time values
_CT_MATCH=$(grep -i "^[[:space:]]*${_CT_ID}" ${HC_STDOUT_LOG} 2>/dev/null)
if [[ -n "${_CT_MATCH}" ]]
then
# field split
_CT_RUN_STATUS=$(data_lc "$(print ${_CT_MATCH} | awk '{print $2}' 2>/dev/null)")
_CT_RUN_BOOT=$(data_lc "$(print ${_CT_MATCH} | awk '{print $3}' 2>/dev/null)")
if [[ "${_CT_RUN_STATUS}" = "${_CT_CFG_STATUS}" ]]
then
_MSG="container ${_CT_ID} has a correct status [${_CT_RUN_STATUS}]"
_STC=0
else
_MSG="container ${_CT_ID} has a wrong status [${_CT_RUN_STATUS}]"
_STC=1
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}" "${_CT_RUN_STATUS}" "${_CT_CFG_STATUS}"
fi
if [[ "${_CT_RUN_BOOT}" = "${_CT_CFG_BOOT}" ]]
then
_MSG="container ${_CT_ID} has a correct boot flag [${_CT_RUN_BOOT}]"
_STC=0
else
_MSG="container ${_CT_ID} has a wrong boot flag [${_CT_RUN_BOOT}]"
_STC=1
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}" "${_CT_RUN_BOOT}" "${_CT_CFG_BOOT}"
fi
else
warn "could not determine status for container ${_CT_ID} from command output {${_VZLIST_BIN} ${_VZLIST_OPTS}}"
_RC=$(( _RC + 1 ))
fi
done
return ${_RC}
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with:
ct:<ctid>:<runtime_status>:<boot_status>
PURPOSE : Checks whether OpenVZ containers are running or not
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************
+148
View File
@@ -0,0 +1,148 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_linux_winbind_status.sh
#******************************************************************************
# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_linux_winbind_status
# DOES: see _show_usage()
# EXPECTS: n/a
# REQUIRES: data_comma2space(), linux_get_init(), init_hc(), log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2013-05-17: initial version [Patrick Van der Veken]
# @(#) 2016-12-01: added systemd code [Patrick Van der Veken]
# @(#) 2017-05-08: fix fall-back for sysv->pgrep [Patrick Van der Veken]
# @(#) 2018-05-21: STDERR fixes [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!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_linux_winbind_status
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _WINBIND_INIT_SCRIPT="/etc/init.d/winbind"
typeset _WINBIND_SYSTEMD_SERVICE="winbind.service"
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _LOG_HEALTHY=0
typeset _RC=0
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
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
# 1) try using the init ways
linux_get_init
case "${LINUX_INIT}" in
'systemd')
systemctl --quiet is-active ${_WINBIND_SYSTEMD_SERVICE} 2>>${HC_STDERR_LOG} || _STC=1
;;
'upstart')
warn "code for upstart managed systems not implemented, NOOP"
return 1
;;
'sysv')
if [[ -x ${_WINBIND_INIT_SCRIPT} ]]
then
if (( $(${_WINBIND_INIT_SCRIPT} status 2>>${HC_STDERR_LOG} | grep -c -i 'running' 2>/dev/null) == 0 ))
then
_STC=1
fi
else
warn "sysv init script not found {${_WINBIND_INIT_SCRIPT}}"
_RC=1
fi
;;
*)
_RC=1
;;
esac
# 2) try the pgrep way (note: old pgreps do not support '-c')
if (( _RC > 0 ))
then
(( $(pgrep -u root winbind 2>>${HC_STDERR_LOG} | wc -l 2>/dev/null) == 0 )) && _STC=1
fi
# evaluate & log results
case ${_STC} in
0)
_MSG="winbind is running"
;;
1)
_MSG="winbind is not running"
;;
*)
_MSG="could not determine status of winbind"
;;
esac
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
PURPOSE : Checks whether Winbind (AD) is running
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************