52 lines
1.7 KiB
Bash
Executable File
52 lines
1.7 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
|
|
|
|
. /opt/monitoring/lib/monitoring-lib.sh || exit 3
|
|
|
|
WARNING=80
|
|
CRITICAL=95
|
|
MOUNTS=("/" "/var" "/home")
|
|
|
|
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
|
|
|
|
# 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 |