Skip to content

Commit

Permalink
Allow plugin to run without enforced thresholds
Browse files Browse the repository at this point in the history
  • Loading branch information
Napsty committed Mar 11, 2014
1 parent a78ac72 commit 0334625
Showing 1 changed file with 52 additions and 23 deletions.
75 changes: 52 additions & 23 deletions check_zpools.sh
Expand Up @@ -2,9 +2,10 @@
#########################################################################
# Script: check_zpools.sh
# Purpose: Nagios plugin to monitor status of zfs pool
# Authors: Aldo Fabi First version (2006-09-01)
# vitaliy@gmail.com Forked (2013-02-04)
# Claudio Kuenzler Complete redo, perfdata, etc (2013)
# Authors: Aldo Fabi First version (2006-09-01)
# Vitaliy Gladkevitch Forked (2013-02-04)
# Claudio Kuenzler Complete redo, perfdata, etc (2013-2014)
# Doc: http://www.claudiokuenzler.com/nagios-plugins/check_zpools.php
# History:
# 2006-09-01 Original first version
# 2006-10-04 Updated (no change history known)
Expand All @@ -15,15 +16,21 @@
# 2013-05-21 Added performance data (percentage used)
# 2013-07-11 Bugfix in zpool health check
# 2014-02-10 Bugfix in threshold comparison
# 2014-03-11 Allow plugin to run without enforced thresholds
#########################################################################
### Begin vars
STATE_OK=0 # define the exit code if status is OK
STATE_WARNING=1 # define the exit code if status is Warning
STATE_CRITICAL=2 # define the exit code if status is Critical
STATE_UNKNOWN=3 # define the exit code if status is Unknown
# Set path
PATH=$PATH:/usr/sbin:/sbin
export PATH
### Begin vars
### End vars
#########################################################################
help="check_zpools.sh (c) 2006-2014 several authors\n
Usage: $0 -p (poolname|ALL) [-w warnpercent] [-c critpercent]\n
Example: $0 -p ALL -w 80 -c 90"
### End vars
#########################################################################
# Check necessary commands are available
for cmd in zpool awk [
Expand All @@ -39,7 +46,7 @@ done
if [ "${1}" = "--help" -o "${#}" = "0" ];
then
echo -e "${help}";
exit 1;
exit ${STATE_UNKNOWN};
fi
#########################################################################
# Get user-given variables
Expand All @@ -50,17 +57,18 @@ do
w) warn=${OPTARG};;
c) crit=${OPTARG};;
*) echo -e $help
exit 3
exit $STATE_UNKNOWN
;;
esac
done
#########################################################################
# Did user obey to usage?
if [ -z $pool ]; then echo -e $help; exit 3; fi
if [ -z $pool ]; then echo -e $help; exit ${STATE_UNKNOWN}; fi
#########################################################################
# Assume thresholds if they were not given
if [ -z $warn ]; then warn=90; fi
if [ -z $crit ]; then crit=95; fi
# Verify threshold sense
if [[ -n $warn ]] && [[ -z $crit ]]; then echo "Both warning and critical thresholds must be set"; exit $STATE_UNKNOWN; fi
if [[ -z $warn ]] && [[ -n $crit ]]; then echo "Both warning and critical thresholds must be set"; exit $STATE_UNKNOWN; fi
if [[ $warn -gt $crit ]]; then echo "Warning threshold cannot be greater than critical"; exit $STATE_UNKNOWN; fi
#########################################################################
# What needs to be checked?
## Check all pools
Expand All @@ -72,12 +80,21 @@ then
do
CAPACITY=$(zpool list -Ho capacity $POOL | awk -F"%" '{print $1}')
HEALTH=$(zpool list -Ho health $POOL)
if [[ $CAPACITY -ge $crit ]]
then error[${p}]="POOL $POOL usage is CRITICAL (${CAPACITY}%)"; fcrit=1
elif [[ $CAPACITY -ge $warn && $CAPACITY -lt $crit ]]
then error[$p]="POOL $POOL usage is WARNING (${CAPACITY}%)"
elif [ $HEALTH != "ONLINE" ]
then error[${p}]="$POOL health is $HEALTH"; fcrit=1
# Check with thresholds
if [[ -n $warn ]] && [[ -n $crit ]]
then
if [[ $CAPACITY -ge $crit ]]
then error[${p}]="POOL $POOL usage is CRITICAL (${CAPACITY}%)"; fcrit=1
elif [[ $CAPACITY -ge $warn && $CAPACITY -lt $crit ]]
then error[$p]="POOL $POOL usage is WARNING (${CAPACITY}%)"
elif [ $HEALTH != "ONLINE" ]
then error[${p}]="$POOL health is $HEALTH"; fcrit=1
fi
# Check without thresholds
else
if [ $HEALTH != "ONLINE" ]
then error[${p}]="$POOL health is $HEALTH"; fcrit=1
fi
fi
perfdata[$p]="$POOL=${CAPACITY}% "
let p++
Expand All @@ -94,12 +111,24 @@ then
else
CAPACITY=$(zpool list -Ho capacity $pool | awk -F"%" '{print $1}')
HEALTH=$(zpool list -Ho health $pool)
if [ $HEALTH != "ONLINE" ]; then echo "ZFS POOL $pool health is $HEALTH|$pool=${CAPACITY}%"; exit 2
elif [[ $CAPACITY -gt $crit ]]; then echo "ZFS POOL $pool usage is CRITICAL (${CAPACITY}%|$pool=${CAPACITY}%)"; exit 2
elif [[ $CAPACITY -gt $warn && $CAPACITY -lt $crit ]]; then echo "ZFS POOL $pool usage is WARNING (${CAPACITY}%)|$pool=${CAPACITY}%"; exit 1
else echo "ALL ZFS POOLS OK ($pool)|$pool=${CAPACITY}%"; exit 0
fi

if [[ -n $warn ]] && [[ -n $crit ]]
then
# Check with thresholds
if [ $HEALTH != "ONLINE" ]; then echo "ZFS POOL $pool health is $HEALTH|$pool=${CAPACITY}%"; exit ${STATE_CRITICAL}
elif [[ $CAPACITY -gt $crit ]]; then echo "ZFS POOL $pool usage is CRITICAL (${CAPACITY}%|$pool=${CAPACITY}%)"; exit ${STATE_CRITICAL}
elif [[ $CAPACITY -gt $warn && $CAPACITY -lt $crit ]]; then echo "ZFS POOL $pool usage is WARNING (${CAPACITY}%)|$pool=${CAPACITY}%"; exit ${STATE_WARNING}
else echo "ALL ZFS POOLS OK ($pool)|$pool=${CAPACITY}%"; exit ${STATE_OK}
fi
else
# Check without thresholds
if [ $HEALTH != "ONLINE" ]
then echo "ZFS POOL $pool health is $HEALTH|$pool=${CAPACITY}%"; exit ${STATE_CRITICAL}
else echo "ALL ZFS POOLS OK ($pool)|$pool=${CAPACITY}%"; exit ${STATE_OK}
fi
fi

fi

echo "UKNOWN - Should never reach this part"
exit 3
exit ${STATE_UNKNOWN}

0 comments on commit 0334625

Please sign in to comment.