rendered paste body#!/bin/bash -x
#source /etc/init.d/nrpe-init.sh
NRPELOC=/opt/tools/nagios
CONF=/tmp/alldiskcheck.conf
CHECKDISK=/usr/lib/nagios/plugins/check_disk
TMPLOG=/tmp/alldiskcheck.log
ERRORLOG=/tmp/alldiskcheck.err
# while reading in config file
# execute check for each line (mount point)
# each line is [mount_point] [warn_thresh] [crit_thresh]
# if warn output to tmplog, continue checking
# if critical stop exit with critical print mount point
# otherwise exit on OK or warning, warning will print
# mountpoints
# Verify
if [ ! -f "$CONF" -o ! -r "$CONF" ]
then
echo "No Config File"
exit 3
fi
# Cleanup from last run
rm $TMPLOG &> /dev/null
rm $ERRORLOG &>/dev/null
while read line
do
MNTPNT=`echo $line|cut -d " " -f 1`
WARNTHR=`echo $line|cut -d " " -f 2`
CRITTHR=`echo $line|cut -d " " -f 3`
CHECKTYPE=`echo $line|cut -d " " -f 4`
echo "Check type =>$CHECKTYPE<="
if [ ! -z $CHECKTYPE ]
then
if [ "$CHECKTYPE" = "GB" -o "$CHECKTYPE" = "MB" ]
then
echo "$CHECKDISK -w $WARNTHR -c $CRITTHR -u $CHECKTYPE -p $MNTPNT > $TMPLOG"
$CHECKDISK -w "$WARNTHR" -c "$CRITTHR" -u "$CHECKTYPE" -p $MNTPNT > $TMPLOG
else
echo "CONFIG Error or something, check it out!"
exit 3
fi
else
echo "$CHECKDISK -w $WARNTHR\% -c $CRITTHR\% -p $MNTPNT > $TMPLOG"
$CHECKDISK -w "$WARNTHR"\% -c "$CRITTHR"\% -p $MNTPNT > $TMPLOG
fi
WHATEXIT=$?
case $WHATEXIT in
0)
# Within thresholds
;;
1)
# exceeded warning threshold
cat $TMPLOG >> $ERRORLOG
;;
2)
# exceeded critical threshold
cat $TMPLOG >> $ERRORLOG
echo "`cat $ERRORLOG`"
exit 2
;;
*)
# something weird happened
echo "UNKNOWN: Please investigate!"
exit 3
;;
esac
done < <(grep -v "#" $CONF)
if [ -s $ERRORLOG ]
then
echo "`cat $ERRORLOG`"
exit 1
else
echo "OK: All disks within thresholds"
exit 0
fi