Skip to content

Instantly share code, notes, and snippets.

@MrYoda
Last active April 28, 2017 13:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MrYoda/802559e2786d8f8ab407fb61829496b6 to your computer and use it in GitHub Desktop.
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
#!/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