#!/bin/bash # ---------------------------------------------------------------------------- # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU 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 General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # ---------------------------------------------------------------------------- # # Written by Tom Molin to make sure a disk is writable, timing it with second resolution # Send any bug fixes or improvements to me and I'll update the script on Nagios Exchange. # This script breaks the Nagios recommendation not to wite to disk because it has to. # # Exit levels: OK=0 WARN=1 ERROR=2 UNKNOWN=3 function usage { echo "Usage: Write a couple of bytes to file and return write speed -F --file -b --bytes NUM -w --warnlevel NUM -c --criticallevel NUM -L LABEL" } # Parse input parameters until [ -z "$1" ]; do case "$1" in -F|--file) # log file to parse FILE="$2" shift ;; -b|--bytes) # What we'll parse for BYTES="$2" shift ;; -w|--warnlevel) WARNLEVEL="$2" shift ;; -c|--criticallevel) CRITLEVEL="$2" shift ;; -L) LBL="$2" shift ;; *) usage exit 1 ;; esac shift done if [[ -z "$FILE" ]] || [[ -z "$BYTES" ]] || [[ -z "$WARNLEVEL" ]] || [[ -z "$CRITLEVEL" ]] || [[ -z "$LBL" ]] then echo "Missing argument" usage exit 1 fi if [[ -w "$FILE" ]] then # Lets do a file write and time it TIME=$(\date +%s) dd if=/dev/zero bs=$BYTES count=1 of=$FILE &> /dev/null let STATUS=$(\date +%s)-$TIME LABEL="| ${LBL}=${STATUS};$WARNLEVEL;$CRITLEVEL;0;" if [ "$STATUS" -lt "$WARNLEVEL" ];then echo "OK - $STATUS $LABEL" exit $OK fi if [ "$STATUS" -ge "$WARNLEVEL" -a "$STATUS" -lt "$CRITLEVEL" ];then echo "WARNING - $STATUS $LABEL" exit $WARN fi if [ "$STATUS" -ge "$CRITLEVEL" ];then echo "CRITICAL - $STATUS $LABEL" exit $CRITICAL fi echo "UNKNOWN ERROR status ($STATUS)!" exit $UNKNOWN else touch $FILE && exit $UKNOWN || echo "$FILE is not writable" usage exit 1 fi