Compare commits

..

No commits in common. "master" and "20190921" have entirely different histories.

98 changed files with 924 additions and 5602 deletions

3
.github/FUNDING.yml vendored
View File

@ -1,3 +0,0 @@
# These are supported funding model platforms
github: patvdv

View File

@ -90,11 +90,6 @@ Additionally, there may be bundles for display or notification plugins, e.g.:
* hc-display-terse
* hc-notify-eif
* hc-notify-sms
* hc-notify-slack
## Configure & deploy
An Ansible role is available at: https://github.com/patvdv/kudos.check_health
## Execute (examples)
@ -142,14 +137,13 @@ An Ansible role is available at: https://github.com/patvdv/kudos.check_health
* **Alerting** on failed health checks:
```
/opt/hc/bin/check_health.sh --hc=check_hpux_root_crontab --run --notify=mail --mail-to="alert@acme.com"
/opt/hc/bin/check_health.sh --hc=check_linux_fs_usage --run --notify=slack
```
## References
### Documentation
More documentation can be found at <https://www.kudos.be/check_health/>
More documentation can be found at http://www.kudos.be/Projects/Health_checker.html
### Logo

View File

@ -32,14 +32,12 @@ Fileset
/opt/hc/lib/platform/aix/check_aix_subsystems.sh
/opt/hc/lib/platform/aix/check_aix_sysbackup.sh
/opt/hc/lib/platform/aix/check_aix_topasrec.sh
/opt/hc/lib/platform/aix/check_aix_uptime.sh
/etc/opt/hc
/etc/opt/hc/check_aix_file_age.conf.dist
/etc/opt/hc/check_aix_file_change.conf.dist
/etc/opt/hc/check_aix_root_crontab.conf.dist
/etc/opt/hc/check_aix_subsystems.conf.dist
/etc/opt/hc/check_aix_sysbackup.conf.dist
/etc/opt/hc/check_aix_uptime.conf.dist
EOROOTFiles
Relocatable: N
EOFileset

View File

@ -1 +0,0 @@
*prereq hc_aix.rte

View File

@ -1,31 +0,0 @@
Package Name: hc_notify_slack
Package VRMF: %BUILD_DATE%
Update: N
Fileset
Fileset Name: hc_notify_slack.rte
Fileset VRMF: %BUILD_DATE%
Fileset Description: Health Checker - core Slack plugin
USRLIBLPPFiles
EOUSRLIBLPPFiles
ROOTLIBLPPFiles
Post-installation Script: /export/nim/build/hc_notify_slack/scripts/hc_notify_slack.postinstall
Unpost-installation Script: /export/nim/build/hc_notify_slack/scripts/hc_notify_slack.postuninstall
EOROOTLIBLPPFiles
Bosboot required: N
License agreement acceptance required: N
Include license files in this package: N
Requisites: /export/nim/build/hc_notify_slack/hc_notify_slack.reqs
USRFiles
EOUSRFiles
ROOT Part: Y
ROOTFiles
/opt/hc/lib
/opt/hc/lib/core
/opt/hc/lib/platform/aix/notify_slack.sh
/etc/opt/hc
/etc/opt/hc/core
/etc/opt/hc/core/providers
/etc/opt/hc/core/providers/notify_slack.conf.dist
EOROOTFiles
Relocatable: N
EOFileset

View File

@ -1,51 +0,0 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) post-install script for hc_notify_slack LPP package
#******************************************************************************
# @(#) Copyright (C) 2022 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
#******************************************************************************
# ------------------------- CONFIGURATION starts here -------------------------
# location of ETC dir
HC_ETC_DIR="/etc/opt/hc"
# location of check_health.sh
HC_BIN="/opt/hc/bin/check_health.sh"
PATH="$PATH:/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin"
# ------------------------- CONFIGURATION ends here ---------------------------
print "INFO: starting post-install script ..."
# copy plugin config file from dist (if needed)
if [[ ! -f ${HC_ETC_DIR}/core/providers/notify_slack.conf ]]
then
cp -p ${HC_ETC_DIR}/core/providers/notify_slack.conf.dist ${HC_ETC_DIR}/core/providers/notify_slack.conf >/dev/null || \
{
print -u2 "ERROR: could not copy plugin config file in ${HC_ETC_DIR}/core/providers"
exit 1
}
fi
# refresh symbolic FPATH links
if [[ -x ${HC_BIN} ]]
then
${HC_BIN} --fix-symlinks || print -u2 "WARN: updating symlinks failed"
else
print -u2 "ERROR: could not locate or excute the HC main script (${HC_BIN})"
fi
print "INFO: finished post-install script"
exit 0
#******************************************************************************
# END of script
#******************************************************************************

View File

@ -1,48 +0,0 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) post-uninstall script for hc_notify_slack LPP package
#******************************************************************************
# @(#) Copyright (C) 2022 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
#******************************************************************************
# ------------------------- CONFIGURATION starts here -------------------------
# location of the HC configuration files
HC_ETC_DIR="/etc/opt/hc"
# location of check_health.sh
HC_BIN="/opt/hc/bin/check_health.sh"
PATH="$PATH:/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin"
# ------------------------- CONFIGURATION ends here ---------------------------
print "INFO: starting post-uninstall script ..."
# remove plugin configuration file (.dist only)
if [[ -d ${HC_ETC_DIR}/core/providers ]]
then
rm -f ${HC_ETC_DIR}/core/providers/notify_slack.conf.dist >/dev/null
(( $? == 0 )) || echo "WARN: could not remove plugin config file in directory ${HC_ETC_DIR}/core/providers"
fi
# refresh symbolic FPATH links
if [[ -x ${HC_BIN} ]]
then
${HC_BIN} --fix-symlinks || print -u2 "WARN: updating symlinks failed"
else
print -u2 "ERROR: could not locate or excute the HC main script (${HC_BIN})"
fi
print "INFO: finished post-uninstall script"
exit 0
#******************************************************************************
# END of script
#******************************************************************************

View File

@ -28,7 +28,6 @@ package() {
install -D -m 755 opt/hc/lib/platform/exadata/check_exadata_cell_luns.sh ${pkgdir}/opt/hc/lib/platform/exadata/check_exadata_cell_luns.sh
install -D -m 755 opt/hc/lib/platform/exadata/check_exadata_cell_megaraid.sh ${pkgdir}/opt/hc/lib/platform/exadata/check_exadata_cell_megaraid.sh
install -D -m 755 opt/hc/lib/platform/exadata/check_exadata_cell_physicaldisks.sh ${pkgdir}/opt/hc/lib/platform/exadata/check_exadata_cell_physicaldisks.sh
install -D -m 755 opt/hc/lib/platform/exadata/check_exadata_ib_status.sh ${pkgdir}/opt/hc/lib/platform/exadata/check_exadata_ib_status.sh
install -D -m 755 opt/hc/lib/platform/exadata/check_exadata_megaraid.sh ${pkgdir}/opt/hc/lib/platform/exadata/check_exadata_megaraid.sh
install -D -m 755 opt/hc/lib/platform/exadata/check_exadata_zfs_cluster.sh ${pkgdir}/opt/hc/lib/platform/exadata/check_exadata_zfs_cluster.sh
install -D -m 755 opt/hc/lib/platform/exadata/check_exadata_zfs_logs.sh ${pkgdir}/opt/hc/lib/platform/exadata/check_exadata_zfs_logs.sh

View File

@ -36,7 +36,6 @@ cp ../SOURCES/opt/hc/lib/platform/exadata/check_exadata_cell_griddisks.sh $RPM_B
cp ../SOURCES/opt/hc/lib/platform/exadata/check_exadata_cell_luns.sh $RPM_BUILD_ROOT/opt/hc/lib/platform/exadata/check_exadata_cell_luns.sh
cp ../SOURCES/opt/hc/lib/platform/exadata/check_exadata_cell_megaraid.sh $RPM_BUILD_ROOT/opt/hc/lib/platform/exadata/check_exadata_cell_megaraid.sh
cp ../SOURCES/opt/hc/lib/platform/exadata/check_exadata_cell_physicaldisks.sh $RPM_BUILD_ROOT/opt/hc/lib/platform/exadata/check_exadata_cell_physicaldisks.sh
cp ../SOURCES/opt/hc/lib/platform/exadata/check_exadata_ib_status.sh $RPM_BUILD_ROOT/opt/hc/lib/platform/exadata/check_exadata_ib_status.sh
cp ../SOURCES/opt/hc/lib/platform/exadata/check_exadata_megaraid.sh $RPM_BUILD_ROOT/opt/hc/lib/platform/exadata/check_exadata_megaraid.sh
cp ../SOURCES/opt/hc/lib/platform/exadata/check_exadata_zfs_cluster.sh $RPM_BUILD_ROOT/opt/hc/lib/platform/exadata/check_exadata_zfs_cluster.sh
cp ../SOURCES/opt/hc/lib/platform/exadata/check_exadata_zfs_logs.sh $RPM_BUILD_ROOT/opt/hc/lib/platform/exadata/check_exadata_zfs_logs.sh
@ -106,7 +105,6 @@ echo "INFO: finished post-uninstall script"
%attr(755, root, root) /opt/hc/lib/platform/exadata/check_exadata_cell_luns.sh
%attr(755, root, root) /opt/hc/lib/platform/exadata/check_exadata_cell_megaraid.sh
%attr(755, root, root) /opt/hc/lib/platform/exadata/check_exadata_cell_physicaldisks.sh
%attr(755, root, root) /opt/hc/lib/platform/exadata/check_exadata_ib_status.sh
%attr(755, root, root) /opt/hc/lib/platform/exadata/check_exadata_megaraid.sh
%attr(755, root, root) /opt/hc/lib/platform/exadata/check_exadata_zfs_cluster.sh
%attr(755, root, root) /opt/hc/lib/platform/exadata/check_exadata_zfs_logs.sh
@ -132,8 +130,6 @@ echo "INFO: finished post-uninstall script"
%changelog
* Tue Jul 07 2020 <patrick@kudos.be> - 0.5.0
- Added check_exadata_ib_status
* Fri Jul 07 2019 <patrick@kudos.be> - 0.4.0
- Added check_exadata_zfs_cluster
* Fri May 14 2019 <patrick@kudos.be> - 0.3.0

View File

@ -63,7 +63,6 @@ This is the OS/platform plugin package"
file -m 755 check_hpux_autopath.sh
file -m 755 check_hpux_cdsf_cluster.sh
file -m 755 check_hpux_cron_status.sh
file -m 755 check_hpux_defunct_processes.sh
file -m 755 check_hpux_drd_status.sh
file -m 755 check_hpux_file_age.sh
file -m 755 check_hpux_file_change.sh
@ -73,7 +72,7 @@ This is the OS/platform plugin package"
file -m 755 check_hpux_ignite_backup.sh
file -m 755 check_hpux_ioscan.sh
file -m 755 check_hpux_guid_status.sh
file -m 755 check_hpux_hpvm_vpar_status.sh
file -m 644 check_hpux_hpvm_vpar_status.sh
file -m 755 check_hpux_httpd_status.sh
file -m 755 check_hpux_kernel_params.sh
file -m 755 check_hpux_kernel_usage.sh
@ -88,7 +87,6 @@ This is the OS/platform plugin package"
file -m 755 check_hpux_sshd_status.sh
file -m 755 check_hpux_syslog.sh
file -m 755 check_hpux_syslogd_status.sh
file -m 755 check_hpux_uptime.sh
file -m 755 check_hpux_vg_minor_number.sh
end
@ -106,8 +104,6 @@ This is the OS/platform plugin package"
directory ../../../etc/opt/hc/=/etc/opt/hc
file -m 644 check_hpux_autofs.conf.dist
file -m 644 check_hpux_cron_status.conf.dist
file -m 644 check_hpux_defunct_processes.conf.dist
file -m 644 check_hpux_drd_status.conf.dist
file -m 644 check_hpux_file_age.conf.dist
file -m 644 check_hpux_file_change.conf.dist
@ -119,12 +115,11 @@ This is the OS/platform plugin package"
file -m 644 check_hpux_kernel_params.conf.dist
file -m 644 check_hpux_kernel_usage.conf.dist
file -m 644 check_hpux_ntp_status.conf.dist
file -m 644 check_hpux_ovpa_status.conf.dist
file -m 644 check_hpux_patch_version.conf.dist
file -m 755 check_hpux_ovpa_status.conf.dist
file -m 755 check_hpux_patch_version.conf.dist
file -m 644 check_hpux_root_crontab.conf.dist
file -m 644 check_hpux_sfm_status.conf.dist
file -m 644 check_hpux_syslog.conf.dist
file -m 644 check_hpux_uptime.conf.dist
end
fileset

View File

@ -1,80 +0,0 @@
# Depot definition:
depot
layout_version 1.0
# Vendor definition:
vendor
tag KUDOS
title "KUDOS BVBA - http://www.kudos.be"
end
# Bundle definitions:
bundle
tag HC-NOTIFY-SLACK
title "The Health Checker (HC) for UNIX (core SLACK plugin)"
os_name HP-UX
revision %BUILD_DATE%
architecture HP-UX_B.11_32/64
machine_type ia64*
vendor_tag KUDOS
contents HC-NOTIFY-SLACK-MAIN,r=,a=,v=
end
# Product definitions:
product
tag HC-NOTIFY-SLACK-MAIN
revision %BUILD_DATE%
category tools
category_title Tools
title "The Health Checker (HC) for UNIX (OS plugins)"
description "The Health Checker is collection of scripts (plugins)
designed to perform regular - but not intensive - health checks on
UNIX/Linux systems. It provides plugins for AIX, HP-UX and Linux as
well customer specific checks. Checks may include topics such file
system mounts, process checks, file consistency etc.
This is the core SLACK plugin package"
architecture S700/S800_HP-UX_10/HP-UX_11/IA64_HP-UX_11
machine_type 9000/7*|9000/8*|ia64*
os_name HP-UX
os_release ?.1?.*
os_version [A-Z]
directory /opt/hc
is_locatable false
is_patch false
postinstall scripts/hc_notify_slack.postinstall
postremove scripts/hc_notify_slack.postremove
# Fileset definitions:
fileset
tag core_plugins
title UX Health Checker (core SLACK plugins)
is_kernel false
is_locatable false
is_reboot false
is_sparse false
is_patch false
prerequisite HC-HPUX-MAIN
file_permissions -u 0222 -o root -g sys
directory ../../../opt/hc/lib/core=/opt/hc/lib/core
file -m 755 notify_slack.sh
end
fileset
tag config
title UX Health Checker (core SLACK plugins: configuration)
is_kernel false
is_locatable false
is_reboot false
is_sparse false
is_patch false
prerequisite HC-NOTIFY-SLACK-MAIN.core_plugins
file_permissions -u 0222 -o root -g sys
directory ../../../etc/opt/hc/core/providers=/etc/opt/hc/core/providers
file -m 644 notify_slack.conf.dist
end
end

View File

@ -1,51 +0,0 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) post-install script for HC-NOTIFY-SLACK SD package
#******************************************************************************
# @(#) Copyright (C) 2022 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
#******************************************************************************
# ------------------------- CONFIGURATION starts here -------------------------
# location of ETC dir
HC_ETC_DIR="/etc/opt/hc"
# location of check_health.sh
HC_BIN="/opt/hc/bin/check_health.sh"
PATH="$PATH:/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin"
# ------------------------- CONFIGURATION ends here ---------------------------
print "INFO: starting post-install script ..."
# copy plugin config file from dist (if needed)
if [[ ! -f ${HC_ETC_DIR}/core/providers/notify_slack.conf ]]
then
cp -p ${HC_ETC_DIR}/core/providers/notify_slack.conf.dist ${HC_ETC_DIR}/core/providers/notify_slack.conf >/dev/null || \
{
print -u2 "ERROR: could not copy plugin config file in ${HC_ETC_DIR}/core/providers"
exit 1
}
fi
# refresh symbolic FPATH links
if [[ -x ${HC_BIN} ]]
then
${HC_BIN} --fix-symlinks || print -u2 "WARN: updating symlinks failed"
else
print -u2 "ERROR: could not locate or excute the HC main script (${HC_BIN})"
fi
print "INFO: finished post-install script"
exit 0
#******************************************************************************
# END of script
#******************************************************************************

View File

@ -1,48 +0,0 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) post-remove script for HC-NOTIFY-SLACK SD package
#******************************************************************************
# @(#) Copyright (C) 2022 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
#******************************************************************************
# ------------------------- CONFIGURATION starts here -------------------------
# location of the HC configuration files
HC_ETC_DIR="/etc/opt/hc"
# location of check_health.sh
HC_BIN="/opt/hc/bin/check_health.sh"
PATH="$PATH:/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin"
# ------------------------- CONFIGURATION ends here ---------------------------
print "INFO: starting post-remove script ..."
# remove plugin configuration file (.dist only)
if [[ -d ${HC_ETC_DIR}/core/providers ]]
then
rm -f ${HC_ETC_DIR}/core/providers/notify_slack.conf.dist >/dev/null
(( $? == 0 )) || echo "WARN: could not remove plugin config file in directory ${HC_ETC_DIR}/core/providers"
fi
# refresh symbolic FPATH links
if [[ -x ${HC_BIN} ]]
then
${HC_BIN} --fix-symlinks || print -u2 "WARN: updating symlinks failed"
else
print -u2 "ERROR: could not locate or excute the HC main script (${HC_BIN})"
fi
print "INFO: finished post-remove script"
exit 0
#******************************************************************************
# END of script
#******************************************************************************

View File

