diff --git a/incubating/pagerduty-alert/lib/pagerduty_alert.py b/incubating/pagerduty-alert/lib/pagerduty_alert.py index 687093033..6b7c56c45 100644 --- a/incubating/pagerduty-alert/lib/pagerduty_alert.py +++ b/incubating/pagerduty-alert/lib/pagerduty_alert.py @@ -1,6 +1,5 @@ import os -from pdpyras import APISession -from pdpyras import ChangeEventsAPISession +from pdpyras import APISession, EventsAPISession, ChangeEventsAPISession def main(): @@ -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) @@ -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) diff --git a/incubating/pagerduty-alert/step.yaml b/incubating/pagerduty-alert/step.yaml index be38d9acb..a4fbb54f0 100644 --- a/incubating/pagerduty-alert/step.yaml +++ b/incubating/pagerduty-alert/step.yaml @@ -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 @@ -36,6 +36,16 @@ metadata: FROM_EMAIL: dustin@codefresh.io 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: @@ -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" @@ -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 ]]'