PagerDuty.Webhooks 1.2.0-beta5

This is a prerelease version of PagerDuty.Webhooks.
dotnet add package PagerDuty.Webhooks --version 1.2.0-beta5
                    
NuGet\Install-Package PagerDuty.Webhooks -Version 1.2.0-beta5
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="PagerDuty.Webhooks" Version="1.2.0-beta5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="PagerDuty.Webhooks" Version="1.2.0-beta5" />
                    
Directory.Packages.props
<PackageReference Include="PagerDuty.Webhooks" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add PagerDuty.Webhooks --version 1.2.0-beta5
                    
#r "nuget: PagerDuty.Webhooks, 1.2.0-beta5"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package PagerDuty.Webhooks@1.2.0-beta5
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=PagerDuty.Webhooks&version=1.2.0-beta5&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=PagerDuty.Webhooks&version=1.2.0-beta5&prerelease
                    
Install as a Cake Tool

📟 PagerDuty

Nuget GitHub Workflow Status Testspace Coveralls

Trigger, acknowledge, and resolve Alerts and create Changes using the PagerDuty Events API V2. Handle Webhook V3 requests.

  1. Quick Start
  2. Prerequisites
  3. Installation
  4. Events V2
  5. Webhooks
  6. Examples
  7. References
  8. Presentation

Quick Start

dotnet add package PagerDuty
using Pager.Duty;

using var pagerDuty = new PagerDuty("my service's integration key");
AlertResponse alertResponse = await pagerDuty.Send(new TriggerAlert(Severity.Error, "My Alert"));
Console.WriteLine("Triggered alert, waiting 30 seconds before resolving...");

await Task.Delay(TimeSpan.FromSeconds(30));
await pagerDuty.Send(new ResolveAlert(alertResponse.DedupKey));
Console.WriteLine("Resolved alert.");

Prerequisites

Installation

You can install this library into your project from NuGet Gallery:

  • dotnet add package PagerDuty
  • Install-Package PagerDuty
  • Go to Project › Manage NuGet Packages in Visual Studio and search for PagerDuty

Events V2

This library provides a strongly-typed client for the PagerDuty Events V2 API.

Configuration

  1. Create an Integration in PagerDuty and get its Integration Key.
    1. Sign into your PagerDuty account.
    2. Go to Services › Service Directory.
    3. Select an existing Service for which you want to publish events, or create a new Service.
    4. In the Integrations tab of the Service, add a new Integration.
    5. Under Most popular integrations, select Events API V2, then click Add.
    6. Expand the newly-created Integration and copy its Integration Key, which will be used to authorize this library to send Events to the correct Service.
  2. Construct a new PagerDuty client instance in your project, passing your Integration Key as a constructor parameter.
    using Pager.Duty;
    
    IPagerDuty pagerDuty = new PagerDuty(integrationKey: "dfca74ebb7450b3e6da3ba6083a323f4");
    

PagerDuty instances can be reused to send multiple events to the same service over the lifetime of your application. You can add one to your dependency injection context and retain it for as long as you like. If you need to send events to multiple services, construct multiple PagerDuty instance objects.

HTTP settings

If you need to customize any of the settings for the HTTP connection to PagerDuty's API servers, you may optionally provide a custom HttpClient instance to the IPagerDuty object. This allows you to set a proxy server, TLS settings, concurrent connection count, DNS TTL, and other properties.

If you don't set this property, a default HttpClient instance is used instead, and will be automatically disposed of when the PagerDuty instance is disposed of. If you do set this property to a custom HttpClient instance, PagerDuty won't dispose of it, so that you can reuse it in multiple places.

pagerDuty.HttpClient = new HttpClient(new SocketsHttpHandler {
    UseProxy = true,
    Proxy = new WebProxy("10.0.0.2", 8443),
    MaxConnectionsPerServer = 10,
    PooledConnectionLifetime = TimeSpan.FromMinutes(2),
    SslOptions = new SslClientAuthenticationOptions {
        EnabledSslProtocols = SslProtocols.Tls12 | SslProtocols.Tls13
    }
}) {
    Timeout = TimeSpan.FromSeconds(5)
};
Base URL

By default, this library sends event requests to the global PagerDuty cluster, https://events.pagerduty.com/v2/.

You may change this by setting the IPagerDuty.BaseUrl property. For example, if your tenant is hosted in the European Union, you must change the base URL to the EU cluster:

pagerDuty.BaseUrl = new Uri("https://events.eu.pagerduty.com/v2/");

Usage

Triggering an Alert

This creates a new, unresolved alert for your PagerDuty service, showing that a new event has just occurred.

Construct a new TriggerAlert instance with the required severity and summary parameters, and pass it to the IPagerDuty.Send(Alert) method. This returns an AlertResponse once it's been successfully uploaded to PagerDuty.

AlertResponse alertResponse = await pagerDuty.Send(new TriggerAlert(Severity.Error, "Summary"));

In addition to the two required parameters, TriggerAlert also has several optional parameters, all of which you can specify using an object initializer or property assignments.

TriggerAlert trigger = new(Severity.Warning, "Summary of warning") {
    Class = "my class",
    Component = "my component",
    Group = "my group",
    Links = { new Link("https://aldaviva.com", "Aldaviva") },
    Images = { new Image("https://aldaviva.com/avatars/ben.jpg", "https://aldaviva.com", "Ben") },
    CustomDetails = new {
        A = 1,
        B = "2"
    }
};

trigger.Source = "my source";
trigger.Timestamp = DateTimeOffset.Now;
trigger.Client = "My Client";
trigger.ClientUrl = "https://myclient.mycompany.com";

AlertResponse alertResponse = await pagerDuty.Send(trigger);

If a key in your CustomDetails object isn't a valid identifier in C#, for example if it contains spaces, you can also use an IDictionary<string, object>, or any other type that can be serialized into JSON.

trigger.CustomDetails = new Dictionary<string, object> {
    { "key 1", "value 1" },
    { "key 2", "value 2" },
};
Acknowledging an Alert

This moves an existing unresolved alert for your service into the acknowledged state, showing that someone is aware of it.

The value of the required DedupKey constructor parameter comes from an AlertResponse, which is returned when you send a TriggerAlert.

await pagerDuty.Send(new AcknowledgeAlert(alertResponse.DedupKey));
Resolving an Alert

This marks an existing alert for your service as resolved, showing that the original conditions that triggered the alert are no longer present.

The value of the required DedupKey constructor parameter comes from an AlertResponse, which is returned when you send a TriggerAlert.

await pagerDuty.Send(new ResolveAlert(alertResponse.DedupKey));
Creating a Change

This is not an alert, it's a different type of event showing that something expected changed in your service, which may be useful to know about if an alert occurs later.

await pagerDuty.Send(new Change("Summary of Change"));
Handling exceptions

All of the exceptions thrown by IPagerDuty.Send inherit from PagerDutyException, so you can catch that superclass, or the more specialized subclasses: NetworkException, BadRequest, RateLimited, and InternalServerError.

try {
    await pagerDuty.Send(new Change("Summary of Change"));
} catch (PagerDutyException e) when (e.RetryAllowedAfterDelay) {
    // try again later
} catch (BadRequest e) {
    Console.WriteLine($"{e.Message} {e.StatusCode} {e.Response}");
} catch (WebApplicationException) {
    // catch-all for unexpected status codes
}
Cleaning up

When you're done with a PagerDuty instance, call PagerDuty.Dispose() to clean it up and allow the default HttpClient to be garbage collected. A custom HttpClient instance, if set, won't be disposed, so that you can reuse it in multiple places.

pagerDuty.Dispose();

Webhooks

This project provides a library for a server-side HTTP resource which receives Webhook V3 requests from PagerDuty. This allows PagerDuty to immediately push a notification to your server when an event occurs, like an incident being triggered or resolved. This is a reusable route handler for ASP.NET Core ≥ 6 web application servers.

Installation

The server-side webhook resource is packaged in a separate library so that Events API V2 users don't need to depend on ASP.NET Core.

dotnet add package PagerDuty
dotnet add package PagerDuty.Webhooks

Configuration

  1. Create a Webhook in PagerDuty and get its Signing Secret.
    1. Sign into your PagerDuty account.
    2. Go to Integrations › Generic Webhooks (v3).
    3. Click + New Webhook.
    4. Specify the absolute URL of the route you're defining in your HTTP server
      • The scheme must be either https: (certificate must be valid and CA must be in Mozilla's trusted root store) or http:
      • The port is optional, and the default value for the scheme will be used if omitted
      • Example: https://myserver.mydomain.com:8443/pagerduty
    5. Choose whether events should be fired for all Services in your account, or just one Service.
    6. Choose which Events should be fired.
    7. Click Add Webhook.
    8. Copy the Signing Secret and keep it someplace safe, because it won't be shown again and you'll need it to verify Webhook request authenticity.
  2. Construct a new WebhookResource instance in your project, passing your signing secret as a constructor parameter.
    using Pager.Duty;
    using Pager.Duty.Webhooks;
    
    IWebhookResource webhookResource = new WebhookResource(pagerDutySecrets: "1yo7GugPm02PTHj6t34vcrZIxc9oLLVNWpk/qegNNg6I92ruxyElaklrHnw+z1gc");
    
    If you have multiple Webhooks pointing to the same server, you can pass multiple signing secrets in an enumerable or array.

Usage

  1. Create an ASP.NET Core web application.
    WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
    
    await using WebApplication webapp = builder.Build();
    
    // routes are added here
    
    await webapp.RunAsync();
    
    If these types can't be found, set your .csproj root element's sdk attribute value to Microsoft.NET.Sdk.Web.
  2. Add a route to your server that uses the webhook resource's handler function.
    webapp.MapPost("/pagerduty", webhookResource.HandlePostRequest);
    
    This resource must be served with the path you specified when creating the webhook URL in PagerDuty in Configuration, and the HTTP verb must be POST.
  3. Subscribe to events on the webhook resource to be notified when requests are received.
    webhookResource.PingReceived += (sender, ping) => 
        Console.WriteLine("Ping webhook request received from PagerDuty");
    
    webhookResource.IncidentReceived += (sender, incident) =>
        Console.WriteLine($"#{incident.IncidentNumber} {incident.EventType}: {incident.Title} is now {incident.Status}");
    
  4. Run your web application in a server like IIS or Kestrel.
Events

The following events are available, corresponding to the thing that changed (subject).

  • PingReceived
  • IncidentReceived
  • IncidentNoteReceived
  • IncidentConferenceBridgeReceived
  • IncidentFieldValuesReceived
  • IncidentStatusUpdateReceived
  • IncidentResponderReceived
  • IncidentWorkflowInstanceReceived
  • ServiceReceived

To determine the action (verb) that occurred on the subject, read the IWebhookPayload.EventType enum property on the event payload object passed to your event handler. For example, the IncidentReceived event has the following event types.

  • Acknowledged
  • Delegated
  • Escalated
  • IncidentTypeChanged
  • PriorityUpdated
  • Reassigned
  • Reopened
  • Resolved
  • ServiceUpdated
  • Triggered
  • Unacknowledged

Examples

References

Presentation

I gave a talk about this project during PagerDuty's 2024-02-09 How-To Happy Hour on their Twitch channel.

Video

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.0-beta5 237 11/12/2025
1.2.0-beta4 131 10/3/2025