PagerDuty

PagerDuty is a powerful digital operations management platform that lets you manage incidents, set up on-call rotations, and access valuable operational analytics and insights.

This IntegrationIntegration - An integration is the place the you write your code to get things done! Written in NodeJS, an integration runs in Fusebit's secure and scalable environment to translate between the needs of your backend application and the remote service or services you're connecting to. allows full access to the PagerDuty REST API from your application. Fusebit's multi-tenant approach makes it easy for you to manage multiple PagerDuty connections on behalf of your app's users. Our Node.js-based programming model and lightweight deployment story make it easy to customize the Integration with any necessary business logic.

Getting Started

  1. Use the Fusebit Management PortalFusebit Management Portal - The Fusebit Management Portal enables you to easily setup and manage all your integrations in one place. Link: https://manage.fusebit.io to create an account and log in.
  2. Create a new Integration using one of our PagerDuty templates
  1. You will then be able to run the Integration, download it's code, modify it, and deploy your changes. Detailed instructions on how to get started with an Integration are available here.

Invoking the PagerDuty API

The Integration template comes pre-configured with some example calls that invoke PagerDuty's API, for example:

const incidents = await pagerdutyClient.get('/incidents');

const incidentList = incidents.resource.map((incident) => ({
  incedentTitle: incident.title,
  affectedService: incident.service.summary,
}));

ctx.body = incidentList;

The pagerdutyClient object provided by Fusebit is an instance of the pdjs npm package. The full reference documentation for the package is available here.

Fusebit ensures the above SDK object is already bootstrapped with the PagerDuty credentials of the user invoking the integration. You do not need to worry about obtaining an access token or refresh token -- Fusebit does that for you automatically.

Creating your own PagerDuty App

Out of the box, Fusebit's PagerDuty Integration uses our own demonstration application. This is to make it easier to get started, however you will likely need to register your own PagerDuty App for use in production.

To create your own PagerDuty App, follow these steps. When in doubt, you can also consult the official docs:

  1. In your Integration in the Fusebit Portal, select the Connector linked to that Integration
  1. Select Enable Production Credentials and then copy the value of OAuth2 Redirect URL from the PagerDuty Configuration section. Hold on to this value as you will be needing it later.
  1. From your PagerDuty account top menu, select Integrations > Developer Mode
  1. On the My Apps page, select Create New App
  2. Fill out the required fields on the Build an App screen
  3. In the Configure App section, select OAuth 2.0 under Functionality
  1. In the OAuth 2.0* screen, paste the value you copied from the Fusebit Portal earlier under Redirect URL and then hit Save**.
  1. PagerDuty will then present you with a Client ID and Client Secret value
  1. Paste those values in the corresponding fields back in the Fusebit Portal. Don't forget to hit Save at the bottom of the page!
  1. Fill out the Set Permission Scopes depending on whether you intend that your integration just read data from PagerDuty or read and write, and hit Save.

πŸ‘

Good Job!

Now, any time a new user installs your Integration, you should now see your PagerDuty App information displayed during the authorization step.

Receiving Events from PagerDuty

Once you have configured your PagerDuty App, you can easily set up PagerDuty Webhooks from within your Integration.

To do this, you will need to do the following:

Create a Webhook Subscription

To register a Webhook Subscription, you will need run the following endpoint in your integration:

router.get('/api/webhooks/:tenantId', async (ctx) => {
  const sdk = await integration.webhook.getSdkByTenant(ctx, pagerDutyConnector, ctx.params.tenantId);
 // API Reference: https://developer.pagerduty.com/api-reference/b3A6MjkyNDc4NA-create-a-webhook-subscription
  await sdk.create({
    description: 'Incident Created',
    events: [
    'incident.escalated',
    'incident.priority_updated',
    'incident.reopened',
    'incident.resolved',
    'incident.triggered'],
    filter: {
      type: 'account_reference'
    }
  })
});

❗️

PagerDuty Generic Webhooks (V3)

Fusebit's current security model does not support receiving events from Generic Webhooks that are configured from the PagerDuty Website under the Integrations Tab.

Please make sure that you create a webhook subscription from within Fusebit through the Integration itself.

Handle the Event in the Integration

Once you have created a subscription for the Webhook, then your integration will automatically receive events. You can listen for and handle them with the following endpoint:

integration.event.on('/:componentName/webhook/:eventtype', async (ctx) => {

  const data = ctx.req.body;
  console.log ('event received!')
// Insert your code here and invoke your backend to perform an action using this information!
});

Support

If you encounter any issues, please reach out via our support channels or use the chat bubble on this page and we'll be happy to assist.


Did this page help you?