Created
July 7, 2015 16:37
-
-
Save patmandenver/bdb320989a92ecd7fc4e to your computer and use it in GitHub Desktop.
Slack startup/shutdown notify script
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 | |
# | |
# 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