From cabaf46f93e12ee70cfa80684e8a3c767cd43dd3 Mon Sep 17 00:00:00 2001 From: Illirik Smirnov Date: Tue, 25 Jul 2023 18:50:07 -0400 Subject: [PATCH 1/3] add resolve flag and documentation --- README.md | 21 ++++++++++++++++++++- action.yml | 3 +++ index.js | 4 ++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9d4a282..ca7bf17 100644 --- a/README.md +++ b/README.md @@ -18,11 +18,16 @@ Sends a critical PagerDuty alert, e.g. on action failure. `pagerduty-dedup-key` **Optional:** a `dedup_key` for your alert. This will enable PagerDuty to coalesce multiple alerts into one. + +`resolve` + +**Optional:** If set to true, will resolve any active alerts with `dedup_key`. This allows you to automatically resolve alerts for a job if a subsequent run is successful. + More documentation is available [here](https://developer.pagerduty.com/docs/events-api-v2/trigger-events/). ## Example usage -In your `steps`: +Adding this to your `steps` will page if the job fails: ```yaml - name: Send PagerDuty alert on failure @@ -32,3 +37,17 @@ In your `steps`: pagerduty-integration-key: '${{ secrets.PAGERDUTY_INTEGRATION_KEY }}' pagerduty-dedup-key: github_workflow_failed ``` + +This config will resolve the page if the job subsequently succeeds: + +```yaml +- name: Send PagerDuty alert on failure + if: ${{ !failure() }} + uses: Entle/action-pagerduty-alert@0.2.0 + with: + pagerduty-integration-key: '${{ secrets.PAGERDUTY_INTEGRATION_KEY }}' + pagerduty-dedup-key: github_workflow_failed + resolve: true +``` + +Customizing the logic within the `if` configs allows for more complex page and resolution behavior. diff --git a/action.yml b/action.yml index a9ca183..153c8f9 100644 --- a/action.yml +++ b/action.yml @@ -7,6 +7,9 @@ inputs: pagerduty-dedup-key: description: 'The key used to correlate PagerDuty triggers, acknowledges, and resolves for the same alert.' required: false + resolve: + description: 'If set to true, will resolve any alert with the same pagerduty-dedup-key (if such an alert exists).' + required: false runs: using: 'node12' main: 'index.js' diff --git a/index.js b/index.js index 46da89c..e5f5c4b 100644 --- a/index.js +++ b/index.js @@ -43,6 +43,10 @@ try { if (dedupKey != '') { alert.dedup_key = dedupKey; } + const shouldResolve = core.getInput('resolve'); + if (shouldResolve == 'true') { + alert.event_action = 'resolve'; + } sendAlert(alert); } catch (error) { core.setFailed(error.message); From 0e1011ebad050528939393233e74b3ebf5975e0e Mon Sep 17 00:00:00 2001 From: Illirik Smirnov Date: Tue, 25 Jul 2023 18:57:59 -0400 Subject: [PATCH 2/3] Fix typo in README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ca7bf17..869816c 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ Adding this to your `steps` will page if the job fails: ```yaml - name: Send PagerDuty alert on failure if: ${{ failure() }} - uses: Entle/action-pagerduty-alert@0.2.0 + uses: Entle/action-pagerduty-alert@0.3.0 with: pagerduty-integration-key: '${{ secrets.PAGERDUTY_INTEGRATION_KEY }}' pagerduty-dedup-key: github_workflow_failed @@ -41,9 +41,9 @@ Adding this to your `steps` will page if the job fails: This config will resolve the page if the job subsequently succeeds: ```yaml -- name: Send PagerDuty alert on failure +- name: Resolve PagerDuty alert on success if: ${{ !failure() }} - uses: Entle/action-pagerduty-alert@0.2.0 + uses: Entle/action-pagerduty-alert@0.3.0 with: pagerduty-integration-key: '${{ secrets.PAGERDUTY_INTEGRATION_KEY }}' pagerduty-dedup-key: github_workflow_failed From 4bec5cae5ec5c20caca4a47c96a97c7254a59a80 Mon Sep 17 00:00:00 2001 From: Illirik Smirnov Date: Tue, 25 Jul 2023 20:11:54 -0400 Subject: [PATCH 3/3] Improve README.MD Adds guidance around passing `github.workflow` as a dedupe key. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 869816c..08425e3 100644 --- a/README.md +++ b/README.md @@ -50,4 +50,4 @@ This config will resolve the page if the job subsequently succeeds: resolve: true ``` -Customizing the logic within the `if` configs allows for more complex page and resolution behavior. +Adding both steps to your job will create an alert when the job fails, and resolve the job when it succeeds. Using `${{ github.workflow }}` for `pagerduty-dedup-key` (or any other key that is unique per-workflow) allows multiple jobs that each trigger and resolve alerts independently, while customizing the logic within the `if` configs allows for more complex page and resolution behavior.