Mise à jour des scripts
Cette révision appartient à :
Parent
c2ab3529c3
révision
065626d815
|
@ -16,13 +16,13 @@ Un script `alerts_switch` s'occupera de gérer le fichier temporaire.
|
|||
# /usr/share/script/alerts_switch disable tomcat
|
||||
~~~
|
||||
|
||||
Cette action va créer un fichier temporaire `/tmp/tomcat_alerts_disabled` et inscrire une entrée datée dans le fichier `/var/log/tomcat_alerts.log`.
|
||||
Cette action va créer un fichier temporaire `/var/lib/misc/tomcat_alerts_disabled` et inscrire une entrée datée dans le fichier `/var/log/tomcat_alerts.log`.
|
||||
|
||||
~~~
|
||||
# /usr/share/script/alerts_switch enable tomcat
|
||||
~~~
|
||||
|
||||
Cette action va renommer le fichier en `/tmp/tomcat_alerts_enabled` s'il existe ou le créer (pour indiquer clairement qu'on a souhaité que les alertes soient activées).
|
||||
Cette action va renommer le fichier en `/var/lib/misc/tomcat_alerts_enabled` s'il existe ou le créer (pour indiquer clairement qu'on a souhaité que les alertes soient activées).
|
||||
|
||||
NB : on ne se contente pas de supprimer le fichier "disabled" pour ne pas risquer de supprimer un fichier important qui serait là au préalable, portant par malchance le même nom.
|
||||
|
||||
|
@ -31,6 +31,11 @@ Détail du script `alerts_switch` :
|
|||
~~~{.bash}
|
||||
#!/bin/bash
|
||||
|
||||
# https://forge.evolix.org/projects/evolix-private/repository
|
||||
#
|
||||
# You should not alter this file.
|
||||
# If you need to, create and customize a copy.
|
||||
|
||||
set -e
|
||||
|
||||
readonly PROGNAME=$(basename $0)
|
||||
|
@ -49,6 +54,7 @@ disable_alerts () {
|
|||
mv "${enabled_file}" "${disabled_file}"
|
||||
else
|
||||
touch "${disabled_file}"
|
||||
chmod 0644 "${disabled_file}"
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -60,6 +66,7 @@ enable_alerts () {
|
|||
mv "${disabled_file}" "${enabled_file}"
|
||||
else
|
||||
touch "${enabled_file}"
|
||||
chmod 0644 "${enabled_file}"
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -68,18 +75,21 @@ now () {
|
|||
}
|
||||
|
||||
log_disable () {
|
||||
echo "$(now) - alerts disabled by $(logname)" >> $1
|
||||
echo "$(now) - alerts disabled by $(logname || echo unknown)" >> $1
|
||||
}
|
||||
|
||||
log_enable () {
|
||||
echo "$(now) - alerts enabled by $(logname)">> $1
|
||||
echo "$(now) - alerts enabled by $(logname || echo unknown)" >> $1
|
||||
}
|
||||
|
||||
main () {
|
||||
local action=$1
|
||||
local prefix=$2
|
||||
|
||||
local file_path="/tmp/${prefix}_alerts"
|
||||
local base_dir="/var/lib/misc"
|
||||
mkdir -p "${base_dir}"
|
||||
|
||||
local file_path="${base_dir}/${prefix}_alerts"
|
||||
local log_file="/var/log/${prefix}_alerts.log"
|
||||
|
||||
case "$action" in
|
||||
|
@ -127,25 +137,41 @@ Détail du script `alerts_wrapper` :
|
|||
~~~{.bash}
|
||||
#!/bin/bash
|
||||
|
||||
readonly check_file="/tmp/$1_alerts_disabled"
|
||||
# https://forge.evolix.org/projects/evolix-private/repository
|
||||
#
|
||||
# You should not alter this file.
|
||||
# If you need to, create and customize a copy.
|
||||
|
||||
readonly check_name="${1}"
|
||||
readonly check_file="/var/lib/misc/${check_name}_alerts_disabled"
|
||||
readonly check_stdout=$(mktemp --tmpdir=/tmp "${check_name}_stdout.XXXX")
|
||||
|
||||
trap "rm ${check_stdout}" EXIT
|
||||
|
||||
shift
|
||||
|
||||
readonly check_stdout=$($@)
|
||||
readonly check_command="$@"
|
||||
|
||||
$check_command > $check_stdout
|
||||
readonly check_rc=$?
|
||||
|
||||
if [ -e "${check_file}" ]; then
|
||||
local last_change=$(stat -c %Z "${check_file}")
|
||||
local limit=$(date --date '24 hours ago' +'%s')
|
||||
delay=0
|
||||
|
||||
if [ ${last_change} -le ${limit} ]; then
|
||||
rm "${check_file}"
|
||||
if [ -e "${check_file}" ]; then
|
||||
readonly last_change=$(stat -c %Z "${check_file}")
|
||||
readonly limit=$(date --date '24 hours ago' +'%s')
|
||||
|
||||
delay=$((${last_change} - ${limit}))
|
||||
|
||||
if [ "${delay}" -le "0" ]; then
|
||||
sudo /usr/share/scripts/alerts_switch enable ${check_name}
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -e "${check_file}" ]; then
|
||||
local formatted_last_change=$(date --date "@$(stat -c %Z "${check_file}")" +'%c')
|
||||
readonly formatted_last_change=$(date --date "@$(stat -c %Z "${check_file}")" +'%c')
|
||||
|
||||
echo "ALERTS DISABLED (since ${formatted_last_change}) - ${check_stdout}"
|
||||
echo "ALERTS DISABLED for ${check_name} (since ${formatted_last_change}, delay: ${delay} sec) - ${check_stdout}"
|
||||
if [ ${check_rc} = 0 ]; then
|
||||
# Nagios OK
|
||||
exit 0
|
||||
|
@ -154,14 +180,14 @@ if [ -e "${check_file}" ]; then
|
|||
exit 1
|
||||
fi
|
||||
else
|
||||
echo ${check_stdout}
|
||||
cat ${check_stdout}
|
||||
exit ${check_rc}
|
||||
fi
|
||||
~~~
|
||||
|
||||
Le wrapper exécute le check et en met de côté la sortie standard et le code de sortie.
|
||||
|
||||
Il cherche ensuite le fichier `/var/tmp/tomcat_alerts_disabled`.
|
||||
Il cherche ensuite le fichier `/var/lib/misc/tomcat_alerts_disabled`.
|
||||
|
||||
S'il est présent et vieux de plus de 24h, il sera détruit pour ne pas risquer d'oubli.
|
||||
|
||||
|
|
Chargement…
Référencer dans un nouveau ticket