@ -22,10 +22,7 @@ package() {
install -D -m 755 opt/hc/lib/platform/linux/check_linux_autofs.sh ${pkgdir}/opt/hc/lib/platform/linux/check_linux_autofs.sh
install -D -m 755 opt/hc/lib/platform/linux/check_linux_burp_backup.sh ${pkgdir}/opt/hc/lib/platform/linux/check_linux_burp_backup.sh
install -D -m 755 opt/hc/lib/platform/linux/check_linux_burp_status.sh ${pkgdir}/opt/hc/lib/platform/linux/check_linux_burp_status.sh
install -D -m 755 opt/hc/lib/platform/linux/check_linux_dovecot_status.sh ${pkgdir}/opt/hc/lib/platform/linux/check_linux_dovecot_status.sh
install -D -m 755 opt/hc/lib/platform/linux/check_linux_es_status.sh ${pkgdir}/opt/hc/lib/platform/linux/check_linux_es_status.sh
install -D -m 755 opt/hc/lib/platform/linux/check_linux_fail2ban_status.sh ${pkgdir}/opt/hc/lib/platform/linux/check_linux_fail2ban_status.sh
install -D -m 755 opt/hc/lib/platform/linux/check_linux_fetchmail_status.sh ${pkgdir}/opt/hc/lib/platform/linux/check_linux_fetchmail_status.sh
install -D -m 755 opt/hc/lib/platform/linux/check_linux_file_age.sh ${pkgdir}/opt/hc/lib/platform/linux/check_linux_file_age.sh
install -D -m 755 opt/hc/lib/platform/linux/check_linux_file_change.sh ${pkgdir}/opt/hc/lib/platform/linux/check_linux_file_change.sh
install -D -m 755 opt/hc/lib/platform/linux/check_linux_fs_mounts.sh ${pkgdir}/opt/hc/lib/platform/linux/check_linux_fs_mounts.sh
@ -45,15 +42,12 @@ package() {
install -D -m 755 opt/hc/lib/platform/linux/check_linux_hpssacli.sh ${pkgdir}/opt/hc/lib/platform/linux/check_linux_hpssacli.sh
install -D -m 755 opt/hc/lib/platform/linux/check_linux_process_limits.sh ${pkgdir}/opt/hc/lib/platform/linux/check_linux_process_limits.sh
install -D -m 755 opt/hc/lib/platform/linux/check_linux_root_crontab.sh ${pkgdir}/opt/hc/lib/platform/linux/check_linux_root_crontab.sh
install -D -m 755 opt/hc/lib/platform/linux/check_linux_uptime.sh ${pkgdir}/opt/hc/lib/platform/linux/check_linux_uptime.sh
install -D -m 755 opt/hc/lib/platform/linux/check_linux_vz_ct_counters.sh ${pkgdir}/opt/hc/lib/platform/linux/check_linux_vz_ct_counters.sh
install -D -m 755 opt/hc/lib/platform/linux/check_linux_vz_ct_status.sh ${pkgdir}/opt/hc/lib/platform/linux/check_linux_vz_ct_status.sh
install -d -m 755 ${pkgdir}/etc/opt/hc
install -D -m 644 etc/opt/hc/check_linux_autofs.conf.dist ${pkgdir}/etc/opt/hc/check_linux_autofs.conf.dist
install -D -m 644 etc/opt/hc/check_linux_burp_backup.conf.dist ${pkgdir}/etc/opt/hc/check_linux_burp_backup.conf.dist
install -D -m 644 etc/opt/hc/check_linux_es_status.conf.dist ${pkgdir}/etc/opt/hc/check_linux_es_status.conf.dist
install -D -m 644 etc/opt/hc/check_linux_fail2ban_status.conf.dist ${pkgdir}/etc/opt/hc/check_linux_fail2ban_status.conf.dist
install -D -m 644 etc/opt/hc/check_linux_fetchmail_status.conf.dist ${pkgdir}/etc/opt/hc/check_linux_fetchmail_status.conf.dist
install -D -m 644 etc/opt/hc/check_linux_file_age.conf.dist ${pkgdir}/etc/opt/hc/check_linux_file_age.conf.dist
install -D -m 644 etc/opt/hc/check_linux_file_change.conf.dist ${pkgdir}/etc/opt/hc/check_linux_file_change.conf.dist
install -D -m 644 etc/opt/hc/check_linux_fs_usage.conf.dist ${pkgdir}/etc/opt/hc/check_linux_fs_usage.conf.dist
@ -61,12 +55,10 @@ package() {
install -D -m 644 etc/opt/hc/check_linux_hpacucli.conf.dist ${pkgdir}/etc/opt/hc/check_linux_hpacucli.conf.dist
install -D -m 644 etc/opt/hc/check_linux_hplog.conf.dist ${pkgdir}/etc/opt/hc/check_linux_hplog.conf.dist
install -D -m 644 etc/opt/hc/check_linux_hpssacli.conf.dist ${pkgdir}/etc/opt/hc/check_linux_hpssacli.conf.dist
install -D -m 644 etc/opt/hc/check_linux_httpd_status.conf.dist ${pkgdir}/etc/opt/hc/check_linux_httpd_status.conf.dist
install -D -m 644 etc/opt/hc/check_linux_mysqld_status.conf.dist ${pkgdir}/etc/opt/hc/check_linux_mysqld_status.conf.dist
install -D -m 644 etc/opt/hc/check_linux_ntp_status.conf.dist ${pkgdir}/etc/opt/hc/check_linux_ntp_status.conf.dist
install -D -m 644 etc/opt/hc/check_linux_process_limits.conf.dist ${pkgdir}/etc/opt/hc/check_linux_process_limits.conf.dist
install -D -m 644 etc/opt/hc/check_linux_root_crontab.conf.dist ${pkgdir}/etc/opt/hc/check_linux_root_crontab.conf.dist
install -D -m 644 etc/opt/hc/check_linux_uptime.conf.dist ${pkgdir}/etc/opt/hc/check_linux_uptime.conf.dist
install -D -m 644 etc/opt/hc/check_linux_vz_ct_counters.conf.dist ${pkgdir}/etc/opt/hc/check_linux_vz_ct_counters.conf.dist
install -D -m 644 etc/opt/hc/check_linux_vz_ct_status.conf.dist ${pkgdir}/etc/opt/hc/check_linux_vz_ct_status.conf.dist
install -d -m 755 ${pkgdir}/etc/opt/hc/core

View File

@ -1,33 +0,0 @@
# -- post-install --
post_install() {
# ------------------------- CONFIGURATION starts here -------------------------
# location of check_health.sh
HC_BIN="/opt/hc/bin/check_health.sh"
PATH="$PATH:/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin"
# ------------------------- CONFIGURATION ends here ---------------------------
echo "INFO: starting post-install script ..."
# refresh symbolic FPATH links
if [[ -x ${HC_BIN} ]]
then
${HC_BIN} --fix-symlinks
(( $? == 0 )) || echo "WARN: updating symlinks failed"
fi
echo "INFO: finished post-install script"
}
# -- post-remove --
post_remove() {
# ------------------------- CONFIGURATION starts here -------------------------
# location of check_health.sh
HC_BIN="/opt/hc/bin/check_health.sh"
PATH="$PATH:/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin"
# ------------------------- CONFIGURATION ends here ---------------------------
echo "INFO: starting post-uninstall script ..."
# refresh symbolic FPATH links
if [[ -x ${HC_BIN} ]]
then
${HC_BIN} --fix-symlinks
(( $? == 0 )) || echo "WARN: updating symlinks failed"
fi
echo "INFO: finished post-uninstall script"
}

View File

@ -1,26 +0,0 @@
# Maintainer: Patrick Van der Veken <patrick@kudos.be>
_pkgname="check_health"
pkgname="hc-notify-slack"
pkgver="%BUILD_DATE%"
pkgrel=1
pkgdesc="The KUDOS Health Checker (HC) for UNIX (Slack notify core plugin)"
arch=("any")
url="https://github.com/patvdv/${_pkgname}"
license=('GPL3')
makedepends=('git')
depends=('hc-linux')
source=("${_pkgname}::git+${url}.git#branch=master")
install=".install"
sha256sums=('SKIP')
package() {
cd "${srcdir}/${_pkgname}"
install -d -m 755 ${pkgdir}/opt/hc/lib
install -d -m 755 ${pkgdir}/opt/hc/lib/core
install -D -m 755 opt/hc/lib/core/notify_slack.sh ${pkgdir}/opt/hc/lib/core/notify_slack.sh
install -d -m 755 ${pkgdir}/etc/opt/hc
install -d -m 755 ${pkgdir}/etc/opt/hc/core
install -d -m 755 ${pkgdir}/etc/opt/hc/core/providers
install -D -m 644 etc/opt/hc/core/providers/notify_slack.conf.dist ${pkgdir}/etc/opt/hc/core/providers/notify_slack.conf.dist
}

View File

@ -4,7 +4,7 @@ Architecture: all
Maintainer: Patrick Van der Veken <patrick@kudos.be>
Essential: no
Installed-Size: 50
Pre-Depends: hc-linux
Depends: hc-linux
Section: tools
Priority: extra
Description: The KUDOS Health Checker (HC) for UNIX (CSV display core plugin).

View File

@ -4,7 +4,7 @@ Architecture: all
Maintainer: Patrick Van der Veken <patrick@kudos.be>
Essential: no
Installed-Size: 50
Pre-Depends: hc-linux
Depends: hc-linux
Section: tools
Priority: extra
Description: The KUDOS Health Checker (HC) for UNIX (init display core plugin).

View File

@ -4,7 +4,7 @@ Architecture: all
Maintainer: Patrick Van der Veken <patrick@kudos.be>
Essential: no
Installed-Size: 50
Pre-Depends: hc-linux
Depends: hc-linux
Section: tools
Priority: extra
Description: The KUDOS Health Checker (HC) for UNIX (JSON display core plugin).

View File

@ -4,7 +4,7 @@ Architecture: all
Maintainer: Patrick Van der Veken <patrick@kudos.be>
Essential: no
Installed-Size: 50
Pre-Depends: hc-linux
Depends: hc-linux
Section: tools
Priority: extra
Description: The KUDOS Health Checker (HC) for UNIX (terse display core plugin).

View File

@ -4,7 +4,7 @@ Architecture: all
Maintainer: Patrick Van der Veken <patrick@kudos.be>
Essential: no
Installed-Size: 50
Pre-Depends: hc-linux
Depends: hc-linux
Section: tools
Priority: extra
Description: The KUDOS Health Checker (HC) for UNIX (Zenoss display core plugin).

View File

@ -4,7 +4,7 @@ Architecture: all
Maintainer: Patrick Van der Veken <patrick@kudos.be>
Essential: no
Installed-Size: 300
Pre-Depends: hc-linux
Depends: hc-linux
Section: tools
Priority: extra
Description: The KUDOS Health Checker (HC) for UNIX (platform plugins).

View File

@ -16,10 +16,8 @@ chown -R root:root /opt/hc /etc/opt/hc 2>/dev/null
chown root:root /etc/logrotate.d/check_health 2>/dev/null
chmod 644 /etc/logrotate.d/check_health 2>/dev/null
# copy configuration files
if [[ -f ${HC_ETC_DIR}/core/check_health.conf.dist ]]
if [[ ! -f ${HC_ETC_DIR}/core/check_health.conf ]]
then
if [[ ! -f ${HC_ETC_DIR}/core/check_health.conf ]]
then
# copy main configuration file
cp -p ${HC_ETC_DIR}/core/check_health.conf.dist ${HC_ETC_DIR}/core/check_health.conf >/dev/null
(( $? == 0 )) || \
@ -27,14 +25,9 @@ then
echo "ERROR: could not copy main config file in ${HC_ETC_DIR}/core"
exit 1
}
fi
else
echo "WARN: could not check_health config .dist file in ${HC_ETC_DIR}/core"
fi
if [[ -f ${HC_ETC_DIR}/check_host.conf.dist ]]
if [[ ! -f ${HC_ETC_DIR}/check_host.conf ]]
then
if [[ ! -f ${HC_ETC_DIR}/check_host.conf ]]
then
# copy host check configuration file
cp -p ${HC_ETC_DIR}/check_host.conf.dist ${HC_ETC_DIR}/check_host.conf >/dev/null
(( $? == 0 )) || \
@ -42,9 +35,6 @@ then
echo "ERROR: could not copy host check config file in ${HC_ETC_DIR}"
exit 1
}
fi
else
echo "WARN: could not find check_host config .dist file in ${HC_ETC_DIR}"
fi
# refresh symbolic FPATH links for core includes & plugins
if [[ -x ${HC_BIN} ]]

View File

@ -10,9 +10,8 @@ HC_VAR_DIR="/var/opt/hc"
echo "INFO: starting post-uninstall script ..."
if [[ -d ${HC_DIR} ]]
then
# remove all symlinks
find ${HC_DIR} -type l -exec rm -f {} \; 2>/dev/null
(( $? == 0 )) || echo "WARN: failed to remove symlinks in ${HC_DIR}"
rm -rf ${HC_DIR} 2>/dev/null
(( $? == 0 )) || echo "WARN: failed to remove ${HC_DIR}"
fi
if [[ -d ${HC_ETC_DIR} ]]
then

View File

@ -4,7 +4,7 @@ Architecture: all
Maintainer: Patrick Van der Veken <patrick@kudos.be>
Essential: no
Installed-Size: 50
Pre-Depends: hc-linux
Depends: hc-linux
Section: tools
Priority: extra
Description: The KUDOS Health Checker (HC) for UNIX (EIF notify core plugin).

View File

@ -10,19 +10,14 @@ echo "INFO: starting post-install script ..."
# debian: reset ownerships
chown -R root:root /opt/hc /etc/opt/hc 2>/dev/null
# copy plugin configuration file
if [[ -f ${HC_ETC_DIR}/core/providers/notify_eif.conf.dist ]]
if [[ ! -f ${HC_ETC_DIR}/core/providers/notify_eif.conf ]]
then
if [[ ! -f ${HC_ETC_DIR}/core/providers/notify_eif.conf ]]
then
cp -p ${HC_ETC_DIR}/core/providers/notify_eif.conf.dist ${HC_ETC_DIR}/core/providers/notify_eif.conf >/dev/null
(( $? == 0 )) || \
{
echo "ERROR: could not copy plugin config file in ${HC_ETC_DIR}/core/providers"
exit 1
}
fi
else
echo "WARN: could not find plugin config .dist file in ${HC_ETC_DIR}/core/providers"
fi
# refresh symbolic FPATH links
if [[ -x ${HC_BIN} ]]

View File

@ -1,10 +0,0 @@
Package: hc-notify-slack
Version: %BUILD_DATE%
Architecture: all
Maintainer: Patrick Van der Veken <patrick@kudos.be>
Essential: no
Installed-Size: 50
Pre-Depends: hc-linux
Section: tools
Priority: extra
Description: The KUDOS Health Checker (HC) for UNIX (Slack notify core plugin).

View File

@ -1,33 +0,0 @@
#!/bin/bash
# ------------------------- CONFIGURATION starts here -------------------------
# location of the HC configuration files
HC_ETC_DIR="/etc/opt/hc"
# location of check_health.sh
HC_BIN="/opt/hc/bin/check_health.sh"
PATH="$PATH:/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin"
# ------------------------- CONFIGURATION ends here ---------------------------
echo "INFO: starting post-install script ..."
# debian: reset ownerships
chown -R root:root /opt/hc /etc/opt/hc 2>/dev/null
# copy plugin configuration file
if [[ -f ${HC_ETC_DIR}/core/providers/notify_slack.conf.dist ]]
then
if [[ ! -f ${HC_ETC_DIR}/core/providers/notify_slack.conf ]]
then
cp -p ${HC_ETC_DIR}/core/providers/notify_slack.conf.dist ${HC_ETC_DIR}/core/providers/notify_slack.conf >/dev/null
(( $? == 0 )) || \
{
echo "ERROR: could not copy plugin config file in ${HC_ETC_DIR}/core/providers"
exit 1
}
fi
else
echo "WARN: could not find plugin config .dist file in ${HC_ETC_DIR}/core/providers"
fi
# refresh symbolic FPATH links
if [[ -x ${HC_BIN} ]]
then
${HC_BIN} --fix-symlinks
(( $? == 0 )) || echo "WARN: updating symlinks failed"
fi
echo "INFO: finished post-install script"

View File

@ -1,32 +0,0 @@
#!/bin/bash
# ------------------------- CONFIGURATION starts here -------------------------
# location of the HC configuration files
HC_ETC_DIR="/etc/opt/hc"
# location of check_health.sh
HC_BIN="/opt/hc/bin/check_health.sh"
PATH="$PATH:/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin"
# ------------------------- CONFIGURATION ends here ---------------------------
# update or uninstall?
if (( $1 == 0 ))
then
echo "INFO: starting post-uninstall script ..."
# copy plugin configuration file (.dist only)
if [[ -d ${HC_ETC_DIR}/core/providers ]]
then
rm -f ${HC_ETC_DIR}/core/providers/notify_slack.conf.dist 2>/dev/null
(( $? == 0 )) || \
{
echo "ERROR: could not remove plugin config file in ${HC_ETC_DIR}/core/providers"
exit 1
}
fi
else
echo "INFO: starting post-uninstall script (RPM upgrade)"
fi
# refresh symbolic FPATH links
if [[ -x ${HC_BIN} ]]
then
${HC_BIN} --fix-symlinks
(( $? == 0 )) || echo "WARN: updating symlinks failed"
fi
echo "INFO: finished post-uninstall script"

View File

@ -4,7 +4,7 @@ Architecture: all
Maintainer: Patrick Van der Veken <patrick@kudos.be>
Essential: no
Installed-Size: 50
Pre-Depends: hc-linux
Depends: hc-linux
Section: tools
Priority: extra
Description: The KUDOS Health Checker (HC) for UNIX (SMS notify core plugin).

View File

@ -10,19 +10,14 @@ echo "INFO: starting post-install script ..."
# debian: reset ownerships
chown -R root:root /opt/hc /etc/opt/hc 2>/dev/null
# copy plugin configuration file
if [[ -f ${HC_ETC_DIR}/core/providers/notify_sms.conf.dist ]]
if [[ ! -f ${HC_ETC_DIR}/core/providers/notify_sms.conf ]]
then
if [[ ! -f ${HC_ETC_DIR}/core/providers/notify_sms.conf ]]
then
cp -p ${HC_ETC_DIR}/core/providers/notify_sms.conf.dist ${HC_ETC_DIR}/core/providers/notify_sms.conf >/dev/null
(( $? == 0 )) || \
{
echo "ERROR: could not copy plugin config file in ${HC_ETC_DIR}/core/providers"
exit 1
}
fi
else
echo "WARN: could not find plugin config .dist file in ${HC_ETC_DIR}/core/providers"
fi
# refresh symbolic FPATH links
if [[ -x ${HC_BIN} ]]

View File

@ -30,10 +30,7 @@ install -d -m 755 $RPM_BUILD_ROOT/opt/hc/lib/platform/linux
cp ../SOURCES/opt/hc/lib/platform/linux/check_linux_autofs.sh $RPM_BUILD_ROOT/opt/hc/lib/platform/linux/check_linux_autofs.sh
cp ../SOURCES/opt/hc/lib/platform/linux/check_linux_burp_backup.sh $RPM_BUILD_ROOT/opt/hc/lib/platform/linux/check_linux_burp_backup.sh
cp ../SOURCES/opt/hc/lib/platform/linux/check_linux_burp_status.sh $RPM_BUILD_ROOT/opt/hc/lib/platform/linux/check_linux_burp_status.sh
cp ../SOURCES/opt/hc/lib/platform/linux/check_linux_dovecot_status.sh $RPM_BUILD_ROOT/opt/hc/lib/platform/linux/check_linux_dovecot_status.sh
cp ../SOURCES/opt/hc/lib/platform/linux/check_linux_es_status.sh $RPM_BUILD_ROOT/opt/hc/lib/platform/linux/check_linux_es_status.sh
cp ../SOURCES/opt/hc/lib/platform/linux/check_linux_fail2ban_status.sh $RPM_BUILD_ROOT/opt/hc/lib/platform/linux/check_linux_fail2ban_status.sh
cp ../SOURCES/opt/hc/lib/platform/linux/check_linux_fetchmail_status.sh $RPM_BUILD_ROOT/opt/hc/lib/platform/linux/check_linux_fetchmail_status.sh
cp ../SOURCES/opt/hc/lib/platform/linux/check_linux_file_age.sh $RPM_BUILD_ROOT/opt/hc/lib/platform/linux/check_linux_file_age.sh
cp ../SOURCES/opt/hc/lib/platform/linux/check_linux_file_change.sh $RPM_BUILD_ROOT/opt/hc/lib/platform/linux/check_linux_file_change.sh
cp ../SOURCES/opt/hc/lib/platform/linux/check_linux_fs_mounts.sh $RPM_BUILD_ROOT/opt/hc/lib/platform/linux/check_linux_fs_mounts.sh
@ -53,15 +50,12 @@ cp ../SOURCES/opt/hc/lib/platform/linux/check_linux_hplog.sh $RPM_BUILD_ROOT/opt
cp ../SOURCES/opt/hc/lib/platform/linux/check_linux_hpssacli.sh $RPM_BUILD_ROOT/opt/hc/lib/platform/linux/check_linux_hpssacli.sh
cp ../SOURCES/opt/hc/lib/platform/linux/check_linux_process_limits.sh $RPM_BUILD_ROOT/opt/hc/lib/platform/linux/check_linux_process_limits.sh
cp ../SOURCES/opt/hc/lib/platform/linux/check_linux_root_crontab.sh $RPM_BUILD_ROOT/opt/hc/lib/platform/linux/check_linux_root_crontab.sh
cp ../SOURCES/opt/hc/lib/platform/linux/check_linux_uptime.sh $RPM_BUILD_ROOT/opt/hc/lib/platform/linux/check_linux_uptime.sh
cp ../SOURCES/opt/hc/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/opt/hc/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
cp ../SOURCES/etc/opt/hc/check_linux_autofs.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/check_linux_autofs.conf.dist
cp ../SOURCES/etc/opt/hc/check_linux_burp_backup.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/check_linux_burp_backup.conf.dist
cp ../SOURCES/etc/opt/hc/check_linux_es_status.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/check_linux_es_status.conf.dist
cp ../SOURCES/etc/opt/hc/check_linux_fail2ban_status.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/check_linux_fail2ban_status.conf.dist
cp ../SOURCES/etc/opt/hc/check_linux_fetchmail_status.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/check_linux_fetchmail_status.conf.dist
cp ../SOURCES/etc/opt/hc/check_linux_file_age.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/check_linux_file_age.conf.dist
cp ../SOURCES/etc/opt/hc/check_linux_file_change.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/check_linux_file_change.conf.dist
cp ../SOURCES/etc/opt/hc/check_linux_fs_usage.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/check_linux_fs_usage.conf.dist
@ -69,12 +63,10 @@ cp ../SOURCES/etc/opt/hc/check_linux_hpasmcli.conf.dist $RPM_BUILD_ROOT/etc/opt/
cp ../SOURCES/etc/opt/hc/check_linux_hpacucli.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/check_linux_hpacucli.conf.dist
cp ../SOURCES/etc/opt/hc/check_linux_hplog.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/check_linux_hplog.conf.dist
cp ../SOURCES/etc/opt/hc/check_linux_hpssacli.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/check_linux_hpssacli.conf.dist
cp ../SOURCES/etc/opt/hc/check_linux_httpd_status.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/check_linux_httpd_status.conf.dist
cp ../SOURCES/etc/opt/hc/check_linux_mysqld_status.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/check_linux_mysqld_status.conf.dist
cp ../SOURCES/etc/opt/hc/check_linux_ntp_status.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/check_linux_ntp_status.conf.dist
cp ../SOURCES/etc/opt/hc/check_linux_process_limits.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/check_linux_process_limits.conf.dist
cp ../SOURCES/etc/opt/hc/check_linux_root_crontab.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/check_linux_root_crontab.conf.dist
cp ../SOURCES/etc/opt/hc/check_linux_uptime.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/check_linux_uptime.conf.dist
cp ../SOURCES/etc/opt/hc/check_linux_vz_ct_counters.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/check_linux_vz_ct_counters.conf.dist
cp ../SOURCES/etc/opt/hc/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
@ -120,10 +112,7 @@ echo "INFO: finished post-uninstall script"
%attr(755, root, root) /opt/hc/lib/platform/linux/check_linux_autofs.sh
%attr(755, root, root) /opt/hc/lib/platform/linux/check_linux_burp_backup.sh
%attr(755, root, root) /opt/hc/lib/platform/linux/check_linux_burp_status.sh
%attr(755, root, root) /opt/hc/lib/platform/linux/check_linux_dovecot_status.sh
%attr(755, root, root) /opt/hc/lib/platform/linux/check_linux_es_status.sh
%attr(755, root, root) /opt/hc/lib/platform/linux/check_linux_fail2ban_status.sh
%attr(755, root, root) /opt/hc/lib/platform/linux/check_linux_fetchmail_status.sh
%attr(755, root, root) /opt/hc/lib/platform/linux/check_linux_file_age.sh
%attr(755, root, root) /opt/hc/lib/platform/linux/check_linux_file_change.sh
%attr(755, root, root) /opt/hc/lib/platform/linux/check_linux_fs_mounts.sh
@ -143,15 +132,12 @@ echo "INFO: finished post-uninstall script"
%attr(755, root, root) /opt/hc/lib/platform/linux/check_linux_hpssacli.sh
%attr(755, root, root) /opt/hc/lib/platform/linux/check_linux_process_limits.sh
%attr(755, root, root) /opt/hc/lib/platform/linux/check_linux_root_crontab.sh
%attr(755, root, root) /opt/hc/lib/platform/linux/check_linux_uptime.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
%dir /etc/opt/hc
%attr(644, root, root) /etc/opt/hc/check_linux_autofs.conf.dist
%attr(644, root, root) /etc/opt/hc/check_linux_burp_backup.conf.dist
%attr(644, root, root) /etc/opt/hc/check_linux_es_status.conf.dist
%attr(644, root, root) /etc/opt/hc/check_linux_fail2ban_status.conf.dist
%attr(644, root, root) /etc/opt/hc/check_linux_fetchmail_status.conf.dist
%attr(644, root, root) /etc/opt/hc/check_linux_file_age.conf.dist
%attr(644, root, root) /etc/opt/hc/check_linux_file_change.conf.dist
%attr(644, root, root) /etc/opt/hc/check_linux_fs_usage.conf.dist
@ -159,12 +145,10 @@ echo "INFO: finished post-uninstall script"
%attr(644, root, root) /etc/opt/hc/check_linux_hpacucli.conf.dist
%attr(644, root, root) /etc/opt/hc/check_linux_hplog.conf.dist
%attr(644, root, root) /etc/opt/hc/check_linux_hpssacli.conf.dist
%attr(644, root, root) /etc/opt/hc/check_linux_httpd_status.conf.dist
%attr(644, root, root) /etc/opt/hc/check_linux_mysqld_status.conf.dist
%attr(644, root, root) /etc/opt/hc/check_linux_ntp_status.conf.dist
%attr(644, root, root) /etc/opt/hc/check_linux_process_limits.conf.dist
%attr(644, root, root) /etc/opt/hc/check_linux_root_crontab.conf.dist
%attr(644, root, root) /etc/opt/hc/check_linux_uptime.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
%dir /etc/opt/hc/core
@ -173,15 +157,6 @@ echo "INFO: finished post-uninstall script"
%attr(644, root, root) /etc/opt/hc/core/templates/mail_body.tpl-check_linux_root_crontab
%changelog
* Sat Dec 26 2020 <patrick@kudos.be> - 0.3.5
- Added check_linux_fetchmail_status plugin
- Added check_linux_dovecot_status plugin
* Mon Dec 21 2020 <patrick@kudos.be> - 0.3.4
- Added check_linux_uptime plugin
* Fri Oct 18 2020 <patrick@kudos.be> - 0.3.3
- Added check_linux_fail2ban_status plugin
* Fri Nov 1 2019 <patrick@kudos.be> - 0.3.2
- Added configuration file for check_linux_httpd_status plugin
* Sun Jul 14 2019 <patrick@kudos.be> - 0.3.1
- Removed check_linux_autofs plugin
* Sat Apr 20 2019 <patrick@kudos.be> - 0.3.0

View File

@ -1,107 +0,0 @@
%define build_timestamp %(date +"%Y%m%d")
Name: hc-notify-slack
Version: %{build_timestamp}
Release: 1
Summary: The KUDOS Health Checker (HC) for UNIX (Slack notify core plugin)
Group: Tools/Monitoring
License: GNU General Public License either version 2 of the License, or (at your option) any later version
URL: http://www.kudos.be
Requires: ksh,hc-linux
BuildArch: noarch
BuildRoot: %{_topdir}/%{name}-%{version}-root
%description
The Health Checker is collection of scripts (plugins) designed to perform regular - but not intensive - health checks on UNIX/Linux systems. It provides plugins for AIX, HP-UX and Linux as well customer specific checks. Checks may include topics such file system mounts, process checks, file consistency etc.
This package contains core plugins (notify).
%prep
%build
%install
rm -rf $RPM_BUILD_ROOT
install -d -m 755 $RPM_BUILD_ROOT/opt/hc/lib
install -d -m 755 $RPM_BUILD_ROOT/opt/hc/lib/core
cp ../SOURCES/opt/hc/lib/core/notify_slack.sh $RPM_BUILD_ROOT/opt/hc/lib/core/notify_slack.sh
install -d -m 755 $RPM_BUILD_ROOT/etc/opt/hc
install -d -m 755 $RPM_BUILD_ROOT/etc/opt/hc/core
install -d -m 755 $RPM_BUILD_ROOT/etc/opt/hc/core/providers
cp ../SOURCES/etc/opt/hc/core/providers/notify_slack.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/core/providers/notify_slack.conf.dist
%post
# ------------------------- CONFIGURATION starts here -------------------------
# location of the HC configuration files
HC_ETC_DIR="/etc/opt/hc"
# location of check_health.sh
HC_BIN="/opt/hc/bin/check_health.sh"
PATH="$PATH:/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin"
# ------------------------- CONFIGURATION ends here ---------------------------
echo "INFO: starting post-install script ..."
# copy plugin configuration file
if [[ ! -f ${HC_ETC_DIR}/core/providers/notify_slack.conf ]]
then
cp -p ${HC_ETC_DIR}/core/providers/notify_slack.conf.dist ${HC_ETC_DIR}/core/providers/notify_slack.conf >/dev/null
(( $? == 0 )) || \
{
echo "ERROR: could not copy plugin config file in ${HC_ETC_DIR}/core/providers"
exit 1
}
fi
# refresh symbolic FPATH links
if [[ -x ${HC_BIN} ]]
then
${HC_BIN} --fix-symlinks
(( $? == 0 )) || echo "WARN: updating symlinks failed"
fi
echo "INFO: finished post-install script"
%postun
# ------------------------- CONFIGURATION starts here -------------------------
# location of the HC configuration files
HC_ETC_DIR="/etc/opt/hc"
# location of check_health.sh
HC_BIN="/opt/hc/bin/check_health.sh"
PATH="$PATH:/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin"
# ------------------------- CONFIGURATION ends here ---------------------------
# update or uninstall?
if (( $1 == 0 ))
then
echo "INFO: starting post-uninstall script ..."
# copy plugin configuration file (.dist only)
if [[ -d ${HC_ETC_DIR}/core/providers ]]
then
rm -f ${HC_ETC_DIR}/core/providers/notify_slack.conf.dist 2>/dev/null
(( $? == 0 )) || \
{
echo "ERROR: could not remove plugin config file in ${HC_ETC_DIR}/core/providers"
exit 1
}
fi
else
echo "INFO: starting post-uninstall script (RPM upgrade)"
fi
# refresh symbolic FPATH links
if [[ -x ${HC_BIN} ]]
then
${HC_BIN} --fix-symlinks
(( $? == 0 )) || echo "WARN: updating symlinks failed"
fi
echo "INFO: finished post-uninstall script"
%files
%defattr(-,root,root,755)
%dir /opt/hc/lib
%dir /opt/hc/lib/core
%attr(755, root, root) /opt/hc/lib/core/notify_slack.sh
%dir /etc/opt/hc
%dir /etc/opt/hc/core
%dir /etc/opt/hc/core/providers
%attr(644, root, root) /etc/opt/hc/core/providers/notify_slack.conf.dist
%changelog
* Sun Oct 14 2022 <patrick@kudos.be> - 0.0.1
- Initial build

View File

@ -47,7 +47,6 @@ rpmbuild -bb ${BUILD_DIR}/SPECS/hc-linux-platform.spec
# build core plugins
rpmbuild -bb ${BUILD_DIR}/SPECS/hc-notify-eif.spec
rpmbuild -bb ${BUILD_DIR}/SPECS/hc-notify-sms.spec
rpmbuild -bb ${BUILD_DIR}/SPECS/hc-notify-slack.spec
rpmbuild -bb ${BUILD_DIR}/SPECS/hc-display-init.spec
rpmbuild -bb ${BUILD_DIR}/SPECS/hc-display-json.spec
rpmbuild -bb ${BUILD_DIR}/SPECS/hc-display-csv.spec

View File

@ -13,11 +13,9 @@ log_healthy="no"
# full path to the location of mksysb images, the tool expects sub-directories
# per host underneath this location
# [default: /export/images]
backup_path=/export/images
# name of the file containing the mksysb output
# [default: mksysb.log]
mksysb_log=mksysb.log
# maximum days before backup gets flagged as 'too old'

View File

@ -1,41 +0,0 @@
#******************************************************************************
# @(#) check_aix_uptime.conf
#******************************************************************************
# This is a configuration file for the check_aix_uptime 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="no"
# trigger event when current uptime is less than previously record uptime?
# [default: yes]
check_reboot="yes"
# time to wait before the current uptime is considered for the reboot check.
# Example: a value of 60m means the check for a previous reboot will be at earliest
# performed 1 hour after the last reboot of the host.
# Format: <value>m|h|d where m=minutes, h=hours, d=days (lowercase suffix).
# if no suffix is specified, then minutes are assumed.
# [default: 60m]
reboot_time="60m"
# trigger event when current uptime goes over the maximum threshold?
# [default: no]
check_old_age="no"
# time to expire before the current uptime is considered "old age".
# Example: a value of 365d means a must-reboot will be flagged at earliest after
# 1 year of uptime of the host
# Format: <value>m|h|d where m=minutes, h=hours, d=days (lowercase suffix).
# if no suffix is specified, then minutes are assumed.
# [default: 365d]
old_age_time="365d"
#******************************************************************************
# End of FILE
#******************************************************************************

View File

@ -1,7 +1,7 @@
#******************************************************************************
# @(#) check_exadata_zfs_logs.conf
# @(#) check_exadata_zfs_share_usage.conf
#******************************************************************************
# This is a configuration file for the check_exadata_zfs_logs HC plugin.
# This is a configuration file for the check_exadata_zfs_share_usage HC plugin.
# All lines starting with a '#' are comment lines.
# [default: indicates hardcoded script values if no value is defined here]
#******************************************************************************

View File

@ -33,26 +33,21 @@ max_replication_lag=300
# will for this given share will be skipped (this allows for exclusion of shares)
# In order to check share(s) for a given ZFS appliance at least one configuration
# entry must be present: either a wildcard or custom entry.
# Caveat: any share must finally resolve to one entry only.
# Format:
# zfs:<host_name>:<replication_name|*>:<true|false|*>:<success|failed|*>:[<max_replication_lag>]:[day1,day2,..|*>]:[<hour|<start_hour-end_hour>|*>]
#
# <day>: 3 letter day name (case insensitive)
# <hour>: 24 hours notation (start and end hours are inclusive)
#
# zfs:<host_name>:<replication_name|*>:<true|false|*>:<success|failed|*>:[<max_replication_lag>]
# Examples:
# check rep_share1 on myzfs1 with a custom threshold of 300 seconds on every day of the week
# zfs:myzfs1:rep_share1:*:*:600:*
# check all shares of myzfs2 with a custom threshold of 1200 seconds on Sunday and Monday
# zfs:myzfs2:*:*:*:1200:Sun,Mon
# check all shares of myzfs3 with the general threshold but only on Friday between 7am-10m
# zfs:myzfs3:*:*:*:Fri:07-10
# check rep_share1 on myzfs1 with a custom threshold of 300 seconds
# zfs:myzfs1:rep_share1:*:*:600
# check all shares of myzfs2 with a custom threshold of 1200 seconds
# zfs:myzfs2:*:*:*:1200
# check all shares of myzfs3 with the general threshold
# zfs:myzfs3:*:*:*:
# disable all shares of myzfs4 from checking
# zfs:myzfs4:*:*:*:0:*
# zfs:myzfs4:*:*:*:0
# disable check of rep_share7 on myzfs5
# zfs:myzfs5:rep_share7:*:*:0:*
# check that rep_share4 on myzfs6 is inactive (every day of the week)
# zfs:myzfs6:rep_share4:false:*:*
# zfs:myzfs5:rep_share7:*:*:0
# check that rep_share4 on myzfs6 is inactive
# zfs:myzfs6:rep_share4:false:*:
#******************************************************************************

View File

@ -33,7 +33,6 @@ max_space_usage=90
# will for this given share will be skipped (this allows for exclusion of shares)
# In order to check share(s) for a given ZFS appliance at least one configuration
# entry must be present: either a wildcard or custom entry.
# Caveat: any share must finally resolve to one entry only.
# Format:
# zfs:<host_name>:<project_name|*>:<share_name|*>:[<usage_threshold_%>]
# Examples:

View File

@ -1,7 +1,7 @@
#******************************************************************************
# @(#) check_hpux_autofs.conf
# @(#) check_linux_autofs.conf
#******************************************************************************
# This is a configuration file for the check_hpux_autofs HC plugin.
# This is a configuration file for the check_linux_autofs HC plugin.
# All lines starting with a '#' are comment lines.
# [default: indicates hardcoded script values if no value is defined here]
#******************************************************************************
@ -11,7 +11,7 @@
# [default: no]
log_healthy="no"
# specify whether to fix autofs (if needed)
# specify whether to extend the current ELDO FS (if needed)
# [default: no]
fix_autofs="no"

View File

@ -1,25 +0,0 @@
#******************************************************************************
# @(#) check_hpux_cron_status.conf
#******************************************************************************
# This is a configuration file for the check_hpux_cron_status 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="no"
# specify the wait time (in seconds) between registering and checking a cron task
# [default: 10]
wait_time=10
# specify the path the cron log file
# [default: /var/adm/cron/log]
cron_log="/var/adm/cron/log"
#******************************************************************************
# End of FILE
#******************************************************************************

View File

@ -1,27 +0,0 @@
#******************************************************************************
# @(#) check_hpux_defunct_processes.conf
#******************************************************************************
# This is a configuration file for the check_hpux_defunct_processes 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 above which threshold of defunct processes to generate a HC fail event
# If group_by_ppid is set to 'yes' then the value of 'process_threshold' will
# apply for each PPID, otherwise it will apply to all defunct processes together
# [default: 10]
process_threshold=10
# specify whether to group by parent ID or not.
# [default: yes]
group_by_ppid="yes"
#******************************************************************************
# End of FILE
#******************************************************************************

View File

@ -32,7 +32,7 @@ max_space_usage=90
# defining a threshold of 0 (zero), then the check will for this give filesystem
# will be skipped (this allows for exclusion of filesystems)
# Format:
# fs:<mount_point>:[<max_inodes_usage_%>]:[<max_space_usage_%]
# fs:<mount_point>:[<max_inode_usage_%>]:[<max_space_usage_%]
# Examples:
# check myfs1 with a custom inodes + space usage threshold
#fs:myfs1:70:95

View File

@ -11,7 +11,7 @@
# [default: no]
log_healthy="no"
# specify properties as displayed by the 'hpvmstatus -M' command
# specify properties as displayed by the 'vzlist -a -H -o ctid,status,onboot' command
# Format:
# [vpar:<parid>:<runtime_status>:<boot_status>]
# runtime_status should be 'on' or 'off'

View File

@ -1,41 +0,0 @@
#******************************************************************************
# @(#) check_hpux_uptime.conf
#******************************************************************************
# This is a configuration file for the check_hpux_uptime 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="no"
# trigger event when current uptime is less than previously record uptime?
# [default: yes]
check_reboot="yes"
# time to wait before the current uptime is considered for the reboot check.
# Example: a value of 60m means the check for a previous reboot will be at earliest
# performed 1 hour after the last reboot of the host.
# Format: <value>m|h|d where m=minutes, h=hours, d=days (lowercase suffix).
# if no suffix is specified, then minutes are assumed.
# [default: 60m]
reboot_time="60m"
# trigger event when current uptime goes over the maximum threshold?
# [default: no]
check_old_age="no"
# time to expire before the current uptime is considered "old age".
# Example: a value of 365d means a must-reboot will be flagged at earliest after
# 1 year of uptime of the host
# Format: <value>m|h|d where m=minutes, h=hours, d=days (lowercase suffix).
# if no suffix is specified, then minutes are assumed.
# [default: 365d]
old_age_time="365d"
#******************************************************************************
# End of FILE
#******************************************************************************

View File

@ -11,7 +11,7 @@
# [default: no]
log_healthy="no"
# specify whether to fix autofs (if needed)
# specify whether to extend the current ELDO FS (if needed)
# [default: no]
fix_autofs="no"

View File

@ -1,27 +0,0 @@
#******************************************************************************
# @(#) check_linux_fail2ban_status.conf
#******************************************************************************
# This is a configuration file for the check_linux_fail2ban_status 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="no"
# specify which type of process check to use
# Format: <auto|pgrep|sysv|systemd>. NULL value equals to "auto"
# [default: auto]
check_type="auto"
# specify the list jails to status check (comma-separated)
# Format: jail1,jail2,jail3,...
# [default: none]
check_jails=""
#******************************************************************************
# End of FILE
#******************************************************************************

View File

@ -1,28 +0,0 @@
#******************************************************************************
# @(#) check_linux_fetchmail_status.conf
#******************************************************************************
# This is a configuration file for the check_linux_fetchmail_status 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="no"
# specify the regex of error codes that will be used to search the log file_path
# [default: error|authfail|lockbusy|ioerr]
error_regex="error|authfail|lockbusy|ioerr"
# specify fetchmail details
# Format:
# fetchmail:<account>:<rc_file>:<check_log=Yes|No>
# Examples:
#fetchmail:vmail:/srv/vmail/janedoe/.fetchmailrc:Yes
#fetchmail:vmail:/srv/vmail/johndoe/.fetchmailrc:No
#******************************************************************************
# End of FILE
#******************************************************************************

View File

@ -32,7 +32,7 @@ max_space_usage=90
# defining a threshold of 0 (zero), then the check will for this give filesystem
# will be skipped (this allows for exclusion of filesystems)
# Format:
# fs:<mount_point>:[<max_inodes_usage_%>]:[<max_space_usage_%]
# fs:<mount_point>:[<max_inode_usage_%>]:[<max_space_usage_%]
# Examples:
# check myfs1 with a custom inodes + space usage threshold
#fs:myfs1:70:95

View File

@ -12,23 +12,18 @@
log_healthy="no"
# location of 'hpacucli' tool
# [default: /usr/sbin/hpacucli]
hpacucli_bin="/usr/sbin/hpacucli"
# controller all show status (0=off, 1=on)
# [default: 1]
# controller all show status (0=off, 1=on) [default: 1]
do_acu_controller=1
# controller slot=X enclosure all show (0=off, 1=on)
# [default: 1]
# controller slot=X enclosure all show (0=off, 1=on) [default: 1]
do_acu_enclosure=1
# controller slot=X physicaldrive all show status (0=off, 1=on)
# [default: 1]
# controller slot=X physicaldrive all show status (0=off, 1=on) [default: 1]
do_acu_physical=1
# controller slot=X logicaldrive all show status (0=off, 1=on)
# [default: 1]
# controller slot=X logicaldrive all show status (0=off, 1=on) [default: 1]
do_acu_logical=1

View File

@ -12,27 +12,21 @@
log_healthy="no"
# location of 'hpasmcli' tool
# [default: /sbin/hpasmcli]
hpasmcli_bin="/sbin/hpasmcli"
# SHOW FANS (0=off, 1=on)
# [default: 1]
# SHOW FANS (0=off, 1=on) [default: 1]
do_asm_fans=1
# SHOW DIMM (0=off, 1=on)
# [default: 1]
# SHOW DIMM (0=off, 1=on) [default: 1]
do_asm_dimm=1
# SHOW POWERSUPPLY (0=off, 1=on)
# [default: 1]
# SHOW POWERSUPPLY (0=off, 1=on) [default: 1]
do_asm_powersupply=1
# SHOW SERVER (0=off, 1=on)
# [default: 1]
# SHOW SERVER (0=off, 1=on) [default: 1]
do_asm_server=1
# SHOW TEMPERATURE (0=off, 1=on)
# [default: 1]
# SHOW TEMPERATURE (0=off, 1=on) [default: 1]
do_asm_temperature=1

View File

@ -12,7 +12,6 @@
log_healthy="no"
# location of 'hpacucli' tool
# [default: /sbin/hplog]
hplog_bin="/sbin/hplog"
# comma-separated list of severities to search for (case insensitive)

View File

@ -12,23 +12,18 @@
log_healthy="no"
# location of 'hpssacli' tool
# [default: /usr/sbin/hpssacli]
hpssacli_bin="/usr/sbin/hpssacli"
# controller all show status (0=off, 1=on)
# [default: 1]
# controller all show status (0=off, 1=on) [default: 1]
do_ssa_controller=1
# controller slot=X enclosure all show (0=off, 1=on)
# [default: 1]
# controller slot=X enclosure all show (0=off, 1=on) [default: 1]
do_ssa_enclosure=1
# controller slot=X physicaldrive all show status (0=off, 1=on)
# [default: 1]
# controller slot=X physicaldrive all show status (0=off, 1=on) [default: 1]
do_ssa_physical=1
# controller slot=X logicaldrive all show status (0=off, 1=on)
# [default: 1]
# controller slot=X logicaldrive all show status (0=off, 1=on) [default: 1]
do_ssa_logical=1
#******************************************************************************

View File

@ -1,34 +0,0 @@
#******************************************************************************
# @(#) check_linux_httpd_status.conf
#******************************************************************************
# This is a configuration file for the check_linux_httpd_status 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="no"
# specify which type of process check to use
# Format: <auto|pgrep|sysv|systemd>. NULL value equals to "auto"
# [default: auto]
# [release >20191101]
check_type="auto"
# specify name of the httpd binary
# Format: httpd|apache|apache2
# [default: httpd]
# [release >20201010]
httpd_bin="httpd"
# specify custom path to the httpd binary
# [default: null]
# [release >20201010]
httpd_path=""
#******************************************************************************
# End of FILE
#******************************************************************************

View File

@ -19,11 +19,6 @@ force_chrony="no"
# [default: no]
force_ntp="no"
# whether to force the use of systemd-timesyncd?
# [default: no]
# [release >20220129]
force_systemd="no"
# maximum allowed offset (in milliseconds (positive integers only)
# [default: 500]
max_offset=500

View File

@ -1,41 +0,0 @@
#******************************************************************************
# @(#) check_linux_uptime.conf
#******************************************************************************
# This is a configuration file for the check_linux_uptime 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="no"
# trigger event when current uptime is less than previously record uptime?
# [default: yes]
check_reboot="yes"
# time to wait before the current uptime is considered for the reboot check.
# Example: a value of 60m means the check for a previous reboot will be at earliest
# performed 1 hour after the last reboot of the host.
# Format: <value>m|h|d where m=minutes, h=hours, d=days (lowercase suffix).
# if no suffix is specified, then minutes are assumed.
# [default: 60m]
reboot_time="60m"
# trigger event when current uptime goes over the maximum threshold?
# [default: no]
check_old_age="no"
# time to expire before the current uptime is considered "old age".
# Example: a value of 365d means a must-reboot will be flagged at earliest after
# 1 year of uptime of the host
# Format: <value>m|h|d where m=minutes, h=hours, d=days (lowercase suffix).
# if no suffix is specified, then minutes are assumed.
# [default: 365d]
old_age_time="365d"
#******************************************************************************
# End of FILE
#******************************************************************************

View File

@ -11,12 +11,6 @@
# [default: no]
log_healthy="no"
# specify UBC names to exclude (comma-separated list) (release >20200411)
# [default: none]
# [release >2020410]
# Examples: numfile,numpty
exclude_counters=""
# specify containers for which to check the UBC
# Format:
# [ct:<ct_id>]

View File

@ -11,18 +11,13 @@
# [default: no]
log_healthy="no"
# specify properties as displayed by the following commands:
# OpenVZ 6.x: 'vzlist -a -H -o ctid,status,onboot'
# OpenVZ 7.x: 'prlctl list --info -a' (release >20200411)
# specify properties as displayed by the 'vzlist -a -H -o ctid,status,onboot' command
# Format:
# [ct:<ct_id>:<runtime_status>:<boot_status>]
# runtime_status should be 'running' or 'stopped'
# boot_status should be 'yes' or 'no' (OpenVZ 6.x)
# boot_status should be 'on' of 'off' (OpenVZ 7.x)
# Examples (OpenVZ 6.x):
# boot_status should be 'yes' or 'no'
# Examples:
#ct:100:running:yes
# Examples (OpenVZ 7.x) (release >20200411):
#ct:621240e6-fa79-406a-a3f9-26de47b5d789:running:on
#******************************************************************************

View File

@ -1,7 +1,7 @@
#******************************************************************************
# @(#) check_serviceguard_package_status.conf
# @(#) check_linux_sg_package_status.conf
#******************************************************************************
# This is a configuration file for the check_serviceguard_package_status HC plugin.
# This is a configuration file for the check_linux_sg_package_status HC plugin.
# All lines starting with a '#' are comment lines.
# [default: indicates hardcoded script values if no value is defined here]
#******************************************************************************

View File

@ -10,31 +10,6 @@
# maximum timeout for HC calls/plugins (seconds) [default: 60]
HC_TIME_OUT=60
# enable/disable logging of passed health checks (warning: this may rapidly grow the HC log)
# see also: '--log-healthy' command-line parameter
# 'log_healthy' setting in HC plugin configuration file(s)
# [values: Yes|No]
HC_LOG_HEALTHY="No"
# enable/disable healing logic if available in HC plugin(s)
# see also: '--no-fix' command-line parameter
# [values: Yes|No]
HC_WILL_FIX="Yes"
# cache "last" reporting entries. Set to 'Yes' to speed up reporting of the last
# registered HC events
# [values: Yes|No]
HC_REPORT_CACHE_LAST="No"
# cache "today" reporting entries. Set to 'Yes' to speed up reporting of today's
# registered HC events
# [values: Yes|No]
HC_REPORT_CACHE_TODAY="No"
# Show log entry count(s) after archiving. Disabling this will speed up archiving.
# [values: Yes|No]
HC_COUNT_ARCHIVES="Yes"
#******************************************************************************
# End of FILE

View File

@ -1,15 +0,0 @@
#******************************************************************************
# @(#) notify_slack.conf
#******************************************************************************
# This is the the configuration file for the notify_slack.sh provider.
# All lines starting with a '#' are comment lines.
# [default: indicates hardcoded script values if no value is defined here]
#******************************************************************************
# URL of the webhook of the Slack app
SLACK_WEBHOOK=""
#******************************************************************************
# End of FILE
#******************************************************************************

View File

@ -23,8 +23,8 @@
# REQUIRES: ksh88/93 (mksh/pdksh will probably work too but YMMV)
# build_fpath(), check_config(), check_core(), check_lock_dir(),
# check_params(), check_platform(), check_user(), check_shell(),
# display_usage(), do_cleanup, fix_symlinks(), get_disable_comment(),
# read_config() + include functions
# display_usage(), do_cleanup, fix_symlinks(), read_config()
# + include functions
# For other pre-requisites see the documentation in display_usage()
# REQUIRES (OPTIONAL): display_*(), notify_*(), report_*()
# EXISTS: 0=no errors encountered, >0=some errors encountered
@ -38,7 +38,7 @@
# ------------------------- CONFIGURATION starts here -------------------------
# define the version (YYYY-MM-DD)
typeset -r SCRIPT_VERSION="2021-03-31"
typeset -r SCRIPT_VERSION="2019-07-16"
# location of parent directory containing KSH functions/HC plugins
typeset -r FPATH_PARENT="/opt/hc/lib"
# location of custom HC configuration files
@ -86,15 +86,14 @@ typeset EXIT_CODE=0
typeset FDIR=""
typeset FFILE=""
typeset FPATH=""
typeset HC_ARCHIVE=""
typeset HC_CHECK=""
typeset HC_COMMENT=""
typeset HC_DISABLE=""
typeset HC_ENABLE=""
typeset HC_RUN=""
typeset HC_FAIL_ID=""
# shellcheck disable=SC2034
typeset HC_FILE_LINE=""
typeset HC_LOG_HEALTHY=""
typeset HC_NOW=""
typeset HC_TIME_OUT=60
typeset HC_MIN_TIME_OUT=30
@ -102,20 +101,10 @@ typeset HC_MIN_TIME_OUT=30
typeset HC_MSG_VAR=""
typeset HC_STDOUT_LOG=""
typeset HC_STDERR_LOG=""
set -A HC_STDOUT_LOG_ARRAY
set -A HC_STDERR_LOG_ARRAY
# shellcheck disable=SC2034
typeset HC_COUNT_ARCHVES=""
typeset HC_WILL_FIX=""
# shellcheck disable=SC2034
typeset HC_REPORT_CACHE_LAST=""
# shellcheck disable=SC2034
typeset HC_REPORT_CACHE_TODAY=""
# shellcheck disable=SC2034
typeset LINUX_DISTRO=""
# shellcheck disable=SC2034
typeset LINUX_RELEASE=""
typeset PREVIOUS_HC_TIME_OUT=""
typeset ARCHIVE_RC=0
typeset DISABLE_RC=0
typeset ENABLE_RC=0
@ -131,7 +120,6 @@ typeset DEBUG_OPTS=""
# command-line parameters
typeset ARG_ACTION=0 # HC action flag
typeset ARG_CHECK_HOST=0 # host check is off by default
typeset ARG_COMMENT=""
typeset ARG_CONFIG_FILE="" # custom configuration file for a HC, none by default
typeset ARG_DEBUG=0 # debug is off by default
typeset ARG_DEBUG_LEVEL=0 # debug() only by default
@ -144,7 +132,6 @@ typeset ARG_HC_ARGS="" # no extra arguments to HC plug-in by default
typeset ARG_HISTORY=0 # include historical events is off by default
typeset ARG_LAST=0 # report last events
typeset ARG_LIST="" # list all by default
typeset ARG_LIST_DETAILS=0 # list with full details is off by default
typeset ARG_LOCK=1 # lock for concurrent script executions is on by default
typeset ARG_LOG=1 # logging is on by default
typeset ARG_NO_FIX=0 # fix/healing is not disabled by default
@ -265,8 +252,8 @@ case "${KSH_VERSION}" in
. ${FPATH_PARENT}/core/include_core.sh
if [[ -r ${FPATH_PARENT}/core/include_data.sh && -h ${FPATH_PARENT}/core/include_data ]]
then
(( ARG_DEBUG > 0 )) && print -u2 "DEBUG: including ${FPATH_PARENT}/core/include_data.sh"
# shellcheck source=/dev/null
(( ARG_DEBUG > 0 )) && print -u2 "DEBUG: including ${FPATH_PARENT}/core/include_data.sh"
. ${FPATH_PARENT}/core/include_data.sh
else
print -u2 "ERROR: library file ${FPATH_PARENT}/core/include_data.sh is not present (tip: run --fix-symlinks)"
@ -274,8 +261,8 @@ case "${KSH_VERSION}" in
fi
if [[ -r ${FPATH_PARENT}/core/include_os.sh && -h ${FPATH_PARENT}/core/include_os ]]
then
(( ARG_DEBUG > 0 )) && print -u2 "DEBUG: including ${FPATH_PARENT}/core/include_os.sh"
# shellcheck source=/dev/null
(( ARG_DEBUG > 0 )) && print -u2 "DEBUG: including ${FPATH_PARENT}/core/include_os.sh"
. ${FPATH_PARENT}/core/include_os.sh
else
print -u2 "ERROR: library file ${FPATH_PARENT}/core/include_os.sh is not present (tip: run --fix-symlinks)"
@ -284,14 +271,14 @@ case "${KSH_VERSION}" in
;;
*)
# include include_*
find ${FPATH_PARENT}/core -name "include_*.sh" -type f -print 2>/dev/null | while read -r INCLUDE_FILE
find ${FPATH_PARENT}/core -name "include_*.sh" -type f -print 2>/dev/null | while read INCLUDE_FILE
do
if [[ -h ${INCLUDE_FILE%%.sh} ]]
then
# shellcheck source=/dev/null
(( ARG_DEBUG > 0 )) && print -u2 "DEBUG: including ${INCLUDE_FILE}"
# shellcheck source=/dev/null
. "${INCLUDE_FILE}"
. ${INCLUDE_FILE}
else
print -u2 "ERROR: library file ${INCLUDE_FILE} exists but has no symlink. Run --fix-symlinks"
exit 1
@ -340,19 +327,18 @@ function check_lock_dir
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
if (( ARG_LOCK > 0 ))
then
mkdir "${LOCK_DIR}" >/dev/null 2>/dev/null || {
mkdir ${LOCK_DIR} >/dev/null || {
print -u2 "ERROR: unable to acquire lock ${LOCK_DIR}"
ARG_VERBOSE=0 warn "unable to acquire lock ${LOCK_DIR}"
if [[ -f ${LOCK_DIR}/.pid ]]
then
# shellcheck disable=SC2086
typeset LOCK_PID=$(<"${LOCK_DIR}/.pid")
typeset LOCK_PID="$(<${LOCK_DIR}/.pid)"
print -u2 "ERROR: active health checker running on PID: ${LOCK_PID}"
ARG_VERBOSE=0 warn "active health checker running on PID: ${LOCK_PID}. Exiting!"
fi
exit 1
}
print $$ > "${LOCK_DIR}/.pid"
print $$ >${LOCK_DIR}/.pid
else
(( ARG_DEBUG > 0 )) && print "DEBUG: locking has been disabled"
fi
@ -476,14 +462,11 @@ then
exit 1
fi
fi
# --comment
if [[ -n "${ARG_COMMENT}" ]]
# --log-healthy
if (( ARG_LOG_HEALTHY > 0 && ARG_ACTION != 4 ))
then
if (( ARG_ACTION != 2 )) && (( ARG_ACTION != 6 ))
then
print -u2 "ERROR: you can only use '--comment' in combination with '--disable' or '--disable-all'"
print -u2 "ERROR: you can only use '--log-healthy' in combination with '--run'"
exit 1
fi
fi
# check log location
if (( ARG_LOG > 0 ))
@ -586,8 +569,8 @@ cat << EOT
Execute/report simple health checks (HC) on UNIX hosts.
Syntax: ${SCRIPT_DIR}/${SCRIPT_NAME} [--help] | [--help-terse] | [--version] |
[--list=<needle>] | [--list-details] | [--list-core] | [--list-include] | [--fix-symlinks] | [--show-stats] | (--archive-all | --disable-all [--comment=<text>] | --enable-all) | [--fix-logs [--with-history]] |
(--check-host | ((--archive | --check | --enable | --disable [--comment=<text>] | --run [--timeout=<secs>] | --show) --hc=<list_of_checks> [--config-file=<configuration_file>] [hc-args="<arg1,arg2=val,arg3">]))
[--list=<needle>] | [--list-core] | [--list-include] | [--fix-symlinks] | [--show-stats] | (--archive-all | --disable-all | --enable-all) | [--fix-logs [--with-history]] |
(--check-host | ((--archive | --check | --enable | --disable | --run [--timeout=<secs>] | --show) --hc=<list_of_checks> [--config-file=<configuration_file>] [hc-args="<arg1,arg2=val,arg3">]))
[--display=<method>] ([--debug] [--debug-level=<level>]) [--log-healthy] [--no-fix] [--no-log] [--no-lock] [--no-monitor] [[--flip-rc] [--with-rc=<count|max|sum>]]]
[--notify=<method_list>] [--mail-to=<address_list>] [--sms-to=<sms_rcpt> --sms-provider=<name>]
[--report=<method> [--with-history] ( ([--last] | [--today]) | [(--older|--newer)=<date>] | [--reverse] [--id=<fail_id> [--detail]] )]
@ -603,7 +586,6 @@ Parameters:
--archive-all : move events for all HCs from the HC log file into archive log files
--check : display HC state.
--check-host : execute all configured HC(s) (see check_host.conf)
--comment : add comment to requested action (--disable). WARNING: comments may not contain spaces!
--config-file : custom configuration file for a HC (may only be specified when executing a single HC plugin)
--debug : run script in debug mode
--debug-level : level of debugging information to show (0,1,2)
@ -622,23 +604,19 @@ Parameters:
in double quotes (example: --hc_args="arg1,arg2=value,arg3").
--id : value of a FAIL ID (must be specified as uninterrupted sequence of numbers)
--last : show the last (failed) events for each HC and their combined STC value
--list : show the available health checks in a terse manner. Use --list-details for a more extensive list.
--list-details : show the available health checks with following details included:
--list : show the available health checks. Use <needle> to search with wildcards. Following details are shown:
- health check (plugin) name
- state of the HC plugin (disabled/enabled)
- version of the HC plugin
- whether the HC plugin requires a configuration file in ${CONFIG_DIR}
- whether the HC plugin is scheduled by cron
- whether the plugin contains a facility for --log-healthy and/or whether it is enabled
- whether the plugin contains fix/healing logic (see --no-fix)
--list-core : show the available core plugins (mail,SMS,...)
--list-include : show the available includes/libraries
--log-healthy : log/show also passed health checks. By default this is off when the plugin support this feature.
(overrides \$HC_LOG_HEALTHY and can itself be overridden by --no-log to disable all logging)
(can be overridden by --no-log to disable all logging)
--mail-to : list of e-mail address(es) to which an e-mail alert will be send to [requires mail core plugin]
--newer : show the (failed) events for each HC that are newer than the given date
--no-fix : do not apply fix/healing logic for failed health checks (if available)
(overrides \$HC_WILL_FIX)
--no-lock : disable locking to allow concurrent script executions
--no-log : do not log any messages to the script log file or health check results.
--no-monitor : do not stop the execution of a HC after \$HC_TIME_OUT seconds
@ -652,7 +630,7 @@ Parameters:
--sms-provider : name of a supported SMS provider (see \$SMS_PROVIDERS) [requires SMS core plugin]
--sms-to : name of person or group to which a sms alert will be send to [requires SMS core plugin]
--timeout : maximum runtime of a HC plugin in seconds (overrides \$HC_TIME_OUT)
--today : show (failed) events of today (HC and their combined STC value)
--today : show today's (failed) events (HC and their combined STC value)
--version : show the timestamp of the script.
--with-history : also include events that have been archived already (reporting)
--with-rc : define RC handling (plugin) when --flip-rc is used
@ -675,28 +653,16 @@ function do_cleanup
log "performing cleanup ..."
# remove temporary files
[[ -f "${HC_MSG_FILE}" ]] && rm -f "${HC_MSG_FILE}" >/dev/null 2>&1
[[ -f "${HC_MSG_FILE}" ]] && rm -f ${HC_MSG_FILE} >/dev/null 2>&1
# remove left over plugin log files (pop from array stacks)
FILE_COUNT=1
while (( FILE_COUNT <= ${#HC_STDOUT_LOG_ARRAY[*]} ))
do
(( ARG_DEBUG > 0 )) && debug "cleaning up plugin log file ${HC_STDOUT_LOG_ARRAY[FILE_COUNT]}"
[[ -f "${HC_STDOUT_LOG_ARRAY[FILE_COUNT]}" ]] && rm -f "${HC_STDOUT_LOG_ARRAY[FILE_COUNT]}" >/dev/null 2>&1
FILE_COUNT=$(( FILE_COUNT + 1 ))
done
FILE_COUNT=1
while (( FILE_COUNT <= ${#HC_STDERR_LOG_ARRAY[*]} ))
do
(( ARG_DEBUG > 0 )) && debug "cleaning up plugin log file ${HC_STDERR_LOG_ARRAY[FILE_COUNT]}"
[[ -f "${HC_STDERR_LOG_ARRAY[FILE_COUNT]}" ]] && rm -f "${HC_STDERR_LOG_ARRAY[FILE_COUNT]}" >/dev/null 2>&1
FILE_COUNT=$(( FILE_COUNT + 1 ))
done
# remove trailing log files
[[ -f "${HC_STDOUT_LOG}" ]] && rm -f ${HC_STDOUT_LOG} >/dev/null 2>&1
[[ -f "${HC_STDERR_LOG}" ]] && rm -f ${HC_STDERR_LOG} >/dev/null 2>&1
# remove lock directory
if [[ -d ${LOCK_DIR} ]]
then
rm -rf "${LOCK_DIR}" >/dev/null 2>&1
rm -rf ${LOCK_DIR} >/dev/null 2>&1
log "${LOCK_DIR} lock directory removed"
fi
@ -721,7 +687,6 @@ typeset FSYML=""
# find missing symlinks (do not skip core plug-ins here)
print "${FPATH}" | tr ':' '\n' 2>/dev/null | while read -r FDIR
do
# shellcheck disable=SC2086
find ${FDIR} -type f -print 2>/dev/null | while read -r FFILE
do
FSYML="${FFILE%.sh}"
@ -740,7 +705,7 @@ done
print "${FPATH}" | tr ':' '\n' 2>/dev/null | while read -r FDIR
do
# do not use 'find -type l' here!
# shellcheck disable=SC2010,SC2086
# shellcheck disable=SC2010
ls ${FDIR} 2>/dev/null | grep -v "\." 2>/dev/null | while read -r FSYML
do
# check if file is a dead symlink
@ -778,24 +743,6 @@ else
. "${CONFIG_FILE}"
fi
# reconcile global settings w/ cmd-line parameters
if (( ARG_LOG_HEALTHY == 0 ))
then
case "${HC_LOG_HEALTHY}" in
yes|YES|Yes)
ARG_LOG_HEALTHY=1
;;
esac
fi
if (( ARG_NO_FIX == 0 ))
then
case "${HC_WILL_FIX}" in
no|NO|No)
ARG_NO_FIX=1
;;
esac
fi
return 0
}
@ -843,12 +790,6 @@ do
fi
ARG_CHECK_HOST=1
;;
-comment=*)
ARG_COMMENT="${CMD_PARAMETER#-comment=}"
;;
--comment=*)
ARG_COMMENT="${CMD_PARAMETER#--comment=}"
;;
-config-file=*)
ARG_CONFIG_FILE="${CMD_PARAMETER#-config-file=}"
;;
@ -992,11 +933,6 @@ do
ARG_ACTION=9
fi
;;
-list-details|--list-details)
# shellcheck disable=SC2034
ARG_LIST_DETAILS=1
ARG_ACTION=9
;;
-list-hc|--list-hc|-list-all|--list-all)
print -u2 "WARN: deprecated option. Use --list | --list=<needle>"
exit 0
@ -1249,13 +1185,7 @@ case ${ARG_ACTION} in
# shellcheck disable=SC2181
if (( $? == 0 ))
then
HC_COMMENT=$(get_disable_comment "${HC_CHECK}")
if [[ -n "${HC_COMMENT}" ]]
then
log "HC ${HC_CHECK} is currently disabled (${HC_COMMENT})"
else
log "HC ${HC_CHECK} is currently disabled"
fi
else
log "HC ${HC_CHECK} is currently enabled"
fi
@ -1277,11 +1207,6 @@ case ${ARG_ACTION} in
exists_hc "${HC_DISABLE}" && die "cannot find HC: ${HC_DISABLE}"
log "disabling HC: ${HC_DISABLE}"
touch "${STATE_PERM_DIR}/${HC_DISABLE}.disabled" >/dev/null 2>&1
# write comment if supplied
if [[ -n "${ARG_COMMENT}" ]]
then
print "${ARG_COMMENT}" >"${STATE_PERM_DIR}/${HC_DISABLE}.disabled"
fi
# shellcheck disable=SC2181
if (( $? == 0 ))
then
@ -1329,7 +1254,7 @@ case ${ARG_ACTION} in
# re-initialize messages stash (log of failed checks)
# shellcheck disable=SC2034
HC_MSG_VAR=""
: > "${HC_MSG_FILE}" 2>/dev/null
: >${HC_MSG_FILE} 2>/dev/null
# shellcheck disable=SC2181
if (( $? > 0 ))
then
@ -1367,16 +1292,13 @@ case ${ARG_ACTION} in
# set & initialize STDOUT/STDERR locations (not in init_hc()!)
HC_STDOUT_LOG="${TMP_DIR}/${HC_RUN}.stdout.log.$$"
HC_STDERR_LOG="${TMP_DIR}/${HC_RUN}.stderr.log.$$"
# push plugin log files to array stacks (index starts at 1!)
HC_STDOUT_LOG_ARRAY[${#HC_STDOUT_LOG_ARRAY[*]}+1]="${HC_STDOUT_LOG}"
HC_STDERR_LOG_ARRAY[${#HC_STDERR_LOG_ARRAY[*]}+1]="${HC_STDERR_LOG}"
: > "${HC_STDOUT_LOG}" 2>/dev/null
: >${HC_STDOUT_LOG} 2>/dev/null
# shellcheck disable=SC2181
if (( $? > 0 ))
then
die "unable to reset the \${HC_STDOUT_LOG} file"
fi
: > "${HC_STDERR_LOG}" 2>/dev/null
: >${HC_STDERR_LOG} 2>/dev/null
# shellcheck disable=SC2181
if (( $? > 0 ))
then
@ -1386,7 +1308,6 @@ case ${ARG_ACTION} in
# --check-host handling: alternative configuration file, mangle ARG_CONFIG_FILE & HC_TIME_OUT
if (( ARG_CHECK_HOST == 1 ))
then
PREVIOUS_HC_TIME_OUT=${HC_TIME_OUT}
ARG_CONFIG_FILE="" # reset from previous call
RUN_CONFIG_FILE=$(grep -i -E -e "^hc:${HC_RUN}:" ${HOST_CONFIG_FILE} 2>/dev/null | cut -f3 -d':')
[[ -n "${RUN_CONFIG_FILE}" ]] && ARG_CONFIG_FILE="${CONFIG_DIR}/${RUN_CONFIG_FILE}"
@ -1396,14 +1317,13 @@ case ${ARG_ACTION} in
(( RUN_TIME_OUT > HC_TIME_OUT )) && HC_TIME_OUT=${RUN_TIME_OUT}
else
# reset for next HC
HC_TIME_OUT=${PREVIOUS_HC_TIME_OUT}
HC_TIME_OUT=60
fi
fi
# run HC with or without monitor
if (( ARG_MONITOR == 0 ))
then
# shellcheck disable=SC2086
${HC_RUN} ${ARG_HC_ARGS}
RUN_RC=$?
EXIT_CODE=${RUN_RC}
@ -1442,7 +1362,6 @@ case ${ARG_ACTION} in
# SLEEP_PID is the PID of the sleep subshell itself
SLEEP_PID=$!
# shellcheck disable=SC2086
${HC_RUN} ${ARG_HC_ARGS} &
CHILD_PID=$!
log "spawning child process with time-out of ${HC_TIME_OUT} secs for HC call [PID=${CHILD_PID}]"
@ -1493,7 +1412,7 @@ case ${ARG_ACTION} in
handle_hc "${HC_RUN}"
# exit with return code from handle_hc() (see --flip-rc)
EXIT_CODE=$?
rm -f "${HC_MSG_FILE}" >/dev/null 2>&1
rm -f ${HC_MSG_FILE} >/dev/null 2>&1
done
;;
5) # show info on HC (single)
@ -1513,11 +1432,6 @@ case ${ARG_ACTION} in
exists_hc "${HC_DISABLE}" && die "cannot find HC: ${HC_DISABLE}"
log "disabling HC: ${HC_DISABLE}"
touch "${STATE_PERM_DIR}/${HC_DISABLE}.disabled" >/dev/null 2>&1
# write comment if supplied
if [[ -n "${ARG_COMMENT}" ]]
then
print "${ARG_COMMENT}" >"${STATE_PERM_DIR}/${HC_DISABLE}.disabled"
fi
DISABLE_RC=$?
if (( DISABLE_RC == 0 ))
then
@ -1592,7 +1506,26 @@ case ${ARG_ACTION} in
esac
;;
13) # archive current log entries for all HCs
archive_hc_all
list_hc "list" | while read -r HC_ARCHIVE
do
# check for HC (function)
exists_hc "${HC_ARCHIVE}" && die "cannot find HC: ${HC_ARCHIVE}"
log "archiving current log entries for HC: ${HC_ARCHIVE}"
archive_hc "${HC_ARCHIVE}"
ARCHIVE_RC=$?
case ${ARCHIVE_RC} in
0)
log "no archiving needed for ${HC_ARCHIVE}"
;;
1)
log "successfully archived log entries for ${HC_ARCHIVE}"
;;
2)
log "failed to archive log entries for ${HC_ARCHIVE} [RC=${ARCHIVE_RC}]"
EXIT_CODE=1
;;
esac
done
;;
esac

