Created
November 11, 2014 08:10
-
-
Save eurica/e95af38a9fc642df7e2f to your computer and use it in GitHub Desktop.
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 | |
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