Last active
December 22, 2015 09:39
-
-
Save aaronzirbes/6453699 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
devices=`mount |grep -E '^/dev/' | cut -d ' ' -f 1` | |
warn_threshold="85" | |
fail_threshold="90" | |
status="OK" | |
for device in ${devices}; do | |
diskfree=`df -h ${device} |grep ${device}` | |
percent=`echo ${diskfree} |awk '{print $5}' |sed -e 's/%//'` | |
free=`echo ${diskfree} |awk '{print $3}' |sed -e 's/%//'` | |
total=`echo ${diskfree} |awk '{print $4}' |sed -e 's/%//'` | |
if (( $percent > ${fail_threshold} )); then | |
echo "FAILURE: ${device} usage is at ${percent}% (${free} free of ${total})" | |
status="FAILURE" | |
elif (( $percent > ${warn_threshold} )); then | |
echo "WARNING: ${device} usage is at ${percent}% (${free} free of ${total})" | |
if [ "${status}" == "OK" ]; then | |
status="WARNING" | |
fi | |
else | |
echo "OK: ${device} usage is at ${percent} (${free}% free of ${total})" | |
fi | |
done | |
if [ "${status}" == "OK" ]; then | |
exit 0 | |
elif [ "${status}" == "WARNING" ]; then | |
exit 1 | |
elif [ "${status}" == "FAILURE" ]; then | |
exit 2 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment