uptime - add new version with override feature & switch warning / critical value

This commit is contained in:
Ludovic Cartier
2026-04-30 14:49:10 +02:00
parent a36446eaaf
commit 59893530e6
2 changed files with 20 additions and 7 deletions
+2 -2
View File
@@ -57,5 +57,5 @@ nrpe_proc_age_critical: 600
# nrpe_redis_replication_lag_warning: 10
# nrpe_redis_replication_lag_critical: 60
nrpe_uptime_warning: 30
nrpe_uptime_critical: 1440
nrpe_uptime_warning: 1440
nrpe_uptime_critical: 30
+18 -5
View File
@@ -6,16 +6,18 @@ STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
# Default values (in minutes)
# Default values
warn=1440
crit=30
OVERRIDE_FILE="/var/lib/nagios/uptime_override"
# Retrieve arguments
while getopts "w:c:" opt; do
while getopts "w:c:f:" opt; do
case $opt in
w) warn=$OPTARG ;;
c) crit=$OPTARG ;;
*) echo "Usage: $0 -w <minutes> -c <minutes>"; exit $STATE_UNKNOWN ;;
f) OVERRIDE_FILE=$OPTARG ;; # Permet de changer le chemin via Icinga
*) echo "Usage: $0 -w <minutes> -c <minutes> [-f <file_path>]"; exit $STATE_UNKNOWN ;;
esac
done
@@ -26,7 +28,18 @@ uptime_min=$((uptime_seconds / 60))
# Performance Data
PERFDATA="|uptime_min=${uptime_min}min;${warn};${crit};0;"
# Decision logic
# 1. Vérification du fichier d'acquittement
if [ -f "$OVERRIDE_FILE" ]; then
# Si le système est redevenu "stable" naturellement, on supprime le flag
if [ "$uptime_min" -gt "$warn" ]; then
rm -f "$OVERRIDE_FILE"
else
echo "OK - Reboot acquitté manuellement (Uptime: ${uptime_min} min)$PERFDATA"
exit $STATE_OK
fi
fi
# 2. Logique de décision standard
if [ "$uptime_min" -le "$crit" ]; then
echo "CRITICAL - Recent reboot detected (${uptime_min} min < threshold ${crit} min)$PERFDATA"
exit $STATE_CRITICAL
@@ -36,4 +49,4 @@ elif [ "$uptime_min" -le "$warn" ]; then
else
echo "OK - System stable (Uptime: ${uptime_min} min)$PERFDATA"
exit $STATE_OK
fi
fi