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 21, 2021
1 parent 57c03b2 commit 8b73b4f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ default_language_version:
python: python3
repos:
- repo: https://github.com/commitizen-tools/commitizen
rev: v2.17.4
rev: v2.17.6
hooks:
- id: commitizen
stages: [commit-msg]
Expand Down Expand Up @@ -48,11 +48,11 @@ repos:
hooks:
- id: markdownlint_docker
- repo: https://github.com/pre-commit/mirrors-eslint
rev: v7.25.0
rev: v7.26.0
hooks:
- id: eslint
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
rev: v4.0.1
hooks:
- id: check-added-large-files
- id: check-case-conflict
Expand Down
1 change: 0 additions & 1 deletion bash/pagerduty-alert
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ options::parse_available "$@"

ALERT_TITLE=${ALERT_TITLE:="Test Alert"}
ALERT_FROM=${ALERT_FROM:="no-reply@blockchaintp.com"}
INCIDENT_KEY=${INCIDENT_KEY:="default_dedup"}

case $ALERT_TYPE in
incident)
Expand Down
16 changes: 12 additions & 4 deletions bash/pagerduty.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,19 @@ function send_incident() {
local alert_token="${5:?}"
local incident_key="${6:?}"

incident_data() {
cat <<EOF
{ "incident": { "type": "$alert_type", "title": "$alert_title", "service": { "id": "$service_id", "type": "service_reference" }, "incident_key": "$incident_key" } }
if [ -z "$incident_key" ]; then
incident_data() {
cat <<EOF
{ "incident": { "type": "$alert_type", "title": "$alert_title", "service": { "id": "$service_id", "type": "service_reference" } } }
EOF
}
}
else
incident_data() {
cat <<EOF
{ "incident": { "type": "$alert_type", "title": "$alert_title", "service": { "id": "$service_id", "type": "service_reference" }, "incident_key": "$incident_key" } }
EOF
}
fi

_curl POST --header 'Content-Type: application/json' \
--header 'Accept: application/vnd.pagerduty+json;version=2' \
Expand Down

0 comments on commit 8b73b4f

Please sign in to comment.