View File

@ -31,7 +31,7 @@
function display_init
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _VERSION="2020-10-10" # YYYY-MM-DD
typeset _VERSION="2019-03-22" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="AIX,HP-UX,Linux" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
@ -139,7 +139,7 @@ fi
# print status line (but also check for terminal support)
# shellcheck disable=SC1117
printf "%-45s %50s\t[ %8s ]%s\n" \
printf "%-30s %50s\t[ %8s ]%s\n" \
"${_DISPLAY_HC}" \
"(${_DISPLAY_CFG})" \
"${_DISPLAY_COLOR}${_DISPLAY_CODE}${_NORMAL}" \

View File

@ -30,7 +30,7 @@
# RETURNS: 0
function version_include_core
{
typeset _VERSION="2022-10-14" # YYYY-MM-DD
typeset _VERSION="2019-06-18" # YYYY-MM-DD
print "INFO: $0: ${_VERSION#version_*}"
@ -50,7 +50,6 @@ typeset HC_NAME="${1}"
typeset ARCHIVE_FILE=""
typeset ARCHIVE_RC=0
typeset YEAR_MONTH=""
typeset COUNT_STATS=1
typeset LOG_COUNT=0
typeset PRE_LOG_COUNT=0
typeset TODO_LOG_COUNT=0
@ -64,136 +63,64 @@ typeset TMP2_FILE="${TMP_DIR}/.$0.tmp2.archive.$$"
trap "rm -f ${TMP1_FILE} ${TMP2_FILE} ${SAVE_LOG_FILE} >/dev/null 2>&1; return 1" 1 2 3 15
# get pre-archive log count
PRE_LOG_COUNT=$(wc -l "${HC_LOG}" 2>/dev/null | cut -f1 -d' ' 2>/dev/null)
PRE_LOG_COUNT=$(wc -l ${HC_LOG} 2>/dev/null | cut -f1 -d' ' 2>/dev/null)
if (( PRE_LOG_COUNT == 0 ))
then
warn "${HC_LOG} is empty, nothing to archive"
return 0
fi
# check log count toggle (only affects $LOG_COUNT)
case "${HC_COUNT_ARCHIVES}" in
No|no|NO)
COUNT_STATS=0
;;
*)
: # default is to do additional stats
;;
esac
# isolate messages from HC, find unique %Y-%m combinations
grep ".*${LOG_SEP}${HC_NAME}${LOG_SEP}" "${HC_LOG}" 2>/dev/null |\
grep ".*${LOG_SEP}${HC_NAME}${LOG_SEP}" ${HC_LOG} 2>/dev/null |\
cut -f1 -d"${LOG_SEP}" 2>/dev/null | cut -f1 -d' ' 2>/dev/null |\
cut -f1-2 -d'-' 2>/dev/null | sort -u 2>/dev/null |\
while read -r YEAR_MONTH
do
# skip messages with bogus date
if [[ -z "${YEAR_MONTH}" ]]
then
warn "skipping bogus log lines (lines without proper datestamp)"
continue
fi
# find all messages for that YEAR-MONTH combination
grep "${YEAR_MONTH}.*${LOG_SEP}${HC_NAME}${LOG_SEP}" "${HC_LOG}" >"${TMP1_FILE}"
TODO_LOG_COUNT=$(wc -l "${TMP1_FILE}" 2>/dev/null | cut -f1 -d' ' 2>/dev/null)
grep "${YEAR_MONTH}.*${LOG_SEP}${HC_NAME}${LOG_SEP}" ${HC_LOG} >${TMP1_FILE}
TODO_LOG_COUNT=$(wc -l ${TMP1_FILE} 2>/dev/null | cut -f1 -d' ' 2>/dev/null)
log "# of entries in ${YEAR_MONTH} to archive: ${TODO_LOG_COUNT}"
# combine existing archived messages and resort
ARCHIVE_FILE="${ARCHIVE_DIR}/hc.${YEAR_MONTH}.log"
cat "${ARCHIVE_FILE}" "${TMP1_FILE}" 2>/dev/null | sort -u >"${TMP2_FILE}" 2>/dev/null
mv "${TMP2_FILE}" "${ARCHIVE_FILE}" 2>/dev/null || {
cat ${ARCHIVE_FILE} ${TMP1_FILE} 2>/dev/null | sort -u >${TMP2_FILE} 2>/dev/null
mv ${TMP2_FILE} ${ARCHIVE_FILE} 2>/dev/null || {
warn "failed to move archive file, aborting"
return 2
}
if (( COUNT_STATS > 0 ))
then
LOG_COUNT=$(wc -l "${ARCHIVE_FILE}" 2>/dev/null | cut -f1 -d' ' 2>/dev/null)
LOG_COUNT=$(wc -l ${ARCHIVE_FILE} 2>/dev/null | cut -f1 -d' ' 2>/dev/null)
log "# of entries in ${ARCHIVE_FILE} now: ${LOG_COUNT}"
fi
# remove archived messages from the $HC_LOG (but create a backup first!)
cp -p "${HC_LOG}" "${SAVE_HC_LOG}" 2>/dev/null
cp -p ${HC_LOG} ${SAVE_HC_LOG} 2>/dev/null
# compare with the sorted $HC_LOG
sort "${HC_LOG}" >"${TMP1_FILE}"
comm -23 "${TMP1_FILE}" "${ARCHIVE_FILE}" 2>/dev/null >"${TMP2_FILE}"
sort ${HC_LOG} >${TMP1_FILE}
comm -23 ${TMP1_FILE} ${ARCHIVE_FILE} 2>/dev/null >${TMP2_FILE}
# check archive action (HC_LOG should not be empty unless it contained
# only messages from one single HC plugin before archival)
if [[ -s ${TMP2_FILE} ]] || (( PRE_LOG_COUNT == TODO_LOG_COUNT ))
then
mv "${TMP2_FILE}" "${HC_LOG}" 2>/dev/null || {
mv ${TMP2_FILE} ${HC_LOG} 2>/dev/null || {
warn "failed to move HC log file, aborting"
return 2
}
if (( COUNT_STATS > 0 ))
then
LOG_COUNT=$(wc -l "${HC_LOG}" 2>/dev/null | cut -f1 -d' ' 2>/dev/null)
LOG_COUNT=$(wc -l ${HC_LOG} 2>/dev/null | cut -f1 -d' ' 2>/dev/null)
log "# entries in ${HC_LOG} now: ${LOG_COUNT}"
fi
ARCHIVE_RC=1
else
warn "a problem occurred. Rolling back archival"
mv "${SAVE_HC_LOG}" "${HC_LOG}" 2>/dev/null
mv ${SAVE_HC_LOG} ${HC_LOG} 2>/dev/null
ARCHIVE_RC=2
fi
done
# clean up temporary file(s)
rm -f "${TMP1_FILE}" "${TMP2_FILE}" "${SAVE_HC_LOG}" >/dev/null 2>&1
rm -f ${TMP1_FILE} ${TMP2_FILE} ${SAVE_HC_LOG} >/dev/null 2>&1
return ${ARCHIVE_RC}
}
# -----------------------------------------------------------------------------
# @(#) FUNCTION: archive_hc_all()
# DOES: archive log entries for all HCs
# EXPECTS: n/a
# RETURNS: 0
# REQUIRES: ${HC_LOG}
function archive_hc_all
{
typeset HC_ARCHIVE=""
# build list with all HCs in $HC_LOG and sort them by highest number of messages
# first (to speed up the archiving operation)
log "parsing log file ${HC_LOG} for messages ..."
awk -F"${LOG_SEP}" '
{
# only do records with a proper HC name in $2
if ($2 ~ /check_/) {
count[$2]++;
}
}
END {
for (hc in count) {
print count[hc] ":" hc;
}
}' "${HC_LOG}" 2>/dev/null | sort -rn 2>/dev/null |\
while IFS=":" read -r HC_COUNT HC_ARCHIVE
do
# check for HC (function)
exists_hc "${HC_ARCHIVE}" && die "cannot find HC: ${HC_ARCHIVE}"
log "archiving ${HC_COUNT} log entries for HC ${HC_ARCHIVE}"
archive_hc "${HC_ARCHIVE}"
ARCHIVE_RC=$?
case ${ARCHIVE_RC} in
0)
log "no archiving needed for ${HC_ARCHIVE}"
;;
1)
log "successfully archived log entries for ${HC_ARCHIVE}"
;;
2)
warn "failed to archive log entries for ${HC_ARCHIVE} [RC=${ARCHIVE_RC}]"
;;
esac
done
return 0
}
# -----------------------------------------------------------------------------
# @(#) FUNCTION: count_log_errors()
# DOES: check hc log file(s) for rogue entries (=lines with NF<>$NUM_LOG_FIELDS
@ -211,7 +138,6 @@ function count_log_errors
typeset LOG_STASH="${1}"
typeset ERROR_COUNT=0
# shellcheck disable=SC2002,SC2086
ERROR_COUNT=$(cat ${LOG_STASH} 2>/dev/null | awk -F"${LOG_SEP}" '
BEGIN { num = 0 }
{
@ -221,7 +147,7 @@ ERROR_COUNT=$(cat ${LOG_STASH} 2>/dev/null | awk -F"${LOG_SEP}" '
}
END { print num }' 2>/dev/null)
print "${ERROR_COUNT}"
print ${ERROR_COUNT}
return 0
}
@ -263,7 +189,7 @@ then
print - "$*" | while read -r LOG_LINE
do
# shellcheck disable=SC2153
print "${NOW}: ERROR: [$$]:" "${LOG_LINE}" >>"${LOG_FILE}"
print "${NOW}: ERROR: [$$]:" "${LOG_LINE}" >>${LOG_FILE}
done
fi
print - "$*" | while read -r LOG_LINE
@ -307,7 +233,6 @@ DO_DISPLAY_CUSTOM9=0
DO_NOTIFY_EIF=0
DO_NOTIFY_MAIL=0
DO_NOTIFY_SMS=0
DO_NOTIFY_SLACK=0
DO_REPORT_STD=0
HAS_DISPLAY_CSV=0
HAS_DISPLAY_INIT=0
@ -326,13 +251,12 @@ HAS_DISPLAY_CUSTOM9=0
HAS_NOTIFY_EIF=0
HAS_NOTIFY_MAIL=0
HAS_NOTIFY_SMS=0
HAS_NOTIFY_SLACK=0
HAS_REPORT_STD=0
# check which core display/notification plugins are installed
# do not use a while-do loop here because mksh/pdksh does not pass updated
# variables back from the sub shell (only works for true ksh88/ksh93)
# shellcheck disable=SC2010,SC2086
# shellcheck disable=SC2010
for FFILE in $(ls -1 ${FPATH_PARENT}/core/*.sh 2>/dev/null | grep -v "include_" 2>/dev/null)
do
case "${FFILE}" in
@ -404,10 +328,6 @@ do
HAS_NOTIFY_EIF=1
(( ARG_DEBUG > 0 )) && debug "notify_eif plugin is available"
;;
*notify_slack.sh)
HAS_NOTIFY_SLACK=1
(( ARG_DEBUG > 0 )) && debug "notify_slack plugin is available"
;;
*report_std.sh)
# shellcheck disable=SC2034
HAS_REPORT_STD=1
@ -565,9 +485,6 @@ then
*mail*) # by mail
DO_NOTIFY_MAIL=1
;;
*slack*) # by Slack
DO_NOTIFY_SLACK=1
;;
*sms*) # by sms
DO_NOTIFY_SMS=1
;;
@ -726,10 +643,8 @@ return 0
function dump_logs
{
log "=== STDOUT ==="
# shellcheck disable=SC2086
log "$(<${HC_STDOUT_LOG})"
log "=== STDERR ==="
# shellcheck disable=SC2086
log "$(<${HC_STDERR_LOG})"
return 0
@ -818,26 +733,24 @@ fi
trap "[[ -f ${TMP_FILE} ]] && rm -f ${TMP_FILE} >/dev/null 2>&1; return 1" 1 2 3 15
# check and rewrite log file(s)
# shellcheck disable=SC2086
find ${LOG_STASH} -type f -print 2>/dev/null | while read -r FIX_FILE
do
log "fixing log file ${FIX_FILE} ..."
# count before rewrite
STASH_COUNT=$(wc -l "${FIX_FILE}" 2>/dev/null | cut -f1 -d' ' 2>/dev/null)
STASH_COUNT=$(wc -l ${FIX_FILE} 2>/dev/null | cut -f1 -d' ' 2>/dev/null)
# does it have errors?
ERROR_COUNT=$(count_log_errors "${FIX_FILE}")
ERROR_COUNT=$(count_log_errors ${FIX_FILE})
# we count the empty lines (again)
EMPTY_COUNT=$(grep -c -E -e '^$' "${FIX_FILE}" 2>/dev/null)
EMPTY_COUNT=$(grep -c -E -e '^$' ${FIX_FILE} 2>/dev/null)
# rewrite if needed
if (( ERROR_COUNT > 0 ))
then
: >"${TMP_FILE}" 2>/dev/null
# shellcheck disable=SC2002
cat "${FIX_FILE}" 2>/dev/null | awk -F"${LOG_SEP}" -v OFS="${LOG_SEP}" '
: >${TMP_FILE} 2>/dev/null
cat ${FIX_FILE} 2>/dev/null | awk -F"${LOG_SEP}" -v OFS="${LOG_SEP}" '
BEGIN { max_log_fields = '"${NUM_LOG_FIELDS}"'
max_fields = (max_log_fields - 1) * 2
@ -913,10 +826,10 @@ do
# correct log line, no rewrite needed
print $0
}
}' >"${TMP_FILE}" 2>/dev/null
}' >${TMP_FILE} 2>/dev/null
# count after rewrite (include empty lines again in the count)
TMP_COUNT=$(wc -l "${TMP_FILE}" 2>/dev/null | cut -f1 -d' ' 2>/dev/null)
TMP_COUNT=$(wc -l ${TMP_FILE} 2>/dev/null | cut -f1 -d' ' 2>/dev/null)
TMP_COUNT=$(( TMP_COUNT + EMPTY_COUNT ))
# bail out when we do not have enough records
@ -927,16 +840,16 @@ do
fi
# swap log file (but create a backup first!)
cp -p "${FIX_FILE}" "${SAVE_TMP_FILE}" 2>/dev/null
cp -p ${FIX_FILE} ${SAVE_TMP_FILE} 2>/dev/null
# shellcheck disable=SC2181
if (( $? == 0 ))
then
mv "${TMP_FILE}" "${FIX_FILE}" 2>/dev/null
mv ${TMP_FILE} ${FIX_FILE} 2>/dev/null
# shellcheck disable=SC2181
if (( $? > 0 ))
then
warn "failed to move/update log file, rolling back"
mv "${SAVE_TMP_FILE}" "${FIX_FILE}" 2>/dev/null
mv ${SAVE_TMP_FILE} ${FIX_FILE} 2>/dev/null
return 2
fi
FIX_RC=1
@ -946,7 +859,7 @@ do
fi
# clean up temporary file(s)
rm -f "${SAVE_TMP_FILE}" "${TMP_FILE}" >/dev/null 2>&1
rm -f ${SAVE_TMP_FILE} ${TMP_FILE} >/dev/null 2>&1
else
log "no fixing needed for ${FIX_FILE}"
fi
@ -957,33 +870,12 @@ done
return ${FIX_RC}
}
# -----------------------------------------------------------------------------
# @(#) FUNCTION: get_disable_comment()
# DOES: retrieve comment for a disabled HC
# EXPECTS: HC name [string]
# OUTPUTS: comment [string]
# RETURNS: 0
# REQUIRES: n/a
function get_disable_comment
{
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
typeset COMMENT_HC="${1}"
if [[ -s "${STATE_PERM_DIR}/${COMMENT_HC}.disabled" ]]
then
cat "${STATE_PERM_DIR}/${COMMENT_HC}.disabled" 2>/dev/null
fi
return 0
}
# -----------------------------------------------------------------------------
# @(#) FUNCTION: handle_hc()
# DOES: handle HC results
# EXPECTS: 1=HC name [string], $HC_MSG_FILE temporary file
# RETURNS: 0 or $HC_STC_RC
# REQUIRES: data_contains_string(), data_is_numeric(), die(), display_*(),
# notify_*(), warn()
# REQUIRES: die(), display_*(), notify_*(), warn()
function handle_hc
{
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
@ -997,21 +889,12 @@ typeset ONE_MSG_TEXT=""
typeset ONE_MSG_CUR_VAL=""
typeset ONE_MSG_EXP_VAL=""
typeset ALL_MSG_STC=0
typeset HC_CACHE_LAST_DATE=""
typeset HC_CACHE_TODAY_DATE=""
typeset HC_CACHE_LAST_NOW="$(date '+%Y-%m-%d %H:%M:%S' 2>/dev/null)" # see also $HC_NOW
typeset HC_CACHE_TODAY_NOW="$(date '+%Y-%m-%d' 2>/dev/null)" # see also $HC_NOW
typeset HC_REPORT_CACHE_LAST_STUB="${STATE_PERM_DIR}/cache.report-last"
typeset HC_REPORT_CACHE_LAST_FILE=""
typeset HC_REPORT_CACHE_TODAY_FILE="${STATE_PERM_DIR}/cache.report-today"
typeset LOG_STRING_GOOD=""
typeset LOG_STRING_FAIL=""
if [[ -s ${HC_MSG_FILE} ]]
then
# load messages file into memory
# do not use array: max 1024 items in ksh88; regular variable is only 32-bit memory limited
HC_MSG_VAR=$(<"${HC_MSG_FILE}")
HC_MSG_VAR=$(<${HC_MSG_FILE})
# DEBUG: dump TMP file
if (( ARG_DEBUG > 0 ))
@ -1029,7 +912,6 @@ else
# nothing to do, respect current EXIT_CODE
if (( EXIT_CODE > 0 ))
then
# shellcheck disable=SC2086
return ${EXIT_CODE}
else
return 0
@ -1247,56 +1129,16 @@ then
ONE_MSG_EXP_VAL=$(data_magic_unquote "${ONE_MSG_EXP_VAL}")
fi
fi
if (( ONE_MSG_STC > 0 ))
then
# build log string
LOG_STRING_FAIL=$(printf "%s${LOG_SEP}%s${LOG_SEP}%s${LOG_SEP}%s${LOG_SEP}%s${LOG_SEP}" "${ONE_MSG_TIME}" "${HC_NAME}" "${ONE_MSG_STC}" "${ONE_MSG_TEXT}" "${HC_FAIL_ID}")
# do atomic log update
# shellcheck disable=SC1117
print "${LOG_STRING_FAIL}" >>"${HC_LOG}"
# cache report (--report --last)
HC_REPORT_CACHE_LAST_FILE="${HC_REPORT_CACHE_LAST_STUB}-${HC_NAME}"
case "${HC_REPORT_CACHE_LAST}" in
Yes|yes|YES)
# fetch date of last cache entry (did we rollover from last HC event?)
HC_CACHE_LAST_DATE=$(tail -n 1 "${HC_REPORT_CACHE_LAST_FILE}" 2>/dev/null | cut -f1 -d"${LOG_SEP}" 2>/dev/null)
if [[ -z "${HC_CACHE_LAST_DATE}" ]] || [[ "${HC_CACHE_LAST_DATE}" != "${HC_CACHE_LAST_NOW}" ]]
then
# set and update cache file
print "${LOG_STRING_FAIL}" >"${HC_REPORT_CACHE_LAST_FILE}"
else
# append cache file
print "${LOG_STRING_FAIL}" >>"${HC_REPORT_CACHE_LAST_FILE}"
fi
;;
*)
# remove cache file if it exists
[[ -f "${HC_REPORT_CACHE_LAST_FILE}" ]] && rm -f "${HC_REPORT_CACHE_LAST_FILE}" >/dev/null 2>/dev/null
;;
esac
# cache report (--report --today)
case "${HC_REPORT_CACHE_TODAY}" in
Yes|yes|YES)
# fetch date of last cache entry (did we rollover midnight?)
HC_CACHE_TODAY_DATE=$(tail -n 1 "${HC_REPORT_CACHE_TODAY_FILE}" 2>/dev/null | cut -f1 -d"${LOG_SEP}" 2>/dev/null | awk '{ print $1 }' 2>/dev/null)
if [[ -z "${HC_CACHE_TODAY_DATE}" ]] || [[ "${HC_CACHE_TODAY_DATE}" != "${HC_CACHE_TODAY_NOW}" ]]
then
# rotate and update cache file
(( ARG_DEBUG > 0 )) && debug "rotating today's cache file at ${HC_REPORT_CACHE_TODAY_FILE}"
print "${LOG_STRING_FAIL}" >"${HC_REPORT_CACHE_TODAY_FILE}"
else
# append cache file
print "${LOG_STRING_FAIL}" >>"${HC_REPORT_CACHE_TODAY_FILE}"
fi
;;
*)
# remove cache file if it exists
[[ -f "${HC_REPORT_CACHE_TODAY_FILE}" ]] && rm -f "${HC_REPORT_CACHE_TODAY_FILE}" >/dev/null 2>/dev/null
;;
esac
printf "%s${LOG_SEP}%s${LOG_SEP}%s${LOG_SEP}%s${LOG_SEP}%s${LOG_SEP}\n" \
"${ONE_MSG_TIME}" \
"${HC_NAME}" \
${ONE_MSG_STC} \
"${ONE_MSG_TEXT}" \
"${HC_FAIL_ID}" >>${HC_LOG}
# RC handling (max/sum/count)
if (( ARG_FLIP_RC > 0 ))
then
@ -1316,53 +1158,13 @@ then
HC_STC_RC=$(( HC_STC_RC + 1 ))
fi
else
# build log string
LOG_STRING_GOOD=$(printf "%s${LOG_SEP}%s${LOG_SEP}%s${LOG_SEP}%s${LOG_SEP}" "${ONE_MSG_TIME}" "${HC_NAME}" "${ONE_MSG_STC}" "${ONE_MSG_TEXT}")
# do atomic log update
# shellcheck disable=SC1117
print "${LOG_STRING_GOOD}" >>"${HC_LOG}"
# cache report (--report --last)
HC_REPORT_CACHE_LAST_FILE="${HC_REPORT_CACHE_LAST_STUB}-${HC_NAME}"
case "${HC_REPORT_CACHE_LAST}" in
Yes|yes|YES)
# fetch date of last cache entry (did we rollover from last HC event?)
HC_CACHE_LAST_DATE=$(tail -n 1 "${HC_REPORT_CACHE_LAST_FILE}" 2>/dev/null | cut -f1 -d"${LOG_SEP}" 2>/dev/null)
if [[ -z "${HC_CACHE_LAST_DATE}" ]] || [[ "${HC_CACHE_LAST_DATE}" != "${HC_CACHE_LAST_NOW}" ]]
then
# set and update cache file
print "${LOG_STRING_GOOD}" >"${HC_REPORT_CACHE_LAST_FILE}"
else
# append cache file
print "${LOG_STRING_GOOD}" >>"${HC_REPORT_CACHE_LAST_FILE}"
fi
;;
*)
# remove cache file if it exists
[[ -f "${HC_REPORT_CACHE_LAST_FILE}" ]] && rm -f "${HC_REPORT_CACHE_LAST_FILE}" >/dev/null 2>/dev/null
;;
esac
# cache report (--report --today)
case "${HC_REPORT_CACHE_TODAY}" in
Yes|yes|YES)
# fetch date of last cache last_entry (did we rollover midnight?)
HC_CACHE_TODAY_DATE=$(tail -n 1 "${HC_REPORT_CACHE_TODAY_FILE}" 2>/dev/null | cut -f1 -d"${LOG_SEP}" 2>/dev/null | awk '{ print $1 }' 2>/dev/null)
if [[ -z "${HC_CACHE_TODAY_DATE}" ]] || [[ "${HC_CACHE_TODAY_DATE}" != "${HC_CACHE_TODAY_NOW}" ]]
then
# rotate and update cache file
(( ARG_DEBUG > 0 )) && debug "rotating today's cache file at ${HC_REPORT_CACHE_TODAY_FILE}"
print "${LOG_STRING_GOOD}" >"${HC_REPORT_CACHE_TODAY_FILE}"
else
# append cache file
print "${LOG_STRING_GOOD}" >>"${HC_REPORT_CACHE_TODAY_FILE}"
fi
;;
*)
# remove cache file if it exists
[[ -f ${HC_REPORT_CACHE_TODAY_FILE} ]] && rm -f "${HC_REPORT_CACHE_TODAY_FILE}" >/dev/null 2>/dev/null
;;
esac
printf "%s${LOG_SEP}%s${LOG_SEP}%s${LOG_SEP}%s${LOG_SEP}\n" \
"${ONE_MSG_TIME}" \
"${HC_NAME}" \
${ONE_MSG_STC} \
"${ONE_MSG_TEXT}" >>${HC_LOG}
fi
done
@ -1379,14 +1181,14 @@ then
then
# cut off the path and the .$$ part from the file location
HC_STDOUT_LOG_SHORT="${HC_STDOUT_LOG##*/}"
mv "${HC_STDOUT_LOG}" "${EVENTS_DIR}/${DIR_PREFIX}/${HC_FAIL_ID}/${HC_STDOUT_LOG_SHORT%.*}" >/dev/null 2>&1 || \
mv ${HC_STDOUT_LOG} "${EVENTS_DIR}/${DIR_PREFIX}/${HC_FAIL_ID}/${HC_STDOUT_LOG_SHORT%.*}" >/dev/null 2>&1 || \
die "failed to move ${HC_STDOUT_LOG} to event directory at ${1}"
fi
if [[ -f ${HC_STDERR_LOG} ]]
then
# cut off the path and the .$$ part from the file location
HC_STDERR_LOG_SHORT="${HC_STDERR_LOG##*/}"
mv "${HC_STDERR_LOG}" "${EVENTS_DIR}/${DIR_PREFIX}/${HC_FAIL_ID}/${HC_STDERR_LOG_SHORT%.*}" >/dev/null 2>&1 || \
mv ${HC_STDERR_LOG} "${EVENTS_DIR}/${DIR_PREFIX}/${HC_FAIL_ID}/${HC_STDERR_LOG_SHORT%.*}" >/dev/null 2>&1 || \
die "failed to move ${HC_STDERR_LOG} to event directory at ${1}"
fi
fi
@ -1425,17 +1227,6 @@ then
warn "notify_sms plugin is not avaible, cannot send alert via sms!"
fi
fi
# by Slack?
if (( DO_NOTIFY_SLACK == 1 ))
then
if (( HAS_NOTIFY_SLACK == 1 ))
then
# call plugin
notify_slack "${HC_NAME}" "${HC_FAIL_ID}"
else
warn "notify_slack plugin is not avaible, cannot send alert via Slack!"
fi
fi
fi
fi
@ -1460,7 +1251,6 @@ fi
function handle_timeout
{
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
# shellcheck disable=SC2086
[[ -n "${CHILD_PID}" ]] && kill -s TERM ${CHILD_PID}
warn "child process with PID ${CHILD_PID} has been forcefully stopped"
# shellcheck disable=SC2034
@ -1590,8 +1380,8 @@ esac
# mangle $ARG_HC to build the full list of HCs to be executed
ARG_HC=""
grep -i '^hc:' "${HOST_CONFIG_FILE}" 2>/dev/null |\
while IFS=':' read -r _ HC_EXEC _ _
grep -i '^hc:' ${HOST_CONFIG_FILE} 2>/dev/null |\
while IFS=':' read _ HC_EXEC _ _
do
ARG_HC="${ARG_HC},${HC_EXEC}"
done
@ -1652,23 +1442,19 @@ case "${OS_NAME}" in
# check system crontabs
if (( CRON_COUNT == 0 ))
then
# shellcheck disable=SC2002,SC2086
CRON_COUNT=$(cat ${CRON_SYS_LOCATIONS} 2>/dev/null | grep -c -E -e "^[^#].*${CRON_HC}" 2>/dev/null)
fi
# check anacron
if (( CRON_COUNT == 0 ))
then
# shellcheck disable=SC2002,SC2086
CRON_COUNT=$(cat ${CRON_ANACRON_LOCATIONS} 2>/dev/null | grep -c -E -e "^[^#].*${CRON_HC}" 2>/dev/null)
fi
;;
*)
# use default root crontab
CRON_COUNT=$(crontab -l 2>/dev/null | grep -c -E -e "^[^#].*${CRON_HC}" 2>/dev/null)
;;
esac
# shellcheck disable=SC2086
return ${CRON_COUNT}
}
@ -1700,11 +1486,11 @@ printf "%80s\n" | tr ' ' -
print "${FPATH}" | tr ':' '\n' 2>/dev/null | grep "core$" | sort 2>/dev/null | while read -r FDIR
do
# exclude core helper librar(y|ies)
# shellcheck disable=SC2010,SC2086
# shellcheck disable=SC2010
ls -1 ${FDIR}/*.sh 2>/dev/null | grep -v "include_" | sort 2>/dev/null | while read -r FFILE
do
# cache script contents in memory
FSCRIPT="$(<${FFILE})"
FSCRIPT=$(<${FFILE})
# reset state
FSTATE="enabled"
@ -1746,12 +1532,12 @@ print -n "Dead links: "
print "${FPATH}" | tr ':' '\n' 2>/dev/null | grep "core$" 2>/dev/null | while read -r FDIR
do
# do not use 'find -type l' here!
# shellcheck disable=SC2010,SC1117,SC2086
# shellcheck disable=SC2010,SC1117
ls ${FDIR} 2>/dev/null | grep -v "\." 2>/dev/null | while read -r FFILE
do
if [[ -h "${FDIR}/${FFILE}" ]] && [[ ! -f "${FDIR}/${FFILE}" ]]
then
printf "%s " "${FFILE##*/}"
printf "%s " ${FFILE##*/}
fi
done
done
@ -1801,44 +1587,21 @@ fi
# print header
if [[ "${FACTION}" != "list" ]]
then
if (( ARG_LIST_DETAILS > 0 ))
then
# shellcheck disable=SC1117
printf "%-40s\t%-8s\t%s\t\t%s\t%s\t%s\t%s\n" "Health Check" "State" "Version" "Config?" "Sched?" "H+?" "Fix?"
# shellcheck disable=SC2183,SC1117
printf "%110s\n" | tr ' ' -
else
# shellcheck disable=SC1117
printf "%-40s\t%-8s\n" "Health Check" "State"
# shellcheck disable=SC2183,SC1117
printf "%60s\n" | tr ' ' -
fi
fi
print "${FPATH}" | tr ':' '\n' 2>/dev/null | grep -v "core$" 2>/dev/null | sort 2>/dev/null |\
while read -r FDIR
do
# shellcheck disable=SC2012,SC2086
ls -1 ${FDIR}/${FNEEDLE} 2>/dev/null | sort 2>/dev/null | while read -r FFILE
do
# cache script contents in memory
FSCRIPT="$(<${FFILE})"
FSCRIPT=$(<${FFILE})
# --list (basic)
# find function name but skip helper functions in the plug-in file (function _name)
FNAME=$(print -R "${FSCRIPT}" | grep -E -e "^function[[:space:]]+[^_]" 2>/dev/null)
# check state
DISABLE_FFILE="$(print ${FFILE##*/} | sed 's/\.sh$//')"
if [[ -f "${STATE_PERM_DIR}/${DISABLE_FFILE}.disabled" ]]
then
FSTATE="disabled"
else
FSTATE="enabled"
fi
# --list-details
if (( ARG_LIST_DETAILS > 0 ))
then
# look for version string (cut off comments but don't use [:space:] in tr)
FVERSION=$(print -R "${FSCRIPT}" | grep '^typeset _VERSION=' 2>/dev/null |\
awk 'match($0,/[0-9]+-[0-9]+-[0-9]+/){print substr($0, RSTART, RLENGTH)}' 2>/dev/null)
@ -1899,7 +1662,14 @@ do
else
FFIX="No"
fi
# check state
DISABLE_FFILE="$(print ${FFILE##*/} | sed 's/\.sh$//')"
if [[ -f "${STATE_PERM_DIR}/${DISABLE_FFILE}.disabled" ]]
then
FSTATE="disabled"
else
FSTATE="enabled"
fi
# reset state when unlinked
[[ -h ${FFILE%%.*} ]] || FSTATE="unlinked"
# check scheduling
@ -1911,12 +1681,9 @@ do
else
FSCHEDULED="Yes"
fi
fi
# show results
if [[ "${FACTION}" != "list" ]]
then
if (( ARG_LIST_DETAILS > 0 ))
then
# shellcheck disable=SC1117
printf "%-40s\t%-8s\t%s\t%s\t%s\t%s\t%s\n" \
@ -1927,12 +1694,6 @@ do
"${FSCHEDULED}" \
"${FHEALTHY}" \
"${FFIX}"
else
# shellcheck disable=SC1117
printf "%-40s\t%-8s\n" \
"${FNAME#function *}" \
"${FSTATE}"
fi
else
# shellcheck disable=SC1117
printf "%s\n" "${FNAME#function *}"
@ -1948,12 +1709,12 @@ then
print "${FPATH}" | tr ':' '\n' 2>/dev/null | grep -v "core" 2>/dev/null | while read -r FDIR
do
# do not use 'find -type l' here!
# shellcheck disable=SC2010,SC1117,SC2086
# shellcheck disable=SC2010,SC1117
ls ${FDIR} 2>/dev/null | grep -v "\." 2>/dev/null | while read -r FFILE
do
if [[ -h "${FDIR}/${FFILE}" ]] && [[ ! -f "${FDIR}/${FFILE}" ]]
then
printf "%s " "${FFILE##*/}"
printf "%s " ${FFILE##*/}
fi
done
done
@ -1967,18 +1728,11 @@ fi
# legend
if [[ "${FACTION}" != "list" ]]
then
if (( ARG_LIST_DETAILS > 0 ))
then
print
print "Config?: plugin has a default configuration file (Yes/No)"
print "Sched? : plugin is scheduled through cron (Yes/No)"
print "H+? : plugin can choose whether to log/show passed health checks (Yes/No/Supported/Not supported)"
print "Fix? : plugin contains fix/healing logic (Yes/No) -- not used by default!"
else
print
print "Tip: use --list-details to see a list of health checks with more details"
fi
fi
return 0
@ -2011,11 +1765,11 @@ printf "%100s\n" | tr ' ' -
print "${FPATH}" | tr ':' '\n' 2>/dev/null | grep "core$" 2>/dev/null | sort 2>/dev/null | while read -r FDIR
do
# exclude core helper librar(y|ies)
# shellcheck disable=SC2010,SC2086
# shellcheck disable=SC2010
ls -1 ${FDIR}/*.sh 2>/dev/null | grep "include_" 2>/dev/null | sort 2>/dev/null | while read -r FFILE
do
# cache script contents in memory
FSCRIPT="$(<${FFILE})"
FSCRIPT=$(<${FFILE})
# find function name
FNAME=$(print -R "${FSCRIPT}" | grep -E -e "^function[[:space:]].*version_" 2>/dev/null)
@ -2048,12 +1802,12 @@ print -n "Dead links: "
print "${FPATH}" | tr ':' '\n' 2>/dev/null | grep "core$" 2>/dev/null | while read -r FDIR
do
# do not use 'find -type l' here!
# shellcheck disable=SC2010,SC1117,SC2086
# shellcheck disable=SC2010,SC1117
ls ${FDIR} 2>/dev/null | grep -v "\." 2>/dev/null | while read -r FFILE
do
if [[ -h "${FDIR}/${FFILE}" ]] && [[ ! -f "${FDIR}/${FFILE}" ]]
then
printf "%s " "${FFILE##*/}"
printf "%s " ${FFILE##*/}
fi
done
done
@ -2084,7 +1838,7 @@ then
then
print - "$*" | while read -r LOG_LINE
do
print "${NOW}: INFO: [$$]:" "${LOG_LINE}" >>"${LOG_FILE}"
print "${NOW}: INFO: [$$]:" "${LOG_LINE}" >>${LOG_FILE}
done
fi
if (( ARG_VERBOSE > 0 ))
@ -2153,7 +1907,7 @@ fi
# save the HC failure message for now
print "${HC_STC}${MSG_SEP}${HC_NOW}${MSG_SEP}${HC_MSG_TEXT}${MSG_SEP}${HC_MSG_CUR_VAL}${MSG_SEP}${HC_MSG_EXP_VAL}" \
>>"${HC_MSG_FILE}"
>>${HC_MSG_FILE}
return 0
}
@ -2208,14 +1962,13 @@ awk -F"${LOG_SEP}" '{
}
}
}
' "${HC_LOG}" 2>/dev/null
' ${HC_LOG} 2>/dev/null
# archived events
print; print
print -R "--- ARCHIVED events --"
print
# shellcheck disable=SC2086
find ${ARCHIVE_DIR} -type f -name "hc.*.log" 2>/dev/null | sort -rn 2>/dev/null | while read -r _ARCHIVE_FILE
find ${ARCHIVE_DIR} -type f -name "hc.*.log" 2>/dev/null | while read -r _ARCHIVE_FILE
do
print "${_ARCHIVE_FILE}:"
awk -F"${LOG_SEP}" '{
@ -2251,7 +2004,7 @@ do
}
}
}
' "${_ARCHIVE_FILE}" 2>/dev/null
' ${_ARCHIVE_FILE} 2>/dev/null
done
return 0
@ -2292,7 +2045,7 @@ then
then
print - "$*" | while read -r LOG_LINE
do
print "${NOW}: WARN: [$$]:" "${LOG_LINE}" >>"${LOG_FILE}"
print "${NOW}: WARN: [$$]:" "${LOG_LINE}" >>${LOG_FILE}
done
fi
if (( ARG_VERBOSE > 0 ))

View File

@ -30,7 +30,7 @@
# RETURNS: 0
function version_include_data
{
typeset _VERSION="2020-12-27" # YYYY-MM-DD
typeset _VERSION="2019-07-14" # YYYY-MM-DD
print "INFO: $0: ${_VERSION#version_*}"
@ -51,7 +51,7 @@ typeset _PARAMETER="${1}"
typeset _LVALUE=""
typeset _RC=0
_LVALUE=$(grep -i "^${_PARAMETER} *=" "${_CONFIG_FILE}" | cut -f2- -d'=')
_LVALUE=$(grep -i "^${_PARAMETER} *=" ${_CONFIG_FILE} | cut -f2- -d'=')
if [[ -n "${_LVALUE}" ]]
then
@ -196,30 +196,10 @@ done
return 0
}
# -----------------------------------------------------------------------------
# @(#) FUNCTION: data_has_newline()
# DOES: checks if a string contains newlines
# EXPECTS: $1=haystack [string]
# OUTPUTS: n/a
# RETURNS: 0=no newline found; 1=newlines found
# REQUIRES: n/a
function data_has_newline
{
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
typeset _HAYSTACK="${1}"
typeset _COUNT=$(print -R "${_HAYSTACK}" | wc -l 2>/dev/null)
(( _COUNT > 1 )) && return 1
return 0
}
# -----------------------------------------------------------------------------
# @(#) FUNCTION: data_magic_quote()
# DOES: magically quotes a needle in a string (default needle is: %)
# EXPECTS: to be magically quoted [string]; $2=needle [string]
# EXPECTS: $1=to be magically quoted [string]; $2=needle [string]
# OUTPUTS: magically quoted [string]
# RETURNS: n/a
# REQUIRES: n/a
@ -613,68 +593,6 @@ esac
return 0
}
# -----------------------------------------------------------------------------
# @(#) FUNCTION: data_expand_numerical_range()
# DOES: expand numerical range (X-Y) to comma-separated list of numbers
# EXPECTS: $1=numerical range [string]
# $2=flag for leading zeroes <10 [0=do not add (default),1=add]
# OUTPUTS: [string]
# RETURNS: 0=no error occurred; <>0=some error occurred
# REQUIRES: n/a
function data_expand_numerical_range
{
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
typeset _NUM_LIST=""
typeset _HAS_LEAD_ZERO=${2:-0}
case "${1}" in
*-*)
# range operator, expand
# check if there are only 2 operands (fields)
if (( $(print "${1}" | awk -F '-' '{ print NF }' 2>/dev/null) > 2 ))
then
(( ARG_DEBUG > 0 )) && debug "in range $1 found more than one range (-) operator"
return 1
fi
# check if X < Y
if print "${1}" | awk -F '-' '{ if ($1 < $2) { exit 1 }}' 2>/dev/null
then
(( ARG_DEBUG > 0 )) && debug "in range $1 operator Y is smaller or equal to operator Y"
return 1
fi
# expand list
_NUM_LIST=$(print "${1}"| awk -F '-' -v has_lead_zero=${_HAS_LEAD_ZERO} '
BEGIN { count = 0; }
{
while ($1 + count <= $2) {
# add leading zero to sprintf when < 10
if (has_lead_zero > 0 && $1 + count < 10) { lead_zero = "0" } else { lead_zero = "" }
if (length (NUM_LIST) == 0) {
NUM_LIST = sprintf ("%" lead_zero "2d", $1 + count);
} else {
NUM_LIST = sprintf ("%s,%" lead_zero "2d", NUM_LIST, $1 + count); }
count++;
}
}
# remove space from end result and print
END { gsub(/[[:space:]]/, "", NUM_LIST); print NUM_LIST; }')
if [[ -z "${_NUM_LIST}" ]]
then
(( ARG_DEBUG > 0 )) && debug "range conversion returned empty list"
return 1
else
print "${_NUM_LIST}"
fi
;;
*)
# no range, return as-is
print "${1}"
;;
esac
return 0
}
# -----------------------------------------------------------------------------
# @(#) FUNCTION: data_encode_url
# DOES: encode URL data
@ -937,7 +855,6 @@ print ${_EPOCH}
# REQUIRES: n/a
function data_epoch2date
{
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
typeset _UNIX_EPOCH="${1}"
typeset _CONVERT_DATE=""
@ -963,154 +880,6 @@ fi
return 0
}
# -----------------------------------------------------------------------------
# @(#) FUNCTION: data_timestring_to_days()
# DOES: converts a specific timestring to days (rounded to integer)
# EXPECTS: time definition with a single s|m|h|d suffix [string]
# OUTPUTS: time value in hours [string]
# RETURNS: 0=conversion OK; 1=conversion failed
# REQUIRES: n/a
function data_timestring_to_days
{
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
typeset _DAYS=""
case "${1}" in
*s|*s)
_DAYS=$(( $(print "${1%*[sS]}") / 60 / 60 / 24 ))
;;
*m|*M)
_DAYS=$(( $(print "${1%*[mM]}") / 60 / 24 ))
;;
*h|*H)
_DAYS=$(( $(print "${1%*[hH]}") / 24 ))
;;
*d|*D)
_DAYS=$(print "${1%*[dD]}")
;;
*)
# invalid suffix specified
(( ARG_DEBUG > 0 )) && debug "invalid time suffix specified (only s[econds]|m[inutes]|h[ours]|d[days] allowed)"
return 1
;;
esac
print "${_DAYS}"
return 0
}
# -----------------------------------------------------------------------------
# @(#) FUNCTION: data_timestring_to_hours()
# DOES: converts a specific timestring to hours (rounded to integer)
# EXPECTS: time definition with a single s|m|h|d suffix [string]
# OUTPUTS: time value in hours [string]
# RETURNS: 0=conversion OK; 1=conversion failed
# REQUIRES: n/a
function data_timestring_to_hours
{
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
typeset _HOURS=""
case "${1}" in
*s|*s)
_HOURS=$(( $(print "${1%*[sS]}") / 60 / 24 ))
;;
*m|*M)
_HOURS=$(( $(print "${1%*[mM]}") / 60 ))
;;
*h|*H)
_HOURS=$(print "${1%*[hH]}")
;;
*d|*D)
_HOURS=$(( $(print "${1%*[dD]}") * 24 ))
;;
*)
# invalid suffix specified
(( ARG_DEBUG > 0 )) && debug "invalid time suffix specified (only s[econds]|m[inutes]|h[ours]|d[days] allowed)"
return 1
;;
esac
print "${_HOURS}"
return 0
}
# -----------------------------------------------------------------------------
# @(#) FUNCTION: data_timestring_to_mins()
# DOES: converts a specific timestring to minutes (rounded to integer)
# EXPECTS: time definition with a single s|m|h|d suffix [string]
# OUTPUTS: time value in minutes [string]
# RETURNS: 0=conversion OK; 1=conversion failed
# REQUIRES: n/a
function data_timestring_to_mins
{
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
typeset _MINUTES=""
case "${1}" in
*s|*s)
_MINUTES=$(( $(print "${1%*[sS]}") / 60 ))
;;
*m|*M)
_MINUTES=$(print "${1%*[mM]}")
;;
*h|*H)
_MINUTES=$(( $(print "${1%*[hH]}") * 60 ))
;;
*d|*D)
_MINUTES=$(( $(print "${1%*[dD]}") * 60 * 24 ))
;;
*)
# invalid suffix specified
(( ARG_DEBUG > 0 )) && debug "invalid time suffix specified (only s[econds]|m[inutes]|h[ours]|d[days] allowed)"
return 1
;;
esac
print "${_MINUTES}"
return 0
}
# -----------------------------------------------------------------------------
# @(#) FUNCTION: data_timestring_to_secs()
# DOES: converts a specific timestring to seconds (rounded to integer)
# EXPECTS: time definition with a single m|h|d suffix [string]
# OUTPUTS: time value in seconds [string]
# RETURNS: 0=conversion OK; 1=conversion failed
# REQUIRES: n/a
function data_timestring_to_secs
{
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
typeset _SECONDS=""
case "${1}" in
*s|*s)
_SECONDS=$(print "${1%*[sS]}")
;;
*m|*M)
_SECONDS=$(( $(print "${1%*[Mm]}") * 60 ))
;;
*h|*H)
_SECONDS=$(( $(print "${1%*[hH]}") * 60 * 60 ))
;;
*d|*D)
_SECONDS=$(( $(print "${1%*[dD]}") * 60 * 60 * 24 ))
;;
*)
# invalid suffix specified
(( ARG_DEBUG > 0 )) && debug "invalid time suffix specified (only s[econds]|m[inutes]|h[ours]|d[days] allowed)"
return 1
;;
esac
print "${_SECONDS}"
return 0
}
#******************************************************************************
# END of script
#******************************************************************************

View File

@ -30,7 +30,7 @@
function notify_mail
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _VERSION="2022-02-16" # YYYY-MM-DD
typeset _VERSION="2019-04-20" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="AIX,HP-UX,Linux" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
@ -58,7 +58,6 @@ typeset _MAIL_ATTACH_BIT=""
typeset _MAIL_METHOD=""
typeset _MAIL_RC=0
typeset _MAILX_BIN=""
typeset _MAILX_ATTACH_SWITCH=""
typeset _MUTT_BIN=""
typeset _SENDMAIL_BIN=""
typeset _UUENCODE_BIN=""
@ -91,17 +90,6 @@ case "${OS_NAME}" in
if [[ -x ${_MAILX_BIN} ]] && [[ -n "${_MAILX_BIN}" ]]
then
_MAIL_METHOD="mailx"
# check which switch we need for attaching a file:
# Debian/Ubuntu: -A file
# Redhat (Heirloom version): -a file
${_MAILX_BIN} -h 2>&1 | grep -q -e "-a FILE" >/dev/null 2>/dev/null
# shellcheck disable=SC2181
if (( $? == 0 ))
then
_MAILX_ATTACH_SWITCH="-a "
else
_MAILX_ATTACH_SWITCH="-A "
fi
else
_MAIL_METHOD="sendmail"
fi
@ -134,18 +122,18 @@ then
[[ -r "${_MAIL_INFO_TPL}" ]] || die "cannot read mail info template at ${_MAIL_INFO_TPL}"
eval "cat << __EOT
$(sed 's/[\$`]/\\&/g;s/<## @\([^ ]*\) ##>/${\1}/g' <${_MAIL_INFO_TPL})
__EOT" >"${_TMP1_MAIL_FILE}"
__EOT" >${_TMP1_MAIL_FILE}
fi
# create header part
[[ -r "${_MAIL_HEADER_TPL}" ]] || die "cannot read mail header template at ${_MAIL_HEADER_TPL}"
eval "cat << __EOT
$(sed 's/[\$`]/\\&/g;s/<## @\([^ ]*\) ##>/${\1}/g' <${_MAIL_HEADER_TPL})
__EOT" >>"${_TMP1_MAIL_FILE}"
print "" >>"${_TMP1_MAIL_FILE}"
__EOT" >>${_TMP1_MAIL_FILE}
print "" >>${_TMP1_MAIL_FILE}
# create body part (from $HC_MSG_VAR)
print "${HC_MSG_VAR}" | while IFS=${MSG_SEP} read -r _MAIL_MSG_STC _ _MAIL_MSG_TEXT _MAIL_MSG_CUR_VAL _MAIL_MSG_EXP_VAL
print "${HC_MSG_VAR}" | while IFS=${MSG_SEP} read _MAIL_MSG_STC _ _MAIL_MSG_TEXT _MAIL_MSG_CUR_VAL _MAIL_MSG_EXP_VAL
do
# magically unquote if needed
if [[ -n "${_MAIL_MSG_TEXT}" ]]
@ -187,8 +175,8 @@ done
[[ -r "${_MAIL_BODY_TPL}" ]] || die "cannot read mail body template at ${_MAIL_BODY_TPL}"
eval "cat << __EOT
$(sed 's/[\$`]/\\&/g;s/<## @\([^ ]*\) ##>/${\1}/g' <${_MAIL_BODY_TPL})
__EOT" >>"${_TMP1_MAIL_FILE}"
print "" >>"${_TMP1_MAIL_FILE}"
__EOT" >>${_TMP1_MAIL_FILE}
print "" >>${_TMP1_MAIL_FILE}
# HC STDOUT log? (drop the .$$ bit)
_MAIL_STDOUT_LOG="${EVENTS_DIR}/${DIR_PREFIX}/${_MAIL_FAIL_ID}/${_HC_STDOUT_LOG_SHORT%.*}"
@ -196,14 +184,7 @@ if [[ -s "${_MAIL_STDOUT_LOG}" ]]
then
# shellcheck disable=SC2034
_MAIL_STDOUT_MSG="${_MAIL_STDOUT_LOG}"
case "${_MAIL_METHOD}" in
"mailx")
_MAIL_ATTACH_BIT="${_MAILX_ATTACH_SWITCH} ${_MAIL_STDOUT_LOG}"
;;
*)
_MAIL_ATTACH_BIT="-a ${_MAIL_STDOUT_LOG}"
;;
esac
else
# shellcheck disable=SC2034
_MAIL_STDOUT_MSG="no log file available"
@ -214,14 +195,7 @@ if [[ -s "${_MAIL_STDERR_LOG}" ]]
then
# shellcheck disable=SC2034
_MAIL_STDERR_MSG="${_MAIL_STDERR_LOG}"
case "${_MAIL_METHOD}" in
"mailx")
_MAIL_ATTACH_BIT="${_MAIL_ATTACH_BIT} ${_MAILX_ATTACH_SWITCH} ${_MAIL_STDERR_LOG}"
;;
*)
_MAIL_ATTACH_BIT="${_MAIL_ATTACH_BIT} -a ${_MAIL_STDERR_LOG}"
;;
esac
else
# shellcheck disable=SC2034
_MAIL_STDERR_MSG="no log file available"
@ -231,29 +205,28 @@ fi
[[ -r ${_MAIL_FOOTER_TPL} ]] || die "cannot read mail body template at ${_MAIL_FOOTER_TPL}"
eval "cat << __EOT
$(sed 's/[\$`]/\\&/g;s/<## @\([^ ]*\) ##>/${\1}/g' <${_MAIL_FOOTER_TPL})
__EOT" >>"${_TMP1_MAIL_FILE}"
__EOT" >>${_TMP1_MAIL_FILE}
# combine and send message components
case "${_MAIL_METHOD}" in
"mailx")
# remove non-ASCII characters to avoid Exchange ATT00001.bin
# shellcheck disable=SC2086
tr -cd '[:print:]\n' < "${_TMP1_MAIL_FILE}" 2>/dev/null |\
cat ${_TMP1_MAIL_FILE} | tr -cd '[:print:]\n' 2>/dev/null |\
${_MAILX_BIN} ${_MAIL_ATTACH_BIT} -s "${_SUBJ_MSG}" "${ARG_MAIL_TO}"
_MAIL_RC=$?
;;
"mutt")
# attach bit goes at the end
# shellcheck disable=SC2086
${_MUTT_BIN} -s "${_SUBJ_MSG}" "${ARG_MAIL_TO}" ${_MAIL_ATTACH_BIT} <"${_TMP1_MAIL_FILE}"
cat ${_TMP1_MAIL_FILE} 2>/dev/null |\
${_MUTT_BIN} -s "${_SUBJ_MSG}" "${ARG_MAIL_TO}" ${_MAIL_ATTACH_BIT}
_MAIL_RC=$?
;;
"sendmail")
[[ -s "${_MAIL_STDOUT_LOG}" ]] && \
uuencode "${_MAIL_STDOUT_LOG}" stdout.log >>"${_TMP2_MAIL_FILE}" 2>/dev/null
uuencode ${_MAIL_STDOUT_LOG} stdout.log >>${_TMP2_MAIL_FILE} 2>/dev/null
[[ -s "${_MAIL_STDERR_LOG}" ]] && \
uuencode "${_MAIL_STDERR_LOG}" stderr.log >>"${_TMP2_MAIL_FILE}" 2>/dev/null
cat "${_TMP1_MAIL_FILE}" "${_TMP2_MAIL_FILE}" 2>/dev/null | ${_SENDMAIL_BIN} -t
uuencode ${_MAIL_STDERR_LOG} stderr.log >>${_TMP2_MAIL_FILE} 2>/dev/null
cat ${_TMP1_MAIL_FILE} ${_TMP2_MAIL_FILE} 2>/dev/null | ${_SENDMAIL_BIN} -t
_MAIL_RC=$?
;;
*)
@ -269,8 +242,8 @@ else
fi
# clean up temporary files
[[ -f ${_TMP1_MAIL_FILE} ]] && rm -f "${_TMP1_MAIL_FILE}" >/dev/null 2>&1
[[ -f ${_TMP2_MAIL_FILE} ]] && rm -f "${_TMP2_MAIL_FILE}" >/dev/null 2>&1
[[ -f ${_TMP1_MAIL_FILE} ]] && rm -f ${_TMP1_MAIL_FILE} >/dev/null 2>&1
[[ -f ${_TMP2_MAIL_FILE} ]] && rm -f ${_TMP2_MAIL_FILE} >/dev/null 2>&1
return 0
}

View File

@ -1,135 +0,0 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) notify_slack.sh
#******************************************************************************
# @(#) Copyright (C) 2022 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: notify_slack
# DOES: send message to slack app
# EXPECTS: 1=HC name [string], 2=HC FAIL_ID [string]
# RETURNS: 0
# REQUIRES: data_contains_string(), data_get_lvalue_from_config(), data_magic_unquote(),
# init_hc(), log(), warn(), curl
#
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
# -----------------------------------------------------------------------------
function notify_slack
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/core/providers/$0.conf"
typeset _VERSION="2022-10-14" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="AIX,HP-UX,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 _SLACK_HC="$1"
typeset _SLACK_FAIL_ID="$2"
typeset _SLACK_TEXT=""
typeset _SLACK_MSG_STC=""
typeset _SLACK_MSG_TEXT=""
typeset _SLACK_MSG_CUR_VAL=""
typeset _SLACK_MSG_EXP_VAL=""
typeset _CURL_BIN=""
typeset _SLACK_WEBHOOK=""
# handle config file
if [[ ! -r ${_CONFIG_FILE} ]]
then
warn "unable to read configuration file at ${_CONFIG_FILE}"
return 1
fi
# read required config values
_SLACK_WEBHOOK=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'SLACK_WEBHOOK')
if [[ -z "${_SLACK_WEBHOOK}" ]]
then
warn "no value set for 'SLACK_WEBHOOK' in ${_CONFIG_FILE}"
return 1
fi
# create header part
_SLACK_TEXT="${EXEC_USER}@${HOST_NAME}: HC ${_SLACK_HC} failed, FAIL_ID=${_SLACK_FAIL_ID}"
# create body part (from $HC_MSG_VAR)
print "${HC_MSG_VAR}" | while IFS=${MSG_SEP} read -r _SLACK_MSG_STC _ _SLACK_MSG_TEXT _SLACK_MSG_CUR_VAL _SLACK_MSG_EXP_VAL
do
# magically unquote if needed
if [[ -n "${_SLACK_MSG_TEXT}" ]]
then
data_contains_string "${_SLACK_MSG_TEXT}" "${MAGIC_QUOTE}"
# shellcheck disable=SC2181
if (( $? > 0 ))
then
_SLACK_MSG_TEXT=$(data_magic_unquote "${_SLACK_MSG_TEXT}")
fi
fi
if [[ -n "${_SLACK_MSG_CUR_VAL}" ]]
then
data_contains_string "${_SLACK_MSG_CUR_VAL}" "${MAGIC_QUOTE}"
# shellcheck disable=SC2181
if (( $? > 0 ))
then
_SLACK_MSG_CUR_VAL=$(data_magic_unquote "${_SLACK_MSG_CUR_VAL}")
fi
fi
if [[ -n "${_SLACK_MSG_EXP_VAL}" ]]
then
data_contains_string "${_SLACK_MSG_EXP_VAL}" "${MAGIC_QUOTE}"
# shellcheck disable=SC2181
if (( $? > 0 ))
then
_SLACK_MSG_EXP_VAL=$(data_magic_unquote "${_SLACK_MSG_EXP_VAL}")
fi
fi
if (( _SLACK_MSG_STC > 0 ))
then
# shellcheck disable=SC1117
_SLACK_BODY=$(printf "%s\n%s\n" "${_SLACK_BODY}" "${_SLACK_MSG_TEXT}")
fi
done
# send message
# find 'curl'
_CURL_BIN="$(command -v curl 2>/dev/null)"
if [[ -x ${_CURL_BIN} ]] && [[ -n "${_CURL_BIN}" ]]
then
if (( ARG_DEBUG == 0 ))
then
${_CURL_BIN} --silent --data-urlencode \
"$(printf 'payload={"text": "%s\n\n%s" }' "${_SLACK_TEXT}" "${_SLACK_BODY}")" \
"${_SLACK_WEBHOOK}" >/dev/null 2>&1
else
${_CURL_BIN} --data-urlencode \
"$(printf 'payload={"text": "%s\n\n%s" }' "${_SLACK_TEXT}" "${_SLACK_BODY}")" \
"${_SLACK_WEBHOOK}"
fi
else
die "unable to send message to Slack - curl is not installed here"
fi
log "Slack alert sent: ${_SLACK_HC} failed, FAIL_ID=${_SLACK_FAIL_ID}"
return 0
}
#******************************************************************************
# END of script
#******************************************************************************

View File

@ -20,8 +20,7 @@
# DOES: send sms alert
# EXPECTS: 1=HC name [string], 2=HC FAIL_ID [string]
# RETURNS: 0
# REQUIRES: data_encode_url(), data_get_lvalue_from_config(), init_hc(),
# log(), warn(), curl
# REQUIRES: data_get_lvalue_from_config(), init_hc(), log(), warn()
#
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
@ -32,7 +31,7 @@ function notify_sms
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/core/providers/$0.conf"
typeset _VERSION="2022-10-14" # YYYY-MM-DD
typeset _VERSION="2018-10-28" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="AIX,HP-UX,Linux" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------

View File

@ -30,7 +30,7 @@
function report_std
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _VERSION="2020-04-08" # YYYY-MM-DD
typeset _VERSION="2019-05-19" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="AIX,HP-UX,Linux" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
@ -59,14 +59,8 @@ typeset _OLDER_MONTH=""
typeset _OLDER_YEAR=""
typeset _NEWER_MONTH=""
typeset _NEWER_YEAR=""
typeset _HC_REPORT_CACHE_LAST_STUB="${STATE_PERM_DIR}/cache.report-last"
typeset _HC_REPORT_CACHE_LAST_FILE=""
typeset _HC_REPORT_CACHE_TODAY_FILE="${STATE_PERM_DIR}/cache.report-today"
typeset _USE_CACHE=0
typeset _USE_ANY_CACHE=0
typeset _CACHE_NOTE_BIT=""
# set archive log stash (never use cache files)
# set archive log stash
if (( ARG_HISTORY > 0 )) || [[ -n "${ARG_OLDER}" ]] || [[ -n "${ARG_NEWER}" ]]
then
set +f # file globbing must be on
@ -154,46 +148,10 @@ then
_HC_LAST_TIME=""
_HC_LAST_STC=0
_HC_LAST_FAIL_ID="-"
_USE_CACHE=0
# check for cache usage
if (( ARG_HISTORY == 0 ))
then
case "${HC_REPORT_CACHE_LAST}" in
Yes|yes|YES)
_HC_REPORT_CACHE_LAST_FILE="${_HC_REPORT_CACHE_LAST_STUB}-${_HC_LAST}"
# check if cache file exists
if [[ -s "${_HC_REPORT_CACHE_LAST_FILE}" ]]
then
_LOG_STASH="${_HC_REPORT_CACHE_LAST_FILE}"
_USE_CACHE=1
_USE_ANY_CACHE=1
(( ARG_DEBUG > 0 )) && debug "setting log stash to cache file at ${_HC_REPORT_CACHE_LAST_FILE}"
else
(( ARG_DEBUG > 0 )) && debug "HC_REPORT_CACHE_LAST is enabled but unable to find cache file at ${_HC_REPORT_CACHE_LAST_FILE}"
# reset log stash to current log
_LOG_STASH="${HC_LOG} ${_LOG_STASH}"
fi
;;
*)
# no caching: reset log stash to current log
(( ARG_DEBUG > 0 )) && debug "HC_REPORT_CACHE_LAST is disabled"
_LOG_STASH="${HC_LOG} ${_LOG_STASH}"
;;
esac
fi
# determine LAST_TIME from cache or log(s)
if (( ARG_HISTORY == 0 )) && (( _USE_CACHE > 1 ))
then
_HC_LAST_TIME="$(tail -n 1 ${_LOG_STASH} 2>/dev/null | cut -f1 -d${LOG_SEP} 2>/dev/null)"
else
# find last event or block of events (same timestamp)
# (but unfortunately this is only accurate to events within the SAME second!)
# shellcheck disable=SC2086
_HC_LAST_TIME="$(grep -h ${_HC_LAST} ${_LOG_STASH} 2>/dev/null | sort -n 2>/dev/null | cut -f1 -d${LOG_SEP} 2>/dev/null | uniq 2>/dev/null | tail -1 2>/dev/null)"
fi
if [[ -z "${_HC_LAST_TIME}" ]]
then
_HC_LAST_TIME="-"
@ -223,26 +181,12 @@ then
fi
# report on findings
# shellcheck disable=SC1117
if (( _USE_CACHE > 0 ))
then
printf "| %-40s | %-20s | %-14s | %-4s (C)\n" \
"${_HC_LAST}" "${_HC_LAST_TIME}" "${_HC_LAST_FAIL_ID}" "${_HC_LAST_STC}"
else
printf "| %-40s | %-20s | %-14s | %-4s\n" \
"${_HC_LAST}" "${_HC_LAST_TIME}" "${_HC_LAST_FAIL_ID}" "${_HC_LAST_STC}"
fi
done
# spacer
print
# disclaimer & note(s)
if (( _USE_ANY_CACHE > 0 ))
then
print "NOTE: entries suffixed by (C) indicate results were retrieved from a cache file. If you wish to use "
print " the real log files then disable HC_REPORT_CACHE_LAST in ${CONFIG_FILE}"
fi
(( ARG_HISTORY == 0 )) && _CACHE_NOTE_BIT="for non-cached entries: "
print "NOTE: ${_CACHE_NOTE_BIT}this report only shows the overall combined status of all events of each HC"
print " within exactly the *same* time stamp (seconds precise). It may therefore fail to report certain FAIL IDs."
# disclaimer
print "NOTE: this report only shows the overall combined status of all events of each HC within exactly"
print " the *same* time stamp (seconds precise). It may therefore fail to report certain FAIL IDs."
print " Use '--report' to get the exact list of failure events."
# other reports
else
@ -254,31 +198,7 @@ else
(( _IS_VALID_ID > 0 )) || die "invalid ID specified"
_ID_NEEDLE="${ARG_FAIL_ID}"
fi
# set today's needle and check cache usage
if (( ARG_TODAY > 0 ))
then
_ID_NEEDLE="$(date '+%Y%m%d')" # refers to timestamp of HC FAIL_ID
# do not use a cache file when --with-history
if (( ARG_HISTORY == 0 ))
then
case "${HC_REPORT_CACHE_TODAY}" in
Yes|yes|YES)
# check if cache file exists
if [[ -s "${_HC_REPORT_CACHE_TODAY_FILE}" ]]
then
_LOG_STASH="${_HC_REPORT_CACHE_TODAY_FILE}"
_USE_CACHE=1
(( ARG_DEBUG > 0 )) && debug "setting log stash to today's cache file at ${_HC_REPORT_CACHE_TODAY_FILE}"
else
(( ARG_DEBUG > 0 )) && debug "HC_REPORT_CACHE_TODAY is enabled but unable to find cache file at ${_HC_REPORT_CACHE_TODAY_FILE}"
fi
;;
*)
(( ARG_DEBUG > 0 )) && debug "HC_REPORT_CACHE_TODAY is disabled"
;;
esac
fi
fi
(( ARG_TODAY > 0 )) && _ID_NEEDLE="$(date '+%Y%m%d')" # refers to timestamp of HC FAIL_ID
# reverse?
if (( ARG_REVERSE == 0 ))
@ -342,9 +262,9 @@ else
split (events[i], event, "|");
printf ("\n| %-20s | %-14s | %-40s | %-s", event[1], event[5], event[2], event[4]);
}
printf ("\n\nSUMMARY: %s failed HC event(s) found.\n\n", event_count);
printf ("\n\nSUMMARY: %s failed HC event(s) found.\n", event_count);
} else {
printf ("\nSUMMARY: 0 failed HC events found.\n\n");
printf ("\nSUMMARY: 0 failed HC events found.\n");
}
}
' 2>/dev/null
@ -396,23 +316,14 @@ else
# shellcheck disable=SC2183,SC1117
printf "%80s\n" | tr ' ' -
fi
# add notes
# cache or not?
if (( _USE_CACHE > 0 ))
then
print "NOTE: results were retrieved from a cache file. If you wish to use the real log files then"
print " remove ${_HC_REPORT_CACHE_TODAY_FILE} and/or disable HC_REPORT_CACHE_TODAY in ${CONFIG_FILE}"
fi
fi
# add general notes
# history or not?
# general note: history or not?
if (( ARG_HISTORY > 0 ))
then
print "NOTE: showing results with all history (archive) included (--with-history)"
else
print "NOTE: showing only results of current entries (use --with-history to view all entries)"
print "NOTE: showing results only of current log entries (use --with-history to view all entries)"
fi
# check consistency of log(s)

View File

