> ## Documentation Index
> Fetch the complete documentation index at: https://docs.chronosphere.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Create a PagerDuty notifier

To create a PagerDuty notifier, set up PagerDuty and then create the notifier in
Chronosphere Observability Platform.

## Set up PagerDuty

Before creating a PagerDuty notifier in Observability Platform, configure the
integration in PagerDuty.

To configure a PagerDuty notifier:

1. In PagerDuty, go to **Services <span aria-label="and then">></span> Service Directory**
   and click **New Service**.
2. Enter a name and description for the service and follow the remaining prompts.
3. Select **Prometheus** from the integration types list and create the service.
4. After PagerDuty redirects you to the new service, click the **Integrations** tab,
   which displays the integration key.
5. Copy the integration key, which you enter when creating a PagerDuty notifier in
   Observability Platform.

<Note>
  The [PagerDuty v1 Event API](https://developer.pagerduty.com/docs/ZG9jOjExMDI5NTc4-send-a-v1-event)
  uses a `service_key`, and the
  [PagerDuty v2 Event API](https://developer.pagerduty.com/docs/ZG9jOjExMDI5NTgx-send-an-alert-event)
  uses a `routing_key`.

  If you're using the PagerDuty v2 Event API, create your notifier with either
  Terraform or Chronoctl. You can specify only a `service_key` in Observability
  Platform.
</Note>

Next, [create a PagerDuty notifier](#create-a-pagerduty-notifier-in-observability-platform)
in Observability Platform.

## Create a PagerDuty notifier in Observability Platform

After [setting up PagerDuty](#set-up-pagerduty), you can create a PagerDuty notifier
in Observability Platform.

The Observability Platform PagerDuty notifier sends alert details to PagerDuty as a
string for improved readability in the PagerDuty user interface. The alert details
can also be sent as a JSON object for use in downstream PagerDuty AIOps features. The
JSON format makes it easier to consume alert details programmatically, while
retaining data visibility in the user interface. To enable JSON format,
[contact Chronosphere Support](/support).

Select from the following methods to create a PagerDuty notifier. You can use
[variables](/investigate/alerts/notifications/notifiers#use-variables-in-notifiers) in your
notifiers.

<Tabs>
  <Tab title="Web" id="create-pagerduty-notifier">
    To create a PagerDuty notifier:

    1. In the navigation menu select
       **<Icon icon="bell" /> Alerting <span aria-label="and then">></span> Notifiers**.

    2. Click **Create notifier**.

    3. Enter a descriptive name for the notifier.

    4. Select **PagerDuty** as the type of notifier you want to create.

    5. In the **Service key** field, enter the integration key you created in PagerDuty.

    6. In the **URL** field, enter a URL, which is called as a `POST` request. For
       example:

       ```text theme={null}
       https://events.pagerduty.com/generic/2010-04-15/create_event.json
       ```

           <Warning>
             Don't use the default value from PagerDuty in the **URL** field. You must enter
             the **Integration URL** from PagerDuty.
           </Warning>

    7. In the **Severity** dropdown, select a severity for the event.

    8. Optional: Select **Notify when resolved** to send a resolved alert notification.

    9. Click **Save**.
  </Tab>

  <Tab title="Chronoctl" id="pagerduty-chronoctl">
    To create one or more notifiers using [Chronoctl](/tooling/chronoctl), create a YAML file
    that defines them and apply the configuration to your instance.

    <Note>
      You can use the `notifiers scaffold` command to generate an example notifier, and
      then copy the resource definition for your notifier type:

      ```shell theme={null}
      chronoctl notifiers scaffold
      ```
    </Note>

    1. Define the resource definition for your PagerDuty notifier by adding the following
       information to a YAML file:

       ```yaml /NAME/ /SLUG/ /ROUTING_KEY/ /SEVERITY/ theme={null}
       api_version: v1/config
       kind: Notifier
       spec:
         name: NAME
         slug: SLUG
         pagerduty:
           - routing_key: ROUTING_KEY
             url: https://events.pagerduty.com/v2/enqueue
             severity: SEVERITY
       ```

       Replace the following:

       * *`NAME`*: A descriptive name, such as `team-pagerduty`.
       * *`SLUG`*: A unique identifier, such as `team-pagerduty`.
       * *`ROUTING_KEY`*: Your PagerDuty integration key.
       * *`SEVERITY`*: A severity, such as `critical` or `warning`.

    2. Apply the changes:

       ```shell /FILE_NAME/ theme={null}
       chronoctl apply -f FILE_NAME.yaml
       ```

       Replace *`FILE_NAME`* with the name of the notifier YAML file you previously
       created.
  </Tab>

  <Tab title="Terraform" id="pagerduty-terraform">
    To create a PagerDuty notifier:

    1. Create a PagerDuty notifier with Terraform by using the
       `chronosphere_pagerduty_alert_notifier` type followed by a name in a resource
       declaration:

       ```terraform theme={null}
       resource "chronosphere_pagerduty_alert_notifier" "pagerduty_notifier" {
         name = "PagerDuty Notifier"

         # Optional slug of the pagerduty notifier.
         slug = "pd-notifier"

         ## Notifier-specific required configuration
         severity      = "info"
         url           = "https://events.pagerduty.com/v2/enqueue"

         # Exactly one of service_key or routing_key has to be specified
         # service_key = "XXXXX"
         routing_key = "my-routing-key"

         ## Notifier-specific optional configurations
         class       = "my_class"
         client      = "my_client"
         client_url  = "https://my_client_url"
         component   = "my_component"
         description = "helpful description"
         details     = {
           "first_detail" = "interesting detail"
         }
         group       = "my_group"

         # Can have multiple images.
         image {
           # src is required for every image
           src  = "https://example.com/image/myimage.png"
           alt  = "Chronosphere"
           href = ""
         }

         # Can have multiple links.
         link {
           # href is required for every link
           href = "https://chronosphere.io/"
           text = "some text"
         }

         ## (Optional) Base configuration common to all notifiers
         send_resolved = true # The default value

         ## (Optional) HTTP configuration common to HTTP notifiers
         basic_auth_username = "username"
         basic_auth_password = "strong+p@ssword"
         # Can use bearer_token instead of basic auth
         tls_insecure_skip_verify = false
       }
       ```

    2. In the `severity` field, specify a severity, such as `critical` or `warning`.

    3. In the `routing_key` field, enter your PagerDuty integration key as the value.

    4. Add the following URL, called as a `POST` request, to the `url` key:

       ```text theme={null}
       https://events.pagerduty.com/v2/enqueue
       ```

    5. Run `terraform apply` to create the notifier resource.

       ```shell theme={null}
       terraform apply
       ```

    See [send an alert event](https://developer.pagerduty.com/docs/events-api-v2/trigger-events/)
    in the PagerDuty documentation for more information.
  </Tab>

  <Tab title="API" id="pagerduty-API">
    To complete this action with the Chronosphere API, use the `pagerduty` object in the
    [`CreateNotifier`](/tooling/api-info/definition/operations/CreateNotifier) endpoint.

    Because the Chronosphere API requires authentication, include an API token with your
    `curl` request, as shown in the following example. For more details, see
    [Create an API token](/tooling/api-info#create-an-api-token).

    ```shell /"TOKEN"/ /INSTANCE/ /METHOD/ /ENDPOINT_PATH/ theme={null}
    export CHRONOSPHERE_API_TOKEN="TOKEN"
    export CHRONOSPHERE_DOMAIN="INSTANCE.chronosphere.io"

    curl -H "API-Token: ${CHRONOSPHERE_API_TOKEN}" \
         -X METHOD "https://${CHRONOSPHERE_DOMAIN}/ENDPOINT_PATH"
    ```

    Replace the following:

    * *`TOKEN`*: Your API token.
    * *`INSTANCE`*: The subdomain name for your organization's Observability Platform instance.
    * *`METHOD`*: The HTTP method to use with the request, such as `GET` or `POST`.
    * *`ENDPOINT_PATH`*: The specific endpoint you want to access.
  </Tab>
</Tabs>
