Import
This commit is contained in:
@@ -0,0 +1,231 @@
|
||||
#!/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_space2comma(),init_hc(), log_hc(),
|
||||
# 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]
|
||||
# -----------------------------------------------------------------------------
|
||||
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
|
||||
#******************************************************************************
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
function check_linux_burp_backup
|
||||
{
|
||||
# ------------------------- CONFIGURATION starts here -------------------------
|
||||
typeset _BURP_CONFIG_FILE="/etc/burp/burp-server.conf"
|
||||
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
|
||||
typeset _VERSION="2016-12-01" # 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_space2comma "$*")
|
||||
typeset _ARG=""
|
||||
typeset _MSG=""
|
||||
typeset _STC=0
|
||||
typeset _BURP_BIN=""
|
||||
typeset _BURP_AGE=""
|
||||
typeset _BURP_CLIENT=""
|
||||
typeset _BURP_WARNINGS=""
|
||||
typeset _GNU_DATE=""
|
||||
typeset _COUNT=1
|
||||
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
|
||||
|
||||
# check for capable GNU date
|
||||
_GNU_DATE=$(date --date="1 day ago" '+%s' 2>/dev/null)
|
||||
case "${_GNU_DATE}" in
|
||||
+([0-9])*(.)*([0-9]))
|
||||
# numeric, OK
|
||||
;;
|
||||
*)
|
||||
warn "no capable GNU date found here"
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
|
||||
# find burp
|
||||
_BURP_BIN="$(which burp 2>/dev/null)"
|
||||
if [[ ! -x ${_BURP_BIN} || -z "${_BURP_BIN}" ]]
|
||||
then
|
||||
warn "burp is not installed here"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# check for burp server
|
||||
if [[ ! -r ${_BURP_CONFIG_FILE} ]]
|
||||
then
|
||||
warn "burp server configuration file not found ($_BURP_CONFIG_FILE)"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# check backup runs of clients
|
||||
grep -v -E -e '^$' -e '^#' ${_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)}')
|
||||
# convert to UNIX seconds
|
||||
_CUR_BACKUP_TIME=$(date -d "${_BACKUP_DATE}" '+%s')
|
||||
else
|
||||
warn "no backup found for client ${_BURP_CLIENT}. Check client impersonation?"
|
||||
_COUNT=$(( _COUNT + 1 ))
|
||||
continue
|
||||
fi
|
||||
|
||||
# get backup warnings
|
||||
_BACKUP_WARNINGS="$(${_BURP_BIN} -c ${_BURP_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':')"
|
||||
if [[ -z "${_BACKUP_WARNINGS}" ]]
|
||||
then
|
||||
warn "could not get stats 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
|
||||
log_hc "$0" ${_STC} "${_MSG}"
|
||||
_COUNT=$(( _COUNT + 1 ))
|
||||
|
||||
# save STDOUT
|
||||
if (( _STC =! 0 ))
|
||||
then
|
||||
print "=== ${_BURP_CLIENT}: ${_BACKUP_RUN} ===" >>${HC_STDOUT_LOG}
|
||||
${_BURP_BIN} -c ${_BURP_CONFIG_FILE} -a S -C ${_BURP_CLIENT} -b ${_BACKUP_RUN} -z log.gz >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG}
|
||||
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:
|
||||
backup_age=<days_till_last_backup>
|
||||
PURPOSE : Checks the status and age of saved burp client backups.
|
||||
Should only berun only on a burp backup server
|
||||
|
||||
EOT
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
#******************************************************************************
|
||||
# END of script
|
||||
#******************************************************************************
|
||||
@@ -0,0 +1,126 @@
|
||||
#!/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_space2comma(), linux_get_init(), init_hc(), log_hc()
|
||||
#
|
||||
# @(#) HISTORY:
|
||||
# @(#) 2016-12-01: initial version [Patrick Van der Veken]
|
||||
# @(#) 2017-05-08: fix fall-back for sysv->pgrep [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="2017-05-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_space2comma "$*")
|
||||
typeset _ARG=""
|
||||
typeset _MSG=""
|
||||
typeset _STC=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
|
||||
|
||||
# 1) try using the init ways
|
||||
linux_get_init
|
||||
case "${LINUX_INIT}" in
|
||||
'systemd')
|
||||
systemctl --quiet is-active ${_BURP_SYSTEMD_SERVICE} || _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') == 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) == 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
|
||||
log_hc "$0" ${_STC} "${_MSG}"
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
function _show_usage
|
||||
{
|
||||
cat <<- EOT
|
||||
NAME : $1
|
||||
VERSION : $2
|
||||
CONFIG : $3
|
||||
PURPOSE : Checks whether a Burp (backup server daemon) is running
|
||||
|
||||
EOT
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
#******************************************************************************
|
||||
# END of script
|
||||
#******************************************************************************
|
||||
@@ -0,0 +1,146 @@
|
||||
#!/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: data_space2comma(), init_hc(), log_hc()
|
||||
#
|
||||
# @(#) HISTORY:
|
||||
# @(#) 2013-05-27: initial version [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="2013-05-27" # 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_space2comma "$*")
|
||||
typeset _ARG=""
|
||||
typeset _MSG=""
|
||||
typeset _STC=0
|
||||
typeset _ENTRY=""
|
||||
typeset _AGE_CHECK==""
|
||||
typeset _FILE_PATH=""
|
||||
typeset _FILE_AGE=""
|
||||
typeset _FILE_NAME=""
|
||||
typeset _FILE_DIR=""
|
||||
|
||||
# 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
|
||||
|
||||
# perform check
|
||||
grep -v -E -e '^$' -e '^#' ${_CONFIG_FILE} 2>/dev/null | while read _ENTRY
|
||||
do
|
||||
# field split
|
||||
_FILE_PATH=$(print "${_ENTRY%%;*}")
|
||||
_FILE_AGE=$(print "${_ENTRY##*;}")
|
||||
|
||||
# split file/dir
|
||||
_FILE_NAME=$(print "${_FILE_PATH##*/}")
|
||||
_FILE_DIR=$(print "${_FILE_PATH%/*}")
|
||||
|
||||
# check config
|
||||
if [ \( -z "${_FILE_PATH}" \) -a \( -z "${_FILE_AGE}" \) ]
|
||||
then
|
||||
warn "missing values in configuration file at ${_CONFIG_FILE}"
|
||||
return 1
|
||||
fi
|
||||
case "${_FILE_AGE}" in
|
||||
+([0-9])*(.)*([0-9]))
|
||||
# numeric, OK
|
||||
;;
|
||||
*)
|
||||
# not numeric
|
||||
warn "invalid file age value '${_FILE_AGE}' in configuration file at ${_CONFIG_FILE}"
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
|
||||
# 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
|
||||
|
||||
# handle unit result
|
||||
log_hc "$0" ${_STC} "${_MSG}"
|
||||
_STC=0
|
||||
done
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
function _show_usage
|
||||
{
|
||||
cat <<- EOT
|
||||
NAME : $1
|
||||
VERSION : $2
|
||||
CONFIG : $3 with:
|
||||
<file_name>;<maximum_age_in_minutes>
|
||||
PURPOSE : Checks whether given files have been changed in the last n minutes
|
||||
(requires GNU find)
|
||||
|
||||
EOT
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
#******************************************************************************
|
||||
# END of script
|
||||
#******************************************************************************
|
||||
@@ -0,0 +1,374 @@
|
||||
#!/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_space2comma(), init_hc(), log_hc(), warn(),
|
||||
# openssl (sha256 digest) OR cksum (CRC32 digest)
|
||||
#
|
||||
# @(#) HISTORY:
|
||||
# @(#) 2017-05-18: initial version [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="2017-05-18" # 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_space2comma "$*")
|
||||
typeset _ARG=""
|
||||
typeset _MSG=""
|
||||
typeset _STC=0
|
||||
typeset _STC_COUNT=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
|
||||
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
|
||||
|
||||
# check for checksum tools
|
||||
_OPENSSL_BIN="$(which openssl 2>>${HC_STDERR_LOG})"
|
||||
[[ -x ${_OPENSSL_BIN} && -n "${_OPENSSL_BIN}" ]] && _HAS_OPENSSL=1
|
||||
_CKSUM_BIN="$(which 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 _DUMMY _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 _DUMMY _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 (( _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
|
||||
log_hc "$0" ${_STC} "${_MSG}" "${_FILE_CKSUM}" "${_STATE_FILE_CKSUM}"
|
||||
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
|
||||
|
||||
# clean up temporary files
|
||||
[[ -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 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.
|
||||
|
||||
|
||||
EOT
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
#******************************************************************************
|
||||
# END of script
|
||||
#******************************************************************************
|
||||
@@ -0,0 +1,114 @@
|
||||
#!/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_space2comma(), init_hc(), log_hc()
|
||||
#
|
||||
# @(#) HISTORY:
|
||||
# @(#) 2013-05-17: initial version [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="2013-05-17" # 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_space2comma "$*")
|
||||
typeset _ARG=""
|
||||
typeset _MSG=""
|
||||
typeset _MSG=""
|
||||
typeset _STC=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
|
||||
|
||||
# collect data (mount only)
|
||||
mount >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG}
|
||||
(( $? == 0 )) || return $?
|
||||
|
||||
# check for each auto-mount configured file system (except /)
|
||||
cat /etc/fstab |\
|
||||
grep -v -E -e '^#' -e '^$' \
|
||||
-e '[ \t]*.*[ \t]+(proc|swap|sysfs|devpts|tmpfs).*' \
|
||||
-e '(floppy|cdrom)' \
|
||||
-e '[ \t]*\/[ \t]+' |\
|
||||
awk '{print $2}' |\
|
||||
while read _FS
|
||||
do
|
||||
_FS_COUNT=$(grep -c -E -e ".*on[ \t]+${_FS}[ \t]+.*" ${HC_STDOUT_LOG})
|
||||
case ${_FS_COUNT} in
|
||||
0)
|
||||
_MSG="${_FS} is not mounted"
|
||||
_STC=1
|
||||
;;
|
||||
1)
|
||||
_MSG="${_FS} is mounted"
|
||||
;;
|
||||
*)
|
||||
_MSG="${_FS} is multiple times mounted?"
|
||||
;;
|
||||
esac
|
||||
|
||||
# handle unit result
|
||||
log_hc "$0" ${_STC} "${_MSG}"
|
||||
_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
|
||||
CONFIG : $3
|
||||
PURPOSE : Checks whether file systems are mounted or not, exclude following FS types:
|
||||
proc, swap, sysfs, devpts, tmpfs, cdrom & floppy
|
||||
|
||||
EOT
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
#******************************************************************************
|
||||
# END of script
|
||||
#******************************************************************************
|
||||
@@ -0,0 +1,291 @@
|
||||
#!/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_space2comma(), init_hc(), log_hc()
|
||||
#
|
||||
# @(#) HISTORY:
|
||||
# @(#) 2013-09-09: initial version [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="2013-09-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_space2comma "$*")
|
||||
typeset _ARG=""
|
||||
typeset _MSG=""
|
||||
typeset _STC=0
|
||||
typeset _STC_COUNT=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
|
||||
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
|
||||
|
||||
# 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 ))
|
||||
# handle unit result
|
||||
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]" | while read _ACU_LINE
|
||||
do
|
||||
_SLOT_NUM="$(print ${_ACU_LINE} | cut -f6 -d' ')"
|
||||
case "${_DO_ACU_LOGL}" in
|
||||
+([0-9])*([0-9]))
|
||||
# numeric OK
|
||||
_SLOT_NUMS="${_SLOT_NUMS} ${_SLOT_NUM}"
|
||||
;;
|
||||
*)
|
||||
# non-numeric
|
||||
warn "found RAID controller at illegal slot?: ${_SLOT_NUM}"
|
||||
;;
|
||||
esac
|
||||
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 ))
|
||||
# handle unit result
|
||||
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 ))
|
||||
# handle unit result
|
||||
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 ))
|
||||
# handle unit result
|
||||
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 (( _STC_COUNT == 0 ))
|
||||
then
|
||||
_MSG="no problems detected by {${_HPACUCLI_BIN}}"
|
||||
log_hc "$0" 0 "${_MSG}"
|
||||
fi
|
||||
|
||||
# remove temporary file
|
||||
[[ -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:
|
||||
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))
|
||||
|
||||
EOT
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
#******************************************************************************
|
||||
# END of script
|
||||
#******************************************************************************
|
||||
@@ -0,0 +1,303 @@
|
||||
#!/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_space2comma(), init_hc(), log_hc()
|
||||
#
|
||||
# @(#) HISTORY:
|
||||
# @(#) 2013-09-07: initial version [Patrick Van der Veken]
|
||||
# @(#) 2017-04-06: bugfix in temperature checking [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="2017-04-06" # 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_space2comma "$*")
|
||||
typeset _ARG=""
|
||||
typeset _MSG=""
|
||||
typeset _STC=0
|
||||
typeset _STC_COUNT=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
|
||||
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
|
||||
|
||||
# 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' |\
|
||||
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 ))
|
||||
# handle unit result
|
||||
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 ))
|
||||
# handle unit result
|
||||
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 ))
|
||||
# handle unit result
|
||||
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 ))
|
||||
# handle unit result
|
||||
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' ')"
|
||||
_TEMP_VALUE="${_TEMP_FIELD%%C/*}"
|
||||
_THRES_FIELD="$(print ${_ASM_LINE} | cut -f4 -d' ')"
|
||||
_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' ')"
|
||||
_MSG="failure in 'SHOW TEMP', unit ${_TEMP_UNIT}"
|
||||
_MSG="${_MSG} has ${_TEMP_VALUE} >= ${_THRES_VALUE}"
|
||||
_STC_COUNT=$(( _STC_COUNT + 1 ))
|
||||
# handle unit result
|
||||
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 (( _STC_COUNT == 0 ))
|
||||
then
|
||||
_MSG="no problems detected by {${_HPASMCLI_BIN}}"
|
||||
log_hc "$0" 0 "${_MSG}"
|
||||
fi
|
||||
|
||||
# remove temporary file
|
||||
[[ -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:
|
||||
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))
|
||||
|
||||
EOT
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
#******************************************************************************
|
||||
# END of script
|
||||
#******************************************************************************
|
||||
@@ -0,0 +1,182 @@
|
||||
#!/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_space2comma(), init_hc(), log_hc()
|
||||
#
|
||||
# @(#) HISTORY:
|
||||
# @(#) 2017-04-22: initial version [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="2017-04-22" # 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_space2comma "$*")
|
||||
typeset _ARG=""
|
||||
typeset _MSG=""
|
||||
typeset _STC=0
|
||||
typeset _STC_COUNT=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
|
||||
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' | while read -r _SEVERITY_ENTRY
|
||||
do
|
||||
_HPLOG_SEVERITIES="${_HPLOG_SEVERITIES}(([0-9]+)\s*${_SEVERITY_ENTRY})|"
|
||||
done
|
||||
# delete last 'OR'
|
||||
_HPLOG_SEVERITIES=${_HPLOG_SEVERITIES%?}
|
||||
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}"
|
||||
return 0
|
||||
}
|
||||
|
||||
# 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 ))
|
||||
# handle unit result
|
||||
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}
|
||||
(( $? > 0 )) && {
|
||||
warn "failed to sort temporary state file"
|
||||
return 1
|
||||
}
|
||||
else
|
||||
_MSG="no new HPLOG messages found"
|
||||
fi
|
||||
log_hc "$0" ${_STC} "${_MSG}"
|
||||
|
||||
# clean up temporary files
|
||||
[[ -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:
|
||||
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))
|
||||
|
||||
EOT
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
#******************************************************************************
|
||||
# END of script
|
||||
#******************************************************************************
|
||||
@@ -0,0 +1,291 @@
|
||||
#!/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_space2comma(), init_hc(), log_hc()
|
||||
#
|
||||
# @(#) HISTORY:
|
||||
# @(#) 2016-04-01: initial version [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="2016-04-01" # 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_space2comma "$*")
|
||||
typeset _ARG=""
|
||||
typeset _MSG=""
|
||||
typeset _STC=0
|
||||
typeset _STC_COUNT=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
|
||||
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
|
||||
|
||||
# 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 ))
|
||||
# handle unit result
|
||||
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]" | while read _SSA_LINE
|
||||
do
|
||||
_SLOT_NUM="$(print ${_SSA_LINE} | cut -f6 -d' ')"
|
||||
case "${_DO_SSA_LOGL}" in
|
||||
+([0-9])*([0-9]))
|
||||
# numeric OK
|
||||
_SLOT_NUMS="${_SLOT_NUMS} ${_SLOT_NUM}"
|
||||
;;
|
||||
*)
|
||||
# non-numeric
|
||||
warn "found RAID controller at illegal slot?: ${_SLOT_NUM}"
|
||||
;;
|
||||
esac
|
||||
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 ))
|
||||
# handle unit result
|
||||
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 ))
|
||||
# handle unit result
|
||||
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 ))
|
||||
# handle unit result
|
||||
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 (( _STC_COUNT == 0 ))
|
||||
then
|
||||
_MSG="no problems detected by {${_HPSSACLI_BIN}}"
|
||||
log_hc "$0" 0 "${_MSG}"
|
||||
fi
|
||||
|
||||
# remove temporary file
|
||||
[[ -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:
|
||||
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))
|
||||
|
||||
EOT
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
#******************************************************************************
|
||||
# END of script
|
||||
#******************************************************************************
|
||||
@@ -0,0 +1,148 @@
|
||||
#!/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_space2comma(), linux_get_init(), init_hc(), log_hc()
|
||||
#
|
||||
# @(#) 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]
|
||||
# -----------------------------------------------------------------------------
|
||||
# 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="2017-05-17" # 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_space2comma "$*")
|
||||
typeset _ARG=""
|
||||
typeset _HTTPD_BIN=""
|
||||
typeset _MSG=""
|
||||
typeset _STC=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
|
||||
|
||||
# ---- process state ----
|
||||
# 1) try using the init ways
|
||||
linux_get_init
|
||||
case "${LINUX_INIT}" in
|
||||
'systemd')
|
||||
systemctl --quiet is-active ${_HTTPD_SYSTEMD_SERVICE} || _STC=1
|
||||
;;
|
||||
'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') == 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) == 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
|
||||
log_hc "$0" ${_STC} "${_MSG}"
|
||||
|
||||
# ---- config state ----
|
||||
_HTTPD_BIN="$(which 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
|
||||
log_hc "$0" ${_STC} "${_MSG}"
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
function _show_usage
|
||||
{
|
||||
cat <<- EOT
|
||||
NAME : $1
|
||||
VERSION : $2
|
||||
CONFIG : $3
|
||||
PURPOSE : Checks whether httpd (apache service) is running and whether the
|
||||
httpd configuration files are syntactically correct
|
||||
|
||||
EOT
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
#******************************************************************************
|
||||
# END of script
|
||||
#******************************************************************************
|
||||
@@ -0,0 +1,160 @@
|
||||
#!/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_space2comma(), linux_get_init(), init_hc(), log_hc()
|
||||
#
|
||||
# @(#) HISTORY:
|
||||
# @(#) 2013-12-01: initial version [Patrick Van der Veken]
|
||||
# @(#) 2017-05-08: fix fall-back for sysv->pgrep [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="2017-05-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_space2comma "$*")
|
||||
typeset _ARG=""
|
||||
typeset _MSG=""
|
||||
typeset _STC=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
|
||||
|
||||
# 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')
|
||||
systemctl --quiet is-active ${_NAMED_SYSTEMD_SERVICE} || _STC=1
|
||||
;;
|
||||
'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') == 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) == 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
|
||||
log_hc "$0" ${_STC} "${_MSG}"
|
||||
|
||||
# ---- config state ----
|
||||
_NAMED_CHECKCONF_BIN="$(which 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
|
||||
log_hc "$0" ${_STC} "${_MSG}"
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
function _show_usage
|
||||
{
|
||||
cat <<- EOT
|
||||
NAME : $1
|
||||
VERSION : $2
|
||||
CONFIG : $3
|
||||
PURPOSE : Checks whether named (BIND) is running and whether the named zone
|
||||
files are syntactically correct.
|
||||
|
||||
EOT
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
#******************************************************************************
|
||||
# END of script
|
||||
#******************************************************************************
|
||||
@@ -0,0 +1,139 @@
|
||||
#!/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_space2comma(), linux_get_init(), init_hc(), log_hc()
|
||||
#
|
||||
# @(#) 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]
|
||||
# -----------------------------------------------------------------------------
|
||||
# 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="2017-05-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_space2comma "$*")
|
||||
typeset _ARG=""
|
||||
typeset _POSTFIX_BIN=""
|
||||
typeset _MSG=""
|
||||
typeset _STC=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
|
||||
|
||||
# 1) try using the init ways
|
||||
linux_get_init
|
||||
case "${LINUX_INIT}" in
|
||||
'systemd')
|
||||
systemctl --quiet is-active ${_POSTFIX_SYSTEMD_SERVICE} || _STC=1
|
||||
;;
|
||||
'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') == 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="$(which 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') == 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
|
||||
log_hc "$0" ${_STC} "${_MSG}"
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
function _show_usage
|
||||
{
|
||||
cat <<- EOT
|
||||
NAME : $1
|
||||
VERSION : $2
|
||||
CONFIG : $3
|
||||
PURPOSE : Checks whether postfix (mail system) is running
|
||||
|
||||
EOT
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
#******************************************************************************
|
||||
# END of script
|
||||
#******************************************************************************
|
||||
@@ -0,0 +1,137 @@
|
||||
#!/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_space2comma(), init_hc(), log_hc()
|
||||
#
|
||||
# @(#) HISTORY:
|
||||
# @(#) 2013-09-19: initial version [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="2013-09-19" # 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_space2comma "$*")
|
||||
typeset _ARG=""
|
||||
typeset _MSG=""
|
||||
typeset _STC=0
|
||||
typeset _CRON_LINE=""
|
||||
typeset _CRON_ENTRY=""
|
||||
typeset _CRON_MATCH=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
|
||||
|
||||
# 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/* | while read _CRON_LINE
|
||||
do
|
||||
if [[ $(print "${_CRON_LINE}" | awk '{print $6}') == "root" ]]
|
||||
then
|
||||
print "${_CRON_LINE}" >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG}
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
# perform check
|
||||
grep -v -E -e '^$' -e '^#' ${_CONFIG_FILE} 2>/dev/null | while read _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
|
||||
|
||||
# handle unit result
|
||||
log_hc "$0" ${_STC} "${_MSG}"
|
||||
_STC=0
|
||||
done
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
function _show_usage
|
||||
{
|
||||
cat <<- EOT
|
||||
NAME : $1
|
||||
VERSION : $2
|
||||
CONFIG : $3
|
||||
PURPOSE : Checks the content of the 'root' user crontab for required entries
|
||||
|
||||
EOT
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
#******************************************************************************
|
||||
# END of script
|
||||
#******************************************************************************
|
||||
@@ -0,0 +1,145 @@
|
||||
#!/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_space2comma(), linux_get_init(), init_hc(), log_hc()
|
||||
#
|
||||
# @(#) 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]
|
||||
# -----------------------------------------------------------------------------
|
||||
# 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="2017-07-23" # 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_space2comma "$*")
|
||||
typeset _ARG=""
|
||||
typeset _MSG=""
|
||||
typeset _STC=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
|
||||
|
||||
# 1) try using the init ways
|
||||
linux_get_init
|
||||
case "${LINUX_INIT}" in
|
||||
'systemd')
|
||||
# check running NMB
|
||||
systemctl --quiet is-active ${_NMB_SYSTEMD_SERVICE} || _STC=1
|
||||
# check running SMB
|
||||
systemctl --quiet is-active ${_SMB_SYSTEMD_SERVICE} || _STC=$(( _STC + 2 ))
|
||||
;;
|
||||
'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.*') == 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.*') == 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) == 0 )) && _STC=1
|
||||
(( $(pgrep -u root smbd 2>>${HC_STDERR_LOG} | wc -l) == 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
|
||||
log_hc "$0" ${_STC} "${_MSG}"
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
function _show_usage
|
||||
{
|
||||
cat <<- EOT
|
||||
NAME : $1
|
||||
VERSION : $2
|
||||
CONFIG : $3
|
||||
PURPOSE : Checks whether SAMBA daemons are running
|
||||
|
||||
EOT
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
#******************************************************************************
|
||||
# END of script
|
||||
#******************************************************************************
|
||||
@@ -0,0 +1,191 @@
|
||||
#!/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_space2comma(), init_hc(), log_hc(), warn()
|
||||
#
|
||||
# @(#) HISTORY:
|
||||
# @(#) 2017-04-01: initial version [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="2017-04-01" # 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_space2comma "$*")
|
||||
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
|
||||
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
|
||||
|
||||
# remove working files
|
||||
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
|
||||
#******************************************************************************
|
||||
@@ -0,0 +1,135 @@
|
||||
#!/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_space2comma(), 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]
|
||||
# -----------------------------------------------------------------------------
|
||||
# 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="2017-05-07" # 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_space2comma "$*")
|
||||
typeset _ARG=""
|
||||
typeset _MSG=""
|
||||
typeset _STC=0
|
||||
typeset _SG_ENTRY=""
|
||||
typeset _SG_MATCH=""
|
||||
typeset _SG_CFG_PARAM=""
|
||||
typeset _SG_RUN_PARAM=""
|
||||
typeset _SG_CFG_VALUE=""
|
||||
typeset _SG_RUN_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
|
||||
|
||||
# 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
|
||||
|
||||
# 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 'cmviewcl'"
|
||||
log_hc "$0" 1 "${_MSG}"
|
||||
return 0
|
||||
}
|
||||
fi
|
||||
|
||||
# do cluster status checks
|
||||
# (replace ':' by '|' for cmcviewcl output)
|
||||
grep -v -E -e '^$' -e '^#' ${_CONFIG_FILE} 2>/dev/null | tr '|' ':' | while read _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
|
||||
log_hc "$0" ${_STC} "${_MSG}" "${_SG_RUN_VALUE}" "${_SG_CFG_VALUE}"
|
||||
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
|
||||
PURPOSE : Checks the status of Serviceguard cluster parameters (SG 11.16+)
|
||||
|
||||
EOT
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
#******************************************************************************
|
||||
# END of script
|
||||
#******************************************************************************
|
||||
@@ -0,0 +1,191 @@
|
||||
#!/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_space2comma(), init_hc(), log_hc(), warn()
|
||||
#
|
||||
# @(#) HISTORY:
|
||||
# @(#) 2017-04-01: initial version [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="2017-04-01" # 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_space2comma "$*")
|
||||
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
|
||||
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']' | 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
|
||||
|
||||
# remove working files
|
||||
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
|
||||
#******************************************************************************
|
||||
@@ -0,0 +1,137 @@
|
||||
#!/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_space2comma(), 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]
|
||||
# -----------------------------------------------------------------------------
|
||||
# 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="2017-05-07" # 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_space2comma "$*")
|
||||
typeset _ARG=""
|
||||
typeset _MSG=""
|
||||
typeset _STC=0
|
||||
typeset _SG_ENTRY=""
|
||||
typeset _SG_MATCH=""
|
||||
typeset _SG_PACKAGE=""
|
||||
typeset _SG_CFG_PARAM=""
|
||||
typeset _SG_RUN_PARAM=""
|
||||
typeset _SG_CFG_VALUE=""
|
||||
typeset _SG_RUN_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
|
||||
|
||||
# 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
|
||||
|
||||
# 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 'cmviewcl'"
|
||||
log_hc "$0" 1 "${_MSG}"
|
||||
return 0
|
||||
}
|
||||
fi
|
||||
|
||||
# do package status checks
|
||||
# (replace ':' by '|' for cmcviewcl output)
|
||||
grep -v -E -e '^$' -e '^#' ${_CONFIG_FILE} 2>/dev/null | tr '|' ':' | while read _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
|
||||
log_hc "$0" ${_STC} "${_MSG}" "${_SG_RUN_VALUE}" "${_SG_CFG_VALUE}"
|
||||
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
|
||||
PURPOSE : Checks the status of Serviceguard package parameters (SG 11.16+)
|
||||
|
||||
EOT
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
#******************************************************************************
|
||||
# END of script
|
||||
#******************************************************************************
|
||||
@@ -0,0 +1,113 @@
|
||||
#!/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_space2comma(), init_hc(), log_hc()
|
||||
#
|
||||
# @(#) HISTORY:
|
||||
# @(#) 2017-05-01: initial version [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="2017-05-01" # 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_space2comma "$*")
|
||||
typeset _ARG=""
|
||||
typeset _MSG=""
|
||||
typeset _STC=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
|
||||
|
||||
# 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
|
||||
log_hc "$0" ${_STC} "${_MSG}"
|
||||
|
||||
# ---- 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
|
||||
log_hc "$0" ${_STC} "${_MSG}"
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
function _show_usage
|
||||
{
|
||||
cat <<- EOT
|
||||
NAME : $1
|
||||
VERSION : $2
|
||||
CONFIG : $3
|
||||
PURPOSE : Checks whether the Serviceguard quorum server is running
|
||||
|
||||
EOT
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
#******************************************************************************
|
||||
# END of script
|
||||
#******************************************************************************
|
||||
@@ -0,0 +1,109 @@
|
||||
#!/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_space2comma(), init_hc(), log_hc()
|
||||
#
|
||||
# @(#) HISTORY:
|
||||
# @(#) 2016-12-01: initial version [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="2016-12-01" # 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_space2comma "$*")
|
||||
typeset _ARG=""
|
||||
typeset _MSG=""
|
||||
typeset _STC=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
|
||||
|
||||
|
||||
# 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
|
||||
log_hc "$0" ${_STC} "${_MSG}"
|
||||
|
||||
# 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
|
||||
log_hc "$0" ${_STC} "${_MSG}"
|
||||
else
|
||||
warn "shorewall is not installed here"
|
||||
return 1
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
function _show_usage
|
||||
{
|
||||
cat <<- EOT
|
||||
NAME : $1
|
||||
VERSION : $2
|
||||
CONFIG : $3
|
||||
PURPOSE : Checks whether shorewall (firewall) service is running and whether
|
||||
shorewall rules compile correctly
|
||||
|
||||
EOT
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
#******************************************************************************
|
||||
# END of script
|
||||
#******************************************************************************
|
||||
@@ -0,0 +1,139 @@
|
||||
#!/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_space2comma(), linux_get_init(), init_hc(), log_hc()
|
||||
#
|
||||
# @(#) 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]
|
||||
# -----------------------------------------------------------------------------
|
||||
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
|
||||
#******************************************************************************
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
function check_linux_sshd_status
|
||||
{
|
||||
# ------------------------- CONFIGURATION starts here -------------------------
|
||||
typeset _VERSION="2017-05-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_space2comma "$*")
|
||||
typeset _ARG=""
|
||||
typeset _MSG=""
|
||||
typeset _SSHD_INIT_SCRIPT=""
|
||||
typeset _SSHD_SYSTEMD_SERVICE=""
|
||||
typeset _STC=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
|
||||
|
||||
# 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')
|
||||
systemctl --quiet is-active ${_SSHD_SYSTEMD_SERVICE} || _STC=1
|
||||
;;
|
||||
'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') == 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) == 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
|
||||
log_hc "$0" ${_STC} "${_MSG}"
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
function _show_usage
|
||||
{
|
||||
cat <<- EOT
|
||||
NAME : $1
|
||||
VERSION : $2
|
||||
CONFIG : $3
|
||||
PURPOSE : Checks whether sshd (Secure Shell daemon) is running
|
||||
|
||||
EOT
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
#******************************************************************************
|
||||
# END of script
|
||||
#******************************************************************************
|
||||
@@ -0,0 +1,185 @@
|
||||
#!/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_space2comma(), 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]
|
||||
# -----------------------------------------------------------------------------
|
||||
# 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 _VERSION="2017-06-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_space2comma "$*")
|
||||
typeset _ARG=""
|
||||
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 _MSG=""
|
||||
typeset _STC=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
|
||||
|
||||
# check openvz
|
||||
if [[ ! -x ${_VZLIST_BIN} || -z "${_VZLIST_BIN}" ]]
|
||||
then
|
||||
warn "OpenVZ is not installed here"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# get container stati
|
||||
${_VZLIST_BIN} -a -H -o ctid,status,onboot >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG}
|
||||
(( $? != 0 )) && {
|
||||
_MSG="unable to run {vzlist}"
|
||||
log_hc "$0" 1 "${_MSG}"
|
||||
return 0
|
||||
}
|
||||
|
||||
# check configuration values
|
||||
grep -v -E -e '^$' -e '^#' ${_CONFIG_FILE} 2>/dev/null | while read _CT_ENTRY
|
||||
do
|
||||
# field split
|
||||
_CT_ID="$(print ${_CT_ENTRY} | cut -f1 -d';')"
|
||||
_CT_CFG_STATUS=$(data_lc $(print "${_CT_ENTRY}" | cut -f2 -d';'))
|
||||
_CT_CFG_BOOT=$(data_lc $(print "${_CT_ENTRY}" | cut -f3 -d';'))
|
||||
|
||||
# check config
|
||||
case "${_CT_ID}" in
|
||||
+([0-9])*(.)*([0-9]))
|
||||
# numeric, OK
|
||||
;;
|
||||
*)
|
||||
# not numeric
|
||||
warn "invalid container ID '${_CT_ID}' in configuration file ${_CONFIG_FILE} at data line ${_LINE_COUNT}"
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
case "${_CT_CFG_STATUS}" in
|
||||
running|stopped)
|
||||
;;
|
||||
*)
|
||||
warn "invalid container status '${_CT_CFG_STATUS}' in configuration file ${_CONFIG_FILE} at data line ${_LINE_COUNT}"
|
||||
return 1
|
||||
;;
|
||||
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}"
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
_LINE_COUNT=$(( _LINE_COUNT + 1 ))
|
||||
done
|
||||
|
||||
|
||||
# perform checks
|
||||
grep -v -E -e '^$' -e '^#' ${_CONFIG_FILE} 2>/dev/null | while read _CT_ENTRY
|
||||
do
|
||||
# field split
|
||||
_CT_ID="$(print ${_CT_ENTRY} | cut -f1 -d';')"
|
||||
_CT_CFG_STATUS="$(print ${_CT_ENTRY} | cut -f2 -d';')"
|
||||
_CT_CFG_BOOT="$(print ${_CT_ENTRY} | cut -f3 -d';')"
|
||||
|
||||
# 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}" | tr -s ' ' ';' | cut -f3 -d';'))
|
||||
_CT_RUN_BOOT=$(data_lc $(print "${_CT_MATCH}" | tr -s ' ' ';' | cut -f4 -d';'))
|
||||
|
||||
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
|
||||
log_hc "$0" ${_STC} "${_MSG}" "${_CT_RUN_STATUS}" "${_CT_CFG_STATUS}"
|
||||
|
||||
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
|
||||
log_hc "$0" ${_STC} "${_MSG}" "${_CT_RUN_BOOT}" "${_CT_CFG_BOOT}"
|
||||
else
|
||||
warn "could not determine status for container ${_CT_ID} from command output {${_VZLIST_BIN}}"
|
||||
_RC=1
|
||||
fi
|
||||
done
|
||||
|
||||
return ${_RC}
|
||||
}
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
function _show_usage
|
||||
{
|
||||
cat <<- EOT
|
||||
NAME : $1
|
||||
VERSION : $2
|
||||
CONFIG : $3 with:
|
||||
<ctid>;<runtime_status>;<boot_status>
|
||||
PURPOSE : Checks whether OpenVZ containers are running or not
|
||||
|
||||
EOT
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
#******************************************************************************
|
||||
# END of script
|
||||
#******************************************************************************
|
||||
@@ -0,0 +1,127 @@
|
||||
#!/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_space2comma(), linux_get_init(), init_hc(), log_hc()
|
||||
#
|
||||
# @(#) 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]
|
||||
# -----------------------------------------------------------------------------
|
||||
# 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="2017-05-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_space2comma "$*")
|
||||
typeset _ARG=""
|
||||
typeset _MSG=""
|
||||
typeset _STC=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
|
||||
|
||||
# 1) try using the init ways
|
||||
linux_get_init
|
||||
case "${LINUX_INIT}" in
|
||||
'systemd')
|
||||
systemctl --quiet is-active ${_WINBIND_SYSTEMD_SERVICE} || _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') == 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) == 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
|
||||
log_hc "$0" ${_STC} "${_MSG}"
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
function _show_usage
|
||||
{
|
||||
cat <<- EOT
|
||||
NAME : $1
|
||||
VERSION : $2
|
||||
CONFIG : $3
|
||||
PURPOSE : Checks whether Winbind (AD) is running
|
||||
|
||||
EOT
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
#******************************************************************************
|
||||
# END of script
|
||||
#******************************************************************************
|
||||
Reference in New Issue
Block a user