@ -29,8 +29,6 @@
# @(#) 2019-01-24: arguments fix [Patrick Van der Veken]
# @(#) 2019-03-09: added support for --log-healthy [Patrick Van der Veken]
# @(#) 2019-03-16: replace 'which' [Patrick Van der Veken]
# @(#) 2020-09-05: fix log_hc call for failed checksum + quote fix [Patrick Van der Veken]
# @(#) 2021-01-13: fix log_hc call (wrong logic) [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
@ -40,7 +38,7 @@ function check_aix_file_change
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _VERSION="2021-01-13" # YYYY-MM-DD
typeset _VERSION="2019-03-16" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
@ -277,7 +275,7 @@ do
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_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}"
@ -287,7 +285,7 @@ do
cksum-crc32)
if (( _USE_CKSUM == 1 ))
then
_FILE_CKSUM=$(${_CKSUM_BIN} "${_FILE_TO_CHECK}" 2>>${HC_STDERR_LOG} | cut -f1 -d' ')
_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}"
@ -303,11 +301,11 @@ do
# 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_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_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}"
@ -323,7 +321,7 @@ do
fi
# bounce failures back and jump to next file
if (( _LOG_HEALTHY > 0 && _STC > 0 ))
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
continue
@ -349,7 +347,7 @@ do
printf "%s|%s|%s\n" "${_FILE_TO_CHECK}" "${_FILE_TYPE}" "${_FILE_CKSUM}" >>${_TMP2_FILE}
# report with curr/exp values
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
if (( _LOG_HEALTHY > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}" "${_FILE_CKSUM}" "${_STATE_FILE_CKSUM}"
continue

View File

@ -1,349 +0,0 @@
#!/usr/bin/env ksh
#------------------------------------------------------------------------------
# @(#) check_aix_uptime
#------------------------------------------------------------------------------
# @(#) Copyright (C) 2020 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#------------------------------------------------------------------------------
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_aix_uptime
# DOES: see _show_usage()
# EXPECTS: see _show_usage()
# REQUIRES: data_is_numeric(), data_timestring_to_mins(), data_comma2space(),
# init_hc(), log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2020-12-21: initial version [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#------------------------------------------------------------------------------
# -----------------------------------------------------------------------------
function check_aix_uptime
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _STATE_FILE="${STATE_PERM_DIR}/current.uptime"
typeset _VERSION="2020-12-21" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="AIX" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _LOG_HEALTHY=0
typeset _CFG_HEALTHY=""
typeset _CFG_CHECK_REBOOT=""
typeset _CFG_REBOOT_TIME=""
typeset _CFG_CHECK_OLD_AGE=""
typeset _CFG_OLD_AGE_TIME=""
typeset _CHECK_REBOOT=""
typeset _REBOOT_TIME=""
typeset _REBOOT_TIME_MINS=""
typeset _CHECK_OLD_AGE=""
typeset _OLD_AGE_TIME=""
typeset _OLD_AGE_TIME_MINS=""
typeset _CURRENT_UPTIME=""
typeset _CURRENT_UPTIME_MINS=""
typeset _INIT_TIME=""
typeset _PREVIOUS_UPTIME=""
typeset _PREVIOUS_UPTIME_MINS=""
typeset _THRESHOLD_UPTIME_MINS=""
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage "$0" "${_VERSION}" "${_CONFIG_FILE}" && return 0
;;
esac
done
# handle config file
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
if [[ ! -r ${_CONFIG_FILE} ]]
then
warn "unable to read configuration file at ${_CONFIG_FILE}"
return 1
fi
# read required config values
_CFG_HEALTHY=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'log_healthy')
case "${_CFG_HEALTHY}" in
yes|YES|Yes)
_LOG_HEALTHY=1
;;
*)
# do not override hc_arg
(( _LOG_HEALTHY > 0 )) || _LOG_HEALTHY=0
;;
esac
_CFG_CHECK_REBOOT=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'check_reboot')
case "${_CFG_CHECK_REBOOT}" in
no|No|NO)
_CHECK_REBOOT=0
;;
*)
_CHECK_REBOOT=1
;;
esac
_CFG_REBOOT_TIME=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'reboot_time')
if [[ -z "${_CFG_REBOOT_TIME}" ]]
then
# default
_REBOOT_TIME="60m"
else
_REBOOT_TIME="${_CFG_REBOOT_TIME}"
fi
_CFG_CHECK_OLD_AGE=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'check_old_age')
case "${_CFG_CHECK_OLD_AGE}" in
yes|Yes|Yes)
_CHECK_OLD_AGE=1
;;
*)
_CHECK_OLD_AGE=0
;;
esac
_CFG_OLD_AGE_TIME=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'old_age_time')
if [[ -z "${_CFG_OLD_AGE_TIME}" ]]
then
# default
_OLD_AGE_TIME="365d"
else
_OLD_AGE_TIME="${_CFG_OLD_AGE_TIME}"
fi
# log_healthy
(( ARG_LOG_HEALTHY > 0 )) && _LOG_HEALTHY=1
if (( _LOG_HEALTHY > 0 ))
then
if (( ARG_LOG > 0 ))
then
log "logging/showing passed health checks"
else
log "showing passed health checks (but not logging)"
fi
else
log "not logging/showing passed health checks"
fi
#------------------------------------------------------------------------------
# read uptime from init process
# shellcheck disable=SC1007
_INIT_TIME=$(UNIX95= ps -p 1 -o etime 2>/dev/null | tail -1)
if [[ -n "${_INIT_TIME}" ]]
then
# calculate exact uptime (seconds)
_CURRENT_UPTIME=$(print "${_INIT_TIME}" |\
awk '
BEGIN { days = 0; hours = 0; mins = 0; seconds = 0 };
{
gsub(/[ \t]/, "");
# get days
split ($0, day_str, "-");
if (2 in day_str) {
# string has days
days = day_str[1];
split (day_str[2], hour_str, ":");
} else {
split (day_str[1], hour_str, ":");
}
# get hours/minutes/seconds
hours = hour_str[1];
mins = hour_str[2];
if (3 in hour_str) {
# string has seconds
secs = hour_str[3];
}
}
END {
time = (days * 24 * 60 * 60) + (hours * 60 * 60) + (mins * 60) + secs;
print time;
}' 2>/dev/null)
data_is_numeric "${_CURRENT_UPTIME}"
# shellcheck disable=SC2181
if (( $? > 0 ))
then
warn "unable to calculate uptime value (seconds)"
(( ARG_DEBUG )) && debug "_CURRENT_UPTIME=${_CURRENT_UPTIME}"
return 1
fi
else
warn "uptime of INIT (1) process cannot be determined"
return 1
fi
#------------------------------------------------------------------------------
# read state file
if [[ -r ${_STATE_FILE} ]]
then
_PREVIOUS_UPTIME=$(<"${_STATE_FILE}")
# shellcheck disable=SC2181
if (( $? > 0 ))
then
warn "failed to read state file at ${_STATE_FILE}"
_PREVIOUS_UPTIME=""
fi
fi
#------------------------------------------------------------------------------
# convert uptimes values
_CURRENT_UPTIME_MINS=$(( _CURRENT_UPTIME / 60 ))
data_is_numeric "${_CURRENT_UPTIME_MINS}"
# shellcheck disable=SC2181
if (( $? > 0 ))
then
warn "unable to calculate current uptime value (minutes)"
(( ARG_DEBUG )) && debug "_CURRENT_UPTIME_MINS=${_CURRENT_UPTIME_MINS}"
return 1
fi
_PREVIOUS_UPTIME_MINS=$(( _PREVIOUS_UPTIME / 60 ))
data_is_numeric "${_CURRENT_UPTIME_MINS}"
# shellcheck disable=SC2181
if (( $? > 0 ))
then
warn "unable to calculate previous uptime value (minutes)"
(( ARG_DEBUG )) && debug "_PREVIOUS_UPTIME_MINS=${_PREVIOUS_UPTIME_MINS}"
return 1
fi
#------------------------------------------------------------------------------
# check reboot event
if (( _CHECK_REBOOT > 0 ))
then
# convert _REBOOT_TIME to minutes
_REBOOT_TIME_MINS=$(data_timestring_to_mins "${_REBOOT_TIME}")
data_is_numeric "${_REBOOT_TIME_MINS}"
# shellcheck disable=SC2181
if (( $? > 0 ))
then
warn "unable to calculate 'reboot_time' value from configuration file ${_CONFIG_FILE}"
(( ARG_DEBUG )) && debug "_REBOOT_TIME=${_REBOOT_TIME}"
return 1
fi
# previous uptime missing?
if [[ -z "${_PREVIOUS_UPTIME}" ]]
then
if (( ARG_LOG > 0 ))
then
print "${_CURRENT_UPTIME}" >"${_STATE_FILE}"
# shellcheck disable=SC2181
if (( $? > 0 ))
then
warn "failed to update state file at ${_STATE_FILE}"
return 1
else
log "unable to find previously recorded uptime, resetting to current uptime"
return 0
fi
else
log "unable to find previously recorded uptime, resetting to current uptime"
fi
else
# current uptime + reboot time is smaller than previous uptime?
_THRESHOLD_UPTIME_MINS=$(( _CURRENT_UPTIME_MINS + _REBOOT_TIME_MINS ))
if (( _THRESHOLD_UPTIME_MINS < _PREVIOUS_UPTIME_MINS ))
then
_MSG="reboot check: current uptime is NOK; check if reboot occurred"
_STC=1
else
_MSG="reboot check: current uptime is OK"
_STC=0
fi
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}" "${_THRESHOLD_UPTIME_MINS}" "${_PREVIOUS_UPTIME_MINS}"
fi
# update state file
if (( ARG_LOG > 0 ))
then
print "${_CURRENT_UPTIME}" >"${_STATE_FILE}"
# shellcheck disable=SC2181
if (( $? > 0 ))
then
warn "failed to update state file at ${_STATE_FILE}"
return 1
fi
fi
else
log "reboot check: not enabled"
fi
#------------------------------------------------------------------------------
# check old age event
if (( _CHECK_OLD_AGE > 0 ))
then
# convert _OLD_AGE_TIME to minutes
_OLD_AGE_TIME_MINS=$(data_timestring_to_mins "${_OLD_AGE_TIME}")
data_is_numeric "${_OLD_AGE_TIME_MINS}"
# shellcheck disable=SC2181
if (( $? > 0 ))
then
warn "unable to calculate 'old_age_time' value from configuration file ${_CONFIG_FILE}"
(( ARG_DEBUG )) && debug "_OLD_AGE_TIME=${_OLD_AGE_TIME}"
return 1
fi
# are we old age yet?
if (( _CURRENT_UPTIME_MINS > _OLD_AGE_TIME_MINS ))
then
_MSG="old_age check: current uptime is NOK; old age has arrived (>${_OLD_AGE_TIME})"
_STC=1
else
_MSG="old_age check: current uptime is OK"
_STC=0
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}" "${_CURRENT_UPTIME_MINS}" "${_OLD_AGE_TIME_MINS}"
fi
else
log "old age check: not enabled"
fi
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with:
log_healthy=<yes|no>
check_reboot=<yes|no>
reboot_time=<timestring>
check_old_age=<yes|no>
old_age_time=<timestring>
PURPOSE : Checks for unexpected/unplanned reboot events based on uptime
values.
Checks whether the host has been up and running for too much time.
LOG HEALTHY : Supported
EOT
return 0
}
#------------------------------------------------------------------------------
# END of script
#------------------------------------------------------------------------------

View File

@ -1,171 +0,0 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_exadata_ib_status.sh
#******************************************************************************
# @(#) Copyright (C) 2020 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_exadata_ib_status
# DOES: see _show_usage()
# EXPECTS: see _show_usage()
# REQUIRES: data_comma2space(), dump_logs(), init_hc(), log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2020-07-07: initial version [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_exadata_ib_status
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _VERSION="2020-07-07" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
typeset _IBSTATUS_BIN="/usr/sbin/ibstatus"
typeset _IBSWITCHES_BIN="/usr/sbin/ibswitches"
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _LOG_HEALTHY=0
typeset _IBSTATUS_OUTPUT=""
typeset _IBSWITCHES_OUTPUT=""
typeset _NUM_INACTIVE_PORTS=0
typeset _NUM_SWITCHES=0
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
esac
done
# log_healthy
(( ARG_LOG_HEALTHY > 0 )) && _LOG_HEALTHY=1
if (( _LOG_HEALTHY > 0 ))
then
if (( ARG_LOG > 0 ))
then
log "logging/showing passed health checks"
else
log "showing passed health checks (but not logging)"
fi
else
log "not logging/showing passed health checks"
fi
# check IB tools
if [[ ! -x ${_IBSTATUS_BIN} || -z "${_IBSWITCHES_BIN}" ]]
then
warn "IB tools are not installed here. This is not an Exadata compute node?"
return 1
fi
# gather infiniband status data
(( ARG_DEBUG > 0 )) && debug "executing command {${_IBSTATUS_BIN}}"
_IBSTATUS_OUTPUT=$(${_IBSTATUS_BIN} 2>>${HC_STDERR_LOG})
# shellcheck disable=SC2181
if (( $?> 0 )) || [[ -z "${_IBSTATUS_OUTPUT}" ]]
then
_MSG="unable to run command {${_IBSTATUS_BIN}}"
_STC=2
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
return 1
fi
(( ARG_DEBUG > 0 )) && debug "executing command {${_IBSWITCHES_BIN}}"
_IBSWITCHES_OUTPUT=$(${_IBSWITCHES_BIN} 2>>${HC_STDERR_LOG})
# shellcheck disable=SC2181
if (( $?> 0 )) || [[ -z "${_IBSWITCHES_OUTPUT}" ]]
then
_MSG="unable to run command {${_IBSWITCHES_BIN}}"
_STC=2
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
return 1
fi
# perform checks on IB status data
_NUM_INACTIVE_PORTS=$(print -R "${_IBSTATUS_OUTPUT}" | grep -E -e '^[[:space:]]+state:' 2>/dev/null | grep -c -v "ACTIVE" 2>/dev/null)
if (( _HAS_OFFLINE_PORTS > 0 ))
then
_MSG="${_NUM_INACTIVE_PORTS} IB port(s) are/is in state INACTIVE"
_STC=1
else
_MSG="all IB port(s) are/is in ACTIVE state"
_STC=0
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
# perform checks on IB switches data
_NUM_SWITCHES=$(print -R "${_IBSWITCHES_OUTPUT}" | wc -l 2>/dev/null)
if (( _NUM_SWITCHES != 2 ))
then
_MSG="only ${_NUM_SWITCHES} IB switch(es) are/is reporting (${_NUM_SWITCHES}<>2)"
_STC=1
else
_MSG="${_NUM_SWITCHES} IB switch(es) are/is reporting"
_STC=0
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
# add IB output to stdout log
print "==== {${_IBSTATUS_BIN}} ====" >>${HC_STDOUT_LOG}
print "${_IBSTATUS_OUTPUT}" >>${HC_STDOUT_LOG}
print "==== {${_IBSWITCHES_BIN}} ====" >>${HC_STDOUT_LOG}
print "${_IBSWITCHES_OUTPUT}" >>${HC_STDOUT_LOG}
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
PURPOSE : 1) Checks that (local) Infiniband ports are in active
2) Checks that Infiniband switches are present (should be 2)
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************

View File

@ -19,10 +19,8 @@
# @(#) MAIN: check_exadata_zfs_share_replication
# DOES: see _show_usage()
# EXPECTS: see _show_usage()
# REQUIRES: data_comma2space(), data_contains_string(), data_expand_numerical_range(),
# data_get_lvalue_from_config(), data_has_newline(), data_is_numeric(),
# data_lc(), data_strip_space(), dump_logs(), init_hc(), linux_exec_ssh(),
# log_hc(), warn()
# REQUIRES: data_comma2space(), data_contains_string(), data_get_lvalue_from_config(),
# dump_logs(), init_hc(), linux_exec_ssh(), log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2019-02-18: initial version [Patrick Van der Veken]
@ -30,10 +28,7 @@
# @(#) 2019-03-16: replace 'which' [Patrick Van der Veken]
# @(#) 2019-04-12: small fixes [Patrick Van der Veken]
# @(#) 2019-05-14: small fixes [Patrick Van der Veken]
# @(#) 2020-01-27: addition of day check option +
# @(#) newline config value check [Patrick Van der Veken]
# @(#) 2020-03-05: addition of hour check option + fix
# @(#) 2020-03-26: fix for expanding numerical range
# @(#) 2019-07-05: help fix [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
@ -43,7 +38,7 @@ function check_exadata_zfs_share_replication
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _VERSION="2020-03-26" # YYYY-MM-DD
typeset _VERSION="2019-07-05" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
# replication query script -- DO NOT CHANGE --
# prj1/share1:true:idle:success:111
@ -80,17 +75,12 @@ typeset _CFG_SSH_USER=""
typeset _CFG_ZFS_HOSTS=""
typeset _CFG_ZFS_HOST=""
typeset _CFG_ZFS_LINE=""
typeset _CFG_REPLICATION_DAYS=""
typeset _CFG_REPLICATION_HOURS=""
typeset _REPLICATION_ENABLED=""
typeset _REPLICATION_HOURS=""
typeset _REPLICATION_LAG=""
typeset _REPLICATION_RESULT=""
typeset _SSH_BIN=""
typeset _SSH_OUTPUT=""
typeset _ZFS_DATA=""
typeset _WEEKDAY=$(data_lc "$(date '+%a' 2>/dev/null)") # Sun
typeset _HOUR=$(data_strip_space "$(date '+%H' 2>/dev/null)") # 7,23 etc
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
@ -220,8 +210,6 @@ do
_CFG_REPLICATION_ENABLED=""
_CFG_REPLICATION_RESULT=""
_CFG_REPLICATION_LAG=""
_CFG_REPLICATION_DAYS=""
_CFG_REPLICATION_HOURS=""
# which values to use (general or custom?), keep in mind wildcards (custom will overrule wildcard entry)
_CFG_ZFS_LINE=$(grep -E -e "^zfs:${_ZFS_HOST}:[*]:" ${_CONFIG_FILE} 2>/dev/null)
@ -231,8 +219,6 @@ do
_CFG_REPLICATION_ENABLED=$(print "${_CFG_ZFS_LINE}" | cut -f4 -d':' 2>/dev/null)
_CFG_REPLICATION_RESULT=$(print "${_CFG_ZFS_LINE}" | cut -f5 -d':' 2>/dev/null)
_CFG_REPLICATION_LAG=$(print "${_CFG_ZFS_LINE}" | cut -f6 -d':' 2>/dev/null)
_CFG_REPLICATION_DAYS=$(print "${_CFG_ZFS_LINE}" | cut -f7 -d':' 2>/dev/null)
_CFG_REPLICATION_HOURS=$(print "${_CFG_ZFS_LINE}" | cut -f8 -d':' 2>/dev/null)
# null value means general threshold
if [[ -z "${_CFG_REPLICATION_LAG}" ]]
then
@ -243,19 +229,10 @@ do
_CFG_ZFS_LINE=$(grep -E -e "^zfs:${_ZFS_HOST}:${_REPLICATION_NAME}:" ${_CONFIG_FILE} 2>/dev/null)
if [[ -n "${_CFG_ZFS_LINE}" ]]
then
data_has_newline "${_CFG_ZFS_LINE}"
# shellcheck disable=SC2181
if (( $? > 0 ))
then
warn "ignoring ${_ZFS_HOST}:${_REPLICATION_NAME} because it parses to multiple results in ${_CONFIG_FILE}"
continue
fi
(( ARG_DEBUG > 0 )) && debug "found custom definition for ${_ZFS_HOST}:${_REPLICATION_NAME} in configuration file ${_CONFIG_FILE}"
_CFG_REPLICATION_ENABLED=$(print "${_CFG_ZFS_LINE}" | cut -f4 -d':' 2>/dev/null)
_CFG_REPLICATION_RESULT=$(print "${_CFG_ZFS_LINE}" | cut -f5 -d':' 2>/dev/null)
_CFG_REPLICATION_LAG=$(print "${_CFG_ZFS_LINE}" | cut -f6 -d':' 2>/dev/null)
_CFG_REPLICATION_DAYS=$(print "${_CFG_ZFS_LINE}" | cut -f7 -d':' 2>/dev/null)
_CFG_REPLICATION_HOURS=$(print "${_CFG_ZFS_LINE}" | cut -f8 -d':' 2>/dev/null)
# null value means general threshold
if [[ -z "${_CFG_REPLICATION_LAG}" ]]
then
@ -285,25 +262,8 @@ do
# fixed defaults if missing
[[ -z "${_CFG_REPLICATION_ENABLED}" || "${_CFG_REPLICATION_ENABLED}" = '*' ]] && _CFG_REPLICATION_ENABLED="true"
[[ -z "${_CFG_REPLICATION_RESULT}" || "${_CFG_REPLICATION_RESULT}" = '*' ]] && _CFG_REPLICATION_RESULT="success"
_CFG_REPLICATION_DAYS=$(data_lc "${_CFG_REPLICATION_DAYS}")
[[ -z "${_CFG_REPLICATION_DAYS}" || "${_CFG_REPLICATION_DAYS}" = '*' ]] && _CFG_REPLICATION_DAYS="${_WEEKDAY}"
if [[ -z "${_CFG_REPLICATION_HOURS}" || "${_CFG_REPLICATION_HOURS}" = '*' ]]
then
_REPLICATION_HOURS="${_HOUR}"
else
# expand range with leading zeroes
_REPLICATION_HOURS=$(data_expand_numerical_range "${_CFG_REPLICATION_HOURS}" 1)
fi
# perform checks
# do we need to perform the check today?
data_contains_string "${_CFG_REPLICATION_DAYS}" "${_WEEKDAY}"
if (( $? > 0 ))
then
# do we need to perform the check this hour?
data_contains_string "${_REPLICATION_HOURS}" "${_HOUR}"
if (( $? > 0 ))
then
# check replication enabled state (active or not?)
if [[ $(data_lc "${_REPLICATION_ENABLED}") != $(data_lc "${_CFG_REPLICATION_ENABLED}") ]]
then
@ -353,12 +313,6 @@ do
then
log_hc "$0" ${_STC} "${_MSG}" "${_REPLICATION_LAG}" "${_CFG_REPLICATION_LAG}"
fi
else
warn "check of ${_ZFS_HOST}:${_REPLICATION_NAME} is only configured for this/these hour(s): ${_REPLICATION_HOURS}"
fi
else
warn "check of ${_ZFS_HOST}:${_REPLICATION_NAME} is not configured for today"
fi
done
return 0
@ -374,10 +328,11 @@ CONFIG : $3 with parameters:
log_healthy=<yes|no>
ssh_user=<ssh_user_account>
ssh_key_file=<ssh_private_key_file>
ssh_opts=<ssh_options>
max_replication_lag=<general_max_replication>
and formatted stanzas of:
zfs:<host_name>:<replication_name>:<replication_enabled>:<replication_result>:<max_replication_lag>:<day1,day2>:<start_hour>-<end_hour>
PURPOSE : Checks the replication state, sync status and maximum lag of the configured ZFS hosts/shares on certain days
zfs:<host_name>:<replication_name>:<replication_enabled>:<replication_result>:<max_replication_lag>
PURPOSE : Checks the replication state, sync status and maximum lag of the configured ZFS hosts/shares
CLI: zfs > shares > replications > packages > select (action) > show
LOG HEALTHY : Supported

View File

@ -19,8 +19,8 @@
# @(#) MAIN: check_exadata_zfs_share_usage
# DOES: see _show_usage()
# EXPECTS: see _show_usage()
# REQUIRES: data_comma2space(), data_get_lvalue_from_config, data_has_newline(),
# dump_logs(), init_hc(), linux_exec_ssh(), log_hc(), warn()
# REQUIRES: data_comma2space(), data_get_lvalue_from_config, dump_logs(),
# init_hc(), linux_exec_ssh(), log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2019-02-18: initial version [Patrick Van der Veken]
@ -28,7 +28,7 @@
# @(#) 2019-04-09: fix bad math in ZFS script & HC message [Patrick Van der Veken]
# @(#) 2019-04-12: small fixes [Patrick Van der Veken]
# @(#) 2019-05-14: small fixes [Patrick Van der Veken]
# @(#) 2020-01-27: newline config value check [Patrick Van der Veken]
# @(#) 2019-07-05: help fix [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
@ -38,7 +38,7 @@ function check_exadata_zfs_share_usage
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _VERSION="2020-01-27" # YYYY-MM-DD
typeset _VERSION="2019-07-05" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
# usage query script -- DO NOT CHANGE --
# prj1:share1:16
@ -233,13 +233,6 @@ do
_CFG_ZFS_LINE=$(grep -E -e "^zfs:${_ZFS_HOST}:${_PROJECT_NAME}:${_SHARE_NAME}:" ${_CONFIG_FILE} 2>/dev/null)
if [[ -n "${_CFG_ZFS_LINE}" ]]
then
data_has_newline "${_CFG_ZFS_LINE}"
# shellcheck disable=SC2181
if (( $? > 0 ))
then
warn "ignoring ${_ZFS_HOST}:${_PROJECT_NAME}:${_SHARE_NAME} because it parses to multiple results in ${_CONFIG_FILE}"
continue
fi
(( ARG_DEBUG > 0 )) && debug "found custom definition for ${_ZFS_HOST}:${_PROJECT_NAME}/${_SHARE_NAME} in configuration file ${_CONFIG_FILE}"
_CFG_SPACE_THRESHOLD=$(print "${_CFG_ZFS_LINE}" | cut -f5 -d':' 2>/dev/null)
# null value means general threshold
@ -297,6 +290,7 @@ CONFIG : $3 with parameters:
log_healthy=<yes|no>
ssh_user=<ssh_user_account>
ssh_key_file=<ssh_private_key_file>
ssh_opts=<ssh_options>
max_space_usage=<general_max_space_treshold>
and formatted stanzas of:
zfs:<host_name>:<project_name>:<share_name>:<max_space_threshold>

View File

@ -19,13 +19,12 @@
# @(#) MAIN: check_hpux_cron_status
# DOES: see _show_usage()
# EXPECTS: n/a
# REQUIRES: data_is_numeric(), data_comma2space(), init_hc(), log_hc()
# REQUIRES: data_comma2space(), init_hc(), log_hc()
#
# @(#) HISTORY:
# @(#) 2018-02-08: initial version [Patrick Van der Veken]µ
# @(#) 2018-02-13: fix to avoid log check if cron is not active [Patrick Van der Veken]
# @(#) 2019-03-16: replace 'which' [Patrick Van der Veken]
# @(#) 2021-03-25: make _WAIT_TIME & _CRON_LOG_FILE configurable [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
@ -34,25 +33,20 @@
function check_hpux_cron_status
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _VERSION="2021-03-25" # YYYY-MM-DD
typeset _CRON_LOG_FILE="/var/adm/cron/log"
typeset _WAIT_TIME=10
typeset _VERSION="2019-02-16" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="HP-UX" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _CFG_HEALTHY=""
typeset _LOG_HEALTHY=0
typeset _CFG_CRON_LOG_FILE=""
typeset _CFG_WAIT_TIME=""
typeset _LOG_HEALTHY=0
typeset _CRON_LOG_FILE=""
typeset _WAIT_TIME=""
typeset _JOB_ID=""
typeset _AT_BIN=""
@ -61,56 +55,11 @@ for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage "${0}" "${_VERSION}" "${_CONFIG_FILE}" && return 0
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
esac
done
# handle configuration file
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
if [[ ! -r ${_CONFIG_FILE} ]]
then
warn "unable to read configuration file at ${_CONFIG_FILE}"
return 1
fi
_CFG_WAIT_TIME=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'wait_time')
if [[ -z "${_CFG_WAIT_TIME}" ]]
then
# default
_WAIT_TIME=10
log "setting value for parameter wait_time to its default (${_WAIT_TIME})"
else
data_is_numeric "${_CFG_WAIT_TIME}"
# shellcheck disable=SC2181
if (( $? > 0 ))
then
warn "wait time parameter is not numeric in configuration file ${_CONFIG_FILE}"
return 1
else
_WAIT_TIME=${_CFG_WAIT_TIME}
fi
fi
_CFG_CRON_LOG_FILE=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'cron_log')
if [[ -z "${_CFG_CRON_LOG_FILE}" ]]
then
# default
_CRON_LOG_FILE="/var/adm/cron/log"
log "setting value for parameter cron_log to its default (${_CRON_LOG_FILE})"
else
_CRON_LOG_FILE="${_CFG_CRON_LOG_FILE}"
log "setting value for parameter cron_log (${_CRON_LOG_FILE})"
fi
_CFG_HEALTHY=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'log_healthy')
case "${_CFG_HEALTHY}" in
yes|YES|Yes)
_LOG_HEALTHY=1
;;
*)
# do not override hc_arg
(( _LOG_HEALTHY > 0 )) || _LOG_HEALTHY=0
;;
esac
# log_healthy
(( ARG_LOG_HEALTHY > 0 )) && _LOG_HEALTHY=1
if (( _LOG_HEALTHY > 0 ))
@ -125,20 +74,10 @@ else
log "not logging/showing passed health checks"
fi
# check timeout (_WAIT_TIME must be at least 30 secs smaller than health check timeout)
if (( _WAIT_TIME > 0 ))
then
if (( (_WAIT_TIME + 30) > HC_TIME_OUT ))
then
warn "wait time value will conflict with health check timeout. Specify a (larger) --timeout value"
return 1
fi
fi
# ---- process state ----
# try the pgrep way (note: old pgreps do not support '-c')
(( ARG_DEBUG > 0 )) && debug "checking cron service via pgrep"
(( $(pgrep -u root cron 2>>"${HC_STDERR_LOG}" | wc -l 2>/dev/null) == 0 )) && _STC=1
(( $(pgrep -u root cron 2>>${HC_STDERR_LOG} | wc -l 2>/dev/null) == 0 )) && _STC=1
# evaluate results
case ${_STC} in
@ -160,30 +99,18 @@ then
fi
# ---- log state ----
# check cron log file
if [[ ! -r ${_CRON_LOG_FILE} ]]
then
_MSG="cron log does not exist (${_CRON_LOG_FILE})"
_STC=1
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" 1 "${_MSG}"
fi
return 0
fi
# create test event
_AT_BIN=$(command -v at 2>>"${HC_STDERR_LOG}")
_AT_BIN="$(command -v at 2>>${HC_STDERR_LOG})"
if [[ -x ${_AT_BIN} && -n "${_AT_BIN}" ]]
then
# start test job
(( ARG_DEBUG > 0 )) && debug "checking cron log via {${_AT_BIN}}"
(echo "*** CHECK LOG ***" >/dev/null | ${_AT_BIN} now) >>"${HC_STDOUT_LOG}" 2>>"${HC_STDERR_LOG}"
sleep "${_WAIT_TIME}"
if (( $(grep -c 'cron may not be running' "${HC_STDERR_LOG}" 2>/dev/null) == 0 ))
(echo "*** CHECK LOG ***" >/dev/null | ${_AT_BIN} now) >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG}
sleep ${_WAIT_TIME}
if (( $(grep -c 'cron may not be running' ${HC_STDERR_LOG} 2>/dev/null) == 0 ))
then
# find job results
_JOB_ID=$(grep -E -e '^job' "${HC_STDERR_LOG}" 2>/dev/null | awk '{ print $2}' 2>/dev/null)
if [[ -n "${_JOB_ID}" ]] && (( $(grep -c "${_JOB_ID}" "${_CRON_LOG_FILE}" 2>/dev/null) > 0 ))
_JOB_ID=$(grep -E -e '^job' ${HC_STDERR_LOG} 2>/dev/null | awk '{ print $2}' 2>/dev/null)
if [[ -n "${_JOB_ID}" ]] && (( $(grep -c "${_JOB_ID}" ${_CRON_LOG_FILE} 2>/dev/null) > 0 ))
then
_MSG="cron is logging correctly, schedule via {${_AT_BIN}} OK"
_STC=0
@ -198,7 +125,7 @@ then
else
# check cron log itself
(( ARG_DEBUG > 0 )) && debug "checking cron log via file check"
if [[ -s ${_CRON_LOG_FILE} ]]
if [[ -r ${_CRON_LOG_FILE} ]] && [[ -s ${_CRON_LOG_FILE} ]]
then
_MSG="cron is logging correctly (${_CRON_LOG_FILE})"
_STC=0
@ -221,12 +148,9 @@ function _show_usage
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with parameters:
log_healthy=<yes|no>
wait_time=<seconds>
cron_log=<file_path>
CONFIG : $3
PURPOSE : Checks whether cron (CRON) service is running and whether cron is
actually logging to the cron log file.
actually logging to ${_CRON_LOG_FILE}.
LOG HEALTHY : Supported
EOT

View File

@ -1,212 +0,0 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_hpux_defunct_processes.sh
#******************************************************************************
# @(#) Copyright (C) 2021 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#******************************************************************************
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_hpux_defunct_processes
# DOES: see _show_usage()
# EXPECTS: n/a
# REQUIRES: data_comma2space(), data_is_numeric(), init_hc(), log_hc()
#
# @(#) HISTORY:
# @(#) 2021-04-07: initial version [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_hpux_defunct_processes
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _VERSION="2021-04-07" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="HP-UX" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _CFG_GROUP_BY_PPID=""
typeset _GROUP_BY_PPID=""
typeset _CFG_PROCESS_THRESHOLD=""
typeset _PROCESS_THRESHOLD=""
typeset _CFG_HEALTHY=""
typeset _LOG_HEALTHY=0
typeset _DEFUNCT_PROCS=""
typeset _NUM_DEFUNCT_PROCS=""
typeset _PPID=""
# 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_PROCESS_THRESHOLD=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'process_threshold')
if [[ -z "${_CFG_PROCESS_THRESHOLD}" ]]
then
# default
_PROCESS_THRESHOLD=10
log "setting value for parameter process_threshold to its default (10)"
else
data_is_numeric "${_CFG_PROCESS_THRESHOLD}"
# shellcheck disable=SC2181
if (( $? > 0 ))
then
warn "value for parameter process_threshold in configuration file ${_CONFIG_FILE} is invalid"
return 1
else
_PROCESS_THRESHOLD=${_CFG_PROCESS_THRESHOLD}
log "setting value for parameter collect_interval (${_PROCESS_THRESHOLD})"
fi
fi
_CFG_GROUP_BY_PPID=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'group_by_ppid')
case "${_CFG_GROUP_BY_PPID}" in
no|NO|No)
_GROUP_BY_PPID=0
log "setting value for parameter group_by_ppid (No)"
;;
*)
# default
_GROUP_BY_PPID=1
log "setting value for parameter group_by_ppid to its default (Yes)"
;;
esac
_CFG_HEALTHY=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'log_healthy')
case "${_CFG_HEALTHY}" in
yes|YES|Yes)
_LOG_HEALTHY=1
;;
*)
# do not override hc_arg
(( _LOG_HEALTHY > 0 )) || _LOG_HEALTHY=0
;;
esac
# log_healthy
(( ARG_LOG_HEALTHY > 0 )) && _LOG_HEALTHY=1
if (( _LOG_HEALTHY > 0 ))
then
if (( ARG_LOG > 0 ))
then
log "logging/showing passed health checks"
else
log "showing passed health checks (but not logging)"
fi
else
log "not logging/showing passed health checks"
fi
# collect defunct processes
# shellcheck disable=SC2009
_DEFUNCT_PROCS=$(UNIX95=1 ps -eo ppid,pid,comm,etime 2>"${HC_STDERR_LOG}" | tee -a "${HC_STDOUT_LOG}" 2>/dev/null | grep '[d]efunct' 2>/dev/null)
# check defunct processes
if [[ -z "${_DEFUNCT_PROCS}" ]]
then
_MSG="no defunct process(es) detected"
_STC=0
if (( _LOG_HEALTHY > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
return 0
else
if (( _GROUP_BY_PPID > 0 ))
then
# per by PPID
print -R "${_DEFUNCT_PROCS}" | awk '
{
# count PIDs per PPID
counts[$1]++;
}
END {
for (i in counts) print i ":" counts[i]
}' 2>/dev/null | while IFS=":" read -r _PPID _NUM_DEFUNCT_PROCS
do
(( ARG_DEBUG > 0 )) && debug "awk found PPID: ${_PPID} with # procs: ${_NUM_DEFUNCT_PROCS}"
if (( _NUM_DEFUNCT_PROCS <= _PROCESS_THRESHOLD ))
then
_MSG="defunct process(es) detected for PPID (${_PPID}) but are still under threshold (${_NUM_DEFUNCT_PROCS}<=${_PROCESS_THRESHOLD})"
_STC=0
else
_MSG="defunct process(es) detected for PPID (${_PPID}) and are over threshold (${_NUM_DEFUNCT_PROCS}>${_PROCESS_THRESHOLD})"
_STC=1
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}" "${_NUM_DEFUNCT_PROCS}" "${_PROCESS_THRESHOLD}"
fi
done
else
_NUM_DEFUNCT_PROCS=$(print -R "${_DEFUNCT_PROCS}" | wc -l 2>/dev/null)
if (( _NUM_DEFUNCT_PROCS <= _PROCESS_THRESHOLD ))
then
_MSG="defunct process(es) detected but are still under threshold (${_NUM_DEFUNCT_PROCS}<=${_PROCESS_THRESHOLD})"
_STC=0
else
_MSG="defunct process(es) detected and are over threshold (${_NUM_DEFUNCT_PROCS}>${_PROCESS_THRESHOLD})"
_STC=1
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}" "${_NUM_DEFUNCT_PROCS}" "${_PROCESS_THRESHOLD}"
fi
fi
fi
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with parameters:
log_healthy=<yes|no>
process_threshold=<#_of_processes>
group_by_ppid=<yes|no>
PURPOSE : Checks whether there are (too many) defunct processes on the host.
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************

View File

@ -29,8 +29,6 @@
# @(#) 2019-01-24: arguments fix [Patrick Van der Veken]
# @(#) 2019-03-09: added support for --log-healthy [Patrick Van der Veken]
# @(#) 2019-03-16: replace 'which' [Patrick Van der Veken]
# @(#) 2020-09-05: fix log_hc call for failed checksum + quote fix [Patrick Van der Veken]
# @(#) 2021-01-13: fix log_hc call (wrong logic) [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
@ -40,7 +38,7 @@ function check_hpux_file_change
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _VERSION="2021-01-13" # YYYY-MM-DD
typeset _VERSION="2019-03-16" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="HP-UX" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
@ -277,7 +275,7 @@ do
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_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}"
@ -287,7 +285,7 @@ do
cksum-crc32)
if (( _USE_CKSUM == 1 ))
then
_FILE_CKSUM=$(${_CKSUM_BIN} "${_FILE_TO_CHECK}" 2>>${HC_STDERR_LOG} | cut -f1 -d' ')
_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}"
@ -303,11 +301,11 @@ do
# 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_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_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}"
@ -323,7 +321,7 @@ do
fi
# bounce failures back and jump to next file
if (( _LOG_HEALTHY > 0 && _STC > 0 ))
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
continue
@ -349,7 +347,7 @@ do
printf "%s|%s|%s\n" "${_FILE_TO_CHECK}" "${_FILE_TYPE}" "${_FILE_CKSUM}" >>${_TMP2_FILE}
# report with curr/exp values
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
if (( _LOG_HEALTHY > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}" "${_FILE_CKSUM}" "${_STATE_FILE_CKSUM}"
continue

View File

@ -32,7 +32,6 @@
# @(#) 2018-10-28: fixed (linter) errors [Patrick Van der Veken]
# @(#) 2019-01-24: arguments fix [Patrick Van der Veken]
# @(#) 2019-03-09: added support for --log-healthy [Patrick Van der Veken]
# @(#) 2021-04-07: quotes & shellcheck fixes [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
@ -44,13 +43,13 @@ function check_hpux_ioscan
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _IOSCAN_BIN="/usr/sbin/ioscan"
typeset _IOSCAN_OPTS="-Fn"
typeset _VERSION="2021-04-07" # YYYY-MM-DD
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="HP-UX" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
init_hc "${0}" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
@ -72,7 +71,7 @@ for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage "${0}" "${_VERSION}" "${_CONFIG_FILE}" && return 0
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
esac
done
@ -155,8 +154,7 @@ else
_IOSCAN_OPTS="${_IOSCAN_OPTS}u"
fi
log "executing ioscan with options: ${_IOSCAN_OPTS}"
${_IOSCAN_BIN} ${_IOSCAN_OPTS} >>"${HC_STDOUT_LOG}" 2>>"${HC_STDERR_LOG}"
# shellcheck disable=SC2181
${_IOSCAN_BIN} ${_IOSCAN_OPTS} >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG}
if (( $? > 0 ))
then
_MSG="unable to run command: {${_IOSCAN_BIN}}"
@ -168,13 +166,13 @@ else
fi
# check for requested device classes
grep -E -e ".*:.*:.*:.*:.*:.*:.*:.*:${_IOSCAN_CLASSES}:.*" "${HC_STDOUT_LOG}" 2>/dev/null |\
while read -r _IOSCAN_LINE
grep -E -e ".*:.*:.*:.*:.*:.*:.*:.*:${_IOSCAN_CLASSES}:.*" ${HC_STDOUT_LOG} 2>/dev/null |\
while read _IOSCAN_LINE
do
# possible states are: CLAIMED, UNCLAIMED, DIFF_HW, NO_HW, ERROR, SCAN
_HW_CLASS=$(print "${_IOSCAN_LINE}" | cut -f9 -d':')
_HW_PATH=$(print "${_IOSCAN_LINE}" | cut -f11 -d':')
_HW_STATE=$(print "${_IOSCAN_LINE}" | cut -f16 -d':')
_HW_CLASS="$(print ${_IOSCAN_LINE} | cut -f9 -d':')"
_HW_PATH="$(print ${_IOSCAN_LINE} | cut -f11 -d':')"
_HW_STATE="$(print ${_IOSCAN_LINE} | cut -f16 -d':')"
case "${_HW_STATE}" in
NO_HW)
@ -216,6 +214,7 @@ function _show_usage
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with:
CONFIG : $3 with parameters:
log_healthy=<yes|no>
ioscan_classes=<list_of_device_classes_to_check>

