Skip to content

Instantly share code, notes, and snippets.

@icasimpan
Forked from alperkokmen/pd-event.sh
Created March 30, 2021 20:53
Show Gist options
  • Save icasimpan/b2597f5ca496fd9a8e62742afdd7ab05 to your computer and use it in GitHub Desktop.
Save icasimpan/b2597f5ca496fd9a8e62742afdd7ab05 to your computer and use it in GitHub Desktop.
Simple script to trigger, acknowledge, and resolve incidents via PagerDuty Integration API.
#!/bin/bash
CONTENT_TYPE="application/json"
DESCRIPTION="bad things™ are happening"
URL="https://events.pagerduty.com/generic/2010-04-15/create_event.json"
if [ $# -ne 3 ]; then
echo "Usage: pd-event.sh [TYPE] [SERVICE KEY] [INCIDENT KEY]"
echo " - TYPE: [t]rigger | [a]cknowledge | [r]esolve"
echo " - SERVICE KEY: unique identifier for service"
echo " - INCIDENT KEY: unique identifier for incident"
exit 1
fi
case $1 in
t) curl -H "${CONTENT_TYPE}" \
-X POST \
-d "{ \"service_key\": \"$2\", \"event_type\": \"trigger\", \"incident_key\": \"$3\", \"description\": \"${DESCRIPTION}\" }" \
"${URL}"
;;
a) curl -H "${CONTENT_TYPE}" \
-X POST \
-d "{ \"service_key\": \"$2\", \"event_type\": \"acknowledge\", \"incident_key\": \"$3\" }" \
"${URL}"
;;
r) curl -H "${CONTENT_TYPE}" \
-X POST \
-d "{ \"service_key\": \"$2\", \"event_type\": \"resolve\", \"incident_key\": \"$3\" }" \
"${URL}"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment