Skip to content

Instantly share code, notes, and snippets.

@AAber
Created June 14, 2017 13:38
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save AAber/7c718b9e3363d5cf811dc22e0eb0d729 to your computer and use it in GitHub Desktop.
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
#!/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
@yedincisenol
Copy link

@AAber thank you for the gist.

@humza024
Copy link

how to create message with spaces?

@AAber
Copy link
Author

AAber commented Dec 28, 2022

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

@sundar0209
Copy link

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

@AAber
Copy link
Author

AAber commented Jul 1, 2023

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