View File

@ -30,7 +30,6 @@
# @(#) with offset calculation [Patrick Van der Veken]
# @(#) 2019-01-24: arguments fix [Patrick Van der Veken]
# @(#) 2019-03-09: Text updates [Patrick Van der Veken]
# @(#) 2020-12-21: fixes for --log-healthy [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#------------------------------------------------------------------------------
@ -40,14 +39,14 @@ function check_hpux_ntp_status
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _VERSION="2020-12-21" # YYYY-MM-DD
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="HP-UX" # uname -s match
typeset _NTPQ_BIN="/usr/sbin/ntpq"
typeset _NTPQ_OPTS="-pn"
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
@ -66,7 +65,7 @@ for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage "$0" "${_VERSION}" "${_CONFIG_FILE}" && return 0
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
esac
done
@ -149,10 +148,7 @@ case "${_NTP_PEER}" in
_MSG="NTP is synchronizing against ${_NTP_PEER##*\*}"
;;
esac
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
log_hc "$0" ${_STC} "${_MSG}"
# 2) offset value
if (( _STC == 0 ))
@ -169,10 +165,7 @@ then
else
_MSG="NTP offset of ${_CURR_OFFSET} is within the acceptable range"
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
;;
*)
# not numeric

View File

@ -26,7 +26,6 @@
# @(#) 2019-01-24: arguments fix [Patrick Van der Veken]
# @(#) 2019-03-09: added support for --log-healthy [Patrick Van der Veken]
# @(#) 2019-03-16: replace 'which' [Patrick Van der Veken]
# @(#) 2020-12-27: add configuration check + quoting fixes [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
@ -35,17 +34,16 @@
function check_hpux_postfix_status
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _VERSION="2020-12-27" # YYYY-MM-DD
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="HP-UX" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _POSTFIX_BIN=""
typeset _POSTFIX_CHECKER=""
typeset _MSG=""
typeset _STC=0
typeset _LOG_HEALTHY=0
@ -55,7 +53,7 @@ for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage "$0" "${_VERSION}" "${_CONFIG_FILE}" && return 0
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
esac
done
@ -74,14 +72,10 @@ else
log "not logging/showing passed health checks"
fi
#-------------------------------------------------------------------------------
# process state
_POSTFIX_BIN="$(command -v postfix 2>>${HC_STDERR_LOG})"
if [[ -x ${_POSTFIX_BIN} && -n "${_POSTFIX_BIN}" ]]
then
${_POSTFIX_BIN} status >>"${HC_STDOUT_LOG}" 2>>"${HC_STDERR_LOG}"
# shellcheck disable=SC2181
${_POSTFIX_BIN} status >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG}
if (( $? == 0 ))
then
_MSG="postfix is running"
@ -93,35 +87,13 @@ else
warn "postfix is not installed here"
return 1
fi
# report result
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
#-------------------------------------------------------------------------------
# configuration state
_POSTFIX_CHECKER="$(command -v postconf 2>>${HC_STDERR_LOG})"
if [[ -x ${_POSTFIX_CHECKER} && -n "${_POSTFIX_CHECKER}" ]]
then
# dump configuration
${_POSTFIX_CHECKER} -n >>"${HC_STDOUT_LOG}" 2>>"${HC_STDERR_LOG}"
# shellcheck disable=SC2181
if (( $? > 0 ))
then
_MSG="postfix configuration files have syntax error(s) {${_POSTFIX_CHECKER} -n}"
_STC=1
else
_MSG="postfix configuration files are syntactically correct"
_STC=0
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
else
warn "skipping syntax check (unable to find syntax check tool)"
fi
return 0
}
@ -131,8 +103,7 @@ function _show_usage
cat <<- EOT
NAME : $1
VERSION : $2
PURPOSE : Checks whether postfix (mail system) is running and whether the
postfix configuration files are syntactically correct
PURPOSE : Checks whether postfix (mail system) is running
LOG HEALTHY : Supported
EOT

View File

@ -26,7 +26,6 @@
# @(#) 2018-02-13: fix to avoid log check if syslogd is not active [Patrick Van der Veken]
# @(#) 2019-03-09: text updates [Patrick Van der Veken]
# @(#) 2019-03-16: replace 'which' [Patrick Van der Veken]
# @(#) 2019-10-07: fixed syslog.log checking [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
@ -36,8 +35,8 @@ function check_hpux_syslogd_status
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _SYSLOGD_PID_FILE="/var/run/syslog.pid"
typeset _SYSLOGD_LOG_FILE="/var/adm/syslog/syslog.log"
typeset _VERSION="2019-10-07" # YYYY-MM-DD
typeset _SYSLOGD_LOG_FILE="/var/adm/syslog.log"
typeset _VERSION="2019-03-16" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="HP-UX" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
@ -122,26 +121,9 @@ then
fi
# ---- log state ----
# check syslog.log
(( ARG_DEBUG > 0 )) && debug "checking syslogd log via file check"
if [[ -r ${_SYSLOGD_LOG_FILE} ]] && [[ -s ${_SYSLOGD_LOG_FILE} ]]
_LOGGER_BIN="$(command -v logger 2>>${HC_STDERR_LOG})"
if [[ -x ${_LOGGER_BIN} && -n "${_LOGGER_BIN}" ]]
then
_MSG="syslog.log is present (${_SYSLOGD_LOG_FILE})"
_STC=0
else
_MSG="syslog.log is not present or empty (${_SYSLOGD_LOG_FILE})"
_STC=1
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
# check logger if syslog.log check did not fail
if (( _STC == 0 ))
then
_LOGGER_BIN="$(command -v logger 2>>${HC_STDERR_LOG})"
if [[ -x ${_LOGGER_BIN} && -n "${_LOGGER_BIN}" ]]
then
# write test entry
(( ARG_DEBUG > 0 )) && debug "checking syslogd log via {${_LOGGER_BIN}}"
${_LOGGER_BIN} -i -t "check_health" "*** LOG CHECK ***" >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG}
@ -153,14 +135,22 @@ then
_MSG="syslogd is not logging (correctly), write via {${_LOGGER_BIN}} NOK"
_STC=1
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
else
# check the syslog itself
(( ARG_DEBUG > 0 )) && debug "checking syslogd log via file check"
if [[ -r ${_SYSLOGD_LOG_FILE} ]] && [[ -s ${_SYSLOGD_LOG_FILE} ]]
then
log_hc "$0" ${_STC} "${_MSG}"
fi
_MSG="syslogd is logging correctly (${_CRON_LOG_FILE})"
_STC=0
else
(( ARG_DEBUG > 0 )) && debug "no logger facility found, skipping logger check"
_MSG="syslogd is not logging (correctly) (${_SYSLOGD_LOG_FILE})"
_STC=1
fi
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
return 0
}

View File

@ -1,349 +0,0 @@
#!/usr/bin/env ksh
#------------------------------------------------------------------------------
# @(#) check_hpux_uptime
#------------------------------------------------------------------------------
# @(#) Copyright (C) 2020 by KUDOS BVBA (info@kudos.be). All rights reserved.
#
# This program is a free software; you can redistribute it and/or modify
# it under the same terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
#------------------------------------------------------------------------------
#
# DOCUMENTATION (MAIN)
# -----------------------------------------------------------------------------
# @(#) MAIN: check_hpux_uptime
# DOES: see _show_usage()
# EXPECTS: see _show_usage()
# REQUIRES: data_is_numeric(), data_timestring_to_mins(), data_comma2space(),
# init_hc(), log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2020-12-21: initial version [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#------------------------------------------------------------------------------
# -----------------------------------------------------------------------------
function check_hpux_uptime
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _STATE_FILE="${STATE_PERM_DIR}/current.uptime"
typeset _VERSION="2020-12-21" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="HP-UX" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _LOG_HEALTHY=0
typeset _CFG_HEALTHY=""
typeset _CFG_CHECK_REBOOT=""
typeset _CFG_REBOOT_TIME=""
typeset _CFG_CHECK_OLD_AGE=""
typeset _CFG_OLD_AGE_TIME=""
typeset _CHECK_REBOOT=""
typeset _REBOOT_TIME=""
typeset _REBOOT_TIME_MINS=""
typeset _CHECK_OLD_AGE=""
typeset _OLD_AGE_TIME=""
typeset _OLD_AGE_TIME_MINS=""
typeset _CURRENT_UPTIME=""
typeset _CURRENT_UPTIME_MINS=""
typeset _INIT_TIME=""
typeset _PREVIOUS_UPTIME=""
typeset _PREVIOUS_UPTIME_MINS=""
typeset _THRESHOLD_UPTIME_MINS=""
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage "$0" "${_VERSION}" "${_CONFIG_FILE}" && return 0
;;
esac
done
# handle config file
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
if [[ ! -r ${_CONFIG_FILE} ]]
then
warn "unable to read configuration file at ${_CONFIG_FILE}"
return 1
fi
# read required config values
_CFG_HEALTHY=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'log_healthy')
case "${_CFG_HEALTHY}" in
yes|YES|Yes)
_LOG_HEALTHY=1
;;
*)
# do not override hc_arg
(( _LOG_HEALTHY > 0 )) || _LOG_HEALTHY=0
;;
esac
_CFG_CHECK_REBOOT=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'check_reboot')
case "${_CFG_CHECK_REBOOT}" in
no|No|NO)
_CHECK_REBOOT=0
;;
*)
_CHECK_REBOOT=1
;;
esac
_CFG_REBOOT_TIME=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'reboot_time')
if [[ -z "${_CFG_REBOOT_TIME}" ]]
then
# default
_REBOOT_TIME="60m"
else
_REBOOT_TIME="${_CFG_REBOOT_TIME}"
fi
_CFG_CHECK_OLD_AGE=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'check_old_age')
case "${_CFG_CHECK_OLD_AGE}" in
yes|Yes|Yes)
_CHECK_OLD_AGE=1
;;
*)
_CHECK_OLD_AGE=0
;;
esac
_CFG_OLD_AGE_TIME=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'old_age_time')
if [[ -z "${_CFG_OLD_AGE_TIME}" ]]
then
# default
_OLD_AGE_TIME="365d"
else
_OLD_AGE_TIME="${_CFG_OLD_AGE_TIME}"
fi
# log_healthy
(( ARG_LOG_HEALTHY > 0 )) && _LOG_HEALTHY=1
if (( _LOG_HEALTHY > 0 ))
then
if (( ARG_LOG > 0 ))
then
log "logging/showing passed health checks"
else
log "showing passed health checks (but not logging)"
fi
else
log "not logging/showing passed health checks"
fi
#------------------------------------------------------------------------------
# read uptime from init process
# shellcheck disable=SC1007
_INIT_TIME=$(UNIX95= ps -p 1 -o etime 2>/dev/null | tail -1)
if [[ -n "${_INIT_TIME}" ]]
then
# calculate exact uptime (seconds)
_CURRENT_UPTIME=$(print "${_INIT_TIME}" |\
awk '
BEGIN { days = 0; hours = 0; mins = 0; seconds = 0 };
{
gsub(/[ \t]/, "");
# get days
split ($0, day_str, "-");
if (2 in day_str) {
# string has days
days = day_str[1];
split (day_str[2], hour_str, ":");
} else {
split (day_str[1], hour_str, ":");
}
# get hours/minutes/seconds
hours = hour_str[1];
mins = hour_str[2];
if (3 in hour_str) {
# string has seconds
secs = hour_str[3];
}
}
END {
time = (days * 24 * 60 * 60) + (hours * 60 * 60) + (mins * 60) + secs;
print time;
}' 2>/dev/null)
data_is_numeric "${_CURRENT_UPTIME}"
# shellcheck disable=SC2181
if (( $? > 0 ))
then
warn "unable to calculate uptime value (seconds)"
(( ARG_DEBUG )) && debug "_CURRENT_UPTIME=${_CURRENT_UPTIME}"
return 1
fi
else
warn "uptime of INIT (1) process cannot be determined"
return 1
fi
#------------------------------------------------------------------------------
# read state file
if [[ -r ${_STATE_FILE} ]]
then
_PREVIOUS_UPTIME=$(<"${_STATE_FILE}")
# shellcheck disable=SC2181
if (( $? > 0 ))
then
warn "failed to read state file at ${_STATE_FILE}"
_PREVIOUS_UPTIME=""
fi
fi
#------------------------------------------------------------------------------
# convert uptimes values
_CURRENT_UPTIME_MINS=$(( _CURRENT_UPTIME / 60 ))
data_is_numeric "${_CURRENT_UPTIME_MINS}"
# shellcheck disable=SC2181
if (( $? > 0 ))
then
warn "unable to calculate current uptime value (minutes)"
(( ARG_DEBUG )) && debug "_CURRENT_UPTIME_MINS=${_CURRENT_UPTIME_MINS}"
return 1
fi
_PREVIOUS_UPTIME_MINS=$(( _PREVIOUS_UPTIME / 60 ))
data_is_numeric "${_CURRENT_UPTIME_MINS}"
# shellcheck disable=SC2181
if (( $? > 0 ))
then
warn "unable to calculate previous uptime value (minutes)"
(( ARG_DEBUG )) && debug "_PREVIOUS_UPTIME_MINS=${_PREVIOUS_UPTIME_MINS}"
return 1
fi
#------------------------------------------------------------------------------
# check reboot event
if (( _CHECK_REBOOT > 0 ))
then
# convert _REBOOT_TIME to minutes
_REBOOT_TIME_MINS=$(data_timestring_to_mins "${_REBOOT_TIME}")
data_is_numeric "${_REBOOT_TIME_MINS}"
# shellcheck disable=SC2181
if (( $? > 0 ))
then
warn "unable to calculate 'reboot_time' value from configuration file ${_CONFIG_FILE}"
(( ARG_DEBUG )) && debug "_REBOOT_TIME=${_REBOOT_TIME}"
return 1
fi
# previous uptime missing?
if [[ -z "${_PREVIOUS_UPTIME}" ]]
then
if (( ARG_LOG > 0 ))
then
print "${_CURRENT_UPTIME}" >"${_STATE_FILE}"
# shellcheck disable=SC2181
if (( $? > 0 ))
then
warn "failed to update state file at ${_STATE_FILE}"
return 1
else
log "unable to find previously recorded uptime, resetting to current uptime"
return 0
fi
else
log "unable to find previously recorded uptime, resetting to current uptime"
fi
else
# current uptime + reboot time is smaller than previous uptime?
_THRESHOLD_UPTIME_MINS=$(( _CURRENT_UPTIME_MINS + _REBOOT_TIME_MINS ))
if (( _THRESHOLD_UPTIME_MINS < _PREVIOUS_UPTIME_MINS ))
then
_MSG="reboot check: current uptime is NOK; check if reboot occurred"
_STC=1
else
_MSG="reboot check: current uptime is OK"
_STC=0
fi
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}" "${_THRESHOLD_UPTIME_MINS}" "${_PREVIOUS_UPTIME_MINS}"
fi
# update state file
if (( ARG_LOG > 0 ))
then
print "${_CURRENT_UPTIME}" >"${_STATE_FILE}"
# shellcheck disable=SC2181
if (( $? > 0 ))
then
warn "failed to update state file at ${_STATE_FILE}"
return 1
fi
fi
else
log "reboot check: not enabled"
fi
#------------------------------------------------------------------------------
# check old age event
if (( _CHECK_OLD_AGE > 0 ))
then
# convert _OLD_AGE_TIME to minutes
_OLD_AGE_TIME_MINS=$(data_timestring_to_mins "${_OLD_AGE_TIME}")
data_is_numeric "${_OLD_AGE_TIME_MINS}"
# shellcheck disable=SC2181
if (( $? > 0 ))
then
warn "unable to calculate 'old_age_time' value from configuration file ${_CONFIG_FILE}"
(( ARG_DEBUG )) && debug "_OLD_AGE_TIME=${_OLD_AGE_TIME}"
return 1
fi
# are we old age yet?
if (( _CURRENT_UPTIME_MINS > _OLD_AGE_TIME_MINS ))
then
_MSG="old_age check: current uptime is NOK; old age has arrived (>${_OLD_AGE_TIME})"
_STC=1
else
_MSG="old_age check: current uptime is OK"
_STC=0
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}" "${_CURRENT_UPTIME_MINS}" "${_OLD_AGE_TIME_MINS}"
fi
else
log "old age check: not enabled"
fi
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with:
log_healthy=<yes|no>
check_reboot=<yes|no>
reboot_time=<timestring>
check_old_age=<yes|no>
old_age_time=<timestring>
PURPOSE : Checks for unexpected/unplanned reboot events based on uptime
values.
Checks whether the host has been up and running for too much time.
LOG HEALTHY : Supported
EOT
return 0
}
#------------------------------------------------------------------------------
# END of script
#------------------------------------------------------------------------------

View File

@ -33,7 +33,7 @@ function check_linux_autofs
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _VERSION="2019-10-24" # YYYY-MM-DD
typeset _VERSION="2019-07-14" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
# shellcheck disable=SC2034
typeset _HC_CAN_FIX=1 # plugin has fix/healing logic?
@ -136,13 +136,6 @@ fi
# check if autofs is enabled
log "checking if autofs daemon is enabled"
_HAS_SERVICE=$(linux_has_service "autofs")
(( $? > 0)) && {
_MSG="error in function {linux_has_service}"
log_hc "$0" 1 "${_MSG}"
# dump debug info
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
return 1
}
if (( _HAS_SERVICE == 2 ))
then
_MSG="autofs service is enabled"
@ -154,13 +147,6 @@ then
# check if autofs is running
log "checking if autofs daemon is active"
_IS_ACTIVE=$(linux_runs_service autofs)
(( $? > 0)) && {
_MSG="error in function {linux_runs_service }"
log_hc "$0" 1 "${_MSG}"
# dump debug info
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
return 1
}
if (( _IS_ACTIVE > 0 ))
then
_MSG="autofs daemon is running"
@ -184,23 +170,9 @@ then
sleep ${_SLEEP_TIME}
_RETRY_COUNT=$(( _RETRY_COUNT + 1 ))
_IS_ACTIVE=$(linux_runs_service "autofs")
(( $? > 0)) && {
_MSG="error in function {linux_runs_service }"
log_hc "$0" 1 "${_MSG}"
# dump debug info
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
return 1
}
done
# check again if autofs is running
_IS_ACTIVE=$(linux_runs_service "autofs")
(( $? > 0)) && {
_MSG="error in function {linux_runs_service }"
log_hc "$0" 1 "${_MSG}"
# dump debug info
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
return 1
}
if (( _IS_ACTIVE > 0 ))
then
_MSG="autofs daemon is running"

View File

@ -34,8 +34,6 @@
# @(#) added support for --log-healthy [Patrick Van der Veken]
# @(#) 2019-03-10: fix for burp v2
# @(#) 2019-03-16: replace 'which' [Patrick Van der Veken]
# @(#) 2021-03-28: updated code for changing 'burp -v' option as of burp v2.2 +
# quote fixes [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
@ -47,12 +45,12 @@ function check_linux_burp_backup
typeset _BURP_SERVER_CONFIG_FILE="/etc/burp/burp-server.conf"
typeset _BURP_CLIENT_CONFIG_FILE="/etc/burp/burp.conf"
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _VERSION="2021-03-28" # YYYY-MM-DD
typeset _VERSION="2019-03-16" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
@ -66,7 +64,6 @@ typeset _BURP_BACKUP_DIR=""
typeset _BURP_CLIENTCONF_DIR=""
typeset _BURP_CLIENT=""
typeset _BURP_VERSION=""
typeset _BURP_V_OUTPUT=""
typeset _BURP_WARNINGS=""
typeset _GNU_DATE=""
typeset _COUNT=1
@ -78,7 +75,7 @@ for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage "$0" "${_VERSION}" "${_CONFIG_FILE}" && return 0
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
esac
done
@ -102,7 +99,7 @@ case "${_CFG_HEALTHY}" in
esac
# check for old-style configuration file (non-prefixed stanzas)
_IS_OLD_STYLE=$(grep -c -E -e "^client:" "${_CONFIG_FILE}" 2>/dev/null)
_IS_OLD_STYLE=$(grep -c -E -e "^client:" ${_CONFIG_FILE} 2>/dev/null)
if (( _IS_OLD_STYLE == 0 ))
then
warn "no 'client:' stanza(s) found in ${_CONFIG_FILE}; possibly an old-style configuration?"
@ -126,7 +123,6 @@ fi
# check for capable GNU date
_GNU_DATE=$(date --date="1 day ago" '+%s' 2>/dev/null)
data_is_numeric "${_GNU_DATE}"
# shellcheck disable=SC2181
if (( $? > 0 ))
then
warn "no capable GNU date found here"
@ -141,20 +137,8 @@ then
return 1
fi
# burp v1 or v2? (up to v2.1 burp -v; as of burp v2.2 use burp -V but we can still use burp -v with a workaround)
_BURP_V_OUTPUT="$(${_BURP_BIN} -v 2>/dev/null)"
# check if the output contains 'server version'
case "${_BURP_V_OUTPUT}" in
*Server\ version*)
# burp 2.2 and above
_BURP_VERSION=$(print "${_BURP_V_OUTPUT}" | grep "Server version" | awk -F":" '{ print $NF}')
_BURP_VERSION="burp-"$(data_strip_outer_space "${_BURP_VERSION}")
;;
*)
# burp 2.1 and below
_BURP_VERSION="${_BURP_V_OUTPUT}"
;;
esac
# burp v1 or v2?
_BURP_VERSION="$(${_BURP_BIN} -v 2>/dev/null)"
(( ARG_DEBUG > 0 )) && debug "burp version: ${_BURP_VERSION}"
case "${_BURP_VERSION}" in
burp-2*)
@ -199,8 +183,8 @@ case "${_BURP_VERSION}" in
esac
# check backup runs of clients
grep -E -e "^client:" "${_CONFIG_FILE}" 2>/dev/null |\
while IFS=':' read -r _ _BURP_CLIENT _BURP_WARNINGS _BURP_AGE
grep -E -e "^client:" ${_CONFIG_FILE} 2>/dev/null |\
while IFS=':' read _ _BURP_CLIENT _BURP_WARNINGS _BURP_AGE
do
typeset _BACKUP_AGING=""
typeset _BACKUP_DATE=""
@ -238,10 +222,10 @@ do
# 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':')"
_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}')"
_BACKUP_RUN="$(print ${_BACKUP_STATS} | awk '{print $1}')"
# output format: YYYYMMDD HHMM
_BACKUP_DATE=$(print "${_BACKUP_STATS}" | awk '{gsub(/-/,"",$2); gsub(/:/,"",$3); print $2" "substr($3,0,4)}' 2>/dev/null)
# convert to UNIX seconds
@ -283,16 +267,16 @@ do
continue
fi
fi
if [[ -r "${_BURP_BACKUP_DIR}"/"${_BURP_CLIENT}"/current/log.gz ]]
if [[ -r ${_BURP_BACKUP_DIR}/${_BURP_CLIENT}/current/log.gz ]]
then
_BACKUP_WARNINGS=$(zcat "${_BURP_BACKUP_DIR}"/"${_BURP_CLIENT}"/current/log.gz 2>/dev/null | grep -c "WARNING:" 2>/dev/null)
_BACKUP_WARNINGS=$(zcat ${_BURP_BACKUP_DIR}/${_BURP_CLIENT}/current/log.gz 2>/dev/null | grep -c "WARNING:" 2>/dev/null)
else
warn "could not find ${_BURP_BACKUP_DIR}/${_BURP_CLIENT}/current/log.gz"
continue
fi
;;
burp-1*)
_BACKUP_WARNINGS=$(${_BURP_BIN} -c ${_BURP_SERVER_CONFIG_FILE} -a S -C "${_BURP_CLIENT}" -b "${_BACKUP_RUN}" -z backup_stats 2>>"${HC_STDERR_LOG}" |\
_BACKUP_WARNINGS=$(${_BURP_BIN} -c ${_BURP_SERVER_CONFIG_FILE} -a S -C ${_BURP_CLIENT} -b ${_BACKUP_RUN} -z backup_stats 2>>${HC_STDERR_LOG} |\
grep '^warnings' 2>/dev/null | cut -f2 -d':' 2>/dev/null)
;;
esac
@ -341,16 +325,16 @@ do
# save STDOUT
if (( _STC > 0 ))
then
print "=== ${_BURP_CLIENT}: ${_BACKUP_RUN} ===" >>"${HC_STDOUT_LOG}"
print "=== ${_BURP_CLIENT}: ${_BACKUP_RUN} ===" >>${HC_STDOUT_LOG}
case "${_BURP_VERSION}" in
burp-2*)
if [[ -r "${_BURP_BACKUP_DIR}"/"${_BURP_CLIENT}"/current/log.gz ]]
if [[ -r ${_BURP_BACKUP_DIR}/${_BURP_CLIENT}/current/log.gz ]]
then
zcat "${_BURP_BACKUP_DIR}"/"${_BURP_CLIENT}"/current/log.gz >>"${HC_STDOUT_LOG}" 2>>"${HC_STDERR_LOG}"
zcat ${_BURP_BACKUP_DIR}/${_BURP_CLIENT}/current/log.gz >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG}
fi
;;
burp-1*)
${_BURP_BIN} -c ${_BURP_SERVER_CONFIG_FILE} -a S -C "${_BURP_CLIENT}" -b "${_BACKUP_RUN}" -z log.gz >>"${HC_STDOUT_LOG}" 2>>"${HC_STDERR_LOG}"
${_BURP_BIN} -c ${_BURP_SERVER_CONFIG_FILE} -a S -C ${_BURP_CLIENT} -b ${_BACKUP_RUN} -z log.gz >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG}
;;
esac
fi

View File

@ -1,209 +0,0 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_linux_dovecot_status.sh
#******************************************************************************
# @(#) Copyright (C) 2020 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_dovecot_status
# DOES: see _show_usage()
# EXPECTS: n/a
# REQUIRES: data_comma2space(), linux_get_init(), init_hc(), log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2020-12-27: initial version [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_linux_dovecot_status
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _DOVECOT_INIT_SCRIPT="/etc/init.d/dovecot"
typeset _DOVECOT_SYSTEMD_SERVICE="dovecot.service"
typeset _VERSION="2020-12-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_comma2space "$*")
typeset _ARG=""
typeset _DOVECOT_BIN=""
typeset _DOVECOT_CHECKER=""
typeset _MSG=""
typeset _STC=0
typeset _LOG_HEALTHY=0
typeset _RC=0
typeset _CHECK_SYSTEMD_SERVICE=0
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage "$0" "${_VERSION}" "${_CONFIG_FILE}" && return 0
;;
esac
done
# log_healthy
(( ARG_LOG_HEALTHY > 0 )) && _LOG_HEALTHY=1
if (( _LOG_HEALTHY > 0 ))
then
if (( ARG_LOG > 0 ))
then
log "logging/showing passed health checks"
else
log "showing passed health checks (but not logging)"
fi
else
log "not logging/showing passed health checks"
fi
#-------------------------------------------------------------------------------
# process state
# 1) try using the init ways
linux_get_init
case "${LINUX_INIT}" in
'systemd')
# Debian8/Ubuntu16 do not correctly report a unit file for dovecot,
# do not check for it and instead just query systemd service
linux_get_distro
if [[ "${LINUX_DISTRO}" = "Debian" ]] && (( ${LINUX_RELEASE%%.*} < 9 ))
then
_CHECK_SYSTEMD_SERVICE=1
elif [[ "${LINUX_DISTRO}" = "Ubuntu" ]] && (( ${LINUX_RELEASE%%.*} < 17 ))
then
_CHECK_SYSTEMD_SERVICE=1
else
_CHECK_SYSTEMD_SERVICE=$(linux_has_systemd_service "${_DOVECOT_SYSTEMD_SERVICE}")
fi
if (( _CHECK_SYSTEMD_SERVICE > 0 ))
then
systemctl --quiet is-active ${_DOVECOT_SYSTEMD_SERVICE} 2>>"${HC_STDERR_LOG}" || _STC=1
else
warn "systemd unit file not found {${_DOVECOT_SYSTEMD_SERVICE}}"
_RC=1
fi
;;
'upstart')
warn "code for upstart managed systems not implemented, NOOP"
_RC=1
;;
'sysv')
# check running SysV
if [[ -x ${_DOVECOT_INIT_SCRIPT} ]]
then
if (( $(${_DOVECOT_INIT_SCRIPT} status 2>>"${HC_STDERR_LOG}" | grep -c -i 'is running' 2>/dev/null) == 0 ))
then
_STC=1
fi
else
warn "sysv init script not found {${_DOVECOT_INIT_SCRIPT}}"
_RC=1
fi
;;
*)
_RC=1
;;
esac
# 2) try the dovecot way
if (( _RC > 0 ))
then
_DOVECOT_BIN="$(command -v dovecot 2>>${HC_STDERR_LOG})"
if [[ -x ${_DOVECOT_BIN} && -n "${_DOVECOT_BIN}" ]]
then
if (( $(${_DOVECOT_BIN} status 2>>"${HC_STDERR_LOG}" | grep -c -i 'is running' 2>/dev/null) == 0 ))
then
_RC=1
fi
else
warn "dovecot is not installed here"
return 1
fi
fi
# 3) try the pgrep way (note: old pgreps do not support '-c')
if (( _RC > 0 ))
then
(( $(pgrep -u dovecot 2>>"${HC_STDERR_LOG}" | wc -l 2>/dev/null) == 0 )) && _STC=1
fi
# evaluate results
case ${_STC} in
0)
_MSG="dovecot is running"
;;
1)
_MSG="dovecot is not running"
;;
*)
_MSG="could not determine status of dovecot"
;;
esac
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
#-------------------------------------------------------------------------------
# configuration state
_DOVECOT_CHECKER="$(command -v doveconf 2>>${HC_STDERR_LOG})"
if [[ -x ${_DOVECOT_CHECKER} && -n "${_DOVECOT_CHECKER}" ]]
then
# dump configuration
${_DOVECOT_CHECKER} -n >>"${HC_STDOUT_LOG}" 2>>"${HC_STDERR_LOG}"
# shellcheck disable=SC2181
if (( $? > 0 ))
then
_MSG="dovecot configuration files have syntax error(s) {${_DOVECOT_CHECKER} -n}"
_STC=1
else
_MSG="dovecot configuration files are syntactically correct"
_STC=0
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
else
warn "skipping syntax check (unable to find syntax check tool)"
fi
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
PURPOSE : Checks whether dovecot (mail system) is running and whether the
dovecot configuration files are syntactically correct
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************

View File

@ -1,266 +0,0 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_linux_fail2ban_status.sh
#******************************************************************************
# @(#) Copyright (C) 2020 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_fail2ban_status
# DOES: see _show_usage()
# EXPECTS: n/a
# REQUIRES: data_comma2newline(), data_comma2space(), linux_get_init(), init_hc(),
# log(), log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2020-10-18: initial version [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_linux_fail2ban_status
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _FAIL2BAN_INIT_SCRIPT="/etc/init.d/fail2ban"
typeset _FAIL2BAN_SYSTEMD_SERVICE="fail2ban.service"
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _VERSION="2020-10-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_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _CHECK_SYSTEMD_SERVICE=0
typeset _CFG_HEALTHY=""
typeset _LOG_HEALTHY=0
typeset _CFG_CHECK_JAILS=""
typeset _CFG_CHECK_TYPE=""
typeset _DO_PGREP=0
typeset _DO_CHECK_JAIL=1
typeset _CHECK_JAIL=""
typeset _JAIL_OUTPUT=""
typeset _FAILED_NUM=0
typeset _BANNED_NUM=0
typeset _RC=0
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
esac
done
# handle configuration file
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
if [[ ! -r ${_CONFIG_FILE} ]]
then
warn "unable to read configuration file at ${_CONFIG_FILE}"
return 1
fi
# read configuration values
_CFG_CHECK_TYPE=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'check_type')
case "${_CFG_CHECK_TYPE}" in
pgrep|Pgrep|PGREP)
_DO_PGREP=1
log "using pgrep process check (config override)"
;;
sysv|Sysv|SYSV)
LINUX_INIT="sysv"
log "using init based process check (config override)"
;;
systemd|Systemd|SYSTEMD)
LINUX_INIT="systemd"
log "using systemd based process check (config override)"
;;
*)
# no overrides
:
;;
esac
_CFG_CHECK_JAILS=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'check_jails')
if [[ -n "${_CFG_CHECK_JAILS}" ]]
then
log "setting jail list to ${_CFG_CHECK_JAILS}"
fi
_CFG_HEALTHY=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'log_healthy')
case "${_CFG_HEALTHY}" in
yes|YES|Yes)
_LOG_HEALTHY=1
;;
*)
# do not override hc_arg
(( _LOG_HEALTHY > 0 )) || _LOG_HEALTHY=0
;;
esac
# log_healthy
(( ARG_LOG_HEALTHY > 0 )) && _LOG_HEALTHY=1
if (( _LOG_HEALTHY > 0 ))
then
if (( ARG_LOG > 0 ))
then
log "logging/showing passed health checks"
else
log "showing passed health checks (but not logging)"
fi
else
log "not logging/showing passed health checks"
fi
# check fail2ban-server
_FAIL2BAN_BIN="$(command -v fail2ban-server 2>>${HC_STDERR_LOG})"
if [[ -x ${_FAIL2BAN_BIN} && -n "${_FAIL2BAN_BIN}" ]]
then
log "fail2ban (server) is installed at {${_FAIL2BAN_BIN}}"
else
warn "fail2ban (server) is not installed here"
return 1
fi
# ---- process state ----
# 1) try using the init ways
if (( _DO_PGREP == 0 ))
then
[[ -n "${LINUX_INIT}" ]] || linux_get_init
case "${LINUX_INIT}" in
'systemd')
_CHECK_SYSTEMD_SERVICE=$(linux_has_systemd_service "${_FAIL2BAN_SYSTEMD_SERVICE}")
if (( _CHECK_SYSTEMD_SERVICE > 0 ))
then
systemctl --quiet is-active ${_FAIL2BAN_SYSTEMD_SERVICE} 2>>${HC_STDERR_LOG} || _STC=1
else
warn "systemd unit file not found {${_FAIL2BAN_SYSTEMD_SERVICE}}"
_RC=1
fi
;;
'upstart')
warn "code for upstart managed systems not implemented, NOOP"
_RC=1
;;
'sysv')
# check running SysV
if [[ -x ${_FAIL2BAN_INIT_SCRIPT} ]]
then
if (( $(${_FAIL2BAN_INIT_SCRIPT} status 2>>${HC_STDERR_LOG} | grep -c -i 'is running' 2>/dev/null) == 0 ))
then
_STC=1
fi
else
warn "sysv init script not found {${_FAIL2BAN_INIT_SCRIPT}}"
_RC=1
fi
;;
*)
_RC=1
;;
esac
fi
# 2) try the pgrep way (note: old pgreps do not support '-c')
if (( _DO_PGREP > 0 || _RC > 0 ))
then
(( $(pgrep --full -u root "python.*${_FAIL2BAN_BIN}" 2>>${HC_STDERR_LOG} | wc -l 2>/dev/null) == 0 )) && _STC=1
fi
# evaluate results
case ${_STC} in
0)
_MSG="${_FAIL2BAN_BIN} is running"
;;
1)
_MSG="${_FAIL2BAN_BIN} is not running"
_DO_CHECK_JAIL=0
;;
*)
_MSG="could not determine status of ${_FAIL2BAN_BIN}"
_DO_CHECK_JAIL=0
;;
esac
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
# ---- jail states ----
if (( _DO_CHECK_JAIL == 0 ))
then
warn "fail2ban (server) is not running, skipping jail checks"
return 0
fi
_FAIL2BAN_BIN="$(command -v fail2ban-client 2>>${HC_STDERR_LOG})"
if [[ -x ${_FAIL2BAN_BIN} && -n "${_FAIL2BAN_BIN}" ]]
then
log "fail2ban (client) is installed at {${_FAIL2BAN_BIN}}"
else
warn "fail2ban (client) is not installed here, skipping jail checks"
return 1
fi
print "$(data_comma2newline ${_CFG_CHECK_JAILS})" | while read -r _CHECK_JAIL
do
_FAILED_NUM=0
_BANNED_NUM=0
_JAIL_OUTPUT=$(${_FAIL2BAN_BIN} status ${_CHECK_JAIL} 2>>${HC_STDERR_LOG})
if (( $? > 0 ))
then
_MSG="state of jail ${_CHECK_JAIL} is NOK"
_STC=1
else
_FAILED_NUM=$(print "${_JAIL_OUTPUT}" | grep -i 'currently failed' 2>/dev/null | awk -F':' '{ gsub(/[[:space:]]/,"",$2); print $2 }')
_BANNED_NUM=$(print "${_JAIL_OUTPUT}" | grep -i 'currently banned' 2>/dev/null | awk -F':' '{ gsub(/[[:space:]]/,"",$2); print $2 }')
_MSG="state of jail ${_CHECK_JAIL} is OK [failed=${_FAILED_NUM}/banned=${_BANNED_NUM}]"
_STC=0
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
# report only number of banned if OK
log_hc "$0" ${_STC} "${_MSG}" ${_BANNED_NUM} ${_BANNED_NUM}
fi
# add jail output to STDOUT
print "==== {${_FAIL2BAN_BIN} status ${_CHECK_JAIL}} ====" >>${HC_STDOUT_LOG}
print "${_JAIL_OUTPUT}" >>${HC_STDOUT_LOG}
done
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with parameters:
log_healthy=<yes|no>
check_type=<auto|pgrep|sysv|systemd>
check_jails=<list_of_jails>
PURPOSE : Checks whether fail2ban (server service) is running and the state
of the configured jails.
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************

View File

