-
-
Save AronNovak/f618cb72d3b21499cdce71e15ff7d71e to your computer and use it in GitHub Desktop.
Script to monitor disk space and alert via slack when disk usage is > 80% Place the script in /etc/cron.hourly
This file contains hidden or 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 | |
# Parse df selected output | |
df -h|egrep -v 'File|tmpfs|docker|udev|snap|loop'| \ | |
while read LINE; do | |
USED_NUMBER=`echo $LINE |awk '{print $5}'|sed 's/\%//'|sed 's/ //g'` | |
USED_PERCENT=`echo $LINE |awk '{print $5}'|sed 's/ //g'` | |
MOUNT_POINT=`echo $LINE |awk '{print $6}'|sed 's/ //g'` | |
if [ $USED_NUMBER -gt 80 ]; then | |
# Create message without spaces | |
MESSAGE=`echo WARNING On $HOSTNAME disk $MOUNT_POINT is full at $USED_PERCENT usage WARNING|sed 's/ /_/g'` | |
# Post message | |
curl -X POST --data-urlencode \ | |
'payload={"channel": "#sitehealth", "username": "webhookbot", "text": "'$MESSAGE'", "icon_emoji": ":ghost:"}' \ | |
https://hooks.slack.com/services/PutYourOwnTokenHere | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment