From 1fcc204d2f99d81f96bbe5dd8a9034d345dc0da0 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Wed, 5 Nov 2025 17:29:57 +0100 Subject: [PATCH 1/7] feat(pagerduty/alert): support integration with pagerduty --- pagerduty/alert/README.md | 51 ++++++++++++++++++++++++ pagerduty/alert/action.yml | 81 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 132 insertions(+) create mode 100644 pagerduty/alert/README.md create mode 100644 pagerduty/alert/action.yml diff --git a/pagerduty/alert/README.md b/pagerduty/alert/README.md new file mode 100644 index 00000000..28faadbd --- /dev/null +++ b/pagerduty/alert/README.md @@ -0,0 +1,51 @@ +# pagerduty-alert + +[![usages](https://img.shields.io/badge/usages-white?logo=githubactions&logoColor=blue)](https://github.com/search?q=elastic%2Foblt-actions%2F.github%2Factions%2Fpagerduty%2Falert+%28path%3A.github%2Fworkflows+OR+path%3A**%2Faction.yml+OR+path%3A**%2Faction.yaml%29&type=code) +[![test-pagerduty-alert](https://github.com/elastic/oblt-actions/actions/workflows/test-pagerduty-alert.yml/badge.svg?branch=main)](https://github.com/elastic/oblt-actions/actions/workflows/test-pagerduty-alert.yml) + + +Raise a PagerDuty + + +## Inputs + +| Name | Description | Required | Default | +|---------------|------------------------------------|----------|------------| +| `summary` | The PagerDuty summary of the alert | `true` | ` ` | +| `source` | The PagerDuty source of the alert | `true` | ` ` | +| `api-key` | The PagerDuty API key | `true` | ` ` | +| `component` | The PagerDuty component | `true` | ` ` | +| `routing-key` | The PagerDuty integration key | `true` | ` ` | +| `severity` | The PagerDuty severity | `false` | `critical` | + + +## Outputs + + +| Name | Description | +|----------------|----------------------------------------| +| `incident-url` | The HTML URL of the PagerDuty incident | + + +## Usage + +```yaml +jobs: + assign-engineer-urgent-now: + steps: + - uses: elastic/oblt-actions/pagerduty/alert@v1 + id: pagerduty + with: + summary: "Reported some errors with XYZ" + source: "https://..." + api-key: "${{ secrets.PD_SECRET }}" + component: "my-component" + severity: "critical" + routing-key: "abderg1231231312" + + - name: Notify a pagerduty incident has been created + run: echo "${{steps.pagerduty.outputs.incident-url}} has been created" + +``` + + diff --git a/pagerduty/alert/action.yml b/pagerduty/alert/action.yml new file mode 100644 index 00000000..683bb023 --- /dev/null +++ b/pagerduty/alert/action.yml @@ -0,0 +1,81 @@ +name: 'pagerduty-alert' +description: 'Raise a PagerDuty' +inputs: + summary: + description: 'The PagerDuty summary of the alert' + required: true + source: + description: 'The PagerDuty source of the alert' + required: true + api-key: + description: 'The PagerDuty API key' + required: true + component: + description: 'The PagerDuty component' + required: true + routing-key: + description: 'The PagerDuty integration key' + required: true + severity: + description: 'The PagerDuty severity' + default: 'critical' + required: false + +outputs: + incident-url: + description: 'The HTML URL of the PagerDuty incident' + value: ${{ steps.get_incident.outputs.result }} + +runs: + using: "composite" + steps: + - uses: actions/github-script@v8 + id: sanitize + env: + SUMMARY: ${{ inputs.summary }} + with: + script: | + const sanitizedTitle = JSON.stringify(process.env.SUMMARY).slice(1, -1) + console.log(`sanitized summary is: ${sanitizedTitle}`) + core.setOutput("summary", sanitizedTitle) + + const now = new Date() + const fifteenMinutesAgo = new Date(now.getTime() - (15 * 60 * 1000)) + const isoDate = fifteenMinutesAgo.toISOString() + core.setOutput("time-search", isoDate) + + - name: Trigger PagerDuty Alert + uses: fjogeleit/http-request-action@1297c6fc63a79b147d1676540a3fd9d2e37817c5 # v1.16.5 + with: + url: 'https://events.pagerduty.com/v2/enqueue' + method: 'POST' + customHeaders: '{"Accept": "application/json", "Content-Type": "application/json", "Authorization" : "Token token=${{ inputs.api-key }}"}' + data: '{"event_action": "trigger", "routing_key": "${{ inputs.routing-key }}", "payload": {"summary": "${{steps.sanitize.outputs.summary}}", "source": "${{ inputs.source }}", "custom_details":"${{ inputs.source }}", "severity": "${{ inputs.severity }}", "component": "${{ inputs.component }}"}}' + + - name: Fetch PagerDuty Incidents + id: pagerduty_incident + uses: fjogeleit/http-request-action@1297c6fc63a79b147d1676540a3fd9d2e37817c5 # v1.16.5 + with: + url: 'https://api.pagerduty.com/incidents?since=${{steps.sanitize.outputs.time-search}}&statuses[]=triggered&statuses[]=acknowledged' + method: 'GET' + customHeaders: '{"Accept": "application/json", "Content-Type": "application/json", "Authorization" : "Token token=${{ inputs.api-key }}"}' + + - name: Search the incident + uses: actions/github-script@v8 + id: get_incident + env: + SUMMARY: ${{ steps.sanitize.outputs.summary }} + with: + script: | + const responseData = `${{ steps.pagerduty_incident.outputs.response }}` + const parsedData = JSON.parse(responseData) + const summary = process.env.SUMMARY + const specificIncident = parsedData.incidents.find(incident => incident.title === summary) + if (specificIncident) { + console.log(`Found HTML URL: ${specificIncident.html_url}`) + return specificIncident.html_url + } else { + console.log('No incident found.') + return '' + } + result-encoding: string From edf295546e85fb9be849f8d59323e9faa86a0d6d Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Wed, 5 Nov 2025 17:38:23 +0100 Subject: [PATCH 2/7] add tests --- .github/workflows/no-test.yml | 1 + .github/workflows/test-pagerduty-alert.yml | 33 ++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 .github/workflows/test-pagerduty-alert.yml diff --git a/.github/workflows/no-test.yml b/.github/workflows/no-test.yml index 1dd85adb..9e553456 100644 --- a/.github/workflows/no-test.yml +++ b/.github/workflows/no-test.yml @@ -27,6 +27,7 @@ on: - '!oblt-cli/cluster-name-validation/**' - '!oblt-cli/list/**' - '!oblt-cli/run/**' + - '!pagerduty/alert/**' - '!pre-commit/**' - '!updatecli/run/**' diff --git a/.github/workflows/test-pagerduty-alert.yml b/.github/workflows/test-pagerduty-alert.yml new file mode 100644 index 00000000..d19f9621 --- /dev/null +++ b/.github/workflows/test-pagerduty-alert.yml @@ -0,0 +1,33 @@ +name: test-pagerduty-alert + +on: + merge_group: ~ + workflow_dispatch: ~ + pull_request: + branches: + - main + paths: + - '.github/workflows/test-pagerduty-alert.yml' + - 'pagerduty/alert/**' + +permissions: + contents: read + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + - uses: ./pagerduty/alert + id: pagerduty-alert + with: + summary: 'Test Alert from OBLT Actions' + source: 'OBLT Actions Test Suite' + api-key: ${{ secrets.PD_SECRET }} + component: 'OBLT Actions' + routing-key: ${{ secrets.PAGERDUTY_ROUTING_KEY }} + severity: 'critical' + + - name: Assert output is not empty + run: | + [ -z "${{ steps.pagerduty-alert.outputs.incident-url }}" ] && exit 1 || exit 0 From 3a061fd544f30d151fe7f01efcd11e78718ab836 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Wed, 5 Nov 2025 17:39:45 +0100 Subject: [PATCH 3/7] rename secret --- .github/workflows/test-pagerduty-alert.yml | 2 +- pagerduty/alert/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-pagerduty-alert.yml b/.github/workflows/test-pagerduty-alert.yml index d19f9621..8e8d2212 100644 --- a/.github/workflows/test-pagerduty-alert.yml +++ b/.github/workflows/test-pagerduty-alert.yml @@ -25,7 +25,7 @@ jobs: source: 'OBLT Actions Test Suite' api-key: ${{ secrets.PD_SECRET }} component: 'OBLT Actions' - routing-key: ${{ secrets.PAGERDUTY_ROUTING_KEY }} + routing-key: ${{ secrets.PD_ROUTING_KEY }} severity: 'critical' - name: Assert output is not empty diff --git a/pagerduty/alert/README.md b/pagerduty/alert/README.md index 28faadbd..4f60ea79 100644 --- a/pagerduty/alert/README.md +++ b/pagerduty/alert/README.md @@ -41,7 +41,7 @@ jobs: api-key: "${{ secrets.PD_SECRET }}" component: "my-component" severity: "critical" - routing-key: "abderg1231231312" + routing-key: "${{ secrets.PD_ROUTING_KEY }}" - name: Notify a pagerduty incident has been created run: echo "${{steps.pagerduty.outputs.incident-url}} has been created" From 17339dbb0b71918170302876bbb33999598456ab Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Wed, 5 Nov 2025 17:44:36 +0100 Subject: [PATCH 4/7] Update .github/workflows/test-pagerduty-alert.yml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .github/workflows/test-pagerduty-alert.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-pagerduty-alert.yml b/.github/workflows/test-pagerduty-alert.yml index 8e8d2212..a70c0f66 100644 --- a/.github/workflows/test-pagerduty-alert.yml +++ b/.github/workflows/test-pagerduty-alert.yml @@ -30,4 +30,4 @@ jobs: - name: Assert output is not empty run: | - [ -z "${{ steps.pagerduty-alert.outputs.incident-url }}" ] && exit 1 || exit 0 + [ -n "${{ steps.pagerduty-alert.outputs.incident-url }}" ] From 5ba4bed46798ee10bea20020feec3ffa64009163 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Wed, 5 Nov 2025 17:46:46 +0100 Subject: [PATCH 5/7] chore --- .github/workflows/test-pagerduty-alert.yml | 2 ++ pagerduty/alert/README.md | 4 ++-- pagerduty/alert/action.yml | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test-pagerduty-alert.yml b/.github/workflows/test-pagerduty-alert.yml index a70c0f66..ea49ed2a 100644 --- a/.github/workflows/test-pagerduty-alert.yml +++ b/.github/workflows/test-pagerduty-alert.yml @@ -19,6 +19,7 @@ jobs: steps: - uses: actions/checkout@v5 - uses: ./pagerduty/alert + if: github.event_name == 'pull_request' id: pagerduty-alert with: summary: 'Test Alert from OBLT Actions' @@ -29,5 +30,6 @@ jobs: severity: 'critical' - name: Assert output is not empty + if: github.event_name == 'pull_request' run: | [ -n "${{ steps.pagerduty-alert.outputs.incident-url }}" ] diff --git a/pagerduty/alert/README.md b/pagerduty/alert/README.md index 4f60ea79..2a4aa42b 100644 --- a/pagerduty/alert/README.md +++ b/pagerduty/alert/README.md @@ -1,10 +1,10 @@ # pagerduty-alert -[![usages](https://img.shields.io/badge/usages-white?logo=githubactions&logoColor=blue)](https://github.com/search?q=elastic%2Foblt-actions%2F.github%2Factions%2Fpagerduty%2Falert+%28path%3A.github%2Fworkflows+OR+path%3A**%2Faction.yml+OR+path%3A**%2Faction.yaml%29&type=code) +[![usages](https://img.shields.io/badge/usages-white?logo=githubactions&logoColor=blue)](https://github.com/search?q=elastic%2Foblt-actions%2Fpagerduty%2Falert+%28path%3A.github%2Fworkflows+OR+path%3A**%2Faction.yml+OR+path%3A**%2Faction.yaml%29&type=code) [![test-pagerduty-alert](https://github.com/elastic/oblt-actions/actions/workflows/test-pagerduty-alert.yml/badge.svg?branch=main)](https://github.com/elastic/oblt-actions/actions/workflows/test-pagerduty-alert.yml) -Raise a PagerDuty +Raise a PagerDuty alert and return the incident URL ## Inputs diff --git a/pagerduty/alert/action.yml b/pagerduty/alert/action.yml index 683bb023..7c9d7b49 100644 --- a/pagerduty/alert/action.yml +++ b/pagerduty/alert/action.yml @@ -1,5 +1,5 @@ name: 'pagerduty-alert' -description: 'Raise a PagerDuty' +description: 'Raise a PagerDuty alert and return the incident URL' inputs: summary: description: 'The PagerDuty summary of the alert' From 507ac4b923f6408442b98a2fca15e808df539b47 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Tue, 11 Nov 2025 15:55:25 +0100 Subject: [PATCH 6/7] Update pagerduty/alert/action.yml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- pagerduty/alert/action.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pagerduty/alert/action.yml b/pagerduty/alert/action.yml index 7c9d7b49..67a61a39 100644 --- a/pagerduty/alert/action.yml +++ b/pagerduty/alert/action.yml @@ -39,8 +39,10 @@ runs: console.log(`sanitized summary is: ${sanitizedTitle}`) core.setOutput("summary", sanitizedTitle) + // Time window (15 minutes) for searching recent incidents, in milliseconds + const SEARCH_WINDOW_MS = 15 * 60 * 1000; const now = new Date() - const fifteenMinutesAgo = new Date(now.getTime() - (15 * 60 * 1000)) + const fifteenMinutesAgo = new Date(now.getTime() - SEARCH_WINDOW_MS) const isoDate = fifteenMinutesAgo.toISOString() core.setOutput("time-search", isoDate) From dfea28f4c6ce6a826b7997a1dca109f097cbfd80 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Tue, 11 Nov 2025 16:06:19 +0100 Subject: [PATCH 7/7] Apply suggestion from @v1v --- pagerduty/alert/action.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pagerduty/alert/action.yml b/pagerduty/alert/action.yml index 67a61a39..b1b72d7d 100644 --- a/pagerduty/alert/action.yml +++ b/pagerduty/alert/action.yml @@ -40,9 +40,8 @@ runs: core.setOutput("summary", sanitizedTitle) // Time window (15 minutes) for searching recent incidents, in milliseconds - const SEARCH_WINDOW_MS = 15 * 60 * 1000; const now = new Date() - const fifteenMinutesAgo = new Date(now.getTime() - SEARCH_WINDOW_MS) + const fifteenMinutesAgo = new Date(now.getTime() - (15 * 60 * 1000)) const isoDate = fifteenMinutesAgo.toISOString() core.setOutput("time-search", isoDate)