Coder Social home page Coder Social logo

action-pagerduty-alert's Introduction

PagerDuty Alert GitHub Action

Sends a critical PagerDuty alert, e.g. on action failure.

Prerequisites

  1. Create a service integration in PagerDuty:
    1. Go to PagerDuty > "Services" > Pick your service > "Integrations" > "Add a new integration"
    2. Choose a name (e.g. "Your GitHub CI/CD") and "Use our API directly" with "Events API v2"
    3. Copy the integration key
  2. Set up a secret in your GitHub repo to store the integration key, e.g. "PAGERDUTY_INTEGRATION_KEY"

Inputs

pagerduty-integration-key

Required: the integration key for your PagerDuty service

pagerduty-dedup-key

Optional: a dedup_key for your alert. This will enable PagerDuty to coalesce multiple alerts into one. More documentation is available here.

Example usage

In your steps:

- name: Send PagerDuty alert on failure
  if: ${{ failure() }}
  uses: Entle/[email protected]
  with:
    pagerduty-integration-key: '${{ secrets.PAGERDUTY_INTEGRATION_KEY }}'
    pagerduty-dedup-key: github_workflow_failed

action-pagerduty-alert's People

Contributors

johjonker avatar miparnisari avatar szunami avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

action-pagerduty-alert's Issues

Allow callers to specify additional parameters (summary, severity, group, class, component)

Would be nice to allow callers to pass additional parameters; I have a (local) branch for this (including updates to README) but don't have permission to push upstream.

// Run the action
try {
  const severityLevels = ['critical', 'error', 'warning', 'info'];
  const defaultSeverity = 'critical';

  const integrationKey = core.getInput('pagerduty-integration-key');
  const summary = core.getInput('pagerduty-summary') ?? `${context.repo.repo}: Error in "${context.workflow}" run by @${context.actor}`;
  const severityParam = core.getInput('pagerduty-severity');
  const severity = severityLevels.includes(severityParam) ? severityParam : defaultSeverity;

  let alert = {
    payload: {
      summary,
      timestamp: new Date().toISOString(),
      source: 'GitHub Actions',
      severity,
      custom_details: {
        run_details: `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
        related_commits: context.payload.commits
          ? context.payload.commits.map((commit) => `${commit.message}: ${commit.url}`).join(', ')
          : 'No related commits',
      },
    },
    routing_key: integrationKey,
    event_action: 'trigger',
  };

  // See https://developer.pagerduty.com/docs/ZG9jOjExMDI5NTgx-send-an-alert-event for endpoint documentation
  const componentParam = core.getInput('pagerduty-component');
  if (componentParam) {
    alert.component = componentParam;
  }

  const groupParam = core.getInput('pagerduty-group');
  if (groupParam) {
    alert.group = groupParam;
  }

  const classParam = core.getInput('pagerduty-class');
  if (classParam) {
    alert.class = classParam;
  }

  const dedupKey = core.getInput('pagerduty-dedup-key');
  if (dedupKey != '') {
    alert.dedup_key = dedupKey;
  }
  sendAlert(alert);
} catch (error) {
  core.setFailed(error.message);
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.