Skip to content

Commit

Permalink
feat(bash): add pagerduty-alert
Browse files Browse the repository at this point in the history
SXT-600

Signed-off-by: Ivo Delmis <ivo@blockchaintp.com>
  • Loading branch information
Ivo Delmis committed May 11, 2021
1 parent eb09f6f commit 782c576
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
3 changes: 2 additions & 1 deletion bash/pagerduty-alert
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ options::add -o a -d "Alert API Token" -a -m -e ALERT_TOKEN
options::add -o s -d "PagerDuty ServiceID" -a -m -e SERVICE_ID
options::add -o i -d "Alert Type (incident or event)" -a -m -e ALERT_TYPE
options::add -o t -d "Alert Title" -a -e ALERT_TITLE
options::add -o k -d "Incident Key" -a -e INCIDENT_KEY
options::add -o f -d "Alert From Email Address" -a -e ALERT_FROM
options::parse_available "$@"

Expand All @@ -38,7 +39,7 @@ ALERT_FROM=${ALERT_FROM:="no-reply@blockchaintp.com"}

case $ALERT_TYPE in
incident)
exec::hide send_incident "$SERVICE_ID" "$ALERT_TYPE" "$ALERT_TITLE" "$ALERT_FROM" "$ALERT_TOKEN" ||
exec::hide send_incident "$SERVICE_ID" "$ALERT_TYPE" "$ALERT_TITLE" "$ALERT_FROM" "$ALERT_TOKEN" "$INCIDENT_KEY" ||
error::exit "Failed to send $ALERT_TYPE"
;;
event)
Expand Down
11 changes: 3 additions & 8 deletions bash/pagerduty.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,15 @@ function send_incident() {
local alert_title="${3:?}"
local alert_from="${4:?}"
local alert_token="${5:?}"

#trap 'rm -f "$pg_data"' EXIT
#pg_data=$(mktemp)
#cat <<EOF > "$pg_data"
##{ "incident": { "type": "$alert_type", "title": "$alert_title", "service": { "id": "$service_id", "type": "service_reference" } } }
#EOF
local incident_key="${6:?}"

incident_data() {
cat <<EOF
{ "incident": { "type": "$alert_type", "title": "$alert_title", "service": { "id": "$service_id", "type": "service_reference" } } }
{ "incident": { "type": "$alert_type", "title": "$alert_title", "service": { "id": "$service_id", "type": "service_reference" }, "incident_key": "$incident_key" } }
EOF
}

_curl -vvv -X POST --header 'Content-Type: application/json' \
_curl POST --header 'Content-Type: application/json' \
--header 'Accept: application/vnd.pagerduty+json;version=2' \
--header "From: $alert_from" \
--header "Authorization: Token token=$alert_token" \
Expand Down

0 comments on commit 782c576

Please sign in to comment.