update-config
This commit is contained in:
@@ -35,7 +35,7 @@ curl -sSL https://git.abonnel.fr/cedricAbonnel/scripts-bash/raw/branch/main/serv
|
||||
|
||||
---
|
||||
|
||||
## ⚙️ Configuration (Que modifier ?)
|
||||
## Configuration (Que modifier ?)
|
||||
|
||||
Après l'installation, vous devez configurer vos accès pour recevoir les alertes.
|
||||
|
||||
@@ -52,7 +52,7 @@ Modifiez les variables suivantes :
|
||||
|
||||
### 2. Seuils des sondes
|
||||
|
||||
Vous pouvez modifier les variables `WARNING` et `CRITICAL` directement dans les scripts du dossier `bin/` ou, mieux, les définir dans `/opt/monitoring/conf/monitoring.conf`.
|
||||
Vous pouvez modifier les variables `WARNING` et `CRITICAL` directement dans les scripts du dossier `bin/` ou, mieux, les définir dans `/opt/monitoring/conf/monitoring.local.conf`.
|
||||
|
||||
---
|
||||
|
||||
|
||||
90
servers/linux/monitoring/bin/monitor-update-config.sh
Executable file
90
servers/linux/monitoring/bin/monitor-update-config.sh
Executable file
@@ -0,0 +1,90 @@
|
||||
#!/bin/bash
|
||||
# Copyright (C) 2026 Cédric Abonnel
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
|
||||
|
||||
set -u
|
||||
|
||||
SCRIPT_NAME="$(basename "$0")"
|
||||
. /opt/monitoring/lib/monitoring-lib.sh || exit 3
|
||||
|
||||
# On s'assure d'avoir les permissions root
|
||||
if [ "${EUID}" -ne 0 ]; then
|
||||
echo "Ce script doit être exécuté en root." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
check_config_drift() {
|
||||
local conf_dir="/opt/monitoring/conf"
|
||||
local base_conf local_conf
|
||||
local found_issue=false
|
||||
|
||||
log_info "audit_start" "Début de l'audit des configurations"
|
||||
|
||||
# Parcourir tous les fichiers .conf officiels
|
||||
find "$conf_dir" -type f -name "*.conf" ! -name "*.local.conf" | while read -r base_conf; do
|
||||
local_conf="${base_conf%.conf}.local.conf"
|
||||
local file_name
|
||||
file_name=$(basename "$base_conf")
|
||||
|
||||
# 1. Si le .local.conf n'existe pas : on le crée proprement
|
||||
if [ ! -f "$local_conf" ]; then
|
||||
log_notice "audit_missing_local" "Création du fichier local manquant" "file=$file_name"
|
||||
# On copie le template en commentant les valeurs par défaut pour inciter à la config
|
||||
cp "$base_conf" "$local_conf"
|
||||
chmod 600 "$local_conf"
|
||||
continue
|
||||
fi
|
||||
|
||||
# 2. Si le .local.conf existe : on compare les clés (options)
|
||||
local tmp_base tmp_local
|
||||
tmp_base=$(mktemp)
|
||||
tmp_local=$(mktemp)
|
||||
|
||||
# Extraction des noms de variables uniquement (Clés)
|
||||
grep -E '^[A-Za-z0-9_]+=' "$base_conf" | cut -d'=' -f1 | sort > "$tmp_base"
|
||||
grep -E '^[A-Za-z0-9_]+=' "$local_conf" | cut -d'=' -f1 | sort > "$tmp_local"
|
||||
|
||||
# Options présentes dans le .conf mais absentes du .local.conf
|
||||
local missing
|
||||
missing=$(comm -23 "$tmp_base" "$tmp_local" | tr '\n' ' ' | xargs)
|
||||
|
||||
if [ -n "$missing" ]; then
|
||||
log_warning "audit_keys_missing" "Nouvelles options disponibles à configurer" \
|
||||
"file=${file_name%.conf}.local.conf" "keys=$missing"
|
||||
found_issue=true
|
||||
fi
|
||||
|
||||
# Options présentes dans le .local.conf mais qui n'existent plus dans le .conf (Obsolètes)
|
||||
local obsolete
|
||||
obsolete=$(comm -13 "$tmp_base" "$tmp_local" | tr '\n' ' ' | xargs)
|
||||
|
||||
if [ -n "$obsolete" ]; then
|
||||
log_info "audit_keys_obsolete" "Options locales obsolètes détectées" \
|
||||
"file=${file_name%.conf}.local.conf" "keys=$obsolete"
|
||||
fi
|
||||
|
||||
rm -f "$tmp_base" "$tmp_local"
|
||||
done
|
||||
|
||||
if [ "$found_issue" = false ]; then
|
||||
log_info "audit_success" "Toutes les configurations locales sont à jour"
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
lock_or_exit "monitoring-audit"
|
||||
check_config_drift
|
||||
}
|
||||
|
||||
main
|
||||
exit_with_status
|
||||
@@ -166,21 +166,21 @@ delete_extra_local_files() {
|
||||
comm -23 "$TMP_LOCAL_LIST" "$TMP_REMOTE_LIST" | while IFS= read -r rel_path; do
|
||||
[ -n "$rel_path" ] || continue
|
||||
|
||||
case "$rel_path" in
|
||||
conf/alert-engine.local.conf|conf/autoupdate.local.conf|conf/monitoring.local.conf)
|
||||
# Protection globale de TOUS les fichiers .local.conf
|
||||
if [[ "$rel_path" == *.local.conf ]]; then
|
||||
log_notice "delete_skipped" \
|
||||
"Suppression ignorée pour fichier local protégé" \
|
||||
"Fichier local protégé (ignoré)" \
|
||||
"file=$rel_path"
|
||||
continue
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Sécurité supplémentaire pour ne pas supprimer les répertoires vitaux
|
||||
rm -f "${MONITORING_BASE_DIR}/${rel_path}" \
|
||||
&& log_notice "file_deleted" \
|
||||
"Fichier supprimé car absent du manifeste" \
|
||||
"Fichier obsolète supprimé" \
|
||||
"file=$rel_path" \
|
||||
|| log_error "delete_failed" \
|
||||
"Impossible de supprimer le fichier local absent du manifeste" \
|
||||
"Échec suppression" \
|
||||
"file=$rel_path"
|
||||
done
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user