From 70c9730237a5eb70bb3756fa188f8715ae5fabb2 Mon Sep 17 00:00:00 2001 From: Chl Date: Wed, 31 Jul 2024 14:40:56 +0200 Subject: [PATCH] nagios/diskstats: status unknown when device not found --- nagios/check_diskstats.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/nagios/check_diskstats.sh b/nagios/check_diskstats.sh index 32273bf..dc691b7 100755 --- a/nagios/check_diskstats.sh +++ b/nagios/check_diskstats.sh @@ -71,6 +71,7 @@ fi while getopts hd:i:I: OPT; do case "$OPT" in 'd') + DEVICE_FOUND=0 while read \ MAJOR MINOR DEVICE_NAME \ READS_COMPLETED READS_MERGED SECTORS_READ TIME_SPENT_READING \ @@ -83,6 +84,7 @@ while getopts hd:i:I: OPT; do do case "$DEVICE_NAME" in $OPTARG) + DEVICE_FOUND=1 # Checking the thresholds if [ -n "$THRESHOLD_IO_IN_PROGRESS_CRITICAL" ] && [ "$IO_IN_PROGRESS" -gt "$THRESHOLD_IO_IN_PROGRESS_CRITICAL" ]; then OUTPUT_EXIT_STATUS=$STATE_CRITICAL @@ -117,6 +119,16 @@ while getopts hd:i:I: OPT; do ;; esac done < /proc/diskstats + # Check if the device requested has been found. + if [ "$DEVICE_FOUND" -lt 1 ]; then + echo "UNKNOWN device '$OPTARG' not found." + exit $STATE_UNKNOWN + fi + ;; + + 'h') + usage + exit 0 ;; 'i') @@ -134,6 +146,8 @@ while getopts hd:i:I: OPT; do esac done +# Should we check if no device has been requested ? Overkill ? + # Final ouput case "$OUTPUT_EXIT_STATUS" in '0')