Skip to content

Instantly share code, notes, and snippets.

@AronNovak
Forked from AAber/disk_used_alert2slack
Last active December 3, 2020 09:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AronNovak/f618cb72d3b21499cdce71e15ff7d71e to your computer and use it in GitHub Desktop.
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
#!/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