Last active
August 22, 2022 01:42
-
-
Save acip/bd41a702deb4e7d0428995d386ba1f3a to your computer and use it in GitHub Desktop.
Get disk space on Linux and send notification to Slack channel via webhook if above threshold.
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 | |
# get disk space available and report to Slack if below threshold | |
SLACK_WEBHOOK_URL=https://hooks.slack.com/services/TXXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | |
DISK_THRESHOLD=60 | |
DISK_USAGE=$(df -h / | awk '{ print $5 }' | tail -n 1 | sed 's/%//g') | |
if [ $DISK_USAGE -ge $DISK_THRESHOLD ]; then | |
echo "Disk usage is $DISK_USAGE% - sending notification to slack" | |
curl -X POST -H 'Content-type: application/json' --data '{"text":":exclamation: Disk space on Database Server ('$HOSTNAME') is high: *'$DISK_USAGE'%*"}' $SLACK_WEBHOOK_URL | |
else | |
echo "Disk usage is $DISK_USAGE% - no notification sent" | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use cron (
crontab -e
) to run every minute:*/1 * * * * /path/to/monitor-space.sh