@ -1,319 +0,0 @@
#!/usr/bin/env ksh
#******************************************************************************
# @(#) check_linux_fetchmail_status.sh
#******************************************************************************
# @(#) Copyright (C) 2020 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_fetchmail_status
# DOES: see _show_usage()
# EXPECTS: n/a
# REQUIRES: data_comma2space(), init_hc(), log_hc(), warn')
#
# @(#) HISTORY:
# @(#) 2016-12-26: initial version [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
# -----------------------------------------------------------------------------
function check_linux_fetchmail_status
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _VERSION="2020-12-26" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _LOG_HEALTHY=0
typeset _CFG_HEALTHY=""
typeset _CFG_ERROR_REGEX=""
typeset _ERROR_REGEX=""
typeset _CFG_ACCOUNT=""
typeset _CFG_RC_FILE=""
typeset _CFG_CHECK_LOG=""
typeset _OPENSSL_BIN=""
typeset _MD5SUM_BIN=""
typeset _HAS_OPENSSL=0
typeset _HAS_MD5SUM=0
typeset _USE_OPENSSL=0
typeset _USE_MD5SUM=0
typeset _DO_LOG=0
typeset _LOG_FILE=""
typeset _HASH_FILE_NAME=""
typeset _STATE_FILE=""
typeset _LAST_POINTER=""
typeset _NEW_LAST_POINTER=""
typeset _LOG_COUNT=""
typeset _LINE_NR=""
typeset _LINE_TEXT=""
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage "$0" "${_VERSION}" "${_CONFIG_FILE}" && return 0
;;
esac
done
# handle config file
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
if [[ ! -r ${_CONFIG_FILE} ]]
then
warn "unable to read configuration file at ${_CONFIG_FILE}"
return 1
fi
# read required config values
_CFG_ERROR_REGEX=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'error_regex')
if [[ -n "${_CFG_ERROR_REGEX}" ]]
then
_ERROR_REGEX="${_CFG_ERROR_REGEX}"
else
_ERROR_REGEX="error|authfail|lockbusy|ioerr"
(( ARG_DEBUG > 0 )) && debug "setting error_regex to default value: ${_ERROR_REGEX}"
fi
_CFG_HEALTHY=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'log_healthy')
case "${_CFG_HEALTHY}" in
yes|YES|Yes)
_LOG_HEALTHY=1
;;
*)
# do not override hc_arg
(( _LOG_HEALTHY > 0 )) || _LOG_HEALTHY=0
;;
esac
# log_healthy
(( ARG_LOG_HEALTHY > 0 )) && _LOG_HEALTHY=1
if (( _LOG_HEALTHY > 0 ))
then
if (( ARG_LOG > 0 ))
then
log "logging/showing passed health checks"
else
log "showing passed health checks (but not logging)"
fi
else
log "not logging/showing passed health checks"
fi
#-------------------------------------------------------------------------------
# check for auxiliary tools
_OPENSSL_BIN="$(command -v openssl 2>>${HC_STDERR_LOG})"
[[ -x ${_OPENSSL_BIN} && -n "${_OPENSSL_BIN}" ]] && _HAS_OPENSSL=1
_MD5SUM_BIN="$(command -v md5sum 2>>${HC_STDERR_LOG})"
[[ -x ${_MD5SUM_BIN} && -n "${_MD5SUM_BIN}" ]] && _HAS_MD5SUM=1
# prefer openssl
if (( _HAS_OPENSSL == 1 ))
then
_USE_OPENSSL=1
elif (( _HAS_MD5SUM == 1 ))
then
_USE_MD5SUM=1
else
warn "unable to find the 'openssl/md5sum' tools, will not do fetchmail log checking"
return 1
fi
#-------------------------------------------------------------------------------
# perform check(s)
grep -E -e "^fetchmail:" "${_CONFIG_FILE}" 2>/dev/null | while IFS=":" read -r _ _CFG_ACCOUNT _CFG_RC_FILE _CFG_CHECK_LOG
do
_STC=0
# check config
if [[ -z "${_CFG_ACCOUNT}" ]] && [[ -z "${_CFG_RC_FILE}" ]]
then
warn "missing values in configuration file at ${_CONFIG_FILE}"
return 1
fi
# check if account exists
id "${_CFG_ACCOUNT}" >/dev/null 2>/dev/null || {
warn "account ${_CFG_ACCOUNT} does not exist on host, skipping"
continue
}
# check if fetchmailrc file exists
[[ -r "${_CFG_RC_FILE}" ]] || {
warn "unable to read fetchmailrc file at ${_CFG_RC_FILE} for account ${_CFG_ACCOUNT}, skipping"
continue
}
# get process details
(( $(pgrep -u "${_CFG_ACCOUNT}" -f "fetchmail.*${_CFG_RC_FILE}" | wc -l 2>/dev/null) == 0 )) && _STC=1
# evaluate results
case ${_STC} in
0)
_MSG="fetchmail is running for account ${_CFG_ACCOUNT} (${_CFG_RC_FILE})"
;;
1)
_MSG="fetchmail is not running for account ${_CFG_ACCOUNT} (${_CFG_RC_FILE})"
;;
*)
_MSG="could not determine status of fetchmail for account ${_CFG_ACCOUNT} (${_CFG_RC_FILE})"
;;
esac
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
# check log?
case "${_CFG_CHECK_LOG}" in
Yes|YES|yes)
(( ARG_DEBUG > 0 )) && debug "doing log check for account ${_CFG_ACCOUNT} (${_CFG_RC_FILE})"
_DO_LOG=1;
;;
*)
log "skipping fetchmail log check for account ${_CFG_ACCOUNT} (${_CFG_RC_FILE})"
_DO_LOG=0;
;;
esac
# check auxiliary tools
if (( _HAS_OPENSSL == 0 && _HAS_MD5SUM == 0 ))
then
warn "unable to find the 'openssl/md5sum' tools, will not do fetchmail log checking for account ${_CFG_ACCOUNT}"
_DO_LOG=0
fi
if (( _DO_LOG > 0 ))
then
(( ARG_DEBUG > 0 )) && debug "will do log check for account ${_CFG_ACCOUNT} [${_CFG_RC_FILE}]"
# get logfile statement in .fetchmailrc
_LOG_FILE=$(grep "^set logfile" "${_CFG_RC_FILE}" 2>/dev/null | awk '{ print $3 }' 2>/dev/null)
[[ -z "${_LOG_FILE}" ]] && {
warn "no fetchmail log file defined in fetchmailrc file at ${_CFG_RC_FILE} for account ${_CFG_ACCOUNT}, skipping log check"
continue
}
[[ -r "${_LOG_FILE}" ]] || {
warn "unable to read fetchmail log file at ${_LOG_FILE} for account ${_CFG_ACCOUNT}, skipping log check"
continue
}
(( ARG_DEBUG > 0 )) && debug "log file found at ${_LOG_FILE}"
# determine state file (we use a hashed file name based on the fetchmail log file full path
# to avoid globbing when account has the same name for multiple entries in the configuration file)
(( _USE_OPENSSL == 1 )) && \
_HASH_FILE_NAME=$(${_OPENSSL_BIN} dgst -md5 "${_LOG_FILE}" 2>>"${HC_STDERR_LOG}" | cut -f2 -d'=' 2>/dev/null | tr -d ' ' 2>/dev/null)
(( _USE_MD5SUM == 1 )) && \
_HASH_FILE_NAME=$(${_MD5SUM_BIN} dgst -md5 "${_LOG_FILE}" 2>>"${HC_STDERR_LOG}" | cut -f1 -d' ' 2>/dev/null)
if [[ -z "${_HASH_FILE_NAME}" ]]
then
warn "unable to determine log state file for account ${_CFG_ACCOUNT}, skipping log check"
continue
fi
# get log pointer from state file
_STATE_FILE="${STATE_PERM_DIR}/${_HASH_FILE_NAME}.fetchmail"
if [[ -r "${_STATE_FILE}" ]]
then
_LAST_POINTER=$(<"${_STATE_FILE}")
fi
if [[ -z "${_LAST_POINTER}" ]]
then
(( ARG_DEBUG > 0 )) && debug "could not determine last known log entry, resetting to 0"
_LAST_POINTER=0
else
(( ARG_DEBUG > 0 )) && debug "old _LAST_POINTER=${_LAST_POINTER}"
fi
# check last known vs current pointer
_LOG_COUNT=$(wc -l "${_LOG_FILE}" 2>/dev/null | cut -f1 -d' ')
(( ARG_DEBUG > 0 )) && debug "line count for current log: ${_LOG_COUNT}"
if (( _LOG_COUNT >= _LAST_POINTER ))
then
# find errors in later log lines
awk -F':' -v error_regex="${_ERROR_REGEX}" -v last_pointer=${_LAST_POINTER} '
{
# find error lines which have a line count > last pointer
if (NR > last_pointer && $0 ~ error_regex) {
# cut fetchmail: prefix & replce possible pipes
gsub(/^fetchmail: +/, "");
gsub(/\|/, "_");
# report issue with line number
print $0 "|" NR;
}
}' "${_LOG_FILE}" 2>/dev/null | while IFS="|" read -r _LINE_TEXT _LINE_NR
do
_MSG="found issue in ${_LOG_FILE}: ${_LINE_TEXT} (LINENO=${_LINE_NR})"
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" 1 "${_MSG}"
fi
# update new last pointer
(( ARG_DEBUG > 0 )) && debug "updating _NEW_LAST_POINTER=${_LINE_NR}"
_NEW_LAST_POINTER=${_LINE_NR}
done
else
# log small has shrunk, assume it has been rotated, resetting pointer to zero
log "log file for account ${_CFG_ACCOUNT} seems to have been rotated, resetting log file pointer to 0"
_LAST_POINTER=0
fi
# update state file with new last pointer
if (( ARG_LOG > 0 ))
then
if [[ -n "${_NEW_LAST_POINTER}" ]] && (( _NEW_LAST_POINTER > _LAST_POINTER ))
then
_LAST_POINTER=${_NEW_LAST_POINTER}
fi
(( ARG_DEBUG > 0 )) && debug "new _LAST_POINTER=${_LAST_POINTER}"
print "${_LAST_POINTER}" >"${_STATE_FILE}"
# shellcheck disable=SC2181
if (( $? > 0 ))
then
warn "failed to update state file at ${_STATE_FILE}"
return 1
fi
fi
fi
done
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with parameters:
log_healthy=<yes|no>
and formatted stanzas:
fetchmail:<account>:<rc_file>:<check_log=Yes|No>
PURPOSE : Checks the status of local fetchmail services (process & log).
Fetchmail should be configured to run in daemon mode.
LOG HEALTHY : Supported
EOT
return 0
}
#******************************************************************************
# END of script
#******************************************************************************

View File

@ -30,8 +30,6 @@
# @(#) 2019-01-24: arguments fix [Patrick Van der Veken]
# @(#) 2019-03-09: added support for --log-healthy [Patrick Van der Veken]
# @(#) 2019-03-16: replace 'which' [Patrick Van der Veken]
# @(#) 2020-09-05: fix log_hc call for failed checksum + quote fix [Patrick Van der Veken]
# @(#) 2021-01-13: fix log_hc call (wrong logic) [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
@ -41,7 +39,7 @@ function check_linux_file_change
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _VERSION="2021-01-13" # YYYY-MM-DD
typeset _VERSION="2019-03-16" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
@ -278,7 +276,7 @@ do
openssl-sha256)
if (( _USE_OPENSSL == 1 ))
then
_FILE_CKSUM=$(${_OPENSSL_BIN} dgst -sha256 "${_FILE_TO_CHECK}" 2>>${HC_STDERR_LOG} | cut -f2 -d'=' 2>/dev/null | tr -d ' ' 2>/dev/null)
_FILE_CKSUM=$(${_OPENSSL_BIN} dgst -sha256 ${_FILE_TO_CHECK} 2>>${HC_STDERR_LOG} | cut -f2 -d'=' 2>/dev/null | tr -d ' ' 2>/dev/null)
_FILE_TYPE="openssl-sha256"
else
_MSG="cannot compute checksum [${_FILE_TYPE}] for ${_FILE_TO_CHECK}"
@ -288,7 +286,7 @@ do
cksum-crc32)
if (( _USE_CKSUM == 1 ))
then
_FILE_CKSUM=$(${_CKSUM_BIN} "${_FILE_TO_CHECK}" 2>>${HC_STDERR_LOG} | cut -f1 -d' ' 2>/dev/null)
_FILE_CKSUM=$(${_CKSUM_BIN} ${_FILE_TO_CHECK} 2>>${HC_STDERR_LOG} | cut -f1 -d' ' 2>/dev/null)
_FILE_TYPE="cksum-crc32"
else
_MSG="cannot compute checksum [${_FILE_TYPE}] for ${_FILE_TO_CHECK}"
@ -304,11 +302,11 @@ do
# new file
if (( _USE_OPENSSL == 1 ))
then
_FILE_CKSUM=$(${_OPENSSL_BIN} dgst -sha256 "${_FILE_TO_CHECK}" 2>>${HC_STDERR_LOG} | cut -f2 -d'=' 2>/dev/null | tr -d ' ' 2>/dev/null)
_FILE_CKSUM=$(${_OPENSSL_BIN} dgst -sha256 ${_FILE_TO_CHECK} 2>>${HC_STDERR_LOG} | cut -f2 -d'=' 2>/dev/null | tr -d ' ' 2>/dev/null)
_FILE_TYPE="openssl-sha256"
elif (( _USE_CKSUM == 1 ))
then
_FILE_CKSUM=$(${_CKSUM_BIN} "${_FILE_TO_CHECK}" 2>>${HC_STDERR_LOG} | cut -f1 -d' ' 2>/dev/null)
_FILE_CKSUM=$(${_CKSUM_BIN} ${_FILE_TO_CHECK} 2>>${HC_STDERR_LOG} | cut -f1 -d' ' 2>/dev/null)
_FILE_TYPE="cksum-crc32"
else
_MSG="cannot compute checksum (openssl/cksum) for ${_FILE_TO_CHECK}"
@ -324,7 +322,7 @@ do
fi
# bounce failures back and jump to next file
if (( _LOG_HEALTHY > 0 && _STC > 0 ))
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
continue
@ -350,7 +348,7 @@ do
printf "%s|%s|%s\n" "${_FILE_TO_CHECK}" "${_FILE_TYPE}" "${_FILE_CKSUM}" >>${_TMP2_FILE}
# report with curr/exp values
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
if (( _LOG_HEALTHY > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}" "${_FILE_CKSUM}" "${_STATE_FILE_CKSUM}"
continue

View File

@ -29,7 +29,6 @@
# @(#) 2019-01-24: arguments fix [Patrick Van der Veken]
# @(#) 2019-03-09: added code for data_is_numeric() & support for
# @(#) --log-healthy [Patrick Van der Veken]
# @(#) 2020-02-03: made slot num detection smarter [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
@ -39,7 +38,7 @@ function check_linux_hpacucli
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _VERSION="2020-02-03" # YYYY-MM-DD
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
@ -194,7 +193,7 @@ then
# get all slot numbers for multiple raid controllers
cat ${_TMP_FILE} | grep "in Slot [0-9]" 2>/dev/null | while read _ACU_LINE
do
_SLOT_NUM="$(print ${_ACU_LINE} | sed 's/.*in Slot \([0-9][0-9]*\).*/\1/' 2>/dev/null)"
_SLOT_NUM="$(print ${_ACU_LINE} | cut -f6 -d' ' 2>/dev/null)"
data_is_numeric "${_SLOT_NUM}"
if (( $? == 0 ))
then

View File

@ -29,8 +29,6 @@
# @(#) 2019-01-24: arguments fix [Patrick Van der Veken]
# @(#) 2019-03-09: added code for data_is_numeric() & support for
# @(#) --log-healthy [Patrick Van der Veken]
# @(#) 2020-02-03: made slot num detection smarter + fixed error in reporting
# @(#) when no problems [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
@ -40,7 +38,7 @@ function check_linux_hpssacli
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _VERSION="2020-02-03" # YYYY-MM-DD
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
@ -195,7 +193,7 @@ then
# get all slot numbers for multiple raid controllers
cat ${_TMP_FILE} | grep "in Slot [0-9]" 2>/dev/null | while read _SSA_LINE
do
_SLOT_NUM="$(print ${_SSA_LINE} | sed 's/.*in Slot \([0-9][0-9]*\).*/\1/' 2>/dev/null)"
_SLOT_NUM="$(print ${_SSA_LINE} | cut -f6 -d' ' 2>/dev/null)"
data_is_numeric "${_SLOT_NUM}"
if (( $? == 0 ))
then
@ -281,7 +279,7 @@ else
fi
# report OK situation
if (( _LOG_HEALTHY > 0 && _STC_COUNT == 0 ))
if (( _LOG_HEALTHY > 0 && _STC_COUNT > 0 ))
then
_MSG="no problems detected by {${_HPSSACLI_BIN}}"
log_hc "$0" 0 "${_MSG}"

View File

@ -30,11 +30,6 @@
# @(#) 2019-01-24: arguments fix [Patrick Van der Veken]
# @(#) 2019-03-09: added support for --log-healthy [Patrick Van der Veken]
# @(#) 2019-03-16: replace 'which' [Patrick Van der Veken]
# @(#) 2019-11-01: added support for configuration parameters 'check_type' and
# @(#) 'httpd_bin' [Patrick Van der Veken]
# @(#) 2020-10-10: added support for configuration parameters 'httpd_path' and
# @(#) changed meaning of 'httpd_bin' in order to support debian/ubuntu
# @(#) distros using the 'apache(2)' binary [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
@ -43,8 +38,9 @@
function check_linux_httpd_status
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _VERSION="2020-10-10" # YYYY-MM-DD
typeset _HTTPD_INIT_SCRIPT="/etc/init.d/httpd"
typeset _HTTPD_SYSTEMD_SERVICE="httpd.service"
typeset _VERSION="2019-03-16" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
@ -53,21 +49,11 @@ typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _CHECK_SYSTEMD_SERVICE=0
typeset _HTTPD_BIN=""
typeset _MSG=""
typeset _STC=0
typeset _HTTPD_INIT_SCRIPT=""
typeset _HTTPD_SYSTEMD_SERVICE=""
typeset _CHECK_SYSTEMD_SERVICE=0
typeset _CFG_HEALTHY=""
typeset _LOG_HEALTHY=0
typeset _CFG_HTTPD_BIN=""
typeset _HTTPD_BIN=""
typeset _CFG_HTTPD_PATH=""
typeset _HTTPD_PATH=""
typeset _HTTPD_COMMAND=""
typeset _CFG_CHECK_TYPE=""
typeset _DO_PGREP=0
typeset _HTTPD_CHECKER=""
typeset _RC=0
# handle arguments (originally comma-separated)
@ -80,57 +66,6 @@ do
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_CHECK_TYPE=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'check_type')
case "${_CFG_CHECK_TYPE}" in
pgrep|Pgrep|PGREP)
_DO_PGREP=1
log "using pgrep process check (config override)"
;;
sysv|Sysv|SYSV)
LINUX_INIT="sysv"
log "using init based process check (config override)"
;;
systemd|Systemd|SYSTEMD)
LINUX_INIT="systemd"
log "using systemd based process check (config override)"
;;
*)
# no overrides
:
;;
esac
_CFG_HTTPD_BIN=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'httpd_bin')
if [[ -n "${_CFG_HTTPD_BIN}" ]]
then
# strip path if full path is used (2019-11-01 version)
_HTTPD_BIN="$(basename ${_CFG_HTTPD_BIN})"
log "setting httpd binary to {${_HTTPD_BIN}} (config override)"
fi
_CFG_HTTPD_PATH=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'httpd_path')
if [[ -n "${_CFG_HTTPD_PATH}" ]]
then
_HTTPD_PATH="${_CFG_HTTPD_PATH}"
log "setting httpd path to {${_HTTPD_PATH}} (config override)"
fi
_CFG_HEALTHY=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'log_healthy')
case "${_CFG_HEALTHY}" in
yes|YES|Yes)
_LOG_HEALTHY=1
;;
*)
# do not override hc_arg
(( _LOG_HEALTHY > 0 )) || _LOG_HEALTHY=0
;;
esac
# log_healthy
(( ARG_LOG_HEALTHY > 0 )) && _LOG_HEALTHY=1
if (( _LOG_HEALTHY > 0 ))
@ -145,50 +80,10 @@ else
log "not logging/showing passed health checks"
fi
# check init/systemd settings
case "${_HTTPD_BIN}" in
apache2)
typeset _HTTPD_INIT_SCRIPT="/etc/init.d/apache2"
typeset _HTTPD_SYSTEMD_SERVICE="apache2.service"
;;
apache)
typeset _HTTPD_INIT_SCRIPT="/etc/init.d/apache"
typeset _HTTPD_SYSTEMD_SERVICE="apache.service"
;;
*)
typeset _HTTPD_INIT_SCRIPT="/etc/init.d/httpd"
typeset _HTTPD_SYSTEMD_SERVICE="httpd.service"
;;
esac
log "setting httpd init script to {${_HTTPD_INIT_SCRIPT}}"
log "setting httpd systemd service to {${_HTTPD_SYSTEMD_SERVICE}}"
# check httpd (if specified)
if [[ -z "${_HTTPD_BIN}" || -z "${_HTTPD_PATH}" ]]
then
if [[ -z "${_HTTPD_BIN}" ]]
then
_HTTPD_COMMAND="$(command -v httpd 2>>${HC_STDERR_LOG})"
else
_HTTPD_COMMAND="$(command -v ${_HTTPD_BIN} 2>>${HC_STDERR_LOG})"
fi
if [[ -n "${_HTTPD_COMMAND}" ]]
then
_HTTPD_BIN="$(basename ${_HTTPD_COMMAND})"
_HTTPD_PATH="$(dirname ${_HTTPD_COMMAND})"
fi
fi
if [[ ! -x ${_HTTPD_PATH}/${_HTTPD_BIN} || -z "${_HTTPD_BIN}" || -z "${_HTTPD_PATH}" ]]
then
warn "httpd (apache) is not installed here"
return 1
fi
# ---- process state ----
# 1) try using the init ways
if (( _DO_PGREP == 0 ))
then
[[ -n "${LINUX_INIT}" ]] || linux_get_init
case "${LINUX_INIT}" in
linux_get_init
case "${LINUX_INIT}" in
'systemd')
_CHECK_SYSTEMD_SERVICE=$(linux_has_systemd_service "${_HTTPD_SYSTEMD_SERVICE}")
if (( _CHECK_SYSTEMD_SERVICE > 0 ))
@ -219,25 +114,24 @@ then
*)
_RC=1
;;
esac
fi
esac
# 2) try the pgrep way (note: old pgreps do not support '-c')
if (( _DO_PGREP > 0 || _RC > 0 ))
if (( _RC > 0 ))
then
(( $(pgrep -u root "${_HTTPD_BIN}" 2>>${HC_STDERR_LOG} | wc -l 2>/dev/null) == 0 )) && _STC=1
(( $(pgrep -u root httpd 2>>${HC_STDERR_LOG} | wc -l 2>/dev/null) == 0 )) && _STC=1
fi
# evaluate results
case ${_STC} in
0)
_MSG="${_HTTPD_BIN} is running"
_MSG="httpd is running"
;;
1)
_MSG="${_HTTPD_BIN} is not running"
_MSG="httpd is not running"
;;
*)
_MSG="could not determine status of ${_HTTPD_BIN}"
_MSG="could not determine status of httpd"
;;
esac
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
@ -246,34 +140,23 @@ then
fi
# ---- config state ----
case "${_HTTPD_BIN}" in
apache2)
_HTTPD_CHECKER="$(command -v apache2ctl 2>>${HC_STDERR_LOG})"
;;
apache)
_HTTPD_CHECKER="$(command -v apachectl 2>>${HC_STDERR_LOG})"
;;
*)
_HTTPD_CHECKER="${_HTTPD_PATH}/${_HTTPD_BIN}"
;;
esac
if [[ -x ${_HTTPD_CHECKER} ]]
_HTTPD_BIN="$(command -v httpd 2>>${HC_STDERR_LOG})"
if [[ -x ${_HTTPD_BIN} && -n "${_HTTPD_BIN}" ]]
then
${_HTTPD_CHECKER} -t >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG}
# validate main configuration
${_HTTPD_BIN} -t >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG}
if (( $? == 0 ))
then
_MSG="${_HTTPD_BIN} configuration files are syntactically correct"
_MSG="httpd configuration files are syntactically correct"
_STC=0
else
_MSG="${_HTTPD_BIN} configuration files have syntax error(s) {${_HTTPD_CHECKER} -t}"
_MSG="httpd configuration files have syntax error(s) {httpd -s}"
_STC=1
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
else
warn "skipping syntax check (unable to find syntax check tool)"
fi
return 0
@ -285,11 +168,6 @@ function _show_usage
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with parameters:
log_healthy=<yes|no>
check_type=<auto|pgrep|sysv|systemd> [compt. >=2019-11-01]
httpd_bin=<name_of_httpd> [compt. >=2020-10-10]
httpd_path=<path_to_httpd> [compt. >=2020-10-10]
PURPOSE : Checks whether httpd (apache service) is running and whether the
httpd configuration files are syntactically correct
LOG HEALTHY : Supported

View File

@ -26,9 +26,6 @@
# @(#) 2019-02-10: initial version [Patrick Van der Veken]
# @(#) 2019-03-09: text files [Patrick Van der Veken]
# @(#) 2019-03-16: replace 'which' [Patrick Van der Veken]
# @(#) 2020-09-25: fixes around systemctl handling, better error handling,
# corrected handling of _DO_MYSQLCHECK, fix non-localhost
# process checking [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
@ -42,7 +39,7 @@ typeset _MYSQLD_INIT_SCRIPT="/etc/init.d/mysqld"
typeset _MYSQLD_SYSTEMD_SERVICE="mysqld.service"
typeset _MARIADB_INIT_SCRIPT="/etc/init.d/mariadb"
typeset _MARIADB_SYSTEMD_SERVICE="mariadb.service"
typeset _VERSION="2020-09-25" # YYYY-MM-DD
typeset _VERSION="2019-03-16" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
@ -168,6 +165,7 @@ case "${_CFG_HEALTHY}" in
(( _LOG_HEALTHY > 0 )) || _LOG_HEALTHY=0
;;
esac
(( _DO_MYSQLCHECK == 0 )) && warn "mysqlcheck is disabled (as configured or due to missing mysql settings)"
# log_healthy
(( ARG_LOG_HEALTHY > 0 )) && _LOG_HEALTHY=1
@ -192,31 +190,20 @@ then
fi
# ---- process state ----
# don't check procs if table check on a non-localhost is requested
if (( _DO_MYSQLCHECK > 0 )) && ( [[ "${_CFG_MYSQL_HOST}" != "localhost" ]] &&
[[ "${_CFG_MYSQL_HOST}" != "127.0.0.1" ]] &&
[[ "${_CFG_MYSQL_HOST}" != "::1" ]] )
then
warn "skipping process check because parameter 'mysql_host' is to a remote host in the configuration file ${_CONFIG_FILE}"
else
# 1) try using the init ways
linux_get_init
case "${LINUX_INIT}" in
# 1) try using the init ways
linux_get_init
case "${LINUX_INIT}" in
'systemd')
# first try mysqld
_CHECK_SYSTEMD_SERVICE=$(linux_has_systemd_service "${_MYSQLD_SYSTEMD_SERVICE}")
if (( _CHECK_SYSTEMD_SERVICE > 0 ))
then
(( ARG_DEBUG > 0 )) && debug "doing systemd service check for mysqld"
systemctl --quiet is-active ${_MYSQLD_SYSTEMD_SERVICE} 2>>${HC_STDERR_LOG} || _STC=1
fi
# then try mariadb (also if mysqld check fails which can happen with --is-active when mysqld & mariadb are both enabled)
if (( _STC > 1 ))
then
else
# then try mariadb
_CHECK_SYSTEMD_SERVICE=$(linux_has_systemd_service "${_MARIADB_SYSTEMD_SERVICE}")
if (( _CHECK_SYSTEMD_SERVICE > 0 ))
then
(( ARG_DEBUG > 0 )) && debug "doing systemd service check for mariadbd"
systemctl --quiet is-active ${_MARIADB_SYSTEMD_SERVICE} 2>>${HC_STDERR_LOG} || _STC=1
else
warn "systemd unit file not found {${_MYSQLD_SYSTEMD_SERVICE}}/${_MARIADB_SYSTEMD_SERVICE}}"
@ -226,8 +213,7 @@ else
;;
'upstart')
warn "code for upstart managed systems not implemented, NOOP"
# fall through to pgrep
_RC=1
return 1
;;
'sysv')
# first check running mysqld
@ -253,23 +239,16 @@ else
*)
_RC=1
;;
esac
esac
# 2) try the pgrep way (note: old pgreps do not support '-c')
if (( _RC > 0 ))
then
(( ARG_DEBUG > 0 )) && debug "doing pgrep check for mysqld"
(( $(pgrep -u root,mysql mysqld 2>>${HC_STDERR_LOG} | wc -l 2>/dev/null) == 0 )) && _STC=1
fi
if (( _STC > 0 ))
then
_STC=0
(( ARG_DEBUG > 0 )) && debug "doing pgrep check for mariadbd"
(( $(pgrep -u root,mysql mariadbd 2>>${HC_STDERR_LOG} | wc -l 2>/dev/null) == 0 )) && _STC=1
fi
# 2) try the pgrep way (note: old pgreps do not support '-c')
if (( _RC > 0 ))
then
(( $(pgrep -u root mysqld 2>>${HC_STDERR_LOG} | wc -l 2>/dev/null) == 0 )) && _STC=1
fi
# evaluate results
case ${_STC} in
# evaluate results
case ${_STC} in
0)
_MSG="mysqld/mariadb is running"
;;
@ -279,11 +258,10 @@ else
*)
_MSG="could not determine status of mysqld/mariadb"
;;
esac
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
esac
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
fi
# ---- table states (ISAM)----
@ -308,17 +286,9 @@ then
return 1
fi
# get all databases from mysqlshow
(( ARG_DEBUG > 0 )) && debug "mysqlshow command: ${_MYSQLSHOW_BIN} ${_MYSQLSHOW_OPTS}"
_DB_LIST=$(${_MYSQLSHOW_BIN} ${_MYSQLSHOW_OPTS} 2>>${HC_STDERR_LOG})
if (( $? > 0 )) || [[ -z "${_DB_LIST}" ]]
then
_MSG="unable to run command for {${_MYSQLSHOW_BIN}}"
log_hc "$0" 1 "${_MSG}"
# dump debug info
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
return 1
fi
_DB_LIST=$(print "${_DB_LIST}" | grep -v -E -e '+--' -e 'Databases' 2>/dev/null | awk '{ print $2}' 2>/dev/null)
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && debug "mysqlshow command: ${_MYSQLSHOW_BIN} ${_MYSQLSHOW_OPTS}"
_DB_LIST=$(${_MYSQLSHOW_BIN} ${_MYSQLSHOW_OPTS} 2>>${HC_STDERR_LOG} |\
grep -v -E -e '+--' -e 'Databases' 2>/dev/null | awk '{ print $2}' 2>/dev/null)
else
_DB_LIST=$(data_comma2newline "${_CFG_CHECK_DATABASES}")
fi
@ -333,11 +303,11 @@ then
warn "could not execute/parse {mysqlshow} or list of databases to check is empty, skipping table checks"
return 1
fi
(( ARG_DEBUG > 0 )) && debug "database list for mysqlcheck: ${_MYSQL_DB_LIST}"
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && debug "database list for mysqlcheck: ${_MYSQL_DB_LIST}"
# run check
for _MYSQL_DB in ${_MYSQL_DB_LIST}
do
(( ARG_DEBUG > 0 )) && debug "mysqlcheck command: ${_MYSQLCHECK_BIN} ${_MYSQLCHECK_OPTS} --database ${_MYSQL_DB}"
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && debug "mysqlcheck command: ${_MYSQLCHECK_BIN} ${_MYSQLCHECK_OPTS} --database ${_MYSQL_DB}"
_MYSQLCHECK_OUTPUT=$(${_MYSQLCHECK_BIN} ${_MYSQLCHECK_OPTS} --database ${_MYSQL_DB} 2>>${HC_STDERR_LOG})
if (( $? > 0 )) || [[ -z "${_MYSQLCHECK_OUTPUT}" ]]
then
@ -367,7 +337,7 @@ then
log_hc "$0" ${_STC} "${_MSG}"
fi
else
(( ARG_DEBUG > 0 )) && debug "excluding table: ${_MYSQL_TABLE}"
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && debug "excluding table: ${_MYSQL_TABLE}"
fi
done
# add mysqlcheck output to stdout log
@ -386,17 +356,9 @@ then
fi
if (( _DO_MYSQL_STATS > 0 ))
then
(( ARG_DEBUG > 0 )) && debug "mysql command: ${_MYSQLADMIN_BIN} ${_MYSQLADMIN_OPTS}"
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && debug "mysql command: ${_MYSQLADMIN_BIN} ${_MYSQLADMIN_OPTS}"
print "==== {${_MYSQLADMIN_BIN} <hidden_opts> extended-status} ====" >>${HC_STDOUT_LOG}
${_MYSQLADMIN_BIN} ${_MYSQLADMIN_OPTS} extended-status >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG}
if (( $? > 0 ))
then
_MSG="unable to run command for {${_MYSQLADMIN_BIN}}"
log_hc "$0" 1 "${_MSG}"
# dump debug info
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
continue
fi
fi
return 0

View File

