Created
June 14, 2017 13:38
-
-
Save AAber/7c718b9e3363d5cf811dc22e0eb0d729 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'| \ | |
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": "#devops", "username": "webhookbot", "text": "'$MESSAGE'", "icon_emoji": ":ghost:"}' \ | |
https://hooks.slack.com/services/PutYourOwnTokenHere | |
fi | |
done |
how to create message with spaces?
channel="mychannel"
message="Hello World 770 Now"
data='{"channel": "'$channel'", "username": "message2slack", "text": "'$message'", "icon_emoji": ":octagonal_sign:"}'
curl -s -X POST -H 'Content-type: application/json' --data "$data" https://hooks.slack.com/services/TXXXXXXX
i have try to ubuntu server . but the script is not working . pleas help me and you share ubuntu server slack trigger script share to me
post the error or any other info about the setup that doesn't work and we will troubleshoot
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@AAber thank you for the gist.