menage et adaptation dans check_disk

This commit is contained in:
2026-03-17 07:59:05 +01:00
parent 35f3c6f5f7
commit 3b05390ec4
7 changed files with 29 additions and 35 deletions

View File

@@ -19,35 +19,34 @@ WARNING=80
CRITICAL=95
MOUNTS=("/" "/var" "/home")
for mount in "${MOUNTS[@]}"; do
# On vérifie si le point de montage existe avant de tester
if ! mountpoint -q "$mount"; then
log_to_php() {
local level="$1"
local event="$2"
local message="$3"
shift 3
# On passe les arguments restants au format JSON ou chaine à PHP
php -r "
require '/opt/monitoring/lib/monitoring-lib.php';
log_event('$level', '$event', '$message', ["$*"]);
"
}
for mount in "${MOUNTS[@]}"; do
if ! mountpoint -q "$mount"; then continue; fi
used_pct="$(df -P "$mount" 2>/dev/null | awk 'NR==2 {gsub("%","",$5); print $5}')"
if [[ ! "$used_pct" =~ ^[0-9]+$ ]]; then
log_to_php "ERROR" "check_failed" "Impossible de lire l'usage" "'mount=$mount'"
continue
fi
used_pct="$(df -P "$mount" 2>/dev/null | awk 'NR==2 {gsub("%","",$5); print $5}')"
if [[ ! "$used_pct" =~ ^[0-9]+$ ]]; then
log_error "check_failed" "Impossible de lire l'utilisation disque" "mount=$mount"
continue
fi
level="$(threshold_level "$used_pct" "$WARNING" "$CRITICAL")"
case "$level" in
INFO)
log_info "disk_ok" "Utilisation disque normale" \
"mount=$mount" "used_pct=$used_pct" "warning=$WARNING" "critical=$CRITICAL"
;;
WARNING)
log_warning "disk_usage_high" "Utilisation disque élevée" \
"mount=$mount" "used_pct=$used_pct" "warning=$WARNING" "critical=$CRITICAL"
;;
CRITICAL)
log_critical "disk_usage_critical" "Utilisation disque critique" \
"mount=$mount" "used_pct=$used_pct" "warning=$WARNING" "critical=$CRITICAL"
;;
esac
done
exit_with_status
# Détermination du niveau (logique bash simple)
if [ "$used_pct" -ge "$CRITICAL" ]; then
log_to_php "CRITICAL" "disk_usage_critical" "Disque plein" "'mount=$mount', 'used=$used_pct%'"
elif [ "$used_pct" -ge "$WARNING" ]; then
log_to_php "WARNING" "disk_usage_high" "Disque presque plein" "'mount=$mount', 'used=$used_pct%'"
else
log_to_php "INFO" "disk_ok" "Disque OK" "'mount=$mount', 'used=$used_pct%'"
fi
done