Files
scripts-bash/servers/linux/monitoring/bin/check_disk.sh

39 lines
1.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 locale
WARNING=80
CRITICAL=95
MOUNTS=("/" "/var" "/home")
LOG_BIN="/opt/monitoring/bin/log-cli.php"
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é."
done