Skip to content

Instantly share code, notes, and snippets.

@patmandenver
Created July 7, 2015 16:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save patmandenver/bdb320989a92ecd7fc4e to your computer and use it in GitHub Desktop.
Save patmandenver/bdb320989a92ecd7fc4e to your computer and use it in GitHub Desktop.
Slack startup/shutdown notify script
#!/bin/bash
#
# Change the slack URL to your own
#
##############################################
start_value=".\n Name : `hostname`"
start_value+="\n IP : `ip route get 8.8.8.8 | awk '{print $NF; exit}'`"
start_value+="\n Memory : `cat /proc/meminfo | grep MemTotal | awk '{mem= $2/1048576; printf("%0.2g GiB", mem) ; exit}'`"
start_value+="\n Drives : `df -h | grep Filesystem`"
start_value+="\n `df -h | grep /dev/sda`"
stop_value=".\n Name : `hostname`"
stop_value+="\n IP : `ip route get 8.8.8.8 | awk '{print $NF; exit}'`"
case "$1" in
start)
curl -H "Content-type: application/json" -X POST -d \
'{
"username": "OpenStack",
"icon_emoji": ":openstack:",
"channel": "#dev_ops",
"attachments": [
{
"fallback": "Server is Starting Up",
"color": "good",
"fields": [
{
"title": "Server Startup",
"value": "'"$start_value"'",
"short": false
}
]
}
]
}' https://hooks.slack.com/services/CHANGE_ME_XXXXXXX
;;
stop)
curl -H "Content-type: application/json" -X POST -d \
'{
"username": "OpenStack",
"icon_emoji": ":openstack:",
"channel": "#dev_ops",
"attachments": [
{
"fallback": "Server is Shutting Down",
"color": "good",
"fields": [
{
"title": "Server Shutdown",
"value": "'"$stop_value"'",
"short": false
}
]
}
]
}' https://hooks.slack.com/services/CHANGE_ME_XXXXXXX
;;
*)
echo "INFO: Script used to send notifications to Slack Shutdown/Startup" >&2
exit 3
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment