#!/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 . /opt/monitoring/lib/monitoring-lib.sh || exit 3 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 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