Add notify_slack plugin
This commit is contained in:
parent
45225e7799
commit
e77d740adb
@ -90,6 +90,7 @@ Additionally, there may be bundles for display or notification plugins, e.g.:
|
||||
* hc-display-terse
|
||||
* hc-notify-eif
|
||||
* hc-notify-sms
|
||||
* hc-notify-slack
|
||||
|
||||
## Configure & deploy
|
||||
|
||||
@ -141,6 +142,7 @@ An Ansible role is available at: https://github.com/patvdv/kudos.check_health
|
||||
* **Alerting** on failed health checks:
|
||||
```
|
||||
/opt/hc/bin/check_health.sh --hc=check_hpux_root_crontab --run --notify=mail --mail-to="alert@acme.com"
|
||||
/opt/hc/bin/check_health.sh --hc=check_linux_fs_usage --run --notify=slack"
|
||||
```
|
||||
|
||||
## References
|
||||
|
1
build/aix/hc_notify_slack/hc_notify_slack.reqs
Normal file
1
build/aix/hc_notify_slack/hc_notify_slack.reqs
Normal file
@ -0,0 +1 @@
|
||||
*prereq hc_aix.rte
|
31
build/aix/hc_notify_slack/hc_notify_slack.template
Normal file
31
build/aix/hc_notify_slack/hc_notify_slack.template
Normal file
@ -0,0 +1,31 @@
|
||||
Package Name: hc_notify_slack
|
||||
Package VRMF: %BUILD_DATE%
|
||||
Update: N
|
||||
Fileset
|
||||
Fileset Name: hc_notify_slack.rte
|
||||
Fileset VRMF: %BUILD_DATE%
|
||||
Fileset Description: Health Checker - core Slack plugin
|
||||
USRLIBLPPFiles
|
||||
EOUSRLIBLPPFiles
|
||||
ROOTLIBLPPFiles
|
||||
Post-installation Script: /export/nim/build/hc_notify_slack/scripts/hc_notify_slack.postinstall
|
||||
Unpost-installation Script: /export/nim/build/hc_notify_slack/scripts/hc_notify_slack.postuninstall
|
||||
EOROOTLIBLPPFiles
|
||||
Bosboot required: N
|
||||
License agreement acceptance required: N
|
||||
Include license files in this package: N
|
||||
Requisites: /export/nim/build/hc_notify_slack/hc_notify_slack.reqs
|
||||
USRFiles
|
||||
EOUSRFiles
|
||||
ROOT Part: Y
|
||||
ROOTFiles
|
||||
/opt/hc/lib
|
||||
/opt/hc/lib/core
|
||||
/opt/hc/lib/platform/aix/notify_slack.sh
|
||||
/etc/opt/hc
|
||||
/etc/opt/hc/core
|
||||
/etc/opt/hc/core/providers
|
||||
/etc/opt/hc/core/providers/notify_slack.conf.dist
|
||||
EOROOTFiles
|
||||
Relocatable: N
|
||||
EOFileset
|
51
build/aix/hc_notify_slack/scripts/hc_notify_sms.postinstall
Normal file
51
build/aix/hc_notify_slack/scripts/hc_notify_sms.postinstall
Normal file
@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env ksh
|
||||
#******************************************************************************
|
||||
# @(#) post-install script for hc_notify_slack LPP package
|
||||
#******************************************************************************
|
||||
# @(#) Copyright (C) 2022 by KUDOS BVBA (info@kudos.be). All rights reserved.
|
||||
#
|
||||
# This program is a free software; you can redistribute it and/or modify
|
||||
# it under the same terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
|
||||
#******************************************************************************
|
||||
|
||||
# ------------------------- CONFIGURATION starts here -------------------------
|
||||
# location of ETC dir
|
||||
HC_ETC_DIR="/etc/opt/hc"
|
||||
# location of check_health.sh
|
||||
HC_BIN="/opt/hc/bin/check_health.sh"
|
||||
PATH="$PATH:/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin"
|
||||
# ------------------------- CONFIGURATION ends here ---------------------------
|
||||
|
||||
print "INFO: starting post-install script ..."
|
||||
|
||||
# copy plugin config file from dist (if needed)
|
||||
if [[ ! -f ${HC_ETC_DIR}/core/providers/notify_slack.conf ]]
|
||||
then
|
||||
cp -p ${HC_ETC_DIR}/core/providers/notify_slack.conf.dist ${HC_ETC_DIR}/core/providers/notify_slack.conf >/dev/null || \
|
||||
{
|
||||
print -u2 "ERROR: could not copy plugin config file in ${HC_ETC_DIR}/core/providers"
|
||||
exit 1
|
||||
}
|
||||
fi
|
||||
|
||||
# refresh symbolic FPATH links
|
||||
if [[ -x ${HC_BIN} ]]
|
||||
then
|
||||
${HC_BIN} --fix-symlinks || print -u2 "WARN: updating symlinks failed"
|
||||
else
|
||||
print -u2 "ERROR: could not locate or excute the HC main script (${HC_BIN})"
|
||||
fi
|
||||
|
||||
print "INFO: finished post-install script"
|
||||
|
||||
exit 0
|
||||
|
||||
#******************************************************************************
|
||||
# END of script
|
||||
#******************************************************************************
|
@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env ksh
|
||||
#******************************************************************************
|
||||
# @(#) post-uninstall script for hc_notify_slack LPP package
|
||||
#******************************************************************************
|
||||
# @(#) Copyright (C) 2022 by KUDOS BVBA (info@kudos.be). All rights reserved.
|
||||
#
|
||||
# This program is a free software; you can redistribute it and/or modify
|
||||
# it under the same terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
|
||||
#******************************************************************************
|
||||
|
||||
# ------------------------- CONFIGURATION starts here -------------------------
|
||||
# location of the HC configuration files
|
||||
HC_ETC_DIR="/etc/opt/hc"
|
||||
# location of check_health.sh
|
||||
HC_BIN="/opt/hc/bin/check_health.sh"
|
||||
PATH="$PATH:/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin"
|
||||
# ------------------------- CONFIGURATION ends here ---------------------------
|
||||
|
||||
print "INFO: starting post-uninstall script ..."
|
||||
|
||||
# remove plugin configuration file (.dist only)
|
||||
if [[ -d ${HC_ETC_DIR}/core/providers ]]
|
||||
then
|
||||
rm -f ${HC_ETC_DIR}/core/providers/notify_slack.conf.dist >/dev/null
|
||||
(( $? == 0 )) || echo "WARN: could not remove plugin config file in directory ${HC_ETC_DIR}/core/providers"
|
||||
fi
|
||||
|
||||
# refresh symbolic FPATH links
|
||||
if [[ -x ${HC_BIN} ]]
|
||||
then
|
||||
${HC_BIN} --fix-symlinks || print -u2 "WARN: updating symlinks failed"
|
||||
else
|
||||
print -u2 "ERROR: could not locate or excute the HC main script (${HC_BIN})"
|
||||
fi
|
||||
|
||||
print "INFO: finished post-uninstall script"
|
||||
|
||||
exit 0
|
||||
|
||||
#******************************************************************************
|
||||
# END of script
|
||||
#******************************************************************************
|
80
build/hpux/hc_notify_slack/hc_notify_slack.psf
Normal file
80
build/hpux/hc_notify_slack/hc_notify_slack.psf
Normal file
@ -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-SLACK
|
||||
title "The Health Checker (HC) for UNIX (core SLACK plugin)"
|
||||
os_name HP-UX
|
||||
revision %BUILD_DATE%
|
||||
architecture HP-UX_B.11_32/64
|
||||
machine_type ia64*
|
||||
vendor_tag KUDOS
|
||||
contents HC-NOTIFY-SLACK-MAIN,r=,a=,v=
|
||||
end
|
||||
|
||||
# Product definitions:
|
||||
product
|
||||
tag HC-NOTIFY-SLACK-MAIN
|
||||
revision %BUILD_DATE%
|
||||
category tools
|
||||
category_title Tools
|
||||
title "The Health Checker (HC) for UNIX (OS plugins)"
|
||||
description "The Health Checker is collection of scripts (plugins)
|
||||
designed to perform regular - but not intensive - health checks on
|
||||
UNIX/Linux systems. It provides plugins for AIX, HP-UX and Linux as
|
||||
well customer specific checks. Checks may include topics such file
|
||||
system mounts, process checks, file consistency etc.
|
||||
This is the core SLACK plugin package"
|
||||
architecture S700/S800_HP-UX_10/HP-UX_11/IA64_HP-UX_11
|
||||
machine_type 9000/7*|9000/8*|ia64*
|
||||
os_name HP-UX
|
||||
os_release ?.1?.*
|
||||
os_version [A-Z]
|
||||
directory /opt/hc
|
||||
is_locatable false
|
||||
is_patch false
|
||||
|
||||
postinstall scripts/hc_notify_slack.postinstall
|
||||
postremove scripts/hc_notify_slack.postremove
|
||||
|
||||
# Fileset definitions:
|
||||
fileset
|
||||
tag core_plugins
|
||||
title UX Health Checker (core SLACK plugins)
|
||||
is_kernel false
|
||||
is_locatable false
|
||||
is_reboot false
|
||||
is_sparse false
|
||||
is_patch false
|
||||
prerequisite HC-HPUX-MAIN
|
||||
|
||||
file_permissions -u 0222 -o root -g sys
|
||||
|
||||
directory ../../../opt/hc/lib/core=/opt/hc/lib/core
|
||||
file -m 755 notify_slack.sh
|
||||
end
|
||||
|
||||
fileset
|
||||
tag config
|
||||
title UX Health Checker (core SLACK plugins: configuration)
|
||||
is_kernel false
|
||||
is_locatable false
|
||||
is_reboot false
|
||||
is_sparse false
|
||||
is_patch false
|
||||
prerequisite HC-NOTIFY-SLACK-MAIN.core_plugins
|
||||
|
||||
file_permissions -u 0222 -o root -g sys
|
||||
|
||||
directory ../../../etc/opt/hc/core/providers=/etc/opt/hc/core/providers
|
||||
file -m 644 notify_slack.conf.dist
|
||||
end
|
||||
end
|
@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env ksh
|
||||
#******************************************************************************
|
||||
# @(#) post-install script for HC-NOTIFY-SLACK SD package
|
||||
#******************************************************************************
|
||||
# @(#) Copyright (C) 2022 by KUDOS BVBA (info@kudos.be). All rights reserved.
|
||||
#
|
||||
# This program is a free software; you can redistribute it and/or modify
|
||||
# it under the same terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
|
||||
#******************************************************************************
|
||||
|
||||
# ------------------------- CONFIGURATION starts here -------------------------
|
||||
# location of ETC dir
|
||||
HC_ETC_DIR="/etc/opt/hc"
|
||||
# location of check_health.sh
|
||||
HC_BIN="/opt/hc/bin/check_health.sh"
|
||||
PATH="$PATH:/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin"
|
||||
# ------------------------- CONFIGURATION ends here ---------------------------
|
||||
|
||||
print "INFO: starting post-install script ..."
|
||||
|
||||
# copy plugin config file from dist (if needed)
|
||||
if [[ ! -f ${HC_ETC_DIR}/core/providers/notify_slack.conf ]]
|
||||
then
|
||||
cp -p ${HC_ETC_DIR}/core/providers/notify_slack.conf.dist ${HC_ETC_DIR}/core/providers/notify_slack.conf >/dev/null || \
|
||||
{
|
||||
print -u2 "ERROR: could not copy plugin config file in ${HC_ETC_DIR}/core/providers"
|
||||
exit 1
|
||||
}
|
||||
fi
|
||||
|
||||
# refresh symbolic FPATH links
|
||||
if [[ -x ${HC_BIN} ]]
|
||||
then
|
||||
${HC_BIN} --fix-symlinks || print -u2 "WARN: updating symlinks failed"
|
||||
else
|
||||
print -u2 "ERROR: could not locate or excute the HC main script (${HC_BIN})"
|
||||
fi
|
||||
|
||||
print "INFO: finished post-install script"
|
||||
|
||||
exit 0
|
||||
|
||||
#******************************************************************************
|
||||
# END of script
|
||||
#******************************************************************************
|
@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env ksh
|
||||
#******************************************************************************
|
||||
# @(#) post-remove script for HC-NOTIFY-SLACK SD package
|
||||
#******************************************************************************
|
||||
# @(#) Copyright (C) 2022 by KUDOS BVBA (info@kudos.be). All rights reserved.
|
||||
#
|
||||
# This program is a free software; you can redistribute it and/or modify
|
||||
# it under the same terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
|
||||
#******************************************************************************
|
||||
|
||||
# ------------------------- CONFIGURATION starts here -------------------------
|
||||
# location of the HC configuration files
|
||||
HC_ETC_DIR="/etc/opt/hc"
|
||||
# location of check_health.sh
|
||||
HC_BIN="/opt/hc/bin/check_health.sh"
|
||||
PATH="$PATH:/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin"
|
||||
# ------------------------- CONFIGURATION ends here ---------------------------
|
||||
|
||||
print "INFO: starting post-remove script ..."
|
||||
|
||||
# remove plugin configuration file (.dist only)
|
||||
if [[ -d ${HC_ETC_DIR}/core/providers ]]
|
||||
then
|
||||
rm -f ${HC_ETC_DIR}/core/providers/notify_slack.conf.dist >/dev/null
|
||||
(( $? == 0 )) || echo "WARN: could not remove plugin config file in directory ${HC_ETC_DIR}/core/providers"
|
||||
fi
|
||||
|
||||
# refresh symbolic FPATH links
|
||||
if [[ -x ${HC_BIN} ]]
|
||||
then
|
||||
${HC_BIN} --fix-symlinks || print -u2 "WARN: updating symlinks failed"
|
||||
else
|
||||
print -u2 "ERROR: could not locate or excute the HC main script (${HC_BIN})"
|
||||
fi
|
||||
|
||||
print "INFO: finished post-remove script"
|
||||
|
||||
exit 0
|
||||
|
||||
#******************************************************************************
|
||||
# END of script
|
||||
#******************************************************************************
|
33
build/linux/ARCH/hc-notify-slack/.install
Normal file
33
build/linux/ARCH/hc-notify-slack/.install
Normal file
@ -0,0 +1,33 @@
|
||||
# -- post-install --
|
||||
post_install() {
|
||||
# ------------------------- CONFIGURATION starts here -------------------------
|
||||
# location of check_health.sh
|
||||
HC_BIN="/opt/hc/bin/check_health.sh"
|
||||
PATH="$PATH:/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin"
|
||||
# ------------------------- CONFIGURATION ends here ---------------------------
|
||||
echo "INFO: starting post-install script ..."
|
||||
# refresh symbolic FPATH links
|
||||
if [[ -x ${HC_BIN} ]]
|
||||
then
|
||||
${HC_BIN} --fix-symlinks
|
||||
(( $? == 0 )) || echo "WARN: updating symlinks failed"
|
||||
fi
|
||||
echo "INFO: finished post-install script"
|
||||
}
|
||||
|
||||
# -- post-remove --
|
||||
post_remove() {
|
||||
# ------------------------- CONFIGURATION starts here -------------------------
|
||||
# location of check_health.sh
|
||||
HC_BIN="/opt/hc/bin/check_health.sh"
|
||||
PATH="$PATH:/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin"
|
||||
# ------------------------- CONFIGURATION ends here ---------------------------
|
||||
echo "INFO: starting post-uninstall script ..."
|
||||
# refresh symbolic FPATH links
|
||||
if [[ -x ${HC_BIN} ]]
|
||||
then
|
||||
${HC_BIN} --fix-symlinks
|
||||
(( $? == 0 )) || echo "WARN: updating symlinks failed"
|
||||
fi
|
||||
echo "INFO: finished post-uninstall script"
|
||||
}
|
26
build/linux/ARCH/hc-notify-slack/PKGBUILD
Normal file
26
build/linux/ARCH/hc-notify-slack/PKGBUILD
Normal file
@ -0,0 +1,26 @@
|
||||
# Maintainer: Patrick Van der Veken <patrick@kudos.be>
|
||||
|
||||
_pkgname="check_health"
|
||||
pkgname="hc-notify-slack"
|
||||
pkgver="%BUILD_DATE%"
|
||||
pkgrel=1
|
||||
pkgdesc="The KUDOS Health Checker (HC) for UNIX (Slack notify core plugin)"
|
||||
arch=("any")
|
||||
url="https://github.com/patvdv/${_pkgname}"
|
||||
license=('GPL3')
|
||||
makedepends=('git')
|
||||
depends=('hc-linux')
|
||||
source=("${_pkgname}::git+${url}.git#branch=master")
|
||||
install=".install"
|
||||
sha256sums=('SKIP')
|
||||
|
||||
package() {
|
||||
cd "${srcdir}/${_pkgname}"
|
||||
install -d -m 755 ${pkgdir}/opt/hc/lib
|
||||
install -d -m 755 ${pkgdir}/opt/hc/lib/core
|
||||
install -D -m 755 opt/hc/lib/core/notify_slack.sh ${pkgdir}/opt/hc/lib/core/notify_slack.sh
|
||||
install -d -m 755 ${pkgdir}/etc/opt/hc
|
||||
install -d -m 755 ${pkgdir}/etc/opt/hc/core
|
||||
install -d -m 755 ${pkgdir}/etc/opt/hc/core/providers
|
||||
install -D -m 644 etc/opt/hc/core/providers/notify_slack.conf.dist ${pkgdir}/etc/opt/hc/core/providers/notify_slack.conf.dist
|
||||
}
|
10
build/linux/DEBIAN/hc-notify-slack/control
Normal file
10
build/linux/DEBIAN/hc-notify-slack/control
Normal file
@ -0,0 +1,10 @@
|
||||
Package: hc-notify-slack
|
||||
Version: %BUILD_DATE%
|
||||
Architecture: all
|
||||
Maintainer: Patrick Van der Veken <patrick@kudos.be>
|
||||
Essential: no
|
||||
Installed-Size: 50
|
||||
Pre-Depends: hc-linux
|
||||
Section: tools
|
||||
Priority: extra
|
||||
Description: The KUDOS Health Checker (HC) for UNIX (Slack notify core plugin).
|
33
build/linux/DEBIAN/hc-notify-slack/postinst
Normal file
33
build/linux/DEBIAN/hc-notify-slack/postinst
Normal file
@ -0,0 +1,33 @@
|
||||
#!/bin/bash
|
||||
# ------------------------- CONFIGURATION starts here -------------------------
|
||||
# location of the HC configuration files
|
||||
HC_ETC_DIR="/etc/opt/hc"
|
||||
# location of check_health.sh
|
||||
HC_BIN="/opt/hc/bin/check_health.sh"
|
||||
PATH="$PATH:/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin"
|
||||
# ------------------------- CONFIGURATION ends here ---------------------------
|
||||
echo "INFO: starting post-install script ..."
|
||||
# debian: reset ownerships
|
||||
chown -R root:root /opt/hc /etc/opt/hc 2>/dev/null
|
||||
# copy plugin configuration file
|
||||
if [[ -f ${HC_ETC_DIR}/core/providers/notify_slack.conf.dist ]]
|
||||
then
|
||||
if [[ ! -f ${HC_ETC_DIR}/core/providers/notify_slack.conf ]]
|
||||
then
|
||||
cp -p ${HC_ETC_DIR}/core/providers/notify_slack.conf.dist ${HC_ETC_DIR}/core/providers/notify_slack.conf >/dev/null
|
||||
(( $? == 0 )) || \
|
||||
{
|
||||
echo "ERROR: could not copy plugin config file in ${HC_ETC_DIR}/core/providers"
|
||||
exit 1
|
||||
}
|
||||
fi
|
||||
else
|
||||
echo "WARN: could not find plugin config .dist file in ${HC_ETC_DIR}/core/providers"
|
||||
fi
|
||||
# refresh symbolic FPATH links
|
||||
if [[ -x ${HC_BIN} ]]
|
||||
then
|
||||
${HC_BIN} --fix-symlinks
|
||||
(( $? == 0 )) || echo "WARN: updating symlinks failed"
|
||||
fi
|
||||
echo "INFO: finished post-install script"
|
32
build/linux/DEBIAN/hc-notify-slack/postrm
Normal file
32
build/linux/DEBIAN/hc-notify-slack/postrm
Normal file
@ -0,0 +1,32 @@
|
||||
#!/bin/bash
|
||||
# ------------------------- CONFIGURATION starts here -------------------------
|
||||
# location of the HC configuration files
|
||||
HC_ETC_DIR="/etc/opt/hc"
|
||||
# location of check_health.sh
|
||||
HC_BIN="/opt/hc/bin/check_health.sh"
|
||||
PATH="$PATH:/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin"
|
||||
# ------------------------- CONFIGURATION ends here ---------------------------
|
||||
# update or uninstall?
|
||||
if (( $1 == 0 ))
|
||||
then
|
||||
echo "INFO: starting post-uninstall script ..."
|
||||
# copy plugin configuration file (.dist only)
|
||||
if [[ -d ${HC_ETC_DIR}/core/providers ]]
|
||||
then
|
||||
rm -f ${HC_ETC_DIR}/core/providers/notify_slack.conf.dist 2>/dev/null
|
||||
(( $? == 0 )) || \
|
||||
{
|
||||
echo "ERROR: could not remove plugin config file in ${HC_ETC_DIR}/core/providers"
|
||||
exit 1
|
||||
}
|
||||
fi
|
||||
else
|
||||
echo "INFO: starting post-uninstall script (RPM upgrade)"
|
||||
fi
|
||||
# refresh symbolic FPATH links
|
||||
if [[ -x ${HC_BIN} ]]
|
||||
then
|
||||
${HC_BIN} --fix-symlinks
|
||||
(( $? == 0 )) || echo "WARN: updating symlinks failed"
|
||||
fi
|
||||
echo "INFO: finished post-uninstall script"
|
107
build/linux/SPECS/hc-notify-slack.spec
Normal file
107
build/linux/SPECS/hc-notify-slack.spec
Normal file
@ -0,0 +1,107 @@
|
||||
%define build_timestamp %(date +"%Y%m%d")
|
||||
|
||||
Name: hc-notify-slack
|
||||
Version: %{build_timestamp}
|
||||
Release: 1
|
||||
|
||||
Summary: The KUDOS Health Checker (HC) for UNIX (Slack notify core plugin)
|
||||
Group: Tools/Monitoring
|
||||
|
||||
License: GNU General Public License either version 2 of the License, or (at your option) any later version
|
||||
URL: http://www.kudos.be
|
||||
|
||||
Requires: ksh,hc-linux
|
||||
BuildArch: noarch
|
||||
BuildRoot: %{_topdir}/%{name}-%{version}-root
|
||||
|
||||
%description
|
||||
The Health Checker is collection of scripts (plugins) designed to perform regular - but not intensive - health checks on UNIX/Linux systems. It provides plugins for AIX, HP-UX and Linux as well customer specific checks. Checks may include topics such file system mounts, process checks, file consistency etc.
|
||||
This package contains core plugins (notify).
|
||||
|
||||
%prep
|
||||
|
||||
%build
|
||||
|
||||
%install
|
||||
rm -rf $RPM_BUILD_ROOT
|
||||
install -d -m 755 $RPM_BUILD_ROOT/opt/hc/lib
|
||||
install -d -m 755 $RPM_BUILD_ROOT/opt/hc/lib/core
|
||||
cp ../SOURCES/opt/hc/lib/core/notify_slack.sh $RPM_BUILD_ROOT/opt/hc/lib/core/notify_slack.sh
|
||||
install -d -m 755 $RPM_BUILD_ROOT/etc/opt/hc
|
||||
install -d -m 755 $RPM_BUILD_ROOT/etc/opt/hc/core
|
||||
install -d -m 755 $RPM_BUILD_ROOT/etc/opt/hc/core/providers
|
||||
cp ../SOURCES/etc/opt/hc/core/providers/notify_slack.conf.dist $RPM_BUILD_ROOT/etc/opt/hc/core/providers/notify_slack.conf.dist
|
||||
|
||||
%post
|
||||
# ------------------------- CONFIGURATION starts here -------------------------
|
||||
# location of the HC configuration files
|
||||
HC_ETC_DIR="/etc/opt/hc"
|
||||
# location of check_health.sh
|
||||
HC_BIN="/opt/hc/bin/check_health.sh"
|
||||
PATH="$PATH:/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin"
|
||||
# ------------------------- CONFIGURATION ends here ---------------------------
|
||||
echo "INFO: starting post-install script ..."
|
||||
# copy plugin configuration file
|
||||
if [[ ! -f ${HC_ETC_DIR}/core/providers/notify_slack.conf ]]
|
||||
then
|
||||
cp -p ${HC_ETC_DIR}/core/providers/notify_slack.conf.dist ${HC_ETC_DIR}/core/providers/notify_slack.conf >/dev/null
|
||||
(( $? == 0 )) || \
|
||||
{
|
||||
echo "ERROR: could not copy plugin config file in ${HC_ETC_DIR}/core/providers"
|
||||
exit 1
|
||||
}
|
||||
fi
|
||||
# refresh symbolic FPATH links
|
||||
if [[ -x ${HC_BIN} ]]
|
||||
then
|
||||
${HC_BIN} --fix-symlinks
|
||||
(( $? == 0 )) || echo "WARN: updating symlinks failed"
|
||||
fi
|
||||
echo "INFO: finished post-install script"
|
||||
|
||||
%postun
|
||||
# ------------------------- CONFIGURATION starts here -------------------------
|
||||
# location of the HC configuration files
|
||||
HC_ETC_DIR="/etc/opt/hc"
|
||||
# location of check_health.sh
|
||||
HC_BIN="/opt/hc/bin/check_health.sh"
|
||||
PATH="$PATH:/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin"
|
||||
# ------------------------- CONFIGURATION ends here ---------------------------
|
||||
# update or uninstall?
|
||||
if (( $1 == 0 ))
|
||||
then
|
||||
echo "INFO: starting post-uninstall script ..."
|
||||
# copy plugin configuration file (.dist only)
|
||||
if [[ -d ${HC_ETC_DIR}/core/providers ]]
|
||||
then
|
||||
rm -f ${HC_ETC_DIR}/core/providers/notify_slack.conf.dist 2>/dev/null
|
||||
(( $? == 0 )) || \
|
||||
{
|
||||
echo "ERROR: could not remove plugin config file in ${HC_ETC_DIR}/core/providers"
|
||||
exit 1
|
||||
}
|
||||
fi
|
||||
else
|
||||
echo "INFO: starting post-uninstall script (RPM upgrade)"
|
||||
fi
|
||||
# refresh symbolic FPATH links
|
||||
if [[ -x ${HC_BIN} ]]
|
||||
then
|
||||
${HC_BIN} --fix-symlinks
|
||||
(( $? == 0 )) || echo "WARN: updating symlinks failed"
|
||||
fi
|
||||
echo "INFO: finished post-uninstall script"
|
||||
|
||||
%files
|
||||
%defattr(-,root,root,755)
|
||||
%dir /opt/hc/lib
|
||||
%dir /opt/hc/lib/core
|
||||
%attr(755, root, root) /opt/hc/lib/core/notify_slack.sh
|
||||
%dir /etc/opt/hc
|
||||
%dir /etc/opt/hc/core
|
||||
%dir /etc/opt/hc/core/providers
|
||||
%attr(644, root, root) /etc/opt/hc/core/providers/notify_slack.conf.dist
|
||||
|
||||
%changelog
|
||||
* Sun Oct 14 2022 <patrick@kudos.be> - 0.0.1
|
||||
- Initial build
|
@ -47,6 +47,7 @@ rpmbuild -bb ${BUILD_DIR}/SPECS/hc-linux-platform.spec
|
||||
# build core plugins
|
||||
rpmbuild -bb ${BUILD_DIR}/SPECS/hc-notify-eif.spec
|
||||
rpmbuild -bb ${BUILD_DIR}/SPECS/hc-notify-sms.spec
|
||||
rpmbuild -bb ${BUILD_DIR}/SPECS/hc-notify-slack.spec
|
||||
rpmbuild -bb ${BUILD_DIR}/SPECS/hc-display-init.spec
|
||||
rpmbuild -bb ${BUILD_DIR}/SPECS/hc-display-json.spec
|
||||
rpmbuild -bb ${BUILD_DIR}/SPECS/hc-display-csv.spec
|
||||
|
15
etc/opt/hc/core/providers/notify_slack.conf.dist
Normal file
15
etc/opt/hc/core/providers/notify_slack.conf.dist
Normal file
@ -0,0 +1,15 @@
|
||||
#******************************************************************************
|
||||
# @(#) notify_slack.conf
|
||||
#******************************************************************************
|
||||
# This is the the configuration file for the notify_slack.sh provider.
|
||||
# All lines starting with a '#' are comment lines.
|
||||
# [default: indicates hardcoded script values if no value is defined here]
|
||||
#******************************************************************************
|
||||
|
||||
# URL of the webhook of the Slack app
|
||||
SLACK_WEBHOOK=""
|
||||
|
||||
|
||||
#******************************************************************************
|
||||
# End of FILE
|
||||
#******************************************************************************
|
@ -30,7 +30,7 @@
|
||||
# RETURNS: 0
|
||||
function version_include_core
|
||||
{
|
||||
typeset _VERSION="2021-03-28" # YYYY-MM-DD
|
||||
typeset _VERSION="2022-10-14" # YYYY-MM-DD
|
||||
|
||||
print "INFO: $0: ${_VERSION#version_*}"
|
||||
|
||||
@ -307,6 +307,7 @@ DO_DISPLAY_CUSTOM9=0
|
||||
DO_NOTIFY_EIF=0
|
||||
DO_NOTIFY_MAIL=0
|
||||
DO_NOTIFY_SMS=0
|
||||
DO_NOTIFY_SLACK=0
|
||||
DO_REPORT_STD=0
|
||||
HAS_DISPLAY_CSV=0
|
||||
HAS_DISPLAY_INIT=0
|
||||
@ -325,6 +326,7 @@ HAS_DISPLAY_CUSTOM9=0
|
||||
HAS_NOTIFY_EIF=0
|
||||
HAS_NOTIFY_MAIL=0
|
||||
HAS_NOTIFY_SMS=0
|
||||
HAS_NOTIFY_SLACK=0
|
||||
HAS_REPORT_STD=0
|
||||
|
||||
# check which core display/notification plugins are installed
|
||||
@ -402,6 +404,10 @@ do
|
||||
HAS_NOTIFY_EIF=1
|
||||
(( ARG_DEBUG > 0 )) && debug "notify_eif plugin is available"
|
||||
;;
|
||||
*notify_slack.sh)
|
||||
HAS_NOTIFY_SLACK=1
|
||||
(( ARG_DEBUG > 0 )) && debug "notify_slack plugin is available"
|
||||
;;
|
||||
*report_std.sh)
|
||||
# shellcheck disable=SC2034
|
||||
HAS_REPORT_STD=1
|
||||
@ -559,6 +565,9 @@ then
|
||||
*mail*) # by mail
|
||||
DO_NOTIFY_MAIL=1
|
||||
;;
|
||||
*slack*) # by Slack
|
||||
DO_NOTIFY_SLACK=1
|
||||
;;
|
||||
*sms*) # by sms
|
||||
DO_NOTIFY_SMS=1
|
||||
;;
|
||||
@ -1416,6 +1425,17 @@ then
|
||||
warn "notify_sms plugin is not avaible, cannot send alert via sms!"
|
||||
fi
|
||||
fi
|
||||
# by Slack?
|
||||
if (( DO_NOTIFY_SLACK == 1 ))
|
||||
then
|
||||
if (( HAS_NOTIFY_SLACK == 1 ))
|
||||
then
|
||||
# call plugin
|
||||
notify_slack "${HC_NAME}" "${HC_FAIL_ID}"
|
||||
else
|
||||
warn "notify_slack plugin is not avaible, cannot send alert via Slack!"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
|
135
opt/hc/lib/core/notify_slack.sh
Normal file
135
opt/hc/lib/core/notify_slack.sh
Normal file
@ -0,0 +1,135 @@
|
||||
#!/usr/bin/env ksh
|
||||
#******************************************************************************
|
||||
# @(#) notify_slack.sh
|
||||
#******************************************************************************
|
||||
# @(#) Copyright (C) 2022 by KUDOS BVBA (info@kudos.be). All rights reserved.
|
||||
#
|
||||
# This program is a free software; you can redistribute it and/or modify
|
||||
# it under the same terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
|
||||
#******************************************************************************
|
||||
#
|
||||
# DOCUMENTATION (MAIN)
|
||||
# -----------------------------------------------------------------------------
|
||||
# @(#) MAIN: notify_slack
|
||||
# DOES: send message to slack app
|
||||
# EXPECTS: 1=HC name [string], 2=HC FAIL_ID [string]
|
||||
# RETURNS: 0
|
||||
# REQUIRES: data_contains_string(), data_get_lvalue_from_config(), data_magic_unquote(),
|
||||
# init_hc(), log(), warn(), curl
|
||||
#
|
||||
# -----------------------------------------------------------------------------
|
||||
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
|
||||
#******************************************************************************
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
function notify_slack
|
||||
{
|
||||
# ------------------------- CONFIGURATION starts here -------------------------
|
||||
typeset _CONFIG_FILE="${CONFIG_DIR}/core/providers/$0.conf"
|
||||
typeset _VERSION="2022-10-14" # YYYY-MM-DD
|
||||
typeset _SUPPORTED_PLATFORMS="AIX,HP-UX,Linux" # uname -s match
|
||||
# ------------------------- CONFIGURATION ends here ---------------------------
|
||||
|
||||
# set defaults
|
||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}"
|
||||
init_hc "$0" "${_SUPPORTED_PLATFORMS}" "${_VERSION}"
|
||||
|
||||
typeset _SLACK_HC="$1"
|
||||
typeset _SLACK_FAIL_ID="$2"
|
||||
|
||||
typeset _SLACK_TEXT=""
|
||||
typeset _SLACK_MSG_STC=""
|
||||
typeset _SLACK_MSG_TEXT=""
|
||||
typeset _SLACK_MSG_CUR_VAL=""
|
||||
typeset _SLACK_MSG_EXP_VAL=""
|
||||
typeset _CURL_BIN=""
|
||||
typeset _SLACK_WEBHOOK=""
|
||||
|
||||
# handle config file
|
||||
if [[ ! -r ${_CONFIG_FILE} ]]
|
||||
then
|
||||
warn "unable to read configuration file at ${_CONFIG_FILE}"
|
||||
return 1
|
||||
fi
|
||||
# read required config values
|
||||
_SLACK_WEBHOOK=$(_CONFIG_FILE="${_CONFIG_FILE}" data_get_lvalue_from_config 'SLACK_WEBHOOK')
|
||||
if [[ -z "${_SLACK_WEBHOOK}" ]]
|
||||
then
|
||||
warn "no value set for 'SLACK_WEBHOOK' in ${_CONFIG_FILE}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# create header part
|
||||
_SLACK_TEXT="${EXEC_USER}@${HOST_NAME}: HC ${_SLACK_HC} failed, FAIL_ID=${_SLACK_FAIL_ID}"
|
||||
|
||||
# create body part (from $HC_MSG_VAR)
|
||||
print "${HC_MSG_VAR}" | while IFS=${MSG_SEP} read -r _SLACK_MSG_STC _ _SLACK_MSG_TEXT _SLACK_MSG_CUR_VAL _SLACK_MSG_EXP_VAL
|
||||
do
|
||||
# magically unquote if needed
|
||||
if [[ -n "${_SLACK_MSG_TEXT}" ]]
|
||||
then
|
||||
data_contains_string "${_SLACK_MSG_TEXT}" "${MAGIC_QUOTE}"
|
||||
# shellcheck disable=SC2181
|
||||
if (( $? > 0 ))
|
||||
then
|
||||
_SLACK_MSG_TEXT=$(data_magic_unquote "${_SLACK_MSG_TEXT}")
|
||||
fi
|
||||
fi
|
||||
if [[ -n "${_SLACK_MSG_CUR_VAL}" ]]
|
||||
then
|
||||
data_contains_string "${_SLACK_MSG_CUR_VAL}" "${MAGIC_QUOTE}"
|
||||
# shellcheck disable=SC2181
|
||||
if (( $? > 0 ))
|
||||
then
|
||||
_SLACK_MSG_CUR_VAL=$(data_magic_unquote "${_SLACK_MSG_CUR_VAL}")
|
||||
fi
|
||||
fi
|
||||
if [[ -n "${_SLACK_MSG_EXP_VAL}" ]]
|
||||
then
|
||||
data_contains_string "${_SLACK_MSG_EXP_VAL}" "${MAGIC_QUOTE}"
|
||||
# shellcheck disable=SC2181
|
||||
if (( $? > 0 ))
|
||||
then
|
||||
_SLACK_MSG_EXP_VAL=$(data_magic_unquote "${_SLACK_MSG_EXP_VAL}")
|
||||
fi
|
||||
fi
|
||||
if (( _SLACK_MSG_STC > 0 ))
|
||||
then
|
||||
# shellcheck disable=SC1117
|
||||
_SLACK_BODY=$(printf "%s\n%s\n" "${_SLACK_BODY}" "${_SLACK_MSG_TEXT}")
|
||||
fi
|
||||
done
|
||||
|
||||
# send message
|
||||
# find 'curl'
|
||||
_CURL_BIN="$(command -v curl 2>/dev/null)"
|
||||
if [[ -x ${_CURL_BIN} ]] && [[ -n "${_CURL_BIN}" ]]
|
||||
then
|
||||
if (( ARG_DEBUG == 0 ))
|
||||
then
|
||||
${_CURL_BIN} --silent --data-urlencode \
|
||||
"$(printf 'payload={"text": "%s\n\n%s" }' "${_SLACK_TEXT}" "${_SLACK_BODY}")" \
|
||||
"${_SLACK_WEBHOOK}" >/dev/null 2>&1
|
||||
else
|
||||
${_CURL_BIN} --data-urlencode \
|
||||
"$(printf 'payload={"text": "%s\n\n%s" }' "${_SLACK_TEXT}" "${_SLACK_BODY}")" \
|
||||
"${_SLACK_WEBHOOK}"
|
||||
fi
|
||||
else
|
||||
die "unable to send message to Slack - curl is not installed here"
|
||||
fi
|
||||
|
||||
log "Slack alert sent: ${_SLACK_HC} failed, FAIL_ID=${_SLACK_FAIL_ID}"
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
#******************************************************************************
|
||||
# END of script
|
||||
#******************************************************************************
|
@ -20,7 +20,8 @@
|
||||
# DOES: send sms alert
|
||||
# EXPECTS: 1=HC name [string], 2=HC FAIL_ID [string]
|
||||
# RETURNS: 0
|
||||
# REQUIRES: data_get_lvalue_from_config(), init_hc(), log(), warn()
|
||||
# REQUIRES: data_encode_url(), data_get_lvalue_from_config(), init_hc(),
|
||||
# log(), warn(), curl
|
||||
#
|
||||
# -----------------------------------------------------------------------------
|
||||
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
|
||||
@ -31,7 +32,7 @@ function notify_sms
|
||||
{
|
||||
# ------------------------- CONFIGURATION starts here -------------------------
|
||||
typeset _CONFIG_FILE="${CONFIG_DIR}/core/providers/$0.conf"
|
||||
typeset _VERSION="2018-10-28" # YYYY-MM-DD
|
||||
typeset _VERSION="2022-10-14" # YYYY-MM-DD
|
||||
typeset _SUPPORTED_PLATFORMS="AIX,HP-UX,Linux" # uname -s match
|
||||
# ------------------------- CONFIGURATION ends here ---------------------------
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user