Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Fully support Events API v2 in PagerDuty step #697

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
15 changes: 13 additions & 2 deletions incubating/pagerduty-alert/lib/pagerduty_alert.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
from pdpyras import APISession
from pdpyras import ChangeEventsAPISession
from pdpyras import APISession, EventsAPISession, ChangeEventsAPISession

def main():

Expand All @@ -14,6 +13,7 @@ def main():
service_id = os.getenv('SERVICE_ID')
title = os.getenv('TITLE')
pagerduty_type = os.getenv('PAGERDUTY_ALERT_TYPE')
pagerduty_severity = os.getenv('PAGERDUTY_SEVERITY')

if pagerduty_type == 'incident':
session = APISession(api_token, default_from=from_email)
Expand All @@ -38,6 +38,17 @@ def main():

pd_incident = session.rpost('incidents', json=payload)

elif pagerduty_type == 'event':
session = EventsAPISession(api_token)

pd_event = session.trigger(
summary='{}'.format(event_summary),
source='{}'.format(event_source),
severity='{}'.format(pagerduty_severity),
custom_details={"Build ID":'{}'.format(cf_build_id)},
links=[{'href':'{}'.format(cf_build_url)}]
)

elif pagerduty_type == 'change_event':

session = ChangeEventsAPISession(api_token)
Expand Down
28 changes: 25 additions & 3 deletions incubating/pagerduty-alert/step.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ kind: step-type
version: '1.0'
metadata:
name: pagerduty-alert
version: 1.0.2
version: 1.1.0
isPublic: true
description: Sends Alerts (Incidents or Change Events) to PagerDuty API
description: Sends events to PagerDuty via the Events or REST APIs (v2)
sources:
- https://github.com/codefresh-io/steps/tree/master/incubating/pagerduty-alert
stage: incubating
Expand Down Expand Up @@ -36,6 +36,16 @@ metadata:
FROM_EMAIL: [email protected]
TITLE: "Codefresh Build Failed: ${{CF_BUILD_URL}}"
SERVICE_ID: 87hsd2fh38gh7g
- description: submit-event
workflow:
SubmitEvent:
type: pagerduty-alert
arguments:
API_TOKEN: x2392fhhgdys867gt3fd
PAGERDUTY_ALERT_TYPE: event
PAGERDUTY_SEVERITY: error
EVENT_SOURCE: Codefresh
EVENT_SUMMARY: "Codefresh Build Failed: ${{CF_BUILD_URL}}"
- description: submit-change-event
workflow:
SubmitChangeEvent:
Expand Down Expand Up @@ -68,9 +78,21 @@ spec:
"default": "change_event",
"enum": [
"incident",
"event",
"change_event"
]
},
"PAGERDUTY_SEVERITY": {
"type": "string",
"description": "Optional for event type, PagerDuty Severity",
"default": "error",
"enum": [
"critical",
"error",
"warning",
"info"
]
},
"ASSIGNEE_USER_ID": {
"type": "string",
"description": "Optional for incident type when an escalation policy is in place, PagerDuty User ID"
Expand Down Expand Up @@ -102,7 +124,7 @@ spec:
stepsTemplate: |-
pagerduty-alert:
name: pagerduty-alert
image: quay.io/codefreshplugins/pagerduty-alert:1.0.2
image: quay.io/codefreshplugins/pagerduty-alert:1.1.0
environment:
[[ range $key, $val := .Arguments ]]
- '[[ $key ]]=[[ $val ]]'
Expand Down