Skip to content

Instantly share code, notes, and snippets.

@eurica
Created November 11, 2014 08:10
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 eurica/e95af38a9fc642df7e2f to your computer and use it in GitHub Desktop.
Save eurica/e95af38a9fc642df7e2f to your computer and use it in GitHub Desktop.
#!/bin/bash
me="$0"
#This function will alert PagerDuty that our script failed
alertonfail() {
if [ "$1" -ne "0" ]; then
echo "Error $1 on $me"
curl -H "Content-type: application/json" -X POST \
-d '{
"service_key": "b38b2d9753ba4b6a804e2c1cf8636b91",
"incident_key": "Fatal error in the accounting script",
"event_type": "trigger",
"description": "Check the logs",
"details": {
"would be": "nice to have"
}
}' \
"https://events.pagerduty.com/generic/2010-04-15/create_event.json"
#Now that we're alerting someone, let's stop running the rest of the script
exit $1
fi
}
#This command succeeds and PD is not alerted:
ls > /dev/null
alertonfail $?
#This command doesn't exist, so it fails. (Hopefully your program exists)
run-the-accounting-system for important files
alertonfail $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment