You've already forked nrpe
uptime - add override command
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
+16
-2
@@ -12,15 +12,29 @@ crit=30
|
|||||||
OVERRIDE_FILE="/var/lib/nagios/uptime_override"
|
OVERRIDE_FILE="/var/lib/nagios/uptime_override"
|
||||||
|
|
||||||
# Retrieve arguments
|
# Retrieve arguments
|
||||||
while getopts "w:c:f:" opt; do
|
RESET=0
|
||||||
|
while getopts "w:c:f:r" opt; do
|
||||||
case $opt in
|
case $opt in
|
||||||
w) warn=$OPTARG ;;
|
w) warn=$OPTARG ;;
|
||||||
c) crit=$OPTARG ;;
|
c) crit=$OPTARG ;;
|
||||||
f) OVERRIDE_FILE=$OPTARG ;; # Permet de changer le chemin via Icinga
|
f) OVERRIDE_FILE=$OPTARG ;; # Permet de changer le chemin via Icinga
|
||||||
*) echo "Usage: $0 -w <minutes> -c <minutes> [-f <file_path>]"; exit $STATE_UNKNOWN ;;
|
r) RESET=1 ;;
|
||||||
|
*) echo "Usage: $0 [-w <minutes>] [-c <minutes>] [-f <file_path>] [-r]"; exit $STATE_UNKNOWN ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# Option reset : crée le fichier d'override avec les bons droits
|
||||||
|
if [ "$RESET" -eq 1 ]; then
|
||||||
|
touch "$OVERRIDE_FILE" && chmod 640 "$OVERRIDE_FILE" && chown nagios:nagios "$OVERRIDE_FILE"
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
echo "OK - Override file created: $OVERRIDE_FILE"
|
||||||
|
exit $STATE_OK
|
||||||
|
else
|
||||||
|
echo "UNKNOWN - Failed to create override file: $OVERRIDE_FILE"
|
||||||
|
exit $STATE_UNKNOWN
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# Extract uptime (in seconds) via /proc
|
# Extract uptime (in seconds) via /proc
|
||||||
uptime_seconds=$(cat /proc/uptime | awk '{print $1}' | cut -d. -f1)
|
uptime_seconds=$(cat /proc/uptime | awk '{print $1}' | cut -d. -f1)
|
||||||
uptime_min=$((uptime_seconds / 60))
|
uptime_min=$((uptime_seconds / 60))
|
||||||
|
|||||||
Reference in New Issue
Block a user