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

# Alert webhooks

> Deliver signed Agnost alert events to incident, ticketing, and automation systems

Alert webhooks send an HTTPS request when an Agnost alert fires, a daily
summary is ready, or Agnost suggests a new pattern. Use them to open incidents
in PagerDuty or Opsgenie, create ServiceNow events, notify an internal bot, or
start an automation job.

## Add a webhook

Add a webhook in **Alerts → Destinations → Webhooks**. Then, when you create or
edit an alert, pick it under **Notify via → Webhook**. The alert form only picks
existing webhooks; it doesn't create them. The form asks for:

1. **Endpoint URL**: a public HTTPS URL.
2. **Name**: how the webhook appears in the alert form.
3. **Format**: **JSON** for your own services, or **ServiceNow Event Management**.
   **What your endpoint receives** shows an example body and what each field
   means.
4. **Headers (optional)**: usually for authentication, such as `Authorization`
   or `x-sn-apikey`.
5. **Advanced: extra body fields (optional)**: fixed JSON fields added to every
   body.

Choose **Test webhook** to send an `alert.test` event to the URL. Agnost shows
the HTTP status, the response time, and the response body from your endpoint.
**Add webhook** turns on only after a test of the current values passes. If you
change the URL, format, headers, or extra fields, test again before saving.

Each webhook in **Destinations → Webhooks** has a **Deliveries** log and
**Settings**. **Settings** uses the same form, so a name-only change saves
without a test. The **Destinations** button shows a dot when any webhook is
failing.

**Send test** in the alert editor runs that alert once and sends it to its
selected destinations as an `alert.test` event, with its real name, threshold,
current value, and records.

## Payload formats

| Format | Body | Use it for |
| - | - | - |
| JSON | The versioned Agnost event below | Your own services, PagerDuty or Opsgenie bridges, automation jobs |
| ServiceNow Event Management | A ServiceNow Event Management batch: `{"records":[...]}` | `https://<instance>.service-now.com/api/global/em/jsonv2` |

Every format is signed the same way. Only the body changes.

### JSON

Webhook bodies are versioned JSON and are limited to 256 KB. Agnost includes up
to 20 rows returned by the alert's context query and removes rows from the end
if the payload would exceed the limit. `context.rows` is always an array.

```json theme={null}
{
  "version": "2026-11-01",
  "type": "alert.triggered",
  "id": "01b56ea4-2638-41ec-a52d-e5742db87832",
  "created_at": "2026-11-18T12:30:00Z",
  "org_id": "11111111-1111-1111-1111-111111111111",
  "alert": {
    "id": "22222222-2222-2222-2222-222222222222",
    "name": "API errors exceed 10",
    "query": "alert when API errors exceed 10",
    "threshold": { "operator": "gt", "value": 10 },
    "value": 23
  },
  "context": { "rows": [{ "route": "/checkout", "errors": 14 }] },
  "links": {
    "alert": "https://app.agnost.ai/alerts?alert=22222222-2222-2222-2222-222222222222"
  },
  "custom": { "environment": "production", "service": "checkout" }
}
```

Extra body fields are added under `custom`, so the rest of the event stays
stable.

`alert.value` and `threshold.value` are the `value` and `threshold` the alert's
query returned (for a **% above usual** alert, usual adjusted by the percentage).
`threshold.operator` is the comparison in its `condition_met`. `context.rows` holds
the records the message lists; if the query returns extra columns, they come first
as one row.

### ServiceNow Event Management

Agnost sends one event record per delivery:

| Field | Value |
| - | - |
| `source` | `Agnost AI` |
| `node` | The `agent_name` from the first context row, or `Agnost AI` |
| `type`, `resource`, `metric_name` | The alert name |
| `severity` | `2` (major) for triggered alerts, `5` (OK) for tests and daily summaries |
| `message_key` | `agnost:<alert id>`, so every time an alert fires it updates the same ServiceNow alert |
| `description` | The value, threshold, and alert condition in one sentence |
| `time_of_event` | UTC, `yyyy-MM-dd HH:mm:ss` |
| `additional_info` | A JSON string with the alert ID, value, threshold, dashboard link, and up to five context rows |

Extra body fields are merged into the record and win over the defaults, so you
can set `node`, `severity`, `assignment_group`, or any field your event rules
expect. Authenticate with a header such as `Authorization: Basic …` or
`x-sn-apikey`, added under **Headers**.

## Events

| `type` / `Agnost-Event` | Sent when |
| - | - |
| `alert.triggered` | An alert starts firing: its condition is met after a check where it wasn't |
| `alert.test` | You choose **Test webhook**, or **Send test** on an alert |
| `report.daily` | The Daily Summary is delivered to the webhook |

## Headers and signature verification

Every request includes:

