# Copyright 2011 Claudiu Vasadi. All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, are # permitted provided that the following conditions are met: # # 1. Redistributions of source code must retain the above copyright notice, this list of # conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright notice, this list # of conditions and the following disclaimer in the documentation and/or other materials # provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY Claudiu Vasadi ''AS IS'' AND ANY EXPRESS OR IMPLIED # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND # FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Claudiu Vasadi OR # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # # The views and conclusions contained in the software and documentation are those of the # authors and should not be interpreted as representing official policies, either expressed # or implied, of Claudiu Vasadi. # # # Script to monitor a quota limit on a ZFS pool # # Usage: # ./check_zfs_quota -d -w -c # PATH=/bin:/sbin:/usr/bin LIBEXEC=/usr/local/libexec/nagios . "$LIBEXEC"/utils.sh usage() { echo "./`basename $0` -d -w -c " exit 1 } if [ -z "$1" ];then usage fi # Read variables while getopts d:w:c: values do case "$values" in d) dataset="$OPTARG" ;; w) warn="$OPTARG" ;; c) crit="$OPTARG" ;; *) usage ;; esac done input_check(){ if [ -z "$dataset" ]; then echo "Error: -d not set" usage fi if [ -z "$warn" ]; then echo "Error: -w not set" usage fi case "$warn" in *[!0-9]*) echo "ERROR: -w must be an integer in percent used." usage esac if [ -z "$crit" ]; then echo "error: -c not set" usage fi case $crit in *[!0-9]*) echo "Error: -c must be an integer in percent used." usage esac if [ "$crit" -lt "$warn" ]; then echo "Error: -c must be greater than -w" usage elif [ "$warn" -eq "$crit" ]; then echo "ERROR: -w canot be the same as -c" usage fi } calc_quota() { # Check if there is a quota zfs get -Hp quota "$dataset" > /dev/null 2>&1 if [ $? != "0" ];then echo "ERROR: No Quota set" exit "$STATE_CRITICAL" fi quota_set=`zfs get -Hp quota "$dataset" | awk '{print $3}'` used_space=`zfs get -Hp used "$dataset" | awk '{print $3}'` # USED*100/QUOTA=percent used percent=`echo "$used_space"*100/"$quota_set" | bc` if [ "$percent" -ge "$warn" ] && [ "$percent" -lt "$crit" ]; then echo "QUOTA NOT OK. "$percent"% used" exit "$STATE_WARNING" fi if [ "$percent" -ge "$crit" ]; then echo "QUOTA NOT OK. "$percent"% used" exit "$STATE_CRITICAL" fi echo "QUOTA OK: "$percent"% used" exit "$STATE_OK" } input_check calc_quota