We are using the below updated script to find disk usage on AIX servers, this is working good for the disk's with GB's but the same is not working fine TB's. updating the error messages too. could you please help me in finding the solution? or is there any right plugin that I can use to find disk usage along with the performance details rightly updated. thanks.
Code: Select all
#!/bin/bash
#
# Modified by Chris Park
# Date: Jul. 27th 2016
#
# Usage: ./check_disk_capacity -w [Warning_condition] -c [Critical_condition] -p {Partitioni_name]"
#
# 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 2 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.
PROGNAME=`basename $0`
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
OS=$(uname)
AWK="/usr/bin/awk"
GREP="/usr/bin/grep"
DF="/usr/bin/df"
#############################
# Functions
#############################
print_help() {
echo ""
echo "$PROGNAME is a Nagios plugin used to check disk used space by"
echo "processing the output of \"df\" command. It runs on UNIX, Linux"
echo "and BSD platforms and reports the following performance data:"
echo "- total disk space (Bytes)"
echo "- currently used disk space (Bytes)"
echo "- currently used disk space (%)"
echo " "
echo "$PROGNAME Warning Critical Partition"
echo " "
}
WarnSpace=$1
CritSpace=$2
Partition=$3
CRITICAL_CONDITION=95
WARNING_CONDITION=90
# float number comparison
function fcomp() {
$AWK -v n1=$1 -v n2=$2 'BEGIN{ if (n1<=n2) exit 0; exit 1}'
}
#formats bytes => KBytes, MBytes, GBytes, TBytes
function UNIX_btokmgt() {
if [ $1 -lt 512 ]; then #KBytes
echo "${1}KB"
elif [ $1 -lt 262144 ]; then #MBytes
echo "$1" | $AWK '{printf "%.1fMB", $1/512}'
elif [ $1 -lt 134217728 ]; then #GBytes
echo "$1" | $AWK '{printf "%.1fGB", ($1*512)/1073741824}'
elif [ $1 -lt 68719476736 ]; then #TBytes
echo "$1" | $AWK '{printf "%.1fTB", $1/134217728}'
fi
}
function btokmgt() {
if [ $1 -lt 1024 ]; then #Bytes
echo "${1}B"
elif [ $1 -lt 1048576 ]; then #KBytes
echo "$1" | $AWK '{printf "%.1fKB", $1/1024}'
elif [ $1 -lt 1073741824 ]; then #MBytes
echo "$1" | $AWK '{printf "%.1fMB", $1/1048576}'
elif [ $1 -lt 1099511627776 ]; then #GBytes
echo "$1" | $AWK '{printf "%.1fGB", $1/1073741824}'
elif [ $1 -lt 1125899906842624 ]; then #TBytes
echo "$1" | $AWK '{printf "%.1fTB", $1/1099511627776}'
fi
}
if [ $# -lt 1 ]; then
print_help
RESULT="UNKNOWN"
RETURN_STATUS=$STATE_UNKNOWN
exit $RETURN_STATUS
fi
if fcomp $WarnSpace 0
then
WarnSpace=0
fi
if fcomp 100 $WarnSpace
then
WarnSpace=100
fi
if fcomp $CritSpace 0
then
CritSpace=0
fi
if fcomp 100 $CritSpace
then
CritSpace=100
fi
if fcomp $CritSpace $WarnSpace
then
WarnSpace=$CritSpace
fi
if [[ $OS == AIX ]]; then
USEDTXT=`$DF -P $Partition 2>&1`
#echo "USEDTXT value is $USEDTXT"
else
USEDTXT=`$DF -P -B 1 $Partition 2>&1`
fi
#if [ $? != 0 ]
#then
# echo "Error! Disk partition $Partition can't be checked. Does it exist?"
# exit 3
#fi
if [[ $OS == AIX ]]; then
CAPACITY=$(df "$Partition" | awk '!/Filesystem/ { print $4 }' | sed 's/%//')
# echo "CAPACITY is $CAPACITY"
else
CAPACITY=$(df -h "$Partition" | awk '!/Filesystem/ { print $4 }' | sed 's/%//')
fi
SpaceTxt=`echo "$USEDTXT" | $GREP "${Partition}\$"`
SpaceTotal=`echo "$SpaceTxt" | $AWK '{print $2}'`
SpaceUsed=`echo "$SpaceTxt" | $AWK '{print $3}'`
SpaceFree=`echo "$SpaceTxt" | $AWK '{print $4}'`
SpaceUsedProc=`echo "$SpaceTxt" | $AWK '{printf "%.1f", $3*100/$2}'`
SpaceFreeProc=`echo "$SpaceTxt" | $AWK '{printf "%.1f", $4*100/$2}'`
WarnSpaceAbs=`echo "$SpaceTotal $WarnSpace" | $AWK '{printf "%d", $1*$2/100}'`
CritSpaceAbs=`echo "$SpaceTotal $CritSpace" | $AWK '{printf "%d", $1*$2/100}'`
#echo "SpaceTxt value is $SpaceTxt"
#echo "SpaceTotal value is $SpaceTotal"
#echo "SpaceUsed value is $SpaceUsed"
#echo "SpaceFree value is $SpaceFree"
#echo "SpaceUsedProc value is $SpaceUsedProc"
if [[ $OS == AIX ]]; then
SpaceTotal_F=`UNIX_btokmgt $SpaceTotal`
SpaceUsed_F=`UNIX_btokmgt $SpaceUsed`
SpaceFree_F=`UNIX_btokmgt $SpaceFree`
# echo "SpaceTotal_F is $SpaceTotal_F"
# echo "SpaceUsed_F is $SpaceUsed_F"
# echo "SpaceFree_F is $SpaceFree_F"
else
SpaceTotal_F=`btokmgt $SpaceTotal`
SpaceUsed_F=`btokmgt $SpaceUsed`
SpaceFree_F=`btokmgt $SpaceFree`
fi
PerfData="'used space'=${SpaceUsed}B;${WarnSpaceAbs};${CritSpaceAbs};0;${SpaceTotal} 'used space (pct.)'=${SpaceUsedProc}%;${WarnSpace};${CritSpace};0;100"
#echo "PerfData is $PerfData"
WarnSpace=$1
CritSpace=$2
CRITICAL_CONDITION=95
WARNING_CONDITION=90
if [[ $CritSpace > $CRITICAL_CONDITION ]]; then
PS_STATUS="'$Partition' is at ${CAPACITY}% capacity, total ${SpaceTotal_F}, used ${SpaceUsed_F} (${SpaceUsedProc}%), free ${SpaceFree_F} (${SpaceFreeProc}%) | $PerfData"
RESULT="CRITICAL"
RETURN_STATUS=$STATE_CRITICAL
FINAL_STATUS="$RESULT: ${PS_STATUS}"
echo $FINAL_STATUS
exit $RETURN_STATUS
elif [[ $WarnSpace > $WARNING_CONDITION ]]; then
PS_STATUS="'$Partition' is at ${CAPACITY}% capacity, total ${SpaceTotal_F}, used ${SpaceUsed_F} (${SpaceUsedProc}%), free ${SpaceFree_F} (${SpaceFreeProc}%) | $PerfData"
RESULT="WARNING"
RETURN_STATUS=$STATE_WARNING
FINAL_STATUS="$RESULT: ${PS_STATUS}"
echo $FINAL_STATUS
exit $RETURN_STATUS
else
PS_STATUS="'$Partition' is at ${CAPACITY}% capacity, total ${SpaceTotal_F}, used ${SpaceUsed_F} (${SpaceUsedProc}%), free ${SpaceFree_F} (${SpaceFreeProc}%) | $PerfData"
RESULT="OK"
RETURN_STATUS=$STATE_OK
FINAL_STATUS="$RESULT: ${PS_STATUS}"
echo $FINAL_STATUS
exit $RETURN_STATUS
fi
echo $FINAL_STATUS
exit $RETURN_STATUS
Code: Select all
./check_disk 80 85 /opt
OK: '/opt' is at 72% capacity, total 0.5GB, used 0.4GB (72.0%), free 0.1GB (28.0%) | 'used space'=754504B;838860;891289;0;1048576 'used space (pct.)'=72.0%;80;85;0;100
Code: Select all
./check_disk 80 85 /opt/IBM
./check_disk: line 67: [: 68719476736: integer expression expected
./check_disk: line 67: [: 68719476736: integer expression expected
OK: '/opt/IBM' is at 9% capacity, total , used 12.6GB (8.6%), free (91.4%) | 'used space'=26502832B;245786214;261147852;0;307232768 'used space (pct.)'=8.6%;80;85;0;100