Last active
April 28, 2017 13:25
-
-
Save MrYoda/802559e2786d8f8ab407fb61829496b6 to your computer and use it in GitHub Desktop.
Bash script for Crontab to detect zombie processes and notify about this via Slack Incoming Webhook
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 | |
function post_to_slack () { | |
SLACK_MESSAGE="$1" | |
SLACK_URL=https://hooks.slack.com/services/YOUR_WEBHOOK_TOKENS_HERE | |
case "$2" in | |
INFO) | |
SLACK_ICON=':slack:' | |
;; | |
WARNING) | |
SLACK_ICON=':warning:' | |
;; | |
ERROR) | |
SLACK_ICON=':bangbang:' | |
;; | |
*) | |
SLACK_ICON=':slack:' | |
;; | |
esac | |
curl -X POST --data "payload={\"icon_emoji\": \"$SLACK_ICON\", \"channel\": \"$3\", \"text\": \"$SLACK_MESSAGE\"}" ${SLACK_URL} | |
} | |
ZOMBIE_COUNT=`ps u -C zombie --no-headers | wc -l` | |
if (( $ZOMBIE_COUNT > 0 )); then | |
ZOMBIE_LIST=`ps u -C zombie` | |
HOSTNAME=`cat /etc/hostname` | |
post_to_slack "Hi, There are $ZOMBIE_COUNT zombie processes on \`$HOSTNAME\`. Please, check! \\n\`\`\`$ZOMBIE_LIST\`\`\` " "WARNING" "#your_channel" | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment