Commit e329209c authored by Philipp Steinpass's avatar Philipp Steinpass
Browse files

Initial commit

parents
#!/bin/bash
minfullwarn_default=90
warning_seconds_default=$((3600 * 48))
critical_seconds_default=$((3600 * 16))
#Parse command line parameters
case "$#" in
0)
minfullwarn=$minfullwarn_default
warning_seconds=$warning_seconds_default
critical_seconds=$critical_seconds_default
;;
1)
minfullwarn=$1
warning_seconds=$warning_seconds_default
critical_seconds=$critical_seconds_default
;;
2)
minfullwarn=$1
warning_seconds=$((3600 * $2))
critical_seconds=$critical_seconds_default
;;
3)
minfullwarn=$1
warning_seconds=$((3600 * $2))
critical_seconds=$((3600 * $3))
;;
*)
echo -e "Usage: check_disk_fill_rate [minimal fill level for warnings in percent] [warning_hours] [critical_hours]\n\tExample: check_disk_fill_rate 85 12 4"
exit 3
esac
critical=0
warning=0
message="fill rate: "
messages="All Volumes not mentioned are OK."
# Store the tail for multiple passes with the same data set (in case the files change under our feet)
data="$(tail -n +$(</var/run/disk_fill_rate-offset) /var/run/disk_fill_rate-statefile | grep ^[0-9])"
declare -a mountpoints
declare -a timestamps
declare -A availability
declare -a full
declare -A filllevel
while read timestamp device mountpoint available full; do
[[ "${mountpoints[@]} " =~ "${mountpoint} " ]] || mountpoints[${#mountpoints[*]}]=$mountpoint
[[ "${fullstates[@]}" =~ $full ]] || fullstates[${#fullstates[*]}]=$full
[[ "${timestamps[@]}" =~ $timestamp ]] || timestamps[${#timestamps[*]}]=$timestamp
availability["$mountpoint:$timestamp"]=$available
filllevel[$mountpoint]=$full
done <<< "$data"
# I now have a list of mountpoints and a list of timestamps,
# and a hash of how many kilobytes the disk had at what time.
#echo mountpoints=${mountpoints[*]}
#echo timestamps=${timestamps[@]}
#echo "availability=${availability[*]}"
for mountpoint in "${mountpoints[@]}"
do
#echo "Mountpoint $mountpoint"
oldtimestamp=${timestamps[0]}
newtimestamp=${timestamps[${#timestamps[@]}]}
delta_seconds=$(( timestamp - oldtimestamp))
#Accumulate byterates
bytesum=0
for timestamp in "${timestamps[@]:1}"
do
# Avoid divide by zero bugs and other strangeness.
delta_kilobytes=$(( ${availability["$mountpoint:$oldtimestamp"]} - ${availability["$mountpoint:$timestamp"]} ))
bytesum=$(( $bytesum + $delta_kilobytes ))
done
averagebyterate=$(( bytesum / ${#timestamps[@]} ))
if [ $averagebyterate -lt 1 ] || [ ${filllevel[$mountpoint]} -lt $minfullwarn ] ; then
messages=${messages}
messages="${messages}${mountpoint} not filling up. "
else
bytestogo=$(( ${availability["$mountpoint:$timestamp"]} * 1024))
secondstogo=$(( bytestogo / averagebyterate ))
if [ $secondstogo -lt $critical_seconds ] ; then
criticalmessages="${criticalmessages}${mountpoint} full within $((secondstogo/3600)) hours. "
elif [ $secondstogo -lt $warning_seconds ] ; then
warningmessages="${warningmessages}${mountpoint} good for only $((secondstogo/3600)) hours. "
else
if [ $((secondstogo/86400)) -gt 30 ] ; then
messages="${messages}${mountpoint} not filling up. "
else
messages="${messages}${mountpoint} good for $((secondstogo/86400)) days. "
fi
fi
# echo "$secondstogo seconds until disk fills up"
fi
done
if [ ! -z "$criticalmessages" ] ; then
echo "${criticalmessages}${warningmessages}"
exit 2
fi
if [ ! -z "$warningmessages" ] ; then
echo "${criticalmessages}${warningmessages}"
exit 1
fi
if [ ! -z "$messages" ] ; then
echo "No disks filling up."
exit 0
fi
# no messages, means no disks?
exit 3
#!/bin/bash
REPQUOTA="sudo /usr/sbin/repquota"
REPPATH=$1
CRITOUTPUT=""
WARNOUTPUT=""
#Run Repquota and pip output to while, iterate over lines
$REPQUOTA $REPPATH |
while read -r line; do
#reportquota ends it's output with multiple newlines
if [[ $line == "" ]] ;then
#Remove last \n
OUTPUT=${CRITOUTPUT}${WARNOUTPUT}
OUTPUT=${OUTPUT::-2}
#Print Output
echo -e $OUTPUT
#Set apropriet exit code
if [ -n "$CRITOUTPUT" ]; then
exit 2
elif [ -n "$WARNOUTPUT" ]; then
exit 1
else
echo "OK: All Quotas are met."
exit 0
fi
elif [ $HEADERDONE ] ;then
userName=`echo $line | awk '{ print $1 }'`
usedSpace=`echo $line | awk '{ print $3 }'`
softQuota=`echo $line | awk '{ print $4 }'`
hardQuota=`echo $line | awk '{ print $5 }'`
if (( $hardQuota == 0)); then
#do nothing
:
elif (( $softQuota == 0)); then
WARNOUTPUT+="WARNING: $userName has hard quota but no soft quota.\n"
elif (( $usedSpace >= $hardQuota )); then
CRITOUTPUT+="CRITICAL: $userName\n"
elif (( $usedSpace >= $softQuota)); then
WARNOUTPUT+="WARNING: $userName\n"
fi
#reportqota always sends a header, parse it out
elif [[ $line == "----------------------------------------------------------------------" ]] ;then
HEADERDONE=1
fi
done
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment