61 lines
2.3 KiB
Bash
Executable File
61 lines
2.3 KiB
Bash
Executable File
#!/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 (Seuils par défaut) ---
|
|
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
|
|
|
|
# --- 1. Espace Disque ---
|
|
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."
|
|
else
|
|
if [ "$used_pct" -ge "$CRITICAL" ]; then
|
|
$LOG_BIN CRITICAL "disk_usage_critical" "Disque $mount critique : $used_pct% utilisé."
|
|
elif [ "$used_pct" -ge "$WARNING" ]; then
|
|
$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
|
|
fi
|
|
|
|
# --- 2. Inodes (Déplacé à l'intérieur de la boucle) ---
|
|
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."
|
|
else
|
|
if [ "$inode_pct" -ge "$CRITICAL" ]; then
|
|
$LOG_BIN CRITICAL "inode_usage_critical" "Inodes $mount critiques ($inode_pct%)."
|
|
elif [ "$inode_pct" -ge "$WARNING" ]; then
|
|
$LOG_BIN WARNING "inode_usage_high" "Inodes $mount élevés ($inode_pct%)."
|
|
else
|
|
$LOG_BIN INFO "inode_ok" "Inodes $mount OK ($inode_pct%)."
|
|
fi
|
|
fi
|
|
done |