#!/bin/ksh # # Copyright (c) 2013, Haukur Kristinsson # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * 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. # * Neither the name of Haukur Kristinsson nor the # names of its contributors may be used to endorse or promote products # derived from this software without specific prior written permission. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 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. ############################################################################ # Made for AIX (Any Version) (Korn Shell). # Depends on /usr/sysv/bin/df. # Build: v0.4 September 2013. # ------------------------------------------------------------------------ # # Usage: ./check_filesystems_space [warning] [critical] [[type pattern]] # [warning] : Percentages for WARNING (MANDATORY) # [critical] : Percentages for CRITICAL (MANDATORY) # [type pattern] : default is "jfs" (OPTIONAL) # -- Changelog ----------------------------------------------------------- # # v0.4 - Include only filesystem type matching a grep pattern # This was needed to exclude mounted nfs filesystems # v0.3 - For loop could terminate to soon as it breaks after proc ############################################################################ # Global Variables count=0 output="" # Default type is the grep pattern jfs (also matches jfs2 etc.) mountType="" # Nagios Exit Codes. STATE_OK=0 STATE_WARNING=1 STATE_CRITICAL=2 STATE_UNKNOWN=3 STATE_DEPENDENT=4 # Default Exit Code as UNKNOWN. exitstatus=$STATE_UNKNOWN errorHelp() { echo "----- ERROR -----" echo "- Dude! You have to pass arguments to the script, for it to work." echo "- Example of usage:" echo " ./check_filesystems_space 90 99 \"jfs\"," echo " for warning 90 and critical 99 and only include filesystems types that matches the pattern 'jfs' (default)." echo "-----------------" exit } # Argument Checking if [[ $# -eq 2 ]] ;then mountType="jfs" elif [[ $# -eq 3 ]]; then mountType=$3 else errorHelp fi # Iteration of file systems. if [ -n "$1" ] && [ -n "$2" ] && [ -n "$mountType" ] then warninglimit=$2 lowlimit=$1 rawSysVDFResults=`/usr/sysv/bin/df -n | grep -i $mountType | awk -F\: '{print ""$1":"$2""}' | tr -d '\t' | tr -d ' '` for fs in $rawSysVDFResults do set -A array $(echo $fs | tr ':' '\n') fMount=${array[0]} fType=${array[1]} size=`df -k $fMount|grep $fMount|awk '{ print $4; }'` prc=`echo $size | tr -d "%"` if [ $prc -gt $warninglimit ] then output=`echo $output "URGENT: Low disk space for $fMount($fType) ($size) - "` count=`expr $count + 1` if [ $exitstatus -ne 2 ] then exitstatus=$STATE_CRITICAL fi elif [ $prc -gt $lowlimit ] then output=`echo $output "WARNING: Low disk space for $fMount($fType) ($size) - "` count=`expr $count + 1` if [ $exitstatus -eq 2 ] then exitstatus=$STATE_CRITICAL else exitstatus=$STATE_WARNING fi fi done fi #output shall we? if [ $count -gt 0 ] then echo $output else if [ -n "$1" ] && [ -n "$2" ] && [ -n "$mountType" ] then echo "OK: Filesystem space inside acceptable levels" exitstatus=$STATE_OK fi fi exit $exitstatus