# Notifications

Insights can push an alert to an external endpoint whenever a check changes state. Each epoch, every system's findings tracker diffs the current check findings against the previous epoch and delivers the transitions (a check firing, resolving, or changing severity) to any endpoint subscribed to that check code. This turns the checks into an active alerting source rather than something you have to watch in the UI.

The same transitions are published on NATS whether or not any endpoint is configured; see [Finding feed on NATS](#finding-feed-on-nats).

## Endpoint types

Endpoints are declared under one key per type:

* **`webhook`**: receives the full Alertmanager-compatible payload envelope (status, alerts, common labels/annotations). Point this at a generic receiver, a relay, or your own HTTP service.
* **`alertmanager`**: receives a bare alert array compatible with the [Alertmanager v2 `POST /api/v2/alerts`](https://prometheus.io/docs/alerting/latest/clients/) API. Point this straight at an Alertmanager instance.
* **`servicenow`**: receives the `webhook` envelope, plus the `alertmanager` per-minute re-send of every active alert. Point this at a Scripted REST API in your ServiceNow instance; see the [ServiceNow guide](/insights/1.3/guides/servicenow.md).
* **`splunk-oncall`**: receives one Splunk On-Call event per alert through the REST endpoint integration, keyed so a resolve recovers the incident its fire opened; see the [Splunk On-Call guide](/insights/1.3/guides/splunk-oncall.md).
* **`datadog`**: receives one Datadog Events API alert event per alert, which pages a Datadog On-Call team and resolves the page when the finding clears; see the [Datadog guide](/insights/1.3/guides/datadog.md).

All types share the same configuration fields; `servicenow` requires `apikey` or `basic` auth, `splunk-oncall` takes `api-key` and `routing-key` instead of `auth-type`, and `datadog` takes `api-key` and `site`.

## Configuration

Notifications are configured in the YAML config file only; there is no equivalent flag or environment variable. Secrets can still come from the environment; see [Secrets from the environment](#secrets-from-the-environment). Add a `notifications` section:

```
notifications:

  webhook:

    - name: "PagerDuty Relay"        # unique across all endpoints

      url: "https://example.com/webhook"

      enabled: true                  # default true

      auth-type: "bearer"            # "", "basic", "bearer", or "hmac"

      auth-token: "${WEBHOOK_TOKEN}"    # token (bearer), password (basic), or secret (hmac)

      headers:                       # extra request headers (webhook, alertmanager)

        x-tenant: "acme"

      subscriptions: ["server-*", stream-002]   # code patterns this endpoint receives

      ignore: [server-046]                       # patterns dropped after a subscription match

  alertmanager:

    - name: "local-am"

      url: "http://localhost:9093/api/v2/alerts"

      subscriptions: ["*"]

  servicenow:

    - name: "servicenow"

      url: "https://<instance>.service-now.com/api/<namespace>/insights/alerts"

      auth-type: "apikey"            # "apikey" or "basic"

      auth-token: "${SERVICENOW_API_KEY}"  # ServiceNow REST API key

      subscriptions: ["*"]

  splunk-oncall:

    - name: "on-call"

      api-key: "${SPLUNK_ONCALL_KEY}"  # REST endpoint integration key

      routing-key: "nats-platform"     # picks the On-Call team

      subscriptions: ["*"]

  datadog:

    - name: "datadog"

      api-key: "${DD_API_KEY}"         # Datadog API key

      site: "datadoghq.eu"             # defaults to datadoghq.com

      subscriptions: ["*"]

      annotations:

        oncall_team: "nats-platform"   # Datadog On-Call team to page
```

| Field           | Default                                              | Notes                                                                                                                                                                |
| --------------- | ---------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `name`          | (required)                                           | Human-readable; must be unique across every endpoint                                                                                                                 |
| `url`           | (required; `splunk-oncall` and `datadog` default it) | Must be `http` or `https`. `${NAME}` reads environment variable `NAME`. The `splunk-oncall` default is the public On-Call endpoint; `datadog` derives it from `site` |
| `enabled`       | `true`                                               | Set `false` to keep a definition without delivering                                                                                                                  |
| `auth-type`     | (none)                                               | `basic`, `bearer`, or `hmac`; `servicenow` requires `apikey` or `basic`; `splunk-oncall` and `datadog` take none                                                     |
| `auth-user`     | (empty)                                              | Username for `basic` auth                                                                                                                                            |
| `auth-token`    | (empty)                                              | Password (`basic`), token (`bearer`), secret (`hmac`), or API key (`apikey`)                                                                                         |
| `api-key`       | (`splunk-oncall` and `datadog` only)                 | The On-Call REST endpoint key, sent in the URL path, or the Datadog API key, sent as `DD-API-KEY`. `${NAME}` reads environment variable `NAME`                       |
| `routing-key`   | (`splunk-oncall` only)                               | The On-Call routing key, sent in the URL path                                                                                                                        |
| `site`          | `datadoghq.com` (`datadog` only)                     | The Datadog site hostname, as `DD_SITE` spells it; picks the url. `${NAME}` reads environment variable `NAME`                                                        |
| `headers`       | (empty; `webhook` and `alertmanager` only)           | Extra request headers, as a name-to-value map of quoted strings; see [Custom headers](#custom-headers). `${NAME}` in a value reads environment variable `NAME`       |
| `subscriptions` | (empty)                                              | Check-code patterns to deliver; see the Checks Reference                                                                                                             |
| `ignore`        | (empty)                                              | Patterns dropped after a subscription match; carves exceptions out of a wildcard                                                                                     |
| `systems`       | (empty)                                              | Selectors for the systems to deliver for, by id or by label; see [Scoping to systems](#scoping-to-systems). Empty delivers for **every** system on the node          |
| `severities`    | (empty)                                              | Severities to deliver: `info`, `warning`, `critical`. Empty delivers every severity; see [Filtering by severity](#filtering-by-severity)                             |
| `labels`        | (empty)                                              | Labels added to this endpoint's alerts; see [Custom labels and annotations](#custom-labels-and-annotations)                                                          |
| `annotations`   | (empty)                                              | Annotations (templated) added to this endpoint's alerts                                                                                                              |

### Patterns

`subscriptions` and `ignore` each take a list of check-code patterns: an exact code (`server-001`), a trailing-wildcard prefix (`server-*`), or `*` for every code. Codes are lowercase and hyphenated, and `*` is only allowed as the last character. `ignore` is applied after `subscriptions`. An empty `subscriptions` list delivers nothing: subscribing is explicit. A pattern that matches no known check code fails startup, so a typo can't silently deliver nothing; an uppercase, underscored pattern (`SERVER_001`, `SERVER_*`) fails with its current spelling in the error. An exact code of a retired check is accepted with a warning and delivers nothing. The endpoint's detail page in the UI expands each pattern into the checks it resolves to.

### Scoping to systems

On a node serving several systems, `systems` restricts an endpoint to a subset; everything else still delivers everywhere. Note it is the inverse of `subscriptions`: an empty `subscriptions` delivers nothing (subscribing to a check is explicit), but an empty `systems` delivers for every system the node owns or acts for as a [remote system](/insights/1.3/guides/federated-deployment.md#notifications-from-the-hub).

Each entry is a selector over a system's labels, and the endpoint delivers for a system any one selector matches:

```
systems:

  - { env: prod, region: "us-*" }   # every key must match

  - { id: "ship-*" }                # id matches the system id

  - west                            # shorthand for { id: west }
```

* A value is exact, or a glob in which `*` matches any run of characters. `"*"` alone matches a system that has the label with any value. Quote a value that starts with `*`, or YAML reads it as an alias.
* `id` matches the system id, not a label.
* Selectors match the system's labels, never the node's (`node.metadata`).

The labels a selector matches depend on where the system's findings come from:

* A system this node scrapes: the labels this node's config gives it, `systems[].metadata` over `system.metadata`.
* A collector-fed system this node indexes: the labels stored with its binding in the `remotes` bucket, the collector's own `system.metadata` as it reported it when this node took the system on, over this node's `system.metadata`. An entry a 1.3 release candidate bound from a node's `systems:` list stores none; the node takes the system on once it hears the collector, and stores the labels it reports then.
* A remote system: the labels its nodes report when it is asked about on `$INS.sys.<id>.ping`, which this node asks again whenever the system's heartbeat says they changed. They're read each time this node starts following the system, after every gap, and when the system is described with other labels. Alerts the endpoint holds for a system whose labels no longer match are resolved then, and an endpoint the system now matches is sent its current alerts. Until this node has read a system's labels once, it does not read the system at all if any endpoint or label rule selects systems by label, since it could not tell which endpoints its alerts belong to; it retries, logging `read the remote system's labels`. Later, a system that does not answer keeps the labels last read.

A selector that matches no system is valid, since a system can arrive while the node runs. A plain id naming a system this node does not own logs a warning at startup, since it is most often a typo. On a node with a `remotes:` block, an id `remotes.accept` could take on is not warned of, since it may name a remote system the node has yet to hear.

### Filtering by severity

`severities: [critical]` limits an endpoint to critical findings, which a code list can't do: a check with a dynamic severity fires as warning and escalates to critical under one code. A finding whose severity moves out of the list is delivered as a resolve for the alert the endpoint holds, so nothing is left firing at the receiver; one moving into the list fires at the new severity. A `webhook`, `servicenow`, `splunk-oncall` or `datadog` endpoint gets the usual severity-change pair (a resolve marked `severity_changed` and a firing alert with `previous_severity`) only when both the old and the new severity are in the list. Otherwise it gets a plain firing alert or a plain resolve, and a plain resolve looks the same to the receiver as the finding clearing. Narrowing the list across a restart resolves what a `webhook`, `splunk-oncall` or `datadog` receiver holds at a severity the endpoint no longer delivers, as removing a subscription does (see [Restarts](#restarts)); the heartbeat types expire it. A filtered-out finding is also left out of the Alertmanager and ServiceNow re-send.

### Authentication

`basic` sends an `Authorization: Basic` header from `auth-user`/`auth-token`; `bearer` sends `Authorization: Bearer <auth-token>`; `hmac` signs the request body with HMAC-SHA256 keyed by `auth-token` and sends `X-Hub-Signature-256: sha256=<hex digest>`; `apikey` (`servicenow` only) sends `auth-token` as ServiceNow's `x-sn-apikey` header. A `splunk-oncall` endpoint takes no `auth-type`: its `api-key` and `routing-key` go in the URL path, which is how On-Call authenticates. A `datadog` endpoint takes none either: its `api-key` goes in the `DD-API-KEY` header.

### Custom headers

A receiver behind an API gateway or an in-house API often needs headers of its own, such as an API key under a name no `auth-type` sends, or a tenant or routing header. `headers` on a `webhook` or `alertmanager` endpoint adds them to every request, for example the `X-Scope-OrgID` tenant header a multi-tenant Alertmanager such as Grafana Mimir reads:

```
notifications:

  webhook:

    - name: "gateway"

      url: "https://api.example.com/insights/alerts"

      headers:

        x-api-key: "${GATEWAY_API_KEY}"

        x-tenant: "nats-platform"

      subscriptions: ["*"]

  alertmanager:

    - name: "mimir"

      url: "https://mimir.example.com/alertmanager/api/v2/alerts"

      headers:

        X-Scope-OrgID: "nats-platform"

      subscriptions: ["*"]
```

Quote every value: YAML reads an unquoted `2`, `true` or `2023-06-01` as a number, boolean or date, which startup refuses rather than send in a converted form. A header is sent alongside `auth-type`'s, never in place of it, so `headers` cannot name `Content-Type`, nor a connection header Go's HTTP client sets, drops or refuses (`Content-Length`, `Host`, `Transfer-Encoding`, `Connection`, `Upgrade`, `Keep-Alive`, `Proxy-Connection`, `Te`, `Trailer`), nor the header the endpoint's `auth-type` sets (`Authorization` for `basic` and `bearer`, `X-Hub-Signature-256` for `hmac`). Names are case-insensitive, so two spellings of one name are refused too. With no `auth-type`, `Authorization` is free for a scheme of the receiver's own. Values are often secrets: they read `${NAME}` from the environment like `auth-token`, and the integrations page lists only the header names.

### Secrets from the environment

`url`, `auth-user`, `auth-token`, `api-key`, `routing-key`, `site` and `headers` values expand `${NAME}` to the value of environment variable `NAME` at startup, so the config file can be checked in or templated without the secret in it. That covers a webhook URL that embeds a token in its path. Only the braced form expands; a bare `$` is kept literally, and no other field is expanded. The integrations page, logs and delivery errors show the URL as written, with the reference unexpanded and any `user:password@` password masked. A network error (a failed DNS lookup or connection) can still name the resolved host, so keep a secret in the path or query rather than the hostname. Leading and trailing whitespace in the value is trimmed, so a Secret file ending in a newline works. A referenced variable that is unset or empty fails startup (and `insights config check`), naming the endpoint and the variable. A disabled endpoint (`enabled: false`) is exempt, so it can stay in a config shared with an environment that lacks its secret; its test delivery on the integrations page reports the missing variable instead of sending. On Kubernetes, map a Secret key to the variable with the Helm chart's `extraEnv` and `secretKeyRef`.

### Delivery timing is fixed

Each delivery uses a 10s request timeout and makes up to 3 attempts with exponential backoff; a client error (4xx other than 429) ends that attempt set at once. Redirects are not followed, so a 3xx response also ends it: set `url` to the address that accepts the POST, not one that redirects to it. A delivery whose attempts all fail is then retried as a batch, as described below.

### Delivery never blocks ingest

Each endpoint has its own delivery worker, so transitions are posted off the scrape path and one endpoint that accepts the connection and then hangs can never stall indexing or delay any other endpoint. While a receiver is slow or down, that endpoint's pending transitions are coalesced per finding (the latest state of each finding is kept), so its backlog is bounded by the number of findings, not by how long the receiver is unavailable, and no finding's current state is lost. A receiver that recovers sees each finding's net state; intermediate flapping (a fire and resolve while it was behind) collapses to the final state rather than replaying every edge, and a fire that resolved before it was ever delivered is dropped rather than sent as a lone resolve.

A failed delivery is retried for that endpoint alone, on an exponential backoff (starting at 2s, capped at once a minute), until it succeeds. A down receiver never causes duplicate deliveries to healthy endpoints. This applies to every failure, a 4xx response included: a receiver that rejects the payload keeps receiving the same batch once a minute until it accepts it, and transitions that arrive meanwhile wait behind that batch. The endpoint's delivery log shows the rejection. Retry re-sends the coalesced batch, so delivery to a given endpoint is at-least-once: a receiver may occasionally see a transition again if the connection dropped after it had already processed the request.

### Validation is strict

Every endpoint is checked at startup, disabled ones included. A missing `name` or `url`, a URL that is not `http`/`https` or has no host, a duplicate `name`, an unknown `auth-type` (or none on a `servicenow` endpoint, or any on a `splunk-oncall` or `datadog` one), a `splunk-oncall` endpoint without `api-key` or `routing-key`, a `datadog` endpoint without `api-key`, with a `site` outside Datadog's domains, or with an `oncall_team` that is not a team handle, a `headers` entry on a type other than `webhook` or `alertmanager`, naming a header delivery or `auth-type` sets, or with an invalid name or an unquoted, empty or multi-line value, a subscription or ignore pattern that matches no check, an unknown `severities` value, or a `systems` selector with an empty entry or an invalid key or value fails startup with an error naming the entry rather than being silently dropped, so you can't believe alerting is on while nothing is delivered. `insights config check` runs the same validation without starting the node.

### Subscribing to a disabled check delivers nothing

A check listed in `disabled-checks` keeps running, but its findings never enter the findings tracker, so nothing is delivered or published on the finding feed for it: not a fire, not a resolve, and nothing on the standing re-send. Turning a check off does not send a resolve for anything it had firing. The subscription is not an error; the Notifications page marks it as disabled so the silence is not mistaken for health.

### Payload links

Each alert's `generatorURL` opens the finding's own page in the web UI, `/systems/<system>/findings/<code>/<entity_type>/<entity_pk>[/<entity_key>]` (`entity_pk` is `0` for a system-scoped finding), which says whether it is still firing, since when, and shows its evidence. A finding that has since resolved opens at the last epoch it fired. Appending `?epoch=<RFC 3339 time>` pins the page to that time instead, as the time controls would. `system-012` keeps no history, so its page says only whether it is firing now, wherever the page is pinned. A hub's `system-012` for a system no node serves, a collector no hub has taken on or a remote system whose node is down or cut off, links to the same address: the page reads the finding and its `detail` from the hub, and says so when nothing answers for the system. Set `--web.external-url` on the node delivering notifications to the public base URL of the web UI that serves the system; without it `generatorURL` is empty. The same link is carried on the [finding feed](#finding-feed-on-nats) as `url`.

## Payload labels and annotations

Each alert carries a set of Alertmanager-style labels (for routing and grouping) and annotations (human-readable context). Labels use unprefixed, generic names so they compose with your existing Alertmanager relabeling.

| Label         | Always present          | Value                                                                                                                                                                                                                                                                                                                                                      |
| ------------- | ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `alertname`   | yes                     | The check code, e.g. `server-001`                                                                                                                                                                                                                                                                                                                          |
| `severity`    | yes                     | `info`, `warning`, or `critical`                                                                                                                                                                                                                                                                                                                           |
| `entity_type` | yes                     | The kind of entity the finding is about, e.g. `server`, `stream`                                                                                                                                                                                                                                                                                           |
| `source`      | yes                     | Always `insights`                                                                                                                                                                                                                                                                                                                                          |
| `system`      | yes                     | The id of the system the finding came from, the same id shown in the UI. Route or group on this to fan alerts out per system.                                                                                                                                                                                                                              |
| `scope`       | when the check is known | The check's scope                                                                                                                                                                                                                                                                                                                                          |
| `category`    | when the check is known | The check's category                                                                                                                                                                                                                                                                                                                                       |
| `entity_key`  | when non-empty          | A secondary NATS name that disambiguates the finding: service name, remote server name, or Raft group name; empty for most entity types                                                                                                                                                                                                                    |
| `entity_pk`   | when non-zero           | This instance's internal id for the entity. It keeps findings on different entities distinct. Without it, two entities that share a scope and name (e.g. the same check firing on two clusters) would produce identical label sets and collapse into one alert. Instance-scoped and not stable across restarts, so don't use it as a durable external key. |

In the `webhook` envelope, `commonLabels` and `commonAnnotations` hold the pairs every alert in the delivery shares, as Alertmanager computes them, so a configured label like `env` shows up there too. `commonLabels` always includes `source` and `system`. `groupLabels` is always `source` and `system`, since one delivery only ever spans a single system.

| Annotation          | Present                                                                                      | Value                                                                                                                                                                                                              |
| ------------------- | -------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `entity_name`       | when non-empty                                                                               | The resolved human-readable entity name                                                                                                                                                                            |
| `detail`            | for a check the node evaluates itself                                                        | What it fired on, such as `system-012`'s scrape error                                                                                                                                                              |
| `summary`           | when the check is known                                                                      | The check's display name                                                                                                                                                                                           |
| `description`       | when the check is known                                                                      | What the check evaluates                                                                                                                                                                                           |
| `remediation`       | when non-empty                                                                               | Suggested remediation                                                                                                                                                                                              |
| `previous_severity` | `webhook`, `servicenow`, `splunk-oncall` and `datadog`, on a severity change's firing alert  | The severity the finding moved from                                                                                                                                                                                |
| `resolve_reason`    | `webhook`, `servicenow`, `splunk-oncall` and `datadog`, on the resolve for a former severity | `severity_changed`: the finding is still up at a new severity, not cleared                                                                                                                                         |
| `data_as_of`        | `alertmanager` and `servicenow`, on a re-send for a remote system that is out of reach       | About when the hub node last heard from the system, in RFC 3339: the alert is the last state known then. See [Notifications from the hub](/insights/1.3/guides/federated-deployment.md#notifications-from-the-hub) |

Each `webhook` and `servicenow` alert also carries a `fingerprint`: a hash of its labels, computed the same way Alertmanager computes it, so a receiver can tie a resolve to the alert it fired without hashing the labels itself. A `splunk-oncall` event carries the same hash as its `entity_id`, with the labels and annotations as top-level fields; see [What Insights sends](/insights/1.3/guides/splunk-oncall.md#what-insights-sends). A `datadog` event carries it in its custom attributes, with the labels as tags; its `aggregation_key` also hashes the endpoint, so it does not match the fingerprint. See [What Insights sends](/insights/1.3/guides/datadog.md#what-insights-sends).

## Custom labels and annotations

You can add your own labels and annotations (an `env`, a `team`, a runbook link) so routing and enrichment happen before the alert leaves Insights. They come from two places, applied in this order:

1. **Rules** under `notifications.labels`, applied to every endpoint's alerts. Each rule has a `match` and the `labels` and/or `annotations` to add. Rules apply in order; a later rule overrides a key an earlier one set.
2. **An endpoint's own** `labels` and `annotations` block, applied last, so it wins over the rules for the same key.

```
notifications:

  labels:

    - match: {}                                   # every alert

      labels: {env: prod}

    - match: {checks: ["stream-*"], severity: [critical]}

      labels: {team: data-platform}

      annotations: {runbook: "https://wiki/insights/{{ .Code }}"}

    - match: {entity-type: [stream], entity-name: ["ORDERS*"]}

      annotations: {owner: orders-team}           # annotations only; see below

  alertmanager:

    - name: "local-am"

      url: "http://localhost:9093/api/v2/alerts"

      subscriptions: ["*"]

      labels: {receiver: local}
```

A `match` selects alerts. Every field you set must match; within a field, any listed value matches. An empty `match` selects every alert.

| Match field   | Values                                                                                     |
| ------------- | ------------------------------------------------------------------------------------------ |
| `checks`      | Check-code patterns, same grammar as `subscriptions`                                       |
| `severity`    | `info`, `warning`, `critical`                                                              |
| `category`    | The check's category (the `category` label)                                                |
| `scope`       | The check's scope (the `scope` label)                                                      |
| `systems`     | Selectors over the system id and labels, as an endpoint's [`systems`](#scoping-to-systems) |
| `entity-type` | The `entity_type` label, e.g. `server`, `stream`, `kvstore`                                |
| `entity-name` | Entity-name globs; `*` matches any run of characters                                       |

**Annotation values are templates** ([Go `text/template`](https://pkg.go.dev/text/template)) with these fields: `.Code`, `.Severity`, `.Scope`, `.Category`, `.System`, `.EntityType`, `.EntityKey`, `.EntityName`, `.EntityPK`. Label values are plain strings. Values must be strings, so quote anything YAML would read as a number or boolean (`priority: "1"`, `page: "true"`).

**Prefer annotations; keep labels for routing.** Labels are part of an alert's identity at the receiver (its fingerprint). Changing a label rule while an alert is firing makes the receiver see a new alert. Alertmanager drops the old one at its `endsAt`, and so does a `servicenow` receiver that follows the [receiver contract](/insights/1.3/guides/servicenow.md#receiver-contract); a `webhook` receiver keyed on `fingerprint`, an On-Call incident keyed on `entity_id`, or a Datadog On-Call page keyed on `aggregation_key`, never sees it resolve, so it has to be cleared by hand. Put descriptive values (owners, links, notes) in annotations, which can change freely. A rule that matches on `severity` changes labels when the severity changes. That's the same as the built-in `severity` label, so every endpoint gets the same resolve for the former severity.

**Matching on the entity name sets annotations only.** Entities are matched by name rather than by `entity_key`, because `entity_key` is empty for most entity types. The name resolves after a finding first appears, so a label set by a name match could change an alert's identity mid-flight. A rule with `entity-name` that sets `labels` fails startup.

**Selecting systems by label sets annotations only.** A rule whose `match.systems` names a label rather than an `id` may set annotations but not labels. A remote system's labels can change while its alerts fire, and a label added by such a rule would then change the alert's identity, so its resolve would close nothing.

**Validation.** Startup fails on any of these:

* a built-in label or annotation name (the ones in the tables above), or on a `splunk-oncall` endpoint one of [On-Call's own fields](/insights/1.3/guides/splunk-oncall.md#what-insights-sends)
* a name outside `[a-zA-Z_][a-zA-Z0-9_]*`, or one starting with `__`; a `splunk-oncall` endpoint's own block may also name [On-Call annotations](/insights/1.3/guides/splunk-oncall.md#adding-to-the-annotations-tab)
* a `checks` pattern that matches no check
* an unknown `severity`, `scope`, `category` or `entity-type` value
* an empty `entity-name` pattern
* a rule that sets no labels or annotations
* a rule whose `systems` selects by label that sets `labels`
* a `systems` selector that is empty or has an invalid key or value
* a template that doesn't parse or names an unknown field
* a templated label value, or an empty one (Alertmanager treats an empty label as absent)

The same holds for an endpoint's own block.

## Delivery cadence

Transitions (a check firing, resolving, or changing severity) are queued for delivery the moment an epoch commits. A severity change is delivered as a firing alert at the new severity. Because `severity` is a label, that is a new alert, and the former severity is handled per type:

* **`webhook`**, **`servicenow`**, **`splunk-oncall`** and **`datadog`** endpoints also receive a resolve for the former severity in the same delivery, ahead of the new firing alert. The firing alert carries a `previous_severity` annotation and the resolve a `resolve_reason` of `severity_changed`, so a receiver can present the pair as an escalation or de-escalation rather than a recovery.
* **`alertmanager`** endpoints receive no resolve for the former severity. It drops out of the per-minute re-send and expires at its last `endsAt`, at most four minutes later, so both severities fire until then. To show only one, add an [inhibit rule](https://prometheus.io/docs/alerting/latest/configuration/#inhibit_rule) with `equal: [alertname, system, entity_type, entity_pk, entity_key]`, the labels that identify one finding. When a finding clears, the resolve is sent at every severity.

Alertmanager and ServiceNow endpoints also receive the full active set re-sent on a fixed wall-clock cadence (every minute, and once immediately at startup), each firing alert carrying a rolling `endsAt` four minutes ahead. Alertmanager holds an alert while it keeps arriving and auto-resolves it once Insights stops re-sending; a ServiceNow receiver must do the same (see the [ServiceNow guide](/insights/1.3/guides/servicenow.md#receiver-contract)). Because the re-send runs on a clock rather than on scrape epochs, delivery does not stop when scrapes do. Webhook, Splunk On-Call and Datadog endpoints are edge-triggered and receive no re-send.

An alert's `startsAt` is the first epoch of the finding's current unbroken run, read from the check history, so a standing finding keeps its real start across restarts.

### Restarts

A `webhook`, `splunk-oncall` or `datadog` receiver never expires an alert, so the node records, for each such endpoint, the alerts its receiver may hold. An alert is recorded before it is sent, confirmed once the receiver accepts it, marked again before its resolve is sent, and removed once the receiver accepts the resolve.

After a restart, once the node has read its findings back from the catalog, it compares each endpoint's record with what is firing and sends the difference: a resolve for an alert that cleared while the node was down, however long that was, a fire for one that started, and a severity change. A finding that fired and cleared while the node was down sends nothing. A finding the endpoint's subscriptions, ignore list, severities or systems no longer match is resolved. This runs on the first minute tick after the catalog is read; until then the node sends these endpoints nothing for that system, and the comparison covers what changed in between.

A delivery the restart interrupted is sent again, so a receiver can get an alert twice but is never left holding one nothing will clear. An endpoint with no record, because it is new or was configured before the record existed, receives every current fire once. The record is keyed by the endpoint's `name`, so renaming an endpoint does the same, and nothing resolves what its receiver held under the old name; the old name's record stays in the stream, as does a removed endpoint's.

Nodes on one JetStream domain share the record, so a node that takes over a [remote system](/insights/1.3/guides/federated-deployment.md#one-hub-node-per-remote-system) from another starts from what that node left each receiver holding. Nodes may define different endpoints, but one `name` must mean the same receiver on every node that shares the record. Nothing checks this: a name pointing at two receivers makes one node resolve or skip alerts the other's receiver holds.

## The notifications page in the UI

Each system has a Notifications page in the web UI. It lists the endpoints that deliver for that system, with each one's type, the number of checks its patterns select, and its last delivery for the system. Each endpoint's detail page covers that system alone. It shows delivery stats over what the log keeps (deliveries, failures, success rate, last successful delivery and p95 duration), the alerts the receiver holds open, each linked to its finding, its configuration, the checks its patterns resolve to (each linked to the check, marking any that are disabled), the label rules and its own labels and annotations in the order they apply (marking a rule whose `systems` miss the system or whose `checks` miss everything the endpoint delivers), and the delivery log. Open alerts are recorded only for `webhook`, `splunk-oncall` and `datadog` endpoints, and only a node that delivers keeps the records, so a node that only serves the web UI shows none. Routine `alertmanager` and `servicenow` re-sends are logged only when they fail, so their success rate understates. The detail page's **Test** button delivers a synthetic firing alert to the endpoint and reports the result inline, so you can confirm connectivity and auth end to end without waiting for a real check to change state. Endpoints themselves are managed exclusively through the config file (see above); the page is read-only apart from sending a test.

## Verifying a delivery locally

Run a local Alertmanager as a receiver, start Insights with the config above, and trigger a test delivery:

```
docker run --rm -p 9093:9093 prom/alertmanager   # a local receiver

insights serve -c config.yaml                     # start Insights

# → Notifications UI → "local-am" → Test

#   a firing alert appears in Alertmanager at http://localhost:9093
```

## Finding feed on NATS

Every transition is also published as a core NATS message, per system, on:

```
$INS.sys.<id>.feed.finding.<status>.<severity>.<code>
```

`status` is `firing`, `resolved`, or `changed` (a severity move while the finding stays up), `severity` is `info`, `warning`, or `critical`, and `code` is the check code. The tokens are in the subject so a subscriber filters server-side:

```
nats sub '$INS.sys.prod.feed.finding.firing.critical.>'   # everything newly critical

nats sub '$INS.sys.prod.feed.finding.*.*.stream-002'       # one check, every transition
```

The JSON payload names the `system`, the check and entity (`code`, `entity_type`, `entity_pk`, `entity_key`, `entity_name`), the `status` and `severity`, `prev_severity` on a `changed`, `starts_at`, `ends_at` on a resolve, `detail` for a check the node evaluates itself (what it fired on, such as `system-012`'s scrape error), and the finding's page as `url` when [payload links](#payload-links) are configured. The feed is fire-and-forget: there is no reply, no queue group, and nothing is stored, so a subscriber that is not connected misses what was published meanwhile. To start from what is firing now, subscribe first and hold what arrives, then read the standing set from `findings.active`, in the same shape, and apply what was held over it in order, skipping a change whose `epoch` is earlier than the set's. A change the standing set already reflects alters nothing when applied again, and one published while the read was under way is not lost. `findings.summary` says how many are firing without listing them:

```
nats sub '$INS.sys.*.feed.finding.>'                       # first: every change, every system, held

nats req '$INS.sys.prod.findings.summary' ''               # how many are firing, per check
```

The feed is published regardless of the `notifications` section, and disabled checks are left out of it. A subscriber needs only subscribe permission on `$INS.sys.<id>.feed.finding.>`, plus publish permission on `$INS.sys.<id>.findings.summary` and `$INS.sys.<id>.findings.active` to read the standing set. See the API reference for the subject space.

## Delivery log and NATS permissions

Endpoint configuration is held in memory, read from the config file at startup. Only the delivery log is stored in JetStream: a stream named `webhook-deliveries`, shared by every node on the JetStream domain, on subjects `$INS.sys.<system>.webhook.delivery.<domain>.<endpoint_id>`, where `<domain>` is the sink's JetStream domain, or `_` without one, and `<endpoint_id>` is derived from the endpoint's `name`. It keeps the last `notifications.delivery-history` deliveries (default 256) per system per endpoint for up to 7 days, each naming the node that delivered it, so an endpoint's log reads the same from any node, one that only serves the web UI included, and a remote system that moves keeps its history. Removing a remote system leaves its entries to age out. The stream is created on the sink connection, with `sink.replicas` replicas, when at least one endpoint is configured on a node that holds a catalog or serves the web UI. Each node reconciles the stream's replicas and delivery history on start, so the last node to start sets both; give every node the same values. An endpoint's page reads every entry kept for that endpoint and the page's system before it paginates, so a page view reads up to `delivery-history` entries. On its first start after an upgrade, a node moves the entries of the per-node stream earlier releases kept, `webhook-deliveries_<node_id>`, into the shared one and deletes it. Of a system an earlier-upgraded node has since delivered to the same endpoint, only entries newer than its last one are moved. Without JetStream, delivery continues and only the history is lost; the endpoint page says the log is unavailable. A node that cannot create the stream delivers without it and tries again every minute. Routine Alertmanager re-sends are logged only when they fail.

A node that holds a catalog also records the alerts each `webhook`, `splunk-oncall` and `datadog` receiver may hold (see [Restarts](#restarts)) in a stream named `webhook-open`, on subjects `$INS.sys.<system>.webhook.open.<domain>.<endpoint_id>.<finding>`, where `<domain>` is the sink's JetStream domain, or `_` without one. Every node on the domain shares the stream, and only the node delivering a system writes its records. It has `sink.replicas` replicas, so give every node on the domain the same value: each scales the stream to its own when it starts. It keeps one message per alert and no age limit, so its size follows the alerts receivers hold. Without it, delivery continues but a restart cannot recover what a receiver missed; a node that cannot create it tries again every minute.

The stream's required grants are documented with the rest of the sink connection's permissions in the [Deployment guide](/insights/1.3/guides/deployment.md#sink-connection-permissions). This matters only against an external sink with a least-privilege user; the default embedded sink needs no grants.
