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

Allow alerts to be resolved with a new argument #8

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,36 @@ 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
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
```

This config will resolve the page if the job subsequently succeeds:

```yaml
- name: Resolve PagerDuty alert on success
if: ${{ !failure() }}
uses: Entle/[email protected]
with:
pagerduty-integration-key: '${{ secrets.PAGERDUTY_INTEGRATION_KEY }}'
pagerduty-dedup-key: github_workflow_failed
resolve: true
```

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.
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down