Added plugin check_linux_vz_ct_counters() + other fixes
This commit is contained in:
parent
a34288fb19
commit
281ae7e564
@ -52,6 +52,7 @@ cp ../SOURCES/lib/platform/linux/check_linux_sg_cluster_status.sh $RPM_BUILD_ROO
|
|||||||
cp ../SOURCES/lib/platform/linux/check_linux_sg_package_config.sh $RPM_BUILD_ROOT/opt/hc/lib/platform/linux/check_linux_sg_package_config.sh
|
cp ../SOURCES/lib/platform/linux/check_linux_sg_package_config.sh $RPM_BUILD_ROOT/opt/hc/lib/platform/linux/check_linux_sg_package_config.sh
|
||||||
cp ../SOURCES/lib/platform/linux/check_linux_sg_package_status.sh $RPM_BUILD_ROOT/opt/hc/lib/platform/linux/check_linux_sg_package_status.sh
|
cp ../SOURCES/lib/platform/linux/check_linux_sg_package_status.sh $RPM_BUILD_ROOT/opt/hc/lib/platform/linux/check_linux_sg_package_status.sh
|
||||||
cp ../SOURCES/lib/platform/linux/check_linux_sg_qs_status.sh $RPM_BUILD_ROOT/opt/hc/lib/platform/linux/check_linux_sg_qs_status.sh
|
cp ../SOURCES/lib/platform/linux/check_linux_sg_qs_status.sh $RPM_BUILD_ROOT/opt/hc/lib/platform/linux/check_linux_sg_qs_status.sh
|
||||||
|
cp ../SOURCES/lib/platform/linux/check_linux_vz_ct_counters.sh $RPM_BUILD_ROOT/opt/hc/lib/platform/linux/check_linux_vz_ct_counters.sh
|
||||||
cp ../SOURCES/lib/platform/linux/check_linux_vz_ct_status.sh $RPM_BUILD_ROOT/opt/hc/lib/platform/linux/check_linux_vz_ct_status.sh
|
cp ../SOURCES/lib/platform/linux/check_linux_vz_ct_status.sh $RPM_BUILD_ROOT/opt/hc/lib/platform/linux/check_linux_vz_ct_status.sh
|
||||||
install -d -m 755 $RPM_BUILD_ROOT/etc/opt/hc
|
install -d -m 755 $RPM_BUILD_ROOT/etc/opt/hc
|
||||||
cp ../SOURCES/etc/check_linux_burp_backup.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/check_linux_burp_backup.conf.dist
|
cp ../SOURCES/etc/check_linux_burp_backup.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/check_linux_burp_backup.conf.dist
|
||||||
@ -69,6 +70,7 @@ cp ../SOURCES/etc/check_linux_sg_cluster_config.conf.dist $RPM_BUILD_ROOT/etc/op
|
|||||||
cp ../SOURCES/etc/check_linux_sg_cluster_status.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/check_linux_sg_cluster_status.conf.dist
|
cp ../SOURCES/etc/check_linux_sg_cluster_status.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/check_linux_sg_cluster_status.conf.dist
|
||||||
cp ../SOURCES/etc/check_linux_sg_package_config.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/check_linux_sg_package_config.conf.dist
|
cp ../SOURCES/etc/check_linux_sg_package_config.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/check_linux_sg_package_config.conf.dist
|
||||||
cp ../SOURCES/etc/check_linux_sg_package_status.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/check_linux_sg_package_status.conf.dist
|
cp ../SOURCES/etc/check_linux_sg_package_status.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/check_linux_sg_package_status.conf.dist
|
||||||
|
cp ../SOURCES/etc/check_linux_vz_ct_counters.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/check_linux_vz_ct_counters.conf.dist
|
||||||
cp ../SOURCES/etc/check_linux_vz_ct_status.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/check_linux_vz_ct_status.conf.dist
|
cp ../SOURCES/etc/check_linux_vz_ct_status.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/check_linux_vz_ct_status.conf.dist
|
||||||
install -d -m 755 $RPM_BUILD_ROOT/etc/opt/hc/core
|
install -d -m 755 $RPM_BUILD_ROOT/etc/opt/hc/core
|
||||||
install -d -m 755 $RPM_BUILD_ROOT/etc/opt/hc/core/templates
|
install -d -m 755 $RPM_BUILD_ROOT/etc/opt/hc/core/templates
|
||||||
@ -135,6 +137,7 @@ echo "INFO: finished post-uninstall script"
|
|||||||
%attr(755, root, root) /opt/hc/lib/platform/linux/check_linux_sg_package_config.sh
|
%attr(755, root, root) /opt/hc/lib/platform/linux/check_linux_sg_package_config.sh
|
||||||
%attr(755, root, root) /opt/hc/lib/platform/linux/check_linux_sg_package_status.sh
|
%attr(755, root, root) /opt/hc/lib/platform/linux/check_linux_sg_package_status.sh
|
||||||
%attr(755, root, root) /opt/hc/lib/platform/linux/check_linux_sg_qs_status.sh
|
%attr(755, root, root) /opt/hc/lib/platform/linux/check_linux_sg_qs_status.sh
|
||||||
|
%attr(755, root, root) /opt/hc/lib/platform/linux/check_linux_vz_ct_counters.sh
|
||||||
%attr(755, root, root) /opt/hc/lib/platform/linux/check_linux_vz_ct_status.sh
|
%attr(755, root, root) /opt/hc/lib/platform/linux/check_linux_vz_ct_status.sh
|
||||||
%dir /etc/opt/hc
|
%dir /etc/opt/hc
|
||||||
%attr(644, root, root) /etc/opt/hc/check_linux_burp_backup.conf.dist
|
%attr(644, root, root) /etc/opt/hc/check_linux_burp_backup.conf.dist
|
||||||
@ -152,6 +155,7 @@ echo "INFO: finished post-uninstall script"
|
|||||||
%attr(644, root, root) /etc/opt/hc/check_linux_sg_cluster_status.conf.dist
|
%attr(644, root, root) /etc/opt/hc/check_linux_sg_cluster_status.conf.dist
|
||||||
%attr(644, root, root) /etc/opt/hc/check_linux_sg_package_config.conf.dist
|
%attr(644, root, root) /etc/opt/hc/check_linux_sg_package_config.conf.dist
|
||||||
%attr(644, root, root) /etc/opt/hc/check_linux_sg_package_status.conf.dist
|
%attr(644, root, root) /etc/opt/hc/check_linux_sg_package_status.conf.dist
|
||||||
|
%attr(644, root, root) /etc/opt/hc/check_linux_vz_ct_counters.conf.dist
|
||||||
%attr(644, root, root) /etc/opt/hc/check_linux_vz_ct_status.conf.dist
|
%attr(644, root, root) /etc/opt/hc/check_linux_vz_ct_status.conf.dist
|
||||||
%dir /etc/opt/hc/core
|
%dir /etc/opt/hc/core
|
||||||
%dir /etc/opt/hc/core/templates
|
%dir /etc/opt/hc/core/templates
|
||||||
@ -159,6 +163,8 @@ echo "INFO: finished post-uninstall script"
|
|||||||
%attr(644, root, root) /etc/opt/hc/core/templates/mail_body.tpl-check_linux_root_crontab
|
%attr(644, root, root) /etc/opt/hc/core/templates/mail_body.tpl-check_linux_root_crontab
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Thu Feb 07 2019 <patrick@kudos.be> - 0.1.3
|
||||||
|
- Added check_linux_vz_ct_counters
|
||||||
* Tue Jan 22 2019 <patrick@kudos.be> - 0.1.2
|
* Tue Jan 22 2019 <patrick@kudos.be> - 0.1.2
|
||||||
- Added check_linux_fs_usage
|
- Added check_linux_fs_usage
|
||||||
* Tue Jul 10 2018 <patrick@kudos.be> - 0.1.1
|
* Tue Jul 10 2018 <patrick@kudos.be> - 0.1.1
|
||||||
|
22
configs/etc/check_linux_vz_ct_counters.conf.dist
Normal file
22
configs/etc/check_linux_vz_ct_counters.conf.dist
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#******************************************************************************
|
||||||
|
# @(#) check_linux_vz_ct_counters.conf
|
||||||
|
#******************************************************************************
|
||||||
|
# This is a configuration file for the check_linux_vz_ct_counters HC plugin.
|
||||||
|
# All lines starting with a '#' are comment lines.
|
||||||
|
# [default: indicates hardcoded script values if no value is defined here]
|
||||||
|
#******************************************************************************
|
||||||
|
|
||||||
|
# specify whether to also log passed health checks
|
||||||
|
# (warning: this may rapidly grow the HC log)
|
||||||
|
# [default: no]
|
||||||
|
log_healthy="yes"
|
||||||
|
|
||||||
|
# specify containers for which to check the UBC
|
||||||
|
# Format:
|
||||||
|
# [ct:<ct_id>]
|
||||||
|
# Examples:
|
||||||
|
# ct:100
|
||||||
|
|
||||||
|
#******************************************************************************
|
||||||
|
# End of FILE
|
||||||
|
#******************************************************************************
|
@ -6,12 +6,17 @@
|
|||||||
# [default: indicates hardcoded script values if no value is defined here]
|
# [default: indicates hardcoded script values if no value is defined here]
|
||||||
#******************************************************************************
|
#******************************************************************************
|
||||||
|
|
||||||
|
# specify whether to also log passed health checks
|
||||||
|
# (warning: this may rapidly grow the HC log)
|
||||||
|
# [default: no]
|
||||||
|
log_healthy="yes"
|
||||||
|
|
||||||
# specify properties as displayed by the 'vzlist -a -H -o ctid,status,onboot' command
|
# specify properties as displayed by the 'vzlist -a -H -o ctid,status,onboot' command
|
||||||
# [ctid;runtime_status;boot_status]
|
# [ct:<ct_id>:<runtime_status>:<boot_status>]
|
||||||
# runtime_status should be 'running' or 'stopped'
|
# runtime_status should be 'running' or 'stopped'
|
||||||
# boot_status should be 'yes' or 'no'
|
# boot_status should be 'yes' or 'no'
|
||||||
# Examples:
|
# Examples:
|
||||||
#100;running;yes
|
#ct:100:running:yes
|
||||||
|
|
||||||
|
|
||||||
#******************************************************************************
|
#******************************************************************************
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
# @(#) 2018-10-18: changed boot status [Patrick Van der Veken]
|
# @(#) 2018-10-18: changed boot status [Patrick Van der Veken]
|
||||||
# @(#) 2018-10-28: fixed (linter) errors [Patrick Van der Veken]
|
# @(#) 2018-10-28: fixed (linter) errors [Patrick Van der Veken]
|
||||||
# @(#) 2018-10-31: better result check for DRD output [Patrick Van der Veken]
|
# @(#) 2018-10-31: better result check for DRD output [Patrick Van der Veken]
|
||||||
|
# @(#) 2019-02-08: fix for mirrored boot disks [Patrick Van der Veken]
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
|
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
|
||||||
#******************************************************************************
|
#******************************************************************************
|
||||||
@ -135,7 +136,7 @@ then
|
|||||||
_ORIGINAL_DISK=$(data_strip_space "$(grep "Original Disk:" ${HC_STDOUT_LOG} 2>/dev/null | cut -f2 -d':')")
|
_ORIGINAL_DISK=$(data_strip_space "$(grep "Original Disk:" ${HC_STDOUT_LOG} 2>/dev/null | cut -f2 -d':')")
|
||||||
_CLONE_DISK=$(data_strip_space "$(grep 'Clone Disk:' ${HC_STDOUT_LOG} 2>/dev/null | cut -f2 -d':')")
|
_CLONE_DISK=$(data_strip_space "$(grep 'Clone Disk:' ${HC_STDOUT_LOG} 2>/dev/null | cut -f2 -d':')")
|
||||||
|
|
||||||
_BOOTED_DISK=$(grep "Booted Disk:" ${HC_STDOUT_LOG} 2>/dev/null | cut -f2 -d'(' | cut -f1 -d ')')
|
_BOOTED_DISK=$(grep "Booted Disk[s]*:" ${HC_STDOUT_LOG} 2>/dev/null | cut -f2 -d'(' | cut -f1 -d ')')
|
||||||
_ACTIVE_DISK=$(grep "Activated Disk:" ${HC_STDOUT_LOG} 2>/dev/null | cut -f2 -d'(' | cut -f1 -d ')')
|
_ACTIVE_DISK=$(grep "Activated Disk:" ${HC_STDOUT_LOG} 2>/dev/null | cut -f2 -d'(' | cut -f1 -d ')')
|
||||||
|
|
||||||
# check boot status: after a fresh clone -> booted == activated == original
|
# check boot status: after a fresh clone -> booted == activated == original
|
||||||
|
180
sources/lib/platform/linux/check_linux_vz_ct_counters.sh
Normal file
180
sources/lib/platform/linux/check_linux_vz_ct_counters.sh
Normal file
@ -0,0 +1,180 @@
|
|||||||
|
#!/usr/bin/env ksh
|
||||||
|
#******************************************************************************
|
||||||
|
# @(#) check_linux_vz_ct_counters.sh
|
||||||
|
#******************************************************************************
|
||||||
|
# @(#) Copyright (C) 2019 by KUDOS BVBA (info@kudos.be). All rights reserved.
|
||||||
|
#
|
||||||
|
# This program is a free software; you can redistribute it and/or modify
|
||||||
|
# it under the same terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
|
||||||
|
#******************************************************************************
|
||||||
|
#
|
||||||
|
# DOCUMENTATION (MAIN)
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
# @(#) MAIN: check_linux_vz_ct_counters
|
||||||
|
# DOES: see _show_usage()
|
||||||
|
# EXPECTS: see _show_usage()
|
||||||
|
# REQUIRES: data_comma2space(), data_is_numeric(), data_strip_space(),
|
||||||
|
# dump_logs(), init_hc(), log_hc(), warn()
|
||||||
|
#
|
||||||
|
# @(#) HISTORY:
|
||||||
|
# @(#) 2019-02-08: initial version [Patrick Van der Veken]
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
|
||||||
|
#******************************************************************************
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
function check_linux_vz_ct_counters
|
||||||
|
{
|
||||||
|
# ------------------------- CONFIGURATION starts here -------------------------
|
||||||
|
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
|
||||||
|
typeset _VZUBC_BIN="/usr/sbin/vzubc"
|
||||||
|
typeset _VZUBC_OPTS="-q -i -r"
|
||||||
|
typeset _VERSION="2019-02-08" # YYYY-MM-DD
|
||||||
|
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
|
||||||
|
# ------------------------- CONFIGURATION ends here ---------------------------
|
||||||
|
|
||||||
|
# set defaults
|
||||||
|
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
|
||||||
|
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
|
||||||
|
typeset _ARGS=$(data_comma2space "$*")
|
||||||
|
typeset _ARG=""
|
||||||
|
typeset _MSG=""
|
||||||
|
typeset _STC=0
|
||||||
|
typeset _CFG_HEALTHY=""
|
||||||
|
typeset _LOG_HEALTHY=0
|
||||||
|
typeset _CT_ID=""
|
||||||
|
typeset _UBC_OUTPUT=""
|
||||||
|
typeset _UBC_NAME=""
|
||||||
|
typeset _UBC_FAIL=""
|
||||||
|
typeset _UBC_HELD=""
|
||||||
|
typeset _UBC_MAX_HELD=""
|
||||||
|
typeset _RC=0
|
||||||
|
|
||||||
|
# handle arguments (originally comma-separated)
|
||||||
|
for _ARG in ${_ARGS}
|
||||||
|
do
|
||||||
|
case "${_ARG}" in
|
||||||
|
help)
|
||||||
|
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
# handle configuration file
|
||||||
|
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
|
||||||
|
if [[ ! -r ${_CONFIG_FILE} ]]
|
||||||
|
then
|
||||||
|
warn "unable to read configuration file at ${_CONFIG_FILE}"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
# read configuration values
|
||||||
|
_CFG_HEALTHY=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'log_healthy')
|
||||||
|
case "${_CFG_HEALTHY}" in
|
||||||
|
yes|YES|Yes)
|
||||||
|
_LOG_HEALTHY=1
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
# do not override hc_arg
|
||||||
|
(( _LOG_HEALTHY > 0 )) || _LOG_HEALTHY=0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# log_healthy
|
||||||
|
(( ARG_LOG_HEALTHY > 0 )) && _LOG_HEALTHY=1
|
||||||
|
if (( _LOG_HEALTHY > 0 ))
|
||||||
|
then
|
||||||
|
if (( ARG_LOG > 0 ))
|
||||||
|
then
|
||||||
|
log "logging/showing passed health checks"
|
||||||
|
else
|
||||||
|
log "showing passed health checks (but not logging)"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
log "not logging/showing passed health checks"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# check openvz
|
||||||
|
if [[ ! -x ${_VZUBC_BIN} || -z "${_VZUBC_BIN}" ]]
|
||||||
|
then
|
||||||
|
warn "OpenVZ is not installed here"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# check configuration values
|
||||||
|
grep -E -e '^ct:' ${_CONFIG_FILE} 2>/dev/null | cut -f2 -d':' 2>/dev/null |\
|
||||||
|
while read -r _CT_ID
|
||||||
|
do
|
||||||
|
data_is_numeric "${_CT_ID}"
|
||||||
|
if (( $? > 0 ))
|
||||||
|
then
|
||||||
|
warn "${_CT_ID} appears to be an incorrect value for CT ID"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
# get bean counters
|
||||||
|
_UBC_OUTPUT=$(${_VZUBC_BIN} ${_VZUBC_OPTS} ${_CT_ID} 2>>${HC_STDERR_LOG})
|
||||||
|
if (( $? > 0 )) || [[ -z "${_UBC_OUTPUT}" ]]
|
||||||
|
then
|
||||||
|
warn "unable to run command {${_VZUBC_BIN}}. Container ${_CT_ID} does not exist?"
|
||||||
|
# dump debug info
|
||||||
|
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
|
||||||
|
_RC=1
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
# check values (data lines start with a space)
|
||||||
|
print "${_UBC_OUTPUT}" | grep "^ " 2>/dev/null | while read -r _UBC_LINE
|
||||||
|
do
|
||||||
|
_UBC_NAME=$(data_strip_space "$(print ${_UBC_LINE} | cut -f1 -d'|' 2>/dev/null)")
|
||||||
|
_UBC_FAIL=$(data_strip_space "$(print ${_UBC_LINE} | cut -f6 -d'|' 2>/dev/null)")
|
||||||
|
_UBC_HELD=$(data_strip_space "$(print ${_UBC_LINE} | cut -f2 -d'|' 2>/dev/null | awk '{print $1}')")
|
||||||
|
_UBC_MAX_HELD=$(data_strip_space "$(print ${_UBC_LINE} | cut -f3 -d'|' 2>/dev/null | awk '{print $1}')")
|
||||||
|
|
||||||
|
if [[ -z "${_UBC_FAIL}" ]] || [[ "${_UBC_FAIL}" = '-' ]]
|
||||||
|
then
|
||||||
|
_MSG="${_UBC_NAME} for CT ${_CT_ID} is unchanged [HELD:${_UBC_HELD}/MAX_HELD:${_UBC_MAX_HELD}]"
|
||||||
|
_STC=0
|
||||||
|
else
|
||||||
|
_MSG="${_UBC_NAME} for CT ${_CT_ID} increased with ${_UBC_FAIL} [HELD:${_UBC_HELD}/MAX_HELD:${_UBC_MAX_HELD}]"
|
||||||
|
_STC=1
|
||||||
|
fi
|
||||||
|
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
|
||||||
|
then
|
||||||
|
log_hc "$0" ${_STC} "${_MSG}" "${_UBC_HELD}" "${_UBC_MAX_HELD}"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# add vzubc output to stdout log
|
||||||
|
print "==== ${_VZUBC_BIN} ${_VZUBC_OPTS} ${_CT_ID} ====" >>${HC_STDOUT_LOG}
|
||||||
|
print "${_UBC_OUTPUT}" >>${HC_STDOUT_LOG}
|
||||||
|
done
|
||||||
|
|
||||||
|
return ${_RC}
|
||||||
|
}
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
function _show_usage
|
||||||
|
{
|
||||||
|
cat <<- EOT
|
||||||
|
NAME : $1
|
||||||
|
VERSION : $2
|
||||||
|
CONFIG : $3 with formatted stanzas:
|
||||||
|
ct:<ct_id>
|
||||||
|
PURPOSE : Checks whether UBC (User Bean Counters) for an OpenVZ containers have
|
||||||
|
increased (failures)
|
||||||
|
LOG HEALTHY : Supported
|
||||||
|
|
||||||
|
EOT
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
#******************************************************************************
|
||||||
|
# END of script
|
||||||
|
#******************************************************************************
|
@ -19,7 +19,8 @@
|
|||||||
# @(#) MAIN: check_linux_vz_ct_status
|
# @(#) MAIN: check_linux_vz_ct_status
|
||||||
# DOES: see _show_usage()
|
# DOES: see _show_usage()
|
||||||
# EXPECTS: see _show_usage()
|
# EXPECTS: see _show_usage()
|
||||||
# REQUIRES: data_comma2space(), dump_logs(), init_hc(), log_hc(), warn()
|
# REQUIRES: data_comma2space(), data_is_numeric(), data_lc(), dump_logs(),
|
||||||
|
# init_hc(), log_hc(), warn()
|
||||||
#
|
#
|
||||||
# @(#) HISTORY:
|
# @(#) HISTORY:
|
||||||
# @(#) 2017-04-01: initial version [Patrick Van der Veken]
|
# @(#) 2017-04-01: initial version [Patrick Van der Veken]
|
||||||
@ -30,6 +31,7 @@
|
|||||||
# @(#) 2018-05-21: STDERR fixes [Patrick Van der Veken]
|
# @(#) 2018-05-21: STDERR fixes [Patrick Van der Veken]
|
||||||
# @(#) 2018-10-28: fixed (linter) errors [Patrick Van der Veken]
|
# @(#) 2018-10-28: fixed (linter) errors [Patrick Van der Veken]
|
||||||
# @(#) 2019-01-24: arguments fix [Patrick Van der Veken]
|
# @(#) 2019-01-24: arguments fix [Patrick Van der Veken]
|
||||||
|
# @(#) 2019-02-08: added support for log_healthy + fixes [Patrick Van der Veken]
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
|
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
|
||||||
#******************************************************************************
|
#******************************************************************************
|
||||||
@ -40,7 +42,8 @@ function check_linux_vz_ct_status
|
|||||||
# ------------------------- CONFIGURATION starts here -------------------------
|
# ------------------------- CONFIGURATION starts here -------------------------
|
||||||
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
|
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
|
||||||
typeset _VZLIST_BIN="/usr/sbin/vzlist"
|
typeset _VZLIST_BIN="/usr/sbin/vzlist"
|
||||||
typeset _VERSION="2019-01-24" # YYYY-MM-DD
|
typeset _VZLIST_OPTS="-a -H -o ctid,status,onboot"
|
||||||
|
typeset _VERSION="2019-02-08" # YYYY-MM-DD
|
||||||
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
|
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
|
||||||
# ------------------------- CONFIGURATION ends here ---------------------------
|
# ------------------------- CONFIGURATION ends here ---------------------------
|
||||||
|
|
||||||
@ -49,6 +52,10 @@ typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
|
|||||||
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
|
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
|
||||||
typeset _ARGS=$(data_comma2space "$*")
|
typeset _ARGS=$(data_comma2space "$*")
|
||||||
typeset _ARG=""
|
typeset _ARG=""
|
||||||
|
typeset _MSG=""
|
||||||
|
typeset _STC=0
|
||||||
|
typeset _CFG_HEALTHY=""
|
||||||
|
typeset _LOG_HEALTHY=0
|
||||||
typeset _LINE_COUNT=1
|
typeset _LINE_COUNT=1
|
||||||
typeset _CT_ENTRY=""
|
typeset _CT_ENTRY=""
|
||||||
typeset _CT_ID=""
|
typeset _CT_ID=""
|
||||||
@ -58,8 +65,6 @@ typeset _CT_CFG_BOOT=""
|
|||||||
typeset _CT_RUN_BOOT=""
|
typeset _CT_RUN_BOOT=""
|
||||||
typeset _CT_ENTRY=""
|
typeset _CT_ENTRY=""
|
||||||
typeset _CT_MATCH=""
|
typeset _CT_MATCH=""
|
||||||
typeset _MSG=""
|
|
||||||
typeset _STC=0
|
|
||||||
typeset _RC=0
|
typeset _RC=0
|
||||||
|
|
||||||
# handle arguments (originally comma-separated)
|
# handle arguments (originally comma-separated)
|
||||||
@ -72,6 +77,39 @@ do
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# handle configuration file
|
||||||
|
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
|
||||||
|
if [[ ! -r ${_CONFIG_FILE} ]]
|
||||||
|
then
|
||||||
|
warn "unable to read configuration file at ${_CONFIG_FILE}"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
# read configuration values
|
||||||
|
_CFG_HEALTHY=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'log_healthy')
|
||||||
|
case "${_CFG_HEALTHY}" in
|
||||||
|
yes|YES|Yes)
|
||||||
|
_LOG_HEALTHY=1
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
# do not override hc_arg
|
||||||
|
(( _LOG_HEALTHY > 0 )) || _LOG_HEALTHY=0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# log_healthy
|
||||||
|
(( ARG_LOG_HEALTHY > 0 )) && _LOG_HEALTHY=1
|
||||||
|
if (( _LOG_HEALTHY > 0 ))
|
||||||
|
then
|
||||||
|
if (( ARG_LOG > 0 ))
|
||||||
|
then
|
||||||
|
log "logging/showing passed health checks"
|
||||||
|
else
|
||||||
|
log "showing passed health checks (but not logging)"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
log "not logging/showing passed health checks"
|
||||||
|
fi
|
||||||
|
|
||||||
# check openvz
|
# check openvz
|
||||||
if [[ ! -x ${_VZLIST_BIN} || -z "${_VZLIST_BIN}" ]]
|
if [[ ! -x ${_VZLIST_BIN} || -z "${_VZLIST_BIN}" ]]
|
||||||
then
|
then
|
||||||
@ -80,9 +118,9 @@ then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# get container stati
|
# get container stati
|
||||||
${_VZLIST_BIN} -a -H -o ctid,status,onboot >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG}
|
${_VZLIST_BIN} ${_VZLIST_OPTS} >${HC_STDOUT_LOG} 2>${HC_STDERR_LOG}
|
||||||
(( $? > 0 )) && {
|
(( $? > 0 )) && {
|
||||||
_MSG="unable to run command: {vzlist}"
|
_MSG="unable to run command {${_VZLIST_BIN} ${_VZLIST_OPTS}}"
|
||||||
log_hc "$0" 1 "${_MSG}"
|
log_hc "$0" 1 "${_MSG}"
|
||||||
# dump debug info
|
# dump debug info
|
||||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
|
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
|
||||||
@ -90,30 +128,27 @@ ${_VZLIST_BIN} -a -H -o ctid,status,onboot >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG
|
|||||||
}
|
}
|
||||||
|
|
||||||
# check configuration values
|
# check configuration values
|
||||||
grep -v -E -e '^$' -e '^#' ${_CONFIG_FILE} 2>/dev/null | while read _CT_ENTRY
|
grep -E -e '^ct:' ${_CONFIG_FILE} 2>/dev/null | cut -f2- -d':' 2>/dev/null |\
|
||||||
|
while read -r _CT_ENTRY
|
||||||
do
|
do
|
||||||
# field split
|
# field split
|
||||||
_CT_ID="$(print ${_CT_ENTRY} | cut -f1 -d';')"
|
_CT_ID=$(print "${_CT_ENTRY}" | cut -f1 -d':' 2>/dev/null)
|
||||||
_CT_CFG_STATUS=$(data_lc "$(print \"${_CT_ENTRY}\" | cut -f2 -d';' 2>/dev/null)")
|
_CT_CFG_STATUS=$(data_lc "$(print ${_CT_ENTRY} | cut -f2 -d':' 2>/dev/null)")
|
||||||
_CT_CFG_BOOT=$(data_lc "$(print \"${_CT_ENTRY}\" | cut -f3 -d';' 2>/dev/null)")
|
_CT_CFG_BOOT=$(data_lc "$(print ${_CT_ENTRY} | cut -f3 -d':' 2>/dev/null)")
|
||||||
|
|
||||||
# check config
|
# check config
|
||||||
case "${_CT_ID}" in
|
data_is_numeric "${_CT_ID}"
|
||||||
+([0-9])*(.)*([0-9]))
|
if (( $? > 0 ))
|
||||||
# numeric, OK
|
then
|
||||||
;;
|
|
||||||
*)
|
|
||||||
# not numeric
|
|
||||||
warn "invalid container ID '${_CT_ID}' in configuration file ${_CONFIG_FILE} at data line ${_LINE_COUNT}"
|
warn "invalid container ID '${_CT_ID}' in configuration file ${_CONFIG_FILE} at data line ${_LINE_COUNT}"
|
||||||
return 1
|
continue
|
||||||
;;
|
fi
|
||||||
esac
|
|
||||||
case "${_CT_CFG_STATUS}" in
|
case "${_CT_CFG_STATUS}" in
|
||||||
running|stopped)
|
running|stopped)
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
warn "invalid container status '${_CT_CFG_STATUS}' in configuration file ${_CONFIG_FILE} at data line ${_LINE_COUNT}"
|
warn "invalid container status '${_CT_CFG_STATUS}' in configuration file ${_CONFIG_FILE} at data line ${_LINE_COUNT}"
|
||||||
return 1
|
continue
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
case "${_CT_CFG_BOOT}" in
|
case "${_CT_CFG_BOOT}" in
|
||||||
@ -121,28 +156,28 @@ do
|
|||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
warn "invalid container boot value '${_CT_CFG_BOOT}' in configuration file ${_CONFIG_FILE} at data line ${_LINE_COUNT}"
|
warn "invalid container boot value '${_CT_CFG_BOOT}' in configuration file ${_CONFIG_FILE} at data line ${_LINE_COUNT}"
|
||||||
return 1
|
continue
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
_LINE_COUNT=$(( _LINE_COUNT + 1 ))
|
_LINE_COUNT=$(( _LINE_COUNT + 1 ))
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
# perform checks
|
# perform checks
|
||||||
grep -v -E -e '^$' -e '^#' ${_CONFIG_FILE} 2>/dev/null | while read _CT_ENTRY
|
grep -E -e '^ct:' ${_CONFIG_FILE} 2>/dev/null | cut -f2- -d':' 2>/dev/null |\
|
||||||
|
while read -r _CT_ENTRY
|
||||||
do
|
do
|
||||||
# field split
|
# field split
|
||||||
_CT_ID="$(print ${_CT_ENTRY} | cut -f1 -d';')"
|
_CT_ID=$(print "${_CT_ENTRY}" | cut -f1 -d':' 2>/dev/null)
|
||||||
_CT_CFG_STATUS="$(print ${_CT_ENTRY} | cut -f2 -d';')"
|
_CT_CFG_STATUS=$(data_lc "$(print ${_CT_ENTRY} | cut -f2 -d':' 2>/dev/null)")
|
||||||
_CT_CFG_BOOT="$(print ${_CT_ENTRY} | cut -f3 -d';')"
|
_CT_CFG_BOOT=$(data_lc "$(print ${_CT_ENTRY} | cut -f3 -d':' 2>/dev/null)")
|
||||||
|
|
||||||
# check run-time values
|
# check run-time values
|
||||||
_CT_MATCH=$(grep -i "^[[:space:]]*${_CT_ID}" ${HC_STDOUT_LOG} 2>/dev/null)
|
_CT_MATCH=$(grep -i "^[[:space:]]*${_CT_ID}" ${HC_STDOUT_LOG} 2>/dev/null)
|
||||||
if [[ -n "${_CT_MATCH}" ]]
|
if [[ -n "${_CT_MATCH}" ]]
|
||||||
then
|
then
|
||||||
# field split
|
# field split
|
||||||
_CT_RUN_STATUS=$(data_lc "$(print \"${_CT_MATCH}\" | tr -s ' ' ';' 2>/dev/null | cut -f3 -d';' 2>/dev/null)")
|
_CT_RUN_STATUS=$(data_lc "$(print ${_CT_MATCH} | awk '{print $2}' 2>/dev/null)")
|
||||||
_CT_RUN_BOOT=$(data_lc "$(print \"${_CT_MATCH}\" | tr -s ' ' ';' 2>/dev/null | cut -f4 -d';' 2>/dev/null)")
|
_CT_RUN_BOOT=$(data_lc "$(print ${_CT_MATCH} | awk '{print $3}' 2>/dev/null)")
|
||||||
|
|
||||||
if [[ "${_CT_RUN_STATUS}" = "${_CT_CFG_STATUS}" ]]
|
if [[ "${_CT_RUN_STATUS}" = "${_CT_CFG_STATUS}" ]]
|
||||||
then
|
then
|
||||||
@ -152,7 +187,10 @@ do
|
|||||||
_MSG="container ${_CT_ID} has a wrong status [${_CT_RUN_STATUS}]"
|
_MSG="container ${_CT_ID} has a wrong status [${_CT_RUN_STATUS}]"
|
||||||
_STC=1
|
_STC=1
|
||||||
fi
|
fi
|
||||||
|
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
|
||||||
|
then
|
||||||
log_hc "$0" ${_STC} "${_MSG}" "${_CT_RUN_STATUS}" "${_CT_CFG_STATUS}"
|
log_hc "$0" ${_STC} "${_MSG}" "${_CT_RUN_STATUS}" "${_CT_CFG_STATUS}"
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ "${_CT_RUN_BOOT}" = "${_CT_CFG_BOOT}" ]]
|
if [[ "${_CT_RUN_BOOT}" = "${_CT_CFG_BOOT}" ]]
|
||||||
then
|
then
|
||||||
@ -162,10 +200,13 @@ do
|
|||||||
_MSG="container ${_CT_ID} has a wrong boot flag [${_CT_RUN_BOOT}]"
|
_MSG="container ${_CT_ID} has a wrong boot flag [${_CT_RUN_BOOT}]"
|
||||||
_STC=1
|
_STC=1
|
||||||
fi
|
fi
|
||||||
|
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
|
||||||
|
then
|
||||||
log_hc "$0" ${_STC} "${_MSG}" "${_CT_RUN_BOOT}" "${_CT_CFG_BOOT}"
|
log_hc "$0" ${_STC} "${_MSG}" "${_CT_RUN_BOOT}" "${_CT_CFG_BOOT}"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
warn "could not determine status for container ${_CT_ID} from command output {${_VZLIST_BIN}}"
|
warn "could not determine status for container ${_CT_ID} from command output {${_VZLIST_BIN} ${_VZLIST_OPTS}}"
|
||||||
_RC=1
|
_RC=$(( _RC + 1 ))
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
@ -179,8 +220,9 @@ cat <<- EOT
|
|||||||
NAME : $1
|
NAME : $1
|
||||||
VERSION : $2
|
VERSION : $2
|
||||||
CONFIG : $3 with:
|
CONFIG : $3 with:
|
||||||
<ctid>;<runtime_status>;<boot_status>
|
ct:<ctid>:<runtime_status>:<boot_status>
|
||||||
PURPOSE : Checks whether OpenVZ containers are running or not
|
PURPOSE : Checks whether OpenVZ containers are running or not
|
||||||
|
LOG HEALTHY : Supported
|
||||||
|
|
||||||
EOT
|
EOT
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user