# Splunk On-Call

A `splunk-oncall` notification endpoint sends each Insights alert to [Splunk On-Call](https://help.splunk.com/en/splunk-cloud-platform/alert-and-respond/splunk-on-call/) (formerly VictorOps) through its [REST endpoint integration](https://help.splunk.com/en/splunk-cloud-platform/alert-and-respond/splunk-on-call/integrations-with-splunk-on-call/rest-endpoint-integration-for-splunk-on-call). On-Call's routing keys, escalation policies and rules decide who is paged; Insights keeps no On-Call state of its own.

## Configuration

```
notifications:

  splunk-oncall:

    - name: "on-call"

      api-key: "${SPLUNK_ONCALL_KEY}"

      routing-key: "nats-platform"

      subscriptions: ["*"]

      severities: [warning, critical]
```

* **`api-key`** (required): the REST endpoint integration's key. In On-Call, enable the REST endpoint under *Integrations* and copy the key from the URL it shows. `${NAME}` reads it from the environment; see [Secrets from the environment](/insights/1.3/guides/notifications.md#secrets-from-the-environment).
* **`routing-key`** (required): a routing key defined in On-Call, which picks the team and escalation policy. `${NAME}` reads it from the environment too, so one config can route each environment to its own team.
* **`url`**: the public On-Call endpoint by default. Set it only to send through a proxy or a different region. The keys are appended to its path, so it takes no query or fragment.
* **`auth-type`** is not accepted: the key in the URL path authenticates the request.

Every other field is the same as for any endpoint type; see [Notifications → Configuration](/insights/1.3/guides/notifications.md#configuration). Both keys go in the request URL path, so the integrations page and the delivery log show the base URL and the routing key, never the api-key.

## What Insights sends

One `POST` per alert, as JSON:

| Field                            | Value                                                                                                                                                                                                                                                                                                                   |
| -------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `message_type`                   | `CRITICAL`, `WARNING` or `INFO` by the alert's severity; `RECOVERY` when it resolves                                                                                                                                                                                                                                    |
| `entity_id`                      | The alert's fingerprint, a hash of its labels                                                                                                                                                                                                                                                                           |
| `entity_display_name`            | `<check name>: <entity> (<system>)`                                                                                                                                                                                                                                                                                     |
| `state_message`                  | The check's description and remediation. A recovery says whether the finding cleared or changed severity                                                                                                                                                                                                                |
| `state_start_time`               | When the finding started, or for a recovery when it ended, in seconds since the epoch                                                                                                                                                                                                                                   |
| `monitoring_tool`                | `insights`                                                                                                                                                                                                                                                                                                              |
| `vo_annotate.u.View_in_Insights` | A link to the entity in Insights, shown in the incident's Annotations tab, when `external-url` is set                                                                                                                                                                                                                   |
| every label and annotation       | As top-level fields: `alertname`, `severity`, `system`, `entity_type`, `summary`, `entity_name` and the rest of the [payload labels and annotations](/insights/1.3/guides/notifications.md#payload-labels-and-annotations), plus any [custom ones](/insights/1.3/guides/notifications.md#custom-labels-and-annotations) |

Labels and annotations are top-level fields because that is where On-Call's rules engine matches, so a rule can route on `severity`, `system` or a custom label such as `team`. A custom label or annotation named like one of the fields above would change what the event means: the endpoint's own block is refused such a name at startup, and one from a global `notifications.labels` rule is dropped and logged instead of sent.

### Adding to the annotations tab

On-Call renders a field named `vo_annotate.u.<Title>` as a link, `vo_annotate.s.<Title>` as text and `vo_annotate.i.<Title>` as an image in the incident's Annotations tab, titled by the part after the type letter. A `splunk-oncall` endpoint's own `annotations` block may use these names, and the values are templates like any other annotation:

```
  splunk-oncall:

    - name: "on-call"

      api-key: "${SPLUNK_ONCALL_KEY}"

      routing-key: "nats-platform"

      subscriptions: ["*"]

      annotations:

        vo_annotate.u.Runbook: "https://wiki.example.com/nats/{{ .Code }}"

        vo_annotate.s.Owner: "platform team"
```

The title is letters, digits and underscores. Only this endpoint type accepts the form, and only in its own block: a dotted name is not a valid Alertmanager annotation, so the global `notifications.labels` rules reject it.

## Incident lifecycle

On-Call groups events on `entity_id`, so every event Insights sends for an alert, from its first fire to its recovery, lands on one incident.

* A **`CRITICAL`** event opens an incident, or adds to the open one with the same `entity_id`, and runs the routing key's escalation policy.
* A **`WARNING`** event does the same only when *Create incidents for entities in WARNING state* is on, under On-Call's Settings → Alert Configuration. Otherwise it goes to the timeline without opening an incident or paging.
* A **`RECOVERY`** resolves that incident. A finding that clears sends one for the alert it had firing.
* An **`INFO`** event appears in the timeline without opening an incident or paging. Set `severities: [warning, critical]` to keep info findings out of the timeline altogether.
* A **severity change** is a new alert, because `severity` is a label and so part of the fingerprint. Insights sends a `RECOVERY` for the former severity's `entity_id` first, with `resolve_reason` set to `severity_changed`, and then the new severity's event with `previous_severity` set. On-Call shows the old incident resolved and a new one open.

The `splunk-oncall` type is edge-triggered: an alert is sent when it fires, resolves or changes severity, and never re-sent. A finding that was already firing when the endpoint was added is not sent until it changes state. On-Call never expires an incident, so a `RECOVERY` that never arrives (one still waiting for a retry when Insights restarted) leaves its incident open until someone resolves it by hand. Changing a label rule while an alert fires has the same effect; see [Prefer annotations](/insights/1.3/guides/notifications.md#custom-labels-and-annotations).

## Testing

Use the **Test** button on the endpoint's page in the Insights UI. It sends a synthetic `INFO` event, so it appears in the timeline of the team the routing key names without opening an incident or paging anyone. A wrong `api-key` is rejected by On-Call and shows in the endpoint's delivery log as a `404`.