@ -35,9 +35,6 @@
# @(#) fixed problem with offset calculation [Patrick Van der Veken]
# @(#) 2019-01-24: arguments fix [Patrick Van der Veken]
# @(#) 2019-03-24: set dynamic path to client tools [Patrick Van der Veken]
# @(#) 2020-12-21: fixes for --log-healthy [Patrick Van der Veken]
# @(#) 2022-01-30: added support for systemd-timesyncd, new force_systemd
# @(#) configuration parameter [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#------------------------------------------------------------------------------
@ -53,13 +50,13 @@ typeset _CHRONYD_SYSTEMD_SERVICE="chronyd.service"
typeset _NTPD_SYSTEMD_SERVICE="ntpd.service"
typeset _CHRONYD_USER="chrony"
typeset _NTPD_USER="ntp"
typeset _VERSION="2022-01-30" # YYYY-MM-DD
typeset _VERSION="2019-03-24" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
typeset _NTPQ_OPTS="-pn"
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
@ -77,18 +74,15 @@ typeset _NTP_PEER=""
typeset _CHECK_OFFSET=0
typeset _USE_CHRONYD=0
typeset _USE_NTPD=0
typeset _USE_SYSTEMD=0
typeset _CHRONYC_BIN=""
typeset _NTPQ_BIN=""
typeset _TIMEDATECTL_BIN=""
typeset _IS_SYNCHRONIZED=0
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage "$0" "${_VERSION}" "${_CONFIG_FILE}" && return 0
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
force_chrony)
log "forcing chrony since force_chrony was used"
@ -98,10 +92,6 @@ do
log "forcing ntp since force_ntp was used"
_USE_NTPD=1
;;
force_systemd)
log "forcing systemd-timesyncd since force_systemd was used"
_USE_SYSTEMD=1
;;
esac
done
@ -150,17 +140,6 @@ case "${_CFG_FORCE_NTP}" in
: # not set
;;
esac
# force_systemd (optional)
_CFG_FORCE_SYSTEMD=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'force_systemd')
case "${_CFG_FORCE_SYSTEMD}" in
yes|YES|Yes)
log "forcing systemd-timesyncd since force_systemd was set"
_USE_SYSTEMD=1
;;
*)
: # not set
;;
esac
_CFG_NTPQ_IPV4=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'ntpq_use_ipv4')
case "${_CFG_NTPQ_IPV4}" in
yes|YES|Yes)
@ -176,16 +155,6 @@ then
warn "you cannot force chrony and ntp at the same time"
return 1
fi
if (( _USE_CHRONYD > 0 && _USE_SYSTEMD > 0 ))
then
warn "you cannot force chrony and systemd at the same time"
return 1
fi
if (( _USE_NTPD > 0 && _USE_SYSTEMD > 0 ))
then
warn "you cannot force ntp and systemd at the same time"
return 1
fi
# log_healthy
(( ARG_LOG_HEALTHY > 0 )) && _LOG_HEALTHY=1
@ -203,17 +172,19 @@ fi
#------------------------------------------------------------------------------
# check for client tools
_CHRONYC_BIN=$(command -v chronyc 2>>"${HC_STDERR_LOG}")
_NTPQ_BIN=$(command -v ntpq 2>>"${HC_STDERR_LOG}")
_TIMEDATECTL_BIN=$(command -v timedatectl 2>>"${HC_STDERR_LOG}")
_CHRONYC_BIN="$(command -v chronyc 2>>${HC_STDERR_LOG})"
_NTPQ_BIN="$(command -v ntpq 2>>${HC_STDERR_LOG})"
#------------------------------------------------------------------------------
# chronyd (prefer) or ntpd (fallback)
# but do not check if _USE_CHRONYD, _USE_NTPD or _USE_SYSTEMD is already set
if (( _USE_CHRONYD == 0 && _USE_NTPD == 0 && _USE_SYSTEMD == 0 ))
# but do not check if _USE_CHRONYD or _USE_NTPD is already set
if (( _USE_CHRONYD == 0 && _USE_NTPD == 0 ))
then
linux_get_init
_CHRONYC_BIN=$(command -v chronyc 2>>"${HC_STDERR_LOG}")
_CHRONYC_BIN="$(command -v chronyc 2>>${HC_STDERR_LOG})"
if [[ -n "${_CHRONYC_BIN}" && -x ${_CHRONYC_BIN} ]]
then
# check that chrony is actually enabled
@ -223,15 +194,14 @@ then
_CHECK_SYSTEMD_SERVICE=$(linux_has_systemd_service "${_CHRONYD_SYSTEMD_SERVICE}")
if (( _CHECK_SYSTEMD_SERVICE > 0 ))
then
systemctl --quiet is-enabled ${_CHRONYD_SYSTEMD_SERVICE} 2>>"${HC_STDERR_LOG}" && _USE_CHRONYD=1
systemctl --quiet is-enabled ${_CHRONYD_SYSTEMD_SERVICE} 2>>${HC_STDERR_LOG} && _USE_CHRONYD=1
else
warn "systemd unit file not found {${_CHRONYD_SYSTEMD_SERVICE}}"
_USE_CHRONYD=0
fi
;;
'sysv')
chkconfig chronyd >>"${HC_STDOUT_LOG}" 2>>"${HC_STDERR_LOG}"
# shellcheck disable=SC2181
chkconfig chronyd >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG}
if (( $? == 0 ))
then
_USE_CHRONYD=1
@ -245,14 +215,14 @@ then
esac
(( ARG_DEBUG > 0 )) && debug "chronyd service state: ${_USE_CHRONYD}"
fi
_NTPQ_BIN=$(command -v ntpq 2>>"${HC_STDERR_LOG}")
_NTPQ_BIN="$(command -v ntpq 2>>${HC_STDERR_LOG})"
if (( _USE_CHRONYD == 0 )) && [[ -n "${_NTPQ_BIN}" && -x ${_NTPQ_BIN} ]]
then
# shellcheck disable=SC2034
_USE_NTPD=1
(( ARG_DEBUG > 0 )) && debug "ntpd service state: ${_USE_NTPD}"
fi
if (( _USE_CHRONYD == 0 && _USE_NTPD == 0 && _USE_SYSTEMD == 0 ))
if (( _USE_CHRONYD == 0 && _USE_NTPD == 0 ))
then
_MSG="unable to find chronyd or ntpd (or they are not enabled)"
log_hc "$0" 1 "${_MSG}"
@ -263,12 +233,10 @@ then
fi
#------------------------------------------------------------------------------
# check ntp service (unless _USE_SYSTEMD is explicitly set)
if (( _USE_SYSTEMD == 0 ))
then
# 1) try using the init ways
linux_get_init
case "${LINUX_INIT}" in
# check ntp service
# 1) try using the init ways
linux_get_init
case "${LINUX_INIT}" in
'systemd')
if (( _USE_CHRONYD > 0 ))
then
@ -301,7 +269,7 @@ then
then
if [[ -x ${_CHRONY_INIT_SCRIPT} ]]
then
if (( $(${_CHRONY_INIT_SCRIPT} status 2>>"${HC_STDERR_LOG}" | grep -c -i 'is running' 2>/dev/null) == 0 ))
if (( $(${_CHRONY_INIT_SCRIPT} status 2>>${HC_STDERR_LOG} | grep -c -i 'is running' 2>/dev/null) == 0 ))
then
_STC=1
fi
@ -312,7 +280,7 @@ then
else
if [[ -x ${_NTPD_INIT_SCRIPT} ]]
then
if (( $(${_NTPD_INIT_SCRIPT} status 2>>"${HC_STDERR_LOG}" | grep -c -i 'is running' 2>/dev/null) == 0 ))
if (( $(${_NTPD_INIT_SCRIPT} status 2>>${HC_STDERR_LOG} | grep -c -i 'is running' 2>/dev/null) == 0 ))
then
_STC=1
fi
@ -325,21 +293,21 @@ then
*)
_RC=1
;;
esac
esac
# 2) try the pgrep way (note: old pgreps do not support '-c')
if (( _RC > 0 ))
then
# 2) try the pgrep way (note: old pgreps do not support '-c')
if (( _RC > 0 ))
then
if (( _USE_CHRONYD > 0 ))
then
(( $(pgrep -u "${_CHRONYD_USER}" 'chronyd' 2>>"${HC_STDERR_LOG}" | wc -l 2>/dev/null) == 0 )) && _STC=1
(( $(pgrep -u "${_CHRONYD_USER}" 'chronyd' 2>>${HC_STDERR_LOG} | wc -l 2>/dev/null) == 0 )) && _STC=1
else
(( $(pgrep -u "${_NTPD_USER}" 'ntpd' 2>>"${HC_STDERR_LOG}" | wc -l 2>/dev/null) == 0 )) && _STC=1
fi
(( $(pgrep -u "${_NTPD_USER}" 'ntpd' 2>>${HC_STDERR_LOG} | wc -l 2>/dev/null) == 0 )) && _STC=1
fi
fi
# evaluate results
case ${_STC} in
# evaluate results
case ${_STC} in
0)
if (( _USE_CHRONYD > 0 ))
then
@ -364,18 +332,15 @@ then
_MSG="could not determine status of ntpd"
fi
;;
esac
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
esac
log_hc "$0" ${_STC} "${_MSG}"
# check chronyc/ntpq results
_STC=0
if (( _USE_CHRONYD > 0 ))
then
${_CHRONYC_BIN} -nc sources 2>>"${HC_STDERR_LOG}" >>"${HC_STDOUT_LOG}"
# shellcheck disable=SC2181
#------------------------------------------------------------------------------
# check chronyc/ntpq results
_STC=0
if (( _USE_CHRONYD > 0 ))
then
${_CHRONYC_BIN} -nc sources 2>>${HC_STDERR_LOG} >>${HC_STDOUT_LOG}
if (( $? > 0 ))
then
_MSG="unable to execute {${_CHRONYC_BIN}}"
@ -403,10 +368,7 @@ then
_MSG="chrony is synchronizing against ${_CHRONY_PEER}"
;;
esac
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
# 2) offset value
if (( _STC == 0 ))
@ -418,7 +380,6 @@ then
# numeric, OK (negatives are OK too!)
# convert from us to ms
_CURR_OFFSET=$(print -R "${_CURR_OFFSET} * 1000" | bc 2>/dev/null)
# shellcheck disable=SC2181
if (( $? > 0 )) || [[ -z "${_CURR_OFFSET}" ]]
then
:
@ -432,10 +393,7 @@ then
else
_MSG="NTP offset of ${_CURR_OFFSET} is within the acceptable range"
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
;;
*)
# not numeric
@ -444,8 +402,9 @@ then
;;
esac
fi
else
${_NTPQ_BIN} ${_NTPQ_OPTS} 2>>"${HC_STDERR_LOG}" >>"${HC_STDOUT_LOG}"
else
${_NTPQ_BIN} ${_NTPQ_OPTS} 2>>${HC_STDERR_LOG} >>${HC_STDOUT_LOG}
# RC is always 0
# 1) active server
@ -466,10 +425,7 @@ then
_MSG="NTP is synchronizing against ${_NTP_PEER##*\*}"
;;
esac
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
# 2) offset value
if (( _STC == 0 ))
@ -486,10 +442,7 @@ then
else
_MSG="NTP offset of ${_CURR_OFFSET} is within the acceptable range"
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
;;
*)
# not numeric
@ -498,54 +451,6 @@ then
;;
esac
fi
fi
fi
#------------------------------------------------------------------------------
# check systemd-timesyncd results
_STC=0
if (( _USE_SYSTEMD > 0 ))
then
${_TIMEDATECTL_BIN} show 2>"${HC_STDERR_LOG}" >"${HC_STDOUT_LOG}"
# shellcheck disable=SC2181
if (( $? > 0 ))
then
_MSG="unable to execute {${_TIMEDATECTL_BIN}}"
log_hc "$0" 1 "${_MSG}"
# dump debug info
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
return 1
fi
# check if NTP is active
_STC=0
_IS_ACTIVE=$(grep -c "^NTP=yes" "${HC_STDOUT_LOG}" 2>/dev/null)
if (( _IS_ACTIVE == 0 ))
then
_MSG="NTP is not synchronizing"
_STC=1
else
_MSG="NTP is synchronizing"
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
# check if clock is synchronized
_STC=0
_IS_SYNCHRONIZED=$(grep -c "^NTPSynchronized=yes" "${HC_STDOUT_LOG}" 2>/dev/null)
if (( _IS_SYNCHRONIZED == 0 ))
then
_MSG="NTP is not synchronizing"
_STC=1
else
_MSG="NTP is synchronizing"
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
fi
return 0
@ -562,11 +467,10 @@ CONFIG : $3 with:
max_offset=<max_offset (ms)>
force_chrony=<yes|no>
force_ntp=<yes|no>
force_systemd=<yes|no>
ntpq_use_ipv4=<yes|no>
EXTRA OPTS : --hc-args=force_chrony, --hc-args=force_ntp, --hc-args=force_systemd
EXTRA OPTS : --hc-args=force_chrony, --hc-args=force_ntp
PURPOSE : Checks the status of NTP service & synchronization.
Supports chronyd, ntpd & systemd-timesyncd
Supports chronyd & ntpd.
Assumes chronyd is the preferred time synchronization.
LOG HEALTHY : Supported

View File

@ -19,7 +19,7 @@
# @(#) MAIN: check_linux_postfix_status
# DOES: see _show_usage()
# EXPECTS: n/a
# REQUIRES: data_comma2space(), linux_get_init(), init_hc(), log_hc(), warn()
# REQUIRES: data_comma2space(), linux_get_init(), init_hc(), log_hc(), warn')
#
# @(#) HISTORY:
# @(#) 2016-12-01: initial version [Patrick Van der Veken]
@ -31,8 +31,6 @@
# @(#) 2019-03-09: added support for --log-healthy [Patrick Van der Veken]
# @(#) 2019-03-16: replace 'which' [Patrick Van der Veken]
# @(#) 2019-03-25: fix for older Debian & Ubuntu [Patrick Van der Veken]
# @(#) 2020-05-08: add pgrep als fallback check [Patrick Van der Veken]
# @(#) 2020-12-27: add configuration check + quoting fixes [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
@ -43,17 +41,16 @@ function check_linux_postfix_status
# ------------------------- CONFIGURATION starts here -------------------------
typeset _POSTFIX_INIT_SCRIPT="/etc/init.d/postfix"
typeset _POSTFIX_SYSTEMD_SERVICE="postfix.service"
typeset _VERSION="2020-12-27" # YYYY-MM-DD
typeset _VERSION="2019-03-25" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS}
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _POSTFIX_BIN=""
typeset _POSTFIX_CHECKER=""
typeset _MSG=""
typeset _STC=0
typeset _LOG_HEALTHY=0
@ -65,7 +62,7 @@ for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage "$0" "${_VERSION}" "${_CONFIG_FILE}" && return 0
_show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0
;;
esac
done
@ -84,9 +81,6 @@ else
log "not logging/showing passed health checks"
fi
#-------------------------------------------------------------------------------
# process state
# 1) try using the init ways
linux_get_init
case "${LINUX_INIT}" in
@ -105,7 +99,7 @@ case "${LINUX_INIT}" in
fi
if (( _CHECK_SYSTEMD_SERVICE > 0 ))
then
systemctl --quiet is-active ${_POSTFIX_SYSTEMD_SERVICE} 2>>"${HC_STDERR_LOG}" || _STC=1
systemctl --quiet is-active ${_POSTFIX_SYSTEMD_SERVICE} 2>>${HC_STDERR_LOG} || _STC=1
else
warn "systemd unit file not found {${_POSTFIX_SYSTEMD_SERVICE}}"
_RC=1
@ -119,7 +113,7 @@ case "${LINUX_INIT}" in
# check running SysV
if [[ -x ${_POSTFIX_INIT_SCRIPT} ]]
then
if (( $(${_POSTFIX_INIT_SCRIPT} status 2>>"${HC_STDERR_LOG}" | grep -c -i 'is running' 2>/dev/null) == 0 ))
if (( $(${_POSTFIX_INIT_SCRIPT} status 2>>${HC_STDERR_LOG} | grep -c -i 'is running' 2>/dev/null) == 0 ))
then
_STC=1
fi
@ -139,9 +133,9 @@ then
_POSTFIX_BIN="$(command -v postfix 2>>${HC_STDERR_LOG})"
if [[ -x ${_POSTFIX_BIN} && -n "${_POSTFIX_BIN}" ]]
then
if (( $(${_POSTFIX_BIN} status 2>>"${HC_STDERR_LOG}" | grep -c -i 'is running' 2>/dev/null) == 0 ))
if (( $(${_POSTFIX_BIN} status 2>>${HC_STDERR_LOG} | grep -c -i 'is running' 2>/dev/null) == 0 ))
then
_RC=1
_STC=1
fi
else
warn "postfix is not installed here"
@ -149,12 +143,6 @@ then
fi
fi
# 3) try the pgrep way (note: old pgreps do not support '-c')
if (( _RC > 0 ))
then
(( $(pgrep -u postfix pickup 2>>"${HC_STDERR_LOG}" | wc -l 2>/dev/null) == 0 )) && _STC=1
fi
# evaluate results
case ${_STC} in
0)
@ -172,30 +160,6 @@ then
log_hc "$0" ${_STC} "${_MSG}"
fi
#-------------------------------------------------------------------------------
# configuration state
_POSTFIX_CHECKER="$(command -v postconf 2>>${HC_STDERR_LOG})"
if [[ -x ${_POSTFIX_CHECKER} && -n "${_POSTFIX_CHECKER}" ]]
then
# dump configuration
${_POSTFIX_CHECKER} -n >>"${HC_STDOUT_LOG}" 2>>"${HC_STDERR_LOG}"
# shellcheck disable=SC2181
if (( $? > 0 ))
then
_MSG="postfix configuration files have syntax error(s) {${_POSTFIX_CHECKER} -n}"
_STC=1
else
_MSG="postfix configuration files are syntactically correct"
_STC=0
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}"
fi
else
warn "skipping syntax check (unable to find syntax check tool)"
fi
return 0
}
@ -205,8 +169,7 @@ function _show_usage
cat <<- EOT
NAME : $1
VERSION : $2
PURPOSE : Checks whether postfix (mail system) is running and whether the
postfix configuration files are syntactically correct
PURPOSE : Checks whether postfix (mail system) is running
LOG HEALTHY : Supported
EOT

View File

@ -27,7 +27,6 @@
# @(#) 2019-01-24: arguments fix [Patrick Van der Veken]
# @(#) 2019-03-09: changed format of stanzas in configuration file &
# @(#) added support for --log-healthy [Patrick Van der Veken]
# @(#) 2019-10-16: fix for cron nicknames extensions [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
@ -37,7 +36,7 @@ function check_linux_root_crontab
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _VERSION="2019-10-16" # YYYY-MM-DD
typeset _VERSION="2019-03-09" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
@ -54,7 +53,6 @@ typeset _CRON_LINE=""
typeset _CRON_ENTRY=""
typeset _CRON_MATCH=0
typeset _IS_OLD_STYLE=0
typeset _USER_FIELD=""
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
@ -124,16 +122,9 @@ print "=== /etc/cron.(hourly|daily|weekly|monthly) ===" >>${HC_STDOUT_LOG}
print "=== /etc/cron.d ===" >>${HC_STDOUT_LOG}
if [[ -d /etc/cron.d ]]
then
cat /etc/cron.d/* 2>/dev/null | grep -v -E -e '^#' -e '^$' 2>/dev/null | while read _CRON_LINE
cat /etc/cron.d/* 2>/dev/null | while read _CRON_LINE
do
# format: standard cron times or extension nicknames
if [[ "${_CRON_LINE}" =~ ^@ ]]
then
_USER_FIELD=2
else
_USER_FIELD=6
fi
if [[ $(print "${_CRON_LINE}" | awk -v field=${_USER_FIELD} '{print $field}' 2>/dev/null) == "root" ]]
if [[ $(print "${_CRON_LINE}" | awk '{print $6}' 2>/dev/null) == "root" ]]
then
print "${_CRON_LINE}" >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG}
fi

View File

@ -1,313 +0,0 @@
#!/usr/bin/env ksh
#------------------------------------------------------------------------------
# @(#) check_linux_uptime
#------------------------------------------------------------------------------
# @(#) Copyright (C) 2020 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_uptime
# DOES: see _show_usage()
# EXPECTS: see _show_usage()
# REQUIRES: data_is_numeric(), data_timestring_to_mins(), data_comma2space(),
# init_hc(), log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2020-12-21: initial version [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#------------------------------------------------------------------------------
# -----------------------------------------------------------------------------
function check_linux_uptime
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _STATE_FILE="${STATE_PERM_DIR}/current.uptime"
typeset _VERSION="2020-12-21" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
# set defaults
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _LOG_HEALTHY=0
typeset _CFG_HEALTHY=
typeset _CFG_CHECK_REBOOT=""
typeset _CFG_REBOOT_TIME=""
typeset _CFG_CHECK_OLD_AGE=""
typeset _CFG_OLD_AGE_TIME=""
typeset _CHECK_REBOOT=""
typeset _REBOOT_TIME=""
typeset _REBOOT_TIME_MINS=""
typeset _CHECK_OLD_AGE=""
typeset _OLD_AGE_TIME=""
typeset _OLD_AGE_TIME_MINS=""
typeset _CURRENT_UPTIME=""
typeset _CURRENT_UPTIME_MINS=""
typeset _PREVIOUS_UPTIME=""
typeset _PREVIOUS_UPTIME_MINS=""
typeset _THRESHOLD_UPTIME_MINS=""
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
do
case "${_ARG}" in
help)
_show_usage "$0" "${_VERSION}" "${_CONFIG_FILE}" && return 0
;;
esac
done
# handle config file
[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}"
if [[ ! -r ${_CONFIG_FILE} ]]
then
warn "unable to read configuration file at ${_CONFIG_FILE}"
return 1
fi
# read required config values
_CFG_HEALTHY=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'log_healthy')
case "${_CFG_HEALTHY}" in
yes|YES|Yes)
_LOG_HEALTHY=1
;;
*)
# do not override hc_arg
(( _LOG_HEALTHY > 0 )) || _LOG_HEALTHY=0
;;
esac
_CFG_CHECK_REBOOT=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'check_reboot')
case "${_CFG_CHECK_REBOOT}" in
no|No|NO)
_CHECK_REBOOT=0
;;
*)
_CHECK_REBOOT=1
;;
esac
_CFG_REBOOT_TIME=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'reboot_time')
if [[ -z "${_CFG_REBOOT_TIME}" ]]
then
# default
_REBOOT_TIME="60m"
else
_REBOOT_TIME="${_CFG_REBOOT_TIME}"
fi
_CFG_CHECK_OLD_AGE=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'check_old_age')
case "${_CFG_CHECK_OLD_AGE}" in
yes|Yes|Yes)
_CHECK_OLD_AGE=1
;;
*)
_CHECK_OLD_AGE=0
;;
esac
_CFG_OLD_AGE_TIME=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'old_age_time')
if [[ -z "${_CFG_OLD_AGE_TIME}" ]]
then
# default
_OLD_AGE_TIME="365d"
else
_OLD_AGE_TIME="${_CFG_OLD_AGE_TIME}"
fi
# log_healthy
(( ARG_LOG_HEALTHY > 0 )) && _LOG_HEALTHY=1
if (( _LOG_HEALTHY > 0 ))
then
if (( ARG_LOG > 0 ))
then
log "logging/showing passed health checks"
else
log "showing passed health checks (but not logging)"
fi
else
log "not logging/showing passed health checks"
fi
#------------------------------------------------------------------------------
# read /proc/uptime
if [[ -r /proc/uptime ]]
then
# drop decimals
_CURRENT_UPTIME=$(awk '{ printf("%2.d", $1)}' /proc/uptime 2>/dev/null)
else
warn "/proc/uptime cannot be found or queried"
return 1
fi
#------------------------------------------------------------------------------
# read state file
if [[ -r ${_STATE_FILE} ]]
then
_PREVIOUS_UPTIME=$(<"${_STATE_FILE}")
# shellcheck disable=SC2181
if (( $? > 0 ))
then
warn "failed to read state file at ${_STATE_FILE}"
_PREVIOUS_UPTIME=""
fi
fi
#------------------------------------------------------------------------------
# convert uptimes values
_CURRENT_UPTIME_MINS=$(( _CURRENT_UPTIME / 60 ))
data_is_numeric "${_CURRENT_UPTIME_MINS}"
# shellcheck disable=SC2181
if (( $? > 0 ))
then
warn "unable to calculate current uptime value (minutes)"
(( ARG_DEBUG )) && debug "_CURRENT_UPTIME_MINS=${_CURRENT_UPTIME_MINS}"
return 1
fi
_PREVIOUS_UPTIME_MINS=$(( _PREVIOUS_UPTIME / 60 ))
data_is_numeric "${_CURRENT_UPTIME_MINS}"
# shellcheck disable=SC2181
if (( $? > 0 ))
then
warn "unable to calculate previous uptime value (minutes)"
(( ARG_DEBUG )) && debug "_PREVIOUS_UPTIME_MINS=${_PREVIOUS_UPTIME_MINS}"
return 1
fi
#------------------------------------------------------------------------------
# check reboot event
if (( _CHECK_REBOOT > 0 ))
then
# convert _REBOOT_TIME to minutes
_REBOOT_TIME_MINS=$(data_timestring_to_mins "${_REBOOT_TIME}")
data_is_numeric "${_REBOOT_TIME_MINS}"
# shellcheck disable=SC2181
if (( $? > 0 ))
then
warn "unable to calculate 'reboot_time' value from configuration file ${_CONFIG_FILE}"
(( ARG_DEBUG )) && debug "_REBOOT_TIME=${_REBOOT_TIME}"
return 1
fi
# previous uptime missing?
if [[ -z "${_PREVIOUS_UPTIME}" ]]
then
if (( ARG_LOG > 0 ))
then
print "${_CURRENT_UPTIME}" >"${_STATE_FILE}"
# shellcheck disable=SC2181
if (( $? > 0 ))
then
warn "failed to update state file at ${_STATE_FILE}"
return 1
else
log "unable to find previously recorded uptime, resetting to current uptime"
return 0
fi
else
log "unable to find previously recorded uptime, resetting to current uptime"
fi
else
# current uptime + reboot time is smaller than previous uptime?
_THRESHOLD_UPTIME_MINS=$(( _CURRENT_UPTIME_MINS + _REBOOT_TIME_MINS ))
if (( _THRESHOLD_UPTIME_MINS < _PREVIOUS_UPTIME_MINS ))
then
_MSG="reboot check: current uptime is NOK; check if reboot occurred"
_STC=1
else
_MSG="reboot check: current uptime is OK"
_STC=0
fi
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}" "${_THRESHOLD_UPTIME_MINS}" "${_PREVIOUS_UPTIME_MINS}"
fi
# update state file
if (( ARG_LOG > 0 ))
then
print "${_CURRENT_UPTIME}" >"${_STATE_FILE}"
# shellcheck disable=SC2181
if (( $? > 0 ))
then
warn "failed to update state file at ${_STATE_FILE}"
return 1
fi
fi
else
log "reboot check: not enabled"
fi
#------------------------------------------------------------------------------
# check old age event
if (( _CHECK_OLD_AGE > 0 ))
then
# convert _OLD_AGE_TIME to minutes
_OLD_AGE_TIME_MINS=$(data_timestring_to_mins "${_OLD_AGE_TIME}")
data_is_numeric "${_OLD_AGE_TIME_MINS}"
# shellcheck disable=SC2181
if (( $? > 0 ))
then
warn "unable to calculate 'old_age_time' value from configuration file ${_CONFIG_FILE}"
(( ARG_DEBUG )) && debug "_OLD_AGE_TIME=${_OLD_AGE_TIME}"
return 1
fi
# are we old age yet?
if (( _CURRENT_UPTIME_MINS > _OLD_AGE_TIME_MINS ))
then
_MSG="old_age check: current uptime is NOK; old age has arrived (>${_OLD_AGE_TIME})"
_STC=1
else
_MSG="old_age check: current uptime is OK"
_STC=0
fi
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
then
log_hc "$0" ${_STC} "${_MSG}" "${_CURRENT_UPTIME_MINS}" "${_OLD_AGE_TIME_MINS}"
fi
else
log "old age check: not enabled"
fi
return 0
}
# -----------------------------------------------------------------------------
function _show_usage
{
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with:
log_healthy=<yes|no>
check_reboot=<yes|no>
reboot_time=<timestring>
check_old_age=<yes|no>
old_age_time=<timestring>
PURPOSE : Checks for unexpected/unplanned reboot events based on uptime
values.
Checks whether the host has been up and running for too much time.
LOG HEALTHY : Supported
EOT
return 0
}
#------------------------------------------------------------------------------
# END of script
#------------------------------------------------------------------------------

View File

@ -19,14 +19,11 @@
# @(#) MAIN: check_linux_vz_ct_counters
# DOES: see _show_usage()
# EXPECTS: see _show_usage()
# REQUIRES: data_comma2space(), data_is_numeric(), data_get_lvalue_from_config(),
# 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]
# @(#) 2020-04-10: added support for OpenVZ 7. Now using /proc/user_beancounters
# @(#) instead of the 'vzubc' tool. Added possbility to exclude
# @(#) UBC counters [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
@ -36,10 +33,9 @@ function check_linux_vz_ct_counters
{
# ------------------------- CONFIGURATION starts here -------------------------
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _VZCTL_BIN="/usr/sbin/vzctl"
typeset _PRLCTL_BIN="/bin/prlctl"
typeset _UBC_FILE="/proc/user_beancounters"
typeset _VERSION="2020-04-10" # YYYY-MM-DD
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 ---------------------------
@ -50,20 +46,14 @@ typeset _ARGS=$(data_comma2space "$*")
typeset _ARG=""
typeset _MSG=""
typeset _STC=0
typeset _CFG_EXCLUDE_COUNTERS=""
typeset _CFG_HEALTHY=""
typeset _LOG_HEALTHY=0
typeset _CT_ID=""
typeset _HAS_VZ6=0
typeset _UBC_DATA=""
typeset _UBC_CT_DATA=""
typeset _UBC_OUTPUT=""
typeset _UBC_NAME=""
typeset _UBC_CURR_FAIL=""
typeset _UBC_PREV_FAIL=""
typeset _UBC_FAIL=""
typeset _UBC_HELD=""
typeset _UBC_MAX_HELD=""
typeset _UBC_STATE_FILE_STUB="${STATE_PERM_DIR}/vzct.failtcnt"
typeset _UBC_STATE_FILE=""
typeset _RC=0
# handle arguments (originally comma-separated)
@ -84,11 +74,6 @@ then
return 1
fi
# read configuration values
_CFG_EXCLUDE_COUNTERS=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'exclude_counters')
if [[ -n "${_CFG_EXCLUDE_COUNTERS}" ]]
then
log "excluding following counters from check: ${_CFG_EXCLUDE_COUNTERS}"
fi
_CFG_HEALTHY=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'log_healthy')
case "${_CFG_HEALTHY}" in
yes|YES|Yes)
@ -114,132 +99,61 @@ else
log "not logging/showing passed health checks"
fi
# check openvz (6.x or 7.x)
if [[ ! -x ${_PRLCTL_BIN} || -z "${_PRLCTL_BIN}" ]]
# check openvz
if [[ ! -x ${_VZUBC_BIN} || -z "${_VZUBC_BIN}" ]]
then
if [[ ! -x ${_VZCTL_BIN} || -z "${_VZCTL_BIN}" ]]
then
warn "OpenVZ is not installed here"
return 1
else
log "OpenVZ 6.x is installed here"
_HAS_VZ6=1
fi
else
log "OpenVZ 7.x is installed here"
fi
if [[ ! -r "${_UBC_FILE}" ]]
then
warn "missing user beancounters file at ${_UBC_FILE}"
return 1
fi
# get bean counters
_UBC_DATA=$(cat ${_UBC_FILE} 2>>${HC_STDERR_LOG})
if (( $? > 0 )) || [[ -z "${_UBC_DATA}" ]]
then
warn "unable to get UBC data from ${_UBC_FILE}"
# dump debug info
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
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
# OpenVZ 6.x has only numeric CT IDs
if (( _HAS_VZ6 > 0 ))
then
data_is_numeric "${_CT_ID}"
if (( $? > 0 ))
then
warn "${_CT_ID} does not appear to be a correct OpenVZ 6 CT ID"
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
# parse UBC data for CT ID
_UBC_CT_DATA=$(print "${_UBC_DATA}" | awk -v ct_id=${_CT_ID} -v exclude_counters="${_CFG_EXCLUDE_COUNTERS}" '
BEGIN {
found_ct = 0;
}
{
# find container start line
if (NF == 7 && $1 !~ /uid/) {
gsub (/:/, "", $1);
if ($1 == ct_id) {
found_ct = 1;
} else {
found_ct = 0;
}
} else {
if (NF == 6 && found_ct > 0 ) {
if ($1 !~ /dummy/ && !match (exclude_counters, $1)) {
printf ("%s:%d:%d:%d\n", $1, $2, $3, $6);
}
}
}
}
' 2>/dev/null)
# check UBC data
if [[ -n "${_UBC_CT_DATA}" ]]
then
print "${_UBC_CT_DATA}" | while IFS=":" read -r _UBC_NAME _UBC_HELD _UBC_MAX_HELD _UBC_CURR_FAIL
# check values (data lines start with a space)
print "${_UBC_OUTPUT}" | grep "^ " 2>/dev/null | while read -r _UBC_LINE
do
if [[ -z "${_UBC_NAME}" ]] || [[ -z "${_UBC_CURR_FAIL}" ]]
then
warn "unable to parse UBC name and/or fail count values for CT ID ${_CT_ID}"
continue
fi
data_is_numeric "${_UBC_CURR_FAIL}"
if (( $? > 0 ))
then
warn "${_UBC_CURR_FAIL} does not appear to a numeric fail count for CT ID ${_CT_ID}"
continue
fi
_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}')")
# get previous fail count value
_UBC_STATE_FILE="${_UBC_STATE_FILE_STUB}-${_UBC_NAME}_${_CT_ID}"
if [[ -s "${_UBC_STATE_FILE}" ]]
if [[ -z "${_UBC_FAIL}" ]] || [[ "${_UBC_FAIL}" = '-' ]]
then
_UBC_PREV_FAIL=$(<${_UBC_STATE_FILE} 2>/dev/null)
else
_UBC_PREV_FAIL=0
fi
if (( _UBC_CURR_FAIL > _UBC_PREV_FAIL ))
then
_MSG="${_UBC_NAME} for CT ${_CT_ID} increased with $(( _UBC_CURR_FAIL - _UBC_PREV_FAIL )) [HELD:${_UBC_HELD}/MAX_HELD:${_UBC_MAX_HELD}]"
_STC=1
else
_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
# write current fail count value
if (( ARG_LOG > 0 ))
then
print "${_UBC_CURR_FAIL}" >${_UBC_STATE_FILE}
fi
done
else
warn "unable to find UBC data for CT ID ${_CT_ID}"
_RC=$(( _RC + 1 ))
continue
fi
done
# add UBC output to stdout log
print "==== ${_UBC_FILE} ====" >>${HC_STDOUT_LOG}
print "${_UBC_OUTPUT}" >>${HC_STDOUT_LOG}
# 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}
}
@ -250,14 +164,11 @@ function _show_usage
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with parameters:
exclude_counters=<ubc_name>,<ubc_name>,... (release >20200411)
with formatted stanzas:
CONFIG : $3 with formatted stanzas:
ct:<ct_id>
PURPOSE : Checks whether UBC (User Bean Counters) for OpenVZ containers have
PURPOSE : Checks whether UBC (User Bean Counters) for an OpenVZ containers have
increased (failures)
LOG HEALTHY : Supported
NOTES : Supports OpenVZ 6.x & OpenVZ 7.x (release >20200411)
EOT

View File

@ -19,8 +19,8 @@
# @(#) MAIN: check_linux_vz_ct_status
# DOES: see _show_usage()
# EXPECTS: see _show_usage()
# REQUIRES: data_comma2space(), data_is_numeric(), data_has_newline(), data_lc(),
# dump_logs(), init_hc(), log_hc(), warn()
# REQUIRES: data_comma2space(), data_is_numeric(), data_lc(), dump_logs(),
# init_hc(), log_hc(), warn()
#
# @(#) HISTORY:
# @(#) 2017-04-01: initial version [Patrick Van der Veken]
@ -32,8 +32,6 @@
# @(#) 2018-10-28: fixed (linter) errors [Patrick Van der Veken]
# @(#) 2019-01-24: arguments fix [Patrick Van der Veken]
# @(#) 2019-02-08: added support for log_healthy + fixes [Patrick Van der Veken]
# @(#) 2020-04-11: added support for OpenVZ 7 [Patrick Van der Veken]
# @(#) 2020-04-12: copy/paste fix [Patrick Van der Veken]
# -----------------------------------------------------------------------------
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
#******************************************************************************
@ -45,9 +43,7 @@ function check_linux_vz_ct_status
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
typeset _VZLIST_BIN="/usr/sbin/vzlist"
typeset _VZLIST_OPTS="-a -H -o ctid,status,onboot"
typeset _PRLCTL_BIN="/bin/prlctl"
typeset _PRLCTL_OPTS="list --info -a"
typeset _VERSION="2020-04-12" # YYYY-MM-DD
typeset _VERSION="2019-02-08" # YYYY-MM-DD
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
# ------------------------- CONFIGURATION ends here ---------------------------
@ -68,9 +64,8 @@ typeset _CT_RUN_STATUS=""
typeset _CT_CFG_BOOT=""
typeset _CT_RUN_BOOT=""
typeset _CT_ENTRY=""
typeset _HAS_VZ6=0
typeset _CT_MATCH=""
typeset _RC=0
set -A _CHECK_CT
# handle arguments (originally comma-separated)
for _ARG in ${_ARGS}
@ -115,42 +110,22 @@ else
log "not logging/showing passed health checks"
fi
# check openvz (6.x or 7.x)
if [[ ! -x ${_PRLCTL_BIN} || -z "${_PRLCTL_BIN}" ]]
# check openvz
if [[ ! -x ${_VZLIST_BIN} || -z "${_VZLIST_BIN}" ]]
then
if [[ ! -x ${_VZLIST_BIN} || -z "${_VZLIST_BIN}" ]]
then
warn "OpenVZ is not installed here"
return 1
else
log "OpenVZ 6.x is installed here"
_HAS_VZ6=1
fi
else
log "OpenVZ 7.x is installed here"
fi
# get container stati
if (( _HAS_VZ6 > 0 ))
then
${_VZLIST_BIN} ${_VZLIST_OPTS} >${HC_STDOUT_LOG} 2>${HC_STDERR_LOG}
(( $? > 0 )) && {
${_VZLIST_BIN} ${_VZLIST_OPTS} >${HC_STDOUT_LOG} 2>${HC_STDERR_LOG}
(( $? > 0 )) && {
_MSG="unable to run command {${_VZLIST_BIN} ${_VZLIST_OPTS}}"
log_hc "$0" 1 "${_MSG}"
# dump debug info
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
return 0
}
else
${_PRLCTL_BIN} ${_PRLCTL_OPTS} >${HC_STDOUT_LOG} 2>${HC_STDERR_LOG}
(( $? > 0 )) && {
_MSG="unable to run command {${_PRLCTL_BIN} ${_PRLCTL_OPTS}}"
log_hc "$0" 1 "${_MSG}"
# dump debug info
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
return 0
}
fi
}
# check configuration values
grep -E -e '^ct:' ${_CONFIG_FILE} 2>/dev/null | cut -f2- -d':' 2>/dev/null |\
@ -162,15 +137,12 @@ do
_CT_CFG_BOOT=$(data_lc "$(print ${_CT_ENTRY} | cut -f3 -d':' 2>/dev/null)")
# check config
if (( _HAS_VZ6 > 0 ))
then
data_is_numeric "${_CT_ID}"
if (( $? > 0 ))
then
warn "invalid container ID '${_CT_ID}' in configuration file ${_CONFIG_FILE} at data line ${_LINE_COUNT}"
continue
fi
fi
case "${_CT_CFG_STATUS}" in
running|stopped)
;;
@ -179,8 +151,6 @@ do
continue
;;
esac
if (( _HAS_VZ6 > 0 ))
then
case "${_CT_CFG_BOOT}" in
yes|no)
;;
@ -189,92 +159,26 @@ do
continue
;;
esac
else
case "${_CT_CFG_BOOT}" in
on|off)
;;
*)
warn "invalid container boot value '${_CT_CFG_BOOT}' in configuration file ${_CONFIG_FILE} at data line ${_LINE_COUNT}"
continue
;;
esac
fi
# add CT to check check list
_CHECK_CT[${#_CHECK_CT[*]}+1]="${_CT_ID}"
_LINE_COUNT=$(( _LINE_COUNT + 1 ))
done
# fetch data & perform checks
for _CT_ID in "${_CHECK_CT[@]}"
# perform checks
grep -E -e '^ct:' ${_CONFIG_FILE} 2>/dev/null | cut -f2- -d':' 2>/dev/null |\
while read -r _CT_ENTRY
do
# field split
_CT_CFG_STATUS=$(grep "^ct:${_CT_ID}" ${_CONFIG_FILE} 2>/dev/null | cut -f3 -d':' 2>/dev/null)
_CT_CFG_BOOT=$(grep "^ct:${_CT_ID}" ${_CONFIG_FILE} 2>/dev/null | cut -f4 -d':' 2>/dev/null)
_CT_ID=$(print "${_CT_ENTRY}" | cut -f1 -d':' 2>/dev/null)
_CT_CFG_STATUS=$(data_lc "$(print ${_CT_ENTRY} | cut -f2 -d':' 2>/dev/null)")
_CT_CFG_BOOT=$(data_lc "$(print ${_CT_ENTRY} | cut -f3 -d':' 2>/dev/null)")
# check for multiple hits
data_has_newline "${_CT_CFG_STATUS}"
# shellcheck disable=SC2181
if (( $? > 0 ))
then
warn "ignoring ${_CT_ID}:${_CT_CFG_STATUS} because it parses to multiple results in ${_CONFIG_FILE}"
continue
fi
data_has_newline "${_CT_CFG_BOOT}"
# shellcheck disable=SC2181
if (( $? > 0 ))
then
warn "ignoring ${_CT_ID}:${_CT_CFG_BOOT} because it parses to multiple results in ${_CONFIG_FILE}"
continue
fi
_CT_CFG_STATUS=$(data_lc "${_CT_CFG_STATUS}")
_CT_CFG_BOOT=$(data_lc "${_CT_CFG_BOOT}")
# fetch current data
if (( _HAS_VZ6 > 0 ))
then
_CT_ENTRY=$(grep -i "^[[:space:]]*${_CT_ID}" ${HC_STDOUT_LOG} 2>/dev/null)
if [[ -n "${_CT_ENTRY}" ]]
# 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_ENTRY} | awk '{print $2}' 2>/dev/null)")
_CT_RUN_BOOT=$(data_lc "$(print ${_CT_ENTRY} | awk '{print $3}' 2>/dev/null)")
fi
else
awk -F":" -v ct_id="${_CT_ID}" '
BEGIN {
found_ct = 0; ct_state = ""; auto_start = "";
regex_ct = "^EnvID:[[:space:]]+"ct_id;
}
_CT_RUN_STATUS=$(data_lc "$(print ${_CT_MATCH} | awk '{print $2}' 2>/dev/null)")
_CT_RUN_BOOT=$(data_lc "$(print ${_CT_MATCH} | awk '{print $3}' 2>/dev/null)")
{
if ($0 ~ regex_ct) {
found_ct = 1;
} else {
if (found_ct == 1 && $0 ~ /State:/) {
ct_state = $2;
gsub (/[[:space:]]/, "", ct_state);
#print "State:" ct_state;
}
if (found_ct == 1 && $0 ~ /Autostart:/) {
auto_start = $2;
gsub (/[[:space:]]/, "", auto_start);
#print "Start:" auto_start;
}
}
if ($0 ~ /^$/) { found_ct = 0; }
# bail out when we have both data points
if (found_ct == 0 && ct_state && auto_start) { nextfile; };
}
END {
printf ("%s:%s", ct_state, auto_start);
}
' ${HC_STDOUT_LOG} 2>/dev/null | IFS=":" read -r _CT_RUN_STATUS _CT_RUN_BOOT
fi
# check stati
if [[ -n "${_CT_RUN_STATUS}" ]] && [[ -n "${_CT_RUN_BOOT}" ]]
then
if [[ "${_CT_RUN_STATUS}" = "${_CT_CFG_STATUS}" ]]
then
_MSG="container ${_CT_ID} has a correct status [${_CT_RUN_STATUS}]"
@ -301,14 +205,8 @@ do
log_hc "$0" ${_STC} "${_MSG}" "${_CT_RUN_BOOT}" "${_CT_CFG_BOOT}"
fi
else
if (( _HAS_VZ6 > 0 ))
then
warn "could not determine status for container ${_CT_ID} from command output {${_VZLIST_BIN} ${_VZLIST_OPTS}}"
else
warn "could not determine status for container ${_CT_ID} from command output {${_PRLCTL_BIN} ${_PRLCTL_OPTS}}"
fi
_RC=$(( _RC + 1 ))
continue
fi
done
@ -321,11 +219,10 @@ function _show_usage
cat <<- EOT
NAME : $1
VERSION : $2
CONFIG : $3 with formatted stanzas:
CONFIG : $3 with:
ct:<ctid>:<runtime_status>:<boot_status>
PURPOSE : Checks whether OpenVZ containers are running or not
LOG HEALTHY : Supported
NOTES : Supports OpenVZ 6.x & OpenVZ 7.x (release >20200411)
EOT