#!/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 # Configuration locale WARNING=80 CRITICAL=95 MOUNTS=("/" "/var" "/home") LOG_BIN="/opt/monitoring/bin/log-cli.php" # --- Vérification ROOT --- if [ "${EUID}" -ne 0 ]; then echo "ERREUR : Ce script doit être exécuté en tant que root." >&2 $LOG_BIN ERROR "internal_error" "Tentative d'exécution sans privilèges root." exit 1 fi 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_BIN ERROR "check_failed" "Erreur lecture disque $mount." continue fi # Logique de décision if [ "$used_pct" -ge "$CRITICAL" ]; then $LOG_BIN CRITICAL "disk_usage_critical" "Disque $mount critique. $used_pct% utilisé." $LOG_BIN WARNING "disk_usage_high" "Disque $mount élevé. $used_pct% utilisé." else $LOG_BIN INFO "disk_ok" "Disque $mount OK. $used_pct% utilisé." fi done # --- 2. Étude des Inodes --- # df -i récupère l'utilisation des inodes inode_pct="$(df -iP "$mount" 2>/dev/null | awk 'NR==2 {gsub("%","",$5); print $5}')" if [[ ! "$inode_pct" =~ ^[0-9]+$ ]]; then $LOG_BIN ERROR "check_failed" "Erreur lecture inodes $mount." continue fi if [ "$inode_pct" -ge "$CRITICAL" ]; then $LOG_BIN CRITICAL "inode_usage_critical" "Inodes $mount critiques ($inode_pct% utilisé)." elif [ "$inode_pct" -ge "$WARNING" ]; then $LOG_BIN WARNING "inode_usage_high" "Inodes $mount élevés ($inode_pct% utilisé)." else $LOG_BIN INFO "inode_ok" "Inodes $mount OK ($inode_pct% utilisé)." fi