From 7711d0cfbf80a58bda9c453ea4f37b20d9ebe79c Mon Sep 17 00:00:00 2001 From: Kiyan Mair Date: Sun, 14 Jul 2024 15:21:16 -0400 Subject: [PATCH 01/11] feat: Add new arg for PD event action --- incubating/pagerduty-alert/lib/pagerduty_alert.py | 1 + 1 file changed, 1 insertion(+) diff --git a/incubating/pagerduty-alert/lib/pagerduty_alert.py b/incubating/pagerduty-alert/lib/pagerduty_alert.py index 687093033..bf21e5247 100644 --- a/incubating/pagerduty-alert/lib/pagerduty_alert.py +++ b/incubating/pagerduty-alert/lib/pagerduty_alert.py @@ -14,6 +14,7 @@ def main(): service_id = os.getenv('SERVICE_ID') title = os.getenv('TITLE') pagerduty_type = os.getenv('PAGERDUTY_ALERT_TYPE') + pagerduty_event_action = os.getenv('PAGERDUTY_EVENT_ACTION') if pagerduty_type == 'incident': session = APISession(api_token, default_from=from_email) From 68f5ad95a8982219456eae001c56c2641b7d4559 Mon Sep 17 00:00:00 2001 From: Kiyan Mair Date: Sun, 14 Jul 2024 15:23:03 -0400 Subject: [PATCH 02/11] feat: Import EventsAPISession --- incubating/pagerduty-alert/lib/pagerduty_alert.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/incubating/pagerduty-alert/lib/pagerduty_alert.py b/incubating/pagerduty-alert/lib/pagerduty_alert.py index bf21e5247..8d3e214cf 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(): From d71364022e5d2dc35669a2925e9631cabd6828a7 Mon Sep 17 00:00:00 2001 From: Kiyan Mair Date: Sun, 14 Jul 2024 15:29:12 -0400 Subject: [PATCH 03/11] revert: Remove PD event action arg --- incubating/pagerduty-alert/lib/pagerduty_alert.py | 1 - 1 file changed, 1 deletion(-) diff --git a/incubating/pagerduty-alert/lib/pagerduty_alert.py b/incubating/pagerduty-alert/lib/pagerduty_alert.py index 8d3e214cf..3575b7bc2 100644 --- a/incubating/pagerduty-alert/lib/pagerduty_alert.py +++ b/incubating/pagerduty-alert/lib/pagerduty_alert.py @@ -13,7 +13,6 @@ def main(): service_id = os.getenv('SERVICE_ID') title = os.getenv('TITLE') pagerduty_type = os.getenv('PAGERDUTY_ALERT_TYPE') - pagerduty_event_action = os.getenv('PAGERDUTY_EVENT_ACTION') if pagerduty_type == 'incident': session = APISession(api_token, default_from=from_email) From 7661282c3cde334ae98925632a54348a60e84170 Mon Sep 17 00:00:00 2001 From: Kiyan Mair Date: Sun, 14 Jul 2024 15:29:53 -0400 Subject: [PATCH 04/11] feat: Add PD severity arg --- incubating/pagerduty-alert/lib/pagerduty_alert.py | 1 + 1 file changed, 1 insertion(+) diff --git a/incubating/pagerduty-alert/lib/pagerduty_alert.py b/incubating/pagerduty-alert/lib/pagerduty_alert.py index 3575b7bc2..e9040751c 100644 --- a/incubating/pagerduty-alert/lib/pagerduty_alert.py +++ b/incubating/pagerduty-alert/lib/pagerduty_alert.py @@ -13,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) From 1f7c8c78c0ea73136940d70b9b74bc3bd4c7608a Mon Sep 17 00:00:00 2001 From: Kiyan Mair Date: Sun, 14 Jul 2024 15:31:02 -0400 Subject: [PATCH 05/11] feat: Implement triggering with Events API v2 --- incubating/pagerduty-alert/lib/pagerduty_alert.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/incubating/pagerduty-alert/lib/pagerduty_alert.py b/incubating/pagerduty-alert/lib/pagerduty_alert.py index e9040751c..6b7c56c45 100644 --- a/incubating/pagerduty-alert/lib/pagerduty_alert.py +++ b/incubating/pagerduty-alert/lib/pagerduty_alert.py @@ -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) From c429a7094c987ae6294bf9a4694417a4622b90a2 Mon Sep 17 00:00:00 2001 From: Kiyan Mair Date: Sun, 14 Jul 2024 15:32:16 -0400 Subject: [PATCH 06/11] docs: Document new "event" alert type --- incubating/pagerduty-alert/step.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/incubating/pagerduty-alert/step.yaml b/incubating/pagerduty-alert/step.yaml index be38d9acb..f531be3ff 100644 --- a/incubating/pagerduty-alert/step.yaml +++ b/incubating/pagerduty-alert/step.yaml @@ -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: From 3317ba5c1f07fa80500d4412e663471227ee5fe5 Mon Sep 17 00:00:00 2001 From: Kiyan Mair Date: Sun, 14 Jul 2024 15:32:36 -0400 Subject: [PATCH 07/11] chore: Bump minor version --- incubating/pagerduty-alert/step.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/incubating/pagerduty-alert/step.yaml b/incubating/pagerduty-alert/step.yaml index f531be3ff..25ab4fc64 100644 --- a/incubating/pagerduty-alert/step.yaml +++ b/incubating/pagerduty-alert/step.yaml @@ -2,7 +2,7 @@ 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 sources: From e5680e147bbaf491d9427246d90c0e16cb8ef32b Mon Sep 17 00:00:00 2001 From: Kiyan Mair Date: Sun, 14 Jul 2024 15:34:18 -0400 Subject: [PATCH 08/11] docs: Update step description --- incubating/pagerduty-alert/step.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/incubating/pagerduty-alert/step.yaml b/incubating/pagerduty-alert/step.yaml index 25ab4fc64..1c44b06c7 100644 --- a/incubating/pagerduty-alert/step.yaml +++ b/incubating/pagerduty-alert/step.yaml @@ -4,7 +4,7 @@ metadata: name: pagerduty-alert 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 From 309397bfdacc25ed6b82a788d01022a9afa9ee57 Mon Sep 17 00:00:00 2001 From: Kiyan Mair Date: Sun, 14 Jul 2024 15:36:03 -0400 Subject: [PATCH 09/11] feat: Add PD severity arg to step spec --- incubating/pagerduty-alert/step.yaml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/incubating/pagerduty-alert/step.yaml b/incubating/pagerduty-alert/step.yaml index 1c44b06c7..a95bca20d 100644 --- a/incubating/pagerduty-alert/step.yaml +++ b/incubating/pagerduty-alert/step.yaml @@ -81,6 +81,17 @@ spec: "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" From 1538818a47048d22f8369dff3cccceb34672910d Mon Sep 17 00:00:00 2001 From: Kiyan Mair Date: Sun, 14 Jul 2024 15:36:21 -0400 Subject: [PATCH 10/11] chore: Bump minor version in steps template --- incubating/pagerduty-alert/step.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/incubating/pagerduty-alert/step.yaml b/incubating/pagerduty-alert/step.yaml index a95bca20d..2423991e7 100644 --- a/incubating/pagerduty-alert/step.yaml +++ b/incubating/pagerduty-alert/step.yaml @@ -123,7 +123,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 ]]' From ce2fa509da57412f9f2baf918a5fd954cd565a7d Mon Sep 17 00:00:00 2001 From: Kiyan Mair Date: Sun, 14 Jul 2024 15:58:06 -0400 Subject: [PATCH 11/11] feat: Add event alert type to enum in step spec --- incubating/pagerduty-alert/step.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/incubating/pagerduty-alert/step.yaml b/incubating/pagerduty-alert/step.yaml index 2423991e7..a4fbb54f0 100644 --- a/incubating/pagerduty-alert/step.yaml +++ b/incubating/pagerduty-alert/step.yaml @@ -78,6 +78,7 @@ spec: "default": "change_event", "enum": [ "incident", + "event", "change_event" ] },