* `Agnost-Signature: t=<unix>,v1=<hex HMAC-SHA256>`
* `Agnost-Delivery-Id`: unique per delivery
* `Agnost-Event`: the event type
* `webhook-id`, `webhook-timestamp`, and `webhook-signature`, following
  [Standard Webhooks](https://www.standardwebhooks.com)
* `User-Agent: Agnost-Webhooks/1.0`
* Your custom headers

Verifying the signature is optional: skip it if your endpoint authenticates
requests with a header instead. To verify, open the webhook's **Settings**, find
**Verify requests**, and choose **Reveal** to copy its secret. Secrets look like
`whsec_<base64>`; the HMAC key is the base64-decoded part after `whsec_`.

### Verify with a Standard Webhooks library

Standard Webhooks libraries exist for Python, JavaScript, Go, Java, Rust, Ruby,
PHP, C#, and Elixir. Pass them the `whsec_` secret as-is:

```python theme={null}
from standardwebhooks.webhooks import Webhook

Webhook(signing_secret).verify(raw_body, request.headers)
```

### Verify Agnost-Signature yourself

Compute the HMAC over `<unix timestamp>.<raw request body>` and compare it with
each `v1` value. Do not parse and re-serialize the body before verification.
Reject timestamps more than five minutes from your server time to prevent replay
attacks.

```js theme={null}
import crypto from "node:crypto";

export function verifyAgnostWebhook(rawBody, signature, secret) {
  const parts = signature.split(",").map((part) => part.split("=", 2));
  const timestamp = Number(parts.find(([name]) => name === "t")?.[1]);
  if (!Number.isFinite(timestamp) || Math.abs(Date.now() / 1000 - timestamp) > 300) {
    throw new Error("Webhook timestamp is outside the five-minute tolerance");
  }

  const key = Buffer.from(secret.replace(/^whsec_/, ""), "base64");
  const expected = crypto
    .createHmac("sha256", key)
    .update(`${timestamp}.`)
    .update(rawBody)
    .digest();
  const valid = parts
    .filter(([name]) => name === "v1")
    .some(([, digest]) => {
      const received = Buffer.from(digest, "hex");
      return received.length === expected.length && crypto.timingSafeEqual(received, expected);
    });
  if (!valid) {
    throw new Error("Invalid Agnost webhook signature");
  }
}
```

```python theme={null}
import base64
import hashlib
import hmac
import time

def verify_agnost_webhook(raw_body: bytes, signature: str, secret: str) -> None:
    parts = [part.split("=", 1) for part in signature.split(",")]
    timestamp = int(dict(parts)["t"])
    if abs(time.time() - timestamp) > 300:
        raise ValueError("Webhook timestamp is outside the five-minute tolerance")

    key = base64.b64decode(secret.removeprefix("whsec_"))
    expected = hmac.new(key, str(timestamp).encode() + b"." + raw_body, hashlib.sha256).hexdigest()
    if not any(name == "v1" and hmac.compare_digest(expected, digest) for name, digest in parts):
        raise ValueError("Invalid Agnost webhook signature")
```

## If a secret leaks

Delete the webhook and add it again. The new webhook gets a new secret, and the
old one stops working immediately. Update the alerts that used it.

With a signed-in session (API keys can't), `POST /dashboard/api/connections/{id}/rotate-secret` with
`{"previous_secret": "expire"}` issues a new secret for the same webhook and
stops the old one immediately, so alerts keep sending to it. With `keep` (the
default), the old secret also signs for 24 hours while your receiver switches
over.

## Headers for receiver credentials

Add headers such as `Authorization` or `x-sn-apikey` under **Headers**.
Header values are encrypted at rest and write-only: the dashboard and API show
only a masked preview, and the delivery log masks them too. To change a value,
type a new one; leave it as is to keep the saved value. Agnost-managed headers
(`Content-Type`, `User-Agent`, `Agnost-*`, and `webhook-*`) cannot be set.

## Delivery and history

Agnost sends each event once, as soon as the alert fires, and waits up to 15
seconds for a response. Any `2xx` response counts as delivered. A timeout,
connection error, or any other status is recorded as failed and isn't retried;
the alert sends again the next time it fires.

The webhook's **Deliveries** tab lists the latest 50 messages sent to it in the
past 30 days: which alert sent it, when, and whether it was delivered. A failed
delivery shows why, for example `HTTP 503` with the start of your receiver's
reply, a timeout, or a TLS error. Filter to **Failed** to find what needs
attention. The same results appear in each alert's history. Test sends
(**Test webhook** and **Send test**) show their result right away and aren't
kept.

## Network restrictions

Production webhook URLs must use HTTPS on port 443 or 8443. Agnost refuses URL
credentials, redirects, and hosts that resolve to private, loopback,
link-local, carrier-grade NAT, or cloud metadata addresses. Agnost connects to
the validated resolved IP so a DNS change cannot redirect the request to an
internal address.

These restrictions apply again on every delivery, not only when the connection
is created.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.