diff --git a/README.md b/README.md index ae79ef1..2427a22 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,101 @@ -# check_health -Health checker for UNIX/Linux +# Health checker for UNIX/Linux + +Health checker for UNIX/Linux is a small framework of monitoring scripts (plugins). It is meant to be used for low latency & low frequency checks, it is easy to extend where necessary and it can be integrated with other toolsets (YMMV). + +## Requirements + +* ksh88/ksh93 (mksh/pdksh will work also but YMMV) +* some disk space for storing logs & event files +* system dependant tools/utilities (see individual health checks) +* UNIX cron or other scheduler +* execute as user root only + +## Installation + +### HP-UX + +Install the core bundle: + + swinstall -x mount_all_filesystems=false -d /tmp/hc-hpux-.sd HC-HPUX + +Install the HP-UX plugin bundle: + + swinstall -x mount_all_filesystems=false -d /tmp/hc-hpux-platform-.sd HC-PLATFORM + +### Linux + +Install the core bundle: + + yum localinstall hc-linux-.noarch.rpm + zypper install hc-linux-.noarch.rpm + +Install the Linux plugin bundle: + + yum localinstall hc-linux-platform-.noarch.rpm + zypper install hc-linux-.noarch.rpm + +### AIX + +Install the core bundle: + + installp -Xap -d hc-aix-.bff all + +Install the AIX plugin bundle: + + installp -Xap -d hc-aix-platform- all + +### Miscelleanous + +Additionally, there may be bundles for display or notification plugins, e.g.: +* hc-display-csv +* hc-display-init +* hc-display-terse +* hc-notify-eif +* hc-notify-sms + +## Examples + +* **Listing** available health checks: +``` +/opt/hc/bin/check_health.sh --list +``` + +* **Running** a single health check: +``` +/opt/hc/bin/check_health.sh --hc=check_hpux_ioscan --run +``` + +* **Running** multiple health checks (at once): +``` +/opt/hc/bin/check_health.sh --hc=check_hpux_ioscan,check_hpux_ovpa_status --run +``` + +* **Running** a single health check with a custom configuration file: +``` +/opt/hc/bin/check_health.sh --hc=check_hpux_ioscan --config-file=/etc/opt/hc/check_hpux_ioscan_new.conf --run +``` + +* **Showing** information on a health check: +``` +/opt/hc/bin/check_health.sh --hc=check_hpux_ioscan --show +``` + +* **Enabling/disabling** a health check: +``` +/opt/hc/bin/check_health.sh --hc=check_hpux_ioscan --check +/opt/hc/bin/check_health.sh --hc=check_hpux_ioscan --disable +/opt/hc/bin/check_health.sh --hc=check_hpux_ioscan --enable +``` + +* **Reporting** on failed health checks: +``` +/opt/hc/bin/check_health.sh --report +/opt/hc/bin/check_health.sh --report --last +/opt/hc/bin/check_health.sh --report --today +/opt/hc/bin/check_health.sh --report --id=20160704154001 --detail +``` + +* **Alerting** on failed health checks: +``` +/opt/hc/bin/check_health.sh --hc=check_hpux_root_crontab --run --notify=mail --mail-to="alert@acme.com" +``` diff --git a/build/aix/build_aix_bff.sh b/build/aix/build_aix_bff.sh new file mode 100644 index 0000000..3907212 --- /dev/null +++ b/build/aix/build_aix_bff.sh @@ -0,0 +1,58 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) build script for HC BFF packages (uses 'build_bff.sh' & 'mkinstallp') +#****************************************************************************** +# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 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 +#****************************************************************************** + +#****************************************************************************** +# Build environment should typically exist on a NIM server. +# Requires following build (dir) structures: +# +# build_bff.sh -> /usr/local/bin/build_bff.sh +# build_aix_bff.sh +# hc_aix/* (containing mkinstallp template & sources) +# hc_aix_platform/* (containing mkinstallp template & sources) +# hc_aix_dll/* (containing mkinstallp template & sources) +# hc_aix_security/* (containing mkinstallp template & sources) +# ... +# lpp_source/KUDOS (defined in build_bff.sh script) +# +# Build order: +# 1) Copy sources/scrips to the correct locations +# 2) Copy pristine version of the build spec file to preserver %BUILD_DATE% (.template) +# 3) Copy template, build and installer script files into correct locations +# 4) Execute build_aix_bff.sh +# 5) RPM packages may be found in the individual 'tmp' directories per plugin +# (also refer to the help of build_bff.sh, ./build_bff.sh --help) +#****************************************************************************** + +BUILD_DATE="$(date +'%Y%m%d')" +BUILD_PRETTY_DATE="$(date +'%Y.%m.%d')" +BUILD_DIR="$(dirname $0)" + +# replace BUILD_DATE placeholder in template files +find ${BUILD_DIR} -name "*.template" | while read FILE +do + perl -pi -e "s/%BUILD_DATE%/${BUILD_PRETTY_DATE}/g" ${FILE} +done + +# cleanup of old BFF packages happens in build_bff.sh + +# build BFF packages +${BUILD_DIR}/build_bff.sh + +exit 0 + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/build/aix/hc_aix/hc_aix.template b/build/aix/hc_aix/hc_aix.template new file mode 100644 index 0000000..b7348f4 --- /dev/null +++ b/build/aix/hc_aix/hc_aix.template @@ -0,0 +1,43 @@ +Package Name: hc_aix +Package VRMF: %BUILD_DATE% +Update: N +Fileset + Fileset Name: hc_aix.rte + Fileset VRMF: %BUILD_DATE% + Fileset Description: Health Checker + USRLIBLPPFiles + EOUSRLIBLPPFiles + ROOTLIBLPPFiles + Post-installation Script: /export/nim/build/hc_aix/scripts/hc_aix.postinstall + Unpost-installation Script: /export/nim/build/hc_aix/scripts/hc_aix.postuninstall + EOROOTLIBLPPFiles + Bosboot required: N + License agreement acceptance required: N + Include license files in this package: N + Requisites: + USRFiles + EOUSRFiles + ROOT Part: Y + ROOTFiles + /opt/hc + /opt/hc/bin + /opt/hc/bin/check_health.sh + /opt/hc/lib + /opt/hc/lib/core + /opt/hc/lib/core/include_core.sh + /opt/hc/lib/core/include_data.sh + /opt/hc/lib/core/include_os.sh + /opt/hc/lib/core/notify_mail.sh + /etc/opt/hc + /etc/opt/hc/check_host.conf.dist + /etc/opt/hc/core + /etc/opt/hc/core/check_health.conf.dist + /etc/opt/hc/core/templates + /etc/opt/hc/core/templates/mail_info.tpl + /etc/opt/hc/core/templates/mail_header.tpl + /etc/opt/hc/core/templates/mail_body.tpl + /etc/opt/hc/core/templates/mail_footer.tpl + /var/opt/hc + EOROOTFiles + Relocatable: N +EOFileset diff --git a/build/aix/hc_aix/scripts/hc_aix.postinstall b/build/aix/hc_aix/scripts/hc_aix.postinstall new file mode 100644 index 0000000..f33f1b8 --- /dev/null +++ b/build/aix/hc_aix/scripts/hc_aix.postinstall @@ -0,0 +1,96 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) post-install script for hc_aix LPP package +#****************************************************************************** +# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** + +# ------------------------- CONFIGURATION starts here ------------------------- +# location of ETC dir +HC_ETC_DIR="/etc/opt/hc" +# location of VAR dir +HC_VAR_DIR="/var/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 ..." + +# create ETC DIR +if [[ ! -d ${HC_ETC_DIR} ]] +then + mkdir -p ${HC_ETC_DIR} >/dev/null || \ + { + print -u2 "ERROR: could not create directory ${HC_ETC_DIR}" + exit 1 + } + chmod 755 ${HC_ETC_DIR} >/dev/null || \ + print -u2 "WARN: could not 'chmod 755' on directory ${HC_ETC_DIR}" +fi +if [[ ! -d ${HC_ETC_DIR}/core ]] +then + mkdir -p ${HC_ETC_DIR}/core >/dev/null || \ + { + print -u2 "ERROR: could not create directory ${HC_ETC_DIR}/core" + exit 1 + } + chmod 755 ${HC_ETC_DIR} >/dev/null || \ + print -u2 "WARN: could not 'chmod 755' on directory ${HC_ETC_DIR}/core" +fi + +# copy main config file from dist (if needed) +if [[ ! -f ${HC_ETC_DIR}/core/check_health.conf ]] +then + cp -p ${HC_ETC_DIR}/core/check_health.conf.dist ${HC_ETC_DIR}/core/check_health.conf >/dev/null || \ + { + print -u2 "ERROR: could not copy main config file in ${HC_ETC_DIR}/core" + exit 1 + } +fi +# copy host check config file from dist (if needed) +if [[ ! -f ${HC_ETC_DIR}/check_host.conf ]] +then + cp -p ${HC_ETC_DIR}/check_host.conf.dist ${HC_ETC_DIR}/check_host.conf >/dev/null || \ + { + print -u2 "ERROR: could not copy main config file in ${HC_ETC_DIR}" + exit 1 + } +fi + +# create VAR DIR +if [[ ! -d ${HC_VAR_DIR} ]] +then + mkdir -p ${HC_VAR_DIR} >/dev/null || \ + { + print -u2 "ERROR: could not create directory ${HC_VAR_DIR}" + exit 1 + } + chmod 755 ${HC_VAR_DIR} >/dev/null || \ + print -u2 "WARN: could not 'chmod 755' on directory ${HC_VAR_DIR}" +fi + +# refresh symbolic FPATH links for core plugins +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 +#****************************************************************************** diff --git a/build/aix/hc_aix/scripts/hc_aix.postuninstall b/build/aix/hc_aix/scripts/hc_aix.postuninstall new file mode 100644 index 0000000..f7238d5 --- /dev/null +++ b/build/aix/hc_aix/scripts/hc_aix.postuninstall @@ -0,0 +1,64 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) post-uninstall script for hc_aix LPP package +#****************************************************************************** +# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** + +# ------------------------- CONFIGURATION starts here ------------------------- +# location of ETC dir +HC_ETC_DIR="/etc/opt/hc" +# location of VAR dir +HC_VAR_DIR="/var/opt/hc" +# location of MAIN dir +HC_MAIN_DIR="/opt/hc" +# ------------------------- CONFIGURATION ends here --------------------------- +echo "INFO: starting post-uninstall script ..." + +# remove ETC DIR (only .dist files) +if [[ -d ${HC_ETC_DIR} ]] +then + rm -rf ${HC_ETC_DIR}/*.dist >/dev/null || \ + print -u2 "WARN: could not remove .dist files in directory ${HC_ETC_DIR}" +fi +if [[ -d ${HC_ETC_DIR}/core ]] +then + rm -rf ${HC_ETC_DIR}/core/*.dist >/dev/null || \ + print -u2 "WARN: could not remove .dist files in directory ${HC_ETC_DIR}/core" +fi +if [[ -d ${HC_ETC_DIR}/core/providers ]] +then + rm -rf ${HC_ETC_DIR}/core/providers/*.dist >/dev/null || \ + print -u2 "WARN: could not remove .dist files in directory ${HC_ETC_DIR}/core/providers" +fi + +# remove VAR DIR (temporary state only) +if [[ -d ${HC_VAR_DIR} ]] +then + rm -rf ${HC_VAR_DIR}/state/temporary >/dev/null || \ + print -u2 "WARN: could not remove directory ${HC_VAR_DIR}/state/temporary" +fi + +# remove MAIN DIR +if [[ -d ${HC_MAIN_DIR} ]] +then + rm -rf ${HC_MAIN_DIR} >/dev/null || \ + print -u2 "WARN: could not remove directory ${HC_VAR_DIR}" +fi + +print "INFO: finished post-uninstall script" + +exit 0 + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/build/aix/hc_aix_platform/hc_aix_platform.reqs b/build/aix/hc_aix_platform/hc_aix_platform.reqs new file mode 100644 index 0000000..f90fa90 --- /dev/null +++ b/build/aix/hc_aix_platform/hc_aix_platform.reqs @@ -0,0 +1 @@ +*prereq hc_aix.rte diff --git a/build/aix/hc_aix_platform/hc_aix_platform.template b/build/aix/hc_aix_platform/hc_aix_platform.template new file mode 100644 index 0000000..4b20ee0 --- /dev/null +++ b/build/aix/hc_aix_platform/hc_aix_platform.template @@ -0,0 +1,43 @@ +Package Name: hc_aix_platform +Package VRMF: %BUILD_DATE% +Update: N +Fileset + Fileset Name: hc_aix_platform.rte + Fileset VRMF: %BUILD_DATE% + Fileset Description: Health Checker - OS/platform plugins + USRLIBLPPFiles + EOUSRLIBLPPFiles + ROOTLIBLPPFiles + Post-installation Script: /export/nim/build/hc_aix_platform/scripts/hc_aix_platform.postinstall + Unpost-installation Script: /export/nim/build/hc_aix_platform/scripts/hc_aix_platform.postuninstall + EOROOTLIBLPPFiles + Bosboot required: N + License agreement acceptance required: N + Include license files in this package: N + Requisites: /export/nim/build/hc_aix_platform/hc_aix_platform.reqs + USRFiles + EOUSRFiles + ROOT Part: Y + ROOTFiles +/opt/hc/lib +/opt/hc/lib/platform +/opt/hc/lib/platform/aix +/opt/hc/lib/platform/aix/check_aix_errpt.sh +/opt/hc/lib/platform/aix/check_aix_file_age.sh +/opt/hc/lib/platform/aix/check_aix_file_change.sh +/opt/hc/lib/platform/aix/check_aix_fs_mounts.sh +/opt/hc/lib/platform/aix/check_aix_lppchk.sh +/opt/hc/lib/platform/aix/check_aix_paths.sh +/opt/hc/lib/platform/aix/check_aix_root_crontab.sh +/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 +/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 + EOROOTFiles + Relocatable: N +EOFileset diff --git a/build/aix/hc_aix_platform/scripts/hc_aix_platform.postinstall b/build/aix/hc_aix_platform/scripts/hc_aix_platform.postinstall new file mode 100644 index 0000000..8c03b43 --- /dev/null +++ b/build/aix/hc_aix_platform/scripts/hc_aix_platform.postinstall @@ -0,0 +1,39 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) post-install script for hc_aix_platform LPP package +#****************************************************************************** +# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** + +# ------------------------- 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 --------------------------- + +print "INFO: starting post-install script ..." + +# 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 +#****************************************************************************** diff --git a/build/aix/hc_aix_platform/scripts/hc_aix_platform.postuninstall b/build/aix/hc_aix_platform/scripts/hc_aix_platform.postuninstall new file mode 100644 index 0000000..d9fc249 --- /dev/null +++ b/build/aix/hc_aix_platform/scripts/hc_aix_platform.postuninstall @@ -0,0 +1,39 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) post-uninstall script for hc_aix_platform LPP package +#****************************************************************************** +# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** + +# ------------------------- 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 --------------------------- + +print "INFO: starting post-uninstall script ..." + +# 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 +#****************************************************************************** diff --git a/build/aix/hc_display_csv/hc_display_csv.reqs b/build/aix/hc_display_csv/hc_display_csv.reqs new file mode 100644 index 0000000..f90fa90 --- /dev/null +++ b/build/aix/hc_display_csv/hc_display_csv.reqs @@ -0,0 +1 @@ +*prereq hc_aix.rte diff --git a/build/aix/hc_display_csv/hc_display_csv.template b/build/aix/hc_display_csv/hc_display_csv.template new file mode 100644 index 0000000..d89b2a1 --- /dev/null +++ b/build/aix/hc_display_csv/hc_display_csv.template @@ -0,0 +1,27 @@ +Package Name: hc_display_csv +Package VRMF: %BUILD_DATE% +Update: N +Fileset + Fileset Name: hc_display_csv.rte + Fileset VRMF: %BUILD_DATE% + Fileset Description: Health Checker - core CSV plugin + USRLIBLPPFiles + EOUSRLIBLPPFiles + ROOTLIBLPPFiles + Post-installation Script: /export/nim/build/hc_display_csv/scripts/hc_display_csv.postinstall + Unpost-installation Script: /export/nim/build/hc_display_csv/scripts/hc_display_csv.postuninstall + EOROOTLIBLPPFiles + Bosboot required: N + License agreement acceptance required: N + Include license files in this package: N + Requisites: /export/nim/build/hc_display_csv/hc_display_csv.reqs + USRFiles + EOUSRFiles + ROOT Part: Y + ROOTFiles +/opt/hc/lib +/opt/hc/lib/core +/opt/hc/lib/platform/aix/display_csv.sh + EOROOTFiles + Relocatable: N +EOFileset diff --git a/build/aix/hc_display_csv/scripts/hc_display_csv.postinstall b/build/aix/hc_display_csv/scripts/hc_display_csv.postinstall new file mode 100644 index 0000000..f08bc87 --- /dev/null +++ b/build/aix/hc_display_csv/scripts/hc_display_csv.postinstall @@ -0,0 +1,41 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) post-install script for hc_display_csv LPP package +#****************************************************************************** +# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** + +# ------------------------- 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 ..." + +# 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 +#****************************************************************************** diff --git a/build/aix/hc_display_csv/scripts/hc_display_csv.postuninstall b/build/aix/hc_display_csv/scripts/hc_display_csv.postuninstall new file mode 100644 index 0000000..3040427 --- /dev/null +++ b/build/aix/hc_display_csv/scripts/hc_display_csv.postuninstall @@ -0,0 +1,41 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) post-uninstall script for hc_display_csv LPP package +#****************************************************************************** +# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** + +# ------------------------- 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 ..." + +# 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 +#****************************************************************************** diff --git a/build/aix/hc_display_init/hc_display_init.reqs b/build/aix/hc_display_init/hc_display_init.reqs new file mode 100644 index 0000000..f90fa90 --- /dev/null +++ b/build/aix/hc_display_init/hc_display_init.reqs @@ -0,0 +1 @@ +*prereq hc_aix.rte diff --git a/build/aix/hc_display_init/hc_display_init.template b/build/aix/hc_display_init/hc_display_init.template new file mode 100644 index 0000000..345745d --- /dev/null +++ b/build/aix/hc_display_init/hc_display_init.template @@ -0,0 +1,27 @@ +Package Name: hc_display_init +Package VRMF: %BUILD_DATE% +Update: N +Fileset + Fileset Name: hc_display_init.rte + Fileset VRMF: %BUILD_DATE% + Fileset Description: Health Checker - core INIT plugin + USRLIBLPPFiles + EOUSRLIBLPPFiles + ROOTLIBLPPFiles + Post-installation Script: /export/nim/build/hc_display_init/scripts/hc_display_init.postinstall + Unpost-installation Script: /export/nim/build/hc_display_init/scripts/hc_display_init.postuninstall + EOROOTLIBLPPFiles + Bosboot required: N + License agreement acceptance required: N + Include license files in this package: N + Requisites: /export/nim/build/hc_display_init/hc_display_init.reqs + USRFiles + EOUSRFiles + ROOT Part: Y + ROOTFiles +/opt/hc/lib +/opt/hc/lib/core +/opt/hc/lib/platform/aix/display_init.sh + EOROOTFiles + Relocatable: N +EOFileset diff --git a/build/aix/hc_display_init/scripts/hc_display_init.postinstall b/build/aix/hc_display_init/scripts/hc_display_init.postinstall new file mode 100644 index 0000000..68e6766 --- /dev/null +++ b/build/aix/hc_display_init/scripts/hc_display_init.postinstall @@ -0,0 +1,41 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) post-install script for hc_display_init LPP package +#****************************************************************************** +# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** + +# ------------------------- 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 ..." + +# 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 +#****************************************************************************** diff --git a/build/aix/hc_display_init/scripts/hc_display_init.postuninstall b/build/aix/hc_display_init/scripts/hc_display_init.postuninstall new file mode 100644 index 0000000..b9f5eaa --- /dev/null +++ b/build/aix/hc_display_init/scripts/hc_display_init.postuninstall @@ -0,0 +1,41 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) post-uninstall script for hc_display_init LPP package +#****************************************************************************** +# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** + +# ------------------------- 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 ..." + +# 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 +#****************************************************************************** diff --git a/build/aix/hc_display_terse/hc_display_terse.reqs b/build/aix/hc_display_terse/hc_display_terse.reqs new file mode 100644 index 0000000..f90fa90 --- /dev/null +++ b/build/aix/hc_display_terse/hc_display_terse.reqs @@ -0,0 +1 @@ +*prereq hc_aix.rte diff --git a/build/aix/hc_display_terse/hc_display_terse.template b/build/aix/hc_display_terse/hc_display_terse.template new file mode 100644 index 0000000..862b7c9 --- /dev/null +++ b/build/aix/hc_display_terse/hc_display_terse.template @@ -0,0 +1,27 @@ +Package Name: hc_display_terse +Package VRMF: %BUILD_DATE% +Update: N +Fileset + Fileset Name: hc_display_terse.rte + Fileset VRMF: %BUILD_DATE% + Fileset Description: Health Checker - core TERSE plugin + USRLIBLPPFiles + EOUSRLIBLPPFiles + ROOTLIBLPPFiles + Post-installation Script: /export/nim/build/hc_display_terse/scripts/hc_display_terse.postinstall + Unpost-installation Script: /export/nim/build/hc_display_terse/scripts/hc_display_terse.postuninstall + EOROOTLIBLPPFiles + Bosboot required: N + License agreement acceptance required: N + Include license files in this package: N + Requisites: /export/nim/build/hc_display_terse/hc_display_terse.reqs + USRFiles + EOUSRFiles + ROOT Part: Y + ROOTFiles +/opt/hc/lib +/opt/hc/lib/core +/opt/hc/lib/platform/aix/display_terse.sh + EOROOTFiles + Relocatable: N +EOFileset diff --git a/build/aix/hc_display_terse/scripts/hc_display_csv.postuninstall b/build/aix/hc_display_terse/scripts/hc_display_csv.postuninstall new file mode 100644 index 0000000..40c9c0a --- /dev/null +++ b/build/aix/hc_display_terse/scripts/hc_display_csv.postuninstall @@ -0,0 +1,41 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) post-uninstall script for hc_display_terse LPP package +#****************************************************************************** +# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** + +# ------------------------- 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 ..." + +# 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 +#****************************************************************************** diff --git a/build/aix/hc_display_terse/scripts/hc_display_terse.postinstall b/build/aix/hc_display_terse/scripts/hc_display_terse.postinstall new file mode 100644 index 0000000..42a6f95 --- /dev/null +++ b/build/aix/hc_display_terse/scripts/hc_display_terse.postinstall @@ -0,0 +1,41 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) post-install script for hc_display_terse LPP package +#****************************************************************************** +# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** + +# ------------------------- 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 ..." + +# 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 +#****************************************************************************** diff --git a/build/aix/hc_notify_eif/hc_notify_eif.reqs b/build/aix/hc_notify_eif/hc_notify_eif.reqs new file mode 100644 index 0000000..f90fa90 --- /dev/null +++ b/build/aix/hc_notify_eif/hc_notify_eif.reqs @@ -0,0 +1 @@ +*prereq hc_aix.rte diff --git a/build/aix/hc_notify_eif/hc_notify_eif.template b/build/aix/hc_notify_eif/hc_notify_eif.template new file mode 100644 index 0000000..d0d35fa --- /dev/null +++ b/build/aix/hc_notify_eif/hc_notify_eif.template @@ -0,0 +1,31 @@ +Package Name: hc_notify_eif +Package VRMF: %BUILD_DATE% +Update: N +Fileset + Fileset Name: hc_notify_eif.rte + Fileset VRMF: %BUILD_DATE% + Fileset Description: Health Checker - core EIF plugin + USRLIBLPPFiles + EOUSRLIBLPPFiles + ROOTLIBLPPFiles + Post-installation Script: /export/nim/build/hc_notify_eif/scripts/hc_notify_eif.postinstall + Unpost-installation Script: /export/nim/build/hc_notify_eif/scripts/hc_notify_eif.postuninstall + EOROOTLIBLPPFiles + Bosboot required: N + License agreement acceptance required: N + Include license files in this package: N + Requisites: /export/nim/build/hc_notify_eif/hc_notify_eif.reqs + USRFiles + EOUSRFiles + ROOT Part: Y + ROOTFiles +/opt/hc/lib +/opt/hc/lib/core +/opt/hc/lib/platform/aix/notify_eif.sh +/etc/opt/hc +/etc/opt/hc/core +/etc/opt/hc/core/providers +/etc/opt/hc/core/providers/notify_eif.conf.dist + EOROOTFiles + Relocatable: N +EOFileset diff --git a/build/aix/hc_notify_eif/scripts/hc_notify_eif.postinstall b/build/aix/hc_notify_eif/scripts/hc_notify_eif.postinstall new file mode 100644 index 0000000..1051329 --- /dev/null +++ b/build/aix/hc_notify_eif/scripts/hc_notify_eif.postinstall @@ -0,0 +1,51 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) post-install script for hc_notify_eif LPP package +#****************************************************************************** +# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** + +# ------------------------- 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_eif.conf ]] +then + cp -p ${HC_ETC_DIR}/core/providers/notify_eif.conf.dist ${HC_ETC_DIR}/core/providers/notify_eif.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 +#****************************************************************************** diff --git a/build/aix/hc_notify_eif/scripts/hc_notify_eif.postuninstall b/build/aix/hc_notify_eif/scripts/hc_notify_eif.postuninstall new file mode 100644 index 0000000..1f3d636 --- /dev/null +++ b/build/aix/hc_notify_eif/scripts/hc_notify_eif.postuninstall @@ -0,0 +1,48 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) post-uninstall script for hc_notify_eif LPP package +#****************************************************************************** +# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** + +# ------------------------- 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_eif.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 +#****************************************************************************** diff --git a/build/aix/hc_notify_sms/hc_notify_sms.reqs b/build/aix/hc_notify_sms/hc_notify_sms.reqs new file mode 100644 index 0000000..f90fa90 --- /dev/null +++ b/build/aix/hc_notify_sms/hc_notify_sms.reqs @@ -0,0 +1 @@ +*prereq hc_aix.rte diff --git a/build/aix/hc_notify_sms/hc_notify_sms.template b/build/aix/hc_notify_sms/hc_notify_sms.template new file mode 100644 index 0000000..9e5b707 --- /dev/null +++ b/build/aix/hc_notify_sms/hc_notify_sms.template @@ -0,0 +1,31 @@ +Package Name: hc_notify_sms +Package VRMF: %BUILD_DATE% +Update: N +Fileset + Fileset Name: hc_notify_sms.rte + Fileset VRMF: %BUILD_DATE% + Fileset Description: Health Checker - core SMS plugin + USRLIBLPPFiles + EOUSRLIBLPPFiles + ROOTLIBLPPFiles + Post-installation Script: /export/nim/build/hc_notify_sms/scripts/hc_notify_sms.postinstall + Unpost-installation Script: /export/nim/build/hc_notify_sms/scripts/hc_notify_sms.postuninstall + EOROOTLIBLPPFiles + Bosboot required: N + License agreement acceptance required: N + Include license files in this package: N + Requisites: /export/nim/build/hc_notify_sms/hc_notify_sms.reqs + USRFiles + EOUSRFiles + ROOT Part: Y + ROOTFiles +/opt/hc/lib +/opt/hc/lib/core +/opt/hc/lib/platform/aix/notify_sms.sh +/etc/opt/hc +/etc/opt/hc/core +/etc/opt/hc/core/providers +/etc/opt/hc/core/providers/notify_sms.conf.dist + EOROOTFiles + Relocatable: N +EOFileset diff --git a/build/aix/hc_notify_sms/scripts/hc_notify_sms.postinstall b/build/aix/hc_notify_sms/scripts/hc_notify_sms.postinstall new file mode 100644 index 0000000..9e79fef --- /dev/null +++ b/build/aix/hc_notify_sms/scripts/hc_notify_sms.postinstall @@ -0,0 +1,51 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) post-install script for hc_notify_sms LPP package +#****************************************************************************** +# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** + +# ------------------------- 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_sms.conf ]] +then + cp -p ${HC_ETC_DIR}/core/providers/notify_sms.conf.dist ${HC_ETC_DIR}/core/providers/notify_sms.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 +#****************************************************************************** diff --git a/build/aix/hc_notify_sms/scripts/hc_notify_sms.postuninstall b/build/aix/hc_notify_sms/scripts/hc_notify_sms.postuninstall new file mode 100644 index 0000000..750efd1 --- /dev/null +++ b/build/aix/hc_notify_sms/scripts/hc_notify_sms.postuninstall @@ -0,0 +1,48 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) post-uninstall script for hc_notify_sms LPP package +#****************************************************************************** +# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** + +# ------------------------- 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_sms.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 +#****************************************************************************** diff --git a/build/hpux/build_hpux_depots.sh b/build/hpux/build_hpux_depots.sh new file mode 100644 index 0000000..4f90eb8 --- /dev/null +++ b/build/hpux/build_hpux_depots.sh @@ -0,0 +1,108 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) build script for HC SD packages (uses 'swpackage') +#****************************************************************************** +# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** + +#****************************************************************************** +# Requires following build (dir) structures: +# +# build/ +# build/build_hpux_depots.sh +# sources/bin/ +# sources/lib/*/ +# depots/ +# +# Build order: +# 1) Copy sources/scrips to the correct locations +# 2) Copy pristine version of the build spec file to preserver %BUILD_DATE% (.psf) +# 3) Copy template, build and installer script files into correct locations +# 4) Execute build_hpux_depots.sh +# 5) SD packages may be found in the 'depots' directory +#****************************************************************************** + +BUILD_DATE="$(date +'%Y%m%d')" +BUILD_PRETTY_DATE="$(date +'%Y.%m.%d')" +BUILD_DIR="$(dirname $0)" + +# clean up previous packages +rm -f ${BUILD_DIR}/depots/* >/dev/null + +# see if we have BUILD_DATE placeholder in PSF files +find ${BUILD_DIR} -name "*.psf" | while read FILE +do + if (( $(grep -c '%BUILD_DATE%' ${FILE}) == 0 )) + then + print -u2 "ERROR: no %BUILD_DATE% placeholder in ${FILE}!" + exit 1 + fi +done + +# replace BUILD_DATE placeholder in PSF files +find ${BUILD_DIR} -name "*.psf" | while read FILE +do + perl -pi -e "s/%BUILD_DATE%/${BUILD_PRETTY_DATE}/g" ${FILE} +done + +# build hc_hpux package +cd ${BUILD_DIR}/hc_hpux/ +swpackage -s hc_hpux.psf -x media_type=tape -d ../../depots/hc_hpux-${BUILD_DATE}.sd +swpackage -s hc_hpux.psf @ /var/opt/depot/kudos +cd - + +# build hc_hpux_platform package +cd ${BUILD_DIR}/hc_hpux_platform +swpackage -s hc_hpux_platform.psf -x media_type=tape -d ../../depots/hc_hpux_platform-${BUILD_DATE}.sd +swpackage -s hc_hpux_platform.psf @ /var/opt/depot/kudos +cd - + +# build hc_display_csv package +cd ${BUILD_DIR}/hc_display_csv +swpackage -s hc_display_csv.psf -x media_type=tape -d ../../depots/hc_display_csv-${BUILD_DATE}.sd +swpackage -s hc_display_csv.psf @ /var/opt/depot/kudos +cd - + +# build hc_display_init package +cd ${BUILD_DIR}/hc_display_init +swpackage -s hc_display_init.psf -x media_type=tape -d ../../depots/hc_display_init-${BUILD_DATE}.sd +swpackage -s hc_display_init.psf @ /var/opt/depot/kudos +cd - + +# build hc_display_terse package +cd ${BUILD_DIR}/hc_display_terse +swpackage -s hc_display_terse.psf -x media_type=tape -d ../../depots/hc_display_terse-${BUILD_DATE}.sd +swpackage -s hc_display_terse.psf @ /var/opt/depot/kudos +cd - + +# build hc_notify_sms package +cd ${BUILD_DIR}/hc_notify_sms +swpackage -s hc_notify_sms.psf -x media_type=tape -d ../../depots/hc_notify_sms-${BUILD_DATE}.sd +swpackage -s hc_notify_sms.psf @ /var/opt/depot/kudos +cd - + +# build hc_notify_eif package +cd ${BUILD_DIR}/hc_notify_eif +swpackage -s hc_notify_eif.psf -x media_type=tape -d ../../depots/hc_notify_eif-${BUILD_DATE}.sd +swpackage -s hc_notify_eif.psf @ /var/opt/depot/kudos +cd - + +print "List of built packages:" +ls -l ${BUILD_DIR}/../depots/* + +# when installed on an ignite server: possible addition of depot registration here + +exit 0 + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/build/hpux/hc_display_csv/hc_display_csv.psf b/build/hpux/hc_display_csv/hc_display_csv.psf new file mode 100644 index 0000000..eb546fc --- /dev/null +++ b/build/hpux/hc_display_csv/hc_display_csv.psf @@ -0,0 +1,64 @@ +# 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-DISPLAY-CSV + title "The Health Checker (HC) for UNIX (core CSV display plugin)" + os_name HP-UX + revision %BUILD_DATE% + architecture HP-UX_B.11_32/64 + machine_type ia64* + vendor_tag KUDOS + contents HC-DISPLAY-CSV-MAIN,r=,a=,v= +end + +# Product definitions: +product + tag HC-DISPLAY-CSV-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 CSV display 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_display_csv.postinstall + postremove scripts/hc_display_csv.postremove + + # Fileset definitions: + fileset + tag core_plugins + title UX Health Checker (core CSV display 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 ../../sources/lib/core=/opt/hc/lib/core + file -m 755 display_csv.sh + end +end diff --git a/build/hpux/hc_display_csv/scripts/hc_display_csv.postinstall b/build/hpux/hc_display_csv/scripts/hc_display_csv.postinstall new file mode 100644 index 0000000..4fcfb31 --- /dev/null +++ b/build/hpux/hc_display_csv/scripts/hc_display_csv.postinstall @@ -0,0 +1,41 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) post-install script for HC-DISPLAY-CSV SD package +#****************************************************************************** +# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** + +# ------------------------- 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 ..." + +# 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 +#****************************************************************************** diff --git a/build/hpux/hc_display_csv/scripts/hc_display_csv.postremove b/build/hpux/hc_display_csv/scripts/hc_display_csv.postremove new file mode 100644 index 0000000..906cc01 --- /dev/null +++ b/build/hpux/hc_display_csv/scripts/hc_display_csv.postremove @@ -0,0 +1,41 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) post-remove script for HC-DISPLAY-CSV SD package +#****************************************************************************** +# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** + +# ------------------------- 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 ..." + +# 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 +#****************************************************************************** diff --git a/build/hpux/hc_display_init/hc_display_init.psf b/build/hpux/hc_display_init/hc_display_init.psf new file mode 100644 index 0000000..683a03d --- /dev/null +++ b/build/hpux/hc_display_init/hc_display_init.psf @@ -0,0 +1,64 @@ +# 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-DISPLAY-INIT + title "The Health Checker (HC) for UNIX (core INIT display plugin)" + os_name HP-UX + revision %BUILD_DATE% + architecture HP-UX_B.11_32/64 + machine_type ia64* + vendor_tag KUDOS + contents HC-DISPLAY-INIT-MAIN,r=,a=,v= +end + +# Product definitions: +product + tag HC-DISPLAY-INIT-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 INIT display 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_display_init.postinstall + postremove scripts/hc_display_init.postremove + + # Fileset definitions: + fileset + tag core_plugins + title UX Health Checker (core INIT display 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 ../../sources/lib/core=/opt/hc/lib/core + file -m 755 display_init.sh + end +end diff --git a/build/hpux/hc_display_init/scripts/hc_display_init.postinstall b/build/hpux/hc_display_init/scripts/hc_display_init.postinstall new file mode 100644 index 0000000..efc0740 --- /dev/null +++ b/build/hpux/hc_display_init/scripts/hc_display_init.postinstall @@ -0,0 +1,41 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) post-install script for HC-DISPLAY-INIT SD package +#****************************************************************************** +# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** + +# ------------------------- 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 ..." + +# 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 +#****************************************************************************** diff --git a/build/hpux/hc_display_init/scripts/hc_display_init.postremove b/build/hpux/hc_display_init/scripts/hc_display_init.postremove new file mode 100644 index 0000000..918f03a --- /dev/null +++ b/build/hpux/hc_display_init/scripts/hc_display_init.postremove @@ -0,0 +1,41 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) post-remove script for HC-DISPLAY-INIT SD package +#****************************************************************************** +# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** + +# ------------------------- 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 ..." + +# 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 +#****************************************************************************** diff --git a/build/hpux/hc_display_terse/hc_display_terse.psf b/build/hpux/hc_display_terse/hc_display_terse.psf new file mode 100644 index 0000000..5e5cbb0 --- /dev/null +++ b/build/hpux/hc_display_terse/hc_display_terse.psf @@ -0,0 +1,64 @@ +# 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-DISPLAY-TERSE + title "The Health Checker (HC) for UNIX (core TERSE display plugin)" + os_name HP-UX + revision %BUILD_DATE% + architecture HP-UX_B.11_32/64 + machine_type ia64* + vendor_tag KUDOS + contents HC-DISPLAY-TERSE-MAIN,r=,a=,v= +end + +# Product definitions: +product + tag HC-DISPLAY-TERSE-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 TERSE display 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_display_terse.postinstall + postremove scripts/hc_display_terse.postremove + + # Fileset definitions: + fileset + tag core_plugins + title UX Health Checker (core TERSE display 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 ../../sources/lib/core=/opt/hc/lib/core + file -m 755 display_terse.sh + end +end diff --git a/build/hpux/hc_display_terse/scripts/hc_display_terse.postinstall b/build/hpux/hc_display_terse/scripts/hc_display_terse.postinstall new file mode 100644 index 0000000..71b3175 --- /dev/null +++ b/build/hpux/hc_display_terse/scripts/hc_display_terse.postinstall @@ -0,0 +1,41 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) post-install script for HC-DISPLAY-TERSE SD package +#****************************************************************************** +# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** + +# ------------------------- 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 ..." + +# 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 +#****************************************************************************** diff --git a/build/hpux/hc_display_terse/scripts/hc_display_terse.postremove b/build/hpux/hc_display_terse/scripts/hc_display_terse.postremove new file mode 100644 index 0000000..199b790 --- /dev/null +++ b/build/hpux/hc_display_terse/scripts/hc_display_terse.postremove @@ -0,0 +1,41 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) post-remove script for HC-DISPLAY-TERSE SD package +#****************************************************************************** +# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** + +# ------------------------- 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 ..." + +# 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 +#****************************************************************************** diff --git a/build/hpux/hc_hpux/hc_hpux.psf b/build/hpux/hc_hpux/hc_hpux.psf new file mode 100644 index 0000000..eb0952a --- /dev/null +++ b/build/hpux/hc_hpux/hc_hpux.psf @@ -0,0 +1,118 @@ +# 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-HPUX + title "The Health Checker (HC) for UNIX" + os_name HP-UX + revision %BUILD_DATE% + architecture HP-UX_B.11_32/64 + machine_type ia64* + vendor_tag KUDOS + contents HC-HPUX-MAIN,r=,a=,v= +end + +# Product definitions: +product + tag HC-HPUX-MAIN + revision %BUILD_DATE% + category tools + category_title Tools + title "The Health Checker (HC) for UNIX" + 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." + 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_hpux.postinstall + postremove scripts/hc_hpux.postremove + + # Fileset definitions: + fileset + tag scripts + title UX Health Checker (scripts) + is_kernel false + is_locatable false + is_reboot false + is_sparse false + is_patch false + + file_permissions -u 0222 -o root -g sys + + directory ../../sources/bin=/opt/hc/bin + file -m 755 check_health.sh + directory ../../sources/lib/core=/opt/hc/lib/core + file -m 755 include_core.sh + file -m 755 include_data.sh + file -m 755 include_os.sh + end + + fileset + tag core_plugins + title UX Health Checker (core plugins) + is_kernel false + is_locatable false + is_reboot false + is_sparse false + is_patch false + + file_permissions -u 0222 -o root -g sys + + directory ../../sources/lib/core=/opt/hc/lib/core + file -m 755 notify_mail.sh + end + + fileset + tag config + title UX Health Checker (configuration) + is_kernel false + is_locatable false + is_reboot false + is_sparse false + is_patch false + prerequisite HC-HPUX-MAIN.scripts + + file_permissions -u 0222 -o root -g sys + + directory ../../sources/etc/core=/etc/opt/hc/core + file -m 644 check_health.conf.dist + directory ../../sources/etc=/etc/opt/hc + file -m 644 check_host.conf.dist + end + + fileset + tag templates + title UX Health Checker (templates) + is_kernel false + is_locatable false + is_reboot false + is_sparse false + is_patch false + prerequisite HC-HPUX-MAIN.scripts + + file_permissions -u 0222 -o root -g sys + + directory ../../sources/etc/core/templates=/etc/opt/hc/core/templates + file -m 644 mail_info.tpl + file -m 644 mail_header.tpl + file -m 644 mail_body.tpl + file -m 644 mail_footer.tpl + end +end diff --git a/build/hpux/hc_hpux/scripts/hc_hpux.postinstall b/build/hpux/hc_hpux/scripts/hc_hpux.postinstall new file mode 100644 index 0000000..77a77d1 --- /dev/null +++ b/build/hpux/hc_hpux/scripts/hc_hpux.postinstall @@ -0,0 +1,96 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) post-install script for HC-HPUX SD package +#****************************************************************************** +# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** + +# ------------------------- CONFIGURATION starts here ------------------------- +# location of ETC dir +HC_ETC_DIR="/etc/opt/hc" +# location of VAR dir +HC_VAR_DIR="/var/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 ..." + +# create ETC DIR +if [[ ! -d ${HC_ETC_DIR} ]] +then + mkdir -p ${HC_ETC_DIR} >/dev/null || \ + { + print -u2 "ERROR: could not create directory ${HC_ETC_DIR}" + exit 1 + } + chmod 755 ${HC_ETC_DIR} >/dev/null || \ + print -u2 "WARN: could not 'chmod 755' on directory ${HC_ETC_DIR}" +fi +if [[ ! -d ${HC_ETC_DIR}/core ]] +then + mkdir -p ${HC_ETC_DIR}/core >/dev/null || \ + { + print -u2 "ERROR: could not create directory ${HC_ETC_DIR}/core" + exit 1 + } + chmod 755 ${HC_ETC_DIR} >/dev/null || \ + print -u2 "WARN: could not 'chmod 755' on directory ${HC_ETC_DIR}/core" +fi + +# copy main config file from dist (if needed) +if [[ ! -f ${HC_ETC_DIR}/core/check_health.conf ]] +then + cp -p ${HC_ETC_DIR}/core/check_health.conf.dist ${HC_ETC_DIR}/core/check_health.conf >/dev/null || \ + { + print -u2 "ERROR: could not copy main config file in ${HC_ETC_DIR}/core" + exit 1 + } +fi +# copy host check config file from dist (if needed) +if [[ ! -f ${HC_ETC_DIR}/check_host.conf ]] +then + cp -p ${HC_ETC_DIR}/check_host.conf.dist ${HC_ETC_DIR}/check_host.conf >/dev/null || \ + { + print -u2 "ERROR: could not copy host check config file in ${HC_ETC_DIR}" + exit 1 + } +fi + +# create VAR DIR +if [[ ! -d ${HC_VAR_DIR} ]] +then + mkdir -p ${HC_VAR_DIR} >/dev/null || \ + { + print -u2 "ERROR: could not create directory ${HC_VAR_DIR}" + exit 1 + } + chmod 755 ${HC_VAR_DIR} >/dev/null || \ + print -u2 "WARN: could not 'chmod 755' on directory ${HC_VAR_DIR}" +fi + +# refresh symbolic FPATH links for core plugins +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 +#****************************************************************************** diff --git a/build/hpux/hc_hpux/scripts/hc_hpux.postremove b/build/hpux/hc_hpux/scripts/hc_hpux.postremove new file mode 100644 index 0000000..fa5c759 --- /dev/null +++ b/build/hpux/hc_hpux/scripts/hc_hpux.postremove @@ -0,0 +1,65 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) post-remove script for HC-HPUX SD package +#****************************************************************************** +# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** + +# ------------------------- CONFIGURATION starts here ------------------------- +# location of ETC dir +HC_ETC_DIR="/etc/opt/hc" +# location of VAR dir +HC_VAR_DIR="/var/opt/hc" +# location of MAIN dir +HC_MAIN_DIR="/opt/hc" +# ------------------------- CONFIGURATION ends here --------------------------- + +print "INFO: starting post-remove script ..." + +# remove ETC DIR (only .dist files) +if [[ -d ${HC_ETC_DIR} ]] +then + rm -rf ${HC_ETC_DIR}/*.dist >/dev/null || \ + print -u2 "WARN: could not remove .dist files in directory ${HC_ETC_DIR}" +fi +if [[ -d ${HC_ETC_DIR}/core ]] +then + rm -rf ${HC_ETC_DIR}/core/*.dist >/dev/null || \ + print -u2 "WARN: could not remove .dist files in directory ${HC_ETC_DIR}/core" +fi +if [[ -d ${HC_ETC_DIR}/core/providers ]] +then + rm -rf ${HC_ETC_DIR}/core/providers/*.dist >/dev/null || \ + print -u2 "WARN: could not remove .dist files in directory ${HC_ETC_DIR}/core/providers" +fi + +# remove VAR DIR (temporary state only) +if [[ -d ${HC_VAR_DIR} ]] +then + rm -rf ${HC_VAR_DIR}/state/temporary >/dev/null || \ + print -u2 "WARN: could not remove directory ${HC_VAR_DIR}/state/temporary" +fi + +# remove MAIN DIR +if [[ -d ${HC_MAIN_DIR} ]] +then + rm -rf ${HC_MAIN_DIR} >/dev/null || \ + print -u2 "WARN: could not remove directory ${HC_VAR_DIR}" +fi + +print "INFO: finished post-remove script" + +exit 0 + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/build/hpux/hc_hpux_platform/hc_hpux_platform.psf b/build/hpux/hc_hpux_platform/hc_hpux_platform.psf new file mode 100644 index 0000000..0ef162e --- /dev/null +++ b/build/hpux/hc_hpux_platform/hc_hpux_platform.psf @@ -0,0 +1,136 @@ +# 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-PLATFORM + title "The Health Checker (HC) for UNIX (OS plugins)" + os_name HP-UX + revision %BUILD_DATE% + architecture HP-UX_B.11_32/64 + machine_type ia64* + vendor_tag KUDOS + contents HC-PLATFORM-MAIN,r=,a=,v= +end + +# Product definitions: +product + tag HC-PLATFORM-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 OS/platform 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_hpux_platform.postinstall + postremove scripts/hc_hpux_platform.postremove + + # Fileset definitions: + fileset + tag plugins + title UX Health Checker (OS/Platform 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 ../../sources/lib/platform/hp-ux=/opt/hc/lib/platform/hp-ux + file -m 755 check_hpux_autopath.sh + file -m 755 check_hpux_file_age.sh + file -m 755 check_hpux_file_change.sh + file -m 755 check_hpux_fs_mounts.sh + file -m 755 check_hpux_fs_mounts_options.sh + 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 644 check_hpux_hpvm_vpar_status.sh + file -m 755 check_hpux_httpd_status.sh + file -m 755 check_hpux_named_status.sh + file -m 755 check_hpux_ntp_status.sh + file -m 755 check_hpux_ovpa_status.sh + file -m 755 check_hpux_postfix_status.sh + file -m 755 check_hpux_root_crontab.sh + file -m 755 check_hpux_sg_package_status.sh + file -m 755 check_hpux_sg_package_config.sh + file -m 755 check_hpux_sg_cluster_status.sh + file -m 755 check_hpux_sg_cluster_config.sh + file -m 755 check_hpux_sg_qs_status.sh + file -m 755 check_hpux_sshd_status.sh + file -m 755 check_hpux_syslog.sh + file -m 755 check_hpux_vg_minor_number.sh + end + + fileset + tag config + title UX Health Checker (OS/Platform plugins: configuration) + is_kernel false + is_locatable false + is_reboot false + is_sparse false + is_patch false + prerequisite HC-PLATFORM-MAIN.plugins + + file_permissions -u 0222 -o root -g sys + + directory ../../sources/etc/=/etc/opt/hc + file -m 644 check_hpux_file_age.conf.dist + file -m 644 check_hpux_file_change.conf.dist + file -m 644 check_hpux_fs_mounts_options.conf.dist + file -m 644 check_hpux_hpvm_vpar_status.conf.dist + file -m 644 check_hpux_ignite_backup.conf.dist + file -m 644 check_hpux_ioscan.conf.dist + file -m 644 check_hpux_ntp_status.conf.dist + file -m 644 check_hpux_root_crontab.conf.dist + file -m 644 check_hpux_sg_package_status.conf.dist + file -m 644 check_hpux_sg_package_config.conf.dist + file -m 644 check_hpux_sg_cluster_status.conf.dist + file -m 644 check_hpux_sg_cluster_config.conf.dist + file -m 644 check_hpux_syslog.conf.dist + end + + fileset + tag templates + title UX Health Checker (OS/Platform plugins: templates) + is_kernel false + is_locatable false + is_reboot false + is_sparse false + is_patch false + prerequisite HC-PLATFORM-MAIN.plugins + + file_permissions -u 0222 -o root -g sys + + directory ../../sources/etc/core/templates=/etc/opt/hc/core/templates + file -m 644 mail_body.tpl-check_hpux_fs_mounts_options + file -m 644 mail_body.tpl-check_hpux_ioscan + file -m 644 mail_body.tpl-check_hpux_ovpa_status + file -m 644 mail_body.tpl-check_hpux_root_crontab + file -m 644 mail_body.tpl-check_hpux_sg_cluster_status + file -m 644 mail_body.tpl-check_hpux_sg_package_status + file -m 644 mail_body.tpl-check_hpux_vg_minor_number + end +end diff --git a/build/hpux/hc_hpux_platform/scripts/hc_hpux_platform.postinstall b/build/hpux/hc_hpux_platform/scripts/hc_hpux_platform.postinstall new file mode 100644 index 0000000..7e3f8dd --- /dev/null +++ b/build/hpux/hc_hpux_platform/scripts/hc_hpux_platform.postinstall @@ -0,0 +1,39 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) post-install script for HC-PLATFORM SD package +#****************************************************************************** +# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** + +# ------------------------- 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 --------------------------- + +print "INFO: starting post-install script ..." + +# 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 +#****************************************************************************** diff --git a/build/hpux/hc_hpux_platform/scripts/hc_hpux_platform.postremove b/build/hpux/hc_hpux_platform/scripts/hc_hpux_platform.postremove new file mode 100644 index 0000000..938260a --- /dev/null +++ b/build/hpux/hc_hpux_platform/scripts/hc_hpux_platform.postremove @@ -0,0 +1,39 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) post-remove script for HC-PLATFORM SD package +#****************************************************************************** +# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** + +# ------------------------- 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 --------------------------- + +print "INFO: starting post-remove script ..." + +# 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 +#****************************************************************************** diff --git a/build/hpux/hc_notify_eif/hc_notify_eif.psf b/build/hpux/hc_notify_eif/hc_notify_eif.psf new file mode 100644 index 0000000..adf3bc0 --- /dev/null +++ b/build/hpux/hc_notify_eif/hc_notify_eif.psf @@ -0,0 +1,80 @@ +# 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-EIF + title "The Health Checker (HC) for UNIX (core EIF plugin)" + os_name HP-UX + revision %BUILD_DATE% + architecture HP-UX_B.11_32/64 + machine_type ia64* + vendor_tag KUDOS + contents HC-NOTIFY-EIF-MAIN,r=,a=,v= +end + +# Product definitions: +product + tag HC-NOTIFY-EIF-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 EIF 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_eif.postinstall + postremove scripts/hc_notify_eif.postremove + + # Fileset definitions: + fileset + tag core_plugins + title UX Health Checker (core EIF 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 ../../sources/lib/core=/opt/hc/lib/core + file -m 755 notify_eif.sh + end + + fileset + tag config + title UX Health Checker (core EIF plugins: configuration) + is_kernel false + is_locatable false + is_reboot false + is_sparse false + is_patch false + prerequisite HC-NOTIFY-EIF-MAIN.core_plugins + + file_permissions -u 0222 -o root -g sys + + directory ../../sources/etc/core/providers=/etc/opt/hc/core/providers + file -m 644 notify_eif.conf.dist + end +end diff --git a/build/hpux/hc_notify_eif/scripts/hc_notify_eif.postinstall b/build/hpux/hc_notify_eif/scripts/hc_notify_eif.postinstall new file mode 100644 index 0000000..bd0cf69 --- /dev/null +++ b/build/hpux/hc_notify_eif/scripts/hc_notify_eif.postinstall @@ -0,0 +1,51 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) post-install script for HC-NOTIFY-EIF SD package +#****************************************************************************** +# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** + +# ------------------------- 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_eif.conf ]] +then + cp -p ${HC_ETC_DIR}/core/providers/notify_eif.conf.dist ${HC_ETC_DIR}/core/providers/notify_eif.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 +#****************************************************************************** diff --git a/build/hpux/hc_notify_eif/scripts/hc_notify_eif.postremove b/build/hpux/hc_notify_eif/scripts/hc_notify_eif.postremove new file mode 100644 index 0000000..52e7709 --- /dev/null +++ b/build/hpux/hc_notify_eif/scripts/hc_notify_eif.postremove @@ -0,0 +1,48 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) post-remove script for HC-NOTIFY-EIF SD package +#****************************************************************************** +# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** + +# ------------------------- 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_eif.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 +#****************************************************************************** diff --git a/build/hpux/hc_notify_sms/hc_notify_sms.psf b/build/hpux/hc_notify_sms/hc_notify_sms.psf new file mode 100644 index 0000000..8383d0a --- /dev/null +++ b/build/hpux/hc_notify_sms/hc_notify_sms.psf @@ -0,0 +1,80 @@ +# 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-SMS + title "The Health Checker (HC) for UNIX (core SMS plugin)" + os_name HP-UX + revision %BUILD_DATE% + architecture HP-UX_B.11_32/64 + machine_type ia64* + vendor_tag KUDOS + contents HC-NOTIFY-SMS-MAIN,r=,a=,v= +end + +# Product definitions: +product + tag HC-NOTIFY-SMS-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 SMS 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_sms.postinstall + postremove scripts/hc_notify_sms.postremove + + # Fileset definitions: + fileset + tag core_plugins + title UX Health Checker (core SMS 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 ../../sources/lib/core=/opt/hc/lib/core + file -m 755 notify_sms.sh + end + + fileset + tag config + title UX Health Checker (core SMS plugins: configuration) + is_kernel false + is_locatable false + is_reboot false + is_sparse false + is_patch false + prerequisite HC-NOTIFY-SMS-MAIN.core_plugins + + file_permissions -u 0222 -o root -g sys + + directory ../../sources/etc/core/providers=/etc/opt/hc/core/providers + file -m 644 notify_sms.conf.dist + end +end diff --git a/build/hpux/hc_notify_sms/scripts/hc_notify_sms.postinstall b/build/hpux/hc_notify_sms/scripts/hc_notify_sms.postinstall new file mode 100644 index 0000000..ce4cd92 --- /dev/null +++ b/build/hpux/hc_notify_sms/scripts/hc_notify_sms.postinstall @@ -0,0 +1,51 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) post-install script for HC-NOTIFY-SMS SD package +#****************************************************************************** +# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** + +# ------------------------- 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_sms.conf ]] +then + cp -p ${HC_ETC_DIR}/core/providers/notify_sms.conf.dist ${HC_ETC_DIR}/core/providers/notify_sms.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 +#****************************************************************************** diff --git a/build/hpux/hc_notify_sms/scripts/hc_notify_sms.postremove b/build/hpux/hc_notify_sms/scripts/hc_notify_sms.postremove new file mode 100644 index 0000000..59d784c --- /dev/null +++ b/build/hpux/hc_notify_sms/scripts/hc_notify_sms.postremove @@ -0,0 +1,48 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) post-remove script for HC-NOTIFY-SMS SD package +#****************************************************************************** +# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** + +# ------------------------- 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_sms.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 +#****************************************************************************** diff --git a/build/linux/SPECS/hc-display-csv.spec b/build/linux/SPECS/hc-display-csv.spec new file mode 100644 index 0000000..6ff4aeb --- /dev/null +++ b/build/linux/SPECS/hc-display-csv.spec @@ -0,0 +1,69 @@ +%define build_timestamp %(date +"%Y%m%d") + +Name: hc-display-csv +Version: %{build_timestamp} +Release: 1 + +Summary: The KUDOS Health Checker (HC) for UNIX (CSV display 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 (display). + +%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/lib/core/display_csv.sh $RPM_BUILD_ROOT/opt/hc/lib/core/display_csv.sh + +%post +# ------------------------- 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" + +%postun +# ------------------------- 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" + +%files +%defattr(-,root,root,755) +%dir /opt/hc/lib +%dir /opt/hc/lib/core +%attr(755, root, root) /opt/hc/lib/core/display_csv.sh + +%changelog +* Sat May 06 2017 - 0.0.1 +- Initial build diff --git a/build/linux/SPECS/hc-display-init.spec b/build/linux/SPECS/hc-display-init.spec new file mode 100644 index 0000000..61e0548 --- /dev/null +++ b/build/linux/SPECS/hc-display-init.spec @@ -0,0 +1,69 @@ +%define build_timestamp %(date +"%Y%m%d") + +Name: hc-display-init +Version: %{build_timestamp} +Release: 1 + +Summary: The KUDOS Health Checker (HC) for UNIX (init display 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 (display). + +%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/lib/core/display_init.sh $RPM_BUILD_ROOT/opt/hc/lib/core/display_init.sh + +%post +# ------------------------- 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" + +%postun +# ------------------------- 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" + +%files +%defattr(-,root,root,755) +%dir /opt/hc/lib +%dir /opt/hc/lib/core +%attr(755, root, root) /opt/hc/lib/core/display_init.sh + +%changelog +* Mon May 08 2017 - 0.0.1 +- Initial build diff --git a/build/linux/SPECS/hc-display-terse.spec b/build/linux/SPECS/hc-display-terse.spec new file mode 100644 index 0000000..1cae32c --- /dev/null +++ b/build/linux/SPECS/hc-display-terse.spec @@ -0,0 +1,69 @@ +%define build_timestamp %(date +"%Y%m%d") + +Name: hc-display-terse +Version: %{build_timestamp} +Release: 1 + +Summary: The KUDOS Health Checker (HC) for UNIX (terse display 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 (display). + +%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/lib/core/display_terse.sh $RPM_BUILD_ROOT/opt/hc/lib/core/display_terse.sh + +%post +# ------------------------- 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" + +%postun +# ------------------------- 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" + +%files +%defattr(-,root,root,755) +%dir /opt/hc/lib +%dir /opt/hc/lib/core +%attr(755, root, root) /opt/hc/lib/core/display_terse.sh + +%changelog +* Sat May 06 2017 - 0.0.1 +- Initial build diff --git a/build/linux/SPECS/hc-kudos.spec b/build/linux/SPECS/hc-kudos.spec new file mode 100644 index 0000000..845ba3c --- /dev/null +++ b/build/linux/SPECS/hc-kudos.spec @@ -0,0 +1,76 @@ +%define build_timestamp %(date +"%Y%m%d") + +Name: hc-kudos +Version: %{build_timestamp} +Release: 1 + +Summary: The KUDOS Health Checker (HC) for UNIX (KUDOS plugins) +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 the KUDOS specific plugins. + +%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/customer +install -d -m 755 $RPM_BUILD_ROOT/opt/hc/lib/customer/kudos +cp ../SOURCES/lib/customer/kudos/check_kudos_kapow_credits.sh $RPM_BUILD_ROOT/opt/hc/lib/customer/kudos/check_kudos_kapow_credits.sh +install -d -m 755 $RPM_BUILD_ROOT/etc/opt/hc +cp ../SOURCES/etc/check_kudos_kapow_credits.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/check_kudos_kapow_credits.conf.dist + + +%post +# ------------------------- 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" + +%postun +# ------------------------- 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" + +%files +%defattr(-,root,root,755) +%dir /opt/hc/lib +%dir /opt/hc/lib/customer +%dir /opt/hc/lib/customer/kudos +%attr(755, root, root) /opt/hc/lib/customer/kudos/check_kudos_kapow_credits.sh +%dir /etc/opt/hc +%attr(644, root, root) /etc/opt/hc/check_kudos_kapow_credits.conf.dist + +%changelog +* Fri Nov 11 2016 - 0.0.1 +- Initial build diff --git a/build/linux/SPECS/hc-linux-platform.spec b/build/linux/SPECS/hc-linux-platform.spec new file mode 100644 index 0000000..2ea4ada --- /dev/null +++ b/build/linux/SPECS/hc-linux-platform.spec @@ -0,0 +1,169 @@ +%define build_timestamp %(date +"%Y%m%d") + +Name: hc-linux-platform +Version: %{build_timestamp} +Release: 1 + +Summary: The KUDOS Health Checker (HC) for UNIX (platform plugins) +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 platform/OS specific plugins. + +%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/platform +install -d -m 755 $RPM_BUILD_ROOT/opt/hc/lib/platform/linux +cp ../SOURCES/lib/platform/linux/check_linux_burp_backup.sh $RPM_BUILD_ROOT/opt/hc/lib/platform/linux/check_linux_burp_backup.sh +cp ../SOURCES/lib/platform/linux/check_linux_file_age.sh $RPM_BUILD_ROOT/opt/hc/lib/platform/linux/check_linux_file_age.sh +cp ../SOURCES/lib/platform/linux/check_linux_file_change.sh $RPM_BUILD_ROOT/opt/hc/lib/platform/linux/check_linux_file_change.sh +cp ../SOURCES/lib/platform/linux/check_linux_fs_mounts.sh $RPM_BUILD_ROOT/opt/hc/lib/platform/linux/check_linux_fs_mounts.sh +cp ../SOURCES/lib/platform/linux/check_linux_burp_status.sh $RPM_BUILD_ROOT/opt/hc/lib/platform/linux/check_linux_burp_status.sh +cp ../SOURCES/lib/platform/linux/check_linux_httpd_status.sh $RPM_BUILD_ROOT/opt/hc/lib/platform/linux/check_linux_httpd_status.sh +cp ../SOURCES/lib/platform/linux/check_linux_named_status.sh $RPM_BUILD_ROOT/opt/hc/lib/platform/linux/check_linux_named_status.sh +cp ../SOURCES/lib/platform/linux/check_linux_postfix_status.sh $RPM_BUILD_ROOT/opt/hc/lib/platform/linux/check_linux_postfix_status.sh +cp ../SOURCES/lib/platform/linux/check_linux_samba_status.sh $RPM_BUILD_ROOT/opt/hc/lib/platform/linux/check_linux_samba_status.sh +cp ../SOURCES/lib/platform/linux/check_linux_shorewall_status.sh $RPM_BUILD_ROOT/opt/hc/lib/platform/linux/check_linux_shorewall_status.sh +cp ../SOURCES/lib/platform/linux/check_linux_sshd_status.sh $RPM_BUILD_ROOT/opt/hc/lib/platform/linux/check_linux_sshd_status.sh +cp ../SOURCES/lib/platform/linux/check_linux_winbind_status.sh $RPM_BUILD_ROOT/opt/hc/lib/platform/linux/check_linux_winbind_status.sh +cp ../SOURCES/lib/platform/linux/check_linux_hpasmcli.sh $RPM_BUILD_ROOT/opt/hc/lib/platform/linux/check_linux_hpasmcli.sh +cp ../SOURCES/lib/platform/linux/check_linux_hpacucli.sh $RPM_BUILD_ROOT/opt/hc/lib/platform/linux/check_linux_hpacucli.sh +cp ../SOURCES/lib/platform/linux/check_linux_hplog.sh $RPM_BUILD_ROOT/opt/hc/lib/platform/linux/check_linux_hplog.sh +cp ../SOURCES/lib/platform/linux/check_linux_hpssacli.sh $RPM_BUILD_ROOT/opt/hc/lib/platform/linux/check_linux_hpssacli.sh +cp ../SOURCES/lib/platform/linux/check_linux_root_crontab.sh $RPM_BUILD_ROOT/opt/hc/lib/platform/linux/check_linux_root_crontab.sh +cp ../SOURCES/lib/platform/linux/check_linux_sg_cluster_config.sh $RPM_BUILD_ROOT/opt/hc/lib/platform/linux/check_linux_sg_cluster_config.sh +cp ../SOURCES/lib/platform/linux/check_linux_sg_cluster_status.sh $RPM_BUILD_ROOT/opt/hc/lib/platform/linux/check_linux_sg_cluster_status.sh +cp ../SOURCES/lib/platform/linux/check_linux_sg_package_config.sh $RPM_BUILD_ROOT/opt/hc/lib/platform/linux/check_linux_sg_package_config.sh +cp ../SOURCES/lib/platform/linux/check_linux_sg_package_status.sh $RPM_BUILD_ROOT/opt/hc/lib/platform/linux/check_linux_sg_package_status.sh +cp ../SOURCES/lib/platform/linux/check_linux_sg_qs_status.sh $RPM_BUILD_ROOT/opt/hc/lib/platform/linux/check_linux_sg_qs_status.sh +cp ../SOURCES/lib/platform/linux/check_linux_vz_ct_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/check_linux_burp_backup.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/check_linux_burp_backup.conf.dist +cp ../SOURCES/etc/check_linux_file_age.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/check_linux_file_age.conf.dist +cp ../SOURCES/etc/check_linux_file_change.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/check_linux_file_change.conf.dist +cp ../SOURCES/etc/check_linux_hpasmcli.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/check_linux_hpasmcli.conf.dist +cp ../SOURCES/etc/check_linux_hpacucli.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/check_linux_hpacucli.conf.dist +cp ../SOURCES/etc/check_linux_hplog.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/check_linux_hplog.conf.dist +cp ../SOURCES/etc/check_linux_hpssacli.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/check_linux_hpssacli.conf.dist +cp ../SOURCES/etc/check_linux_root_crontab.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/check_linux_root_crontab.conf.dist +cp ../SOURCES/etc/check_linux_sg_cluster_config.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/check_linux_sg_cluster_config.conf.dist +cp ../SOURCES/etc/check_linux_sg_cluster_status.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/check_linux_sg_cluster_status.conf.dist +cp ../SOURCES/etc/check_linux_sg_package_config.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/check_linux_sg_package_config.conf.dist +cp ../SOURCES/etc/check_linux_sg_package_status.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/check_linux_sg_package_status.conf.dist +cp ../SOURCES/etc/check_linux_vz_ct_status.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/check_linux_vz_ct_status.conf.dist +install -d -m 755 $RPM_BUILD_ROOT/etc/opt/hc/core +install -d -m 755 $RPM_BUILD_ROOT/etc/opt/hc/core/templates +cp ../SOURCES/etc/core/templates/mail_body.tpl-check_linux_fs_mounts_options $RPM_BUILD_ROOT/etc/opt/hc/core/templates +cp ../SOURCES/etc/core/templates/mail_body.tpl-check_linux_root_crontab $RPM_BUILD_ROOT/etc/opt/hc/core/templates + +%post +# ------------------------- 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" + +%postun +# ------------------------- 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" + +%files +%defattr(-,root,root,755) +%dir /opt/hc/lib +%dir /opt/hc/lib/platform +%dir /opt/hc/lib/platform/linux +%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_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 +%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_httpd_status.sh +%attr(755, root, root) /opt/hc/lib/platform/linux/check_linux_named_status.sh +%attr(755, root, root) /opt/hc/lib/platform/linux/check_linux_postfix_status.sh +%attr(755, root, root) /opt/hc/lib/platform/linux/check_linux_samba_status.sh +%attr(755, root, root) /opt/hc/lib/platform/linux/check_linux_shorewall_status.sh +%attr(755, root, root) /opt/hc/lib/platform/linux/check_linux_sshd_status.sh +%attr(755, root, root) /opt/hc/lib/platform/linux/check_linux_winbind_status.sh +%attr(755, root, root) /opt/hc/lib/platform/linux/check_linux_hpasmcli.sh +%attr(755, root, root) /opt/hc/lib/platform/linux/check_linux_hpacucli.sh +%attr(755, root, root) /opt/hc/lib/platform/linux/check_linux_hplog.sh +%attr(755, root, root) /opt/hc/lib/platform/linux/check_linux_hpssacli.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_sg_cluster_config.sh +%attr(755, root, root) /opt/hc/lib/platform/linux/check_linux_sg_cluster_status.sh +%attr(755, root, root) /opt/hc/lib/platform/linux/check_linux_sg_package_config.sh +%attr(755, root, root) /opt/hc/lib/platform/linux/check_linux_sg_package_status.sh +%attr(755, root, root) /opt/hc/lib/platform/linux/check_linux_sg_qs_status.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_burp_backup.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_hpasmcli.conf.dist +%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_root_crontab.conf.dist +%attr(644, root, root) /etc/opt/hc/check_linux_sg_cluster_config.conf.dist +%attr(644, root, root) /etc/opt/hc/check_linux_sg_cluster_status.conf.dist +%attr(644, root, root) /etc/opt/hc/check_linux_sg_package_config.conf.dist +%attr(644, root, root) /etc/opt/hc/check_linux_sg_package_status.conf.dist +%attr(644, root, root) /etc/opt/hc/check_linux_vz_ct_status.conf.dist +%dir /etc/opt/hc/core +%dir /etc/opt/hc/core/templates +%attr(644, root, root) /etc/opt/hc/core/templates/mail_body.tpl-check_linux_fs_mounts_options +%attr(644, root, root) /etc/opt/hc/core/templates/mail_body.tpl-check_linux_root_crontab + +%changelog +* Thu May 18 2017 - 0.0.9 +- Added check_linux_file_change +* Thu May 04 2017 - 0.0.9 +- Added check_linux_sg_qs_status +* Sun Apr 30 2017 - 0.0.8 +- Updated location of templates (../core) +* Sun Apr 23 2017 - 0.0.7 +- Added httpd check script +* Sat Apr 22 2017 - 0.0.6 +- Added hplog script +* Thu Apr 06 2017 - 0.0.5 +- Added hpasmcli + serviceguard scripts +* Sat Apr 01 2017 - 0.0.4 +- Added openvz container check +* Thu Dec 01 2016 - 0.0.3 +- Added burp,named,postfix,sshd,shorewall check +* Sat Nov 05 2016 - 0.0.2 +- Added mail templates +* Fri Jan 01 2016 - 0.0.1 +- Initial build diff --git a/build/linux/SPECS/hc-linux-security.spec b/build/linux/SPECS/hc-linux-security.spec new file mode 100644 index 0000000..fd1efbb --- /dev/null +++ b/build/linux/SPECS/hc-linux-security.spec @@ -0,0 +1,72 @@ +%define build_timestamp %(date +"%Y%m%d") + +Name: hc-linux-security +Version: %{build_timestamp} +Release: 1 + +Summary: The KUDOS Health Checker (HC) for UNIX (security plugins) +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 security specific plugins. + +%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/security +install -d -m 755 $RPM_BUILD_ROOT/opt/hc/lib/security +cp ../SOURCES/lib/security/check_all_ssh_controls.sh $RPM_BUILD_ROOT/opt/hc/lib/security/check_all_ssh_controls.sh +install -d -m 755 $RPM_BUILD_ROOT/etc/opt/hc/core +install -d -m 755 $RPM_BUILD_ROOT/etc/opt/hc/core/templates + +%post +# ------------------------- 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" + +%postun +# ------------------------- 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" + +%files +%defattr(-,root,root,755) +%dir /opt/hc/lib +%dir /opt/hc/lib/security +%attr(755, root, root) /opt/hc/lib/security/check_all_ssh_controls.sh + +%changelog +* Fri Jan 01 2016 - 0.0.1 +- Initial build diff --git a/build/linux/SPECS/hc-linux.spec b/build/linux/SPECS/hc-linux.spec new file mode 100644 index 0000000..741cc67 --- /dev/null +++ b/build/linux/SPECS/hc-linux.spec @@ -0,0 +1,172 @@ +%define build_timestamp %(date +"%Y%m%d") + +Name: hc-linux +Version: %{build_timestamp} +Release: 1 + +Summary: The KUDOS Health Checker (HC) for UNIX +Group: Tools/MonitoringGroup: 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 +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. + +%prep + +%build + +%install +rm -rf $RPM_BUILD_ROOT +install -d -m 755 $RPM_BUILD_ROOT/opt/hc +install -d -m 755 $RPM_BUILD_ROOT/opt/hc/bin +cp ../SOURCES/bin/check_health.sh $RPM_BUILD_ROOT/opt/hc/bin +install -d -m 755 $RPM_BUILD_ROOT/opt/hc/lib +install -d -m 755 $RPM_BUILD_ROOT/opt/hc/lib/core +cp ../SOURCES/lib/core/include_core.sh $RPM_BUILD_ROOT/opt/hc/lib/core +cp ../SOURCES/lib/core/include_data.sh $RPM_BUILD_ROOT/opt/hc/lib/core +cp ../SOURCES/lib/core/include_os.sh $RPM_BUILD_ROOT/opt/hc/lib/core +cp ../SOURCES/lib/core/notify_mail.sh $RPM_BUILD_ROOT/opt/hc/lib/core +install -d -m 755 $RPM_BUILD_ROOT/etc/opt/hc +cp ../SOURCES/etc/check_host.conf.dist $RPM_BUILD_ROOT/etc/opt/hc +install -d -m 755 $RPM_BUILD_ROOT/etc/opt/hc/core +cp ../SOURCES/etc/core/check_health.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/core +install -d -m 755 $RPM_BUILD_ROOT/etc/opt/hc/core/providers +install -d -m 755 $RPM_BUILD_ROOT/etc/opt/hc/core/templates +cp ../SOURCES/etc/core/templates/mail_info.tpl $RPM_BUILD_ROOT/etc/opt/hc/core/templates +cp ../SOURCES/etc/core/templates/mail_header.tpl $RPM_BUILD_ROOT/etc/opt/hc/core/templates +cp ../SOURCES/etc/core/templates/mail_body.tpl $RPM_BUILD_ROOT/etc/opt/hc/core/templates +cp ../SOURCES/etc/core/templates/mail_footer.tpl $RPM_BUILD_ROOT/etc/opt/hc/core/templates +install -d -m 755 $RPM_BUILD_ROOT/var/opt/hc + +%post +# ------------------------- CONFIGURATION starts here ------------------------- +# location of the HC scripts +HC_DIR="/opt/hc" +# location of the HC configuration files +HC_ETC_DIR="/etc/opt/hc" +# location of the HC log/state files +HC_VAR_DIR="/var/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 configuration files +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 )) || \ + { + echo "ERROR: could not copy main config file in ${HC_ETC_DIR}/core" + exit 1 + } +fi +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 )) || \ + { + echo "ERROR: could not copy host check config file in ${HC_ETC_DIR}" + exit 1 + } +fi +# refresh symbolic FPATH links for core includes & plugins +if [[ -x ${HC_BIN} ]] +then + ${HC_BIN} --fix-symlinks || echo "WARN: updating symlinks failed" +else + echo "ERROR: could not locate or excute the HC main script (${HC_BIN})" +fi +echo "INFO: finished post-install script" + +%postun +# ------------------------- CONFIGURATION starts here ------------------------- +# location of the HC scripts +HC_DIR="/opt/hc" +# location of the HC configuration files +HC_ETC_DIR="/etc/opt/hc" +# location of the HC log/state files +HC_VAR_DIR="/var/opt/hc" +# ------------------------- CONFIGURATION ends here --------------------------- +# update or uninstall? +if (( $1 == 0 )) +then + echo "INFO: starting post-uninstall script ..." + if [[ -d ${HC_DIR} ]] + then + rm -rf ${HC_DIR} 2>/dev/null + (( $? == 0 )) || echo "WARN: failed to remove ${HC_DIR}" + fi + if [[ -d ${HC_ETC_DIR} ]] + then + rm -rf ${HC_ETC_DIR}/*.dist >/dev/null + (( $? == 0 )) || echo "WARN: could not remove .dist files in directory ${HC_ETC_DIR}" + fi + if [[ -d ${HC_ETC_DIR}/core ]] + then + rm -rf ${HC_ETC_DIR}/core/*.dist >/dev/null + (( $? == 0 )) || echo "WARN: could not remove .dist files in directory ${HC_ETC_DIR}/core" + fi + if [[ -d ${HC_ETC_DIR}/core/providers ]] + then + rm -rf ${HC_ETC_DIR}/core/providers/*.dist >/dev/null + (( $? == 0 )) || echo "WARN: could not remove .dist files in directory ${HC_ETC_DIR}/core/providers" + fi + if [[ -d ${HC_VAR_DIR} ]] + then + rm -rf ${HC_VAR_DIR}/state/temporary 2>/dev/null + (( $? == 0 )) || echo "WARN: failed to remove ${HC_VAR_DIR}/state/temporary" + fi + echo "INFO: finished post-uninstall script" +else + echo "INFO: skipping post-uninstall script (RPM upgrade)" +fi + +%files +%defattr(-,root,root,755) +%dir /opt/hc +%dir /opt/hc/bin +%attr(755, root, root) /opt/hc/bin/check_health.sh +%dir /opt/hc/lib +%dir /opt/hc/lib/core +%attr(755, root, root) /opt/hc/lib/core/include_core.sh +%attr(755, root, root) /opt/hc/lib/core/include_data.sh +%attr(755, root, root) /opt/hc/lib/core/include_os.sh +%attr(755, root, root) /opt/hc/lib/core/notify_mail.sh +%dir /etc/opt/hc +%attr(644, root, root) /etc/opt/hc/check_host.conf.dist +%dir /etc/opt/hc/core +%attr(644, root, root) /etc/opt/hc/core/check_health.conf.dist +%dir /etc/opt/hc/core/providers +%dir /etc/opt/hc/core/templates +%attr(644, root, root) /etc/opt/hc/core/templates/mail_info.tpl +%attr(644, root, root) /etc/opt/hc/core/templates/mail_header.tpl +%attr(644, root, root) /etc/opt/hc/core/templates/mail_body.tpl +%attr(644, root, root) /etc/opt/hc/core/templates/mail_footer.tpl +%dir /var/opt/hc + +%changelog +* Tue Jun 20 2017 - 0.0.8 +- Made %postun RPM update aware +* Mon May 08 2017 - 0.0.7 +- Added check_host_conf.dist +* Sat May 06 2017 - 0.0.6 +- Added include_core.sh +* Sun Apr 30 2017 - 0.0.5 +- Added core plugins (mail) and new location of check_health.conf.dist +* Sat Apr 08 2017 - 0.0.4 +- Changed check_health.conf to check_health.conf.dist and added %post +* Fri Nov 11 2016 - 0.0.3 +- Added SMS directory +* Sat Nov 05 2016 - 0.0.2 +- Added mail templates +* Fri Jan 01 2016 - 0.0.1 +- Initial build diff --git a/build/linux/SPECS/hc-notify-eif.spec b/build/linux/SPECS/hc-notify-eif.spec new file mode 100644 index 0000000..481dd4c --- /dev/null +++ b/build/linux/SPECS/hc-notify-eif.spec @@ -0,0 +1,109 @@ +%define build_timestamp %(date +"%Y%m%d") + +Name: hc-notify-eif +Version: %{build_timestamp} +Release: 1 + +Summary: The KUDOS Health Checker (HC) for UNIX (EIF 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/lib/core/notify_eif.sh $RPM_BUILD_ROOT/opt/hc/lib/core/notify_eif.sh +install -d -m 755 $RPM_BUILD_ROOT/etc/opt/hc +install -d -m 755 $RPM_BUILD_ROOT/etc/opt/hc/core/providers +install -d -m 755 $RPM_BUILD_ROOT/etc/opt/hc/core/providers +cp ../SOURCES/etc/core/providers/notify_eif.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/core/providers/notify_eif.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_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 +# 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_eif.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_eif.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_eif.conf.dist + +%changelog +* Tue Jun 20 2017 - 0.0.2 +- Made %postun RPM update aware +* Sun Apr 30 2017 - 0.0.1 +- Initial build diff --git a/build/linux/SPECS/hc-notify-sms.spec b/build/linux/SPECS/hc-notify-sms.spec new file mode 100644 index 0000000..0ab4b0a --- /dev/null +++ b/build/linux/SPECS/hc-notify-sms.spec @@ -0,0 +1,109 @@ +%define build_timestamp %(date +"%Y%m%d") + +Name: hc-notify-sms +Version: %{build_timestamp} +Release: 1 + +Summary: The KUDOS Health Checker (HC) for UNIX (SMS 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/lib/core/notify_sms.sh $RPM_BUILD_ROOT/opt/hc/lib/core/notify_sms.sh +install -d -m 755 $RPM_BUILD_ROOT/etc/opt/hc +install -d -m 755 $RPM_BUILD_ROOT/etc/opt/hc/core/providers +install -d -m 755 $RPM_BUILD_ROOT/etc/opt/hc/core/providers +cp ../SOURCES/etc/core/providers/notify_sms.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/core/providers/notify_sms.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_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 +# 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_sms.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_sms.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_sms.conf.dist + +%changelog +* Tue Jun 20 2017 - 0.0.2 +- Made %postun RPM update aware +* Sun Apr 30 2017 - 0.0.1 +- Initial build diff --git a/build/linux/build_linux_rpms.sh b/build/linux/build_linux_rpms.sh new file mode 100644 index 0000000..6220c96 --- /dev/null +++ b/build/linux/build_linux_rpms.sh @@ -0,0 +1,62 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) build script for HC RPM packages (uses 'rpmbuild') +#****************************************************************************** +# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 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 +#****************************************************************************** + +#****************************************************************************** +# Requires following build (dir) structures: +# +# build_linux_rpms.sh +# BUILD/ +# BUILDROOT/ +# RPMS/ +# SOURCES/ +# SOURCES/bin/ +# SOURCES/lib/*/ +# SPECS/ +# SRPMS/ +# +# Build order: +# 1) Copy sources/scrips to the correct locations +# 2) Copy template, build and installer script files into correct locations +# 3) Execute build_linux_rpms.sh +# 4) RPM packages may be found in the RPMS directory +#****************************************************************************** + +BUILD_DIR="$(dirname $0)" + +# clean up previous packages +rm -f ${BUILD_DIR}/RPMS/*/* >/dev/null + +# build main packages +rpmbuild -bb ${BUILD_DIR}/SPECS/hc-linux.spec +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-display-init.spec +rpmbuild -bb ${BUILD_DIR}/SPECS/hc-display-csv.spec +rpmbuild -bb ${BUILD_DIR}/SPECS/hc-display-terse.spec + +print "List of built packages:" +ls -l ${BUILD_DIR}/RPMS/*/* + +exit 0 + +#****************************************************************************** +# END of script +#****************************************************************************** + + diff --git a/configs/etc/check_aix_file_age.conf.dist b/configs/etc/check_aix_file_age.conf.dist new file mode 100644 index 0000000..2ca409e --- /dev/null +++ b/configs/etc/check_aix_file_age.conf.dist @@ -0,0 +1,15 @@ +#****************************************************************************** +# @(#) check_aix_file_age.conf.dist +#****************************************************************************** +# This is a configuration file for the check_aix_file_age HC plugin. +# All lines starting with a '#' are comment lines. +# [default: indicates hardcoded script values if no value is defined here] +#****************************************************************************** + +# file (full path); maximum age in minutes since last change +/var/adm/ras/syslog.caa;600 +/var/log/ntp.log;30 + +#****************************************************************************** +# End of FILE +#****************************************************************************** \ No newline at end of file diff --git a/configs/etc/check_aix_file_change.conf.dist b/configs/etc/check_aix_file_change.conf.dist new file mode 100644 index 0000000..0885a38 --- /dev/null +++ b/configs/etc/check_aix_file_change.conf.dist @@ -0,0 +1,30 @@ +#****************************************************************************** +# @(#) check_aix_file_change.conf +#****************************************************************************** +# This is a configuration file for the check_aix_file_change HC plugin. +# All lines starting with a '#' are comment lines. +# [default: indicates hardcoded script values if no value is defined here] +#****************************************************************************** + +# name of the state file to use (will be relative to /var/opt/hc/state/persistent +# [default: discovered.file_change] +state_file=discovered.file_change + +# specify if file names need to be checked/flagged for meta characters [yes|no] +# [default: yes] +do_meta_check=yes + +# specify files or directories check (directories are automatically expanded) +# format: +# incl: (includes a path) +# excl: (excludes a path) +# note: shell wild cards in the file paths are not supported! Exclusions have +# a higher priority than inclusions. +incl:file1 +incl:dir1 +excl:dir1/file2 + + +#****************************************************************************** +# End of FILE +#****************************************************************************** \ No newline at end of file diff --git a/configs/etc/check_aix_root_crontab.conf.dist b/configs/etc/check_aix_root_crontab.conf.dist new file mode 100644 index 0000000..1bd33e9 --- /dev/null +++ b/configs/etc/check_aix_root_crontab.conf.dist @@ -0,0 +1,16 @@ +#****************************************************************************** +# @(#) check_aix_root_crontab.conf.dist +#****************************************************************************** +# This is a configuration file for the check_aix_root_crontab HC plugin. +# All lines starting with a '#' are comment lines. +# [default: indicates hardcoded script values if no value is defined here] +#****************************************************************************** + +# list of commands (or strings) that should appear in active cron entries +/opt/cfg2html/bin/cfg2html_aix.sh +/usr/local/bin/run_aix_system_backup.sh +/usr/bin/nmon + +#****************************************************************************** +# End of FILE +#****************************************************************************** \ No newline at end of file diff --git a/configs/etc/check_aix_subsystems.conf.dist b/configs/etc/check_aix_subsystems.conf.dist new file mode 100644 index 0000000..2f5e119 --- /dev/null +++ b/configs/etc/check_aix_subsystems.conf.dist @@ -0,0 +1,35 @@ +#****************************************************************************** +# @(#) check_aix_subsystems.conf.dist +#****************************************************************************** +# This is a configuration file for the check_aix_subsystems HC plugin. +# All lines starting with a '#' are comment lines. +# [default: indicates hardcoded script values if no value is defined here] +#****************************************************************************** + +# list of required active subsystems +sendmail +syslogd +portmap +inetd +snmpd +hostmibd +snmpmibd +aixmibd +#nimsh +biod +rpc.statd +rpc.lockd +automountd +qdaemon +writesrv +sshd +xntpd +cimsys +ctrmc +IBM.ServiceRM +IBM.DRM +IBM.CSMAgentRM + +#****************************************************************************** +# End of FILE +#****************************************************************************** \ No newline at end of file diff --git a/configs/etc/check_aix_sysbackup.conf.dist b/configs/etc/check_aix_sysbackup.conf.dist new file mode 100644 index 0000000..5600a0d --- /dev/null +++ b/configs/etc/check_aix_sysbackup.conf.dist @@ -0,0 +1,22 @@ +#****************************************************************************** +# @(#) check_aix_sysbackup.conf.dist +#****************************************************************************** +# This is a configuration file for the check_aix_sysbackup HC plugin. +# All lines starting with a '#' are comment lines. +# [default: indicates hardcoded script values if no value is defined here] +#****************************************************************************** + +# full path to the location of mksysb images, the tool expects sub-directories +# per host underneath this location +backup_path=/export/images + +# name of the file containing the mksysb output +mksysb_log=mksysb.log + +# maximum days before backup gets flagged as 'too old' +# [default: 14] +backup_age=14 + +#****************************************************************************** +# End of FILE +#****************************************************************************** \ No newline at end of file diff --git a/configs/etc/check_host.conf.dist b/configs/etc/check_host.conf.dist new file mode 100644 index 0000000..c0bb8ec --- /dev/null +++ b/configs/etc/check_host.conf.dist @@ -0,0 +1,21 @@ +#****************************************************************************** +# @(#) check_host.conf +#****************************************************************************** +# This is a configuration file for the check_host feature. +# All lines starting with a '#' are comment lines. +# [default: indicates hardcoded script values if no value is defined here] +#****************************************************************************** + +# specify the style in which results should be displayed (see --list-core) +# [default: init] +display_style=init + +# specify the list of HC plugins that need to be executed +# [hc:HC plugin name] +hc:plugin1 +hc:plugin2 + + +#****************************************************************************** +# End of FILE +#****************************************************************************** diff --git a/configs/etc/check_hpux_file_age.conf.dist b/configs/etc/check_hpux_file_age.conf.dist new file mode 100644 index 0000000..7ef9959 --- /dev/null +++ b/configs/etc/check_hpux_file_age.conf.dist @@ -0,0 +1,14 @@ +#****************************************************************************** +# @(#) check_hpux_file_age.conf +#****************************************************************************** +# This is a configuration file for the check_hpux_file_age HC plugin. +# All lines starting with a '#' are comment lines. +# [default: indicates hardcoded script values if no value is defined here] +#****************************************************************************** + +# file (full path); maximum age in minutes since last change +/var/adm/syslog/syslog.log;60 + +#****************************************************************************** +# End of FILE +#****************************************************************************** \ No newline at end of file diff --git a/configs/etc/check_hpux_file_change.conf.dist b/configs/etc/check_hpux_file_change.conf.dist new file mode 100644 index 0000000..69e0280 --- /dev/null +++ b/configs/etc/check_hpux_file_change.conf.dist @@ -0,0 +1,30 @@ +#****************************************************************************** +# @(#) check_hpux_file_change.conf +#****************************************************************************** +# This is a configuration file for the check_hpux_file_change HC plugin. +# All lines starting with a '#' are comment lines. +# [default: indicates hardcoded script values if no value is defined here] +#****************************************************************************** + +# name of the state file to use (will be relative to /var/opt/hc/state/persistent +# [default: discovered.file_change] +state_file=discovered.file_change + +# specify if file names need to be checked/flagged for meta characters [yes|no] +# [default: yes] +do_meta_check=yes + +# specify files or directories check (directories are automatically expanded) +# format: +# incl: (includes a path) +# excl: (excludes a path) +# note: shell wild cards in the file paths are not supported! Exclusions have +# a higher priority than inclusions. +incl:file1 +incl:dir1 +excl:dir1/file2 + + +#****************************************************************************** +# End of FILE +#****************************************************************************** \ No newline at end of file diff --git a/configs/etc/check_hpux_fs_mounts_options.conf.dist b/configs/etc/check_hpux_fs_mounts_options.conf.dist new file mode 100644 index 0000000..d741aed --- /dev/null +++ b/configs/etc/check_hpux_fs_mounts_options.conf.dist @@ -0,0 +1,22 @@ +#****************************************************************************** +# @(#) check_hpux_fs_mounts_options.conf +#****************************************************************************** +# This is a configuration file for the check_hpux_fs_mounts_options HC plugin. +# All lines starting with a '#' are comment lines. +# [default: indicates hardcoded script values if no value is defined here] +#****************************************************************************** + +# specify whether non-mounted FS should be alerted on (yes|no) +# [default: yes] +ignore_missing_fs=yes + +# specify mount points and their options (use the mount options as displayed +# by the 'mount' command; order of the options is not important) +# [fs::] +fs:myfs1:myopts1 +fs:myfs2:myopts2 + + +#****************************************************************************** +# End of FILE +#****************************************************************************** \ No newline at end of file diff --git a/configs/etc/check_hpux_hpvm_vpar_status.conf.dist b/configs/etc/check_hpux_hpvm_vpar_status.conf.dist new file mode 100644 index 0000000..d955aaf --- /dev/null +++ b/configs/etc/check_hpux_hpvm_vpar_status.conf.dist @@ -0,0 +1,18 @@ +#****************************************************************************** +# @(#) check_hpux_hpvm_vpar_status.conf +#****************************************************************************** +# This is a configuration file for the check_hpux_hpvm_vpar_status HC plugin. +# All lines starting with a '#' are comment lines. +# [default: indicates hardcoded script values if no value is defined here] +#****************************************************************************** + +# specify properties as displayed by the 'vzlist -a -H -o ctid,status,onboot' command +# [parid;runtime_status;boot_status] +# runtime_status should be 'on' or 'off' +# boot_status should be 'auto' or 'manual' +#1;on;auto + + +#****************************************************************************** +# End of FILE +#****************************************************************************** diff --git a/configs/etc/check_hpux_ignite_backup.conf.dist b/configs/etc/check_hpux_ignite_backup.conf.dist new file mode 100644 index 0000000..bd3f03a --- /dev/null +++ b/configs/etc/check_hpux_ignite_backup.conf.dist @@ -0,0 +1,19 @@ +#****************************************************************************** +# @(#) check_hpux_ignite_backup.conf.dist +#****************************************************************************** +# This is a configuration file for the check_hpux_ignite_backup HC plugin. +# All lines starting with a '#' are comment lines. +# [default: indicates hardcoded script values if no value is defined here] +#****************************************************************************** + +# maximum days before backup gets flagged as 'too old' +# [default: 14] +backup_age=14 + +# list of hosts to exclude from the check (comma-separated list) +# [default: none] +exclude_hosts="" + +#****************************************************************************** +# End of FILE +#****************************************************************************** \ No newline at end of file diff --git a/configs/etc/check_hpux_ioscan.conf.dist b/configs/etc/check_hpux_ioscan.conf.dist new file mode 100644 index 0000000..868c991 --- /dev/null +++ b/configs/etc/check_hpux_ioscan.conf.dist @@ -0,0 +1,24 @@ +#****************************************************************************** +# @(#) check_hpux_ioscan.conf +#****************************************************************************** +# This is a configuration file for the check_hpux_ioscan HC plugin. +# All lines starting with a '#' are comment lines. +# [default: indicates hardcoded script values if no value is defined here] +#****************************************************************************** + +# comma-separated list of HW device classes that should be checked +# [default: ctl,diag,disk,ext_bus,fc,fcp,i2o,ipmi,lan,lvm,olar,vxvm] +ioscan_classes="ctl,diag,disk,ext_bus,fc,fcp,i2o,ipmi,lan,lvm,olar,vxvm" + +# specify whether ioscan needs to be run in kernel-cached or not (yes|no) +# [default: yes] +kernel_mode=yes + +# specify whether ioscan needs to report in Agile view or not (yes|no) +# [default: yes] +agile_view=yes + + +#****************************************************************************** +# End of FILE +#****************************************************************************** \ No newline at end of file diff --git a/configs/etc/check_hpux_ntp_status.conf.dist b/configs/etc/check_hpux_ntp_status.conf.dist new file mode 100644 index 0000000..35e29ee --- /dev/null +++ b/configs/etc/check_hpux_ntp_status.conf.dist @@ -0,0 +1,16 @@ +#****************************************************************************** +# @(#) check_hpux_ntp_status.conf.dist +#****************************************************************************** +# This is a configuration file for the check_hpux_ntp_status HC plugin. +# All lines starting with a '#' are comment lines. +# [default: indicates hardcoded script values if no value is defined here] +#****************************************************************************** + +# maximum allowed offset (in milliseconds) +# [default: 500] +max_offset=500 + + +#****************************************************************************** +# End of FILE +#****************************************************************************** \ No newline at end of file diff --git a/configs/etc/check_hpux_root_crontab.conf.dist b/configs/etc/check_hpux_root_crontab.conf.dist new file mode 100644 index 0000000..a252d79 --- /dev/null +++ b/configs/etc/check_hpux_root_crontab.conf.dist @@ -0,0 +1,14 @@ +#****************************************************************************** +# @(#) check_hpux_root_crontab.conf.dist +#****************************************************************************** +# This is a configuration file for the check_hpux_root_crontab HC plugin. +# All lines starting with a '#' are comment lines. +# [default: indicates hardcoded script values if no value is defined here] +#****************************************************************************** + +# list of commands (or strings) that should appear in active cron entries +/opt/cfg2html/cfg2html_hpux.sh + +#****************************************************************************** +# End of FILE +#****************************************************************************** \ No newline at end of file diff --git a/configs/etc/check_hpux_sg_cluster_config.conf.dist b/configs/etc/check_hpux_sg_cluster_config.conf.dist new file mode 100644 index 0000000..f3613e6 --- /dev/null +++ b/configs/etc/check_hpux_sg_cluster_config.conf.dist @@ -0,0 +1,16 @@ +#****************************************************************************** +# @(#) check_hpux_sg_cluster_config.conf.dist +#****************************************************************************** +# This is a configuration file for the check_hpux_sg_cluster_config HC plugin. +# All lines starting with a '#' are comment lines. +# It is recommended to only monitor unique "param1 value2" combinations +#****************************************************************************** + +#[mycluster] +#param1 value1 +#param2 value2 + + +#****************************************************************************** +# End of FILE +#****************************************************************************** \ No newline at end of file diff --git a/configs/etc/check_hpux_sg_cluster_status.conf.dist b/configs/etc/check_hpux_sg_cluster_status.conf.dist new file mode 100644 index 0000000..c7fa11a --- /dev/null +++ b/configs/etc/check_hpux_sg_cluster_status.conf.dist @@ -0,0 +1,15 @@ +#****************************************************************************** +# @(#) check_hpux_sg_cluster_status.conf.dist +#****************************************************************************** +# This is a configuration file for the check_hpux_sg_cluster_status HC plugin. +# All lines starting with a '#' are comment lines. +# [default: indicates hardcoded script values if no value is defined here] +#****************************************************************************** + +# list of required cluster statuses (format : "parameter=value") +#status=up + + +#****************************************************************************** +# End of FILE +#****************************************************************************** \ No newline at end of file diff --git a/configs/etc/check_hpux_sg_package_config.conf.dist b/configs/etc/check_hpux_sg_package_config.conf.dist new file mode 100644 index 0000000..56832b0 --- /dev/null +++ b/configs/etc/check_hpux_sg_package_config.conf.dist @@ -0,0 +1,20 @@ +#****************************************************************************** +# @(#) check_hpux_sg_package_config.conf.dist +#****************************************************************************** +# This is a configuration file for the check_hpux_sg_package_config HC plugin. +# All lines starting with a '#' are comment lines. +# It is recommended to only monitor unique "param1 value2" combinations +#****************************************************************************** + +#[mypkg1] +#param1 value1 +#param2 value2 + +#[mypkg2] +#param1 value1 +#param2 value2 + + +#****************************************************************************** +# End of FILE +#****************************************************************************** \ No newline at end of file diff --git a/configs/etc/check_hpux_sg_package_status.conf.dist b/configs/etc/check_hpux_sg_package_status.conf.dist new file mode 100644 index 0000000..bedceac --- /dev/null +++ b/configs/etc/check_hpux_sg_package_status.conf.dist @@ -0,0 +1,15 @@ +#****************************************************************************** +# @(#) check_hpux_sg_package_status.conf.dist +#****************************************************************************** +# This is a configuration file for the check_hpux_sg_package_status HC plugin. +# All lines starting with a '#' are comment lines. +# [default: indicates hardcoded script values if no value is defined here] +#****************************************************************************** + +# list of required package statuses (format : "package_name:parameter=value") +#my_package|status=up + + +#****************************************************************************** +# End of FILE +#****************************************************************************** \ No newline at end of file diff --git a/configs/etc/check_hpux_syslog.conf.dist b/configs/etc/check_hpux_syslog.conf.dist new file mode 100644 index 0000000..217831b --- /dev/null +++ b/configs/etc/check_hpux_syslog.conf.dist @@ -0,0 +1,20 @@ +#****************************************************************************** +# @(#) check_hpux_syslog.conf.dist +#****************************************************************************** +# This is a configuration file for the check_hpux_syslog HC plugin. +# All lines starting with a '#' are comment lines. +# [default: indicates hardcoded script values if no value is defined here] +#****************************************************************************** + +# path to the SYSLOG file +# [default: /var/adm/syslog/syslog.log] +syslog_file="/var/adm/syslog/syslog.log" + +# comma-separated list of tags to search for (case insensitive) (see man 1 logger) +# [default: vmunix] +syslog_classes="vmunix" + + +#****************************************************************************** +# End of FILE +#****************************************************************************** \ No newline at end of file diff --git a/configs/etc/check_linux_burp_backup.conf.dist b/configs/etc/check_linux_burp_backup.conf.dist new file mode 100644 index 0000000..ad06c92 --- /dev/null +++ b/configs/etc/check_linux_burp_backup.conf.dist @@ -0,0 +1,17 @@ +#****************************************************************************** +# @(#) check_linux_burp_backup.conf +#****************************************************************************** +# This is a configuration file for the check_linux_burp_backup HC plugin. +# All lines starting with a '#' are comment lines. +# [default: indicates hardcoded script values if no value is defined here] +#****************************************************************************** + +# client name; maximum amount of warnings allowed; maximum backup age (hours/days/weeks) +testclient1;0;10h +testclient2;0;2d +testclient3;0;5w + + +#****************************************************************************** +# End of FILE +#****************************************************************************** diff --git a/configs/etc/check_linux_file_age.conf.dist b/configs/etc/check_linux_file_age.conf.dist new file mode 100644 index 0000000..b3fc864 --- /dev/null +++ b/configs/etc/check_linux_file_age.conf.dist @@ -0,0 +1,15 @@ +#****************************************************************************** +# @(#) check_linux_file_age.conf +#****************************************************************************** +# This is a configuration file for the check_linux_file_age HC plugin. +# All lines starting with a '#' are comment lines. +# [default: indicates hardcoded script values if no value is defined here] +#****************************************************************************** + +# file (full path); maximum age in minutes since last change +/var/log/messages;60 +/var/log/ntp.log;30 + +#****************************************************************************** +# End of FILE +#****************************************************************************** \ No newline at end of file diff --git a/configs/etc/check_linux_file_change.conf.dist b/configs/etc/check_linux_file_change.conf.dist new file mode 100644 index 0000000..d1aa4c7 --- /dev/null +++ b/configs/etc/check_linux_file_change.conf.dist @@ -0,0 +1,30 @@ +#****************************************************************************** +# @(#) check_linux_file_change.conf +#****************************************************************************** +# This is a configuration file for the check_linux_file_change HC plugin. +# All lines starting with a '#' are comment lines. +# [default: indicates hardcoded script values if no value is defined here] +#****************************************************************************** + +# name of the state file to use (will be relative to /var/opt/hc/state/persistent +# [default: discovered.file_change] +state_file=discovered.file_change + +# specify if file names need to be checked/flagged for meta characters [yes|no] +# [default: yes] +do_meta_check=yes + +# specify files or directories check (directories are automatically expanded) +# format: +# incl: (includes a path) +# excl: (excludes a path) +# note: shell wild cards in the file paths are not supported! Exclusions have +# a higher priority than inclusions. +incl:file1 +incl:dir1 +excl:dir1/file2 + + +#****************************************************************************** +# End of FILE +#****************************************************************************** \ No newline at end of file diff --git a/configs/etc/check_linux_hpacucli.conf.dist b/configs/etc/check_linux_hpacucli.conf.dist new file mode 100644 index 0000000..0a195c0 --- /dev/null +++ b/configs/etc/check_linux_hpacucli.conf.dist @@ -0,0 +1,26 @@ +#****************************************************************************** +# @(#) check_linux_hpacucli.conf +#****************************************************************************** +# This is a configuration file for the check_linux_hpacucli HC plugin. +# All lines starting with a '#' are comment lines. +# [default: indicates hardcoded script values if no value is defined here] +#****************************************************************************** + +# location of 'hpacucli' tool +hpacucli_bin="/usr/sbin/hpacucli" + +# 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] +do_acu_enclosure=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] +do_acu_logical=1 + +#****************************************************************************** +# End of FILE +#****************************************************************************** \ No newline at end of file diff --git a/configs/etc/check_linux_hpasmcli.conf.dist b/configs/etc/check_linux_hpasmcli.conf.dist new file mode 100644 index 0000000..30d2d82 --- /dev/null +++ b/configs/etc/check_linux_hpasmcli.conf.dist @@ -0,0 +1,29 @@ +#****************************************************************************** +# @(#) check_linux_hpasmcli.conf +#****************************************************************************** +# This is a configuration file for the check_linux_hpasmcli HC plugin. +# All lines starting with a '#' are comment lines. +# [default: indicates hardcoded script values if no value is defined here] +#****************************************************************************** + +# location of 'hpasmcli' tool +hpasmcli_bin="/sbin/hpasmcli" + +# SHOW FANS (0=off, 1=on) [default: 1] +do_asm_fans=1 + +# SHOW DIMM (0=off, 1=on) [default: 1] +do_asm_dimm=1 + +# SHOW POWERSUPPLY (0=off, 1=on) [default: 1] +do_asm_powersupply=1 + +# SHOW SERVER (0=off, 1=on) [default: 1] +do_asm_server=1 + +# SHOW TEMPERATURE (0=off, 1=on) [default: 1] +do_asm_temperature=1 + +#****************************************************************************** +# End of FILE +#****************************************************************************** \ No newline at end of file diff --git a/configs/etc/check_linux_hplog.conf.dist b/configs/etc/check_linux_hplog.conf.dist new file mode 100644 index 0000000..6b111c4 --- /dev/null +++ b/configs/etc/check_linux_hplog.conf.dist @@ -0,0 +1,19 @@ +#****************************************************************************** +# @(#) check_linux_hplog.conf +#****************************************************************************** +# This is a configuration file for the check_linux_hplog HC plugin. +# All lines starting with a '#' are comment lines. +# [default: indicates hardcoded script values if no value is defined here] +#****************************************************************************** + +# location of 'hpacucli' tool +hplog_bin="/sbin/hplog" + +# comma-separated list of severities to search for (case insensitive) +# [default: CRITICAL,CAUTION] +hplog_severities="CRITICAL,CAUTION" + + +#****************************************************************************** +# End of FILE +#****************************************************************************** diff --git a/configs/etc/check_linux_hpssacli.conf.dist b/configs/etc/check_linux_hpssacli.conf.dist new file mode 100644 index 0000000..1121ca5 --- /dev/null +++ b/configs/etc/check_linux_hpssacli.conf.dist @@ -0,0 +1,26 @@ +#****************************************************************************** +# @(#) check_linux_hpssacli.conf +#****************************************************************************** +# This is a configuration file for the check_linux_hpssacli HC plugin. +# All lines starting with a '#' are comment lines. +# [default: indicates hardcoded script values if no value is defined here] +#****************************************************************************** + +# location of 'hpssacli' tool +hpssacli_bin="/usr/sbin/hpssacli" + +# 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] +do_ssa_enclosure=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] +do_ssa_logical=1 + +#****************************************************************************** +# End of FILE +#****************************************************************************** \ No newline at end of file diff --git a/configs/etc/check_linux_root_crontab.conf.dist b/configs/etc/check_linux_root_crontab.conf.dist new file mode 100644 index 0000000..6a230b9 --- /dev/null +++ b/configs/etc/check_linux_root_crontab.conf.dist @@ -0,0 +1,14 @@ +#****************************************************************************** +# @(#) check_linux_root_crontab.conf.dist +#****************************************************************************** +# This is a configuration file for the check_linux_root_crontab HC plugin. +# All lines starting with a '#' are comment lines. +# [default: indicates hardcoded script values if no value is defined here] +#****************************************************************************** + +# list of commands (or strings) that should appear in active cron entries +/usr/bin/cfg2html-linux + +#****************************************************************************** +# End of FILE +#****************************************************************************** \ No newline at end of file diff --git a/configs/etc/check_linux_sg_cluster_config.conf.dist b/configs/etc/check_linux_sg_cluster_config.conf.dist new file mode 100644 index 0000000..db57827 --- /dev/null +++ b/configs/etc/check_linux_sg_cluster_config.conf.dist @@ -0,0 +1,16 @@ +#****************************************************************************** +# @(#) check_linux_sg_cluster_config.conf.dist +#****************************************************************************** +# This is a configuration file for the check_linux_sg_cluster_config HC plugin. +# All lines starting with a '#' are comment lines. +# It is recommended to only monitor unique "param1 value2" combinations +#****************************************************************************** + +#[mycluster] +#param1 value1 +#param2 value2 + + +#****************************************************************************** +# End of FILE +#****************************************************************************** \ No newline at end of file diff --git a/configs/etc/check_linux_sg_cluster_status.conf.dist b/configs/etc/check_linux_sg_cluster_status.conf.dist new file mode 100644 index 0000000..537e774 --- /dev/null +++ b/configs/etc/check_linux_sg_cluster_status.conf.dist @@ -0,0 +1,15 @@ +#****************************************************************************** +# @(#) check_linux_sg_cluster_status.conf.dist +#****************************************************************************** +# This is a configuration file for the check_linux_sg_cluster_status HC plugin. +# All lines starting with a '#' are comment lines. +# [default: indicates hardcoded script values if no value is defined here] +#****************************************************************************** + +# list of required cluster statuses (format : "parameter=value") +#status=up + + +#****************************************************************************** +# End of FILE +#****************************************************************************** \ No newline at end of file diff --git a/configs/etc/check_linux_sg_package_config.conf.dist b/configs/etc/check_linux_sg_package_config.conf.dist new file mode 100644 index 0000000..eaf8fa2 --- /dev/null +++ b/configs/etc/check_linux_sg_package_config.conf.dist @@ -0,0 +1,20 @@ +#****************************************************************************** +# @(#) check_linux_sg_package_config.conf.dist +#****************************************************************************** +# This is a configuration file for the check_linux_sg_package_config HC plugin. +# All lines starting with a '#' are comment lines. +# It is recommended to only monitor unique "param1 value2" combinations +#****************************************************************************** + +#[mypkg1] +#param1 value1 +#param2 value2 + +#[mypkg2] +#param1 value1 +#param2 value2 + + +#****************************************************************************** +# End of FILE +#****************************************************************************** \ No newline at end of file diff --git a/configs/etc/check_linux_sg_package_status.conf.dist b/configs/etc/check_linux_sg_package_status.conf.dist new file mode 100644 index 0000000..cfce57e --- /dev/null +++ b/configs/etc/check_linux_sg_package_status.conf.dist @@ -0,0 +1,15 @@ +#****************************************************************************** +# @(#) check_linux_sg_package_status.conf.dist +#****************************************************************************** +# 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] +#****************************************************************************** + +# list of required package statuses (format : "package_name:parameter=value") +#my_package|status=up + + +#****************************************************************************** +# End of FILE +#****************************************************************************** \ No newline at end of file diff --git a/configs/etc/check_linux_vz_ct_status.conf.dist b/configs/etc/check_linux_vz_ct_status.conf.dist new file mode 100644 index 0000000..e26c2b1 --- /dev/null +++ b/configs/etc/check_linux_vz_ct_status.conf.dist @@ -0,0 +1,18 @@ +#****************************************************************************** +# @(#) check_linux_vz_ct_status.conf +#****************************************************************************** +# This is a configuration file for the check_linux_openvz_ct_status HC plugin. +# All lines starting with a '#' are comment lines. +# [default: indicates hardcoded script values if no value is defined here] +#****************************************************************************** + +# specify properties as displayed by the 'vzlist -a -H -o ctid,status,onboot' command +# [ctid;runtime_status;boot_status] +# runtime_status should be 'running' or 'stopped' +# boot_status should be 'yes' or 'no' +#100;running;yes + + +#****************************************************************************** +# End of FILE +#****************************************************************************** diff --git a/configs/etc/core/check_health.conf.dist b/configs/etc/core/check_health.conf.dist new file mode 100644 index 0000000..e27fa82 --- /dev/null +++ b/configs/etc/core/check_health.conf.dist @@ -0,0 +1,31 @@ +#****************************************************************************** +# @(#) check_health.conf +#****************************************************************************** +# This is the main configuration file for the check_health.sh tool. +# All lines starting with a '#' are comment lines. +# [default: indicates hardcoded script values if no value is defined here] +#****************************************************************************** + +# --- general settings --- +# maximum timeout for HC calls (seconds) +HC_TIME_OUT=60 + +# location of log directory, see also --log-dir) +LOG_DIR="/var/opt/hc" + +# location of events directory +EVENTS_DIR="${LOG_DIR}/events" + +# location of state directory +STATE_DIR="${LOG_DIR}/state" + +# location of persistent state directory +STATE_PERM_DIR="${STATE_DIR}/persistent" + +# location of temporary state directory +STATE_TEMP_DIR="${STATE_DIR}/temporary" + + +#****************************************************************************** +# End of FILE +#****************************************************************************** diff --git a/configs/etc/core/providers/notify_eif.conf.dist b/configs/etc/core/providers/notify_eif.conf.dist new file mode 100644 index 0000000..a9ff269 --- /dev/null +++ b/configs/etc/core/providers/notify_eif.conf.dist @@ -0,0 +1,22 @@ +#****************************************************************************** +# @(#) notify_eif.conf +#****************************************************************************** +# This is the configuration file for the notify_eif.sh provider. +# All lines starting with a '#' are comment lines. +# [default: indicates hardcoded script values if no value is defined here] +#****************************************************************************** + +# --- EIF settings --- +# location of the posteifmsg tool +EIF_BIN="/opt/eif/bin/posteifmsg" + +# location of the posteifmsg configuration file +EIF_ETC="/etc/opt/eif/posteifmsg.conf" + +# default ITM severity +EIF_SEVERITY="MINOR" + + +#****************************************************************************** +# End of FILE +#****************************************************************************** diff --git a/configs/etc/core/providers/notify_sms.conf.dist b/configs/etc/core/providers/notify_sms.conf.dist new file mode 100644 index 0000000..a89754f --- /dev/null +++ b/configs/etc/core/providers/notify_sms.conf.dist @@ -0,0 +1,18 @@ +#****************************************************************************** +# @(#) notify_sms.conf +#****************************************************************************** +# This is the the configuration file for the notify_sms.sh provider. +# All lines starting with a '#' are comment lines. +# [default: indicates hardcoded script values if no value is defined here] +#****************************************************************************** + +# --- SMS settings --- +# list of supported SMS providers (comma-separated) +SMS_PROVIDERS="" + +# configuration settings for individual SMS providers go here + + +#****************************************************************************** +# End of FILE +#****************************************************************************** diff --git a/configs/etc/core/templates/mail_body.tpl b/configs/etc/core/templates/mail_body.tpl new file mode 100644 index 0000000..93e27b1 --- /dev/null +++ b/configs/etc/core/templates/mail_body.tpl @@ -0,0 +1,3 @@ +*** MESSAGE *** +<## @_HC_BODY ##> + diff --git a/configs/etc/core/templates/mail_body.tpl-check_hpux_fs_mounts_options b/configs/etc/core/templates/mail_body.tpl-check_hpux_fs_mounts_options new file mode 100644 index 0000000..5a7bc89 --- /dev/null +++ b/configs/etc/core/templates/mail_body.tpl-check_hpux_fs_mounts_options @@ -0,0 +1,13 @@ +*** MESSAGE *** +<## @_HC_BODY ##> + +*** RECOMMENDATION *** +File system is mounted with incorrect options. Remount the file system with the correct options. +* Check /etc/fstab +* Check /etc/cmcluster//.conf files (directive "fs_mount_opt") + +Keep in mind that special mount options may apply for: +* NFS file systems +* SAP file systems +* Oracle data/redo files + diff --git a/configs/etc/core/templates/mail_body.tpl-check_hpux_ioscan b/configs/etc/core/templates/mail_body.tpl-check_hpux_ioscan new file mode 100644 index 0000000..49c4c97 --- /dev/null +++ b/configs/etc/core/templates/mail_body.tpl-check_hpux_ioscan @@ -0,0 +1,10 @@ +*** MESSAGE *** +<## @_HC_BODY ##> + +*** RECOMMENDATION *** +Check any faulty devices or error messages: +* ioscan -P health (look for 'offline' devices) +* ioscan -fnN (look for 'NO_HW' devices) +* dmesg +* /var/adm/syslog/syslog.log + diff --git a/configs/etc/core/templates/mail_body.tpl-check_hpux_ovpa_status b/configs/etc/core/templates/mail_body.tpl-check_hpux_ovpa_status new file mode 100644 index 0000000..b6ac906 --- /dev/null +++ b/configs/etc/core/templates/mail_body.tpl-check_hpux_ovpa_status @@ -0,0 +1,10 @@ +*** MESSAGE *** +<## @_HC_BODY ##> + +*** RECOMMENDATION *** +Execute: +* mwa start all +* /sbin/init.d/ovpa start +Verify: +* perfstat -p + diff --git a/configs/etc/core/templates/mail_body.tpl-check_hpux_root_crontab b/configs/etc/core/templates/mail_body.tpl-check_hpux_root_crontab new file mode 100644 index 0000000..4fafecb --- /dev/null +++ b/configs/etc/core/templates/mail_body.tpl-check_hpux_root_crontab @@ -0,0 +1,7 @@ +*** MESSAGE *** +<## @_HC_BODY ##> + +*** RECOMMMENDATION *** +Check the root crontab for any wrongly commented lines and fix: +* crontab -l | grep '^#' + diff --git a/configs/etc/core/templates/mail_body.tpl-check_hpux_sg_cluster_status b/configs/etc/core/templates/mail_body.tpl-check_hpux_sg_cluster_status new file mode 100644 index 0000000..5dbd600 --- /dev/null +++ b/configs/etc/core/templates/mail_body.tpl-check_hpux_sg_cluster_status @@ -0,0 +1,12 @@ +*** MESSAGE *** +<## @_HC_BODY ##> + +*** RECOMMENDATION *** +Check current cluster status: +* cmviewcl [-v] +If the cluster is down: +* cmruncl +Check for possible errors in: +* /var/adm/cmcluster/log/* +* /var/adm/syslog/syslog.log (cmcld) + diff --git a/configs/etc/core/templates/mail_body.tpl-check_hpux_sg_package_status b/configs/etc/core/templates/mail_body.tpl-check_hpux_sg_package_status new file mode 100644 index 0000000..fa966a7 --- /dev/null +++ b/configs/etc/core/templates/mail_body.tpl-check_hpux_sg_package_status @@ -0,0 +1,15 @@ +*** MESSAGE *** +<## @_HC_BODY ##> + +*** RECOMMENDATION *** +Check current package status: +* cmviewcl [-v] -p +If the package is down: +* cmrunpkg (on the primary node) +- or - +* cmmodpkg -e +* cmmodpkg -e -n +Check for possible errors in: +* /var/adm/cmcluster/log/* +* /var/adm/syslog/syslog.log (cmcld) + diff --git a/configs/etc/core/templates/mail_body.tpl-check_hpux_vg_minor_number b/configs/etc/core/templates/mail_body.tpl-check_hpux_vg_minor_number new file mode 100644 index 0000000..a623ef8 --- /dev/null +++ b/configs/etc/core/templates/mail_body.tpl-check_hpux_vg_minor_number @@ -0,0 +1,11 @@ +*** MESSAGE *** +<## @_HC_BODY ##> + +*** RECOMMENDATION *** +If this host is part of Serviceguard cluster and the affected volume group +is cluster aware, then major/minor numbers must be unique AND identical on +all cluster nodes. + +View the current major/minor: +* vgs + diff --git a/configs/etc/core/templates/mail_body.tpl-check_linux_fs_mounts_options b/configs/etc/core/templates/mail_body.tpl-check_linux_fs_mounts_options new file mode 100644 index 0000000..78b472e --- /dev/null +++ b/configs/etc/core/templates/mail_body.tpl-check_linux_fs_mounts_options @@ -0,0 +1,12 @@ +*** MESSAGE *** +<## @_HC_BODY ##> + +*** RECOMMENDATION *** +File system is mounted with incorrect options. Remount the file system with the correct options. +* Check /etc/fstab + +Keep in mind that special mount options may apply for: +* NFS file systems +* SAP file systems +* Oracle data/redo files + diff --git a/configs/etc/core/templates/mail_body.tpl-check_linux_root_crontab b/configs/etc/core/templates/mail_body.tpl-check_linux_root_crontab new file mode 100644 index 0000000..4fafecb --- /dev/null +++ b/configs/etc/core/templates/mail_body.tpl-check_linux_root_crontab @@ -0,0 +1,7 @@ +*** MESSAGE *** +<## @_HC_BODY ##> + +*** RECOMMMENDATION *** +Check the root crontab for any wrongly commented lines and fix: +* crontab -l | grep '^#' + diff --git a/configs/etc/core/templates/mail_footer.tpl b/configs/etc/core/templates/mail_footer.tpl new file mode 100644 index 0000000..dde2b8a --- /dev/null +++ b/configs/etc/core/templates/mail_footer.tpl @@ -0,0 +1,11 @@ +*** LOGS *** +Please check the corresponding log file(s) for more details. At <## @HOST_NAME ##>:<## @LOG_DIR ##>) + +You can also run /opt/hc/bin/check_health.sh --report --id=<## @_MAIL_FAIL_ID ##> (--detail) on <## @HOST_NAME ##> + +Following log files have been attached to this e-mail: + +STDOUT : <## @_MAIL_STDOUT_MSG ##> +STDERR : <## @_MAIL_STDERR_MSG ##> + +******* END OF MAIL. DO NOT REPLY TO THIS E-MAIL. NOBODY WILL SEE IT! ******** diff --git a/configs/etc/core/templates/mail_header.tpl b/configs/etc/core/templates/mail_header.tpl new file mode 100644 index 0000000..08ca8cd --- /dev/null +++ b/configs/etc/core/templates/mail_header.tpl @@ -0,0 +1,4 @@ +*** ID *** +HC NAME : <## @_MAIL_HC ##> +FAIL ID : <## @_MAIL_FAIL_ID ##> + diff --git a/configs/etc/core/templates/mail_info.tpl b/configs/etc/core/templates/mail_info.tpl new file mode 100644 index 0000000..1a6a88a --- /dev/null +++ b/configs/etc/core/templates/mail_info.tpl @@ -0,0 +1,3 @@ +To: <## @ARG_MAIL_TO ##> +Subject: <## @_SUBJ_MSG ##> +From: <## @_FROM_MSG ##> diff --git a/sources/bin/check_health.sh b/sources/bin/check_health.sh new file mode 100644 index 0000000..83736b1 --- /dev/null +++ b/sources/bin/check_health.sh @@ -0,0 +1,1260 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_health.sh +#****************************************************************************** +# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_health.sh +# DOES: performs simple health checks on UNIX hosts. Individual checks are +# contained in separate KSH functions (aka plug-ins) +# EXPECTS: (see --help for more options) +# 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(), read_config() +# + include functions +# For other pre-requisites see the documentation in display_usage() +# REQUIRES (OPTIONAL): display_csv(), display_terse(), display_init(), +# notify_eif(), notify_mail(), notify_sms() +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +#****************************************************************************** +# DATA structures +#****************************************************************************** + +# ------------------------- CONFIGURATION starts here ------------------------- +# define the version (YYYY-MM-DD) +typeset -r SCRIPT_VERSION="2017-08-24" +# location of parent directory containing KSH functions/HC plugins +typeset -r FPATH_PARENT="/opt/hc/lib" +# location of custom HC configuration files +typeset -r CONFIG_DIR="/etc/opt/hc" +# location of main configuration file +typeset -r CONFIG_FILE="${CONFIG_DIR}/core/check_health.conf" +# location of the host check configuration file (optional) +typeset -r HOST_CONFIG_FILE="${CONFIG_DIR}/check_host.conf" +# location of temporary working storage +typeset -r TMP_DIR="/var/tmp" +# health check log separator +typeset -r SEP="|" +# specify the UNIX user that needs to be used for executing the script +typeset -r EXEC_USER="root" +# ------------------------- CONFIGURATION ends here --------------------------- +# miscellaneous +typeset PATH=${PATH}:/usr/bin:/usr/sbin:/usr/local/bin +typeset -r SCRIPT_NAME="$(basename $0)" +typeset -r SCRIPT_DIR="$(dirname $0)" +typeset -r HOST_NAME="$(hostname)" +typeset -r OS_NAME="$(uname -s)" +typeset -r LOCK_DIR="${TMP_DIR}/.${SCRIPT_NAME}.lock" +typeset -r HC_MSG_FILE="${TMP_DIR}/.${SCRIPT_NAME}.hc.msg.$$" # plugin messages files +typeset CHILD_ERROR=0 +typeset DIR_PREFIX="$(date '+%Y-%m')" +typeset EXIT_CODE=0 +typeset FDIR="" +typeset FFILE="" +typeset FPATH="" +typeset HC_FAIL_ID="" +typeset HC_FILE_LINE="" +typeset HC_NOW="" +typeset HC_STDOUT_LOG="" +typeset HC_STDERR_LOG="" +typeset LINUX_DISTRO="" +typeset LINUX_RELEASE="" +typeset RUN_RC=0 +typeset SORT_CMD="" +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_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 +typeset ARG_DETAIL=0 # for --report +typeset ARG_DISPLAY="" # display is STDOUT by default +typeset ARG_FAIL_ID="" +typeset ARG_HC="" +typeset ARG_HC_ARGS="" # no extra arguments to HC plug-in by default +typeset ARG_LAST=0 # report last events +typeset ARG_LIST="" # list all by default +typeset ARG_LOG_DIR="" # location of the log directory (~root, oracle etc) +typeset ARG_LOG=1 # logging is on by default +typeset ARG_MONITOR=1 # killing long running HC processes is on by default +typeset ARG_NOTIFY="" # notification of problems is off by default +typeset ARG_REVERSE=0 # show report in reverse date order is off by default +typeset ARG_TERSE=0 # show terse help is off by default +typeset ARG_TODAY=0 # report today's events +typeset ARG_VERBOSE=1 # STDOUT is on by default +set +o bgnice + + +#****************************************************************************** +# FUNCTION routines +#****************************************************************************** + +# ----------------------------------------------------------------------------- +# COMMON +# ----------------------------------------------------------------------------- + +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: build_fpath() +# DOES: build the FPATH environment variable from FPATH_PARENT +# EXPECTS: n/a +# RETURNS: 0 +# REQUIRES: n/a +function build_fpath +{ +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}" +typeset FPATH_DIR="" + +# 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) +for FPATH_DIR in $(find ${FPATH_PARENT} -type d | grep -v -E -e "^${FPATH_PARENT}$" | tr '\n' ' ' 2>/dev/null) +do + if [[ -z "${FPATH}" ]] + then + FPATH="${FPATH_DIR}" + else + FPATH="${FPATH}:${FPATH_DIR}" + fi +done + +return 0 +} +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: check_config() +# DOES: check script configuration settings, abort upon failure +# EXPECTS: n/a +# RETURNS: 0 +# REQUIRES: n/a +function check_config +{ +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}" + +# EXEC_USER +if [[ -z "${EXEC_USER}" ]] +then + print -u2 "ERROR: you must define a value for the EXEC_USER setting in $0" + exit 1 +fi +# FPATH_PARENT +if [[ -z "${FPATH_PARENT}" ]] +then + print -u2 "ERROR: you must define a value for the FPATH_PARENT setting in $0" + exit 1 +fi +if [[ ! -d "${FPATH_PARENT}" ]] +then + print -u2 "ERROR: directory in setting FPATH_PARENT does not exist" + exit 1 +fi +# SEP +if [[ -z "${SEP}" ]] +then + print -u2 "ERROR: you must define a value for the SEP setting in $0" + exit 1 +fi +# HC_TIME_OUT +if [[ -z "${HC_TIME_OUT}" ]] +then + print -u2 "ERROR: you must define a value for the HC_TIME_OUT setting in $0" + exit 1 +fi +# EVENTS_DIR (auto-created dir) +if [[ -z "${EVENTS_DIR}" ]] +then + print -u2 "ERROR: you must define a value for the EVENTS_DIR setting in $0" + exit 1 +fi +# STATE_DIR (auto-created dir) +if [[ -z "${STATE_DIR}" ]] +then + print -u2 "ERROR: you must define a value for the STATE_DIR setting in $0" + exit 1 +fi + +return 0 +} + +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: check_core() +# DOES: check core plugins & files/directories +# EXPECTS: n/a +# RETURNS: 0 +# REQUIRES: n/a +function check_core +{ +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}" + +# check and include core helper libs +if [[ -r ${FPATH_PARENT}/core/include_core.sh && -h ${FPATH_PARENT}/core/include_core ]] +then + # source /opt/hc/lib/core/include_core.sh + . ${FPATH_PARENT}/core/include_core.sh +else + print -u2 "ERROR: library file ${FPATH_PARENT}/core/include_core.sh is not present (tip: run --fix-symlinks)" + exit 1 +fi +if [[ -r ${FPATH_PARENT}/core/include_data.sh && -h ${FPATH_PARENT}/core/include_data ]] +then + # source /opt/hc/lib/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)" + exit 1 +fi +if [[ -r ${FPATH_PARENT}/core/include_os.sh && -h ${FPATH_PARENT}/core/include_os ]] +then + # source /opt/hc/lib/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)" + exit 1 +fi + +# check for core directories +[[ -d ${EVENTS_DIR} ]] || mkdir -p "${EVENTS_DIR}" >/dev/null 2>&1 +if [[ ! -d "${EVENTS_DIR}" ]] || [[ ! -w "${EVENTS_DIR}" ]] +then + print -u2 "ERROR: unable to access the state directory at ${EVENTS_DIR}" +fi +[[ -d ${STATE_DIR} ]] || mkdir -p "${STATE_DIR}" >/dev/null 2>&1 +if [[ ! -d "${STATE_DIR}" ]] || [[ ! -w "${STATE_DIR}" ]] +then + print -u2 "ERROR: unable to access the state directory at ${STATE_DIR}" +fi +[[ -d ${STATE_PERM_DIR} ]] || mkdir -p "${STATE_PERM_DIR}" >/dev/null 2>&1 +if [[ ! -d "${STATE_PERM_DIR}" ]] || [[ ! -w "${STATE_PERM_DIR}" ]] +then + print -u2 "ERROR: unable to access the persistent state directory at ${STATE_PERM_DIR}" +fi +[[ -d ${STATE_TEMP_DIR} ]] || mkdir -p "${STATE_TEMP_DIR}" >/dev/null 2>&1 +if [[ ! -d "${STATE_TEMP_DIR}" ]] || [[ ! -w "${STATE_TEMP_DIR}" ]] +then + print -u2 "ERROR: unable to access the temporary state directory at ${STATE_TEMP_DIR}" +fi + +return 0 +} + +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: check_lock_dir() +# DOES: check if script lock directory exists, abort upon duplicate run +# EXPECTS: n/a +# RETURNS: 0 +# REQUIRES: n/a +function check_lock_dir +{ +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}" +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 + typeset LOCK_PID="$(cat ${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 + +return 0 +} + +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: check_params() +# DOES: check if arguments/options are valid, abort script upon error +# EXPECTS: n/a +# RETURNS: 0 +# REQUIRES: n/a +function check_params +{ +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}" + +# --debug-level +if (( ARG_DEBUG_LEVEL > 2 )) +then + print -u2 "ERROR: you must specify a debug level between 0-2" + exit 1 +fi +# --config-file +if [[ -n "${ARG_CONFIG_FILE}" ]] +then + # do not allow a custom configuration file for multiple checks + if [[ "${ARG_HC}" = *,* ]] # use =, ksh88 + then + print -u2 "ERROR: custom configuration file is not allowed when executing multiple HC's" + exit 1 + fi + # check if config file exists + if [[ ! -r "${ARG_CONFIG_FILE}" ]] + then + print -u2 "ERROR: unable to read configuration file at ${ARG_CONFIG_FILE}" + exit 1 + fi +fi +# --report/--detail/--id/--reverse/--last/--today +if (( ARG_ACTION == 8 )) +then + if (( ARG_DETAIL != 0 )) && [[ -z "${ARG_FAIL_ID}" ]] + then + print -u2 "ERROR: you must specify an unique value for '--id' when using '--detail'" + exit 1 + fi + if (( ARG_LAST != 0 )) && (( ARG_TODAY != 0 )) + then + print -u2 "ERROR: you cannot specify '--last' with '--today'" + exit 1 + fi + if (( ARG_LAST != 0 )) && (( ARG_DETAIL != 0 )) + then + print -u2 "ERROR: you cannot specify '--last' with '--detail'" + exit 1 + fi + if (( ARG_LAST != 0 )) && (( ARG_REVERSE != 0 )) + then + print -u2 "ERROR: you cannot specify '--last' with '--detail'" + exit 1 + fi + if (( ARG_LAST != 0 )) && [[ -n "${ARG_FAIL_ID}" ]] + then + print -u2 "ERROR: you cannot specify '--last' with '--id'" + exit 1 + fi + if (( ARG_TODAY != 0 )) && (( ARG_DETAIL != 0 )) + then + print -u2 "ERROR: you cannot specify '--today' with '--detail'" + exit 1 + fi + if (( ARG_TODAY != 0 )) && (( ARG_REVERSE != 0 )) + then + print -u2 "ERROR: you cannot specify '--today' with '--detail'" + exit 1 + fi + if (( ARG_TODAY != 0 )) && [[ -n "${ARG_FAIL_ID}" ]] + then + print -u2 "ERROR: you cannot specify '--today' with '--id'" + exit 1 + fi +fi +if (( ARG_ACTION != 8 )) && (( ARG_LAST != 0 )) +then + print -u2 "ERROR: you cannot specify '--last' without '--report'" + exit 1 +fi +if (( ARG_ACTION != 8 )) && (( ARG_REVERSE != 0 )) +then + print -u2 "ERROR: you cannot specify '--reverse' without '--report'" + exit 1 +fi +if (( ARG_ACTION != 8 )) && (( ARG_DETAIL != 0 )) +then + print -u2 "ERROR: you cannot specify '--detail' without '--report'" + exit 1 +fi +if (( ARG_ACTION != 8 )) && [[ -n "${ARG_FAIL_ID}" ]] +then + print -u2 "ERROR: you cannot specify '--id' without '--report'" + exit 1 +fi +# --check-host,--check/--disable/--enable/--run/--show,--hc +if [[ -n "${ARG_HC}" ]] && (( ARG_ACTION == 0 )) +then + print -u2 "ERROR: you must specify an action for the HC (--check/--disable/--enable/--run/--show)" + exit 1 +fi +if (( ARG_CHECK_HOST == 0 )) +then + if (( ARG_ACTION < 6 )) && [[ -z "${ARG_HC}" ]] + then + print -u2 "ERROR: you specify a value for parameter '--hc'" + exit 1 + fi + if (( ARG_ACTION == 5 )) || [[ -n "${ARG_HC_ARGS}" ]] + then + case "${ARG_HC}" in + *,*) + print -u2 "ERROR: you can only specify one value for '--hc' in combination with '--show'" + exit 1 + ;; + esac + fi +else + # host checking has no other messages to display + ARG_VERBOSE=0 +fi +# --list +if (( ARG_ACTION == 9 )) +then + ARG_VERBOSE=0 + ARG_LOG=0 +fi +# --log-dir +[[ -z "${ARG_LOG_DIR}" ]] || LOG_DIR="${ARG_LOG_DIR}" +LOG_FILE="${LOG_DIR}/${SCRIPT_NAME}.log" +if (( ARG_LOG != 0 )) +then + if [[ ! -d "${LOG_DIR}" ]] || [[ ! -w "${LOG_DIR}" ]] + then + print -u2 "ERROR: unable to write to the log directory at ${LOG_DIR}" + exit 1 + fi +fi + +return 0 +} + +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: check_platform() +# DOES: check running platform +# EXPECTS: platform name [string] +# RETURNS: 0=platform matches, 1=platform does not match +# REQUIRES: $OS_NAME +function check_platform +{ +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}" +typeset HC_PLATFORM="${1}" +typeset RC=0 + +if [[ "${OS_NAME}" != @(${HC_PLATFORM}) ]] +then + (( ARG_DEBUG != 0 )) && warn "platform ${HC_PLATFORM} does not match ${OS_NAME}" + RC=1 +fi + +return ${RC} +} + +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: check_user() +# DOES: check user that is executing the script, abort script if user 'root' +# EXPECTS: n/a +# RETURNS: 0 +# REQUIRES: n/a +function check_user +{ +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}" +typeset WHOAMI="" + +# avoid sub-shell for mksh/pdksh +WHOAMI=$(IFS='()'; set -- $(id); print $2) +if [[ "${WHOAMI}" != "${EXEC_USER}" ]] +then + print -u2 "ERROR: must be run as user '${EXEC_USER}'" + exit 1 +fi + +return 0 +} + +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: check_shell() +# DOES: check for ksh version +# EXPECTS: n/a +# RETURNS: 0 +# REQUIRES: n/a +function check_shell +{ +case "${KSH_VERSION}" in + *MIRBSD*|*PD*|*LEGACY*) + (( ARG_DEBUG != 0 )) && debug "running ksh: ${KSH_VERSION}" + ;; + *) + if [[ -z "${ERRNO}" ]] + then + (( ARG_DEBUG != 0 )) && print "running ksh: ${.sh.version}" + else + (( ARG_DEBUG != 0 )) && print "running ksh: ksh88 or older" + fi + ;; +esac + +return 0 +} + +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: display_usage() +# DOES: display usage and exit with error code 0 +# EXPECTS: n/a +# RETURNS: 0 +# REQUIRES: n/a +function display_usage +{ +cat << EOT + +**** ${SCRIPT_NAME} **** +**** (c) KUDOS BVBA - Patrick Van der Veken **** + +Execute/report simple health checks (HC) on UNIX hosts. + +Syntax: ${SCRIPT_DIR}/${SCRIPT_NAME} [--help] | [--help-terse] | [--version] | + [--list=] | [--list-core] | [--fix-symlinks] | (--disable-all | enable-all) | + (--check-host | ((--check | --enable | --disable | --run | --show) --hc= [--config-file=] [hc-args="])) + [--display=] ([--debug] [--debug-level=]) [--no-monitor] [--no-log] [--log-dir=] + [--notify=] [--mail-to=] [--sms-to= --sms-provider=] + --report ( ([--last] | [--today]) | ([--reverse] [--id= [--detail]]) ) + +EOT + +if (( ARG_TERSE == 0 )) +then + cat << EOT +Parameters: + +--check : display HC state. +--check-host : execute all configured HC(s) (see check_host.conf) +--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) +--detail : show detailed info on failed HC event (will show STDOUT+STDERR logs) +--disable : disable HC(s). +--disable-all : disable all HC. +--display : display HC results in a formatted way. Default is STDOUT (see --list-core for available formats) +--enable : enable HC(s). +--enable-all : enable all HCs. +--fix-symlinks : update symbolic links for the KSH autoloader. +--hc : list of health checks to be executed (comma-separated) (see also --list-hc) +--hc-args : extra arguments to be passed to an individual HC. Arguments must be comma-separated and enclosed + 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 events for each HC and their combined STC value +--list : show the available health checks. Use 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 ${HC_ETC_DIR} + - whether the HC plugin is scheduled by cron +--list-core : show the available core plugins (mail,SMS,...) +--log-dir : specify a log directory location (for both script & health checks log). +--mail-to : list of e-mail address(es) to which an e-mail alert will be send to [requires mail core plugin] +--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 +--notify : notify upon HC failure(s). Multiple options may be specified if comma-separated (see --list-core for availble formats) +--report : report on failed HC events +--reverse : show the report in reverse date order (newest events first) +--run : execute HC(s). +--show : show information/documentation on a HC +--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] +--today : show today's events (HC and their combined STC value) +--version : show the script version (major/minor/fix). + +EOT +fi + +return 0 +} + +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: do_cleanup() +# DOES: remove temporary file(s)/director(y|ies) +# EXPECTS: n/a +# RETURNS: 0 +# REQUIRES: log() +function do_cleanup +{ +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}" +log "performing cleanup ..." + +# remove temporary files +[[ -f "${HC_MSG_FILE}" ]] && rm -f ${HC_MSG_FILE} >/dev/null 2>&1 + +# 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 + log "${LOCK_DIR} lock directory removed" +fi + +log "*** finish of ${SCRIPT_NAME} [${CMD_LINE}] ***" + +return 0 +} + +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: fix_symlinks() +# DOES: create symbolic links to HC scripts to satisfy KSH autoloader +# EXPECTS: n/a +# RETURNS: 0 +# REQUIRES: n/a +function fix_symlinks +{ +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}" +typeset FDIR="" +typeset FFILE="" +typeset FSYML="" + +# find missing symlinks (do not skip core plug-ins here) +print "${FPATH}" | tr ':' '\n' | while read -r FDIR +do + find ${FDIR} -type f -print 2>/dev/null | while read -r FFILE + do + FSYML="${FFILE%.sh}" + # check if symlink already exists + if [[ ! -h "${FSYML}" ]] + then + ln -s "${FFILE##*/}" "${FSYML}" >/dev/null + (( $? == 0 )) && \ + print -u2 "INFO: created symbolic link ${FFILE} -> ${FSYML}" + fi + done +done + +# find & remove broken symbolic links (do not skip core plug-ins here) +print "${FPATH}" | tr ':' '\n' | while read -r FDIR +do + # do not use 'find -type l' here! + ls ${FDIR} 2>/dev/null | grep -v "\." | while read -r FSYML + do + # check if file is a dead symlink + if [[ -h "${FDIR}/${FSYML}" ]] && [[ ! -f "${FDIR}/${FSYML}" ]] + then + rm -f "${FDIR}/${FSYML}" >/dev/null + (( $? == 0 )) && \ + print -u2 "INFO: remove dead symbolic link ${FSYML}" + fi + done +done + +return 0 +} + +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: read_config() +# DOES: read & parse the main configuration file(s) +# EXPECTS: n/a +# RETURNS: 0 +# REQUIRES: die() +function read_config +{ +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}" +typeset SMS_CONFIG_FILE="" + +if [[ -z "${CONFIG_FILE}" ]] || [[ -z "${CONFIG_FILE}" ]] +then + die "you must define a value for the CONFIG_DIR and CONFIG_FILE setting in $0" +fi +if [[ ! -r "${CONFIG_FILE}" ]] +then + die "unable to read configuration file at ${CONFIG_FILE}" +else + . "${CONFIG_FILE}" +fi + +return 0 +} + + +#****************************************************************************** +# MAIN routine +#****************************************************************************** + +# parse arguments/parameters +CMD_LINE="$*" +[[ -z "${CMD_LINE}" ]] && display_usage && exit 0 +for PARAMETER in ${CMD_LINE} +do + case ${PARAMETER} in + -check|--check) + ARG_ACTION=1 + ;; + -c|-check-host|--check-host) + ARG_CHECK_HOST=1 + ARG_ACTION=4 + ;; + -config-file=*) + ARG_CONFIG_FILE="${PARAMETER#-config-file=}" + ;; + --config-file=*) + ARG_CONFIG_FILE="${PARAMETER#--config-file=}" + ;; + -debug|--debug) + ARG_DEBUG=1 + PS4='DEBUG: $0: line $LINENO: ' + set "${DEBUG_OPTS}" + ;; + -debug-level=*) + ARG_DEBUG_LEVEL="${PARAMETER#-debug-level=}" + ;; + --debug-level=*) + ARG_DEBUG_LEVEL="${PARAMETER#--debug-level=}" + ;; + -detail|--detail) + ARG_DETAIL=1 + ;; + -d|-disable|--disable) + ARG_ACTION=2 + ;; + -disable-all|--disable-all) + ARG_ACTION=6 + ;; + -display|--display) + # STDOUT as default + ARG_DISPLAY="" + ;; + -display=*) + ARG_DISPLAY="${PARAMETER#-display=}" + ;; + --display=*) + ARG_DISPLAY="${PARAMETER#--display=}" + ;; + -e|-enable|--enable) + ARG_ACTION=3 + ;; + -enable-all|--enable-all) + ARG_ACTION=7 + ;; + -hc=*) + ARG_HC="${PARAMETER#-hc=}" + ;; + --hc=*) + ARG_HC="${PARAMETER#--hc=}" + ;; + -hc-args=*) + ARG_HC_ARGS="${PARAMETER#-hc-args=}" + ;; + --hc-args=*) + ARG_HC_ARGS="${PARAMETER#--hc-args=}" + ;; + -f|-fix-symlinks|--fix-symlinks) + read_config + check_config + build_fpath + check_shell + check_user + fix_symlinks + exit 0 + ;; + -id=*) + ARG_FAIL_ID="${PARAMETER#-id=}" + ;; + --id=*) + ARG_FAIL_ID="${PARAMETER#--id=}" + ;; + -last|--last) + ARG_LAST=1 + ;; + -list|--list) + ARG_ACTION=9 + ;; + -list=*) + ARG_LIST="${PARAMETER#-list=}" + ARG_ACTION=9 + ;; + --list=*) + ARG_LIST="${PARAMETER#--list=}" + ARG_ACTION=9 + ;; + -list-hc|--list-hc|-list-all|--list-all) + print -u2 "WARN: deprecated option. Use --list | --list=" + exit 0 + ;; + -list-core|--list-core) + read_config + check_config + build_fpath + check_core + check_shell + check_user + list_core + exit 0 + ;; + -log-dir=*) + ARG_LOG_DIR="${PARAMETER#-log-dir=}" + ;; + --log-dir=*) + ARG_LOG_DIR="${PARAMETER#--log-dir=}" + ;; + -mail-to=*) + ARG_MAIL_TO="${PARAMETER#-mail-to=}" + ;; + --mail-to=*) + ARG_MAIL_TO="${PARAMETER#--mail-to=}" + ;; + -notify=*) + ARG_NOTIFY="${PARAMETER#-notify=}" + ;; + --notify=*) + ARG_NOTIFY="${PARAMETER#--notify=}" + ;; + -no-log|--no-log) + ARG_LOG=0 + ;; + -no-monitor|--no-monitor) + ARG_MONITOR=0 + ;; + -report|--report) + ARG_LOG=0; ARG_VERBOSE=0 + ARG_ACTION=8 + ;; + -reverse|--reverse) + ARG_REVERSE=1 + ;; + -r|-run|--run) + ARG_ACTION=4 + ;; + -s|-show|--show) + ARG_ACTION=5 + ARG_LOG=0 + ARG_VERBOSE=0 + ;; + -sms-provider=*) + ARG_SMS_PROVIDER="${PARAMETER#-sms-provider=}" + ;; + --sms-provider=*) + ARG_SMS_PROVIDER="${PARAMETER#--sms-provider=}" + ;; + -sms-to=*) + ARG_SMS_TO="${PARAMETER#-sms-to=}" + ;; + --sms-to=*) + ARG_SMS_TO="${PARAMETER#--sms-to=}" + ;; + -today|--today) + ARG_TODAY=1 + ;; + -v|-version|--version) + print "INFO: $0: ${SCRIPT_VERSION}" + exit 0 + ;; + \?|-h|-help|--help) + display_usage + exit 0 + ;; + -help-terse|--help-terse) + ARG_TERSE=1 + display_usage + exit 0 + ;; + *) + display_usage + exit 0 + ;; + esac +done + +# startup checks & processing (no build_fpath() here to avoid dupes in FPATH!) +read_config +check_config +build_fpath +check_core +check_shell +check_params # parse cmd-line +discover_core # parse cmd-line (for core plugins) +check_user + +# catch shell signals +trap 'do_cleanup; exit' HUP INT QUIT TERM + +# set debugging options +if (( ARG_DEBUG != 0 )) +then + case ${ARG_DEBUG_LEVEL} in + 0) + # display only messages via debug() (default) + : + ;; + 1) + # set -x + DEBUG_OPTS='-x' + ;; + 2) + # set -vx + DEBUG_OPTS='-vx' + ;; + esac +fi + +log "*** start of ${SCRIPT_NAME} [${CMD_LINE}] ***" +(( ARG_LOG != 0 )) && log "logging takes places in ${LOG_FILE}" + +# check/create lock file & write PID file (only for --run) +(( ARG_ACTION == 4 )) && check_lock_dir + +# general HC log +HC_LOG="${LOG_DIR}/hc.log" + +# get linux stuff +[[ "${OS_NAME}" = "Linux" ]] && linux_get_distro # use =, ksh88 + +# act on HC check(s) +case ${ARG_ACTION} in + 1) # check (status) HC(s) + print "${ARG_HC}" | tr ',' '\n' | grep -v '^$' | while read -r HC_CHECK + do + # check for HC (function) + exists_hc "${HC_CHECK}" && die "cannot find HC: ${HC_CHECK}" + stat_hc "${HC_CHECK}" + if (( $? == 0 )) + then + log "HC ${HC_CHECK} is currently disabled" + else + log "HC ${HC_CHECK} is currently enabled" + fi + is_scheduled "${HC_CHECK}" + if (( $? == 0 )) + then + log "HC ${HC_CHECK} is currently not scheduled (cron)" + else + log "HC ${HC_CHECK} is currently scheduled (cron)" + fi + done + ;; + 2) # disable HC(s) + print "${ARG_HC}" | tr ',' '\n' | grep -v '^$' | while read -r HC_DISABLE + do + # check for HC (function) + 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 + if (( $? == 0 )) + then + log "successfully disabled HC: ${HC_DISABLE}" + else + log "failed to disable HC: ${HC_DISABLE} [RC=${DISABLE_RC}]" + EXIT_CODE=1 + fi + done + ;; + 3) # enable HC(s) + print "${ARG_HC}" | tr ',' '\n' | grep -v '^$' | while read -r HC_ENABLE + do + # check for HC (function) + exists_hc "${HC_ENABLE}" && die "cannot find HC: ${HC_ENABLE}" + log "enabling HC: ${HC_ENABLE}" + [[ -d ${STATE_PERM_DIR} ]] || \ + die "state directory does not exist, all HC(s) are enabled" + stat_hc "${HC_ENABLE}" || die "HC is already enabled" + rm -f "${STATE_PERM_DIR}/${HC_ENABLE}.disabled" >/dev/null 2>&1 + if (( $? == 0 )) + then + log "successfully enabled HC: ${HC_ENABLE}" + else + log "failed to enable HC: ${HC_ENABLE} [RC=${ENABLE_RC}]" + EXIT_CODE=1 + fi + done + ;; + 4) # run HC(s) + # pre-allocate FAIL_ID + HC_NOW="$(date '+%Y-%m-%d %H:%M:%S' 2>/dev/null)" + if [[ -z "${HC_FAIL_ID}" ]] + then + HC_FAIL_ID="$(print ${HC_NOW} | tr -d '\-:[:space:]')" + fi + # --check-host handling + (( ARG_CHECK_HOST == 1 )) && init_check_host + # execute plug-in(s) + print "${ARG_HC}" | tr ',' '\n' | grep -v '^$' | while read -r HC_RUN + do + # check for HC (function) + exists_hc "${HC_RUN}" + if (( $? == 0 )) + then + # callback for display_init with extra code 'MISSING' + if (( DO_DISPLAY_INIT == 1 )) + then + display_init "${HC_RUN}" "" "MISSING" + else + warn "cannot find HC: ${HC_RUN}" + EXIT_CODE=${RUN_RC} + fi + continue + fi + stat_hc "${HC_RUN}" + if (( $? == 0 )) + then + # callback for display_init with extra code 'DISABLED' + if (( DO_DISPLAY_INIT == 1 )) + then + display_init "${HC_RUN}" "" "DISABLED" + else + warn "may not run disabled HC: ${HC_RUN}" + EXIT_CODE=${RUN_RC} + fi + continue + fi + # 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.$$" + >${HC_STDOUT_LOG} 2>/dev/null + >${HC_STDERR_LOG} 2>/dev/null + + # --check-host handling: alternative configuration file, mangle ARG_CONFIG_FILE + if (( ARG_CHECK_HOST == 1 )) + then + 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}" + fi + + # run HC with or without monitor + if (( ARG_MONITOR == 0 )) + then + ${HC_RUN} ${ARG_HC_ARGS} + RUN_RC=$? + EXIT_CODE=${RUN_RC} + if (( RUN_RC == 0 )) + then + log "executed HC: ${HC_RUN} [RC=${RUN_RC}]" + else + # callback for display_init with extra code 'ERROR' + if (( DO_DISPLAY_INIT == 1 )) + then + display_init "${HC_RUN}" "" "ERROR" + else + warn "failed to execute HC: ${HC_RUN} [RC=${RUN_RC}]" + fi + fi + else + # set trap on SIGUSR1 + trap "handle_timeout" USR1 + + # $PID is PID of the owner shell + OWNER_PID=$$ + ( + # sleep for $TIME_OUT seconds. If the sleep subshell is then still alive, send a SIGUSR1 to the owner + sleep ${HC_TIME_OUT} + kill -s USR1 ${OWNER_PID} >/dev/null 2>&1 + ) & + # SLEEP_PID is the PID of the sleep subshell itself + SLEEP_PID=$! + + ${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}]" + # wait for the command to complete + wait ${CHILD_PID} + # when the child completes, we can get rid of the sleep trigger + RUN_RC=$? + EXIT_CODE=${RUN_RC} + kill -s TERM ${SLEEP_PID} >/dev/null 2>&1 + # process return codes + if (( RUN_RC != 0 )) + then + # callback for display_init with extra code 'ERROR' + if (( DO_DISPLAY_INIT == 1 )) + then + display_init "${HC_RUN}" "" "ERROR" + else + warn "failed to execute HC: ${HC_RUN} [RC=${RUN_RC}]" + fi + else + if (( CHILD_ERROR == 0 )) + then + log "executed HC: ${HC_RUN} [RC=${RUN_RC}]" + else + # callback for display_init with extra code 'ERROR' + if (( DO_DISPLAY_INIT == 1 )) + then + display_init "${HC_RUN}" "" "ERROR" + else + warn "failed to execute HC as background process" + fi + fi + fi + fi + + # reset FAIL_ID & HC failure storage (also for failed HCs) + handle_hc "${HC_RUN}" + rm -f ${HC_MSG_FILE} >/dev/null 2>&1 + done + ;; + 5) # show info on HC (single) + exists_hc "${ARG_HC}" + if (( $? == 0 )) + then + die "cannot find HC: ${ARG_HC}" + else + ${ARG_HC} "help" + fi + ;; + 6) # disable all HCs + list_hc "list" | while read -r HC_DISABLE + do + # check for HC (function) + 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 + if (( $? == 0 )) + then + log "successfully disabled HC: ${HC_DISABLE}" + else + log "failed to disable HC: ${HC_DISABLE} [RC=${DISABLE_RC}]" + EXIT_CODE=1 + fi + done + ;; + 7) # enable all HCs + list_hc "list" | while read -r HC_ENABLE + do + # check for HC (function) + exists_hc "${HC_ENABLE}" && die "cannot find HC: ${HC_ENABLE}" + log "enabling HC: ${HC_ENABLE}" + [[ -d ${STATE_PERM_DIR} ]] || \ + die "state directory does not exist, all HC(s) are enabled" + rm -f "${STATE_PERM_DIR}/${HC_ENABLE}.disabled" >/dev/null 2>&1 + if (( $? == 0 )) + then + log "successfully enabled HC: ${HC_ENABLE}" + else + log "failed to enable HC: ${HC_ENABLE} [RC=${ENABLE_RC}]" + EXIT_CODE=1 + fi + done + ;; + 8) # report on last events or FAIL_IDs + if (( ARG_LAST != 0 )) + then + printf "\n| %-30s | %-20s | %-14s | %-4s\n" "HC" "Timestamp" "FAIL ID" "STC (combined value)" + printf "%100s\n" | tr ' ' - + # loop over all HCs + list_hc "list" | while read -r HC_LAST + do + HC_LAST_TIME="" + HC_LAST_STC=0 + HC_LAST_FAIL_ID="-" + # find last event or block of events (same timestamp) + # (but unfortunately this is only accurate to events within the SAME second!) + HC_LAST_TIME="$(grep ${HC_LAST} ${HC_LOG} 2>/dev/null | sort -n | cut -f1 -d${SEP} | uniq | tail -1)" + if [[ -z "${HC_LAST_TIME}" ]] + then + HC_LAST_TIME="-" + HC_LAST_STC="-" + else + # find all STC codes for the last event and add them up + grep "${HC_LAST_TIME}${SEP}${HC_LAST}" ${HC_LOG} 2>/dev/null |\ + while read -r REPORT_LINE + do + HC_LAST_EVENT_STC=$(print "${REPORT_LINE}" | cut -f3 -d"${SEP}") + HC_LAST_EVENT_FAIL_ID=$(print "${REPORT_LINE}" | cut -f5 -d"${SEP}") + HC_LAST_STC=$(( HC_LAST_STC + HC_LAST_EVENT_STC )) + [[ -n "${HC_LAST_EVENT_FAIL_ID}" ]] && HC_LAST_FAIL_ID="${HC_LAST_EVENT_FAIL_ID}" + done + fi + # report on findings + printf "| %-30s | %-20s | %-14s | %-4s\n" \ + "${HC_LAST}" "${HC_LAST_TIME}" "${HC_LAST_FAIL_ID}" "${HC_LAST_STC}" + done + # 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 $0 --report to get the exact list of failure events." + else + ID_NEEDLE="[0-9][0-9]*" + [[ -n "${ARG_FAIL_ID}" ]] && ID_NEEDLE="${ARG_FAIL_ID}" + (( ARG_TODAY != 0 )) && ID_NEEDLE="$(date '+%Y%m%d')" # refers to timestamp of HC FAIL_ID + + # check fail count (look for unique IDs in the 5th field of the HC log) + FAIL_COUNT=$(cut -f5 -d"${SEP}" ${HC_LOG} 2>/dev/null | grep -E -e "${ID_NEEDLE}" | uniq | wc -l) + if (( FAIL_COUNT != 0 )) + then + # check for detail or not? + if (( ARG_DETAIL != 0 )) && (( FAIL_COUNT != 1 )) + then + ARG_LOG=1 die "you must specify a unique FAIL_ID value" + fi + # reverse? + if (( ARG_REVERSE == 0 )) + then + SORT_CMD="sort -n" + else + SORT_CMD="sort -rn" + fi + # global or detailed? + if (( ARG_DETAIL == 0 )) + then + printf "\n| %-20s | %-14s | %-30s | %-s\n" \ + "Timestamp" "FAIL ID" "HC" "Message" + printf "%120s\n" | tr ' ' - + + # print failed events + # no extended grep here and no end $SEP! + grep ".*${SEP}.*${SEP}.*${SEP}.*${SEP}${ID_NEEDLE}" ${HC_LOG} 2>/dev/null |\ + ${SORT_CMD} | while read -r REPORT_LINE + do + FAIL_F1=$(print "${REPORT_LINE}" | cut -f1 -d"${SEP}") + FAIL_F2=$(print "${REPORT_LINE}" | cut -f2 -d"${SEP}") + FAIL_F3=$(print "${REPORT_LINE}" | cut -f4 -d"${SEP}") + FAIL_F4=$(print "${REPORT_LINE}" | cut -f5 -d"${SEP}") + + printf "| %-20s | %-14s | %-30s | %-s\n" \ + "${FAIL_F1}" "${FAIL_F4}" "${FAIL_F2}" "${FAIL_F3}" + done + + printf "\n%-s\n" "SUMMARY: ${FAIL_COUNT} failed HC event(s) found." + else + # print failed events (we may have multiple events for 1 FAIL ID) + EVENT_COUNT=1 + DIR_PREFIX="$(expr substr ${ARG_FAIL_ID} 1 4)-$(expr substr ${ARG_FAIL_ID} 5 2)" + # no extended grep here! + grep ".*${SEP}.*${SEP}.*${SEP}.*${SEP}${ID_NEEDLE}${SEP}" ${HC_LOG} 2>/dev/null |\ + ${SORT_CMD} | while read -r REPORT_LINE + do + FAIL_F1=$(print "${REPORT_LINE}" | cut -f1 -d"${SEP}") + FAIL_F2=$(print "${REPORT_LINE}" | cut -f2 -d"${SEP}") + FAIL_F3=$(print "${REPORT_LINE}" | cut -f4 -d"${SEP}") + + printf "%36sMSG #%03d%36s" "" ${EVENT_COUNT} "" | tr ' ' - + printf "\nTime : %-s\nHC : %-s\nDetail : %-s\n" \ + "${FAIL_F1}" "${FAIL_F2}" "${FAIL_F3}" + EVENT_COUNT=$(( EVENT_COUNT + 1 )) + done + + printf "%37sSTDOUT%37s\n" | tr ' ' -; + # display non-empty STDOUT file(s) + if [[ -n "$(du -a ${EVENTS_DIR}/${DIR_PREFIX}/${ARG_FAIL_ID}/*.stdout.log 2>/dev/null | awk '$1*512 > 0 {print $2}')" ]] + then + cat ${EVENTS_DIR}/${DIR_PREFIX}/${ARG_FAIL_ID}/*.stdout.log + else + printf "%-s\n" "No STDOUT found" + fi + + printf "%37sSTDERR%37s\n" | tr ' ' -; + # display non-empty STDERR file(s) + if [[ -n "$(du -a ${EVENTS_DIR}/${DIR_PREFIX}/${ARG_FAIL_ID}/*.stderr.log 2>/dev/null | awk '$1*512 > 0 {print $2}')" ]] + then + cat ${EVENTS_DIR}/${DIR_PREFIX}/${ARG_FAIL_ID}/*.stderr.log + else + printf "%-s\n" "No STDERR found" + fi + + printf "%80s\n" | tr ' ' - + fi + else + printf "\n%-s\n" "SUMMARY: 0 failed HC events found." + fi + fi + ;; + 9) # list HC plugins + list_hc "" "${ARG_LIST}" + ;; +esac + +# finish up work +do_cleanup + +exit ${EXIT_CODE} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/core/display_csv.sh b/sources/lib/core/display_csv.sh new file mode 100644 index 0000000..afffc83 --- /dev/null +++ b/sources/lib/core/display_csv.sh @@ -0,0 +1,100 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) display_csv.sh +#****************************************************************************** +# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: display_csv +# DOES: display HC results in CSV format (semi-colon as separator) +# EXPECTS: 1=HC name [string], 2=HC FAIL_ID [string] +# RETURNS: 0 +# REQUIRES: init_hc() +# +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function display_csv +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _VERSION="2017-05-06" # YYYY-MM-DD +typeset _SUPPORTED_PLATFORMS="AIX,HP-UX,Linux" # uname -s match +typeset _SEP=";" +# ------------------------- CONFIGURATION ends here --------------------------- + +# set defaults +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}" +init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}" + +typeset _DISPLAY_HC="$1" +typeset _DISPLAY_FAIL_ID="$2" + +set -A _DISPLAY_MSG_STC +set -A _DISPLAY_MSG_TIME +set -A _DISPLAY_MSG_TEXT +set -A _DISPLAY_MSG_CUR_VAL +set -A _DISPLAY_MSG_EXP_VAL +typeset _I=0 +typeset _MAX_I=0 +typeset _ID_BIT="" + +# read HC_MSG_FILE into an arrays +# note: this is less efficient but provides more flexibility for future extensions +# max array size: 1023 in ksh88f, plugins spawning more than >1K messages are crazy :-) +while read HC_MSG_ENTRY +do + _DISPLAY_MSG_STC[${_I}]=$(print "${HC_MSG_ENTRY}" | awk -F "%%" '{ print $1'}) + _DISPLAY_MSG_TIME[${_I}]=$(print "${HC_MSG_ENTRY}" | awk -F "%%" '{ print $2'}) + _DISPLAY_MSG_TEXT[${_I}]=$(print "${HC_MSG_ENTRY}" | awk -F "%%" '{ print $3'}) + _DISPLAY_MSG_CUR_VAL[${_I}]=$(print "${HC_MSG_ENTRY}" | awk -F "%%" '{ print $4'}) + _DISPLAY_MSG_EXP_VAL[${_I}]=$(print "${HC_MSG_ENTRY}" | awk -F "%%" '{ print $5'}) + _I=$(( _I + 1 )) +done <${HC_MSG_FILE} 2>/dev/null + +# display HC results +_MAX_I=${#_DISPLAY_MSG_STC[*]} +_I=0 +if (( _MAX_I > 0 )) +then + printf "%s${_SEP}%s${_SEP}%s${_SEP}%s${_SEP}%s${_SEP}%s\n" "Health Check" "STC" "Message" "FAIL ID" \ + "Current Value" "Expected Value" + while (( _I < _MAX_I )) + do + if (( _DISPLAY_MSG_STC[${_I}] != 0 )) + then + _ID_BIT="${_DISPLAY_FAIL_ID}" + else + _ID_BIT="" + fi + printf "%s${_SEP}%s${_SEP}%s${_SEP}%s${_SEP}%s${_SEP}%s\n" \ + "${_DISPLAY_HC}" \ + "${_DISPLAY_MSG_STC[${_I}]}" \ + "${_ID_BIT}" \ + "${_DISPLAY_MSG_TEXT[${_I}]}" \ + "${_DISPLAY_MSG_CUR_VAL[${_I}]}" \ + "${_DISPLAY_MSG_EXP_VAL[${_I}]}" + _I=$(( _I + 1 )) + done +else + ARG_LOG=0 ARG_VERBOSE=1 log "INFO: no HC results to display" +fi + +return 0 +} + +#****************************************************************************** +# END of script +#************************************************************************** diff --git a/sources/lib/core/display_init.sh b/sources/lib/core/display_init.sh new file mode 100644 index 0000000..f97a264 --- /dev/null +++ b/sources/lib/core/display_init.sh @@ -0,0 +1,151 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) display_init.sh +#****************************************************************************** +# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: display_init +# DOES: display HC results as boot/init-style messages (coloured stati) +# EXPECTS: 1=HC name [string], 2=HC FAIL_ID [string], +# 3=display code [string] (optional) +# RETURNS: 0 +# REQUIRES: init_hc() +# +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function display_init +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _VERSION="2017-06-29" # 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 _DISPLAY_HC="$1" +typeset _DISPLAY_FAIL_ID="$2" +typeset _DISPLAY_MSG_CODE="$3" + +typeset _DISPLAY_MSG_STC=0 +typeset _DISPLAY_HC_DESC="" +typeset _DISPLAY_CFG="" +typeset _DISPLAY_COLOR="" +typeset -R8 _DISPLAY_CODE="" +typeset _DISPLAY_ID="" + +# check for terminal support (no ((...)) here) +if [[ $(tput colors 2>/dev/null) -gt 0 ]] +then + typeset _RED=$(tput setaf 1) + typeset _GREEN=$(tput setaf 2) + typeset _YELLOW=$(tput setaf 3) + typeset _BLUE=$(tput setaf 4) + typeset _MAGENTA=$(tput setaf 5) + typeset _CYAN=$(tput setaf 6) + typeset _WHITE=$(tput setaf 7) + typeset _BOLD=$(tput bold) + typeset _NORMAL=$(tput sgr0) +else + typeset _RED="" + typeset _GREEN="" + typeset _YELLOW="" + typeset _BLUE="" + typeset _MAGENTA="" + typeset _CYAN="" + typeset _WHITE="" + typeset _BOLD="" + typeset _NORMAL="" +fi + +# read HC_MSG_FILE for STC +if [[ -n "${_DISPLAY_MSG_CODE}" ]] +then + case "${_DISPLAY_MSG_CODE}" in + ERROR|error) + _DISPLAY_COLOR="${_MAGENTA}" + ;; + DISABLED|disabled) + _DISPLAY_COLOR="${_CYAN}" + ;; + MISSING|missing) + _DISPLAY_COLOR="${_BLUE}" + ;; + *) + _DISPLAY_COLOR="" + ;; + esac + _DISPLAY_CODE="${_DISPLAY_MSG_CODE}" +else + if [[ -s ${HC_MSG_FILE} ]] + then + while read HC_MSG_ENTRY + do + _DISPLAY_MSG_STC=$(( $(print "${HC_MSG_ENTRY}" | awk -F "%%" '{ print $1'}) + _DISPLAY_MSG_STC )) + done <${HC_MSG_FILE} 2>/dev/null + + # display HC results + if (( _DISPLAY_MSG_STC == 0 )) + then + _DISPLAY_CODE="OK" + _DISPLAY_COLOR="${_GREEN}" + else + _DISPLAY_CODE="FAIL" + _DISPLAY_COLOR="${_RED}" + # check if we have a valid FAIL_ID + if (( ARG_LOG == 1 )) + then + _DISPLAY_ID=" (${_BOLD}${_DISPLAY_FAIL_ID}${_NORMAL})" + else + _DISPLAY_ID=" (${_BOLD}not logged${_NORMAL})" + fi + fi + else + _DISPLAY_CODE="UNKNOWN" + _DISPLAY_COLOR="${_YELLOW}" + fi +fi + +# check for alternative description, mangle _DISPLAY_HC +_DISPLAY_HC_DESC=$(grep -i "^hc:${HC_RUN}:" ${HOST_CONFIG_FILE} 2>/dev/null | cut -f4 -d':') +[[ -n "${_DISPLAY_HC_DESC}" ]] && _DISPLAY_HC="${_DISPLAY_HC_DESC}" + +# check for alternative configuration file +if [[ -n "${ARG_CONFIG_FILE}" ]] +then + # file name only + _DISPLAY_CFG="${ARG_CONFIG_FILE##*/}" +else + _DISPLAY_CFG="default config" +fi + +# print status line (but also check for terminal support) + +printf "%-30s %50s\t[ %8s ]%s\n" \ + "${_DISPLAY_HC}" \ + "(${_DISPLAY_CFG})" \ + "${_DISPLAY_COLOR}${_DISPLAY_CODE}${_NORMAL}" \ + "${_DISPLAY_ID}" + +return 0 +} + +#****************************************************************************** +# END of script +#************************************************************************** diff --git a/sources/lib/core/display_terse.sh b/sources/lib/core/display_terse.sh new file mode 100644 index 0000000..34e5519 --- /dev/null +++ b/sources/lib/core/display_terse.sh @@ -0,0 +1,96 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) display_terse.sh +#****************************************************************************** +# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: display_terse +# DOES: display HC results in a terse way +# EXPECTS: 1=HC name [string], 2=HC FAIL_ID [string] +# RETURNS: 0 +# REQUIRES: init_hc() +# +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function display_terse +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _VERSION="2017-05-06" # 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 _DISPLAY_HC="$1" +typeset _DISPLAY_FAIL_ID="$2" + +set -A _DISPLAY_MSG_STC +set -A _DISPLAY_MSG_TIME +set -A _DISPLAY_MSG_TEXT +typeset _I=0 +typeset _MAX_I=0 +typeset _ID_BIT="" + +# read HC_MSG_FILE into an arrays +# note: this is less efficient but provides more flexibility for future extensions +# max array size: 1023 in ksh88f, plugins spawning more than >1K messages are crazy :-) +while read HC_MSG_ENTRY +do + _DISPLAY_MSG_STC[${_I}]=$(print "${HC_MSG_ENTRY}" | awk -F "%%" '{ print $1'}) + _DISPLAY_MSG_TIME[${_I}]=$(print "${HC_MSG_ENTRY}" | awk -F "%%" '{ print $2'}) + _DISPLAY_MSG_TEXT[${_I}]=$(print "${HC_MSG_ENTRY}" | awk -F "%%" '{ print $3'}) + _I=$(( _I + 1 )) +done <${HC_MSG_FILE} 2>/dev/null + +# display HC results +_MAX_I=${#_DISPLAY_MSG_STC[*]} +_I=0 +if (( _MAX_I > 0 )) +then + printf "%-30s\t%s\t%-16s\t%s\n" "HC" "STC" "FAIL ID" "Message" + while (( _I < _MAX_I )) + do + if (( _DISPLAY_MSG_STC[${_I}] != 0 )) + then + _ID_BIT="${_DISPLAY_FAIL_ID}" + else + _ID_BIT="" + fi + printf "%-30s\t%s\t%-16s\t%s\n" \ + "${_DISPLAY_HC}" \ + "${_DISPLAY_MSG_STC[${_I}]}" \ + "${_ID_BIT}" \ + "${_DISPLAY_MSG_TEXT[${_I}]}" + _I=$(( _I + 1 )) + done +else + ARG_LOG=0 ARG_VERBOSE=1 log "INFO: no HC results to display" +fi + +# notice of other messages +print +ARG_LOG=0 ARG_VERBOSE=1 log "all other messages have been suppressed (except fatal errors)" + +return 0 +} + +#****************************************************************************** +# END of script +#************************************************************************** diff --git a/sources/lib/core/include_core.sh b/sources/lib/core/include_core.sh new file mode 100644 index 0000000..3b4fe62 --- /dev/null +++ b/sources/lib/core/include_core.sh @@ -0,0 +1,910 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) include_core.sh +#****************************************************************************** +# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: include_core +# DOES: helper functions +# +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: debug() +# DOES: handle debug messages +# EXPECTS: log message [string] +# RETURNS: 0 +# REQUIRES: n/a +function debug +{ +typeset LOG_LINE="" + +print - "$*" | while read -r LOG_LINE +do + print -u2 "DEBUG: ${LOG_LINE}" +done + +return 0 +} + + +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: die() +# DOES: handle fatal errors and exit script +# EXPECTS: log message [string] +# RETURNS: 0 +# REQUIRES: n/a +function die +{ +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}" +typeset NOW="$(date '+%d-%h-%Y %H:%M:%S')" +typeset LOG_LINE="" + +if [[ -n "$1" ]] +then + if (( ARG_LOG != 0 )) + then + print - "$*" | while read -r LOG_LINE + do + print "${NOW}: ERROR: [$$]:" "${LOG_LINE}" >>${LOG_FILE} + done + fi + print - "$*" | while read -r LOG_LINE + do + print -u2 "ERROR:" "${LOG_LINE}" + done +fi + +# finish up work +do_cleanup + +exit 1 +} + +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: discover_core() +# DOES: discover core plugins +# EXPECTS: n/a +# RETURNS: 0 +# REQUIRES: die() +function discover_core +{ +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}" +typeset NOTIFY_OPTS="" + +# init global flags for core plugins (no typeset!) +DO_DISPLAY_CSV=0 +DO_DISPLAY_INIT=0 +DO_DISPLAY_TERSE=0 +DO_NOTIFY_EIF=0 +DO_NOTIFY_MAIL=0 +DO_NOTIFY_SMS=0 +HAS_DISPLAY_CSV=0 +HAS_DISPLAY_INIT=0 +HAS_DISPLAY_TERSE=0 +HAS_NOTIFY_EIF=0 +HAS_NOTIFY_MAIL=0 +HAS_NOTIFY_SMS=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) +for FFILE in $(ls -1 ${FPATH_PARENT}/core/*.sh 2>/dev/null | grep -v "include_" 2>/dev/null) +do + case "${FFILE}" in + *display_csv.sh) + HAS_DISPLAY_CSV=1 + (( ARG_DEBUG != 0 )) && debug "display_csv plugin is available" + ;; + *display_init.sh) + HAS_DISPLAY_INIT=1 + (( ARG_DEBUG != 0 )) && debug "display_init plugin is available" + ;; + *display_terse.sh) + HAS_DISPLAY_TERSE=1 + (( ARG_DEBUG != 0 )) && debug "display_terse plugin is available" + ;; + *notify_mail.sh) + HAS_NOTIFY_MAIL=1 + (( ARG_DEBUG != 0 )) && debug "notify_mail plugin is available" + ;; + *notify_sms.sh) + HAS_NOTIFY_SMS=1 + (( ARG_DEBUG != 0 )) && debug "notify_sms plugin is available" + ;; + *notify_eif.sh) + HAS_NOTIFY_EIF=1 + (( ARG_DEBUG != 0 )) && debug "notify_eif plugin is available" + ;; + esac +done + +# check command-line parameters for core plugins +# --display +if [[ -n "${ARG_DISPLAY}" ]] +then + case "${ARG_DISPLAY}" in + csv) # csv format + if (( HAS_DISPLAY_CSV == 1 )) + then + DO_DISPLAY_CSV=1 + ARG_VERBOSE=0 + else + warn "csv plugin for '--display' not present" + fi + ;; + init) # init/boot format + if (( HAS_DISPLAY_INIT == 1 )) + then + DO_DISPLAY_INIT=1 + ARG_VERBOSE=0 + else + warn "init plugin for '--display' not present" + fi + ;; + terse) # terse format + if (( HAS_DISPLAY_TERSE == 1 )) + then + DO_DISPLAY_TERSE=1 + ARG_VERBOSE=0 + else + warn "terse plugin for '--display' not present" + fi + ;; + *) # stdout default + ;; + esac +fi +# --notify +if [[ -n "${ARG_NOTIFY}" ]] +then + # 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) + for NOTIFY_OPTS in $(print "${ARG_NOTIFY}" | tr ',' ' ' 2>/dev/null) + do + case "${NOTIFY_OPTS}" in + *eif*) # by ITM + DO_NOTIFY_EIF=1 + ;; + *mail*) # by mail + DO_NOTIFY_MAIL=1 + ;; + *sms*) # by sms + DO_NOTIFY_SMS=1 + ;; + *) # no valid option + die "you have specified an invalid option for '--notify'" + ;; + esac + done +fi +# --mail-to/--notify +if [[ -n "${ARG_MAIL_TO}" ]] && (( DO_NOTIFY_MAIL == 0 )) +then + die "you cannot specify '--mail-to' without '--notify=mail'" +fi +if (( DO_NOTIFY_MAIL != 0 )) && [[ -z "${ARG_MAIL_TO}" ]] +then + die "you cannot specify '--notify=mail' without '--mail-to'" +fi +# --sms-to/--sms-provider/--notify +if [[ -n "${ARG_SMS_TO}" ]] && (( DO_NOTIFY_SMS == 0 )) +then + die "you cannot specify '--sms-to' without '--notify=sms'" +fi +if [[ -n "${ARG_SMS_PROVIDER}" ]] && (( DO_NOTIFY_SMS == 0 )) +then + die "you cannot specify '--sms-provider' without '--notify=sms'" +fi +if (( DO_NOTIFY_SMS != 0 )) && [[ -z "${ARG_SMS_TO}" ]] +then + die "you cannot specify '--notify=sms' without '--sms-to'" +fi +if (( DO_NOTIFY_SMS != 0 )) && [[ -z "${ARG_SMS_PROVIDER}" ]] +then + die "you cannot specify '--notify=sms' without '--sms-provider'" +fi + +return 0 +} + +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: exists_hc() +# DOES: check if a HC (function) exists in $FPATH +# EXPECTS: health check name [string] +# RETURNS: 0=HC not found; 1=HC found +# REQUIRES: n/a +function exists_hc +{ +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}" +typeset EXISTS_HC="$1" +typeset FDIR="" +typeset EXISTS_RC=0 + +# 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) +for FDIR in $(print "${FPATH}" | tr ':' ' ' 2>/dev/null) +do + $(data_contains_string "${FDIR}" "core") + if (( $? == 0 )) + then + ls "${FDIR}/${EXISTS_HC}" >/dev/null 2>&1 && EXISTS_RC=1 + fi +done + +return ${EXISTS_RC} +} + +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: find_hc() +# DOES: find location of a HC (function) in $FPATH +# EXPECTS: health check name [string] +# RETURNS: file location [string] +# REQUIRES: n/a +function find_hc +{ +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}" +typeset FIND_HC="$1" +typeset FIND_PATH="" +typeset FDIR="" + +print "${FPATH}" | tr ':' '\n' | grep -v "core$" | while read -r FDIR +do + ls "${FDIR}/${FIND_HC}" >/dev/null 2>&1 && print "${FDIR}/${FIND_HC}" +done + +return 0 +} + +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: handle_hc() +# DOES: handle HC results +# EXPECTS: 1=HC name [string], $HC_MSG_FILE temporary file +# RETURNS: 0 +# REQUIRES: die(), display_csv(), display_terse(), notify_mail(), notify_sms(), +# notify_eif(), warn() +function handle_hc +{ +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}" +typeset HC_NAME="$1" +typeset HC_STC_COUNT=0 +typeset I=0 +typeset MAX_I=0 +typeset HC_STDOUT_LOG_SHORT="" +typeset HC_STDERR_LOG_SHORT="" +set -A HC_MSG_STC +set -A HC_MSG_TIME +set -A HC_MSG_TEXT +set -A HC_MSG_CUR_VAL # optional +set -A HC_MSG_EXP_VAL # optional + +if [[ -s ${HC_MSG_FILE} ]] +then + # DEBUG: dump TMP file + if (( ARG_DEBUG != 0 )) + then + debug "begin dumping plugin messages file (${HC_MSG_FILE})" + cat ${HC_MSG_FILE} 2>/dev/null + debug "end dumping plugin messages file (${HC_MSG_FILE})" + fi + + # process message file into arrays + while read HC_MSG_ENTRY + do + HC_MSG_STC[${I}]=$(print "${HC_MSG_ENTRY}" | awk -F "%%" '{ print $1'}) + HC_MSG_TIME[${I}]=$(print "${HC_MSG_ENTRY}" | awk -F "%%" '{ print $2'}) + HC_MSG_TEXT[${I}]=$(print "${HC_MSG_ENTRY}" | awk -F "%%" '{ print $3'}) + + HC_MSG_CUR_VAL[${I}]=$(print "${HC_MSG_ENTRY}" | awk -F "%%" '{ print $4'}) + HC_MSG_EXP_VAL[${I}]=$(print "${HC_MSG_ENTRY}" | awk -F "%%" '{ print $5'}) + I=$(( I + 1 )) + done <${HC_MSG_FILE} 2>/dev/null +fi + +# display routines +if (( ${#HC_MSG_STC[*]} > 0 )) +then + if (( DO_DISPLAY_CSV == 1 )) + then + if (( HAS_DISPLAY_CSV == 1 )) + then + # call plugin + display_csv "${HC_NAME}" "${HC_FAIL_ID}" + else + warn "display_csv plugin is not avaible, cannot display_results!" + fi + elif (( DO_DISPLAY_INIT == 1 )) + then + if (( HAS_DISPLAY_INIT == 1 )) + then + # call plugin + display_init "${HC_NAME}" "${HC_FAIL_ID}" + else + warn "display_init plugin is not avaible, cannot display_results!" + fi + elif (( DO_DISPLAY_TERSE == 1 )) + then + if (( HAS_DISPLAY_TERSE == 1 )) + then + # call plugin + display_terse "${HC_NAME}" "${HC_FAIL_ID}" + else + warn "display_terse plugin is not avaible, cannot display_results!" + fi + else + # default STDOUT + if (( ARG_VERBOSE != 0 )) + then + I=0 + MAX_I=${#HC_MSG_STC[*]} + while (( I < MAX_I )) + do + printf "%s" "INFO: ${HC_NAME} [STC=${HC_MSG_STC[${I}]}]: ${HC_MSG_TEXT[${I}]}" + if (( HC_MSG_STC[${I}] != 0 )) + then + printf " %s\n" "[FAIL_ID=${HC_FAIL_ID}]" + else + printf "\n" + fi + I=$(( I + 1 )) + done + fi + fi +fi + +# log & notify routines +if (( ARG_LOG != 0 )) && (( ${#HC_MSG_STC[*]} > 0 )) +then + # log routine (combined STC=0 or <>0) + I=0 + MAX_I=${#HC_MSG_STC[*]} + while (( I < MAX_I )) + do + printf "%s${SEP}%s${SEP}%s${SEP}%s${SEP}" \ + "${HC_MSG_TIME[${I}]}" \ + "${HC_NAME}" \ + ${HC_MSG_STC[${I}]} \ + "${HC_MSG_TEXT[${I}]}" >>${HC_LOG} + if (( HC_MSG_STC[${I}] != 0 )) + then + printf "%s${SEP}\n" "${HC_FAIL_ID}" >>${HC_LOG} + else + printf "\n" >>${HC_LOG} + fi + HC_STC_COUNT=$(( HC_STC_COUNT + HC_MSG_STC[${I}] )) + I=$(( I + 1 )) + done + + # notify routine (combined STC > 0) + if (( HC_STC_COUNT > 0 )) + then + # save stdout/stderr to HC events location + if [[ -s ${HC_STDOUT_LOG} ]] || [[ -s ${HC_STDERR_LOG} ]] + then + # organize logs in sub-directories: YYYY/MM + mkdir -p "${EVENTS_DIR}/${DIR_PREFIX}/${HC_FAIL_ID}" >/dev/null 2>&1 || \ + die "failed to create event directory at $1" + if [[ -f ${HC_STDOUT_LOG} ]] + 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 || \ + 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 || \ + die "failed to move ${HC_STDERR_LOG} to event directory at $1" + fi + fi + + # notify if needed (i.e. when we have HC failures) + # by mail? + if (( DO_NOTIFY_MAIL == 1 )) + then + if (( HAS_NOTIFY_MAIL == 1 )) + then + # call plugin (pick up HC failure/stdout/stderr files in notify_mail()) + notify_mail "${HC_NAME}" "${HC_FAIL_ID}" + else + warn "notify_mail plugin is not avaible, cannot send alert via e-mail!" + fi + fi + # by sms? + if (( DO_NOTIFY_SMS == 1 )) + then + if (( HAS_NOTIFY_SMS == 1 )) + then + # call plugin + notify_sms "${HC_NAME}" "${HC_FAIL_ID}" + else + warn "notify_sms plugin is not avaible, cannot send alert via sms!" + fi + fi + # by EIF? + if (( DO_NOTIFY_EIF == 1 )) + then + if (( HAS_NOTIFY_EIF == 1 )) + then + # call plugin + notify_eif "${HC_NAME}" "${HC_FAIL_ID}" + else + warn "notify_sms plugin is not avaible, cannot send alert via sms!" + fi + fi + fi +fi + +return 0 +} + +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: handle_timeout() +# DOES: kill long running background jobs +# EXPECTS: ${CHILD_PID} to be populated +# RETURNS: 0 +# REQUIRES: warn() +function handle_timeout +{ +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}" +[[ -n "${CHILD_PID}" ]] && kill -s TERM ${CHILD_PID} +warn "child process with PID ${CHILD_PID} has been forcefully stopped" +CHILD_ERROR=1 + +return 0 +} + +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: init_check_host +# DOES: init full host check +# EXPECTS: n/a +# RETURNS: 0 +# REQUIRES: die() +function init_check_host +{ +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}" +typeset DUMMY="" +typeset HC_CONFIG="" +typeset HC_DESC="" +typeset HC_EXEC="" +typeset REPORT_STYLE="" + +[[ -r ${HOST_CONFIG_FILE} ]] || die "unable to read configuration file at ${HOST_CONFIG_FILE}" + +# read required config values +REPORT_STYLE="$(grep -i '^report_style=' ${HOST_CONFIG_FILE} | cut -f2 -d'=' | tr -d '\"')" +case "${REPORT_STYLE}" in + csv|CSV) # csv format + if (( HAS_DISPLAY_CSV == 1 )) + then + DO_DISPLAY_CSV=1 + ARG_VERBOSE=0 + fi + ;; + terse|TERSE) # terse format + if (( HAS_DISPLAY_TERSE == 1 )) + then + DO_DISPLAY_TERSE=1 + ARG_VERBOSE=0 + fi + ;; + *) # init/boot default, stdout fallback + if (( HAS_DISPLAY_INIT == 1 )) + then + DO_DISPLAY_INIT=1 + ARG_VERBOSE=0 + else + ARG_VERBOSE=1 + warn "default boot/init display plugin not present" + fi +esac + +# mangle $ARG_HC to build the full list of HCs to be executed +ARG_HC="" +grep -i '^hc:' ${HOST_CONFIG_FILE} 2>/dev/null |\ + while IFS=':' read DUMMY HC_EXEC HC_CONFIG HC_DESC +do + ARG_HC="${ARG_HC},${HC_EXEC}" +done + +return 0 +} + +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: init_hc +# DOES: init routines for HC/core plugins +# EXPECTS: 1=HC name [string], 2=list of platforms [string], 3=HC version [string] +# RETURNS: 0 +# REQUIRES: die() +function init_hc +{ +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}" +typeset HC_PLATFORMS="$2" +typeset HC_VERSION="$3" +typeset HC_OK=0 + +# check platform (don't use a pattern comparison here (~! mksh/pdksh)) +HC_OK=$(print "${HC_PLATFORMS}" | grep -c "${OS_NAME}" 2>/dev/null) +(( HC_OK != 0 )) || die "may only run on platform(s): ${HC_PLATFORMS}" + +# check version of HC plugin +case "${HC_VERSION}" in + [0-2][0-9][0-9][0-9]-[0-1][0-9]-[0-3][0-9]) + # OK + (( ARG_DEBUG != 0 )) && debug "HC plugin $1 has version ${HC_VERSION}" + ;; + *) + die "version of the HC plugin $1 is not in YYYY-MM-DD format (${HC_VERSION})" + ;; +esac + +return 0 +} + +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: is_scheduled() +# DOES: check if a HC is scheduled in a cron +# EXPECTS: health check name [string] +# RETURNS: 0=HC not scheduled; <>0=HC is scheduled +# REQUIRES: n/a +function is_scheduled +{ +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}" +typeset CRON_HC="$1" +typeset CRON_COUNT=0 +typeset CRON_SYS_LOCATIONS='/etc/crontab /etc/cron.d/*' +typeset CRON_ANACRON_LOCATIONS='/etc/anacrontab /etc/cron.*' + +# check for a scheduled job +case "${OS_NAME}" in + "Linux") + # check default root crontab + CRON_COUNT=$(crontab -l 2>/dev/null | grep -c -E -e "^[^#].*${CRON_HC}" 2>/dev/null) + # check system crontabs + if (( CRON_COUNT == 0 )) + then + 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 + 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 + +return ${CRON_COUNT} +} + +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: list_core() +# DOES: find HC core plugins +# EXPECTS: action identifier [string] +# RETURNS: 0 +# REQUIRES: n/a +function list_core +{ +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}" +typeset FACTION="$1" +typeset FCONFIG="" +typeset FDIR="" +typeset FNAME="" +typeset FVERSION="" +typeset FCONFIG="" +typeset FSTATE="enabled" # default +typeset FFILE="" +typeset HAS_FCONFIG=0 +typeset HC_VERSION="" + +# print header +if [[ "${FACTION}" != "list" ]] +then + printf "%-30s\t%-8s\t%s\t\t%s\n" "Core plugin" "State" "Version" "Config?" + printf "%80s\n" | tr ' ' - +fi +print "${FPATH}" | tr ':' '\n' | grep "core$" | sort 2>/dev/null | while read -r FDIR +do + # exclude core helper librar(y|ies) + ls -1 ${FDIR}/*.sh 2>/dev/null | grep -v "include_" | sort 2>/dev/null | while read -r FFILE + do + # find function name but skip helper functions in the plug-in file (function _name) + FNAME=$(grep -E -e "^function[[:space:]]+[^_]" "${FFILE}" 2>&1) + # look for version string (cut off comments but don't use [:space:] in tr) + FVERSION=$(grep '^typeset _VERSION=' "${FFILE}" 2>&1 | tr -d '\"' | tr -d ' \t' | cut -f1 -d'#' | cut -f2 -d'=') + # look for configuration file string + HAS_FCONFIG=$(grep -c '^typeset _CONFIG_FILE=' "${FFILE}" 2>&1) + if (( HAS_FCONFIG != 0 )) + then + FCONFIG="Yes" + else + FCONFIG="No" + fi + # check state (only for unlinked) + [[ -h ${FFILE%%.*} ]] || FSTATE="unlinked" + + # show results + if [[ "${FACTION}" != "list" ]] + then + printf "%-30s\t%-8s\t%s\t%s\n" \ + "${FNAME#function *}" \ + "${FSTATE}" \ + "${FVERSION#typeset _VERSION=*}" \ + "${FCONFIG}" + else + printf "%s\n" "${FNAME#function *}" + fi + done +done + +# dead link detection +if [[ "${FACTION}" != "list" ]] +then + print + print -n "Dead links: " + print "${FPATH}" | tr ':' '\n' | grep "core$" | while read -r FDIR + do + # do not use 'find -type l' here! + ls ${FDIR} 2>/dev/null | grep -v "\." | while read -r FFILE + do + if [[ -h "${FDIR}/${FFILE}" ]] && [[ ! -f "${FDIR}/${FFILE}" ]] + then + printf "%s " ${FFILE##*/} + fi + done + done + print + + # show FPATH + print + print "current FPATH: ${FPATH}" +fi + +return 0 +} + +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: list_hc() +# DOES: find HC plugins/functions +# EXPECTS: action identifier [string] +# RETURNS: 0 +# REQUIRES: is_scheduled() +function list_hc +{ +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}" +typeset FACTION="$1" +typeset FNEEDLE="$2" +typeset FCONFIG="" +typeset FDIR="" +typeset FNAME="" +typeset FVERSION="" +typeset FCONFIG="" +typeset FSTATE="" +typeset FFILE="" +typeset HAS_FCONFIG=0 +typeset FSCHEDULED=0 +typeset DISABLE_FFILE="" +typeset HC_VERSION="" + +# build search needle +if [[ -z "${ARG_LIST}" ]] +then + FNEEDLE="*.sh" +else + FNEEDLE="${ARG_LIST}.sh" +fi + +# print header +if [[ "${FACTION}" != "list" ]] +then + printf "%-30s\t%-8s\t%s\t\t%s\t%s\n" "Health Check" "State" "Version" "Config?" "Sched?" + printf "%80s\n" | tr ' ' - +fi +print "${FPATH}" | tr ':' '\n' | grep -v "core$" | sort 2>/dev/null | while read -r FDIR +do + ls -1 ${FDIR}/${FNEEDLE} 2>/dev/null | sort 2>/dev/null | while read -r FFILE + do + # find function name but skip helper functions in the plug-in file (function _name) + FNAME=$(grep -E -e "^function[[:space:]]+[^_]" "${FFILE}" 2>&1) + # look for version string (cut off comments but don't use [:space:] in tr) + FVERSION=$(grep '^typeset _VERSION=' "${FFILE}" 2>&1 | tr -d '\"' | tr -d ' \t' | cut -f1 -d'#' | cut -f2 -d'=') + # look for configuration file string + HAS_FCONFIG=$(grep -c '^typeset _CONFIG_FILE=' "${FFILE}" 2>&1) + if (( HAS_FCONFIG != 0 )) + then + FCONFIG="Yes" + else + FCONFIG="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 + [[ -h ${FFILE%%.*} ]] || FSTATE="unlinked" + # check scheduling + is_scheduled "${FNAME#function *}" + if (( $? == 0 )) + then + FSCHEDULED="No" + else + FSCHEDULED="Yes" + fi + + # show results + if [[ "${FACTION}" != "list" ]] + then + printf "%-30s\t%-8s\t%s\t%s\t%s\n" \ + "${FNAME#function *}" \ + "${FSTATE}" \ + "${FVERSION#typeset _VERSION=*}" \ + "${FCONFIG}" \ + "${FSCHEDULED}" + else + printf "%s\n" "${FNAME#function *}" + fi + done +done + +# dead link detection +if [[ "${FACTION}" != "list" ]] +then + print + print -n "Dead links: " + print "${FPATH}" | tr ':' '\n' | grep -v "core" | while read -r FDIR + do + # do not use 'find -type l' here! + ls ${FDIR} 2>/dev/null | grep -v "\." | while read -r FFILE + do + if [[ -h "${FDIR}/${FFILE}" ]] && [[ ! -f "${FDIR}/${FFILE}" ]] + then + printf "%s " ${FFILE##*/} + fi + done + done + print + + # show FPATH + print + print "current FPATH: ${FPATH}" +fi + +return 0 +} + +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: log() +# DOES: handle messages +# EXPECTS: log message [string] +# RETURNS: 0 +# REQUIRES: n/a +function log +{ +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}" +typeset NOW="$(date '+%d-%h-%Y %H:%M:%S')" +typeset LOG_LINE="" + +if [[ -n "$1" ]] +then + if (( ARG_LOG != 0 )) + then + print - "$*" | while read -r LOG_LINE + do + print "${NOW}: INFO: [$$]:" "${LOG_LINE}" >>${LOG_FILE} + done + fi + if (( ARG_VERBOSE != 0 )) + then + print - "$*" | while read -r LOG_LINE + do + print "INFO:" "${LOG_LINE}" + done + fi +fi + +return 0 +} + +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: log_hc() +# DOES: log a HC plugin result +# EXPECTS: 1=HC name [string], 2=HC status code [integer], 3=HC message [string], +# 4=HC found value [string] (optional), +# 5=HC expected value [string] (optional) +# RETURNS: 0 +# REQUIRES: n/a +function log_hc +{ +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}" +typeset HC_NAME="$1" +typeset HC_STC=$2 +typeset HC_MSG="$3" +typeset HC_NOW="$(date '+%Y-%m-%d %H:%M:%S' 2>/dev/null)" +typeset HC_MSG_CUR_VAL="" +typeset HC_MSG_EXP_VAL="" + +# assign optional parameters +[[ -n "$4" ]] && HC_MSG_CUR_VAL=$(data_newline2hash "$4") +[[ -n "$5" ]] && HC_MSG_EXP_VAL=$(data_newline2hash "$5") + +# save the HC failure message for now +print "${HC_STC}%%${HC_NOW}%%${HC_MSG}%%${HC_MSG_CUR_VAL}%%${HC_MSG_EXP_VAL}" \ + >>${HC_MSG_FILE} + +return 0 +} + +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: stat_hc() +# DOES: retrieve status of a HC +# EXPECTS: HC name [string] +# RETURNS: 0=HC is disabled; 1=HC is enabled +# REQUIRES: n/a +function stat_hc +{ +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}" +typeset STAT_HC="$1" +typeset STAT_RC=1 # default: enabled + +[[ -f "${STATE_PERM_DIR}/${STAT_HC}.disabled" ]] && STAT_RC=0 + +return ${STAT_RC} +} + +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: warn() +# DOES: handle warnings +# EXPECTS: log message [string] +# RETURNS: 0 +# REQUIRES: n/a +function warn +{ +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}" +typeset NOW="$(date '+%d-%h-%Y %H:%M:%S')" +typeset LOG_LINE="" + +if [[ -n "$1" ]] +then + if (( ARG_LOG != 0 )) + then + print - "$*" | while read -r LOG_LINE + do + print "${NOW}: WARN: [$$]:" "${LOG_LINE}" >>${LOG_FILE} + done + fi + if (( ARG_VERBOSE != 0 )) + then + print - "$*" | while read -r LOG_LINE + do + print "WARN:" "${LOG_LINE}" + done + fi +fi + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/core/include_data.sh b/sources/lib/core/include_data.sh new file mode 100644 index 0000000..df9f61d --- /dev/null +++ b/sources/lib/core/include_data.sh @@ -0,0 +1,504 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) include_data.sh +#****************************************************************************** +# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: include_data +# DOES: helper functions for data (manipulation) +# +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: data_get_lvalue_from_config() +# DOES: get an lvalue from the configuration file +# EXPECTS: parameter to look for [string] +# OUTPUTS: parameter value [string] +# RETURNS: 0=found; 1=not found +# REQUIRES: n/a +function data_get_lvalue_from_config +{ +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}" +typeset _PARAMETER="${1}" +typeset _LVALUE="" +typeset _RC=0 + +_LVALUE=$(grep -i "^${_PARAMETER}=" ${_CONFIG_FILE} | cut -f2 -d'=') + +if [[ -n "${_LVALUE}" ]] +then + print $(data_dequote "${_LVALUE}") +else + _RC=1 +fi + +return ${_RC} +} + +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: data_chop() +# DOES: cut last character of input +# EXPECTS: string +# OUTPUTS: string with last character omitted +# RETURNS: 0 +# REQUIRES: n/a +function data_chop +{ +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}" + +print "${1%?}" + +return 0 +} + +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: data_contains_string() +# DOES: checks if a string (haystack) contains a substring (needle). +# EXPECTS: $1=haystack [string]; $2=needle [string] +# OUTPUTS: n/a +# RETURNS: 0=not found; 1=found +# REQUIRES: n/a +function data_contains_string +{ +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}" + +typeset _HAYSTACK="$1" +typeset _NEEDLE="$2" +typeset _RC=0 + +[[ "${_HAYSTACK#*${_NEEDLE}}" = "${_HAYSTACK}" ]] || _RC=1 + +return ${_RC} +} + +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: data_decomma() +# DOES: remove comma's +# EXPECTS: [string] with comma's +# OUTPUTS: [string] without comma's +# RETURNS: 0 +# REQUIRES: n/a +function data_decomma +{ +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}" + +print "${1}" | tr -d ',' 2>/dev/null + +return 0 +} + +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: data_decomma_last() +# DOES: remove last comma +# EXPECTS: [string] with a last comma +# OUTPUTS: [string] without last comma +# RETURNS: 0 +# REQUIRES: n/a +function data_decomma_last +{ +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}" + +print "${1%*,}" + +return 0 +} + +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: data_decomma_first() +# DOES: remove last comma +# EXPECTS: [string] with a last comma +# OUTPUTS: [string] without last comma +# RETURNS: 0 +# REQUIRES: n/a +function data_decomma_first +{ +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}" + +print "${1#,*}" + +return 0 +} + +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: data_dequote() +# DOES: remove quotes +# EXPECTS: quoted [string] +# OUTPUTS: de-quoted (both double and single, but not escaped) [string] +# RETURNS: 0 +# REQUIRES: n/a +function data_dequote +{ +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}" + +print "${1}" | tr -d '\"' 2>/dev/null | tr -d "'" 2>/dev/null + +return 0 +} + +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: data_comma2space() +# DOES: replace commas with a space +# EXPECTS: [string] with commas +# OUTPUTS: [string] with spaces +# RETURNS: 0 +# REQUIRES: n/a +function data_comma2space +{ +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}" + +print "${1}" | tr ',' ' ' 2>/dev/null + +return 0 +} + +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: data_comma2newline() +# DOES: replace commas with a space +# EXPECTS: [string] with commas +# OUTPUTS: [string] with newlines +# RETURNS: 0 +# REQUIRES: n/a +function data_comma2newline +{ +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}" + +print "${1}" | tr ',' '\n' 2>/dev/null + +return 0 +} + +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: data_newline2comma() +# DOES: replace newlines with a comma +# EXPECTS: [string] with newlines +# OUTPUTS: [string] with commas +# RETURNS: 0 +# REQUIRES: n/a +function data_newline2comma +{ +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}" + +print "${1}" | tr '\n' ',' 2>/dev/null + +return 0 +} + +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: data_newline2hash() +# DOES: replace newlines with a hash +# EXPECTS: [string] with newlines +# OUTPUTS: [string] with hashes +# RETURNS: 0 +# REQUIRES: n/a +function data_newline2hash +{ +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}" + +print "${1}" | tr '\n' '#' 2>/dev/null | tr '\r' '#' 2>/dev/null + +return 0 +} + +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: data_space2comma() +# DOES: replace spaces with a comma +# EXPECTS: [string] with spaces +# OUTPUTS: [string] with commas +# RETURNS: 0 +# REQUIRES: n/a +function data_space2comma +{ +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}" + +print "${1}" | tr -s ' ' 2>/dev/null | tr ' ' ',' 2>/dev/null + +return 0 +} + +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: data_space2hash() +# DOES: replace spaces with a hash +# EXPECTS: [string] with spaces +# OUTPUTS: [string] with hashes +# RETURNS: 0 +# REQUIRES: n/a +function data_space2hash +{ +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}" + +print "${1}" | tr -s ' ' 2>/dev/null | tr ' ' '#' 2>/dev/null + +return 0 +} + +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: data_strip_newline() +# DOES: remove newlines +# EXPECTS: [string] with newlines +# OUTPUTS: [string] without newlines +# RETURNS: 0 +# REQUIRES: n/a +function data_strip_newline +{ +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}" + +print "${1}" | tr -d '\n' 2>/dev/null | tr -d '\r' 2>/dev/null + +return 0 +} + +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: data_lc() +# DOES: switch to lower case +# EXPECTS: [string] +# OUTPUTS: lower case [string] +# RETURNS: 0 +# REQUIRES: n/a +function data_lc +{ +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}" + +print "${1}" | tr '[:upper:]' '[:lower:]' 2>/dev/null + +return 0 +} + +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: data_uc() +# DOES: switch to upper case +# EXPECTS: [string] +# OUTPUTS: upper case [string] +# RETURNS: 0 +# REQUIRES: n/a +function data_uc +{ +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}" + +print "${1}" | tr '[:lower:]' '[:upper:]' 2>/dev/null + +return 0 +} + +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: data_encode_url +# DOES: encode URL data +# EXPECTS: text to be encoded [string] +# OUTPUTS: encoded text [string] +# RETURNS: 0 +# REQUIRES: +# REFERENCE: added from http://www.shelldorado.com/scripts/cmds/urlencode +function data_encode_url +{ +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}" +typeset _EncodeEOL=0 + +LANG=C awk ' + BEGIN { + # We assume an awk implementation that is just plain dumb. + # We will convert an character to its ASCII value with the + # table ord[], and produce two-digit hexadecimal output + # without the printf("%02X") feature. + + EOL = "%0A" # "end of line" string (encoded) + split ("1 2 3 4 5 6 7 8 9 A B C D E F", hextab, " ") + hextab [0] = 0 + for ( i=1; i<=255; ++i ) ord [ sprintf ("%c", i) "" ] = i + 0 + if ("'"$_EncodeEOL"'" == "yes") _EncodeEOL = 1; else _EncodeEOL = 0 + } + { + encoded = "" + for ( i=1; i<=length ($0); ++i ) { + c = substr ($0, i, 1) + if ( c ~ /[a-zA-Z0-9.-]/ ) { + encoded = encoded c # safe character + } else if ( c == " " ) { + encoded = encoded "+" # special handling + } else { + # unsafe character, encode it as a two-digit hex-number + lo = ord [c] % 16 + hi = int (ord [c] / 16); + encoded = encoded "%" hextab [hi] hextab [lo] + } + } + if ( _EncodeEOL ) { + printf ("%s", encoded EOL) + } else { + print encoded + } + } + END { + #if ( _EncodeEOL ) print "" + } +' "$@" + +return 0 +} + +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: data_dot2ip() +# DOES: converts a dotted-decimal IPv4 address representation to the 32 bit number. +# EXPECTS: dotted-decimal IPv4 address [string] +# OUTPUTS: 32 bit number [string] +# REQUIRES: n/a +# REFERENCE: https://raw.githubusercontent.com/dualbus/tutorial_nmap/master/iprange +function data_dot2ip +{ +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}" +typeset _DOT="$1" +typeset _IP=0 +typeset _OLD_IFS="${IFS}" + +IFS="." +set -A _COMPS ${_DOT} +IFS="${OLD_IFS}" + +_IP=$((_IP | ((_COMPS[0] & 255) << 24) )) +_IP=$((_IP | ((_COMPS[1] & 255) << 16) )) +_IP=$((_IP | ((_COMPS[2] & 255) << 8) )) +_IP=$((_IP | ((_COMPS[3] & 255) << 0) )) + +print "${_IP}" + +return 0 +} + +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: data_ip2dot() +# DOES: converts a 32 bit unsigned integer to dotted-decimal notation. +# EXPECTS: 32 bit unsigned integer [string] +# OUTPUTS: dotted-decimal [string] +# RETURNS: 0 +# REQUIRES: n/a +# REFERENCE: https://raw.githubusercontent.com/dualbus/tutorial_nmap/master/iprange +function data_ip2dot +{ +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}" +typeset _IP="$1" +typeset _W="" +typeset _X="" +typeset _Y="" +typeset _Z="" + +_W=$(( (_IP >> 24) & 255 )) +_X=$(( (_IP >> 16) & 255 )) +_Y=$(( (_IP >> 8) & 255 )) +_Z=$(( (_IP >> 0) & 255 )) + +print "${_W}.${_X}.${_Y}.${_Z}" + +return 0 +} + +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: data_bits2mask() +# DOES: converts bits notation (prefix) to a dotted-decimal representation +# EXPECTS: netmask in prefix [string] +# OUTPUTS: netmask in dotted decimal notation [string] +# RETURNS: 0 +# REQUIRES: n/a +# REFERENCE: https://raw.githubusercontent.com/dualbus/tutorial_nmap/master/iprange +function data_bits2mask +{ +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}" +typeset _BITS=$1 +typeset _MAX=4294967296 +typeset _OFFSET=0 + +case "${_BITS}" in + 0) _OFFSET=${_MAX} ;; + 1) _OFFSET=2147483648 ;; + 2) _OFFSET=1073741824 ;; + 3) _OFFSET=536870912 ;; + 4) _OFFSET=268435456 ;; + 5) _OFFSET=134217728 ;; + 6) _OFFSET=67108864 ;; + 7) _OFFSET=33554432 ;; + 8) _OFFSET=16777216 ;; + 9) _OFFSET=8388608 ;; + 10) _OFFSET=4194304 ;; + 11) _OFFSET=2097152 ;; + 12) _OFFSET=1048576 ;; + 13) _OFFSET=524288 ;; + 14) _OFFSET=262144 ;; + 15) _OFFSET=131072 ;; + 16) _OFFSET=65536 ;; + 17) _OFFSET=32768 ;; + 18) _OFFSET=16384 ;; + 19) _OFFSET=8192 ;; + 20) _OFFSET=4096 ;; + 21) _OFFSET=2048 ;; + 22) _OFFSET=1024 ;; + 23) _OFFSET=512 ;; + 24) _OFFSET=256 ;; + 25) _OFFSET=128 ;; + 26) _OFFSET=64 ;; + 27) _OFFSET=32 ;; + 28) _OFFSET=16 ;; + 29) _OFFSET=8 ;; + 30) _OFFSET=4 ;; + 31) _OFFSET=2 ;; + 32) _OFFSET=1 ;; +esac + +data_ip2dot "$(( (_MAX - 1) & ~(_OFFSET - 1) ))" + +return 0 +} + +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: data_mask2bits() +# DOES: converts decimal netmask to bits notation (prefix) +# EXPECTS: netmask in dotted decimal notation [string] +# OUTPUTS: netmask in prefix [string] +# RETURNS: 0 +# REQUIRES: n/a +# REFERENCE: https://raw.githubusercontent.com/dualbus/tutorial_nmap/master/iprange +function data_mask2bits +{ +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}" +typeset _MASK="$1" +typeset -i _I=32 + +while (( _I > 0 )) +do + [[ "${_MASK}" = $(data_bits2mask "${_I}") ]] && print "${_I}" + _I=$(( _I - 1 )) +done + +return 0 +} + +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: data_is_IPv4() +# DOES: checks if an IP address is in IPv4 dotted notation +# EXPECTS: IPv4 address in decimal notation [string] +# RETURNS: 0=not IPv4; <>0=IPv4 +# REQUIRES: n/a +function data_is_ipv4 +{ +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}" +typeset _IP="$1" +typeset _RC=0 + +_RC=$(print "${_IP}" | grep -c -E -e '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' 2>/dev/null) + +return ${_RC} +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/core/include_os.sh b/sources/lib/core/include_os.sh new file mode 100644 index 0000000..248778c --- /dev/null +++ b/sources/lib/core/include_os.sh @@ -0,0 +1,211 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) include_os.sh +#****************************************************************************** +# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: include_OS +# DOES: helper functions for OS related functions +# +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: linux_get_distro() +# DOES: get Linux distribution name & version, sets $LINUX_DISTRO & $LINUX_RELEASE +# EXPECTS: n/a +# RETURNS: 0 +# REQUIRES: n/a +function linux_get_distro +{ +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}" + +# linux only +check_platform 'Linux' || { + (( ARG_DEBUG != 0 )) && debug "may only run on platform(s): Linux" + return 1 +} + +# try LSB first (good for Ubuntu & derivatives) +if [[ -f /etc/lsb-release ]] +then + . /etc/lsb-release + LINUX_DISTRO="${DISTRIB_ID}" + LINUX_RELEASE="${DISTRIB_RELEASE}" +fi + +# LSB turned up zippo, start digging +if [[ -z "${LINUX_DISTRO}" || -z "${LINUX_RELEASE}" ]] +then + if [[ -f /etc/debian_version ]] + then + LINUX_DISTRO="Debian" + LINUX_RELEASE=$(/dev/null) + elif [[ -f /etc/SuSE-release ]] + then + LINUX_DISTRO="SuSE" + LINUX_RELEASE=$(grep 'VERSION' /etc/SuSE-release 2>/dev/null | cut -f2 -d'=' | tr -d ' ') + [[ -n "${LINUX_RELEASE}" ]] || LINUX_RELEASE=$(grep 'CPE_NAME' /etc/os-release 2>/dev/null | cut -f2 -d'=' | cut -f5 -d':') + elif [[ -f /etc/redhat-release ]] + then + LINUX_DISTRO="Redhat" + # system-release-cpe is present since Fedora 9 [cpe:/o:centos:linux:6:GA] + LINUX_RELEASE=$(cut -f5 -d':' /dev/null) + else + LINUX_DISTRO="${OS_NAME}" + LINUX_RELEASE="unknown" + fi +fi + +return 0 +} + +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: linux_get_init() +# DOES: get Linux init mechanism, sets $LINUX_INIT +# EXPECTS: n/a +# RETURNS: 0 +# REQUIRES: n/a +function linux_get_init +{ +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}" + +# linux only +check_platform 'Linux' || { + (( ARG_DEBUG != 0 )) && debug "may only run on platform(s): Linux" + return 1 +} + +# default is sysv +LINUX_INIT="sysv" +if [[ -r /usr/lib/systemd ]] +then + LINUX_INIT="systemd" +elif [[ -r /usr/share/upstart ]] +then + LINUX_INIT="upstart" +fi + +return 0 +} + +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: linux_has_crm() +# DOES: check if Corosync (CRM version) is running +# EXPECTS: n/a +# OUTPUTS: 0=not active/installed; 1=active/installed +# RETURNS: 0=success; 1=error +# REQUIRES: n/a +function linux_has_crm +{ +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}" +typeset _CRM_BIN="" +typeset _HAS_CRM=0 + +# linux only +check_platform 'Linux' || { + warn "may only run on platform(s): Linux" + return 1 +} + +_CRM_BIN="$(which crm 2>/dev/null)" +if [[ -x ${_CRM_BIN} && -n "${_CRM_BIN}" ]] +then + # check for active + crm status >/dev/null 2>/dev/null + (( $? == 0 )) && _HAS_CRM=1 +else + (( ARG_DEBUG != 0 )) && debug "corosync (crm) is not active here" + return 1 +fi + +print ${_HAS_CRM} + +return 0 +} + +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: linux_has_docker() +# DOES: check if docker is running +# EXPECTS: n/a +# OUTPUTS: 0=not active/installed; 1=active/installed +# RETURNS: 0=success; 1=error +# REQUIRES: n/a +function linux_has_docker +{ +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}" +typeset _DOCKER_BIN="" +typeset _HAS_DOCKER=0 + +# linux only +check_platform 'Linux' || { + warn "may only run on platform(s): Linux" + return 1 +} + +_DOCKER_BIN="$(which docker 2>/dev/null)" +if [[ -x ${_DOCKER_BIN} && -n "${_DOCKER_BIN}" ]] +then + # check for active + docker ps >/dev/null 2>/dev/null + (( $? == 0 )) && _HAS_DOCKER=1 +else + (( ARG_DEBUG != 0 )) && debug "docker is not active here" + return 1 +fi + +print ${_HAS_DOCKER} + +return 0 +} + +# ----------------------------------------------------------------------------- +# @(#) FUNCTION: linux_has_nm() +# DOES: check if NetworkManager is running +# EXPECTS: n/a +# OUTPUTS: 0=not active/installed; 1=active/installed +# RETURNS: 0=success; 1=error +# REQUIRES: n/a +function linux_has_nm +{ +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}" +typeset _NMCLI_BIN="" +typeset _HAS_NM=0 + +# linux only +check_platform 'Linux' || { + warn "may only run on platform(s): Linux" + return 1 +} + +_NMCLI_BIN="$(which nmcli 2>/dev/null)" +if [[ -x ${_NMCLI_BIN} && -n "${_NMCLI_BIN}" ]] +then + # check for active + _HAS_NM=$(nmcli networking 2>/dev/null | grep -c -i "enabled") +else + (( ARG_DEBUG != 0 )) && debug "NetworkManager is not active here" + return 1 +fi + +print ${_HAS_NM} + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/core/notify_eif.sh b/sources/lib/core/notify_eif.sh new file mode 100644 index 0000000..7bd28e5 --- /dev/null +++ b/sources/lib/core/notify_eif.sh @@ -0,0 +1,126 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) notify_eif.sh +#****************************************************************************** +# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: notify_eif +# DOES: send alert via posteifmsg +# EXPECTS: HC name [string] +# RETURNS: 0 +# REQUIRES: handle_timeout(), init_hc(), log(), warn() +# INFO: https://www-01.ibm.com/support/knowledgecenter/SSSHTQ_8.1.0/com.ibm.netcool_OMNIbus.doc_8.1.0/omnibus/wip/eifsdk/reference/omn_eif_posteifmsg.html +# +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function notify_eif +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _CONFIG_FILE="${CONFIG_DIR}/core/providers/$0.conf" +typeset _VERSION="2016-03-04" # 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 _EIF_MESSAGE="$1 alert with ID ${HC_FAIL_ID}" +typeset _EIF_CLASS="${SCRIPT_NAME}" +typeset _EIF_BIN="" +typeset _EIF_ETC="" +typeset _EIF_SEVERITY="" +typeset _TIME_OUT=10 +typeset _CHILD_ERROR=0 +typeset _OWNER_PID=0 +typeset _SLEEP_PID=0 +typeset _CHILD_RC=0 + +# handle config file +if [[ ! -r ${_CONFIG_FILE} ]] +then + warn "unable to read configuration file at ${_CONFIG_FILE}" + return 1 +fi +# read required config values +_EIF_BIN="$(grep -i '^EIF_BIN=' ${_CONFIG_FILE} | cut -f2 -d'=' | tr -d '\"')" +if [[ -z "${_EIF_BIN}" ]] +then + warn "no value set for 'EIF_BIN' in ${_CONFIG_FILE}" + return 1 +fi +_EIF_ETC="$(grep -i '^EIF_ETC=' ${_CONFIG_FILE} | cut -f2 -d'=' | tr -d '\"')" +if [[ -z "${_EIF_ETC}" ]] +then + warn "no value set for 'EIF_ETC' in ${_CONFIG_FILE}" + return 1 +fi +_EIF_SEVERITY="$(grep -i '^EIF_SEVERITY=' ${_CONFIG_FILE} | cut -f2 -d'=' | tr -d '\"')" +if [[ -z "${_EIF_SEVERITY}" ]] +then + warn "no value set for 'EIF_SEVERITY' in ${_CONFIG_FILE}" + return 1 +fi + +# send EIF +if [[ -x ${EIF_BIN} ]] +then + # set trap on SIGUSR1 + trap "handle_timeout" USR1 + + # $PID is PID of the owner shell + _OWNER_PID=$$ + ( + # sleep for $_TIME_OUT seconds. If the sleep subshell is then still alive, send a SIGUSR1 to the owner + sleep ${_TIME_OUT} + kill -s USR1 ${_OWNER_PID} >/dev/null 2>&1 + ) & + # $_SLEEP_PID is the PID of the sleep subshell itself + _SLEEP_PID=$! + + # do POSTEIFMSG in the background + ${EIF_BIN} -f ${EIF_ETC} -r ${EIF_SEVERITY} -m "${_EIF_MESSAGE}" \ + hostname=${HOST_NAME} sub_origin=part1 ${_EIF_CLASS} POST & + CHILD_PID=$! + log "spawning child process with time-out of ${_TIME_OUT} secs for EIF notify [PID=${CHILD_PID}]" + # wait for the command to complete + wait ${CHILD_PID} + # when the child completes, we can get rid of the sleep trigger + _CHILD_RC=$? + kill -s TERM ${_SLEEP_PID} >/dev/null 2>&1 + # process return codes + if (( _CHILD_RC != 0 )) + then + warn "problem in sending alert via EIF [RC=${_CHILD_RC}]" + else + if (( _CHILD_ERROR == 0 )) + then + log "child process with PID ${CHILD_PID} ended correctly" + else + log "child process with PID ${CHILD_PID} did end correctly" + fi + fi +else + warn "could not sent alert via EIF (posteifmsg tool not found)" +fi + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/core/notify_mail.sh b/sources/lib/core/notify_mail.sh new file mode 100644 index 0000000..fc3c6d6 --- /dev/null +++ b/sources/lib/core/notify_mail.sh @@ -0,0 +1,225 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) notify_mail.sh +#****************************************************************************** +# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: notify_mail +# DOES: send e-mail alert +# EXPECTS: 1=HC name [string], 2=HC FAIL_ID [string] +# RETURNS: 0 +# REQUIRES: curl, die(), init_hc(), log() +# +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function notify_mail +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _VERSION="2017-05-17" # 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 _MAIL_HC="$1" +typeset _MAIL_FAIL_ID="$2" + +typeset _HC_BODY="" +set -A _MAIL_MSG_STC +set -A _MAIL_MSG_TIME +set -A _MAIL_MSG_TEXT +typeset _I=0 +typeset _MAX_I=0 +typeset _HC_STDOUT_LOG_SHORT="" +typeset _HC_STDERR_LOG_SHORT="" +typeset _MAIL_INFO_TPL="${CONFIG_DIR}/core/templates/mail_info.tpl" +typeset _MAIL_HEADER_TPL="${CONFIG_DIR}/core/templates/mail_header.tpl" +typeset _MAIL_BODY_TPL="${CONFIG_DIR}/core/templates/mail_body.tpl" +typeset _MAIL_FOOTER_TPL="${CONFIG_DIR}/core/templates/mail_footer.tpl" +typeset _MAIL_STDOUT_LOG="" +typeset _MAIL_STDERR_LOG="" +typeset _MAIL_STDOUT_MSG="" +typeset _MAIL_STDERR_MSG="" +typeset _MAIL_ATTACH_BIT="" +typeset _MAIL_METHOD="" +typeset _MAIL_RC=0 +typeset _MAILX_BIN="" +typeset _MUTT_BIN="" +typeset _SENDMAIL_BIN="" +typeset _UUENCODE_BIN="" +typeset _TMP1_MAIL_FILE="${TMP_DIR}/.${SCRIPT_NAME}.mail.tmp1.$$" +typeset _TMP2_MAIL_FILE="${TMP_DIR}/.${SCRIPT_NAME}.mail.tmp2.$$" +typeset _NOW="$(date '+%d-%h-%Y %H:%M:%S')" +typeset _SUBJ_MSG="[${HOST_NAME}] HC ${_MAIL_HC} failed (${_NOW})" +typeset _FROM_MSG="${EXEC_USER}@${HOST_NAME}" + +# set local trap for cleanup +trap "[[ -f ${_TMP1_MAIL_FILE} ]] && rm -f ${_TMP1_MAIL_FILE} >/dev/null 2>&1; [[ -f ${_TMP2_MAIL_FILE} ]] && rm -f ${_TMP2_MAIL_FILE} >/dev/null 2>&1; return 1" 1 2 3 15 + +# set short paths for STDOUT/STDERR logs +_HC_STDOUT_LOG_SHORT="${HC_STDOUT_LOG##*/}" +_HC_STDERR_LOG_SHORT="${HC_STDERR_LOG##*/}" + +# check & determine mailer tools +case "${OS_NAME}" in + "Linux") + # prefer mutt :-) + _MUTT_BIN="$(which mutt 2>/dev/null)" + if [[ -x ${_MUTT_BIN} ]] && [[ -n "${_MUTT_BIN}" ]] + then + _MAIL_METHOD="mutt" + else + # prefer mailx next + _MAILX_BIN="$(which mailx 2>/dev/null)" + if [[ -x ${_MAILX_BIN} ]] && [[ -n "${_MAILX_BIN}" ]] + then + _MAIL_METHOD="mailx" + else + _MAIL_METHOD="sendmail" + fi + fi + ;; + *) + _MAIL_METHOD="sendmail" + ;; +esac +# check if fall-back & last resort exists +if [[ "${_MAIL_METHOD}" = "sendmail" ]] +then + # find 'sendmail' + _SENDMAIL_BIN="$(which sendmail 2>/dev/null)" + if [[ ! -x ${_SENDMAIL_BIN} ]] || [[ -z "${_SENDMAIL_BIN}" ]] + then + die "unable to send e-mail - sendmail is not installed here" + fi + # find 'uuencode' + _UUENCODE_BIN="$(which uuencode 2>/dev/null)" + if [[ ! -x ${_UUENCODE_BIN} ]] || [[ -z "${_UUENCODE_BIN}" ]] + then + die "unable to send e-mail - uuencode is not installed here" + fi +fi + +# create info part (not for mailx or mutt) +if [[ "${_MAIL_METHOD}" = "sendmail" ]] +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} +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} + +# create body part (max array size: 1023 in ksh88f, plugins spawning more than >1K messages are crazy :-)) +while read HC_MSG_ENTRY +do + _MAIL_MSG_STC[${_I}]=$(print "${HC_MSG_ENTRY}" | awk -F "%%" '{ print $1'}) + _MAIL_MSG_TIME[${_I}]=$(print "${HC_MSG_ENTRY}" | awk -F "%%" '{ print $2'}) + _MAIL_MSG_TEXT[${_I}]=$(print "${HC_MSG_ENTRY}" | awk -F "%%" '{ print $3'}) + _I=$(( _I + 1 )) +done <${HC_MSG_FILE} 2>/dev/null +_MAX_I=${#_MAIL_MSG_STC[*]} +_I=0 +while (( _I < _MAX_I )) +do + (( _MAIL_MSG_STC[${_I}] > 0 )) && _HC_BODY=$(printf "%s\n%s\n" "${_HC_BODY}" "${_MAIL_MSG_TEXT[${_I}]}") + _I=$(( _I + 1 )) +done +# check for custom template +[[ -r "${_MAIL_BODY_TPL}-${_MAIL_HC}" ]] && _MAIL_BODY_TPL="${_MAIL_BODY_TPL}-${_MAIL_HC}" +[[ -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} + +# HC STDOUT log? (drop the .$$ bit) +_MAIL_STDOUT_LOG="${EVENTS_DIR}/${DIR_PREFIX}/${_MAIL_FAIL_ID}/${_HC_STDOUT_LOG_SHORT%.*}" +if [[ -s "${_MAIL_STDOUT_LOG}" ]] +then + _MAIL_STDOUT_MSG="${_MAIL_STDOUT_LOG}" + _MAIL_ATTACH_BIT="-a ${_MAIL_STDOUT_LOG}" +else + _MAIL_STDOUT_MSG="no log file available" +fi +# HC STDERR? (drop the .$$ bit) +_MAIL_STDERR_LOG="${EVENTS_DIR}/${DIR_PREFIX}/${_MAIL_FAIL_ID}/${_HC_STDERR_LOG_SHORT%.*}" +if [[ -s "${_MAIL_STDERR_LOG}" ]] +then + _MAIL_STDERR_MSG="${_MAIL_STDERR_LOG}" + _MAIL_ATTACH_BIT="${_MAIL_ATTACH_BIT} -a ${_MAIL_STDERR_LOG}" +else + _MAIL_STDERR_MSG="no log file available" +fi + +# create footer part +[[ -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} + +# combine and send message components +case "${_MAIL_METHOD}" in + "mailx") + # remove non-ASCII characters to avoid Exchange ATT00001.bin + 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 + 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 + [[ -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 + _MAIL_RC=$? + ;; + *) + : + ;; +esac + +if (( _MAIL_RC == 0 )) +then + log "e-mail alert sent/queued to ${ARG_MAIL_TO}: ${_MAIL_HC} failed, FAIL_ID=${_MAIL_FAIL_ID}" +else + log "failed to send e-mail to ${ARG_MAIL_TO}: ${_MAIL_HC} failed, FAIL_ID=${_MAIL_FAIL_ID}" +fi + +# clean up temporary files +[[ -f ${_TMP1_MAIL_FILE} ]] && rm -f ${_TMP1_MAIL_FILE} >/dev/null 2>&1 +[[ -f ${_TMP2_MAIL_FILE} ]] && rm -f ${_TMP2_MAIL_FILE} >/dev/null 2>&1 + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/core/notify_sms.sh b/sources/lib/core/notify_sms.sh new file mode 100644 index 0000000..12720cd --- /dev/null +++ b/sources/lib/core/notify_sms.sh @@ -0,0 +1,129 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) notify_sms.sh +#****************************************************************************** +# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: notify_sms +# DOES: send sms alert +# EXPECTS: 1=HC name [string], 2=HC FAIL_ID [string] +# RETURNS: 0 +# REQUIRES: init_hc(), log(), warn() +# +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function notify_sms +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _CONFIG_FILE="${CONFIG_DIR}/core/providers/$0.conf" +typeset _VERSION="2017-04-27" # 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 _SMS_HC="$1" +typeset _SMS_FAIL_ID="$2" +typeset _SMS_TEXT="" +typeset _FROM_MSG="${EXEC_USER}@${HOST_NAME}" +typeset _CURL_BIN="" +typeset _SMS_PROVIDERS="" +typeset _SMS_KAPOW_SEND_URL="" +typeset _SMS_KAPOW_USER="" +typeset _SMS_KAPOW_PASSWORD="" + +# handle config file +if [[ ! -r ${_CONFIG_FILE} ]] +then + warn "unable to read configuration file at ${_CONFIG_FILE}" + return 1 +fi +# read required config values +_SMS_PROVIDERS="$(grep -i '^SMS_PROVIDERS=' ${_CONFIG_FILE} | cut -f2 -d'=' | tr -d '\"')" +if [[ -z "${_SMS_PROVIDERS}" ]] +then + warn "no value set for 'SMS_PROVIDERS' in ${_CONFIG_FILE}" + return 1 +fi + +# SMS_PROVIDERS & SMS settings +if [[ -n "${_SMS_PROVIDERS}" ]] +then + # SMS specific values are sourced in read_config() + print "${_SMS_PROVIDERS}" | tr ',' '\n' | while read -r _PROVIDER_OPTS + do + case "${_PROVIDER_OPTS}" in + *kapow*|*KAPOW*|*Kapow*) + # read required config values + _SMS_KAPOW_SEND_URL="$(grep -i '^SMS_KAPOW_SEND_URL=' ${_CONFIG_FILE} | cut -f2 -d'=' | tr -d '\"')" + if [[ -z "${_SMS_KAPOW_SEND_URL}" ]] + then + warn "no value set for 'SMS_KAPOW_SEND_URL' in ${_CONFIG_FILE}" + return 1 + fi + _SMS_KAPOW_USER="$(grep -i '^SMS_KAPOW_USER=' ${_CONFIG_FILE} | cut -f2 -d'=' | tr -d '\"')" + if [[ -z "${_SMS_KAPOW_USER}" ]] + then + warn "no value set for 'SMS_KAPOW_USER' in ${_CONFIG_FILE}" + return 1 + fi + _SMS_KAPOW_PASS="$(grep -i '^SMS_KAPOW_PASS=' ${_CONFIG_FILE} | cut -f2 -d'=' | tr -d '\"')" + if [[ -z "${_SMS_KAPOW_PASS}" ]] + then + warn "no value set for 'SMS_KAPOW_PASS' in ${_CONFIG_FILE}" + return 1 + fi + esac + done +fi + +# send SMS +case "${ARG_SMS_PROVIDER}" in + *kapow*|*KAPOW*|*Kapow*) + # KAPOW (https://www.kapow.co.uk/) + # find 'curl' + _CURL_BIN="$(which curl 2>/dev/null)" + if [[ -x ${_CURL_BIN} ]] && [[ -n "${_CURL_BIN}" ]] + then + _SMS_TEXT=$(print "${_FROM_MSG}: HC ${_SMS_HC} failed, FAIL_ID=${_SMS_FAIL_ID}" | data_encode_url) + if (( ARG_DEBUG == 0 )) + then + ${_CURL_BIN} -s --url "${_SMS_KAPOW_SEND_URL}?username=${_SMS_KAPOW_USER}&password=${_SMS_KAPOW_PASS}&mobile=${ARG_SMS_TO}&sms=${_SMS_TEXT}" >/dev/null 2>&1 + else + ${_CURL_BIN} --url "${_SMS_KAPOW_SEND_URL}?username=${_SMS_KAPOW_USER}&password=${_SMS_KAPOW_PASS}&mobile=${ARG_SMS_TO}&sms=${_SMS_TEXT}" + fi + else + die "unable to send SMS - curl is not installed here" + fi + ;; + *) + # nothing here + die "unable to send SMS - no method defined for SMS provider ${ARG_SMS_PROVIDER}" + ;; +esac + +log "SMS alert sent/queued to ${ARG_SMS_TO}: ${_SMS_HC} failed, FAIL_ID=${_SMS_FAIL_ID}" + +return 0 +} + + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/aix/check_aix_errpt.sh b/sources/lib/platform/aix/check_aix_errpt.sh new file mode 100644 index 0000000..7c7aab1 --- /dev/null +++ b/sources/lib/platform/aix/check_aix_errpt.sh @@ -0,0 +1,133 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_aix_errpt.sh +#****************************************************************************** +# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_aix_errpt +# DOES: see _show_usage() +# EXPECTS: n/a +# REQUIRES: data_space2comma(), init_hc(), log_hc() +# +# @(#) HISTORY: +# @(#) 2013-05-15: initial version [Patrick Van der Veken] +# @(#) 2013-05-29: small fix errpt last check time [Patrick Van der Veken] +# @(#) 2013-06-24: big fix errpt last check time [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_aix_errpt +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _VERSION="2013-06-24" # 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_space2comma "$*") +typeset _ARG="" +typeset _MSG="" +typeset _STC=0 +typeset _LAST_TIME_CHECK="" +typeset _LAST_TIME_FILE="" +typeset _LABEL="" +typeset _IDENTIFIER="" +typeset _NEW_CHECK_TIME="" + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + +# check for last known check date +_LAST_TIME_FILE="${STATE_DIR}/$0.lasttime" +if [[ -r ${_LAST_TIME_FILE} ]] +then + if [[ -s ${_LAST_TIME_FILE} ]] + then + _LAST_TIME_CHECK="<${_LAST_TIME_FILE})" + else + warn "$0: no last known check date/time" + fi +fi + +# collect data +if [[ -z "${_LAST_TIME_CHECK}" ]] +then + errpt -A >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG} +else + errpt -s "${_LAST_TIME_CHECK}" |\ + grep -v "${_LAST_TIME_CHECK}" | grep -v "_IDENTIFIER" |\ + awk '{ print $1}' | uniq | while read _LABEL + do + errpt -a -j ${_LABEL} -s "${_LAST_TIME_CHECK}" \ + >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG} + done + (( $? == 0)) || return $? +fi + +# do we have errors? +if [[ -s ${HC_STDOUT_LOG} ]] +then + _MSG="new entries found in errpt: {$(grep -c '^LABEL' ${HC_STDOUT_LOG} 2>/dev/null)}" + _STC=1 +else + _MSG="no new entries found in {errpt}" +fi + +# update last known check date/time (potential race condition here, +# but we can live it :-)) +_NEW_CHECK_TIME="$(errpt 2>/dev/null | head -n 2 | tail -n 1 | awk '{print $2}')" +# blank result indicates either no errpt entries or exist the time call failed +if [[ -n "${_NEW_CHECK_TIME}" ]] +then + print "${_NEW_CHECK_TIME}" >${_LAST_TIME_FILE} + (( $? == 0)) || warn "$0: unable to write last check time to ${_LAST_TIME_FILE}" +else + warn "$0: no last check time received from errpt (no entries)" +fi + +# handle results +log_hc "$0" ${_STC} "${_MSG}" + +return 0 +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 +PURPOSE : Checks AIX errpt for new error(s) + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/aix/check_aix_file_age.sh b/sources/lib/platform/aix/check_aix_file_age.sh new file mode 100644 index 0000000..e97577d --- /dev/null +++ b/sources/lib/platform/aix/check_aix_file_age.sh @@ -0,0 +1,146 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_aix_file_age.sh +#****************************************************************************** +# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_aix_file_age +# DOES: see _show_usage() +# EXPECTS: see _show_usage() +# REQUIRES: data_space2comma(), init_hc(), log_hc() +# +# @(#) HISTORY: +# @(#) 2013-05-27: initial version [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_aix_file_age +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" +typeset _VERSION="2013-05-27" # 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_space2comma "$*") +typeset _ARG="" +typeset _MSG="" +typeset _STC=0 +typeset _ENTRY="" +typeset _AGE_CHECK=="" +typeset _FILE_PATH="" +typeset _FILE_AGE="" +typeset _FILE_NAME="" +typeset _FILE_DIR="" + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + +# handle configuration file +[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}" +if [[ ! -r ${_CONFIG_FILE} ]] +then + warn "unable to read configuration file at ${_CONFIG_FILE}" + return 1 +fi + +# perform check +grep -v -E -e '^$' -e '^#' ${_CONFIG_FILE} 2>/dev/null | while read _ENTRY +do + # field split + _FILE_PATH="$(print ${_ENTRY%%;*})" + _FILE_AGE="$(print ${_ENTRY##*;})" + + # split file/dir + _FILE_NAME="$(print ${_FILE_PATH##*/})" + _FILE_DIR="$(print ${_FILE_PATH%/*})" + + # check config + if [ \( -z "${_FILE_PATH}" \) -a \( -z "${_FILE_AGE}" \) ] + then + warn "missing values in configuration file at ${_CONFIG_FILE}" + return 1 + fi + case "${_FILE_AGE}" in + +([0-9])*(.)*([0-9])) + # numeric, OK + ;; + *) + # not numeric + warn "invalid file age value '${_FILE_AGE}' in configuration file at ${_CONFIG_FILE}" + return 1 + ;; + esac + + # perform check + if [[ ! -r "${_FILE_PATH}" ]] + then + _MSG="unable to read or access requested file at ${_FILE_PATH}" + _STC=1 + else + _AGE_CHECK=$(find "${_FILE_DIR}" -type f -name "${_FILE_NAME}" -mmin -"${_FILE_AGE}") + if (( $? != 0 )) + then + warn "unable to execute file age test for ${_FILE_PATH}" + return 1 + fi + if [[ -z "${_AGE_CHECK}" ]] + then + _MSG="file age of ${_FILE_AGE} has expired on ${_FILE_PATH}" + _STC=1 + else + _MSG="file age of ${_FILE_AGE} has not expired on ${_FILE_PATH}" + fi + fi + + # handle unit result + log_hc "$0" ${_STC} "${_MSG}" + _STC=0 +done + +return 0 +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 with: + ; +PURPOSE : Checks whether given files have been changed in the last n minutes + Requires {find -mmin}. + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/aix/check_aix_file_change.sh b/sources/lib/platform/aix/check_aix_file_change.sh new file mode 100644 index 0000000..e75108c --- /dev/null +++ b/sources/lib/platform/aix/check_aix_file_change.sh @@ -0,0 +1,373 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_aix_file_change.sh +#****************************************************************************** +# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_aix_file_change +# DOES: see _show_usage() +# EXPECTS: see _show_usage() +# REQUIRES: data_space2comma(), init_hc(), log_hc(), warn(), +# openssl (sha256 digest) OR cksum (CRC32 digest) +# +# @(#) HISTORY: +# @(#) 2017-05-18: initial version [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_aix_file_change +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" +typeset _VERSION="2017-05-18" # YYYY-MM-DD +typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match +# ------------------------- CONFIGURATION ends here --------------------------- + +# set defaults +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS} +init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}" +typeset _ARGS=$(data_space2comma "$*") +typeset _ARG="" +typeset _MSG="" +typeset _STC=0 +typeset _STC_COUNT=0 +typeset _DO_META_CHECK=0 +typeset _CFG_STATE_FILE="" +typeset _STATE_FILE="" +typeset _STATE_FILE_LINE="" +typeset _FILE_TO_CHECK="" +typeset _EXCL_OBJECT="" +typeset _INCL_OBJECT="" +typeset _HAS_OPENSSL=0 +typeset _HAS_CKSUM=0 +typeset _OPENSSL_BIN="" +typeset _CKSUM_BIN="" +typeset _USE_OPENSSL=0 +typeset _USE_CKSUM=0 +typeset _TMP1_FILE="${TMP_DIR}/.$0.tmp1.$$" +typeset _TMP2_FILE="${TMP_DIR}/.$0.tmp2.$$" +typeset _TMP_INCL_FILE="${TMP_DIR}/.$0.tmp_incl.$$" +typeset _TMP_EXCL_FILE="${TMP_DIR}/.$0.tmp_excl.$$" +set -o noglob # no file globbing + +# set local trap for clean-up +trap "[[ -f ${_TMP1_FILE} ]] && rm -f ${_TMP1_FILE} >/dev/null 2>&1; + [[ -f ${_TMP2_FILE} ]] && rm -f ${_TMP2_FILE} >/dev/null 2>&1; + [[ -f ${_TMP_INCL_FILE} ]] && rm -f ${_TMP_INCL_FILE} >/dev/null 2>&1; + [[ -f ${_TMP_EXCL_FILE} ]] && rm -f ${_TMP_EXCL_FILE} >/dev/null 2>&1; + return 1" 1 2 3 15 + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + +# handle configuration file +[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}" +if [[ ! -r ${_CONFIG_FILE} ]] +then + warn "unable to read configuration file at ${_CONFIG_FILE}" + return 1 +fi +# read required configuration values +_CFG_STATE_FILE=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'state_file') +if [[ -z "${_CFG_STATE_FILE}" ]] +then + _STATE_FILE="${STATE_PERM_DIR}/discovered.file_change" +else + _STATE_FILE="${STATE_PERM_DIR}/${_CFG_STATE_FILE}" +fi +log "using state file ${_STATE_FILE}" +_DO_META_CHECK=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'do_meta_check') +case "${_DO_META_CHECK}" in + no|NO|No) + _DO_META_CHECK=0 + log "check for meta characters is disabled" + ;; + *) + _DO_META_CHECK=1 + log "check for meta characters is enabled" + ;; +esac + +# check for checksum tools +_OPENSSL_BIN="$(which openssl 2>>${HC_STDERR_LOG})" +[[ -x ${_OPENSSL_BIN} && -n "${_OPENSSL_BIN}" ]] && _HAS_OPENSSL=1 +_CKSUM_BIN="$(which cksum 2>>${HC_STDERR_LOG})" +[[ -x ${_CKSUM_BIN} && -n "${_CKSUM_BIN}" ]] && _HAS_CKSUM=1 +# prefer openssl (for sha256) +if (( _HAS_OPENSSL == 1 )) +then + _USE_OPENSSL=1 +elif (( _HAS_CKSUM == 1 )) +then + _USE_CKSUM=1 +else + warn "unable to find the 'openssl/cksum' tools" + return 1 +fi + +# check state file & TMP_FILEs +[[ -r ${_STATE_FILE} ]] || { + >${_STATE_FILE} + (( $? > 0 )) && { + warn "failed to create new state file at ${_STATE_FILE}" + return 1 + } + log "created new state file at ${_STATE_FILE}" +} +>${_TMP_INCL_FILE} +(( $? > 0 )) && { + warn "failed to create temporary file at ${_TMP_INCL_FILE}" + return 1 +} +>${_TMP_EXCL_FILE} +(( $? > 0 )) && { + warn "failed to create temporary file at ${_TMP_EXCL_FILE}" + return 1 +} +>${_TMP1_FILE} +(( $? > 0 )) && { + warn "failed to create temporary file at ${_TMP1_FILE}" + return 1 +} +>${_TMP2_FILE} +(( $? > 0 )) && { + warn "failed to create temporary file at ${_TMP2_FILE}" + return 1 +} + +# build list of configured objects: inclusion +grep -i '^incl:' ${_CONFIG_FILE} 2>/dev/null |\ + while IFS=':' read _DUMMY _INCL_OBJECT +do + # check for meta & globbing characters (*?[]{}|) + if (( _DO_META_CHECK == 1 )) + then + case "${_INCL_OBJECT}" in + *\**|*\?*|*\[*|*\]*|*\{*|*\}*|*\|*) + warn "meta characters are not supported in the entry (incl:${_INCL_OBJECT})" + continue + ;; + esac + fi + + # expand directories + if [[ -d ${_INCL_OBJECT} ]] + then + find ${_INCL_OBJECT} -type f -xdev >>${_TMP_INCL_FILE} 2>>${HC_STDERR_LOG} + else + print ${_INCL_OBJECT} >>${_TMP_INCL_FILE} + fi +done + +# build list of configured objects: exclusion +grep -i '^excl:' ${_CONFIG_FILE} 2>/dev/null |\ + while IFS=':' read _DUMMY _EXCL_OBJECT +do + # check for meta & globbing characters (*?[]{}|) + if (( _DO_META_CHECK == 1 )) + then + case "${_EXCL_OBJECT}" in + *\**|*\?*|*\[*|*\]*|*\{*|*\}*|*\|*) + warn "meta characters are not supported in the entry (excl:${_EXCL_OBJECT})" + continue + ;; + esac + fi + + # expand directories + if [[ -d ${_EXCL_OBJECT} ]] + then + find ${_EXCL_OBJECT} -type f -xdev >>${_TMP_EXCL_FILE} 2>>${HC_STDERR_LOG} + else + print ${_EXCL_OBJECT} >>${_TMP_EXCL_FILE} + fi +done + +# subtract exclusion from inclusion (exclusion has higher priority) +sort ${_TMP_INCL_FILE} -o ${_TMP_INCL_FILE} 2>>${HC_STDERR_LOG} +sort ${_TMP_EXCL_FILE} -o ${_TMP_EXCL_FILE} 2>>${HC_STDERR_LOG} +comm -23 ${_TMP_INCL_FILE} ${_TMP_EXCL_FILE} 2>>${HC_STDERR_LOG} >${_TMP1_FILE} + +# check discovered objects +while read _FILE_TO_CHECK +do + # reset variables + _STC=0 + _MSG="" + _IS_NEW=0 + + # object to check must be a file (and be present) + if [[ ! -f ${_FILE_TO_CHECK} ]] + then + _MSG="${_FILE_TO_CHECK} is not a file or has disappeared" + _STC=1 + log_hc "$0" ${_STC} "${_MSG}" + continue + fi + + # read entry from state file + _STATE_FILE_LINE=$(grep -E -e "^${_FILE_TO_CHECK}\|" ${_STATE_FILE}) + if [[ -n "${_STATE_FILE_LINE}" ]] + then + # field 1 is the file name + _STATE_FILE_TYPE=$(print "${_STATE_FILE_LINE}" | cut -f2 -d'|') + _STATE_FILE_CKSUM=$(print "${_STATE_FILE_LINE}" | cut -f3 -d'|') + else + _IS_NEW=1 + fi + + # compute new checksum (keep the same type as before) + if (( _IS_NEW == 0 )) + then + case "${_STATE_FILE_TYPE}" in + openssl-sha256) + if (( _USE_OPENSSL == 1 )) + then + _FILE_CKSUM=$(${_OPENSSL_BIN} dgst -sha256 ${_FILE_TO_CHECK} 2>>${HC_STDERR_LOG} | cut -f2 -d'=' | tr -d ' ') + _FILE_TYPE="openssl-sha256" + else + _MSG="cannot compute checksum [${_FILE_TYPE}] for ${_FILE_TO_CHECK}" + _STC=1 + fi + ;; + cksum-crc32) + if (( _USE_CKSUM == 1 )) + then + _FILE_CKSUM=$(${_CKSUM_BIN} ${_FILE_TO_CHECK} 2>>${HC_STDERR_LOG} | cut -f1 -d' ') + _FILE_TYPE="cksum-crc32" + else + _MSG="cannot compute checksum [${_FILE_TYPE}] for ${_FILE_TO_CHECK}" + _STC=1 + fi + ;; + *) + _MSG="cannot compute checksum (unknown checksum type) for ${_FILE_TO_CHECK}" + _STC=1 + ;; + esac + else + # new file + if (( _USE_OPENSSL == 1 )) + then + _FILE_CKSUM=$(${_OPENSSL_BIN} dgst -sha256 ${_FILE_TO_CHECK} 2>>${HC_STDERR_LOG} | cut -f2 -d'=' | tr -d ' ') + _FILE_TYPE="openssl-sha256" + elif (( _USE_CKSUM == 1 )) + then + _FILE_CKSUM=$(${_CKSUM_BIN} ${_FILE_TO_CHECK} 2>>${HC_STDERR_LOG} | cut -f1 -d' ') + _FILE_TYPE="cksum-crc32" + else + _MSG="cannot compute checksum (openssl/cksum) for ${_FILE_TO_CHECK}" + _STC=1 + fi + fi + + # check for failed checksums + if [[ -z "${_FILE_CKSUM}" ]] + then + _MSG="did not receive checksum (openssl/cksum) for ${_FILE_TO_CHECK}" + _STC=1 + fi + + # bounce failures back and jump to next file + if (( _STC != 0 )) + then + log_hc "$0" ${_STC} "${_MSG}" + continue + fi + + if (( _IS_NEW == 0 )) + then + # compare old vs new checksums + if [[ "${_STATE_FILE_CKSUM}" != "${_FILE_CKSUM}" ]] + then + _MSG="${_FILE_TO_CHECK} has a changed checksum [${_FILE_TYPE}]" + _STC=1 + else + _MSG="${_FILE_TO_CHECK} has the same checksum [${_FILE_TYPE}]" + _STC=0 + fi + else + _MSG="${_FILE_TO_CHECK} is a new file [${_FILE_TYPE}]" + _STC=0 + fi + + # save entry to temp file + printf "%s|%s|%s\n" "${_FILE_TO_CHECK}" "${_FILE_TYPE}" "${_FILE_CKSUM}" >>${_TMP2_FILE} + + # report with curr/exp values + log_hc "$0" ${_STC} "${_MSG}" "${_FILE_CKSUM}" "${_STATE_FILE_CKSUM}" +done <${_TMP1_FILE} + +# update state file (also if TMP2_FILE is empty) +if (( ARG_LOG != 0 )) +then + [[ -s ${_TMP2_FILE} ]] || { + warn "no files found to check, zeroing new state file" + } + mv ${_TMP2_FILE} ${_STATE_FILE} >/dev/null 2>&1 + (( $? > 0 )) && { + warn "failed to move temporary state file" + return 1 + } +fi + +# clean up temporary files +[[ -f ${_TMP1_FILE} ]] && rm -f ${_TMP1_FILE} >/dev/null 2>&1 +[[ -f ${_TMP2_FILE} ]] && rm -f ${_TMP2_FILE} >/dev/null 2>&1 +[[ -f ${_TMP_INCL_FILE} ]] && rm -f ${_TMP_INCL_FILE} >/dev/null 2>&1 +[[ -f ${_TMP_EXCL_FILE} ]] && rm -f ${_TMP_EXCL_FILE} >/dev/null 2>&1 + +return 0 +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 with formatted stanzas: + incl: + excl: +PURPOSE : a KISS file integrity checker (like AIDE). Supports includes and excludes + of files and directories (automatically expanded). Excludes have a higher + priority than includes. Integrity checks will only be performed on files. + Will detect changed, new & deleted files (but not when deleted files + occur in an expanded directory tree). If you wish to detect deleted files: + use only direct file references in the configuration file. Uses by preference + openssl for hash calculation, with cksum as fall-back). + Updated and deleted files will cause a HC failure, new files will not. + CAVEAT EMPTOR: use only to check a relatively small number of files. + Processing a big number of files is likely to take + ages and probably will cause the plugin to time out + (see HC_TIME_OUT). YMMV. + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/aix/check_aix_fs_mounts.sh b/sources/lib/platform/aix/check_aix_fs_mounts.sh new file mode 100644 index 0000000..3296fe5 --- /dev/null +++ b/sources/lib/platform/aix/check_aix_fs_mounts.sh @@ -0,0 +1,109 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_aix_fs_mounts.sh +#****************************************************************************** +# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_aix_fs_mounts +# DOES: see _show_usage() +# EXPECTS: n/a +# REQUIRES: data_space2comma(), init_hc(), log_hc() +# +# @(#) HISTORY: +# @(#) 2013-05-15: initial version [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_aix_fs_mounts +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _VERSION="2013-05-15" # 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_space2comma "$*") +typeset _ARG="" +typeset _MSG="" +typeset _STC=0 +typeset _FS="" +typeset _FS_COUNT="" + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + +# collect data (mount & lsfs output may be safely merged) +mount >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG} +(( $? == 0)) || return $? +lsfs -ac >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG} +(( $? == 0)) || return $? + +# check for each auto-mount configured file system (except /) +lsfs -ac |\ + grep -v -E -e '^#' -e '^\/:' |\ + grep -E -e '.*:.*:.*:.*:.*:.*:.*:yes:.*' |\ + cut -f1 -d':' |\ +while read _FS +do + _FS_COUNT=$(grep -c -E -e ".*[ \t]*+${_FS}[ \t].*" ${HC_STDOUT_LOG} 2>/dev/null) + case ${_FS_COUNT} in + 0) + _MSG="${_FS} is not mounted" + _STC=1 + ;; + 1) + _MSG="${_FS} is mounted" + ;; + *) + _MSG="${_FS} is multiple times mounted?" + ;; + esac + + # handle unit result + log_hc "$0" ${_STC} "${_MSG}" + _STC=0 +done + +return 0 +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 +PURPOSE : Checks whether file systems are mounted or not {lsfs/mount} + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/aix/check_aix_lppchk.sh b/sources/lib/platform/aix/check_aix_lppchk.sh new file mode 100644 index 0000000..081e6a2 --- /dev/null +++ b/sources/lib/platform/aix/check_aix_lppchk.sh @@ -0,0 +1,91 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_aix_lppchk.sh +#****************************************************************************** +# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_aix_lppchk +# DOES: see _show_usage() +# EXPECTS: n/a +# REQUIRES: data_space2comma(), init_hc(), log_hc() +# +# @(#) HISTORY: +# @(#) 2013-05-17: initial version [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_aix_lppchk +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _VERSION="2013-05-17" # 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_space2comma "$*") +typeset _ARG="" +typeset _MSG="" +typeset _STC=0 + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + +# collect data +lppchk -v -m1 >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG} +(( $? == 0)) || return $? + +# perform check +if [[ -s ${HC_STDOUT_LOG} ]] +then + _MSG="lppchk detected errors {lppchk -v -m1}" + _STC=1 +else + _MSG="lppchk passed without errors" +fi + +# handle results +log_hc "$0" ${_STC} "${_MSG}" + +return 0 +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 +PURPOSE : Run {lppchk -v} + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/aix/check_aix_paths.sh b/sources/lib/platform/aix/check_aix_paths.sh new file mode 100644 index 0000000..5274989 --- /dev/null +++ b/sources/lib/platform/aix/check_aix_paths.sh @@ -0,0 +1,95 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_aix_paths.sh +#****************************************************************************** +# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_aix_paths +# DOES: see _show_usage() +# EXPECTS: n/a +# REQUIRES: data_space2comma(), init_hc(), log_hc() +# +# @(#) HISTORY: +# @(#) 2013-05-07: initial version [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_aix_paths +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _VERSION="2013-05-07" # 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_space2comma "$*") +typeset _ARG="" +typeset _MSG="" +typeset _STC=0 +typeset _PATH="" + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + +# collect data +lspath >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG} +(( $? == 0)) || return $? + +# perform check +_PATH=$(grep -v -c "Enabled" ${HC_STDOUT_LOG} 2>/dev/null) +case ${_PATH} in + 0) + _MSG="all paths are enabled" + ;; + *) + _MSG="failure in some paths detected {lspath}" + _STC=1 + ;; +esac + +# handle results +log_hc "$0" ${_STC} "${_MSG}" + +return 0 +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 +PURPOSE : Checks whether any hardware paths are missing {lspath} + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/aix/check_aix_root_crontab.sh b/sources/lib/platform/aix/check_aix_root_crontab.sh new file mode 100644 index 0000000..ae14ce4 --- /dev/null +++ b/sources/lib/platform/aix/check_aix_root_crontab.sh @@ -0,0 +1,113 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_aix_root_crontab +#****************************************************************************** +# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_aix_root_crontab +# DOES: see _show_usage() +# EXPECTS: n/a +# REQUIRES: data_space2comma(), init_hc(), log_hc() +# +# @(#) HISTORY: +# @(#) 2013-09-19: initial version [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_aix_root_crontab +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" +typeset _VERSION="2013-09-19" # 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_space2comma "$*") +typeset _ARG="" +typeset _MSG="" +typeset _STC=0 +typeset _CRON_ENTRY="" +typeset _CRON_MATCH=0 + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + + +# handle configuration file +[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}" +if [[ ! -r ${_CONFIG_FILE} ]] +then + warn "unable to read configuration file at ${_CONFIG_FILE}" + return 1 +fi + +# collect data +crontab -l >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG} + +# perform check +grep -v -E -e '^$' -e '^#' ${_CONFIG_FILE} 2>/dev/null | while read _CRON_ENTRY +do + _CRON_MATCH=$(grep -v '^#' ${HC_STDOUT_LOG} 2>/dev/null |\ + grep -c -E -e "${_CRON_ENTRY}") + case ${_CRON_MATCH} in + 0) + _MSG="'${_CRON_ENTRY}' is not configured in cron" + _STC=1 + ;; + 1) + _MSG="'${_CRON_ENTRY}' is configured in cron" + ;; + +([0-9])*([0-9])) + _MSG="'${_CRON_ENTRY}' is configured multiple times in cron" + ;; + esac + + # handle unit result + log_hc "$0" ${_STC} "${_MSG}" + _STC=0 +done + +return 0 +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 +PURPOSE : Checks the content of the 'root' user crontab for required entries + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/aix/check_aix_subsystems.sh b/sources/lib/platform/aix/check_aix_subsystems.sh new file mode 100644 index 0000000..f2cb6e2 --- /dev/null +++ b/sources/lib/platform/aix/check_aix_subsystems.sh @@ -0,0 +1,114 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_aix_subsystems.sh +#****************************************************************************** +# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_aix_subsystems +# DOES: see _show_usage() +# EXPECTS: see _show_usage() +# REQUIRES: data_space2comma(), init_hc(), log_hc() +# +# @(#) HISTORY: +# @(#) 2013-05-07: initial version [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_aix_subsystems +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" +typeset _VERSION="2013-05-07" # 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_space2comma "$*") +typeset _ARG="" +typeset _MSG="" +typeset _STC=0 +typeset _STATUS="" + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + + +# handle configuration file +[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}" +if [[ ! -r ${_CONFIG_FILE} ]] +then + warn "unable to read configuration file at ${_CONFIG_FILE}" + return 1 +fi + +# collect data +lssrc -a >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG} +(( $? == 0)) || return $? + +# perform check +grep -v -E -e '^$' -e '^#' ${_CONFIG_FILE} 2>/dev/null | while read _SUBSYS +do + _STATUS="$(grep -E -e ${_SUBSYS} ${HC_STDOUT_LOG} 2>/dev/null)" + case "${_STATUS}" in + *active*) + _MSG="${_SUBSYS} is running" + ;; + *inoperative*) + _MSG="${_SUBSYS} is not running" + _STC=1 + ;; + *) + _MSG="${_SUBSYS} is not on file" + ;; + esac + + # handle unit result + log_hc "$0" ${_STC} "${_MSG}" + _STC=0 +done + +return 0 +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 with: + subsys1 + subsys2 +PURPOSE : Checks whether subsystem(s) are active/operative {lssrc} + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/aix/check_aix_sysbackup.sh b/sources/lib/platform/aix/check_aix_sysbackup.sh new file mode 100644 index 0000000..501b4fe --- /dev/null +++ b/sources/lib/platform/aix/check_aix_sysbackup.sh @@ -0,0 +1,194 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_aix_sysbackup.sh +#****************************************************************************** +# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_aix_sysbackup +# DOES: see _show_usage() +# EXPECTS: see _show_usage() +# REQUIRES: data_space2comma(), init_hc(), log_hc() +# +# @(#) HISTORY: +# @(#) 2013-05-28: initial version [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_aix_sysbackup +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" +# mksysb identifier prefix of error code(s) +typeset _MKSYSB_NEEDLE="^0512" +typeset _VERSION="2013-05-28" # 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_space2comma "$*") +typeset _ARG="" +typeset _MSG="" +typeset _STC=0 +typeset _BACKUP_PATH="" +typeset _BACKUP_HOST="" +typeset _BACKUP_LOG="" +typeset _BACKUP_AGE=0 +typeset _MKSYSB_LOG="" +typeset _MKSYSB_CODE="" +typeset _COUNT=0 + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + +# handle configuration file +[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}" +if [[ ! -r ${_CONFIG_FILE} ]] +then + warn "unable to read configuration file at ${_CONFIG_FILE}" + return 1 +fi +# read required configuration values +_BACKUP_PATH=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'backup_path') +if [[ -z "${_BACKUP_PATH}" ]] +then + warn "ERROR: no value for the _BACKUP_PATH setting in ${_CONFIG_FILE}" + return 1 +fi +if [[ ! -d ${_BACKUP_PATH} ]] +then + warn "ERROR: ${_BACKUP_PATH} does not exist" + return 1 +fi +_MKSYSB_LOG=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'mksysb_log') +if [[ -z "${_MKSYSB_LOG}" ]] +then + warn "ERROR: no value for the _MKSYSB_LOG setting in ${_CONFIG_FILE}" + return 1 +fi +_BACKUP_AGE=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'backup_age') +case "${_BACKUP_AGE}" in + +([0-9])*(.)*([0-9])) + # numeric, OK + ;; + *) + # not numeric, set default + _BACKUP_AGE=14 + ;; +esac + +# perform state check on mksysb log files +ls -1 ${_BACKUP_PATH} | while read _BACKUP_HOST +do + _BACKUP_LOG="${_BACKUP_PATH}/${_BACKUP_HOST}/curr/${_MKSYSB_LOG}" + if [[ -r "${_BACKUP_LOG}" ]] + then + # read status from log file + _MKSYSB_CODE=$(grep -E -e "${_MKSYSB_NEEDLE}" ${_BACKUP_LOG} 2>/dev/null) + case "${_MKSYSB_CODE}" in + # 0512-038 mksysb: Backup Completed Successfully + 0512-038*) + _MSG="sysbackup status for ${_BACKUP_HOST}: completed successfully" + ;; + # 0512-003 mksysb may not have been able to archive some files + 0512-003*) + _MSG="sysbackup status for ${_BACKUP_HOST}: completed with warnings" + # save log + print "=== ${_BACKUP_HOST} ===" >>${HC_STDOUT_LOG} + cat ${_BACKUP_LOG} >>${HC_STDOUT_LOG} + ;; + *) + _MSG="sysbackup status for ${_BACKUP_HOST}: failed" + _STC=1 + print "=== ${_BACKUP_HOST} ===" >>${HC_STDOUT_LOG} + cat ${_BACKUP_LOG} >>${HC_STDOUT_LOG} + ;; + esac + else + # don't flag this as erroneous, we could drop into this fork for + # VIO servers for example without mksysb but having backupios instead + # caveat emptor: also means that hosts *without* backup go undetected + continue + fi + + # handle unit result + log_hc "$0" ${_STC} "${_MSG}" + _STC=0 +done + +# perform age check on mksysb log files +ls -1 ${_BACKUP_PATH} | while read _BACKUP_HOST +do + _BACKUP_LOG="${_BACKUP_PATH}/${_BACKUP_HOST}/curr/${_MKSYSB_LOG}" + if [[ -r "${_BACKUP_LOG}" ]] + then + _COUNT=$(find "${_BACKUP_LOG}" -mtime +${_BACKUP_AGE} | wc -l) + if (( _COUNT == 0 )) + then + _MSG="sysbackup age for ${_BACKUP_HOST}: <=${_BACKUP_AGE} days" + _STC=0 + else + _MSG="sysbackup age for ${_BACKUP_HOST}: >${_BACKUP_AGE} days" + _STC=1 + print "=== ${_BACKUP_HOST} ===" >>${HC_STDOUT_LOG} + print "age: $(ls -l ${_BACKUP_LOG})" >>${HC_STDOUT_LOG} + fi + else + # don't flag this as erroneous, we could drop into this fork for + # VIO servers for example without mksysb but having backupios instead + # caveat emptor: also means that hosts *without* backup go undetected + continue + fi + + # handle unit result + log_hc "$0" ${_STC} "${_MSG}" + _STC=0 +done + +return 0 +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 with: + backup_path= + mksysb_log= + backup_age= +PURPOSE : Checks the state of saved mksysb client backups (should typically be + run only on the NIM master or server that is acting as mksysb repo, + do NOT run on a typical client LPAR) + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/aix/check_aix_topasrec.sh b/sources/lib/platform/aix/check_aix_topasrec.sh new file mode 100644 index 0000000..03e440c --- /dev/null +++ b/sources/lib/platform/aix/check_aix_topasrec.sh @@ -0,0 +1,94 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_aix_topasrec.sh +#****************************************************************************** +# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_aix_topasrec +# DOES: see _show_usage() +# EXPECTS: n/a +# REQUIRES: data_space2comma(), init_hc(), log_hc() +# +# @(#) HISTORY: +# @(#) 2013-05-07: initial version [Patrick Van der Veken] +# @(#) 2013-08-16: comparison fix [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_aix_topasrec +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _VERSION="2013-08-16" # 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_space2comma "$*") +typeset _ARG="" +typeset _MSG="" +typeset _STC=0 +typeset _TOPAS=0 +typeset _NMON=0 + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + +# collect data +topasrec -l >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG} +(( $? == 0 )) || return $? + +# perform check +_TOPAS=$(grep -c "bin" ${HC_STDOUT_LOG} 2>/dev/null) +_NMON=$(grep -c "nmon" ${HC_STDOUT_LOG} 2>/dev/null) +_MSG="process checks: nmon=${_NMON}; topasrec=${_TOPAS}" +if (( _NMON != 1 || _TOPAS != 1 )) +then + _STC=1 +fi + +# handle results +log_hc "$0" ${_STC} "${_MSG}" + +return 0 +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 +PURPOSE : Checks on the active topasrec/nmon processes (only 1 should be running) + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/hp-ux/check_hpux_autopath.sh b/sources/lib/platform/hp-ux/check_hpux_autopath.sh new file mode 100644 index 0000000..e16dd32 --- /dev/null +++ b/sources/lib/platform/hp-ux/check_hpux_autopath.sh @@ -0,0 +1,118 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_hpux_autopath.sh +#****************************************************************************** +# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_hpux_autopath +# DOES: see _show_usage(). +# EXPECTS: n/a +# REQUIRES: data_space2comma(), init_hc(), log_hc() +# +# @(#) HISTORY: +# @(#) 2013-08-29: initial version [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_hpux_autopath +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _AUTOPATH_BIN="/sbin/autopath" +typeset _AUTOPATH_NEEDLE="Failed" +typeset _VERSION="2013-08-29" # 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_space2comma "$*") +typeset _ARG="" +typeset _MSG="" +typeset _STC=0 +typeset _STC_COUNT=0 +typeset _AUTOPATH_LINE="" +typeset _DEVICE="" + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + +# check autopath presence +if [[ ! -x ${_AUTOPATH_BIN} ]] +then + warn "${_AUTOPATH_BIN} is not installed here" + return 1 +fi + +# collect autopath info +log "collecting autopath information, this may take a while ..." +${_AUTOPATH_BIN} display >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG} +(( $? != 0 )) && { + _MSG="unable to run {${_AUTOPATH_BIN}}" + log_hc "$0" 1 "${_MSG}" + return 0 +} + +# check for device failures +grep -E -e "${_AUTOPATH_NEEDLE}" ${HC_STDOUT_LOG} 2>/dev/null |\ + while read _AUTOPATH_LINE +do + _DEVICE="$(print ${_AUTOPATH_LINE} | cut -f1 -d' ')" + _MSG="failed path for device '${_DEVICE}'" + _STC=1 + _STC_COUNT=$(( _STC_COUNT + 1 )) + + # handle unit result + log_hc "$0" ${_STC} "${_MSG}" + _STC=0 +done + +# report OK situation +if (( _STC_COUNT == 0 )) +then + _MSG="no failed paths detected by {${_AUTOPATH_BIN}}" + log_hc "$0" 0 "${_MSG}" +fi + +return 0 +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 +PURPOSE : Checks whether failed paths exist for StorageWorks disk arrays + using the 'autopath' utility. + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/hp-ux/check_hpux_file_age.sh b/sources/lib/platform/hp-ux/check_hpux_file_age.sh new file mode 100644 index 0000000..78b8f5b --- /dev/null +++ b/sources/lib/platform/hp-ux/check_hpux_file_age.sh @@ -0,0 +1,175 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_hpux_file_age.sh +#****************************************************************************** +# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_hpux_file_age +# DOES: see _show_usage() +# EXPECTS: see _show_usage() +# REQUIRES: data_space2comma(), init_hc(), log_hc() +# +# @(#) HISTORY: +# @(#) 2013-05-27: initial version [Patrick Van der Veken] +# @(#) 2013-05-29: added local trap for cleanup [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_hpux_file_age +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" +typeset _VERSION="2013-05-29" # 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_space2comma "$*") +typeset _ARG="" +typeset _MSG="" +typeset _STC=0 +typeset _REF_FILE="${TMP_DIR}/.$0.ref.$$" +typeset _DO_REF=0 +typeset _ENTRY="" +typeset _REF_TIME="" +typeset _AGE_CHECK=="" +typeset _FILE_PATH="" +typeset _FILE_AGE="" +typeset _FILE_NAME="" +typeset _FILE_DIR="" + +# set local trap for cleanup +trap "[[ -f ${_REF_FILE} ]] && rm -f ${_REF_FILE} >/dev/null 2>&1; return 1" 1 2 3 15 + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + +# handle configuration file +[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}" +if [[ ! -r ${_CONFIG_FILE} ]] +then + warn "unable to read configuration file at ${_CONFIG_FILE}" + return 1 +fi + +# perform check +cat ${_CONFIG_FILE} | grep -v -E -e '^$' -e '^#' | while read _ENTRY +do + # field split + _FILE_PATH=$(print "${_ENTRY%%;*}") + _FILE_AGE=$(print "${_ENTRY##*;}") + + # split file/dir + _FILE_NAME=$(print "${_FILE_PATH##*/}") + _FILE_DIR=$(print "${_FILE_PATH%/*}") + + # check config + if [ \( -z "${_FILE_PATH}" \) -a \( -z "${_FILE_AGE}" \) ] + then + warn "missing values in configuration file at ${_CONFIG_FILE}" + return 1 + fi + case "${_FILE_AGE}" in + +([0-9])*(.)*([0-9])) + # numeric, OK + ;; + *) + # not numeric + warn "invalid file age value '${_FILE_AGE}' in configuration file at ${_CONFIG_FILE}" + return 1 + ;; + esac + + # calculate reference timestamp & set reference file (once only) + if (( _DO_REF == 0 )) + then + REF_TIME=$(perl -e "use POSIX;\$t=time-(${_FILE_AGE}*60);print(strftime '%m%d%H%M',localtime(\$t))") + if (( $? != 0 )) + then + warn "failed to query reference time (Perl)" + return 1 + fi + touch -amt "${REF_TIME}" ${_REF_FILE} >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG} + if (( $? != 0 )) + then + warn "failed to create reference time ${TMP_DIR}" + return 1 + fi + _DO_REF=1 + fi +sleep 60 + # perform check + if [[ ! -r "${_FILE_PATH}" ]] + then + _MSG="unable to read or access requested file at ${_FILE_PATH}" + _STC=1 + else + # age check + AGE_CHECK=$(find "${_FILE_DIR}" -type f -name "${_FILE_NAME}" -newer ${_REF_FILE}) + if (( $? != 0 )) + then + warn "unable to execute file age test for ${_FILE_PATH}" + return 1 + fi + if [[ -z "${AGE_CHECK}" ]] + then + _MSG="file age of ${_FILE_AGE} has expired on ${_FILE_PATH}" + _STC=1 + else + _MSG="file age of ${_FILE_AGE} has not expired on ${_FILE_PATH}" + fi + fi + + # handle unit result + log_hc "$0" ${_STC} "${_MSG}" + _STC=0 +done + +# remove reference file +[[ -f ${_REF_FILE} ]] & rm -f ${_REF_FILE} >/dev/null 2>&1 + +return 0 +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 with: + ; +PURPOSE : Checks whether given files have been changed in the last n minutes + (requires perl!) + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/hp-ux/check_hpux_file_change.sh b/sources/lib/platform/hp-ux/check_hpux_file_change.sh new file mode 100644 index 0000000..26b689c --- /dev/null +++ b/sources/lib/platform/hp-ux/check_hpux_file_change.sh @@ -0,0 +1,373 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_hpux_file_change.sh +#****************************************************************************** +# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_hpux_file_change +# DOES: see _show_usage() +# EXPECTS: see _show_usage() +# REQUIRES: data_space2comma(), init_hc(), log_hc(), warn(), +# openssl (sha256 digest) OR cksum (CRC32 digest) +# +# @(#) HISTORY: +# @(#) 2017-05-18: initial version [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_hpux_file_change +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" +typeset _VERSION="2017-05-18" # 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_space2comma "$*") +typeset _ARG="" +typeset _MSG="" +typeset _STC=0 +typeset _STC_COUNT=0 +typeset _DO_META_CHECK=0 +typeset _CFG_STATE_FILE="" +typeset _STATE_FILE="" +typeset _STATE_FILE_LINE="" +typeset _FILE_TO_CHECK="" +typeset _EXCL_OBJECT="" +typeset _INCL_OBJECT="" +typeset _HAS_OPENSSL=0 +typeset _HAS_CKSUM=0 +typeset _OPENSSL_BIN="" +typeset _CKSUM_BIN="" +typeset _USE_OPENSSL=0 +typeset _USE_CKSUM=0 +typeset _TMP1_FILE="${TMP_DIR}/.$0.tmp1.$$" +typeset _TMP2_FILE="${TMP_DIR}/.$0.tmp2.$$" +typeset _TMP_INCL_FILE="${TMP_DIR}/.$0.tmp_incl.$$" +typeset _TMP_EXCL_FILE="${TMP_DIR}/.$0.tmp_excl.$$" +set -o noglob # no file globbing + +# set local trap for clean-up +trap "[[ -f ${_TMP1_FILE} ]] && rm -f ${_TMP1_FILE} >/dev/null 2>&1; + [[ -f ${_TMP2_FILE} ]] && rm -f ${_TMP2_FILE} >/dev/null 2>&1; + [[ -f ${_TMP_INCL_FILE} ]] && rm -f ${_TMP_INCL_FILE} >/dev/null 2>&1; + [[ -f ${_TMP_EXCL_FILE} ]] && rm -f ${_TMP_EXCL_FILE} >/dev/null 2>&1; + return 1" 1 2 3 15 + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + +# handle configuration file +[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}" +if [[ ! -r ${_CONFIG_FILE} ]] +then + warn "unable to read configuration file at ${_CONFIG_FILE}" + return 1 +fi +# read required configuration values +_CFG_STATE_FILE=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'state_file') +if [[ -z "${_CFG_STATE_FILE}" ]] +then + _STATE_FILE="${STATE_PERM_DIR}/discovered.file_change" +else + _STATE_FILE="${STATE_PERM_DIR}/${_CFG_STATE_FILE}" +fi +log "using state file ${_STATE_FILE}" +_DO_META_CHECK=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'do_meta_check') +case "${_DO_META_CHECK}" in + no|NO|No) + _DO_META_CHECK=0 + log "check for meta characters is disabled" + ;; + *) + _DO_META_CHECK=1 + log "check for meta characters is enabled" + ;; +esac + +# check for checksum tools +_OPENSSL_BIN="$(which openssl 2>>${HC_STDERR_LOG})" +[[ -x ${_OPENSSL_BIN} && -n "${_OPENSSL_BIN}" ]] && _HAS_OPENSSL=1 +_CKSUM_BIN="$(which cksum 2>>${HC_STDERR_LOG})" +[[ -x ${_CKSUM_BIN} && -n "${_CKSUM_BIN}" ]] && _HAS_CKSUM=1 +# prefer openssl (for sha256) +if (( _HAS_OPENSSL == 1 )) +then + _USE_OPENSSL=1 +elif (( _HAS_CKSUM == 1 )) +then + _USE_CKSUM=1 +else + warn "unable to find the 'openssl/cksum' tools" + return 1 +fi + +# check state file & TMP_FILEs +[[ -r ${_STATE_FILE} ]] || { + >${_STATE_FILE} + (( $? > 0 )) && { + warn "failed to create new state file at ${_STATE_FILE}" + return 1 + } + log "created new state file at ${_STATE_FILE}" +} +>${_TMP_INCL_FILE} +(( $? > 0 )) && { + warn "failed to create temporary file at ${_TMP_INCL_FILE}" + return 1 +} +>${_TMP_EXCL_FILE} +(( $? > 0 )) && { + warn "failed to create temporary file at ${_TMP_EXCL_FILE}" + return 1 +} +>${_TMP1_FILE} +(( $? > 0 )) && { + warn "failed to create temporary file at ${_TMP1_FILE}" + return 1 +} +>${_TMP2_FILE} +(( $? > 0 )) && { + warn "failed to create temporary file at ${_TMP2_FILE}" + return 1 +} + +# build list of configured objects: inclusion +grep -i '^incl:' ${_CONFIG_FILE} 2>/dev/null |\ + while IFS=':' read _DUMMY _INCL_OBJECT +do + # check for meta & globbing characters (*?[]{}|) + if (( _DO_META_CHECK == 1 )) + then + case "${_INCL_OBJECT}" in + *\**|*\?*|*\[*|*\]*|*\{*|*\}*|*\|*) + warn "meta characters are not supported in the entry (incl:${_INCL_OBJECT})" + continue + ;; + esac + fi + + # expand directories + if [[ -d ${_INCL_OBJECT} ]] + then + find ${_INCL_OBJECT} -type f -xdev >>${_TMP_INCL_FILE} 2>>${HC_STDERR_LOG} + else + print ${_INCL_OBJECT} >>${_TMP_INCL_FILE} + fi +done + +# build list of configured objects: exclusion +grep -i '^excl:' ${_CONFIG_FILE} 2>/dev/null |\ + while IFS=':' read _DUMMY _EXCL_OBJECT +do + # check for meta & globbing characters (*?[]{}|) + if (( _DO_META_CHECK == 1 )) + then + case "${_EXCL_OBJECT}" in + *\**|*\?*|*\[*|*\]*|*\{*|*\}*|*\|*) + warn "meta characters are not supported in the entry (excl:${_EXCL_OBJECT})" + continue + ;; + esac + fi + + # expand directories + if [[ -d ${_EXCL_OBJECT} ]] + then + find ${_EXCL_OBJECT} -type f -xdev >>${_TMP_EXCL_FILE} 2>>${HC_STDERR_LOG} + else + print ${_EXCL_OBJECT} >>${_TMP_EXCL_FILE} + fi +done + +# subtract exclusion from inclusion (exclusion has higher priority) +sort ${_TMP_INCL_FILE} -o ${_TMP_INCL_FILE} 2>>${HC_STDERR_LOG} +sort ${_TMP_EXCL_FILE} -o ${_TMP_EXCL_FILE} 2>>${HC_STDERR_LOG} +comm -23 ${_TMP_INCL_FILE} ${_TMP_EXCL_FILE} 2>>${HC_STDERR_LOG} >${_TMP1_FILE} + +# check discovered objects +while read _FILE_TO_CHECK +do + # reset variables + _STC=0 + _MSG="" + _IS_NEW=0 + + # object to check must be a file (and be present) + if [[ ! -f ${_FILE_TO_CHECK} ]] + then + _MSG="${_FILE_TO_CHECK} is not a file or has disappeared" + _STC=1 + log_hc "$0" ${_STC} "${_MSG}" + continue + fi + + # read entry from state file + _STATE_FILE_LINE=$(grep -E -e "^${_FILE_TO_CHECK}\|" ${_STATE_FILE}) + if [[ -n "${_STATE_FILE_LINE}" ]] + then + # field 1 is the file name + _STATE_FILE_TYPE=$(print "${_STATE_FILE_LINE}" | cut -f2 -d'|') + _STATE_FILE_CKSUM=$(print "${_STATE_FILE_LINE}" | cut -f3 -d'|') + else + _IS_NEW=1 + fi + + # compute new checksum (keep the same type as before) + if (( _IS_NEW == 0 )) + then + case "${_STATE_FILE_TYPE}" in + openssl-sha256) + if (( _USE_OPENSSL == 1 )) + then + _FILE_CKSUM=$(${_OPENSSL_BIN} dgst -sha256 ${_FILE_TO_CHECK} 2>>${HC_STDERR_LOG} | cut -f2 -d'=' | tr -d ' ') + _FILE_TYPE="openssl-sha256" + else + _MSG="cannot compute checksum [${_FILE_TYPE}] for ${_FILE_TO_CHECK}" + _STC=1 + fi + ;; + cksum-crc32) + if (( _USE_CKSUM == 1 )) + then + _FILE_CKSUM=$(${_CKSUM_BIN} ${_FILE_TO_CHECK} 2>>${HC_STDERR_LOG} | cut -f1 -d' ') + _FILE_TYPE="cksum-crc32" + else + _MSG="cannot compute checksum [${_FILE_TYPE}] for ${_FILE_TO_CHECK}" + _STC=1 + fi + ;; + *) + _MSG="cannot compute checksum (unknown checksum type) for ${_FILE_TO_CHECK}" + _STC=1 + ;; + esac + else + # new file + if (( _USE_OPENSSL == 1 )) + then + _FILE_CKSUM=$(${_OPENSSL_BIN} dgst -sha256 ${_FILE_TO_CHECK} 2>>${HC_STDERR_LOG} | cut -f2 -d'=' | tr -d ' ') + _FILE_TYPE="openssl-sha256" + elif (( _USE_CKSUM == 1 )) + then + _FILE_CKSUM=$(${_CKSUM_BIN} ${_FILE_TO_CHECK} 2>>${HC_STDERR_LOG} | cut -f1 -d' ') + _FILE_TYPE="cksum-crc32" + else + _MSG="cannot compute checksum (openssl/cksum) for ${_FILE_TO_CHECK}" + _STC=1 + fi + fi + + # check for failed checksums + if [[ -z "${_FILE_CKSUM}" ]] + then + _MSG="did not receive checksum (openssl/cksum) for ${_FILE_TO_CHECK}" + _STC=1 + fi + + # bounce failures back and jump to next file + if (( _STC != 0 )) + then + log_hc "$0" ${_STC} "${_MSG}" + continue + fi + + if (( _IS_NEW == 0 )) + then + # compare old vs new checksums + if [[ "${_STATE_FILE_CKSUM}" != "${_FILE_CKSUM}" ]] + then + _MSG="${_FILE_TO_CHECK} has a changed checksum [${_FILE_TYPE}]" + _STC=1 + else + _MSG="${_FILE_TO_CHECK} has the same checksum [${_FILE_TYPE}]" + _STC=0 + fi + else + _MSG="${_FILE_TO_CHECK} is a new file [${_FILE_TYPE}]" + _STC=0 + fi + + # save entry to temp file + printf "%s|%s|%s\n" "${_FILE_TO_CHECK}" "${_FILE_TYPE}" "${_FILE_CKSUM}" >>${_TMP2_FILE} + + # report with curr/exp values + log_hc "$0" ${_STC} "${_MSG}" "${_FILE_CKSUM}" "${_STATE_FILE_CKSUM}" +done <${_TMP1_FILE} + +# update state file (also if TMP2_FILE is empty) +if (( ARG_LOG != 0 )) +then + [[ -s ${_TMP2_FILE} ]] || { + warn "no files found to check, zeroing new state file" + } + mv ${_TMP2_FILE} ${_STATE_FILE} >/dev/null 2>&1 + (( $? > 0 )) && { + warn "failed to move temporary state file" + return 1 + } +fi + +# clean up temporary files +[[ -f ${_TMP1_FILE} ]] && rm -f ${_TMP1_FILE} >/dev/null 2>&1 +[[ -f ${_TMP2_FILE} ]] && rm -f ${_TMP2_FILE} >/dev/null 2>&1 +[[ -f ${_TMP_INCL_FILE} ]] && rm -f ${_TMP_INCL_FILE} >/dev/null 2>&1 +[[ -f ${_TMP_EXCL_FILE} ]] && rm -f ${_TMP_EXCL_FILE} >/dev/null 2>&1 + +return 0 +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 with: + incl: + excl: +PURPOSE : a KISS file integrity checker (like AIDE). Supports includes and excludes + of files and directories (automatically expanded). Excludes have a higher + priority than includes. Integrity checks will only be performed on files. + Will detect changed, new & deleted files (but not when deleted files + occur in an expanded directory tree). If you wish to detect deleted files: + use only direct file references in the configuration file. Uses by preference + openssl for hash calculation, with cksum as fall-back). + Updated and deleted files will cause a HC failure, new files will not. + CAVEAT EMPTOR: use only to check a relatively small number of files. + Processing a big number of files is likely to take + ages and probably will cause the plugin to time out + (see HC_TIME_OUT). YMMV. + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/hp-ux/check_hpux_fs_mounts.sh b/sources/lib/platform/hp-ux/check_hpux_fs_mounts.sh new file mode 100644 index 0000000..31c8536 --- /dev/null +++ b/sources/lib/platform/hp-ux/check_hpux_fs_mounts.sh @@ -0,0 +1,111 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_hpux_fs_mounts.sh +#****************************************************************************** +# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_hpux_fs_mounts +# DOES: see _show_usage() +# EXPECTS: n/a +# REQUIRES: data_space2comma(), init_hc(), log_hc() +# +# @(#) HISTORY: +# @(#) 2013-05-27: initial version [Patrick Van der Veken] +# @(#) 2016-04-04: exclude dump/swap spaces (...) [Patrick Van der Veken] +# @(#) 2016-07-04: fix for nfs exclusion [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_hpux_fs_mounts +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _VERSION="2016-07-04" # 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_space2comma "$*") +typeset _ARG="" +typeset _MSG="" +typeset _STC=0 +typeset _FS="" +typeset _FS_COUNT=0 + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + +# collect data (mount only) +mount >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG} +(( $? == 0)) || return $? + +# check for each auto-mount configured file system (except / and dump/swap) +grep -v -E -e '^#' -e '^$' \ + -e '[[:space:]]*\/[[:space:]]+' -e '\.\.\.' /etc/fstab 2>/dev/null |\ + awk '{print $2}' |\ +while read _FS +do + _FS_COUNT=$(grep -c -E -e "^${_FS}[ \t]+on.*[ \t]+" ${HC_STDOUT_LOG} 2>/dev/null) + case ${_FS_COUNT} in + 0) + _MSG="${_FS} is not mounted" + _STC=1 + ;; + 1) + _MSG="${_FS} is mounted" + ;; + *) + _MSG="${_FS} is multiple times mounted?" + ;; + esac + + # handle unit result + log_hc "$0" ${_STC} "${_MSG}" + _STC=0 +done + +# add /etc/fstab to STDOUT log +cat /etc/fstab >>${HC_STDOUT_LOG} + +return 0 +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 +PURPOSE : Checks whether file systems are mounted or not + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/hp-ux/check_hpux_fs_mounts_options.sh b/sources/lib/platform/hp-ux/check_hpux_fs_mounts_options.sh new file mode 100644 index 0000000..d0a574b --- /dev/null +++ b/sources/lib/platform/hp-ux/check_hpux_fs_mounts_options.sh @@ -0,0 +1,144 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_hpux_fs_mounts_options.sh +#****************************************************************************** +# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_hpux_fs_mounts_options +# DOES: see _show_usage() +# EXPECTS: see _show_usage() +# REQUIRES: data_space2comma(), init_hc(), log_hc() +# +# @(#) HISTORY: +# @(#) 2016-04-04: original version [Patrick Van der Veken] +# @(#) 2016-12-02: add support for ignore_missing_fs option [Patrick Van der Veken] +# @(#) 2017-07-31: added support for current/expected value output [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_hpux_fs_mounts_options +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" +typeset _VERSION="2017-07-31" # 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_space2comma "$*") +typeset _ARG="" +typeset _MSG="" +typeset _STC=0 +typeset _CONFIG_FS="" +typeset _CONFIG_OPTS="" +typeset _CURR_OPTS="" +typeset _DUMMY="" +typeset _IGNORE_FS="" +typeset _IS_ACTIVE=0 +typeset _FS_ENTRY="" +typeset _CFG_SORTED_OPTS="" +typeset _CURR_SORTED_OPTS="" + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + +# handle configuration file +[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}" +if [[ ! -r ${_CONFIG_FILE} ]] +then + warn "unable to read configuration file at ${_CONFIG_FILE}" + return 1 +fi +# read required configuration values +_IGNORE_FS=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'ignore_missing_fs') +if [[ -z "${_IGNORE_FS}" ]] +then + # default + _IGNORE_FS="yes" +fi + +# collect data (mount only) +mount >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG} +(( $? == 0)) || return $? + +# check for each configured file system +grep -i '^fs:' ${_CONFIG_FILE} 2>/dev/null |\ + while IFS=':' read _DUMMY _CONFIG_FS _CONFIG_OPTS +do + # check for active FS + _IS_ACTIVE=$(grep -c -E -e "^${_CONFIG_FS}[ \t].*" ${HC_STDOUT_LOG} 2>/dev/null) + if (( _IS_ACTIVE == 0 )) && [[ "${_IGNORE_FS}" = "yes" ]] + then + # ignore event + warn "${_CONFIG_FS} is not active, ignoring in the HC" + continue + else + # find needle in mount output + _FS_ENTRY=$(grep -E -e "^${_CONFIG_FS}[ \t]+on.*" ${HC_STDOUT_LOG} 2>/dev/null) + # get real mount options + _CURR_OPTS=$(print "${_FS_ENTRY}" | awk '{ print $4 }' | sed s'/dev=.*//g') + + # get real mount options: compressed & sorted (comma's + 'dev=' deleted) + _CURR_SORTED_OPTS=$(print "${_CURR_OPTS}" | tr -d ',' | sed 's/./&\n/g'| sort | tr -d '\n') + # get options to match: compressed & sorted (comma's deleted) + _CFG_SORTED_OPTS=$(print "${_CONFIG_OPTS}" | tr -d ',' | sed 's/./&\n/g'| sort | tr -d '\n') + + # compare strings (also flags FS that are not mounted) + if [[ "${_CURR_SORTED_OPTS}" != "${_CFG_SORTED_OPTS}" ]] + then + _MSG="${_CONFIG_FS} is not mounted with the correct options" + _STC=1 + else + _MSG="${_CONFIG_FS} is mounted with the correct options" + fi + fi + + # handle unit result + log_hc "$0" ${_STC} "${_MSG}" "${_CURR_OPTS}" "${_CONFIG_OPTS}" + _STC=0 +done + +return 0 +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 with formatted stanzas: + fs:: +PURPOSE : Checks whether file systems are mounted with correct options + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/hp-ux/check_hpux_guid_status.sh b/sources/lib/platform/hp-ux/check_hpux_guid_status.sh new file mode 100644 index 0000000..95eff47 --- /dev/null +++ b/sources/lib/platform/hp-ux/check_hpux_guid_status.sh @@ -0,0 +1,124 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_hpux_guid_status.sh +#****************************************************************************** +# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_hpux_guid_status +# DOES: see _show_usage() +# EXPECTS: n/a +# REQUIRES: data_space2comma(), init_hc(), log_hc() +# +# @(#) HISTORY: +# @(#) 2017-05-18: initial version [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_hpux_guid_status +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _VERSION="2017-05-18" # 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_space2comma "$*") +typeset _ARG="" +typeset _GUID_PID="" +typeset _MSG="" +typeset _STC=0 +typeset _RC=0 + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + +# ---- process state ---- +# 1) try using the PID way +if [[ -r "${_GUID_PID_FILE}" ]] +then + _GUID_PID=$(<${_GUID_PID_FILE}) + if [[ -n "${_GUID_PID}" ]] + then + # get PID list without heading + (( $(UNIX95= ps -o pid= -p ${_GUID_PID}| wc -l) == 0 )) && _STC=1 + else + # not running + _RC=1 + fi +else + _RC=1 +fi + +# 2) try the pgrep way (note: old pgreps do not support '-c') +if (( _RC != 0 )) +then + # we need guidkeyd & guidd + (( $(pgrep -P 1 -u root guidd 2>>${HC_STDERR_LOG} | wc -l) == 0 )) && _STC=1 + (( $(pgrep -P 1 -u root guidkeyd 2>>${HC_STDERR_LOG} | wc -l) == 0 )) && _STC=$(( _STC + 2 )) +fi + +# evaluate results +case ${_STC} in + 0) + _MSG="guidd/guidkeyd are running" + ;; + 1) + _MSG="guidd is not running" + ;; + 2) + _MSG="guidkeyd is not running" + ;; + 3) + _MSG="guidd/guidkeyd are not running" + ;; + *) + _MSG="could not determine status of GUID daemons" + ;; +esac + +# handle results +log_hc "$0" ${_STC} "${_MSG}" + +return 0 +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 +PURPOSE : Checks whether guid daemons (VSP GUID) are running + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/hp-ux/check_hpux_hpvm_vpar_status.sh b/sources/lib/platform/hp-ux/check_hpux_hpvm_vpar_status.sh new file mode 100644 index 0000000..b21df6b --- /dev/null +++ b/sources/lib/platform/hp-ux/check_hpux_hpvm_vpar_status.sh @@ -0,0 +1,182 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_hpux_hpvm_vpar_status.sh +#****************************************************************************** +# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_hpux_hpvm_vpar_status +# DOES: see _show_usage() +# EXPECTS: see _show_usage() +# REQUIRES: data_space2comma(), init_hc(), log_hc(), warn() +# +# @(#) HISTORY: +# @(#) 2017-06-01: initial version [Patrick Van der Veken] +# @(#) 2017-06-08: return 1 on error [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_hpux_hpvm_vpar_status +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" +typeset _HPVMSTATUS_BIN="/opt/hpvm/bin/hpvmstatus" +typeset _VERSION="2017-06-08" # 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_space2comma "$*") +typeset _ARG="" +typeset _LINE_COUNT=1 +typeset _PAR_ENTRY="" +typeset _PAR_ID="" +typeset _PAR_CFG_STATUS="" +typeset _PAR_RUN_STATUS="" +typeset _PAR_CFG_BOOT="" +typeset _PAR_RUN_BOOT="" +typeset _PAR_ENTRY="" +typeset _PAR_MATCH="" +typeset _MSG="" +typeset _STC=0 +typeset _RC=0 + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + +# check HPVM +if [[ ! -x ${_HPVMSTATUS_BIN} || -z "${_HPVMSTATUS_BIN}" ]] +then + warn "HPVM is not installed here" + return 1 +fi + +${_HPVMSTATUS_BIN} -M >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG} +(( $? != 0 )) && { + _MSG="unable to run {hpmvmstatus}" + log_hc "$0" 1 "${_MSG}" + return 0 +} + +# check configuration values +grep -v -E -e '^$' -e '^#' ${_CONFIG_FILE} 2>/dev/null | while read _PAR_ENTRY +do + # field split + _PAR_ID=$(print "${_PAR_ENTRY}" | cut -f1 -d';') + _PAR_CFG_STATUS=$(data_lc $(print "${_PAR_ENTRY}" | cut -f2 -d';')) + _PAR_CFG_BOOT=$(data_lc $(print "${_PAR_ENTRY}" | cut -f3 -d';')) + + # check configuration + case "${_PAR_ID}" in + +([0-9])*(.)*([0-9])) + # numeric, OK + ;; + *) + # not numeric + warn "invalid partition ID '${_PAR_ID}' in configuration file ${_CONFIG_FILE} at data line ${_LINE_COUNT}" + return 1 + ;; + esac + case "${_PAR_CFG_STATUS}" in + on|off) + ;; + *) + warn "invalid partition status '${_PAR_CFG_STATUS}' in configuration file ${_CONFIG_FILE} at data line ${_LINE_COUNT}" + return 1 + ;; + esac + case "${_PAR_CFG_BOOT}" in + auto|manual) + ;; + *) + warn "invalid partition boot value '${_PAR_CFG_BOOT}' in configuration file ${_CONFIG_FILE} at data line ${_LINE_COUNT}" + return 1 + ;; + esac + _LINE_COUNT=$(( _LINE_COUNT + 1 )) +done + +# perform checks +grep -v -E -e '^$' -e '^#' ${_CONFIG_FILE} 2>/dev/null | while read _PAR_ENTRY +do + # field split + _PAR_ID=$(print "${_PAR_ENTRY}" | cut -f1 -d';') + _PAR_CFG_STATUS=$(data_lc $(print "${_PAR_ENTRY}" | cut -f2 -d';')) + _PAR_CFG_BOOT=$(data_lc $(print "${_PAR_ENTRY}" | cut -f3 -d';')) + + # check run-time values (we need to make the needle sufficiently less greedy) + _PAR_MATCH=$(grep -i "^.*:.*:${_PAR_ID}::Integrity" ${HC_STDOUT_LOG} 2>/dev/null) + if [[ -n "${_PAR_MATCH}" ]] + then + # field split + _PAR_RUN_STATUS=$(data_lc $(print "${_PAR_MATCH}" | cut -f11 -d':')) + _PAR_RUN_BOOT=$(data_lc $(print "${_PAR_MATCH}" | cut -f12 -d':')) + + if [[ "${_PAR_RUN_STATUS}" = "${_PAR_CFG_STATUS}" ]] + then + _MSG="partition ${_PAR_ID} has a correct status [${_PAR_RUN_STATUS}]" + _STC=0 + else + _MSG="partition ${_PAR_ID} has a wrong status [${_PAR_RUN_STATUS}]" + _STC=1 + fi + log_hc "$0" ${_STC} "${_MSG}" "${_PAR_RUN_STATUS}" "${_PAR_CFG_STATUS}" + + if [[ "${_PAR_RUN_BOOT}" = "${_PAR_CFG_BOOT}" ]] + then + _MSG="partition ${_PAR_ID} has a correct boot flag [${_PAR_RUN_BOOT}]" + _STC=0 + else + _MSG="partition ${_PAR_ID} has a wrong boot flag [${_PAR_RUN_BOOT}]" + _STC=1 + fi + log_hc "$0" ${_STC} "${_MSG}" "${_PAR_RUN_BOOT}" "${_PAR_CFG_BOOT}" + else + warn "could not determine status for partition ${_PAR_ID} from command output {${_HPVMSTATUS_BIN}}" + _RC=1 + fi +done + +return ${_RC} +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 with: + ;; +PURPOSE : Checks the status of vPars (on a VSP) + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/hp-ux/check_hpux_httpd_status.sh b/sources/lib/platform/hp-ux/check_hpux_httpd_status.sh new file mode 100644 index 0000000..382a201 --- /dev/null +++ b/sources/lib/platform/hp-ux/check_hpux_httpd_status.sh @@ -0,0 +1,133 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_hpux_httpd_status.sh +#****************************************************************************** +# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_hpux_httpd_status +# DOES: see _show_usage() +# EXPECTS: n/a +# REQUIRES: data_space2comma(), init_hc(), log_hc() +# +# @(#) HISTORY: +# @(#) 2017-04-23: initial version [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_hpux_httpd_status +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _HTTPD_PID_FILE="/var/run/httpd/httpd.pid" +typeset _VERSION="2017-04-23" # 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_space2comma "$*") +typeset _ARG="" +typeset _HTTPD_CHECKCONF_BIN="" +typeset _HTTPD_PID="" +typeset _MSG="" +typeset _STC=0 +typeset _RC=0 + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + +# ---- process state ---- +# 1) try using the PID way +if [[ -r "${_HTTPD_PID_FILE}" ]] +then + _HTTPD_PID=$(<${_HTTPD_PID_FILE}) + if [[ -n "${_HTTPD_PID}" ]] + then + # get PID list without heading + (( $(UNIX95= ps -o pid= -p ${_HTTPD_PID}| wc -l) == 0 )) && _STC=1 + else + # not running + _RC=1 + fi +else + _RC=1 +fi + +# 2) try the pgrep way (note: old pgreps do not support '-c') +if (( _RC != 0 )) +then + (( $(pgrep -u root httpd 2>>${HC_STDERR_LOG} | wc -l) == 0 )) && _STC=1 +fi + +# evaluate results +case ${_STC} in + 0) + _MSG="httpd is running" + ;; + 1) + _MSG="httpd is not running" + ;; + *) + _MSG="could not determine status of httpd" + ;; +esac +log_hc "$0" ${_STC} "${_MSG}" + +# ---- config state ---- +_HTTPD_BIN="$(which httpd 2>>${HC_STDERR_LOG})" +if [[ -x ${_HTTPD_BIN} && -n "${_HTTPD_BIN}" ]] +then + # validate main configuration + ${_HTTPD_BIN} -t >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG} + if (( $? == 0 )) + then + _MSG="httpd configuration files are syntactically correct" + _STC=0 + else + _MSG="httpd configuration files have syntax error(s) {httpd -s}" + _STC=1 + fi + log_hc "$0" ${_STC} "${_MSG}" +fi + +return 0 +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 +PURPOSE : Checks whether httpd (apache) is running + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/hp-ux/check_hpux_ignite_backup.sh b/sources/lib/platform/hp-ux/check_hpux_ignite_backup.sh new file mode 100644 index 0000000..c6de787 --- /dev/null +++ b/sources/lib/platform/hp-ux/check_hpux_ignite_backup.sh @@ -0,0 +1,199 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_hpux_ignite_backup.sh +#****************************************************************************** +# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_hpux_ignite_backup +# DOES: see _show_usage() +# EXPECTS: see _show_usage() +# REQUIRES: data_space2comma(), init_hc(), log_hc() +# +# @(#) HISTORY: +# @(#) 2013-05-28: initial version [Patrick Van der Veken] +# @(#) 2016-05-26: added a simple exclusion list for hosts as configurable +# @(#) parameter [Patrick Van der Veken] +# @(#) 2016-06-03: small fix [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_hpux_ignite_backup +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" +# backup DONE identifier +typeset _IGNITE_NEEDLE="^DONE" +typeset _VERSION="2016-06-03" # 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_space2comma "$*") +typeset _ARG="" +typeset _MSG="" +typeset _STC=0 +typeset _BACKUP_AGE=0 +typeset _EXCLUDE_HOSTS="" +typeset _IGNITE_HOST="" +typeset _IGNITE_LOG="" +typeset _IGNITE_STATUS="" +typeset _COUNT=0 +typeset _OLD_PWD="" + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + +# handle configuration file +[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}" +if [[ ! -r ${_CONFIG_FILE} ]] +then + warn "unable to read configuration file at ${_CONFIG_FILE}" + return 1 +fi +# read required configuration values +_BACKUP_AGE=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'backup_age') +case "${_BACKUP_AGE}" in + +([0-9])*(.)*([0-9])) + # numeric, OK + ;; + *) + # not numeric, set default + _BACKUP_AGE=14 + ;; +esac +log "backup age to check: ${_BACKUP_AGE} days" +_EXCLUDE_HOSTS=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'exclude_hosts') +[[ -n "${_EXCLUDE_HOSTS}" ]] && log "excluding hosts: $(print ${_EXCLUDE_HOSTS})" + +# perform check on Ignite 'client_status' files +if [[ -d /var/opt/ignite/clients ]] +then + _OLD_PWD="$(pwd)" + cd /var/opt/ignite/clients + + # check backup states + find * -prune -type l | while read _IGNITE_HOST + do + # check exclude + [[ "${_EXCLUDE_HOSTS#*${_IGNITE_HOST}}" != "${_EXCLUDE_HOSTS}" ]] && continue + _IGNITE_LOG="${_IGNITE_HOST}/recovery/client_status" + if [[ -r "${_IGNITE_LOG}" ]] + then + # read status from log file + _IGNITE_STATUS=$(grep -E -e "${_IGNITE_NEEDLE}" ${_IGNITE_LOG} 2>/dev/null) + case "${_IGNITE_STATUS}" in + *Complete*) + _MSG="ignite backup status for ${_IGNITE_HOST}: completed successfully" + ;; + *Warning*) + _MSG="ignite backup status for ${_IGNITE_HOST}: completed with warnings" + # save log + print "=== ${_IGNITE_HOST} ===" >>${HC_STDOUT_LOG} + cat ${_IGNITE_LOG} >>${HC_STDOUT_LOG} + ;; + *Error*) + _MSG="ignite backup status for ${_IGNITE_HOST}: failed" + _STC=1 + # save log + print "=== ${_IGNITE_HOST} ===" >>${HC_STDOUT_LOG} + cat ${_IGNITE_LOG} >>${HC_STDOUT_LOG} + ;; + *) + _MSG="ignite backup status for ${_IGNITE_HOST}: failed" + _STC=1 + # save log + print "=== ${_IGNITE_HOST} ===" >>${HC_STDOUT_LOG} + cat ${_IGNITE_LOG} >>${HC_STDOUT_LOG} + ;; + esac + else + _MSG="ignite backup status for ${_IGNITE_HOST}: unknown" + _STC=1 + fi + + # handle unit result + log_hc "$0" ${_STC} "${_MSG}" + _STC=0 + done + + # check backup ages + find * -prune -type l | while read _IGNITE_HOST + do + # check exclude + [[ "${_EXCLUDE_HOSTS#*${_IGNITE_HOST}}" != "${_EXCLUDE_HOSTS}" ]] && continue + _IGNITE_LOG="${_IGNITE_HOST}/recovery/client_status" + if [[ -r "${_IGNITE_LOG}" ]] + then + _COUNT=$(find "${_IGNITE_LOG}" -mtime +${_BACKUP_AGE} | wc -l) + if (( _COUNT == 0 )) + then + _MSG="ignite backup age for ${_IGNITE_HOST}: <=${_BACKUP_AGE} days" + _STC=0 + else + _MSG="ignite backup age for ${_IGNITE_HOST}: >${_BACKUP_AGE} days" + _STC=1 + print "=== ${_IGNITE_HOST} ===" >>${HC_STDOUT_LOG} + print "age: $(ls -l ${_IGNITE_LOG})" >>${HC_STDOUT_LOG} + fi + else + _MSG="ignite backup age for ${_IGNITE_HOST}: unknown" + _STC=1 + fi + + # handle unit result + log_hc "$0" ${_STC} "${_MSG}" + _STC=0 + done + + cd "${_OLD_PWD}" +else + _MSG="Host is not an Ignite/UX server" + log_hc "$0" ${_STC} "${_MSG}" +fi + +return 0 +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 with: + backup_age= +PURPOSE : Checks the state and age of saved Ignite-UX client backups (should only be + run only on the Ignite-UX server). Backups with warnings are considered + to OK. Backups older than $backup_age will not pass the health check. + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/hp-ux/check_hpux_ioscan.sh b/sources/lib/platform/hp-ux/check_hpux_ioscan.sh new file mode 100644 index 0000000..19209eb --- /dev/null +++ b/sources/lib/platform/hp-ux/check_hpux_ioscan.sh @@ -0,0 +1,193 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_hpux_ioscan.sh +#****************************************************************************** +# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_hpux_ioscan +# DOES: see _show_usage() +# EXPECTS: see _show_usage() +# REQUIRES: data_space2comma(), init_hc(), log_hc(), warn() +# +# @(#) HISTORY: +# @(#) 2013-08-28: initial version [Patrick Van der Veken] +# @(#) 2013-08-29: more verbosity & kernel_mode setting [Patrick Van der Veken] +# @(#) 2016-06-08: introduced _AGILE_VIEW parameter [Patrick Van der Veken] +# @(#) 2016-12-01: more standardized error handling [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_hpux_ioscan +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" +typeset _IOSCAN_BIN="/usr/sbin/ioscan" +typeset _IOSCAN_OPTS="-Fn" +typeset _VERSION="2016-12-01" # 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_space2comma "$*") +typeset _ARG="" +typeset _MSG="" +typeset _STC=0 +typeset _STC_COUNT=0 +typeset _CLASS_LINE="" +typeset _IOSCAN_CLASSES="" +typeset _AGILE_VIEW="" +typeset _KERNEL_MODE="" +typeset _IOSCAN_LINE="" +typeset _HW_CLASS="" +typeset _HW_PATH="" +typeset _HW_STATE="" + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + +# handle configuration file +[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}" +if [[ ! -r ${_CONFIG_FILE} ]] +then + warn "unable to read configuration file at ${_CONFIG_FILE}" + return 1 +fi +# read required configuration values +_CLASS_LINE=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'ioscan_classes') +if [[ -z "${_CLASS_LINE}" ]] +then + # default + _IOSCAN_CLASSES="ctl|diag|disk|ext_bus|fc|fcp|i2o|ipmi|lan|lvm|olar|${DEBUG_OPTS}vm" +else + # convert comma's + _IOSCAN_CLASSES="$(print ${_CLASS_LINE} | tr -s ',' '|' | tr -d '\"')" +fi +_KERNEL_MODE=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'kernel_mode') +if [[ -z "${_KERNEL_MODE}" ]] +then + # default + _KERNEL_MODE="yes" +fi +_AGILE_VIEW=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'agile_view') +if [[ -z "${_AGILE_VIEW}" ]] +then + # default + _AGILE_VIEW="yes" +fi + +# check and get ioscan stuff +if [[ ! -x ${_IOSCAN_BIN} ]] +then + warn "${_IOSCAN_BIN} is not installed here" + return 1 +else + log "collecting ioscan information, this is may take a while ..." + if [[ "${_KERNEL_MODE}" = "yes" ]] && [[ "${_AGILE_VIEW}" = "yes" ]] + then + _IOSCAN_OPTS="${_IOSCAN_OPTS}Nk" + fi + if [[ "${_KERNEL_MODE}" = "yes" ]] && [[ "${_AGILE_VIEW}" = "no" ]] + then + _IOSCAN_OPTS="${_IOSCAN_OPTS}k" + fi + if [[ "${_KERNEL_MODE}" = "no" ]] && [[ "${_AGILE_VIEW}" = "yes" ]] + then + _IOSCAN_OPTS="${_IOSCAN_OPTS}Nu" + fi + if [[ "${_KERNEL_MODE}" = "no" ]] && [[ "${_AGILE_VIEW}" = "no" ]] + then + _IOSCAN_OPTS="${_IOSCAN_OPTS}u" + fi + log "executing ioscan with options: ${_IOSCAN_OPTS}" + ioscan "${_IOSCAN_OPTS}" >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG} + if (( $? != 0 )) + then + _MSG="unable to gather ioscan information" + log_hc "$0" 1 "${_MSG}" + return 0 + fi +fi + +# check for requested device classes +grep -E -e ".*:.*:.*:.*:.*:.*:.*:.*:${_IOSCAN_CLASSES}:.*" ${HC_STDOUT_LOG} 2>/dev/null |\ + while read _IOSCAN_LINE +do + # possible states are: CLAIMED, UNCLAIMED, DIFF_HW, NO_HW, ERROR, SCAN + _HW_CLASS="$(print ${_IOSCAN_LINE} | cut -f9 -d':')" + _HW_PATH="$(print ${_IOSCAN_LINE} | cut -f11 -d':')" + _HW_STATE="$(print ${_IOSCAN_LINE} | cut -f16 -d':')" + + case "${_HW_STATE}" in + NO_HW) + _MSG="detected NO_HW for device on path '${_HW_PATH}', class '${_HW_CLASS}'" + _STC=1 + _STC_COUNT=$(( _STC_COUNT + 1 )) + ;; + ERROR) + _MSG="detected ERROR for device on HW path '${_HW_PATH}', class '${_HW_CLASS}'" + _STC=1 + _STC_COUNT=$(( _STC_COUNT + 1 )) + ;; + *) + # everything else is considered non-fatal (do not report) + continue + esac + + # handle unit result + log_hc "$0" ${_STC} "${_MSG}" + _STC=0 +done + +# report OK situation +if (( _STC_COUNT == 0 )) +then + _MSG="no problems detected by {${_IOSCAN_BIN}}" + log_hc "$0" 0 "${_MSG}" +fi + +return 0 +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 with: + ioscan_classes= + kernel_mode= + agile_view= +PURPOSE : Checks whether 'ioscan' returns errors or not (NO_HW, ERROR) + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/hp-ux/check_hpux_named_status.sh b/sources/lib/platform/hp-ux/check_hpux_named_status.sh new file mode 100644 index 0000000..6a0a044 --- /dev/null +++ b/sources/lib/platform/hp-ux/check_hpux_named_status.sh @@ -0,0 +1,135 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_hpux_named_status.sh +#****************************************************************************** +# @(#) Copyright (C) 2016 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_hpux_named_status +# DOES: see _show_usage() +# EXPECTS: n/a +# REQUIRES: data_space2comma(), init_hc(), log_hc() +# +# @(#) HISTORY: +# @(#) 2017-01-07: initial version [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_hpux_named_status +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _NAMED_PID_FILE="/var/run/named/named.pid" +typeset _VERSION="2017-01-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 _NAMED_CHECKCONF_BIN="" +typeset _NAMED_PID="" +typeset _ARGS=$(data_space2comma "$*") +typeset _ARG="" +typeset _MSG="" +typeset _STC=0 +typeset _RC=0 + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + +# ---- process state ---- +# 1) try using the PID way +if [[ -r "${_NAMED_PID_FILE}" ]] +then + _NAMED_PID=$(<${_NAMED_PID_FILE}) + if [[ -n "${_NAMED_PID}" ]] + then + # get PID list without heading + (( $(UNIX95= ps -o pid= -p ${_NAMED_PID}| wc -l) == 0 )) && _STC=1 + else + # not running + _RC=1 + fi +else + _RC=1 +fi + +# 2) try the pgrep way (note: old pgreps do not support '-c') +if (( _RC != 0 )) +then + (( $(pgrep -u root named 2>>${HC_STDERR_LOG} | wc -l) == 0 )) && _STC=1 +fi + +# evaluate results +case ${_STC} in + 0) + _MSG="named is running" + ;; + 1) + _MSG="named is not running" + ;; + *) + _MSG="could not determine status of named" + ;; +esac +log_hc "$0" ${_STC} "${_MSG}" + +# ---- config state ---- +_NAMED_CHECKCONF_BIN="$(which named-checkconf 2>>${HC_STDERR_LOG})" +if [[ -x ${_NAMED_CHECKCONF_BIN} && -n "${_NAMED_CHECKCONF_BIN}" ]] +then + # validate main configuration and test load zones + ${_NAMED_CHECKCONF_BIN} -z >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG} + if (( $? == 0 )) + then + _MSG="named & zones configuration files are syntactically correct" + _STC=0 + else + _MSG="named configuration and/or zone files have syntax error(s) {named-checkconf -z}" + _STC=1 + fi + log_hc "$0" ${_STC} "${_MSG}" +fi + +return 0 +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 +PURPOSE : Checks whether named (BIND) service is running and whether the named + zone files are syntactically correct. + +EOT + +return 0 +} + + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/hp-ux/check_hpux_ntp_status.sh b/sources/lib/platform/hp-ux/check_hpux_ntp_status.sh new file mode 100644 index 0000000..cdc1c92 --- /dev/null +++ b/sources/lib/platform/hp-ux/check_hpux_ntp_status.sh @@ -0,0 +1,153 @@ +#!/usr/bin/env ksh +#------------------------------------------------------------------------------ +# @(#) check_hpux_ntp_status +#------------------------------------------------------------------------------ +# @(#) Copyright (C) 2016 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#------------------------------------------------------------------------------ +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_hpux_ntp_status +# DOES: see _show_usage() +# EXPECTS: see _show_usage() +# REQUIRES: data_space2comma(), init_hc(), log_hc(), warn() +# +# @(#) HISTORY: +# @(#) 2016-12-01: initial version [Patrick Van der Veken] +# @(#) 2016-12-29: added threshold & config file [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#------------------------------------------------------------------------------ + +# ----------------------------------------------------------------------------- +function check_hpux_ntp_status +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" +typeset _VERSION="2016-12-29" # YYYY-MM-DD +typeset _SUPPORTED_PLATFORMS="HP-UX" # uname -s match +typeset _NTPQ_BIN="/usr/sbin/ntpq" +# ------------------------- CONFIGURATION ends here --------------------------- + +# set defaults +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS} +init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}" +typeset _ARGS=$(data_space2comma "$*") +typeset _ARG="" +typeset _MSG="" +typeset _STC=0 +typeset _CURR_OFFSET=0 +typeset _MAX_OFFSET=0 +typeset _NTP_PEER="" + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + +# handle config file +[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}" +if [[ ! -r ${_CONFIG_FILE} ]] +then + warn "unable to read configuration file at ${_CONFIG_FILE}" + return 1 +fi +# read required config values +_MAX_OFFSET=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'max_offset') +if [[ -z "${_MAX_OFFSET}" ]] +then + # default + _MAX_OFFSET=500 +fi + +# check & get NTP status +if [[ ! -x ${_NTPQ_BIN} ]] +then + warn "${_NTPQ_BIN} is not installed here" + return 1 +else + ${_NTPQ_BIN} -np 2>>${HC_STDERR_LOG} >>${HC_STDOUT_LOG} + # RC is always 0 +fi + +#------------------------------------------------------------------------------ +# evaluate ntpq results +#------------------------------------------------------------------------------ + +# 1) active server +_NTP_PEER="$(grep -E -e '^\*' 2>/dev/null ${HC_STDOUT_LOG} | awk '{ print $1 }')" +case ${_NTP_PEER} in + \*127.127.1.0*) + _MSG="NTP is synchronizing against its internal clock" + _STC=1 + ;; + \*[0-9]*) + # some valid server + _MSG="NTP is synchronizing against ${_NTP_PEER##*\*}" + ;; + *) + _MSG="NTP is not synchronizing or NTP daemon is not running" + _STC=1 + ;; +esac +log_hc "$0" ${_STC} "${_MSG}" + +# 2) offset value +if (( _STC == 0 )) +then + _CURR_OFFSET="$(grep -E -e '^\*' 2>/dev/null ${HC_STDOUT_LOG} | awk '{ print $9 }')" + case ${_CURR_OFFSET} in + +([-0-9])*(.)*([0-9])) + # numeric, OK (negatives are OK too!) + if (( $(awk -v c="${_CURR_OFFSET}" -v m="${_MAX_OFFSET}" 'BEGIN { print (c>m) }') != 0 )) + then + _MSG="NTP offset of ${_CURR_OFFSET} is bigger than the configured maximum of ${_MAX_OFFSET}" + _STC=1 + else + _MSG="NTP offset of ${_CURR_OFFSET} is within the acceptable range" + fi + log_hc "$0" ${_STC} "${_MSG}" + ;; + *) + # not numeric + warn "invalid offset value of ${_CURR_OFFSET} found for ${NTP_PEER}?" + return 1 + ;; + esac +fi + +return 0 +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 +PURPOSE : Checks the status of NTP synchronization + +EOT + +return 0 +} + + +#------------------------------------------------------------------------------ +# END of script +#------------------------------------------------------------------------------ diff --git a/sources/lib/platform/hp-ux/check_hpux_ovpa_status.sh b/sources/lib/platform/hp-ux/check_hpux_ovpa_status.sh new file mode 100644 index 0000000..c7d3a8f --- /dev/null +++ b/sources/lib/platform/hp-ux/check_hpux_ovpa_status.sh @@ -0,0 +1,123 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_hpux_ovpa_status +#****************************************************************************** +# @(#) Copyright (C) 2016 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_hpux_ovpa_status +# DOES: see _show_usage() +# EXPECTS: n/a +# REQUIRES: data_space2comma(), init_hc(), log_hc(), warn() +# +# @(#) HISTORY: +# @(#) 2016-04-08: initial version [Patrick Van der Veken] +# @(#) 2016-12-01: more standardized error handling [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_hpux_ovpa_status +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _VERSION="2016-12-01" # YYYY-MM-DD +typeset _SUPPORTED_PLATFORMS="HP-UX" # uname -s match +typeset _OVPA_BIN="/opt/perf/bin/perfstat" +# ------------------------- CONFIGURATION ends here --------------------------- + +# set defaults +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS} +init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}" +typeset _ARGS=$(data_space2comma "$*") +typeset _ARG="" +typeset _MSG="" +typeset _STC=0 +typeset _OVPA_MATCH=0 +typeset _OVPA_VERSION="" +typeset _OVPA_DAEMONS="" + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + +# check & get ovpa status +if [[ ! -x ${_OVPA_BIN} ]] +then + warn "${_OVPA_BIN} is not installed here" + return 1 +else + ${_OVPA_BIN} -p >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG} + # no RC check here because perfstat will throw <>0 when procs are down +fi + +# get ovpa version (<12.x: scopeux; >=12.x: oacore, no coda) +_OVPA_VERSION="$(${_OVPA_BIN} -v 2>>${HC_STDERR_LOG} | grep "HP Performance Agent" | awk '{ print $NF }')" +case "${_OVPA_VERSION}" in + 12.*) + log "running HP Operations Agent v12 ..." + _OVPA_DAEMONS="oacore midaemon perfalarm ttd ovcd ovbbccb" + ;; + *) + log "running HP Operations Agent v11 or lower ..." + _OVPA_DAEMONS="scopeux midaemon perfalarm ttd ovcd ovbbccb coda" + ;; +esac + +# do OVPA status checks +for _OVPA_DAEMON in ${_OVPA_DAEMONS} +do + # anchored grep here! + _OVPA_MATCH=$(grep -c -E -e "[ \t]*Running[ \t]*${_OVPA_DAEMON}" 2>/dev/null ${HC_STDOUT_LOG}) + case ${_OVPA_MATCH} in + 0) + _MSG="${_OVPA_DAEMON} is not running" + _STC=1 + ;; + *) + _MSG="${_OVPA_DAEMON} is running" + ;; + esac + + # handle unit result + log_hc "$0" ${_STC} "${_MSG}" + _STC=0 +done + +return 0 +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 +PURPOSE : Checks the status of OVPA processes (OpenView Performance Agent) + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/hp-ux/check_hpux_postfix_status.sh b/sources/lib/platform/hp-ux/check_hpux_postfix_status.sh new file mode 100644 index 0000000..29cb6f4 --- /dev/null +++ b/sources/lib/platform/hp-ux/check_hpux_postfix_status.sh @@ -0,0 +1,95 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_hpux_postfix_status.sh +#****************************************************************************** +# @(#) Copyright (C) 2016 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_hpux_postfix_status +# DOES: see _show_usage() +# EXPECTS: n/a +# REQUIRES: data_space2comma(), init_hc(), log_hc() +# +# @(#) HISTORY: +# @(#) 2016-12-01: initial version [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_hpux_postfix_status +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _VERSION="2016-12-01" # 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_space2comma "$*") +typeset _ARG="" +typeset _POSTFIX_BIN="" +typeset _MSG="" +typeset _STC=0 + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + +_POSTFIX_BIN="$(which postfix 2>>${HC_STDERR_LOG})" +if [[ -x ${_POSTFIX_BIN} && -n "${_POSTFIX_BIN}" ]] +then + ${_POSTFIX_BIN} status >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG} + if (( $? == 0 )) + then + _MSG="postfix is running" + else + _MSG="postfix is not running" + _STC=1 + fi +else + warn "postfix is not installed here" + return 1 +fi + +# handle results +log_hc "$0" ${_STC} "${_MSG}" + +return 0 +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 +PURPOSE : Checks whether postfix (mail system) is running + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/hp-ux/check_hpux_root_crontab.sh b/sources/lib/platform/hp-ux/check_hpux_root_crontab.sh new file mode 100644 index 0000000..b423807 --- /dev/null +++ b/sources/lib/platform/hp-ux/check_hpux_root_crontab.sh @@ -0,0 +1,112 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_hpux_root_crontab +#****************************************************************************** +# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_hpux_root_crontab +# DOES: see _show_usage() +# EXPECTS: n/a +# REQUIRES: data_space2comma(), init_hc(), log_hc() +# +# @(#) HISTORY: +# @(#) 2013-09-19: initial version [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_hpux_root_crontab +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" +typeset _VERSION="2013-09-09" # YYYY-MM-DD +typeset _SUPPORTED_PLATFORMS="HP-UX" # uname -s match +# ------------------------- CONFIGURATION ends here --------------------------- + +# set defaults +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS} +init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}" +typeset _ARGS=$(data_space2comma "$*") +typeset _ARG="" +typeset _MSG="" +typeset _STC=0 +typeset _CRON_ENTRY="" +typeset _CRON_MATCH=0 + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + +# handle configuration file +[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}" +if [[ ! -r ${_CONFIG_FILE} ]] +then + warn "unable to read configuration file at ${_CONFIG_FILE}" + return 1 +fi + +# collect data +crontab -l >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG} + +# perform check +grep -v -E -e '^$' -e '^#' ${_CONFIG_FILE} 2>/dev/null | while read _CRON_ENTRY +do + _CRON_MATCH=$(grep -v '^#' ${HC_STDOUT_LOG} 2>/dev/null |\ + grep -c -E -e "${_CRON_ENTRY}") + case ${_CRON_MATCH} in + 0) + _MSG="'${_CRON_ENTRY}' is not configured in cron" + _STC=1 + ;; + 1) + _MSG="'${_CRON_ENTRY}' is configured in cron" + ;; + +([0-9])*([0-9])) + _MSG="'${_CRON_ENTRY}' is configured multiple times in cron" + ;; + esac + + # handle unit result + log_hc "$0" ${_STC} "${_MSG}" + _STC=0 +done + +return 0 +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 +PURPOSE : Checks the content of the 'root' crontab for required entries + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/hp-ux/check_hpux_sg_cluster_config.sh b/sources/lib/platform/hp-ux/check_hpux_sg_cluster_config.sh new file mode 100644 index 0000000..64016e7 --- /dev/null +++ b/sources/lib/platform/hp-ux/check_hpux_sg_cluster_config.sh @@ -0,0 +1,191 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_hpux_sg_cluster_config +#****************************************************************************** +# @(#) Copyright (C) 2016 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_hpux_sg_cluster_status +# DOES: see _show_usage() +# EXPECTS: see _show_usage() +# REQUIRES: data_space2comma(), init_hc(), log_hc(), warn() +# +# @(#) HISTORY: +# @(#) 2016-03-08: initial version [Patrick Van der Veken] +# @(#) 2016-12-01: more standardized error handling [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_hpux_sg_cluster_config +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" +typeset _VERSION="2016-12-01" # YYYY-MM-DD +typeset _SUPPORTED_PLATFORMS="HP-UX" # uname -s match +typeset _SG_DAEMON="/usr/lbin/cmcld" +# rubbish that cmgetconf outputs to STDOUT instead of STDERR +typeset _SG_CMGETCONF_FILTER="Permission denied|Number of configured" +# ------------------------- CONFIGURATION ends here --------------------------- + +# set defaults +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS} +init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}" +typeset _ARGS=$(data_space2comma "$*") +typeset _ARG="" +typeset _MSG="" +typeset _STC=0 +typeset _CLUSTER_RUN_FILE="${TMP_DIR}/.$0.cluster_run.$$" +typeset _CLUSTER_CFG_FILE="${TMP_DIR}/.$0.cluster_cfg.$$" +typeset _CLUSTER_INSTANCE="" +typeset _CLUSTER_INSTANCES="" +typeset _CLUSTER_ENTRY="" +typeset _CLUSTER_CFG_ENTRY="" +typeset _CLUSTER_MATCH="" +typeset _CLUSTER_PARAM="" +typeset _CLUSTER_VALUE="" + +# set local trap for cleanup +trap "rm -f ${_CLUSTER_RUN_FILE}.* ${_CLUSTER_CFG_FILE}.* >/dev/null 2>&1; return 1" 1 2 3 15 + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + +# handle configuration file +[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}" +if [[ ! -r ${_CONFIG_FILE} ]] +then + warn "unable to read configuration file at ${_CONFIG_FILE}" + return 1 +fi + +# look for cluster instance names +grep -E -e '^\[' ${_CONFIG_FILE} 2>/dev/null | cut -f1 -d']' | cut -f2 -d'[' |\ +while read _CLUSTER_INSTANCE +do + _CLUSTER_INSTANCES="${_CLUSTER_INSTANCES} ${_CLUSTER_INSTANCE}" +done +if [[ -z "${_CLUSTER_INSTANCES}" ]] +then + warn "no cluster information configured in ${_CONFIG_FILE}" + return 1 +fi + +# check serviceguard status & gather cluster information from running cluster (compressed lines) +if [[ ! -x ${_SG_DAEMON} ]] +then + warn "${_SG_DAEMON} is not installed here" + return 1 +else + for _CLUSTER_INSTANCE in ${_CLUSTER_INSTANCES} + do + cmgetconf -c ${_CLUSTER_INSTANCE} 2>>${HC_STDERR_LOG} |\ + grep -v -E -e "${_SG_CMGETCONF_FILTER}" | tr -d ' \t' >${_CLUSTER_RUN_FILE}.${_CLUSTER_INSTANCE} + [[ -s ${_CLUSTER_RUN_FILE}.${_CLUSTER_INSTANCE} ]] || { + _MSG="unable to gather cluster configuration" + log_hc "$0" 1 "${_MSG}" + return 0 + } + done +fi + +# gather cluster information from healthcheck configuration +for _CLUSTER_INSTANCE in ${_CLUSTER_INSTANCES} +do + awk -v cluster="${_CLUSTER_INSTANCE}" ' + BEGIN { found = 0; needle = "^\["cluster"\]" } + + # skip blank lines + /^\s*$/ { next; } + # skip comment lines + /^#/ { next; } + + # end marker + ( $0 ~ /^\[.*\]/ && found ) { + found = 0; + } + # start marker + $0 ~ needle { + found = 1; + }; + # stanza body + ( found && $0 !~ /^\[.*\]/ ) { + # print non-compressed and compressed version + printf "%s|", $0; + gsub(" |\t", "", $0); + printf "%s\n", $0; + }' < ${_CONFIG_FILE} 2>>${HC_STDERR_LOG} >${_CLUSTER_CFG_FILE}.${_CLUSTER_INSTANCE} +done + +# do cluster configuration checks (using the compressed strings) +for _CLUSTER_INSTANCE in ${_CLUSTER_INSTANCES} +do + while read _CLUSTER_ENTRY + do + # split entry to get the compressed version + _CLUSTER_CFG_ENTRY=$(print "${_CLUSTER_ENTRY}" | cut -f2 -d'|') + # get parameter name from non-compressed version + _CLUSTER_PARAM=$(print "${_CLUSTER_ENTRY}" | cut -f1 -d'|' | awk '{ print $1 }') + # get parameter value from non-compressed version + _CLUSTER_VALUE=$(print "${_CLUSTER_ENTRY}" | cut -f1 -d'|' | awk '{ print substr($2,1,30)}') + # is it present? + _CLUSTER_MATCH=$(grep -c "${_CLUSTER_CFG_ENTRY}" ${_CLUSTER_RUN_FILE}.${_CLUSTER_INSTANCE} 2>/dev/null) + if (( _CLUSTER_MATCH == 0 )) + then + # get parameter name from non-compressed version + _MSG="'${_CLUSTER_PARAM} (${_CLUSTER_VALUE} ...)' is not correctly configured for ${_CLUSTER_INSTANCE}" + _STC=1 + else + _MSG="'${_CLUSTER_PARAM} (${_CLUSTER_VALUE} ...)' is configured for ${_CLUSTER_INSTANCE}" + fi + + # handle unit result + log_hc "$0" ${_STC} "${_MSG}" + _STC=0 + done <${_CLUSTER_CFG_FILE}.${_CLUSTER_INSTANCE} +done + +# remove working files +rm -f ${_CLUSTER_RUN_FILE}.* ${_CLUSTER_CFG_FILE}.* >/dev/null 2>&1 + +return 0 +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 +PURPOSE : Checks the configuration of Serviceguard cluster (SG 11.16+) (comparing + serialized strings from the plugin configuration file to the running cluster + configuration) + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/hp-ux/check_hpux_sg_cluster_status.sh b/sources/lib/platform/hp-ux/check_hpux_sg_cluster_status.sh new file mode 100644 index 0000000..07f274c --- /dev/null +++ b/sources/lib/platform/hp-ux/check_hpux_sg_cluster_status.sh @@ -0,0 +1,135 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_hpux_sg_cluster_status +#****************************************************************************** +# @(#) Copyright (C) 2016 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_hpux_sg_cluster_status +# DOES: see _show_usage() +# EXPECTS: see _show_usage() +# REQUIRES: data_space2comma(), init_hc(), log_hc(), warn() +# +# @(#) HISTORY: +# @(#) 2016-03-25: initial version [Patrick Van der Veken] +# @(#) 2016-12-01: more standardized error handling [Patrick Van der Veken] +# @(#) 2017-05-07: made checks more detailed for log_hc() [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_hpux_sg_cluster_status +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" +typeset _VERSION="2017-05-07" # YYYY-MM-DD +typeset _SUPPORTED_PLATFORMS="HP-UX" # uname -s match +typeset _SG_DAEMON="/usr/lbin/cmcld" +# ------------------------- CONFIGURATION ends here --------------------------- + +# set defaults +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS} +init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}" +typeset _ARGS=$(data_space2comma "$*") +typeset _ARG="" +typeset _MSG="" +typeset _STC=0 +typeset _SG_ENTRY="" +typeset _SG_MATCH="" +typeset _SG_CFG_PARAM="" +typeset _SG_RUN_PARAM="" +typeset _SG_CFG_VALUE="" +typeset _SG_RUN_VALUE="" + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + +# handle configuration file +[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}" +if [[ ! -r ${_CONFIG_FILE} ]] +then + warn "unable to read configuration file at ${_CONFIG_FILE}" + return 1 +fi + +# check & get serviceguard status +if [[ ! -x ${_SG_DAEMON} ]] +then + warn "${_SG_DAEMON} is not installed here" + return 1 +else + cmviewcl -v -f line 2>>${HC_STDERR_LOG} | tr '|' ':' >>${HC_STDOUT_LOG} + (( $? != 0 )) && { + _MSG="unable to run 'cmviewcl'" + log_hc "$0" 1 "${_MSG}" + return 0 + } +fi + +# do cluster status checks +# (replace ':' by '|' for cmcviewcl output) +grep -v -E -e '^$' -e '^#' ${_CONFIG_FILE} 2>/dev/null | tr '|' ':' | while read _SG_ENTRY +do + # field split + _SG_CFG_PARAM="$(print ${_SG_ENTRY} | cut -f1 -d'=')" # field 1 + _SG_CFG_VALUE="$(print ${_SG_ENTRY} | cut -f2 -d'=')" # field 2 + + # check run-time values (anchored grep here!) + _SG_MATCH=$(grep -i "^${_SG_CFG_PARAM}" ${HC_STDOUT_LOG} 2>/dev/null) + if [[ -n "${_SG_MATCH}" ]] + then + _SG_RUN_VALUE=$(print "${_SG_MATCH}" | cut -f2 -d'=') # field 2 + + if [[ "${_SG_CFG_VALUE}" = "${_SG_RUN_VALUE}" ]] + then + _MSG="cluster parameter ${_SG_CFG_PARAM} has a correct value [${_SG_RUN_VALUE}]" + _STC=0 + else + _MSG="cluster parameter ${_SG_CFG_PARAM} has a wrong value [${_SG_RUN_VALUE}]" + _STC=1 + fi + log_hc "$0" ${_STC} "${_MSG}" "${_SG_RUN_VALUE}" "${_SG_CFG_VALUE}" + else + warn "could not determine status for ${_SG_CFG_PARAM} from command output {cmviewcl}" + fi +done + +return 0 +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 +PURPOSE : Checks the status of Serviceguard cluster parameters (SG 11.16+) + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/hp-ux/check_hpux_sg_package_config.sh b/sources/lib/platform/hp-ux/check_hpux_sg_package_config.sh new file mode 100644 index 0000000..21e33ed --- /dev/null +++ b/sources/lib/platform/hp-ux/check_hpux_sg_package_config.sh @@ -0,0 +1,191 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_hpux_sg_package_config +#****************************************************************************** +# @(#) Copyright (C) 2016 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_hpux_sg_package_config +# DOES: see _show_usage() +# EXPECTS: see _show_usage() +# REQUIRES: data_space2comma(), init_hc(), log_hc(), warn() +# +# @(#) HISTORY: +# @(#) 2016-03-08: initial version [Patrick Van der Veken] +# @(#) 2016-12-01: more standardized error handling [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_hpux_sg_package_config +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" +typeset _VERSION="2016-12-01" # YYYY-MM-DD +typeset _SUPPORTED_PLATFORMS="HP-UX" # uname -s match +typeset _SG_DAEMON="/usr/lbin/cmcld" +# rubbish that cmgetconf outputs to STDOUT instead of STDERR +typeset _SG_CMGETCONF_FILTER="Permission denied|Number of configured" +# ------------------------- CONFIGURATION ends here --------------------------- + +# set defaults +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS} +init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}" +typeset _ARGS=$(data_space2comma "$*") +typeset _ARG="" +typeset _MSG="" +typeset _STC=0 +typeset _PKG_RUN_FILE="${TMP_DIR}/.$0.pkg_run.$$" +typeset _PKG_CFG_FILE="${TMP_DIR}/.$0.pkg_cfg.$$" +typeset _PKG_INSTANCE="" +typeset _PKG_INSTANCES="" +typeset _PKG_ENTRY="" +typeset _PKG_CFG_ENTRY="" +typeset _PKG_MATCH="" +typeset _PKG_PARAM="" +typeset _PKG_VALUE="" + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + +# set local trap for cleanup +trap "rm -f ${_PKG_RUN_FILE}.* ${_PKG_CFG_FILE}.* >/dev/null 2>&1; return 1" 1 2 3 15 + +# handle configuration file +[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}" +if [[ ! -r ${_CONFIG_FILE} ]] +then + warn "unable to read configuration file at ${_CONFIG_FILE}" + return 1 +fi + +# look for package instance names +grep -E -e '^\[' ${_CONFIG_FILE} 2>/dev/null | cut -f1 -d']' | cut -f2 -d'[' |\ +while read _PKG_INSTANCE +do + _PKG_INSTANCES="${_PKG_INSTANCES} ${_PKG_INSTANCE}" +done +if [[ -z "${_PKG_INSTANCES}" ]] +then + warn "no package information configured in ${_CONFIG_FILE}" + return 1 +fi + +# check serviceguard status & gather package information from running cluster (compressed lines) +if [[ ! -x ${_SG_DAEMON} ]] +then + warn "${_SG_DAEMON} is not installed here" + return 1 +else + for _PKG_INSTANCE in ${_PKG_INSTANCES} + do + cmgetconf -p ${_PKG_INSTANCE} -v 0 2>>${HC_STDERR_LOG} |\ + grep -v -E -e "${_SG_CMGETCONF_FILTER}" | tr -d ' \t' >${_PKG_RUN_FILE}.${_PKG_INSTANCE} + [[ -s ${_PKG_RUN_FILE}.${_PKG_INSTANCE} ]] || { + _MSG="unable to gather package configuration for at least one cluster package" + log_hc "$0" 1 "${_MSG}" + return 0 + } + done +fi + +# gather package information from healthcheck configuration +for _PKG_INSTANCE in ${_PKG_INSTANCES} +do + awk -v package="${_PKG_INSTANCE}" ' + BEGIN { found = 0; needle = "^\["package"\]" } + + # skip blank lines + /^\s*$/ { next; } + # skip comment lines + /^#/ { next; } + + # end marker + ( $0 ~ /^\[.*\]/ && found ) { + found = 0; + } + # start marker + $0 ~ needle { + found = 1; + }; + # stanza body + ( found && $0 !~ /^\[.*\]/ ) { + # print non-compressed and compressed version + printf "%s|", $0; + gsub(" |\t", "", $0); + printf "%s\n", $0; + }' < ${_CONFIG_FILE} 2>>${HC_STDERR_LOG} >${_PKG_CFG_FILE}.${_PKG_INSTANCE} +done + +# do package configuration checks (using the compressed strings) +for _PKG_INSTANCE in ${_PKG_INSTANCES} +do + while read _PKG_ENTRY + do + # split entry to get the compressed version + _PKG_CFG_ENTRY=$(print "${_PKG_ENTRY}" | cut -f2 -d'|') + # get parameter name from non-compressed version + _PKG_PARAM=$(print "${_PKG_ENTRY}" | awk '{ print $1 }') + # get parameter value from non-compressed version + _PKG_VALUE=$(print "${_PKG_ENTRY}" | cut -f1 -d'|' | awk '{ print substr($2,1,30)}') + # is it present? + _PKG_MATCH=$(grep -c "${_PKG_CFG_ENTRY}" ${_PKG_RUN_FILE}.${_PKG_INSTANCE} 2>/dev/null) + if (( _PKG_MATCH == 0 )) + then + # get parameter name from non-compressed version + _MSG="'${_PKG_PARAM} (${_PKG_VALUE} ...)' is not correctly configured for ${_PKG_INSTANCE}" + _STC=1 + else + _MSG="'${_PKG_PARAM} (${_PKG_VALUE} ...)' is configured for ${_PKG_INSTANCE}" + fi + + # handle unit result + log_hc "$0" ${_STC} "${_MSG}" + _STC=0 + done <${_PKG_CFG_FILE}.${_PKG_INSTANCE} +done + +# remove working files +rm -f ${_PKG_RUN_FILE}.* ${_PKG_CFG_FILE}.* >/dev/null 2>&1 + +return 0 +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 +PURPOSE : Checks the configuration of Serviceguard packages (SG 11.16+) (comparing + serialized strings from the HC configuration file to the running cluster + configuration) + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/hp-ux/check_hpux_sg_package_status.sh b/sources/lib/platform/hp-ux/check_hpux_sg_package_status.sh new file mode 100644 index 0000000..dbc3b76 --- /dev/null +++ b/sources/lib/platform/hp-ux/check_hpux_sg_package_status.sh @@ -0,0 +1,137 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_hpux_sg_package_status +#****************************************************************************** +# @(#) Copyright (C) 2016 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_hpux_sg_package_status +# DOES: see _show_usage() +# EXPECTS: see _show_usage() +# REQUIRES: data_space2comma(), init_hc(), log_hc(), warn() +# +# @(#) HISTORY: +# @(#) 2016-03-08: initial version [Patrick Van der Veken] +# @(#) 2016-12-01: more standardized error handling [Patrick Van der Veken] +# @(#) 2017-05-07: made checks more detailed for log_hc() [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_hpux_sg_package_status +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" +typeset _VERSION="2017-07-05" # YYYY-MM-DD +typeset _SUPPORTED_PLATFORMS="HP-UX" # uname -s match +typeset _SG_DAEMON="/usr/lbin/cmcld" +# ------------------------- CONFIGURATION ends here --------------------------- + +# set defaults +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS} +init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}" +typeset _ARGS=$(data_space2comma "$*") +typeset _ARG="" +typeset _MSG="" +typeset _STC=0 +typeset _SG_ENTRY="" +typeset _SG_MATCH="" +typeset _SG_PACKAGE="" +typeset _SG_CFG_PARAM="" +typeset _SG_RUN_PARAM="" +typeset _SG_CFG_VALUE="" +typeset _SG_RUN_VALUE="" + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + +# handle configuration file +[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}" +if [[ ! -r ${_CONFIG_FILE} ]] +then + warn "unable to read configuration file at ${_CONFIG_FILE}" + return 1 +fi + +# check & get serviceguard status +if [[ ! -x ${_SG_DAEMON} ]] +then + warn "${_SG_DAEMON} is not installed here" + return 1 +else + cmviewcl -v -f line -l package 2>>${HC_STDERR_LOG} | tr '|' ':' >>${HC_STDOUT_LOG} + (( $? != 0)) && { + _MSG="unable to run 'cmviewcl'" + log_hc "$0" 1 "${_MSG}" + return 0 + } +fi + +# do package status checks +# (replace ':' by '|' for cmcviewcl output) +grep -v -E -e '^$' -e '^#' ${_CONFIG_FILE} 2>/dev/null | tr '|' ':' | while read _SG_ENTRY +do + # field split + _SG_PACKAGE="$(print ${_SG_ENTRY} | cut -f1 -d':')" + _SG_CFG_PARAM="$(print ${_SG_ENTRY} | cut -f2- -d':' | cut -f1 -d'=')" # field 2-,1 + _SG_CFG_VALUE="$(print ${_SG_ENTRY} | cut -f2- -d':' | cut -f2 -d'=')" # field 2-,2 + + # check run-time values (anchored grep here!) + _SG_MATCH=$(grep -i "^package:${_SG_PACKAGE}:${_SG_CFG_PARAM}" ${HC_STDOUT_LOG} 2>/dev/null) + if [[ -n "${_SG_MATCH}" ]] + then + _SG_RUN_VALUE=$(print "${_SG_MATCH}" | cut -f3- -d':' | cut -f2 -d'=') # field3-,2 + + if [[ "${_SG_CFG_VALUE}" = "${_SG_RUN_VALUE}" ]] + then + _MSG="package ${_SG_PACKAGE} parameter ${_SG_CFG_PARAM} has a correct value [${_SG_RUN_VALUE}]" + _STC=0 + else + _MSG="package ${_SG_PACKAGE} parameter ${_SG_CFG_PARAM} has a wrong value [${_SG_RUN_VALUE}]" + _STC=1 + fi + log_hc "$0" ${_STC} "${_MSG}" "${_SG_RUN_VALUE}" "${_SG_CFG_VALUE}" + else + warn "could not determine status for ${_SG_PACKAGE}/${_SG_CFG_PARAM} from command output {cmviewcl}" + fi +done + +return 0 +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 +PURPOSE : Checks the status of Serviceguard package parameters (SG 11.16+) + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/hp-ux/check_hpux_sg_qs_status.sh b/sources/lib/platform/hp-ux/check_hpux_sg_qs_status.sh new file mode 100644 index 0000000..07cf7cf --- /dev/null +++ b/sources/lib/platform/hp-ux/check_hpux_sg_qs_status.sh @@ -0,0 +1,113 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_hpux_sg_qs_status.sh +#****************************************************************************** +# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_hpux_sg_qs_status +# DOES: see _show_usage() +# EXPECTS: n/a +# REQUIRES: data_space2comma(), init_hc(), log_hc() +# +# @(#) HISTORY: +# @(#) 2017-05-01: initial version [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_hpux_sg_qs_status +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _VERSION="2017-05-01" # YYYY-MM-DD +typeset _SUPPORTED_PLATFORMS="HP-UX" # uname -s match +typeset _QS_BIN="/usr/lbin/qsc" +typeset _QS_AUTH_FILE="/etc/cmcluster/qs_authfile" +# ------------------------- CONFIGURATION ends here --------------------------- + +# set defaults +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS} +init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}" +typeset _ARGS=$(data_space2comma "$*") +typeset _ARG="" +typeset _MSG="" +typeset _STC=0 +typeset _RC=0 + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + +# check QS presence +if [[ ! -x ${_QS_BIN} ]] +then + warn "${_QS_BIN} is not installed here" + return 1 +fi + +# ---- process state ---- +(( $(pgrep -u root -f ${_QS_BIN} 2>>${HC_STDERR_LOG} | wc -l) == 0 )) && _STC=1 + +# evaluate results +case ${_STC} in + 0) + _MSG="QS is running" + ;; + 1) + _MSG="QS is not running" + ;; + *) + _MSG="could not determine status of QS" + ;; +esac +log_hc "$0" ${_STC} "${_MSG}" + +# ---- config state ---- +if [[ -s ${_QS_AUTH_FILE} ]] +then + _MSG="QS authorizations file has been configured" + _STC=0 +else + _MSG="QS authorizations file is missing or empty (${_QS_AUTH_FILE})" + _STC=1 +fi +log_hc "$0" ${_STC} "${_MSG}" + +return 0 +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 +PURPOSE : Checks whether the Serviceguard quorum server is running + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/hp-ux/check_hpux_sshd_status.sh b/sources/lib/platform/hp-ux/check_hpux_sshd_status.sh new file mode 100644 index 0000000..457c39e --- /dev/null +++ b/sources/lib/platform/hp-ux/check_hpux_sshd_status.sh @@ -0,0 +1,117 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_hpux_sshd_status.sh +#****************************************************************************** +# @(#) Copyright (C) 2016 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_hpux_sshd_status +# DOES: see _show_usage() +# EXPECTS: n/a +# REQUIRES: data_space2comma(), init_hc(), log_hc() +# +# @(#) HISTORY: +# @(#) 2017-04-01: initial version [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_hpux_sshd_status +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _SSHD_PID_FILE="/var/run/sshd/sshd.pid" +typeset _VERSION="2017-04-01" # 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_space2comma "$*") +typeset _ARG="" +typeset _SSHD_PID="" +typeset _MSG="" +typeset _STC=0 +typeset _RC=0 + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + +# ---- process state ---- +# 1) try using the PID way +if [[ -r "${_SSHD_PID_FILE}" ]] +then + _SSHD_PID=$(<${_SSHD_PID_FILE}) + if [[ -n "${_SSHD_PID}" ]] + then + # get PID list without heading + (( $(UNIX95= ps -o pid= -p ${_SSHD_PID}| wc -l) == 0 )) && _STC=1 + else + # not running + _RC=1 + fi +else + _RC=1 +fi + +# 2) try the pgrep way (note: old pgreps do not support '-c') +if (( _RC != 0 )) +then + (( $(pgrep -P 1 -u root sshd 2>>${HC_STDERR_LOG} | wc -l) == 0 )) && _STC=1 +fi + +# evaluate results +case ${_STC} in + 0) + _MSG="sshd is running" + ;; + 1) + _MSG="sshd is not running" + ;; + *) + _MSG="could not determine status of sshd" + ;; +esac + +# handle results +log_hc "$0" ${_STC} "${_MSG}" + +return 0 +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 +PURPOSE : Checks whether sshd (Secure Shell daemon) is running + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/hp-ux/check_hpux_syslog.sh b/sources/lib/platform/hp-ux/check_hpux_syslog.sh new file mode 100644 index 0000000..858d4fe --- /dev/null +++ b/sources/lib/platform/hp-ux/check_hpux_syslog.sh @@ -0,0 +1,173 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_hpux_syslog.sh +#****************************************************************************** +# @(#) Copyright (C) 2016 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_hpux_syslog +# DOES: see _show_usage() +# EXPECTS: see _show_usage() +# REQUIRES: data_space2comma(), init_hc(), log_hc() +# +# @(#) HISTORY: +# @(#) 2016-06-20: initial version [Patrick Van der Veken] +# @(#) 2017-05-18: do not update the state file with --no-log [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_hpux_syslog +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" +typeset _STATE_FILE="${STATE_PERM_DIR}/discovered.syslog" +typeset _VERSION="2017-05-18" # 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_space2comma "$*") +typeset _ARG="" +typeset _MSG="" +typeset _STC=0 +typeset _STC_COUNT=0 +typeset _TMP_FILE="${TMP_DIR}/.$0.tmp.$$" +typeset _CLASSES_LINE="" +typeset _SYSLOG_FILE="" +typeset _SYSLOG_CLASSES="" + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + +# set local trap for cleanup +trap "[[ -f ${_TMP_FILE} ]] && rm -f ${_TMP_FILE} >/dev/null 2>&1; return 1" 1 2 3 15 + +# handle configuration file +[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}" +if [[ ! -r ${_CONFIG_FILE} ]] +then + warn "unable to read configuration file at ${_CONFIG_FILE}" + return 1 +fi +# read required configuration values +_SYSLOG_FILE=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'syslog_file') +if [[ -z "${_SYSLOG_FILE}" ]] +then + # default + _SYSLOG_FILE="/var/adm/syslog/syslog.log" +fi +_CLASSES_LINE=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'syslog_classes') +if [[ -z "${_CLASSES_LINE}" ]] +then + # default (mind the complex regex!, support facility[PID]) + _SYSLOG_CLASSES="vmunix(\[[0-9]+\])?:" +else + # convert comma's (mind the complex regex!, support facility[PID]) + _SYSLOG_CLASSES=$(print "${_CLASSES_LINE}" | sed 's/,/(\\[[0-9]+\\])\?:\|/g') + # add PID qualifier to last item + _SYSLOG_CLASSES="${_SYSLOG_CLASSES}(\[[0-9]+\])?:" +fi + +# check SYSLOG file +[[ -r ${_SYSLOG_FILE} ]] || _MSG="SYSLOG file ${_SYSLOG_FILE} cannot be found" +if [[ -n "${_MSG}" ]] +then + # handle results + log_hc "$0" 1 "${_MSG}" + return 0 +fi + +# check state file +[[ -r ${_STATE_FILE} ]] || { + print "## this file is not date sorted! Do not edit manually!" >${_STATE_FILE} + (( $? > 0 )) && { + warn "failed to create new state file at ${_STATE_FILE}" + return 1 + } + log "created new state file at ${_STATE_FILE}" +} + +# filter current SYSLOG messages (must be uniquely sorted for 'comm') +log "searching SYSLOG with filter: ${_SYSLOG_CLASSES}" +grep -E -e "${_SYSLOG_CLASSES}" ${_SYSLOG_FILE} | sort -u >${_TMP_FILE} 2>/dev/null + +# compare results to already discovered messages +comm -13 ${_STATE_FILE} ${_TMP_FILE} 2>/dev/null | sed 's/^ //g' >${HC_STDOUT_LOG} + +# report results +_STC_COUNT=$(wc -l ${HC_STDOUT_LOG} 2>/dev/null | cut -f1 -d' ') +if (( _STC_COUNT > 0 )) +then + _MSG="found ${_STC_COUNT} new SYSLOG messages" + _STC=1 + # add results to state file (must be sorted; re-use TMP_FILE) + sort -u ${HC_STDOUT_LOG} ${_STATE_FILE} >${_TMP_FILE} + (( $? > 0 )) && { + warn "failed to sort temporary state file" + return 1 + } + if (( ARG_LOG != 0 )) + then + mv ${_TMP_FILE} ${_STATE_FILE} >/dev/null 2>&1 + (( $? > 0 )) && { + warn "failed to move temporary state file" + return 1 + } + fi +else + _MSG="no new SYSLOG messages found" +fi + +# handle results +log_hc "$0" ${_STC} "${_MSG}" + +# clean up temporary files +[[ -f ${_TMP_FILE} ]] && rm -f ${_TMP_FILE} >/dev/null 2>&1 + +return 0 +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 with: + syslog_file= + syslog_classes= +PURPOSE : Provides a KISS syslog monitor (keep tracks of already discovered messages in + a state file and compares new lines in SYSLOG to the ones kept in the + state file. The plugin will sort both state & SYSLOG data before doing + the comparison. + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/hp-ux/check_hpux_vg_minor_number.sh b/sources/lib/platform/hp-ux/check_hpux_vg_minor_number.sh new file mode 100644 index 0000000..4d0c9a7 --- /dev/null +++ b/sources/lib/platform/hp-ux/check_hpux_vg_minor_number.sh @@ -0,0 +1,103 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_hpux_vg_minor_number +#****************************************************************************** +# @(#) Copyright (C) 2016 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_hpux_vg_minor_number +# DOES: see _show_usage() +# EXPECTS: n/a +# REQUIRES: data_space2comma(), init_hc(), log_hc() +# +# @(#) HISTORY: +# @(#) 2016-04-28: initial version [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_hpux_vg_minor_number +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _VERSION="2016-04-28" # 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_space2comma "$*") +typeset _ARG="" +typeset _MSG="" +typeset _STC=0 +typeset _VG="" +typeset _VG_DUPE="" +typeset _VG_DUPES="" + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + +# get list of major and minor numbers for vgs +vgdisplay -F | cut -f1 -d':' | cut -f2 -d'=' | while read _VG +do + ls -l ${_VG}/group >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG} +done + +# check unique combination of major/minor numbers +_VG_DUPES="$(awk '{ print $5":"$6 }' ${HC_STDOUT_LOG} | sort | uniq -d)" +if [[ -n ${_VG_DUPES} ]] +then + print "${_VG_DUPES}" | while read _VG_DUPE + do + _MSG="MAJ/MIN numbers combination '${_VG_DUPE}' is not unique" + _STC=1 + + # handle unit result + log_hc "$0" ${_STC} "${_MSG}" + done +else + _MSG="no VGs with duplicate MAJ/MIN numbers detected" + + # handle unit result + log_hc "$0" ${_STC} "${_MSG}" +fi + +return 0 +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 +PURPOSE : Checks whether all volume groups have a unique minor number + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/linux/check_linux_burp_backup.sh b/sources/lib/platform/linux/check_linux_burp_backup.sh new file mode 100644 index 0000000..3c53ded --- /dev/null +++ b/sources/lib/platform/linux/check_linux_burp_backup.sh @@ -0,0 +1,231 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_linux_burp_backup.sh +#****************************************************************************** +# @(#) Copyright (C) 2016 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_linux_burp_backup +# DOES: see _show_usage() +# EXPECTS: see _show_usage() +# REQUIRES: data_space2comma(),init_hc(), log_hc(), +# GNU date that can calculate UNIX epoch seconds from given date, +# BURP server must be be able to impersonate configured clients +# +# @(#) HISTORY: +# @(#) 2016-12-01: initial version [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_linux_burp_backup +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _BURP_CONFIG_FILE="/etc/burp/burp-server.conf" +typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" +typeset _VERSION="2016-12-01" # YYYY-MM-DD +typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match +# ------------------------- CONFIGURATION ends here --------------------------- + +# set defaults +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS} +init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}" +typeset _ARGS=$(data_space2comma "$*") +typeset _ARG="" +typeset _MSG="" +typeset _STC=0 +typeset _BURP_BIN="" +typeset _BURP_AGE="" +typeset _BURP_CLIENT="" +typeset _BURP_WARNINGS="" +typeset _GNU_DATE="" +typeset _COUNT=1 +typeset _NOW="$(date '+%Y%m%d %H%M' 2>/dev/null)" # format: YYYYMMDD HHMM + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + +# handle configuration file +[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}" +if [[ ! -r ${_CONFIG_FILE} ]] +then + warn "unable to read configuration file at ${_CONFIG_FILE}" + return 1 +fi + +# check for capable GNU date +_GNU_DATE=$(date --date="1 day ago" '+%s' 2>/dev/null) +case "${_GNU_DATE}" in + +([0-9])*(.)*([0-9])) + # numeric, OK + ;; + *) + warn "no capable GNU date found here" + return 1 + ;; +esac + +# find burp +_BURP_BIN="$(which burp 2>/dev/null)" +if [[ ! -x ${_BURP_BIN} || -z "${_BURP_BIN}" ]] +then + warn "burp is not installed here" + return 1 +fi + +# check for burp server +if [[ ! -r ${_BURP_CONFIG_FILE} ]] +then + warn "burp server configuration file not found ($_BURP_CONFIG_FILE)" + return 1 +fi + +# check backup runs of clients +grep -v -E -e '^$' -e '^#' ${_CONFIG_FILE} 2>/dev/null |\ + while IFS=';' read _BURP_CLIENT _BURP_WARNINGS _BURP_AGE +do + typeset _BACKUP_AGING="" + typeset _BACKUP_DATE="" + typeset _BACKUP_RUN="" + typeset _BACKUP_STATS="" + typeset _BACKUP_WARNINGS="" # set empty string, not 0! + typeset _CUR_BACKUP_TIME="" + typeset _MIN_BACKUP_TIME="" + typeset _STC=0 + + if [[ -n "{_BURP_CLIENT}" ]] && [[ -n "{_BURP_WARNINGS}" ]] && [[ -n "${_BURP_AGE}" ]] + then + # convert backup aging (UNIX seconds) + case "${_BURP_AGE}" in + *h) + _BACKUP_AGING="${_BURP_AGE%%h}" + _MIN_BACKUP_TIME=$(( $(date -d "${_NOW}" '+%s' 2>/dev/null) - (_BACKUP_AGING * 60 * 60) )) + ;; + *d) + _BACKUP_AGING="${_BURP_AGE%%d}" + _MIN_BACKUP_TIME=$(( $(date -d "${_NOW}" '+%s' 2>/dev/null) - (_BACKUP_AGING * 60 * 60 * 24) )) + ;; + *w) + _BACKUP_AGING="${_BURP_AGE%%w}" + _MIN_BACKUP_TIME=$(( $(date -d "${_NOW}" '+%s' 2>/dev/null) - (_BACKUP_AGING * 60 * 60 * 24 * 7) )) + ;; + *) + warn "no correct backup age specified for client ${_BURP_CLIENT}" + _COUNT=$(( _COUNT + 1 )) + continue + ;; + esac + + # get the most recent burp backup of the client + # ex.: + # Backup: 0000078 2016-11-27 03:39:03 (deletable) + # Backup: 0000079 2016-12-04 03:59:04 + + _BACKUP_STATS="$(${_BURP_BIN} -a l -C ${_BURP_CLIENT} 2>>${HC_STDERR_LOG} | grep '^Backup' | tail -n 1 | cut -f2- -d':')" + if [[ -n "${_BACKUP_STATS}" ]] + then + _BACKUP_RUN="$(print ${_BACKUP_STATS} | awk '{print $1}')" + # output format: YYYYMMDD HHMM + _BACKUP_DATE=$(print "${_BACKUP_STATS}" | awk '{gsub(/-/,"",$2); gsub(/:/,"",$3); print $2" "substr($3,0,4)}') + # convert to UNIX seconds + _CUR_BACKUP_TIME=$(date -d "${_BACKUP_DATE}" '+%s') + else + warn "no backup found for client ${_BURP_CLIENT}. Check client impersonation?" + _COUNT=$(( _COUNT + 1 )) + continue + fi + + # get backup warnings + _BACKUP_WARNINGS="$(${_BURP_BIN} -c ${_BURP_CONFIG_FILE} -a S -C ${_BURP_CLIENT} -b ${_BACKUP_RUN} -z backup_stats 2>>${HC_STDERR_LOG} | grep '^warnings' 2>/dev/null | cut -f2 -d':')" + if [[ -z "${_BACKUP_WARNINGS}" ]] + then + warn "could not get stats for backup ${_BACKUP_RUN} of client ${_BURP_CLIENT}" + _COUNT=$(( _COUNT + 1 )) + continue + fi + + # check & evaluate the results + if (( _BACKUP_WARNINGS > _BURP_WARNINGS )) + then + _STC=$(( _STC + 1 )) + fi + if (( _CUR_BACKUP_TIME < _MIN_BACKUP_TIME )) + then + _STC=$(( _STC + 2 )) + fi + + # report the results + case ${_STC} in + 0) + _MSG="backup ${_BACKUP_RUN} of client ${_BURP_CLIENT} is OK" + ;; + 1) + _MSG="backup ${_BACKUP_RUN} of client ${_BURP_CLIENT} has too many warnings (${_BACKUP_WARNINGS}>${_BURP_WARNINGS})" + ;; + 2) + _MSG="backup ${_BACKUP_RUN} of client ${_BURP_CLIENT} is too old (>${_BURP_AGE})" + ;; + 3) + _MSG="backup ${_BACKUP_RUN} of client ${_BURP_CLIENT} is too old (>${_BURP_AGE}) and has too many warnings (${_BACKUP_WARNINGS}>${_BURP_WARNINGS})" + ;; + *) + : + ;; + esac + log_hc "$0" ${_STC} "${_MSG}" + _COUNT=$(( _COUNT + 1 )) + + # save STDOUT + if (( _STC =! 0 )) + then + print "=== ${_BURP_CLIENT}: ${_BACKUP_RUN} ===" >>${HC_STDOUT_LOG} + ${_BURP_BIN} -c ${_BURP_CONFIG_FILE} -a S -C ${_BURP_CLIENT} -b ${_BACKUP_RUN} -z log.gz >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG} + fi + else + warn "bad entry in the configuration file ${_CONFIG_FILE} on data line ${_COUNT}" + _COUNT=$(( _COUNT + 1 )) + continue + fi +done + +return 0 +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 with: + backup_age= +PURPOSE : Checks the status and age of saved burp client backups. + Should only berun only on a burp backup server + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/linux/check_linux_burp_status.sh b/sources/lib/platform/linux/check_linux_burp_status.sh new file mode 100644 index 0000000..5011570 --- /dev/null +++ b/sources/lib/platform/linux/check_linux_burp_status.sh @@ -0,0 +1,126 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_linux_burp_status.sh +#****************************************************************************** +# @(#) Copyright (C) 2016 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_linux_burp_status +# DOES: see _show_usage() +# EXPECTS: n/a +# REQUIRES: data_space2comma(), linux_get_init(), init_hc(), log_hc() +# +# @(#) HISTORY: +# @(#) 2016-12-01: initial version [Patrick Van der Veken] +# @(#) 2017-05-08: fix fall-back for sysv->pgrep [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_linux_burp_status +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _BURP_INIT_SCRIPT="/etc/init.d/burp" +typeset _BURP_SYSTEMD_SERVICE="burp.service" +typeset _VERSION="2017-05-08" # YYYY-MM-DD +typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match +# ------------------------- CONFIGURATION ends here --------------------------- + +# set defaults +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS} +init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}" +typeset _ARGS=$(data_space2comma "$*") +typeset _ARG="" +typeset _MSG="" +typeset _STC=0 +typeset _RC=0 + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + +# 1) try using the init ways +linux_get_init +case "${LINUX_INIT}" in + 'systemd') + systemctl --quiet is-active ${_BURP_SYSTEMD_SERVICE} || _STC=1 + ;; + 'upstart') + warn "code for upstart managed systems not implemented, NOOP" + return 1 + ;; + 'sysv') + if [[ -x ${_BURP_INIT_SCRIPT} ]] + then + if (( $(${_BURP_INIT_SCRIPT} status 2>>${HC_STDERR_LOG} | grep -c -i 'is running') == 0 )) + then + _STC=1 + fi + else + warn "sysv init script not found {${_BURP_INIT_SCRIPT}}" + _RC=1 + fi + ;; + *) + _RC=1 + ;; +esac + +# 2) try the pgrep way (note: old pgreps do not support '-c') +if (( _RC != 0 )) +then + (( $(pgrep -u root burp 2>>${HC_STDERR_LOG} | wc -l) == 0 )) && _STC=1 +fi + +# evaluate results +case ${_STC} in + 0) + _MSG="burp is running" + ;; + 1) + _MSG="burp is not running" + ;; + *) + _MSG="could not determine status of burp" + ;; +esac +log_hc "$0" ${_STC} "${_MSG}" + +return 0 +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 +PURPOSE : Checks whether a Burp (backup server daemon) is running + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/linux/check_linux_file_age.sh b/sources/lib/platform/linux/check_linux_file_age.sh new file mode 100644 index 0000000..ac4286f --- /dev/null +++ b/sources/lib/platform/linux/check_linux_file_age.sh @@ -0,0 +1,146 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_linux_file_age.sh +#****************************************************************************** +# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_linux_file_age +# DOES: see _show_usage() +# EXPECTS: see _show_usage() +# REQUIRES: data_space2comma(), init_hc(), log_hc() +# +# @(#) HISTORY: +# @(#) 2013-05-27: initial version [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_linux_file_age +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" +typeset _VERSION="2013-05-27" # YYYY-MM-DD +typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match +# ------------------------- CONFIGURATION ends here --------------------------- + +# set defaults +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS} +init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}" +typeset _ARGS=$(data_space2comma "$*") +typeset _ARG="" +typeset _MSG="" +typeset _STC=0 +typeset _ENTRY="" +typeset _AGE_CHECK=="" +typeset _FILE_PATH="" +typeset _FILE_AGE="" +typeset _FILE_NAME="" +typeset _FILE_DIR="" + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + +# handle configuration file +[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}" +if [[ ! -r ${_CONFIG_FILE} ]] +then + warn "unable to read configuration file at ${_CONFIG_FILE}" + return 1 +fi + +# perform check +grep -v -E -e '^$' -e '^#' ${_CONFIG_FILE} 2>/dev/null | while read _ENTRY +do + # field split + _FILE_PATH=$(print "${_ENTRY%%;*}") + _FILE_AGE=$(print "${_ENTRY##*;}") + + # split file/dir + _FILE_NAME=$(print "${_FILE_PATH##*/}") + _FILE_DIR=$(print "${_FILE_PATH%/*}") + + # check config + if [ \( -z "${_FILE_PATH}" \) -a \( -z "${_FILE_AGE}" \) ] + then + warn "missing values in configuration file at ${_CONFIG_FILE}" + return 1 + fi + case "${_FILE_AGE}" in + +([0-9])*(.)*([0-9])) + # numeric, OK + ;; + *) + # not numeric + warn "invalid file age value '${_FILE_AGE}' in configuration file at ${_CONFIG_FILE}" + return 1 + ;; + esac + + # perform check + if [[ ! -r "${_FILE_PATH}" ]] + then + _MSG="unable to read or access requested file at ${_FILE_PATH}" + _STC=1 + else + _AGE_CHECK=$(find "${_FILE_DIR}" -type f -name "${_FILE_NAME}" -mmin -"${_FILE_AGE}") + if (( $? != 0 )) + then + warn "unable to execute file age test for ${_FILE_PATH}" + return 1 + fi + if [[ -z "${_AGE_CHECK}" ]] + then + _MSG="file age of ${_FILE_AGE} has expired on ${_FILE_PATH}" + _STC=1 + else + _MSG="file age of ${_FILE_AGE} has not expired on ${_FILE_PATH}" + fi + fi + + # handle unit result + log_hc "$0" ${_STC} "${_MSG}" + _STC=0 +done + +return 0 +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 with: + ; +PURPOSE : Checks whether given files have been changed in the last n minutes + (requires GNU find) + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/linux/check_linux_file_change.sh b/sources/lib/platform/linux/check_linux_file_change.sh new file mode 100644 index 0000000..fb17131 --- /dev/null +++ b/sources/lib/platform/linux/check_linux_file_change.sh @@ -0,0 +1,374 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_linux_file_change.sh +#****************************************************************************** +# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_linux_file_change +# DOES: see _show_usage() +# EXPECTS: see _show_usage() +# REQUIRES: data_space2comma(), init_hc(), log_hc(), warn(), +# openssl (sha256 digest) OR cksum (CRC32 digest) +# +# @(#) HISTORY: +# @(#) 2017-05-18: initial version [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_linux_file_change +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" +typeset _VERSION="2017-05-18" # YYYY-MM-DD +typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match +# ------------------------- CONFIGURATION ends here --------------------------- + +# set defaults +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS} +init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}" +typeset _ARGS=$(data_space2comma "$*") +typeset _ARG="" +typeset _MSG="" +typeset _STC=0 +typeset _STC_COUNT=0 +typeset _DO_META_CHECK=0 +typeset _CFG_STATE_FILE="" +typeset _STATE_FILE="" +typeset _STATE_FILE_LINE="" +typeset _FILE_TO_CHECK="" +typeset _EXCL_OBJECT="" +typeset _INCL_OBJECT="" +typeset _HAS_OPENSSL=0 +typeset _HAS_CKSUM=0 +typeset _OPENSSL_BIN="" +typeset _CKSUM_BIN="" +typeset _USE_OPENSSL=0 +typeset _USE_CKSUM=0 +typeset _TMP1_FILE="${TMP_DIR}/.$0.tmp1.$$" +typeset _TMP2_FILE="${TMP_DIR}/.$0.tmp2.$$" +typeset _TMP_INCL_FILE="${TMP_DIR}/.$0.tmp_incl.$$" +typeset _TMP_EXCL_FILE="${TMP_DIR}/.$0.tmp_excl.$$" +set -o noglob # no file globbing + +# set local trap for clean-up +trap "[[ -f ${_TMP1_FILE} ]] && rm -f ${_TMP1_FILE} >/dev/null 2>&1; + [[ -f ${_TMP2_FILE} ]] && rm -f ${_TMP2_FILE} >/dev/null 2>&1; + [[ -f ${_TMP_INCL_FILE} ]] && rm -f ${_TMP_INCL_FILE} >/dev/null 2>&1; + [[ -f ${_TMP_EXCL_FILE} ]] && rm -f ${_TMP_EXCL_FILE} >/dev/null 2>&1; + return 1" 1 2 3 15 + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + +# handle configuration file +[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}" +if [[ ! -r ${_CONFIG_FILE} ]] +then + warn "unable to read configuration file at ${_CONFIG_FILE}" + return 1 +fi +# read required configuration values +_CFG_STATE_FILE=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'state_file') +if [[ -z "${_CFG_STATE_FILE}" ]] +then + _STATE_FILE="${STATE_PERM_DIR}/discovered.file_change" +else + _STATE_FILE="${STATE_PERM_DIR}/${_CFG_STATE_FILE}" +fi +log "using state file ${_STATE_FILE}" +_DO_META_CHECK=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'do_meta_check') +case "${_DO_META_CHECK}" in + no|NO|No) + _DO_META_CHECK=0 + log "check for meta characters is disabled" + ;; + *) + _DO_META_CHECK=1 + log "check for meta characters is enabled" + ;; +esac + +# check for checksum tools +_OPENSSL_BIN="$(which openssl 2>>${HC_STDERR_LOG})" +[[ -x ${_OPENSSL_BIN} && -n "${_OPENSSL_BIN}" ]] && _HAS_OPENSSL=1 +_CKSUM_BIN="$(which cksum 2>>${HC_STDERR_LOG})" +[[ -x ${_CKSUM_BIN} && -n "${_CKSUM_BIN}" ]] && _HAS_CKSUM=1 +# prefer openssl (for sha256) +if (( _HAS_OPENSSL == 1 )) +then + _USE_OPENSSL=1 +elif (( _HAS_CKSUM == 1 )) +then + _USE_CKSUM=1 +else + warn "unable to find the 'openssl/cksum' tools" + return 1 +fi + +# check state file & TMP_FILEs +[[ -r ${_STATE_FILE} ]] || { + >${_STATE_FILE} + (( $? > 0 )) && { + warn "failed to create new state file at ${_STATE_FILE}" + return 1 + } + log "created new state file at ${_STATE_FILE}" +} +>${_TMP_INCL_FILE} +(( $? > 0 )) && { + warn "failed to create temporary file at ${_TMP_INCL_FILE}" + return 1 +} +>${_TMP_EXCL_FILE} +(( $? > 0 )) && { + warn "failed to create temporary file at ${_TMP_EXCL_FILE}" + return 1 +} +>${_TMP1_FILE} +(( $? > 0 )) && { + warn "failed to create temporary file at ${_TMP1_FILE}" + return 1 +} +>${_TMP2_FILE} +(( $? > 0 )) && { + warn "failed to create temporary file at ${_TMP2_FILE}" + return 1 +} + +# build list of configured objects: inclusion +grep -i '^incl:' ${_CONFIG_FILE} 2>/dev/null |\ + while IFS=':' read _DUMMY _INCL_OBJECT +do + # check for meta & globbing characters (*?[]{}|) + if (( _DO_META_CHECK == 1 )) + then + case "${_INCL_OBJECT}" in + *\**|*\?*|*\[*|*\]*|*\{*|*\}*|*\|*) + warn "meta characters are not supported in the entry (incl:${_INCL_OBJECT})" + continue + ;; + esac + fi + + # expand directories + if [[ -d ${_INCL_OBJECT} ]] + then + find ${_INCL_OBJECT} -type f -xdev >>${_TMP_INCL_FILE} 2>>${HC_STDERR_LOG} + else + print ${_INCL_OBJECT} >>${_TMP_INCL_FILE} + fi +done + +# build list of configured objects: exclusion +grep -i '^excl:' ${_CONFIG_FILE} 2>/dev/null |\ + while IFS=':' read _DUMMY _EXCL_OBJECT +do + # check for meta & globbing characters (*?[]{}|) + if (( _DO_META_CHECK == 1 )) + then + case "${_EXCL_OBJECT}" in + *\**|*\?*|*\[*|*\]*|*\{*|*\}*|*\|*) + warn "meta characters are not supported in the entry (excl:${_EXCL_OBJECT})" + continue + ;; + esac + fi + + # expand directories + if [[ -d ${_EXCL_OBJECT} ]] + then + find ${_EXCL_OBJECT} -type f -xdev >>${_TMP_EXCL_FILE} 2>>${HC_STDERR_LOG} + else + print ${_EXCL_OBJECT} >>${_TMP_EXCL_FILE} + fi +done + +# subtract exclusion from inclusion (exclusion has higher priority) +sort ${_TMP_INCL_FILE} -o ${_TMP_INCL_FILE} 2>>${HC_STDERR_LOG} +sort ${_TMP_EXCL_FILE} -o ${_TMP_EXCL_FILE} 2>>${HC_STDERR_LOG} +comm -23 ${_TMP_INCL_FILE} ${_TMP_EXCL_FILE} 2>>${HC_STDERR_LOG} >${_TMP1_FILE} + +# check discovered objects +while read _FILE_TO_CHECK +do + # reset variables + _STC=0 + _MSG="" + _IS_NEW=0 + + # object to check must be a file (and be present) + if [[ ! -f ${_FILE_TO_CHECK} ]] + then + _MSG="${_FILE_TO_CHECK} is not a file or has disappeared" + _STC=1 + log_hc "$0" ${_STC} "${_MSG}" + continue + fi + + # read entry from state file + _STATE_FILE_LINE=$(grep -E -e "^${_FILE_TO_CHECK}\|" ${_STATE_FILE}) + if [[ -n "${_STATE_FILE_LINE}" ]] + then + # field 1 is the file name + _STATE_FILE_TYPE=$(print "${_STATE_FILE_LINE}" | cut -f2 -d'|') + _STATE_FILE_CKSUM=$(print "${_STATE_FILE_LINE}" | cut -f3 -d'|') + else + _IS_NEW=1 + fi + + # compute new checksum (keep the same type as before) + if (( _IS_NEW == 0 )) + then + case "${_STATE_FILE_TYPE}" in + openssl-sha256) + if (( _USE_OPENSSL == 1 )) + then + _FILE_CKSUM=$(${_OPENSSL_BIN} dgst -sha256 ${_FILE_TO_CHECK} 2>>${HC_STDERR_LOG} | cut -f2 -d'=' | tr -d ' ') + _FILE_TYPE="openssl-sha256" + else + _MSG="cannot compute checksum [${_FILE_TYPE}] for ${_FILE_TO_CHECK}" + _STC=1 + fi + ;; + cksum-crc32) + if (( _USE_CKSUM == 1 )) + then + _FILE_CKSUM=$(${_CKSUM_BIN} ${_FILE_TO_CHECK} 2>>${HC_STDERR_LOG} | cut -f1 -d' ') + _FILE_TYPE="cksum-crc32" + else + _MSG="cannot compute checksum [${_FILE_TYPE}] for ${_FILE_TO_CHECK}" + _STC=1 + fi + ;; + *) + _MSG="cannot compute checksum (unknown checksum type) for ${_FILE_TO_CHECK}" + _STC=1 + ;; + esac + else + # new file + if (( _USE_OPENSSL == 1 )) + then + _FILE_CKSUM=$(${_OPENSSL_BIN} dgst -sha256 ${_FILE_TO_CHECK} 2>>${HC_STDERR_LOG} | cut -f2 -d'=' | tr -d ' ') + _FILE_TYPE="openssl-sha256" + elif (( _USE_CKSUM == 1 )) + then + _FILE_CKSUM=$(${_CKSUM_BIN} ${_FILE_TO_CHECK} 2>>${HC_STDERR_LOG} | cut -f1 -d' ') + _FILE_TYPE="cksum-crc32" + else + _MSG="cannot compute checksum (openssl/cksum) for ${_FILE_TO_CHECK}" + _STC=1 + fi + fi + + # check for failed checksums + if [[ -z "${_FILE_CKSUM}" ]] + then + _MSG="did not receive checksum (openssl/cksum) for ${_FILE_TO_CHECK}" + _STC=1 + fi + + # bounce failures back and jump to next file + if (( _STC != 0 )) + then + log_hc "$0" ${_STC} "${_MSG}" + continue + fi + + if (( _IS_NEW == 0 )) + then + # compare old vs new checksums + if [[ "${_STATE_FILE_CKSUM}" != "${_FILE_CKSUM}" ]] + then + _MSG="${_FILE_TO_CHECK} has a changed checksum [${_FILE_TYPE}]" + _STC=1 + else + _MSG="${_FILE_TO_CHECK} has the same checksum [${_FILE_TYPE}]" + _STC=0 + fi + else + _MSG="${_FILE_TO_CHECK} is a new file [${_FILE_TYPE}]" + _STC=0 + fi + + # save entry to temp file + printf "%s|%s|%s\n" "${_FILE_TO_CHECK}" "${_FILE_TYPE}" "${_FILE_CKSUM}" >>${_TMP2_FILE} + + # report with curr/exp values + log_hc "$0" ${_STC} "${_MSG}" "${_FILE_CKSUM}" "${_STATE_FILE_CKSUM}" +done <${_TMP1_FILE} + +# update state file (also if TMP2_FILE is empty) +if (( ARG_LOG != 0 )) +then + [[ -s ${_TMP2_FILE} ]] || { + warn "no files found to check, zeroing new state file" + } + mv ${_TMP2_FILE} ${_STATE_FILE} >/dev/null 2>&1 + (( $? > 0 )) && { + warn "failed to move temporary state file" + return 1 + } +fi + +# clean up temporary files +[[ -f ${_TMP1_FILE} ]] && rm -f ${_TMP1_FILE} >/dev/null 2>&1 +[[ -f ${_TMP2_FILE} ]] && rm -f ${_TMP2_FILE} >/dev/null 2>&1 +[[ -f ${_TMP_INCL_FILE} ]] && rm -f ${_TMP_INCL_FILE} >/dev/null 2>&1 +[[ -f ${_TMP_EXCL_FILE} ]] && rm -f ${_TMP_EXCL_FILE} >/dev/null 2>&1 + +return 0 +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 with formatted stanzas: + incl: + excl: +PURPOSE : a KISS file integrity checker (like AIDE). Supports includes and excludes + of files and directories (automatically expanded). Excludes have a higher + priority than includes. Integrity checks will only be performed on files. + Will detect changed, new & deleted files (but not when deleted files + occur in an expanded directory tree). If you wish to detect deleted files: + use only direct file references in the configuration file. Uses by preference + openssl for hash calculation, with cksum as fall-back). + Updated and deleted files will cause a HC failure, new files will not. + CAVEAT EMPTOR: use only to check a relatively small number of files. + Processing a big number of files is likely to take + ages and probably will cause the plugin to time out + (see HC_TIME_OUT). YMMV. + + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/linux/check_linux_fs_mounts.sh b/sources/lib/platform/linux/check_linux_fs_mounts.sh new file mode 100644 index 0000000..c16e458 --- /dev/null +++ b/sources/lib/platform/linux/check_linux_fs_mounts.sh @@ -0,0 +1,114 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_linux_fs_mounts.sh +#****************************************************************************** +# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_linux_fs_mounts +# DOES: see _show_usage() +# EXPECTS: n/a +# REQUIRES: data_space2comma(), init_hc(), log_hc() +# +# @(#) HISTORY: +# @(#) 2013-05-17: initial version [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_linux_fs_mounts +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _VERSION="2013-05-17" # YYYY-MM-DD +typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match +# ------------------------- CONFIGURATION ends here --------------------------- + +# set defaults +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS} +init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}" +typeset _ARGS=$(data_space2comma "$*") +typeset _ARG="" +typeset _MSG="" +typeset _MSG="" +typeset _STC=0 +typeset _FS="" +typeset _FS_COUNT=0 + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + +# collect data (mount only) +mount >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG} +(( $? == 0 )) || return $? + +# check for each auto-mount configured file system (except /) +cat /etc/fstab |\ + grep -v -E -e '^#' -e '^$' \ + -e '[ \t]*.*[ \t]+(proc|swap|sysfs|devpts|tmpfs).*' \ + -e '(floppy|cdrom)' \ + -e '[ \t]*\/[ \t]+' |\ + awk '{print $2}' |\ +while read _FS +do + _FS_COUNT=$(grep -c -E -e ".*on[ \t]+${_FS}[ \t]+.*" ${HC_STDOUT_LOG}) + case ${_FS_COUNT} in + 0) + _MSG="${_FS} is not mounted" + _STC=1 + ;; + 1) + _MSG="${_FS} is mounted" + ;; + *) + _MSG="${_FS} is multiple times mounted?" + ;; + esac + + # handle unit result + log_hc "$0" ${_STC} "${_MSG}" + _STC=0 +done + +# add /etc/fstab to STDOUT log +cat /etc/fstab >>${HC_STDOUT_LOG} + +return 0 +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 +PURPOSE : Checks whether file systems are mounted or not, exclude following FS types: + proc, swap, sysfs, devpts, tmpfs, cdrom & floppy + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/linux/check_linux_hpacucli.sh b/sources/lib/platform/linux/check_linux_hpacucli.sh new file mode 100644 index 0000000..3fad2c5 --- /dev/null +++ b/sources/lib/platform/linux/check_linux_hpacucli.sh @@ -0,0 +1,291 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_linux_hpacucli.sh +#****************************************************************************** +# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_linux_hpacucli +# DOES: see _show_usage() +# EXPECTS: see _show_usage() +# REQUIRES: data_space2comma(), init_hc(), log_hc() +# +# @(#) HISTORY: +# @(#) 2013-09-09: initial version [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_linux_hpacucli +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" +typeset _VERSION="2013-09-09" # YYYY-MM-DD +typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match +# ------------------------- CONFIGURATION ends here --------------------------- + +# set defaults +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS} +init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}" +typeset _ARGS=$(data_space2comma "$*") +typeset _ARG="" +typeset _MSG="" +typeset _STC=0 +typeset _STC_COUNT=0 +typeset _TMP_FILE="${TMP_DIR}/.$0.tmp.$$" +typeset _HPACUCLI_BIN="" +typeset _ACU_LINE="" +typeset _SLOT_NUM="" +typeset _SLOT_NUMS="" +typeset _DO_ACU_CTRL=1 +typeset _DO_ACU_ENCL=1 +typeset _DO_ACU_PHYS=1 +typeset _DO_ACU_LOGL=1 +typeset _DO_CHECK=0 + +# set local trap for cleanup +trap "[[ -f ${_TMP_FILE} ]] && rm -f ${_TMP_FILE} >/dev/null 2>&1; return 1" 1 2 3 15 + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + +# handle configuration file +[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}" +if [[ ! -r ${_CONFIG_FILE} ]] +then + warn "unable to read configuration file at ${_CONFIG_FILE}" + return 1 +fi +# read required configuration values +_HPACUCLI_BIN=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'hpacucli_bin') +if [[ -z "${_HPACUCLI_BIN}" ]] +then + warn "no value set for 'hpacucli_bin' in ${_CONFIG_FILE}" + return 1 +fi +_DO_ACU_CTRL=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'do_acu_controller') +case "${_DO_ACU_CTRL}" in + 0|1) + # on/off, OK + ;; + *) + # set default + warn "illegal value for 'do_acu_controller' in ${_CONFIG_FILE}, using default" + _DO_ACU_CTRL=1 + ;; +esac +_DO_ACU_ENCL=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'do_acu_enclosure') +case "${_DO_ACU_ENCL}" in + 0|1) + # on/off, OK + ;; + *) + # set default + warn "illegal value for 'do_acu_enclosure' in ${_CONFIG_FILE}, using default" + _DO_ACU_ENCL=1 + ;; +esac +_DO_ACU_PHYS=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'do_acu_physical') +case "${_DO_ACU_PHYS}" in + 0|1) + # on/off, OK + ;; + *) + # set default + warn "illegal value for 'do_acu_physical' in ${_CONFIG_FILE}, using default" + _DO_ACU_PHYS=1 + ;; +esac +_DO_ACU_LOGL=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'do_acu_logical') +case "${_DO_ACU_LOGL}" in + 0|1) + # on/off, OK + ;; + *) + # set default + warn "illegal value for 'do_acu_logical' in ${_CONFIG_FILE}, using default" + _DO_ACU_LOGL=1 + ;; +esac +# check for dependencies: we need to do DO_ACU_CTRL to have the slot info for all +# the other checks +_DO_CHECK=$(( _DO_ACU_ENCL + _DO_ACU_PHYS + _DO_ACU_LOGL )) +if (( _DO_CHECK != 0 && _DO_ACU_CTRL == 0 )) +then + log "switching setting 'do_acu_controller' to 1 to fetch slot info" + _DO_ACU_CTRL=1 +fi + +# check for HP tools +if [[ ! -x ${_HPACUCLI_BIN} || -z "${_HPACUCLI_BIN}" ]] +then + warn "${_HPACUCLI_BIN} is not installed here" + return 1 +fi + +# --- perform checks --- +# CONTROLLER(s) +if (( _DO_ACU_CTRL != 0 )) +then + ${_HPACUCLI_BIN} controller all show status >${_TMP_FILE} 2>${_TMP_FILE} + (( $? != 0 )) && warn "'${_HPACUCLI_BIN} controller all show status' exited non-zero" + # look for failures + grep -i -E -e "(nok|fail.*)" ${_TMP_FILE} 2>/dev/null |\ + while read _ACU_LINE + do + _MSG="failure in controller" + _STC_COUNT=$(( _STC_COUNT + 1 )) + # handle unit result + log_hc "$0" 1 "${_MSG}" + done + print "=== ACU controller(s) ===" >>${HC_STDOUT_LOG} + cat ${_TMP_FILE} >>${HC_STDOUT_LOG} + # get all slot numbers for multiple raid controllers + cat ${_TMP_FILE} | grep "in Slot [0-9]" | while read _ACU_LINE + do + _SLOT_NUM="$(print ${_ACU_LINE} | cut -f6 -d' ')" + case "${_DO_ACU_LOGL}" in + +([0-9])*([0-9])) + # numeric OK + _SLOT_NUMS="${_SLOT_NUMS} ${_SLOT_NUM}" + ;; + *) + # non-numeric + warn "found RAID controller at illegal slot?: ${_SLOT_NUM}" + ;; + esac + done +else + warn "${_HPACUCLI_BIN}: do_acu_controller check is not enabled" +fi + +# ENCLOSURE(s) +if (( _DO_ACU_ENCL != 0 )) +then + for _CTRL_SLOT in ${_SLOT_NUMS} + do + ${_HPACUCLI_BIN} controller slot=${_CTRL_SLOT} enclosure all show \ + >${_TMP_FILE} 2>${_TMP_FILE} + (( $? != 0 )) && \ + warn "'${_HPACUCLI_BIN} controller slot=${_CTRL_SLOT} enclosure all show' exited non-zero" + # look for failures + grep -i -E -e "(nok|fail.*)" ${_TMP_FILE} 2>/dev/null |\ + while read _ACU_LINE + do + _MSG="failure in enclosure for controller ${_CTRL_SLOT}" + _STC_COUNT=$(( _STC_COUNT + 1 )) + # handle unit result + log_hc "$0" 1 "${_MSG}" + done + print "=== ACU enclosure(s) ===" >>${HC_STDOUT_LOG} + cat ${_TMP_FILE} >>${HC_STDOUT_LOG} + done +else + warn "${_HPACUCLI_BIN}: do_acu_enclosure check is not enabled" +fi + +# PHYSICAL DRIVE(s) +if (( _DO_ACU_PHYS != 0 )) +then + for _CTRL_SLOT in ${_SLOT_NUMS} + do + ${_HPACUCLI_BIN} controller slot=${_CTRL_SLOT} physicaldrive all show status \ + >${_TMP_FILE} 2>${_TMP_FILE} + (( $? != 0 )) && \ + warn "'${_HPACUCLI_BIN} controller slot=${_CTRL_SLOT} physicaldrive all show status' exited non-zero" + # look for failures + grep -i -E -e "(nok|fail.*)" ${_TMP_FILE} 2>/dev/null |\ + while read _ACU_LINE + do + _MSG="failure in physical drive(s) for controller ${_CTRL_SLOT}" + _STC_COUNT=$(( _STC_COUNT + 1 )) + # handle unit result + log_hc "$0" 1 "${_MSG}" + done + print "=== ACU physical drive(s) ===" >>${HC_STDOUT_LOG} + cat ${_TMP_FILE} >>${HC_STDOUT_LOG} + done +else + warn "${_HPACUCLI_BIN}: do_acu_physical check is not enabled" + fi + +# LOGICAL DRIVE(s) +if (( _DO_ACU_LOGL != 0 )) +then + for _CTRL_SLOT in ${_SLOT_NUMS} + do + ${_HPACUCLI_BIN} controller slot=${_CTRL_SLOT} logicaldrive all show status \ + >${_TMP_FILE} 2>${_TMP_FILE} + (( $? != 0 )) && \ + warn "'${_HPACUCLI_BIN} controller slot=${_CTRL_SLOT}logicaldrive all show status' exited non-zero" + # look for failures + grep -i -E -e "(nok|fail)" ${_TMP_FILE} 2>/dev/null |\ + while read _ACU_LINE + do + _MSG="failure in logical drive(s) for controller ${_CTRL_SLOT}" + _STC_COUNT=$(( _STC_COUNT + 1 )) + # handle unit result + log_hc "$0" 1 "${_MSG}" + done + print "=== ACU logical drive(s) ===" >>${HC_STDOUT_LOG} + cat ${_TMP_FILE} >>${HC_STDOUT_LOG} + done +else + warn "${_HPACUCLI_BIN}: do_acu_logical check is not enabled" +fi + +# report OK situation +if (( _STC_COUNT == 0 )) +then + _MSG="no problems detected by {${_HPACUCLI_BIN}}" + log_hc "$0" 0 "${_MSG}" +fi + +# remove temporary file +[[ -f ${_TMP_FILE} ]] & rm -f ${_TMP_FILE} >/dev/null 2>&1 + +return 0 +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 with: + hpacucli_bin= + do_acu_controller=0|1 + do_acu_enclosure=0|1 + do_acu_physical=0|1 + do_acu_logical=0|1 +PURPOSE : Checks for errors from the HP Proliant 'hpacucli' tool (see HP Proliant + support pack (PSP)) + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/linux/check_linux_hpasmcli.sh b/sources/lib/platform/linux/check_linux_hpasmcli.sh new file mode 100644 index 0000000..b1458b1 --- /dev/null +++ b/sources/lib/platform/linux/check_linux_hpasmcli.sh @@ -0,0 +1,303 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_linux_hpasmcli.sh +#****************************************************************************** +# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_linux_hpasmcli +# DOES: see _show_usage() +# EXPECTS: see _show_usage() +# REQUIRES: data_space2comma(), init_hc(), log_hc() +# +# @(#) HISTORY: +# @(#) 2013-09-07: initial version [Patrick Van der Veken] +# @(#) 2017-04-06: bugfix in temperature checking [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_linux_hpasmcli +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" +typeset _VERSION="2017-04-06" # YYYY-MM-DD +typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match +# ------------------------- CONFIGURATION ends here --------------------------- + +# set defaults +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS} +init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}" +typeset _ARGS=$(data_space2comma "$*") +typeset _ARG="" +typeset _MSG="" +typeset _STC=0 +typeset _STC_COUNT=0 +typeset _TMP_FILE="${TMP_DIR}/.$0.tmp.$$" +typeset _HPASMCLI_BIN="" +typeset _ASM_LINE="" +typeset _DO_ASM_FANS=1 +typeset _DO_ASM_DIMM=1 +typeset _DO_ASM_POWR=1 +typeset _DO_ASM_SRVR=1 +typeset _DO_ASM_TEMP=1 +typeset _FAN_UNIT="" +typeset _TEMP_FIELD="" +typeset _TEMP_VALUE="" +typeset _THRES_FIELD="" +typeset _THRES_VALUE="" +typeset _TEMP_UNIT="" + +# set local trap for cleanup +trap "[[ -f ${_TMP_FILE} ]] && rm -f ${_TMP_FILE} >/dev/null 2>&1; return 1" 1 2 3 15 + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + +# handle configuration file +[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}" +if [[ ! -r ${_CONFIG_FILE} ]] +then + warn "unable to read configuration file at ${_CONFIG_FILE}" + return 1 +fi +# read required configuration values +_HPASMCLI_BIN=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'hpasmcli_bin') +if [[ -z "${_HPASMCLI_BIN}" ]] +then + warn "no value set for 'hpasmcli_bin' in ${_CONFIG_FILE}" + return 1 +fi +_DO_ASM_FANS=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'do_asm_fans') +case "${_DO_ASM_FANS}" in + 0|1) + # on/off, OK + ;; + *) + # set default + warn "illegal value for 'do_asm_fans' in ${_CONFIG_FILE}, using default" + _DO_ASM_FANS=1 + ;; +esac +_DO_ASM_DIMM=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'do_asm_dimm') +case "${_DO_ASM_DIMM}" in + 0|1) + # on/off, OK + ;; + *) + # set default + warn "illegal value for 'do_asm_dimm' in ${_CONFIG_FILE}, using default" + _DO_ASM_DIMM=1 + ;; +esac +_DO_ASM_POWR=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'do_asm_powersupply') +case "${_DO_ASM_POWR}" in + 0|1) + # on/off, OK + ;; + *) + # set default + warn "illegal value for 'do_asm_powersupply' in ${_CONFIG_FILE}, using default" + _DO_ASM_POWR=1 + ;; +esac +_DO_ASM_SRVR=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'do_asm_server') +case "${_DO_ASM_POWR}" in + 0|1) + # on/off, OK + ;; + *) + # set default + warn "illegal value for 'do_asm_server' in ${_CONFIG_FILE}, using default" + _DO_ASM_SRVR=1 + ;; +esac +_DO_ASM_TEMP=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'do_asm_temperature') +case "${_DO_ASM_TEMP}" in + 0|1) + # on/off, OK + ;; + *) + # set default + warn "illegal value for 'do_asm_temperature' in ${_CONFIG_FILE}, using default" + _DO_ASM_TEMP=1 + ;; +esac + +# check for HP tools +if [[ ! -x ${_HPASMCLI_BIN} || -z "${_HPASMCLI_BIN}" ]] +then + warn "${_HPASMCLI_BIN} is not installed here" + return 1 +fi + +# --- perform checks --- +# SHOW FANS +if (( _DO_ASM_FANS != 0 )) +then + ${_HPASMCLI_BIN} -s 'SHOW FANS' >${_TMP_FILE} 2>${_TMP_FILE} + (( $? != 0 )) && warn "'${_HPASMCLI_BIN} -s SHOW FANS' exited non-zero" + # look for failures + grep -E -e '^#' ${_TMP_FILE} 2>/dev/null | grep -vi 'normal' |\ + while read _ASM_LINE + do + _FAN_UNIT="$(print ${_ASM_LINE} | cut -f1 -d' ')" + _MSG="failure in 'SHOW FANS', unit ${_FAN_UNIT}" + _STC_COUNT=$(( _STC_COUNT + 1 )) + # handle unit result + log_hc "$0" 1 "${_MSG}" + done + print "=== ASM fans ===" >>${HC_STDOUT_LOG} + cat ${_TMP_FILE} >>${HC_STDOUT_LOG} +else + warn "${_HPASMCLI_BIN}: do_asm_fans check not enabled" +fi + +# SHOW DIMM +if (( _DO_ASM_DIMM != 0 )) +then + ${_HPASMCLI_BIN} -s 'SHOW DIMM' >${_TMP_FILE} 2>${_TMP_FILE} + (( $? != 0 )) && warn "'${_HPASMCLI_BIN} -s SHOW DIMM' exited non-zero" + # look for failures + grep -i -E -e "(nok|fail)" ${_TMP_FILE} 2>/dev/null |\ + while read _ASM_LINE + do + _MSG="failure in 'SHOW DIMM'" + _STC_COUNT=$(( _STC_COUNT + 1 )) + # handle unit result + log_hc "$0" 1 "${_MSG}" + done + print "=== ASM DIMMs ===" >>${HC_STDOUT_LOG} + cat ${_TMP_FILE} >>${HC_STDOUT_LOG} +else + warn "${_HPASMCLI_BIN}: do_asm_dimm check not enabled" +fi + +# SHOW POWERSUPPLY +if (( _DO_ASM_POWR != 0 )) +then + ${_HPASMCLI_BIN} -s 'SHOW POWERSUPPLY' >${_TMP_FILE} 2>${_TMP_FILE} + (( $? != 0 )) && warn "'${_HPASMCLI_BIN} -s SHOW POWERSUPPLY' exited non-zero" + # look for failures + grep -i -E -e "(nok|fail)" ${_TMP_FILE} 2>/dev/null |\ + while read _ASM_LINE + do + _MSG="failure in 'SHOW POWERSUPPLY'" + _STC_COUNT=$(( _STC_COUNT + 1 )) + # handle unit result + log_hc "$0" 1 "${_MSG}" + done + print "=== ASM power supply ===" >>${HC_STDOUT_LOG} + cat ${_TMP_FILE} >>${HC_STDOUT_LOG} +else + warn "${_HPASMCLI_BIN}: do_asm_powersupply check not enabled" +fi + +# SHOW SERVER +if (( _DO_ASM_SRVR != 0 )) +then + ${_HPASMCLI_BIN} -s 'SHOW SERVER' >${_TMP_FILE} 2>${_TMP_FILE} + (( $? != 0 )) && warn "'${_HPASMCLI_BIN} -s SHOW SERVER' exited non-zero" + # look for failures + grep -i -E -e "(nok|fail)" ${_TMP_FILE} 2>/dev/null |\ + while read _ASM_LINE + do + _MSG="failure in 'SHOW SERVER'" + _STC_COUNT=$(( _STC_COUNT + 1 )) + # handle unit result + log_hc "$0" 1 "${_MSG}" + done + print "=== ASM server ===" >>${HC_STDOUT_LOG} + cat ${_TMP_FILE} >>${HC_STDOUT_LOG} +else + warn "${_HPASMCLI_BIN}: do_asm_server check not enabled" + fi + +# SHOW TEMP +if (( _DO_ASM_TEMP != 0 )) +then + ${_HPASMCLI_BIN} -s 'SHOW TEMP' >${_TMP_FILE} 2>${_TMP_FILE} + (( $? != 0 )) && warn "'${_HPASMCLI_BIN} -s SHOW TEMP' exited non-zero" + # look for failures + grep -E -e '^#' ${_TMP_FILE} 2>/dev/null |\ + while read _ASM_LINE + do + _TEMP_FIELD="$(print ${_ASM_LINE} | cut -f3 -d' ')" + _TEMP_VALUE="${_TEMP_FIELD%%C/*}" + _THRES_FIELD="$(print ${_ASM_LINE} | cut -f4 -d' ')" + _THRES_VALUE="${_THRES_FIELD%%C/*}" + if [[ "${_TEMP_VALUE}" != "-" ]] && [[ "${_THRES_VALUE}" != "-" ]] + then + if (( _TEMP_VALUE >= _THRES_VALUE )) + then + _TEMP_UNIT="$(print ${_ASM_LINE} | cut -f1 -d' ')" + _MSG="failure in 'SHOW TEMP', unit ${_TEMP_UNIT}" + _MSG="${_MSG} has ${_TEMP_VALUE} >= ${_THRES_VALUE}" + _STC_COUNT=$(( _STC_COUNT + 1 )) + # handle unit result + log_hc "$0" 1 "${_MSG}" "${_TEMP_VALUE}" "${_THRES_VALUE}" + fi + fi + done + print "=== ASM temperature ===" >>${HC_STDOUT_LOG} + cat ${_TMP_FILE} >>${HC_STDOUT_LOG} +else + warn "${_HPASMCLI_BIN}: do_asm_temperature check not enabled" +fi + +# report OK situation +if (( _STC_COUNT == 0 )) +then + _MSG="no problems detected by {${_HPASMCLI_BIN}}" + log_hc "$0" 0 "${_MSG}" +fi + +# remove temporary file +[[ -f ${_TMP_FILE} ]] & rm -f ${_TMP_FILE} >/dev/null 2>&1 + +return 0 +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 with: + hpasmcli_bin= + do_asm_fans=0|1 + do_asm_dimm=0|1 + do_asm_powersupply=0|1 + do_asm_server=0|1 + do_asm_temperature=0|1 +PURPOSE : Checks for errors from the HP Proliant 'hpasmcli' tool (see HP Proliant + support pack (PSP)) + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/linux/check_linux_hplog.sh b/sources/lib/platform/linux/check_linux_hplog.sh new file mode 100644 index 0000000..37b9dcd --- /dev/null +++ b/sources/lib/platform/linux/check_linux_hplog.sh @@ -0,0 +1,182 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_linux_hplog.sh +#****************************************************************************** +# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_linux_hplog +# DOES: see _show_usage() +# EXPECTS: see _show_usage() +# REQUIRES: data_space2comma(), init_hc(), log_hc() +# +# @(#) HISTORY: +# @(#) 2017-04-22: initial version [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_linux_hplog +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" +typeset _STATE_FILE="${STATE_PERM_DIR}/discovered.hplog" +typeset _VERSION="2017-04-22" # YYYY-MM-DD +typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match +# ------------------------- CONFIGURATION ends here --------------------------- + +# set defaults +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS} +init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}" +typeset _ARGS=$(data_space2comma "$*") +typeset _ARG="" +typeset _MSG="" +typeset _STC=0 +typeset _STC_COUNT=0 +typeset _TMP1_FILE="${TMP_DIR}/.$0.tmp1.$$" +typeset _TMP2_FILE="${TMP_DIR}/.$0.tmp2.$$" +typeset _HPLOG_BIN="" +typeset _HPLOG_SEVERITIES="" +typeset _SEVERITIES_LINE="" +typeset _SEVERITY_ENTRY="" +typeset _EVENT_ENTRY="" + +# set local trap for cleanup +trap "[[ -f ${_TMP1_FILE} ]] && rm -f ${_TMP1_FILE} >/dev/null 2>&1 + [[ -f ${_TMP2_FILE} ]] && rm -f ${_TMP2_FILE} >/dev/null 2>&1 + return 1" 1 2 3 15 + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + +# handle configuration file +[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}" +if [[ ! -r ${_CONFIG_FILE} ]] +then + warn "unable to read configuration file at ${_CONFIG_FILE}" + return 1 +fi +# read required configuration values +_HPLOG_BIN=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'hplog_bin') +if [[ -z "${_HPLOG_BIN}" ]] +then + warn "no value set for 'hplog_bin' in ${_CONFIG_FILE}" + return 1 +fi +_SEVERITIES_LINE=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'hplog_severities') +if [[ -z "${_SEVERITIES_LINE}" ]] +then + # set complex search regex (default) + _HPLOG_SEVERITIES="^([0-9]+)\s*(CRITICAL|CAUTION)" +else + # build the complex search regex + _HPLOG_SEVERITIES="^" + print "${_SEVERITIES_LINE}" | tr ',' '\n' | while read -r _SEVERITY_ENTRY + do + _HPLOG_SEVERITIES="${_HPLOG_SEVERITIES}(([0-9]+)\s*${_SEVERITY_ENTRY})|" + done + # delete last 'OR' + _HPLOG_SEVERITIES=${_HPLOG_SEVERITIES%?} +fi + +# check hplog utility +if [[ ! -x ${_HPLOG_BIN} || -z "${_HPLOG_BIN}" ]] +then + warn "${_HPLOG_BIN} is not installed here" + return 1 +fi + +# get hplog output +${_HPLOG_BIN} -v >${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG} +(( $? != 0 )) && { + _MSG="unable to run ${_HPLOG_BIN}" + log_hc "$0" 1 "${_MSG}" + return 0 +} + +# check state file +[[ -r ${_STATE_FILE} ]] || { + print "## this file sorted! Do not edit manually!" >${_STATE_FILE} + (( $? > 0 )) && { + warn "failed to create new state file" + return 1 + } + log "created new state file at ${_STATE_FILE}" +} + +# filter current hplog messages (must be uniquely sorted for 'comm') +log "searching HPLOG with filter: ${_HPLOG_SEVERITIES}" +grep -i -E -e "${_HPLOG_SEVERITIES}" ${HC_STDOUT_LOG} >${_TMP1_FILE} 2>/dev/null + +# compare results to already discovered messages +comm -13 ${_STATE_FILE} ${_TMP1_FILE} 2>/dev/null >${_TMP2_FILE} + +# report results +while read -r _EVENT_ENTRY +do + _MSG="${_EVENT_ENTRY}" + _STC_COUNT=$(( _STC_COUNT + 1 )) + # handle unit result + log_hc "$0" 1 "${_MSG}" +done <${_TMP2_FILE} +if (( _STC_COUNT > 0 )) +then + _MSG="found ${_STC_COUNT} new HPLOG messages {${_HPLOG_BIN} -v}" + _STC=1 + # add results to state file (must be sorted; re-use TMP_FILE) + sort -u ${_TMP1_FILE} ${_TMP2_FILE} > ${_STATE_FILE} + (( $? > 0 )) && { + warn "failed to sort temporary state file" + return 1 + } +else + _MSG="no new HPLOG messages found" +fi +log_hc "$0" ${_STC} "${_MSG}" + +# clean up temporary files +[[ -f ${_TMP1_FILE} ]] && rm -f ${_TMP1_FILE} >/dev/null 2>&1 +[[ -f ${_TMP2_FILE} ]] && rm -f ${_TMP2_FILE} >/dev/null 2>&1 + +return 0 +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 with: + hplog_bin= + hplog_severities= +PURPOSE : Checks for errors from the HP Proliant 'hpacucli' tool (see HP Proliant + support pack (PSP)) + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/linux/check_linux_hpssacli.sh b/sources/lib/platform/linux/check_linux_hpssacli.sh new file mode 100644 index 0000000..33885a4 --- /dev/null +++ b/sources/lib/platform/linux/check_linux_hpssacli.sh @@ -0,0 +1,291 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_linux_hpssacli.sh +#****************************************************************************** +# @(#) Copyright (C) 2016 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_linux_hpssacli +# DOES: _show_usage() +# EXPECTS: _show_usage() +# REQUIRES: data_space2comma(), init_hc(), log_hc() +# +# @(#) HISTORY: +# @(#) 2016-04-01: initial version [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_linux_hpssacli +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" +typeset _VERSION="2016-04-01" # YYYY-MM-DD +typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match +# ------------------------- CONFIGURATION ends here --------------------------- + +# set defaults +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS} +init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}" +typeset _ARGS=$(data_space2comma "$*") +typeset _ARG="" +typeset _MSG="" +typeset _STC=0 +typeset _STC_COUNT=0 +typeset _TMP_FILE="${TMP_DIR}/.$0.tmp.$$" +typeset _HPSSACLI_BIN="" +typeset _SSA_LINE="" +typeset _SLOT_NUM="" +typeset _SLOT_NUMS="" +typeset _DO_SSA_CTRL=1 +typeset _DO_SSA_ENCL=1 +typeset _DO_SSA_PHYS=1 +typeset _DO_SSA_LOGL=1 +typeset _DO_CHECK=0 + +# set local trap for cleanup +trap "[[ -f ${_TMP_FILE} ]] && rm -f ${_TMP_FILE} >/dev/null 2>&1; return 1" 1 2 3 15 + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + +# handle configuration file +[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}" +if [[ ! -r ${_CONFIG_FILE} ]] +then + warn "unable to read configuration file at ${_CONFIG_FILE}" + return 1 +fi +# read required configuration values +_HPSSACLI_BIN=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'hpssacli_bin') +if [[ -z "${_HPSSACLI_BIN}" ]] +then + warn "no value set for 'hpssacli_bin' in ${_CONFIG_FILE}" + return 1 +fi +_DO_SSA_CTRL=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'do_ssa_controller') +case "${_DO_SSA_CTRL}" in + 0|1) + # on/off, OK + ;; + *) + # set default + warn "illegal value for 'do_ssa_controller' in ${_CONFIG_FILE}, using default" + _DO_SSA_CTRL=1 + ;; +esac +_DO_SSA_ENCL=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'do_ssa_enclosure') +case "${_DO_SSA_ENCL}" in + 0|1) + # on/off, OK + ;; + *) + # set default + warn "illegal value for 'do_ssa_enclosure' in ${_CONFIG_FILE}, using default" + _DO_SSA_ENCL=1 + ;; +esac +_DO_SSA_PHYS=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'do_ssa_physical') +case "${_DO_SSA_PHYS}" in + 0|1) + # on/off, OK + ;; + *) + # set default + warn "illegal value for 'do_ssa_physical' in ${_CONFIG_FILE}, using default" + _DO_SSA_PHYS=1 + ;; +esac +_DO_SSA_LOGL=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'do_ssa_logical') +case "${_DO_SSA_LOGL}" in + 0|1) + # on/off, OK + ;; + *) + # set default + warn "illegal value for 'do_ssa_logical' in ${_CONFIG_FILE}, using default" + _DO_SSA_LOGL=1 + ;; +esac +# check for dependencies: we need to do DO_SSA_CTRL to have the slot info for all +# the other checks +_DO_CHECK=$(( _DO_SSA_ENCL + _DO_SSA_PHYS + _DO_SSA_LOGL )) +if (( _DO_CHECK != 0 && _DO_SSA_CTRL == 0 )) +then + log "switching setting 'do_ssa_controller' to 1 to fetch slot info" + _DO_SSA_CTRL=1 +fi + +# check for HP tools +if [[ ! -x ${_HPSSACLI_BIN} || -z "${_HPSSACLI_BIN}" ]] +then + warn "${_HPSSACLI_BIN} is not installed here" + return 1 +fi + +# --- perform checks --- +# CONTROLLER(s) +if (( _DO_SSA_CTRL != 0 )) +then + ${_HPSSACLI_BIN} controller all show status >${_TMP_FILE} 2>${_TMP_FILE} + (( $? != 0 )) && warn "'${_HPSSACLI_BIN} controller all show status' exited non-zero" + # look for failures + grep -i -E -e "(nok|fail.*)" ${_TMP_FILE} 2>/dev/null |\ + while read _SSA_LINE + do + _MSG="failure in controller" + _STC_COUNT=$(( _STC_COUNT + 1 )) + # handle unit result + log_hc "$0" 1 "${_MSG}" + done + print "=== SSA controller(s) ===" >>${HC_STDOUT_LOG} + cat ${_TMP_FILE} >>${HC_STDOUT_LOG} + # get all slot numbers for multiple raid controllers + cat ${_TMP_FILE} | grep "in Slot [0-9]" | while read _SSA_LINE + do + _SLOT_NUM="$(print ${_SSA_LINE} | cut -f6 -d' ')" + case "${_DO_SSA_LOGL}" in + +([0-9])*([0-9])) + # numeric OK + _SLOT_NUMS="${_SLOT_NUMS} ${_SLOT_NUM}" + ;; + *) + # non-numeric + warn "found RAID controller at illegal slot?: ${_SLOT_NUM}" + ;; + esac + done +else + warn "${_HPSSACLI_BIN}: do_ssa_controller check is not enabled" +fi + +# ENCLOSURE(s) +if (( _DO_SSA_ENCL != 0 )) +then + for _CTRL_SLOT in ${_SLOT_NUMS} + do + ${_HPSSACLI_BIN} controller slot=${_CTRL_SLOT} enclosure all show \ + >${_TMP_FILE} 2>${_TMP_FILE} + (( $? != 0 )) && \ + warn "'${_HPSSACLI_BIN} controller slot=${_CTRL_SLOT} enclosure all show' exited non-zero" + # look for failures + grep -i -E -e "(nok|fail.*)" ${_TMP_FILE} 2>/dev/null |\ + while read _SSA_LINE + do + _MSG="failure in enclosure for controller ${_CTRL_SLOT}" + _STC_COUNT=$(( _STC_COUNT + 1 )) + # handle unit result + log_hc "$0" 1 "${_MSG}" + done + print "=== SSA enclosure(s) ===" >>${HC_STDOUT_LOG} + cat ${_TMP_FILE} >>${HC_STDOUT_LOG} + done +else + warn "${_HPSSACLI_BIN}: do_ssa_enclosure check is not enabled" +fi + +# PHYSICAL DRIVE(s) +if (( _DO_SSA_PHYS != 0 )) +then + for _CTRL_SLOT in ${_SLOT_NUMS} + do + ${_HPSSACLI_BIN} controller slot=${_CTRL_SLOT} physicaldrive all show status \ + >${_TMP_FILE} 2>${_TMP_FILE} + (( $? != 0 )) && \ + warn "'${_HPSSACLI_BIN} controller slot=${_CTRL_SLOT} physicaldrive all show status' exited non-zero" + # look for failures + grep -i -E -e "(nok|fail.*)" ${_TMP_FILE} 2>/dev/null |\ + while read _SSA_LINE + do + _MSG="failure in physical drive(s) for controller ${_CTRL_SLOT}" + _STC_COUNT=$(( _STC_COUNT + 1 )) + # handle unit result + log_hc "$0" 1 "${_MSG}" + done + print "=== SSA physical drive(s) ===" >>${HC_STDOUT_LOG} + cat ${_TMP_FILE} >>${HC_STDOUT_LOG} + done +else + warn "${_HPSSACLI_BIN}: do_ssa_physical check is not enabled" +fi + +# LOGICAL DRIVE(s) +if (( _DO_SSA_LOGL != 0 )) +then + for _CTRL_SLOT in ${_SLOT_NUMS} + do + ${_HPSSACLI_BIN} controller slot=${_CTRL_SLOT} logicaldrive all show status \ + >${_TMP_FILE} 2>${_TMP_FILE} + (( $? != 0 )) && \ + warn "'${_HPSSACLI_BIN} controller slot=${_CTRL_SLOT}logicaldrive all show status' exited non-zero" + # look for failures + grep -i -E -e "(nok|fail)" ${_TMP_FILE} 2>/dev/null |\ + while read _SSA_LINE + do + _MSG="failure in logical drive(s) for controller ${_CTRL_SLOT}" + _STC_COUNT=$(( _STC_COUNT + 1 )) + # handle unit result + log_hc "$0" 1 "${_MSG}" + done + print "=== SSA logical drive(s) ===" >>${HC_STDOUT_LOG} + cat ${_TMP_FILE} >>${HC_STDOUT_LOG} + done +else + warn "${_HPSSACLI_BIN}: do_ssa_logical check is not enabled" +fi + +# report OK situation +if (( _STC_COUNT == 0 )) +then + _MSG="no problems detected by {${_HPSSACLI_BIN}}" + log_hc "$0" 0 "${_MSG}" +fi + +# remove temporary file +[[ -f ${_TMP_FILE} ]] & rm -f ${_TMP_FILE} >/dev/null 2>&1 + +return 0 +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 with: + hpssacli_bin= + do_ssa_controller=0|1 + do_ssa_enclosure=0|1 + do_ssa_physical=0|1 + do_ssa_logical=0|1 +PURPOSE : Checks for errors from the HP Proliant 'hpssacli' tool (see HP Proliant + support pack (PSP)) + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/linux/check_linux_httpd_status.sh b/sources/lib/platform/linux/check_linux_httpd_status.sh new file mode 100644 index 0000000..728348c --- /dev/null +++ b/sources/lib/platform/linux/check_linux_httpd_status.sh @@ -0,0 +1,148 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_linux_httpd_status.sh +#****************************************************************************** +# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_linux_httpd_status +# DOES: see _show_usage() +# EXPECTS: n/a +# REQUIRES: data_space2comma(), linux_get_init(), init_hc(), log_hc() +# +# @(#) HISTORY: +# @(#) 2017-04-23: initial version [Patrick Van der Veken] +# @(#) 2017-05-08: fix fall-back for sysv->pgrep [Patrick Van der Veken] +# @(#) 2017-05-17: removed _MSG dupe [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_linux_httpd_status +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _HTTPD_INIT_SCRIPT="/etc/init.d/httpd" +typeset _HTTPD_SYSTEMD_SERVICE="httpd.service" +typeset _VERSION="2017-05-17" # YYYY-MM-DD +typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match +# ------------------------- CONFIGURATION ends here --------------------------- + +# set defaults +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS} +init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}" +typeset _ARGS=$(data_space2comma "$*") +typeset _ARG="" +typeset _HTTPD_BIN="" +typeset _MSG="" +typeset _STC=0 +typeset _RC=0 + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + +# ---- process state ---- +# 1) try using the init ways +linux_get_init +case "${LINUX_INIT}" in + 'systemd') + systemctl --quiet is-active ${_HTTPD_SYSTEMD_SERVICE} || _STC=1 + ;; + 'upstart') + warn "code for upstart managed systems not implemented, NOOP" + _RC=1 + ;; + 'sysv') + # check running SysV + if [[ -x ${_HTTPD_INIT_SCRIPT} ]] + then + if (( $(${_HTTPD_INIT_SCRIPT} status 2>>${HC_STDERR_LOG} | grep -c -i 'is running') == 0 )) + then + _STC=1 + fi + else + warn "sysv init script not found {${_HTTPD_INIT_SCRIPT}}" + _RC=1 + fi + ;; + *) + _RC=1 + ;; +esac + +# 2) try the pgrep way (note: old pgreps do not support '-c') +if (( _RC != 0 )) +then + (( $(pgrep -u root httpd 2>>${HC_STDERR_LOG} | wc -l) == 0 )) && _STC=1 +fi + +# evaluate results +case ${_STC} in + 0) + _MSG="httpd is running" + ;; + 1) + _MSG="httpd is not running" + ;; + *) + _MSG="could not determine status of httpd" + ;; +esac +log_hc "$0" ${_STC} "${_MSG}" + +# ---- config state ---- +_HTTPD_BIN="$(which httpd 2>>${HC_STDERR_LOG})" +if [[ -x ${_HTTPD_BIN} && -n "${_HTTPD_BIN}" ]] +then + # validate main configuration + ${_HTTPD_BIN} -t >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG} + if (( $? == 0 )) + then + _MSG="httpd configuration files are syntactically correct" + _STC=0 + else + _MSG="httpd configuration files have syntax error(s) {httpd -s}" + _STC=1 + fi + log_hc "$0" ${_STC} "${_MSG}" +fi + +return 0 +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 +PURPOSE : Checks whether httpd (apache service) is running and whether the + httpd configuration files are syntactically correct + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/linux/check_linux_named_status.sh b/sources/lib/platform/linux/check_linux_named_status.sh new file mode 100644 index 0000000..b4680da --- /dev/null +++ b/sources/lib/platform/linux/check_linux_named_status.sh @@ -0,0 +1,160 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_linux_named_status.sh +#****************************************************************************** +# @(#) Copyright (C) 2016 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_linux_named_status +# DOES: see _show_usage() +# EXPECTS: n/a +# REQUIRES: data_space2comma(), linux_get_init(), init_hc(), log_hc() +# +# @(#) HISTORY: +# @(#) 2013-12-01: initial version [Patrick Van der Veken] +# @(#) 2017-05-08: fix fall-back for sysv->pgrep [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_linux_named_status +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _VERSION="2017-05-08" # YYYY-MM-DD +typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match +# ------------------------- CONFIGURATION ends here --------------------------- + +# set defaults +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS} +init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}" +typeset _ARGS=$(data_space2comma "$*") +typeset _ARG="" +typeset _MSG="" +typeset _STC=0 +typeset _NAMED_CHECKCONF_BIN="" +typeset _NAMED_INIT_SCRIPT="" +typeset _NAMED_SYSTEMD_SERVICE="" +typeset _RC=0 + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + +# set init script & systemd service +case "${LINUX_DISTRO}" in + Debian) + _NAMED_INIT_SCRIPT="/etc/init.d/bind9" + _NAMED_SYSTEMD_SERVICE="bind9.service" + ;; + *) + _NAMED_INIT_SCRIPT="/etc/init.d/named" + _NAMED_SYSTEMD_SERVICE="named.service" + ;; +esac + +# ---- process state ---- +# 1) try using the init ways +linux_get_init +case "${LINUX_INIT}" in + 'systemd') + systemctl --quiet is-active ${_NAMED_SYSTEMD_SERVICE} || _STC=1 + ;; + 'upstart') + warn "code for upstart managed systems not implemented, NOOP" + return 1 + ;; + 'sysv') + # check running named + if [[ -x ${_NAMED_INIT_SCRIPT} ]] + then + if (( $(${_NAMED_INIT_SCRIPT} status 2>>${HC_STDERR_LOG} | grep -c -i 'is running') == 0 )) + then + _STC=1 + fi + else + warn "sysv init script not found {${_NAMED_INIT_SCRIPT}}" + _RC=1 + fi + ;; + *) + _RC=1 + ;; +esac + +# 2) try the pgrep way (note: old pgreps do not support '-c') +if (( _RC != 0 )) +then + (( $(pgrep -u root named 2>>${HC_STDERR_LOG} | wc -l) == 0 )) && _STC=1 +fi + +# evaluate results +case ${_STC} in + 0) + _MSG="named is running" + ;; + 1) + _MSG="named is not running" + ;; + *) + _MSG="could not determine status of named" + ;; +esac +log_hc "$0" ${_STC} "${_MSG}" + +# ---- config state ---- +_NAMED_CHECKCONF_BIN="$(which named-checkconf 2>>${HC_STDERR_LOG})" +if [[ -x ${_NAMED_CHECKCONF_BIN} && -n "${_NAMED_CHECKCONF_BIN}" ]] +then + # validate main configuration and test load zones + ${_NAMED_CHECKCONF_BIN} -z >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG} + if (( $? == 0 )) + then + _MSG="named & zones configuration files are syntactically correct" + _STC=0 + else + _MSG="named configuration and/or zone files have syntax error(s) {named-checkconf -z}" + _STC=1 + fi + log_hc "$0" ${_STC} "${_MSG}" +fi + +return 0 +} + + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 +PURPOSE : Checks whether named (BIND) is running and whether the named zone + files are syntactically correct. + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/linux/check_linux_postfix_status.sh b/sources/lib/platform/linux/check_linux_postfix_status.sh new file mode 100644 index 0000000..b70ab5c --- /dev/null +++ b/sources/lib/platform/linux/check_linux_postfix_status.sh @@ -0,0 +1,139 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_linux_postfix_status.sh +#****************************************************************************** +# @(#) Copyright (C) 2016 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_linux_postfix_status +# DOES: see _show_usage() +# EXPECTS: n/a +# REQUIRES: data_space2comma(), linux_get_init(), init_hc(), log_hc() +# +# @(#) HISTORY: +# @(#) 2016-12-01: initial version [Patrick Van der Veken] +# @(#) 2017-05-08: suppress errors on postfix call + fix fall-back +# @(#) for sysv->pgrep[Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_linux_postfix_status +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _POSTFIX_INIT_SCRIPT="/etc/init.d/postfix" +typeset _POSTFIX_SYSTEMD_SERVICE="postfix.service" +typeset _VERSION="2017-05-08" # YYYY-MM-DD +typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match +# ------------------------- CONFIGURATION ends here --------------------------- + +# set defaults +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS} +init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}" +typeset _ARGS=$(data_space2comma "$*") +typeset _ARG="" +typeset _POSTFIX_BIN="" +typeset _MSG="" +typeset _STC=0 +typeset _RC=0 + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + +# 1) try using the init ways +linux_get_init +case "${LINUX_INIT}" in + 'systemd') + systemctl --quiet is-active ${_POSTFIX_SYSTEMD_SERVICE} || _STC=1 + ;; + 'upstart') + warn "code for upstart managed systems not implemented, NOOP" + _RC=1 + ;; + 'sysv') + # check running SysV + if [[ -x ${_POSTFIX_INIT_SCRIPT} ]] + then + if (( $(${_POSTFIX_INIT_SCRIPT} status 2>>${HC_STDERR_LOG} | grep -c -i 'is running') == 0 )) + then + _STC=1 + fi + else + warn "sysv init script not found {${_POSTFIX_INIT_SCRIPT}}" + _RC=1 + fi + ;; + *) + _RC=1 + ;; +esac + +# 2) try the postfix way +if (( _RC != 0 )) +then + _POSTFIX_BIN="$(which postfix 2>>${HC_STDERR_LOG})" + if [[ -x ${_POSTFIX_BIN} && -n "${_POSTFIX_BIN}" ]] + then + if (( $(${_POSTFIX_BIN} status 2>>${HC_STDERR_LOG} | grep -c -i 'is running') == 0 )) + then + _STC=1 + fi + else + warn "postfix is not installed here" + return 1 + fi +fi + +# evaluate results +case ${_STC} in + 0) + _MSG="postfix is running" + ;; + 1) + _MSG="postfix is not running" + ;; + *) + _MSG="could not determine status of postfix" + ;; +esac +log_hc "$0" ${_STC} "${_MSG}" + +return 0 +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 +PURPOSE : Checks whether postfix (mail system) is running + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/linux/check_linux_root_crontab.sh b/sources/lib/platform/linux/check_linux_root_crontab.sh new file mode 100644 index 0000000..d7140d9 --- /dev/null +++ b/sources/lib/platform/linux/check_linux_root_crontab.sh @@ -0,0 +1,137 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_linux_root_crontab +#****************************************************************************** +# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#******************************************************************************* +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_linux_root_crontab +# DOES: see _show_usage() +# EXPECTS: see _show_usage() +# REQUIRES: data_space2comma(), init_hc(), log_hc() +# +# @(#) HISTORY: +# @(#) 2013-09-19: initial version [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_linux_root_crontab +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" +typeset _VERSION="2013-09-19" # YYYY-MM-DD +typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match +# ------------------------- CONFIGURATION ends here --------------------------- + +# set defaults +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS} +init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}" +typeset _ARGS=$(data_space2comma "$*") +typeset _ARG="" +typeset _MSG="" +typeset _STC=0 +typeset _CRON_LINE="" +typeset _CRON_ENTRY="" +typeset _CRON_MATCH=0 + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + +# handle configuration file +[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}" +if [[ ! -r ${_CONFIG_FILE} ]] +then + warn "unable to read configuration file at ${_CONFIG_FILE}" + return 1 +fi + +# collect data, since Linux can have multiple cron sources we will +# squash them all together, standard cron, vixie, anacron, you name it :) +print "=== crontab -l ===" >>${HC_STDOUT_LOG} +crontab -l >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG} +print "=== /etc/crontab ===" >>${HC_STDOUT_LOG} +[[ -s /etc/crontab ]] && cat /etc/crontab >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG} +print "=== /etc/cron.(hourly|daily|weekly|monthly) ===" >>${HC_STDOUT_LOG} +[[ -d /etc/cron.hourly ]] && cat /etc/cron.hourly/* \ + >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG} +[[ -d /etc/cron.daily ]] && cat /etc/cron.daily/* \ + >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG} +[[ -d /etc/cron.weekly ]] && cat /etc/cron.weekly/* \ + >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG} +[[ -d /etc/cron.monthly ]] && cat /etc/cron.monthly/* \ + >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG} +print "=== /etc/cron.d ===" >>${HC_STDOUT_LOG} +if [[ -d /etc/cron.d ]] +then + cat /etc/cron.d/* | while read _CRON_LINE + do + if [[ $(print "${_CRON_LINE}" | awk '{print $6}') == "root" ]] + then + print "${_CRON_LINE}" >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG} + fi + done +fi + +# perform check +grep -v -E -e '^$' -e '^#' ${_CONFIG_FILE} 2>/dev/null | while read _CRON_ENTRY +do + _CRON_MATCH=$(grep -v '^#' ${HC_STDOUT_LOG} 2>/dev/null |\ + grep -c -E -e "${_CRON_ENTRY}") + case ${_CRON_MATCH} in + 0) + _MSG="'${_CRON_ENTRY}' is not configured in cron" + _STC=1 + ;; + 1) + _MSG="'${_CRON_ENTRY}' is configured in cron" + ;; + +([0-9])*([0-9])) + _MSG="'${_CRON_ENTRY}' is configured multiple times in cron" + ;; + esac + + # handle unit result + log_hc "$0" ${_STC} "${_MSG}" + _STC=0 +done + +return 0 +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 +PURPOSE : Checks the content of the 'root' user crontab for required entries + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/linux/check_linux_samba_status.sh b/sources/lib/platform/linux/check_linux_samba_status.sh new file mode 100644 index 0000000..b1c01bc --- /dev/null +++ b/sources/lib/platform/linux/check_linux_samba_status.sh @@ -0,0 +1,145 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_linux_samba_status.sh +#****************************************************************************** +# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_linux_samba_status +# DOES: see _show_usage() +# EXPECTS: n/a +# REQUIRES: data_space2comma(), linux_get_init(), init_hc(), log_hc() +# +# @(#) HISTORY: +# @(#) 2013-05-17: initial version [Patrick Van der Veken] +# @(#) 2016-12-01: added systemd code [Patrick Van der Veken] +# @(#) 2017-05-08: fix fall-back for sysv->pgrep [Patrick Van der Veken] +# @(#) 2017-07-23: fix for systemd service names [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_linux_samba_status +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _SMB_INIT_SCRIPT="/etc/init.d/samba" +typeset _SMB_SYSTEMD_SERVICE="smb.service" +typeset _NMB_SYSTEMD_SERVICE="nmb.service" +typeset _VERSION="2017-07-23" # YYYY-MM-DD +typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match +# ------------------------- CONFIGURATION ends here --------------------------- + +# set defaults +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS} +init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}" +typeset _ARGS=$(data_space2comma "$*") +typeset _ARG="" +typeset _MSG="" +typeset _STC=0 +typeset _RC=0 + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + +# 1) try using the init ways +linux_get_init +case "${LINUX_INIT}" in + 'systemd') + # check running NMB + systemctl --quiet is-active ${_NMB_SYSTEMD_SERVICE} || _STC=1 + # check running SMB + systemctl --quiet is-active ${_SMB_SYSTEMD_SERVICE} || _STC=$(( _STC + 2 )) + ;; + 'upstart') + warn "code for upstart managed systems not implemented, NOOP" + return 1 + ;; + 'sysv') + # check running NMB/SMB + if [[ -x ${_SMB_INIT_SCRIPT} ]] + then + if (( $(${_SMB_INIT_SCRIPT} status 2>>${HC_STDERR_LOG} | grep -c -i -E -e 'NMB.*is running.*') == 0 )) + then + _STC=1 + fi + # check running SMB + if (( $(${_SMB_INIT_SCRIPT} status 2>>${HC_STDERR_LOG} | grep -c -i -E -e 'SMB.*is running.*') == 0 )) + then + _STC=$(( _STC + 2 )) + fi + else + warn "sysv init script not found {${_SMB_INIT_SCRIPT}}" + _RC=1 + fi + ;; + *) + _RC=1 + ;; +esac + +# 2) try the pgrep way (note: old pgreps do not support '-c') +if (( _RC != 0 )) +then + (( $(pgrep -u root nmbd 2>>${HC_STDERR_LOG}| wc -l) == 0 )) && _STC=1 + (( $(pgrep -u root smbd 2>>${HC_STDERR_LOG} | wc -l) == 0 )) && _STC=$(( _STC + 2 )) +fi + +# evaluate results +case ${_STC} in + 0) + _MSG="NMB/SMB are running" + ;; + 1) + _MSG="NMB is not running" + ;; + 2) + _MSG="SMB is not running" + ;; + 3) + _MSG="NMB/SMB are not running" + ;; + *) + _MSG="could not determine status of NMB/SMB" + ;; +esac +log_hc "$0" ${_STC} "${_MSG}" + +return 0 +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 +PURPOSE : Checks whether SAMBA daemons are running + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/linux/check_linux_sg_cluster_config.sh b/sources/lib/platform/linux/check_linux_sg_cluster_config.sh new file mode 100644 index 0000000..d73195d --- /dev/null +++ b/sources/lib/platform/linux/check_linux_sg_cluster_config.sh @@ -0,0 +1,191 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_hpux_sg_cluster_config +#****************************************************************************** +# @(#) Copyright (C) 2016 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#*****************************************hpux************************************* +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_linux_sg_cluster_status +# DOES: see _show_usage() +# EXPECTS: see _show_usage() +# REQUIRES: data_space2comma(), init_hc(), log_hc(), warn() +# +# @(#) HISTORY: +# @(#) 2017-04-01: initial version [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_linux_sg_cluster_config +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" +typeset _VERSION="2017-04-01" # YYYY-MM-DD +typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match +typeset _SG_DAEMON="/opt/cmcluster/bin/cmcld" +# rubbish that cmgetconf outputs to STDOUT instead of STDERR +typeset _SG_CMGETCONF_FILTER="Permission denied|Number of configured" +# ------------------------- CONFIGURATION ends here --------------------------- + +# set defaults +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS} +PATH=$PATH:/opt/cmcluster/bin +init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}" +typeset _ARGS=$(data_space2comma "$*") +typeset _ARG="" +typeset _MSG="" +typeset _STC=0 +typeset _CLUSTER_RUN_FILE="${TMP_DIR}/.$0.cluster_run.$$" +typeset _CLUSTER_CFG_FILE="${TMP_DIR}/.$0.cluster_cfg.$$" +typeset _CLUSTER_INSTANCE="" +typeset _CLUSTER_INSTANCES="" +typeset _CLUSTER_ENTRY="" +typeset _CLUSTER_CFG_ENTRY="" +typeset _CLUSTER_MATCH="" +typeset _CLUSTER_PARAM="" +typeset _CLUSTER_VALUE="" + +# set local trap for cleanup +trap "rm -f ${_CLUSTER_RUN_FILE}.* ${_CLUSTER_CFG_FILE}.* >/dev/null 2>&1; return 1" 1 2 3 15 + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + +# handle configuration file +[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}" +if [[ ! -r ${_CONFIG_FILE} ]] +then + warn "unable to read configuration file at ${_CONFIG_FILE}" + return 1 +fi + +# look for cluster instance names +grep -E -e '^\[' ${_CONFIG_FILE} 2>/dev/null | cut -f1 -d']' | cut -f2 -d'[' |\ +while read _CLUSTER_INSTANCE +do + _CLUSTER_INSTANCES="${_CLUSTER_INSTANCES} ${_CLUSTER_INSTANCE}" +done +if [[ -z "${_CLUSTER_INSTANCES}" ]] +then + warn "no cluster information configured in ${_CONFIG_FILE}" + return 1 +fi + +# check serviceguard status & gather cluster information from running cluster (compressed lines) +if [[ ! -x ${_SG_DAEMON} ]] +then + warn "${_SG_DAEMON} is not installed here" + return 1 +else + for _CLUSTER_INSTANCE in ${_CLUSTER_INSTANCES} + do + cmgetconf -c ${_CLUSTER_INSTANCE} 2>>${HC_STDERR_LOG} |\ + grep -v -E -e "${_SG_CMGETCONF_FILTER}" | tr -d ' \t' >${_CLUSTER_RUN_FILE}.${_CLUSTER_INSTANCE} + [[ -s ${_CLUSTER_RUN_FILE}.${_CLUSTER_INSTANCE} ]] || { + _MSG="unable to gather cluster configuration" + log_hc "$0" 1 "${_MSG}" + return 0 + } + done +fi + +# gather cluster information from healthcheck configuration +for _CLUSTER_INSTANCE in ${_CLUSTER_INSTANCES} +do + awk -v cluster="${_CLUSTER_INSTANCE}" ' + BEGIN { found = 0; needle = "^\["cluster"\]" } + + # skip blank lines + /^\s*$/ { next; } + # skip comment lines + /^#/ { next; } + + # end marker + ( $0 ~ /^\[.*\]/ && found ) { + found = 0; + } + # start marker + $0 ~ needle { + found = 1; + }; + # stanza body + ( found && $0 !~ /^\[.*\]/ ) { + # print non-compressed and compressed version + printf "%s|", $0; + gsub(" |\t", "", $0); + printf "%s\n", $0; + }' < ${_CONFIG_FILE} 2>>${HC_STDERR_LOG} >${_CLUSTER_CFG_FILE}.${_CLUSTER_INSTANCE} +done + +# do cluster configuration checks (using the compressed strings) +for _CLUSTER_INSTANCE in ${_CLUSTER_INSTANCES} +do + while read _CLUSTER_ENTRY + do + # split entry to get the compressed version + _CLUSTER_CFG_ENTRY=$(print "${_CLUSTER_ENTRY}" | cut -f2 -d'|') + # get parameter name from non-compressed version + _CLUSTER_PARAM=$(print "${_CLUSTER_ENTRY}" | cut -f1 -d'|' | awk '{ print $1 }') + # get parameter value from non-compressed version + _CLUSTER_VALUE=$(print "${_CLUSTER_ENTRY}" | cut -f1 -d'|' | awk '{ print substr($2,1,30)}') + # is it present? + _CLUSTER_MATCH=$(grep -c "${_CLUSTER_CFG_ENTRY}" ${_CLUSTER_RUN_FILE}.${_CLUSTER_INSTANCE} 2>/dev/null) + if (( _CLUSTER_MATCH == 0 )) + then + # get parameter name from non-compressed version + _MSG="'${_CLUSTER_PARAM} (${_CLUSTER_VALUE} ...)' is not correctly configured for ${_CLUSTER_INSTANCE}" + _STC=1 + else + _MSG="'${_CLUSTER_PARAM} (${_CLUSTER_VALUE} ...)' is configured for ${_CLUSTER_INSTANCE}" + fi + + # handle unit result + log_hc "$0" ${_STC} "${_MSG}" + _STC=0 + done <${_CLUSTER_CFG_FILE}.${_CLUSTER_INSTANCE} +done + +# remove working files +rm -f ${_CLUSTER_RUN_FILE}.* ${_CLUSTER_CFG_FILE}.* >/dev/null 2>&1 + +return 0 +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 +PURPOSE : Checks the configuration of a Serviceguard cluster (SG 11.16+) (comparing + serialized strings from the plugin configuration file with the running + cluster configuration) + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/linux/check_linux_sg_cluster_status.sh b/sources/lib/platform/linux/check_linux_sg_cluster_status.sh new file mode 100644 index 0000000..a5c0254 --- /dev/null +++ b/sources/lib/platform/linux/check_linux_sg_cluster_status.sh @@ -0,0 +1,135 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_linux_sg_cluster_status +#****************************************************************************** +# @(#) Copyright (C) 2016 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_linux_sg_cluster_status +# DOES: see _show_usage() +# EXPECTS: see _show_usage() +# REQUIRES: data_space2comma(), init_hc(), log_hc(), warn() +# +# @(#) HISTORY: +# @(#) 2017-04-01: initial version [Patrick Van der Veken] +# @(#) 2017-05-07: made checks more detailed for log_hc() [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_linux_sg_cluster_status +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" +typeset _VERSION="2017-05-07" # YYYY-MM-DD +typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match +typeset _SG_DAEMON="/opt/cmcluster/bin/cmcld" +# ------------------------- CONFIGURATION ends here --------------------------- + +# set defaults +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS} +PATH=$PATH:/opt/cmcluster/bin +init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}" +typeset _ARGS=$(data_space2comma "$*") +typeset _ARG="" +typeset _MSG="" +typeset _STC=0 +typeset _SG_ENTRY="" +typeset _SG_MATCH="" +typeset _SG_CFG_PARAM="" +typeset _SG_RUN_PARAM="" +typeset _SG_CFG_VALUE="" +typeset _SG_RUN_VALUE="" + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + +# handle configuration file +[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}" +if [[ ! -r ${_CONFIG_FILE} ]] +then + warn "unable to read configuration file at ${_CONFIG_FILE}" + return 1 +fi + +# check & get serviceguard status +if [[ ! -x ${_SG_DAEMON} ]] +then + warn "${_SG_DAEMON} is not installed here" + return 1 +else + cmviewcl -v -f line 2>>${HC_STDERR_LOG} | tr '|' ':' >>${HC_STDOUT_LOG} + (( $? != 0 )) && { + _MSG="unable to run 'cmviewcl'" + log_hc "$0" 1 "${_MSG}" + return 0 + } +fi + +# do cluster status checks +# (replace ':' by '|' for cmcviewcl output) +grep -v -E -e '^$' -e '^#' ${_CONFIG_FILE} 2>/dev/null | tr '|' ':' | while read _SG_ENTRY +do + # field split + _SG_CFG_PARAM="$(print ${_SG_ENTRY} | cut -f1 -d'=')" # field 1 + _SG_CFG_VALUE="$(print ${_SG_ENTRY} | cut -f2 -d'=')" # field 2 + + # check run-time values (anchored grep here!) + _SG_MATCH=$(grep -i "^${_SG_CFG_PARAM}" ${HC_STDOUT_LOG} 2>/dev/null) + if [[ -n "${_SG_MATCH}" ]] + then + _SG_RUN_VALUE=$(print "${_SG_MATCH}" | cut -f2 -d'=') # field 2 + + if [[ "${_SG_CFG_VALUE}" = "${_SG_RUN_VALUE}" ]] + then + _MSG="cluster parameter ${_SG_CFG_PARAM} has a correct value [${_SG_RUN_VALUE}]" + _STC=0 + else + _MSG="cluster parameter ${_SG_CFG_PARAM} has a wrong value [${_SG_RUN_VALUE}]" + _STC=1 + fi + log_hc "$0" ${_STC} "${_MSG}" "${_SG_RUN_VALUE}" "${_SG_CFG_VALUE}" + else + warn "could not determine status for ${_SG_CFG_PARAM} from command output {cmviewcl}" + fi +done + +return 0 +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 +PURPOSE : Checks the status of Serviceguard cluster parameters (SG 11.16+) + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/linux/check_linux_sg_package_config.sh b/sources/lib/platform/linux/check_linux_sg_package_config.sh new file mode 100644 index 0000000..3f67867 --- /dev/null +++ b/sources/lib/platform/linux/check_linux_sg_package_config.sh @@ -0,0 +1,191 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_linux_sg_package_config +#****************************************************************************** +# @(#) Copyright (C) 2016 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_linux_sg_package_config +# DOES: see _show_usage() +# EXPECTS: see _show_usage() +# REQUIRES: data_space2comma(), init_hc(), log_hc(), warn() +# +# @(#) HISTORY: +# @(#) 2017-04-01: initial version [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_linux_sg_package_config +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" +typeset _VERSION="2017-04-01" # YYYY-MM-DD +typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match +typeset _SG_DAEMON="/opt/cmcluster/bin/cmcld" +# rubbish that cmgetconf outputs to STDOUT instead of STDERR +typeset _SG_CMGETCONF_FILTER="Permission denied|Number of configured" +# ------------------------- CONFIGURATION ends here --------------------------- + +# set defaults +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS} +PATH=$PATH:/opt/cmcluster/bin +init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}" +typeset _ARGS=$(data_space2comma "$*") +typeset _ARG="" +typeset _MSG="" +typeset _STC=0 +typeset _PKG_RUN_FILE="${TMP_DIR}/.$0.pkg_run.$$" +typeset _PKG_CFG_FILE="${TMP_DIR}/.$0.pkg_cfg.$$" +typeset _PKG_INSTANCE="" +typeset _PKG_INSTANCES="" +typeset _PKG_ENTRY="" +typeset _PKG_CFG_ENTRY="" +typeset _PKG_MATCH="" +typeset _PKG_PARAM="" +typeset _PKG_VALUE="" + +# set local trap for cleanup +trap "rm -f ${_PKG_RUN_FILE}.* ${_PKG_CFG_FILE}.* >/dev/null 2>&1; return 1" 1 2 3 15 + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + +# handle config file +[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}" +if [[ ! -r ${_CONFIG_FILE} ]] +then + warn "unable to read configuration file at ${_CONFIG_FILE}" + return 1 +fi + +# look for package instance names +grep -E -e '^\[' ${_CONFIG_FILE} 2>/dev/null | cut -f1 -d']' | cut -f2 -d'[' |\ +while read _PKG_INSTANCE +do + _PKG_INSTANCES="${_PKG_INSTANCES} ${_PKG_INSTANCE}" +done +if [[ -z "${_PKG_INSTANCES}" ]] +then + warn "no package information configured in ${_CONFIG_FILE}" + return 1 +fi + +# check serviceguard status & gather package information from running cluster (compressed lines) +if [[ ! -x ${_SG_DAEMON} ]] +then + warn "${_SG_DAEMON} is not installed here" + return 1 +else + for _PKG_INSTANCE in ${_PKG_INSTANCES} + do + cmgetconf -p ${_PKG_INSTANCE} -v 0 2>>${HC_STDERR_LOG} |\ + grep -v -E -e "${_SG_CMGETCONF_FILTER}" | tr -d ' \t' >${_PKG_RUN_FILE}.${_PKG_INSTANCE} + [[ -s ${_PKG_RUN_FILE}.${_PKG_INSTANCE} ]] || { + _MSG="unable to gather package configuration for at least one cluster package" + log_hc "$0" 1 "${_MSG}" + return 0 + } + done +fi + +# gather package information from healthcheck configuration +for _PKG_INSTANCE in ${_PKG_INSTANCES} +do + awk -v package="${_PKG_INSTANCE}" ' + BEGIN { found = 0; needle = "^\["package"\]" } + + # skip blank lines + /^\s*$/ { next; } + # skip comment lines + /^#/ { next; } + + # end marker + ( $0 ~ /^\[.*\]/ && found ) { + found = 0; + } + # start marker + $0 ~ needle { + found = 1; + }; + # stanza body + ( found && $0 !~ /^\[.*\]/ ) { + # print non-compressed and compressed version + printf "%s|", $0; + gsub(" |\t", "", $0); + printf "%s\n", $0; + }' < ${_CONFIG_FILE} 2>>${HC_STDERR_LOG} >${_PKG_CFG_FILE}.${_PKG_INSTANCE} +done + +# do package configuration checks (using the compressed strings) +for _PKG_INSTANCE in ${_PKG_INSTANCES} +do + while read _PKG_ENTRY + do + # split entry to get the compressed version + _PKG_CFG_ENTRY=$(print "${_PKG_ENTRY}" | cut -f2 -d'|') + # get parameter name from non-compressed version + _PKG_PARAM=$(print "${_PKG_ENTRY}" | awk '{ print $1 }') + # get parameter value from non-compressed version + _PKG_VALUE=$(print "${_PKG_ENTRY}" | cut -f1 -d'|' | awk '{ print substr($2,1,30)}') + # is it present? + _PKG_MATCH=$(grep -c "${_PKG_CFG_ENTRY}" ${_PKG_RUN_FILE}.${_PKG_INSTANCE} 2>/dev/null) + if (( _PKG_MATCH == 0 )) + then + # get parameter name from non-compressed version + _MSG="'${_PKG_PARAM} (${_PKG_VALUE} ...)' is not correctly configured for ${_PKG_INSTANCE}" + _STC=1 + else + _MSG="'${_PKG_PARAM} (${_PKG_VALUE} ...)' is configured for ${_PKG_INSTANCE}" + fi + + # handle unit result + log_hc "$0" ${_STC} "${_MSG}" + _STC=0 + done <${_PKG_CFG_FILE}.${_PKG_INSTANCE} +done + +# remove working files +rm -f ${_PKG_RUN_FILE}.* ${_PKG_CFG_FILE}.* >/dev/null 2>&1 + +return 0 +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 +PURPOSE : Checks the configuration of Serviceguard package parameters (SG 11.16+) + (comparing serialized strings from the HC configuration file to the + running cluster configuration) + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/linux/check_linux_sg_package_status.sh b/sources/lib/platform/linux/check_linux_sg_package_status.sh new file mode 100644 index 0000000..6cdcc20 --- /dev/null +++ b/sources/lib/platform/linux/check_linux_sg_package_status.sh @@ -0,0 +1,137 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_linux_sg_package_status +#****************************************************************************** +# @(#) Copyright (C) 2016 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_linux_sg_package_status +# DOES: see _show_usage() +# EXPECTS: see _show_usage() +# REQUIRES: data_space2comma(), init_hc(), log_hc(), warn() +# +# @(#) HISTORY: +# @(#) 2017-04-01: initial version [Patrick Van der Veken] +# @(#) 2017-05-07: made checks more detailed for log_hc() [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_linux_sg_package_status +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" +typeset _VERSION="2017-05-07" # YYYY-MM-DD +typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match +typeset _SG_DAEMON="/opt/cmcluster/bin/cmcld" +# ------------------------- CONFIGURATION ends here --------------------------- + +# set defaults +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS} +PATH=$PATH:/opt/cmcluster/bin +init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}" +typeset _ARGS=$(data_space2comma "$*") +typeset _ARG="" +typeset _MSG="" +typeset _STC=0 +typeset _SG_ENTRY="" +typeset _SG_MATCH="" +typeset _SG_PACKAGE="" +typeset _SG_CFG_PARAM="" +typeset _SG_RUN_PARAM="" +typeset _SG_CFG_VALUE="" +typeset _SG_RUN_VALUE="" + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + +# handle configuration file +[[ -n "${ARG_CONFIG_FILE}" ]] && _CONFIG_FILE="${ARG_CONFIG_FILE}" +if [[ ! -r ${_CONFIG_FILE} ]] +then + warn "unable to read configuration file at ${_CONFIG_FILE}" + return 1 +fi + +# check & get serviceguard status +if [[ ! -x ${_SG_DAEMON} ]] +then + warn "${_SG_DAEMON} is not installed here" + return 1 +else + cmviewcl -v -f line -l package 2>>${HC_STDERR_LOG} | tr '|' ':' >>${HC_STDOUT_LOG} + (( $? != 0)) && { + _MSG="unable to run 'cmviewcl'" + log_hc "$0" 1 "${_MSG}" + return 0 + } +fi + +# do package status checks +# (replace ':' by '|' for cmcviewcl output) +grep -v -E -e '^$' -e '^#' ${_CONFIG_FILE} 2>/dev/null | tr '|' ':' | while read _SG_ENTRY +do + # field split + _SG_PACKAGE="$(print ${_SG_ENTRY} | cut -f1 -d':')" + _SG_CFG_PARAM="$(print ${_SG_ENTRY} | cut -f2- -d':' | cut -f1 -d'=')" # field 2-,1 + _SG_CFG_VALUE="$(print ${_SG_ENTRY} | cut -f2- -d':' | cut -f2 -d'=')" # field 2-,2 + + # check run-time values (anchored grep here!) + _SG_MATCH=$(grep -i "^package:${_SG_PACKAGE}:${_SG_CFG_PARAM}" ${HC_STDOUT_LOG} 2>/dev/null) + if [[ -n "${_SG_MATCH}" ]] + then + _SG_RUN_VALUE=$(print "${_SG_MATCH}" | cut -f3- -d':' | cut -f2 -d'=') # field3-,2 + + if [[ "${_SG_CFG_VALUE}" = "${_SG_RUN_VALUE}" ]] + then + _MSG="package ${_SG_PACKAGE} parameter ${_SG_CFG_PARAM} has a correct value [${_SG_RUN_VALUE}]" + _STC=0 + else + _MSG="package ${_SG_PACKAGE} parameter ${_SG_CFG_PARAM} has a wrong value [${_SG_RUN_VALUE}]" + _STC=1 + fi + log_hc "$0" ${_STC} "${_MSG}" "${_SG_RUN_VALUE}" "${_SG_CFG_VALUE}" + else + warn "could not determine status for ${_SG_PACKAGE}/${_SG_CFG_PARAM} from command output {cmviewcl}" + fi +done + +return 0 +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 +PURPOSE : Checks the status of Serviceguard package parameters (SG 11.16+) + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/linux/check_linux_sg_qs_status.sh b/sources/lib/platform/linux/check_linux_sg_qs_status.sh new file mode 100644 index 0000000..efad74b --- /dev/null +++ b/sources/lib/platform/linux/check_linux_sg_qs_status.sh @@ -0,0 +1,113 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_linux_sg_qs_status.sh +#****************************************************************************** +# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_linux_sg_qs_status +# DOES: see _show_usage() +# EXPECTS: n/a +# REQUIRES: data_space2comma(), init_hc(), log_hc() +# +# @(#) HISTORY: +# @(#) 2017-05-01: initial version [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_linux_sg_qs_status +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _VERSION="2017-05-01" # YYYY-MM-DD +typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match +typeset _QS_BIN="/opt/qs/bin/qsc" +typeset _QS_AUTH_FILE="/opt/qs/conf/qs_authfile" +# ------------------------- CONFIGURATION ends here --------------------------- + +# set defaults +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS} +init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}" +typeset _ARGS=$(data_space2comma "$*") +typeset _ARG="" +typeset _MSG="" +typeset _STC=0 +typeset _RC=0 + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + +# check QS presence +if [[ ! -x ${_QS_BIN} ]] +then + warn "${_QS_BIN} is not installed here" + return 1 +fi + +# ---- process state ---- +(( $(pgrep -u root -f ${_QS_BIN} 2>>${HC_STDERR_LOG} | wc -l) == 0 )) && _STC=1 + +# evaluate results +case ${_STC} in + 0) + _MSG="QS is running" + ;; + 1) + _MSG="QS is not running" + ;; + *) + _MSG="could not determine status of QS" + ;; +esac +log_hc "$0" ${_STC} "${_MSG}" + +# ---- config state ---- +if [[ -s ${_QS_AUTH_FILE} ]] +then + _MSG="QS authorizations file has been configured" + _STC=0 +else + _MSG="QS authorizations file is missing or empty (${_QS_AUTH_FILE})" + _STC=1 +fi +log_hc "$0" ${_STC} "${_MSG}" + +return 0 +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 +PURPOSE : Checks whether the Serviceguard quorum server is running + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/linux/check_linux_shorewall_status.sh b/sources/lib/platform/linux/check_linux_shorewall_status.sh new file mode 100644 index 0000000..c11654c --- /dev/null +++ b/sources/lib/platform/linux/check_linux_shorewall_status.sh @@ -0,0 +1,109 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_linux_shorewall_status.sh +#****************************************************************************** +# @(#) Copyright (C) 2016 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_linux_shorewall_status +# DOES: see _show_usage() +# EXPECTS: n/a +# REQUIRES: data_space2comma(), init_hc(), log_hc() +# +# @(#) HISTORY: +# @(#) 2016-12-01: initial version [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_linux_shorewall_status +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _SHOREWALL_BIN="/sbin/shorewall" +typeset _VERSION="2016-12-01" # YYYY-MM-DD +typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match +# ------------------------- CONFIGURATION ends here --------------------------- + +# set defaults +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS} +init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}" +typeset _ARGS=$(data_space2comma "$*") +typeset _ARG="" +typeset _MSG="" +typeset _STC=0 + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + + +# check status +if [[ -x ${_SHOREWALL_BIN} && -n "${_SHOREWALL_BIN}" ]] +then + # check status + ${_SHOREWALL_BIN} status >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG} + if (( $? == 0 )) + then + _MSG="shorewall is running" + _STC=0 + else + _MSG="shorewall is not running {shorewall status}" + _STC=1 + fi + log_hc "$0" ${_STC} "${_MSG}" + + # check compile + ${_SHOREWALL_BIN} check >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG} + if (( $? == 0 )) + then + _MSG="shorewall rules compile correctly" + _STC=0 + else + _MSG="shorewall rules do not compile correctly {shorewall check}" + _STC=1 + fi + log_hc "$0" ${_STC} "${_MSG}" +else + warn "shorewall is not installed here" + return 1 +fi + +return 0 +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 +PURPOSE : Checks whether shorewall (firewall) service is running and whether + shorewall rules compile correctly + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/linux/check_linux_sshd_status.sh b/sources/lib/platform/linux/check_linux_sshd_status.sh new file mode 100644 index 0000000..9b2b770 --- /dev/null +++ b/sources/lib/platform/linux/check_linux_sshd_status.sh @@ -0,0 +1,139 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_linux_sshd_status.sh +#****************************************************************************** +# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_linux_sshd_status +# DOES: see _show_usage() +# EXPECTS: n/a +# REQUIRES: data_space2comma(), linux_get_init(), init_hc(), log_hc() +# +# @(#) HISTORY: +# @(#) 2016-12-01: initial version [Patrick Van der Veken] +# @(#) 2017-05-05: fix fall-back for sysv->pgrep [Patrick Van der Veken] +# @(#) 2017-05-08: set init/systemd based on distro [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_linux_sshd_status +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _VERSION="2017-05-08" # YYYY-MM-DD +typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match +# ------------------------- CONFIGURATION ends here --------------------------- + +# set defaults +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS} +init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}" +typeset _ARGS=$(data_space2comma "$*") +typeset _ARG="" +typeset _MSG="" +typeset _SSHD_INIT_SCRIPT="" +typeset _SSHD_SYSTEMD_SERVICE="" +typeset _STC=0 +typeset _RC=0 + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + +# set init script & systemd service +case "${LINUX_DISTRO}" in + Debian) + _SSHD_INIT_SCRIPT="/etc/init.d/ssh" + _SSHD_SYSTEMD_SERVICE="ssh.service" + ;; + *) + _SSHD_INIT_SCRIPT="/etc/init.d/sshd" + _SSHD_SYSTEMD_SERVICE="sshd.service" + ;; +esac + +# 1) try using the init ways +linux_get_init +case "${LINUX_INIT}" in + 'systemd') + systemctl --quiet is-active ${_SSHD_SYSTEMD_SERVICE} || _STC=1 + ;; + 'upstart') + warn "code for upstart managed systems not implemented, NOOP" + return 1 + ;; + 'sysv') + if [[ -x ${_SSHD_INIT_SCRIPT} ]] + then + if (( $(${_SSHD_INIT_SCRIPT} status 2>>${HC_STDERR_LOG} | grep -c -i 'is running') == 0 )) + then + _STC=1 + fi + else + warn "sysv init script not found {${_SSHD_INIT_SCRIPT}}" + _RC=1 + fi + ;; + *) + _RC=1 + ;; +esac + +# 2) try the pgrep way (note: old pgreps do not support '-c') +if (( _RC != 0 )) +then + (( $(pgrep -P 1 -u root sshd 2>>${HC_STDERR_LOG} | wc -l) == 0 )) && _STC=1 +fi + +# evaluate results +case ${_STC} in + 0) + _MSG="sshd is running" + ;; + 1) + _MSG="sshd is not running" + ;; + *) + _MSG="could not determine status of sshd" + ;; +esac +log_hc "$0" ${_STC} "${_MSG}" + +return 0 +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 +PURPOSE : Checks whether sshd (Secure Shell daemon) is running + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/linux/check_linux_vz_ct_status.sh b/sources/lib/platform/linux/check_linux_vz_ct_status.sh new file mode 100644 index 0000000..1ef9844 --- /dev/null +++ b/sources/lib/platform/linux/check_linux_vz_ct_status.sh @@ -0,0 +1,185 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_linux_vz_ct_status.sh +#****************************************************************************** +# @(#) Copyright (C) 2017 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_linux_vz_ct_status +# DOES: see _show_usage() +# EXPECTS: see _show_usage() +# REQUIRES: data_space2comma(), init_hc(), log_hc(), warn() +# +# @(#) HISTORY: +# @(#) 2017-04-01: initial version [Patrick Van der Veken] +# @(#) 2017-05-07: made checks more detailed for hc_log() [Patrick Van der Veken] +# @(#) 2017-06-08: return 1 on error [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_linux_vz_ct_status +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" +typeset _VZLIST_BIN="/usr/sbin/vzlist" +typeset _VERSION="2017-06-08" # YYYY-MM-DD +typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match +# ------------------------- CONFIGURATION ends here --------------------------- + +# set defaults +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS} +init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}" +typeset _ARGS=$(data_space2comma "$*") +typeset _ARG="" +typeset _LINE_COUNT=1 +typeset _CT_ENTRY="" +typeset _CT_ID="" +typeset _CT_CFG_STATUS="" +typeset _CT_RUN_STATUS="" +typeset _CT_CFG_BOOT="" +typeset _CT_RUN_BOOT="" +typeset _CT_ENTRY="" +typeset _CT_MATCH="" +typeset _MSG="" +typeset _STC=0 +typeset _RC=0 + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + +# check openvz +if [[ ! -x ${_VZLIST_BIN} || -z "${_VZLIST_BIN}" ]] +then + warn "OpenVZ is not installed here" + return 1 +fi + +# get container stati +${_VZLIST_BIN} -a -H -o ctid,status,onboot >>${HC_STDOUT_LOG} 2>>${HC_STDERR_LOG} +(( $? != 0 )) && { + _MSG="unable to run {vzlist}" + log_hc "$0" 1 "${_MSG}" + return 0 +} + +# check configuration values +grep -v -E -e '^$' -e '^#' ${_CONFIG_FILE} 2>/dev/null | while read _CT_ENTRY +do + # field split + _CT_ID="$(print ${_CT_ENTRY} | cut -f1 -d';')" + _CT_CFG_STATUS=$(data_lc $(print "${_CT_ENTRY}" | cut -f2 -d';')) + _CT_CFG_BOOT=$(data_lc $(print "${_CT_ENTRY}" | cut -f3 -d';')) + + # check config + case "${_CT_ID}" in + +([0-9])*(.)*([0-9])) + # numeric, OK + ;; + *) + # not numeric + warn "invalid container ID '${_CT_ID}' in configuration file ${_CONFIG_FILE} at data line ${_LINE_COUNT}" + return 1 + ;; + esac + case "${_CT_CFG_STATUS}" in + running|stopped) + ;; + *) + warn "invalid container status '${_CT_CFG_STATUS}' in configuration file ${_CONFIG_FILE} at data line ${_LINE_COUNT}" + return 1 + ;; + esac + case "${_CT_CFG_BOOT}" in + yes|no) + ;; + *) + warn "invalid container boot value '${_CT_CFG_BOOT}' in configuration file ${_CONFIG_FILE} at data line ${_LINE_COUNT}" + return 1 + ;; + esac + _LINE_COUNT=$(( _LINE_COUNT + 1 )) +done + + +# perform checks +grep -v -E -e '^$' -e '^#' ${_CONFIG_FILE} 2>/dev/null | while read _CT_ENTRY +do + # field split + _CT_ID="$(print ${_CT_ENTRY} | cut -f1 -d';')" + _CT_CFG_STATUS="$(print ${_CT_ENTRY} | cut -f2 -d';')" + _CT_CFG_BOOT="$(print ${_CT_ENTRY} | cut -f3 -d';')" + + # check run-time values + _CT_MATCH=$(grep -i "^[[:space:]]*${_CT_ID}" ${HC_STDOUT_LOG} 2>/dev/null) + if [[ -n "${_CT_MATCH}" ]] + then + # field split + _CT_RUN_STATUS=$(data_lc $(print "${_CT_MATCH}" | tr -s ' ' ';' | cut -f3 -d';')) + _CT_RUN_BOOT=$(data_lc $(print "${_CT_MATCH}" | tr -s ' ' ';' | cut -f4 -d';')) + + if [[ "${_CT_RUN_STATUS}" = "${_CT_CFG_STATUS}" ]] + then + _MSG="container ${_CT_ID} has a correct status [{$_CT_RUN_STATUS}]" + _STC=0 + else + _MSG="container ${_CT_ID} has a wrong status [{$_CT_RUN_STATUS}]" + _STC=1 + fi + log_hc "$0" ${_STC} "${_MSG}" "${_CT_RUN_STATUS}" "${_CT_CFG_STATUS}" + + if [[ "${_CT_RUN_BOOT}" = "${_CT_CFG_BOOT}" ]] + then + _MSG="container ${_CT_ID} has a correct boot flag [${_CT_RUN_BOOT}]" + _STC=0 + else + _MSG="container ${_CT_ID} has a wrong boot flag [${_CT_RUN_BOOT}]" + _STC=1 + fi + log_hc "$0" ${_STC} "${_MSG}" "${_CT_RUN_BOOT}" "${_CT_CFG_BOOT}" + else + warn "could not determine status for container ${_CT_ID} from command output {${_VZLIST_BIN}}" + _RC=1 + fi +done + +return ${_RC} +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 with: + ;; +PURPOSE : Checks whether OpenVZ containers are running or not + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#****************************************************************************** diff --git a/sources/lib/platform/linux/check_linux_winbind_status.sh b/sources/lib/platform/linux/check_linux_winbind_status.sh new file mode 100644 index 0000000..7a59876 --- /dev/null +++ b/sources/lib/platform/linux/check_linux_winbind_status.sh @@ -0,0 +1,127 @@ +#!/usr/bin/env ksh +#****************************************************************************** +# @(#) check_linux_winbind_status.sh +#****************************************************************************** +# @(#) Copyright (C) 2014 by KUDOS BVBA (info@kudos.be). All rights reserved. +# +# This program is a free software; you can redistribute it and/or modify +# it under the same terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +#****************************************************************************** +# +# DOCUMENTATION (MAIN) +# ----------------------------------------------------------------------------- +# @(#) MAIN: check_linux_winbind_status +# DOES: see _show_usage() +# EXPECTS: n/a +# REQUIRES: data_space2comma(), linux_get_init(), init_hc(), log_hc() +# +# @(#) HISTORY: +# @(#) 2013-05-17: initial version [Patrick Van der Veken] +# @(#) 2016-12-01: added systemd code [Patrick Van der Veken] +# @(#) 2017-05-08: fix fall-back for sysv->pgrep [Patrick Van der Veken] +# ----------------------------------------------------------------------------- +# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! +#****************************************************************************** + +# ----------------------------------------------------------------------------- +function check_linux_winbind_status +{ +# ------------------------- CONFIGURATION starts here ------------------------- +typeset _WINBIND_INIT_SCRIPT="/etc/init.d/winbind" +typeset _WINBIND_SYSTEMD_SERVICE="winbind.service" +typeset _VERSION="2017-05-08" # YYYY-MM-DD +typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match +# ------------------------- CONFIGURATION ends here --------------------------- + +# set defaults +(( ARG_DEBUG != 0 && ARG_DEBUG_LEVEL > 0 )) && set ${DEBUG_OPTS} +init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}" +typeset _ARGS=$(data_space2comma "$*") +typeset _ARG="" +typeset _MSG="" +typeset _STC=0 +typeset _RC=0 + +# handle arguments (originally comma-separated) +for _ARG in ${_ARGS} +do + case "${_ARG}" in + help) + _show_usage $0 ${_VERSION} ${_CONFIG_FILE} && return 0 + ;; + esac +done + +# 1) try using the init ways +linux_get_init +case "${LINUX_INIT}" in + 'systemd') + systemctl --quiet is-active ${_WINBIND_SYSTEMD_SERVICE} || _STC=1 + ;; + 'upstart') + warn "code for upstart managed systems not implemented, NOOP" + return 1 + ;; + 'sysv') + if [[ -x ${_WINBIND_INIT_SCRIPT} ]] + then + if (( $(${_WINBIND_INIT_SCRIPT} status 2>>${HC_STDERR_LOG} | grep -c -i 'running') == 0 )) + then + _STC=1 + fi + else + warn "sysv init script not found {${_WINBIND_INIT_SCRIPT}}" + _RC=1 + fi + ;; + *) + _RC=1 + ;; +esac + +# 2) try the pgrep way (note: old pgreps do not support '-c') +if (( _RC != 0 )) +then + (( $(pgrep -u root winbind 2>>${HC_STDERR_LOG} | wc -l) == 0 )) && _STC=1 +fi + +# evaluate & log results +case ${_STC} in + 0) + _MSG="winbind is running" + ;; + 1) + _MSG="winbind is not running" + ;; + *) + _MSG="could not determine status of winbind" + ;; +esac +log_hc "$0" ${_STC} "${_MSG}" + +return 0 +} + +# ----------------------------------------------------------------------------- +function _show_usage +{ +cat <<- EOT +NAME : $1 +VERSION : $2 +CONFIG : $3 +PURPOSE : Checks whether Winbind (AD) is running + +EOT + +return 0 +} + +#****************************************************************************** +# END of script +#******************************************************************************