# Any tool (JSON)

> Turn JSON from Grafana, Alertmanager, Datadog, Home Assistant or your own scripts into pushes, with templates and field mapping.

The generic webhook works with any tool that can send JSON to a URL: Grafana, Prometheus Alertmanager, Datadog, Zabbix, Home Assistant, Jenkins, or a script you wrote. You tell Opush which JSON fields hold the title, the message and the link, and every request becomes a push.

## Set it up [#set-it-up]

1. In the app or the web console, add a service integration and pick **Any tool (JSON)**.
2. Pick a **Template** that matches your tool: Generic JSON, Prometheus Alertmanager, Grafana or Datadog.
3. Create it. Copy the **Payload URL** and the **Token**.
4. In your tool, add a webhook (or HTTP notification) that sends JSON to the payload URL with `POST`.
5. Add the header `Authorization: Bearer YOUR_TOKEN`. If the tool can't set headers, use **URL with token** instead. It's the payload URL with `?token=YOUR_TOKEN` at the end.
6. Send a test from the tool.

Opush accepts the token in any of these places:

```http
Authorization: Bearer YOUR_TOKEN
X-Opush-Token: YOUR_TOKEN
https://opu.sh/v1/hooks/YOUR_HOOK_ID?token=YOUR_TOKEN
```

## Try it with curl [#try-it-with-curl]

With the Generic JSON template:

```bash
curl -X POST "https://opu.sh/v1/hooks/YOUR_HOOK_ID" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"title":"Backup failed","message":"pg_dump exited 1","status":"firing","severity":"critical"}'
```

You get a time-sensitive push:

```text
Webhook
🔴 Backup failed
pg_dump exited 1
```

The push title is the integration's name. If you didn't name it, it's the template's name ("Webhook", "Alertmanager", "Grafana" or "Datadog"). Opush doesn't translate these pushes. They show in the language your tool sends.

## What goes into the push [#what-goes-into-the-push]

Opush reads six fields from your JSON:

| Field | Used for |
|---|---|
| Title | The main line of the push |
| Message | The text under it |
| Link | Opened when you tap the push (only `http` and `https` links) |
| Status | `firing` adds 🔴, `resolved` adds ✅ |
| Severity | High severity makes the push time-sensitive |
| Event ID | Stops duplicates |

If Opush finds neither a title nor a message, nothing is pushed. Opush still answers `200` with `"ignored": true`.

If the body isn't JSON, the whole body (up to 500 characters) becomes the message. So even plain text works:

```bash
curl -X POST "https://opu.sh/v1/hooks/YOUR_HOOK_ID?token=YOUR_TOKEN" -d "disk almost full"
```

### Status [#status]

These values count as **firing**: `firing`, `alerting`, `alert`, `triggered`, `trigger`, `problem`, `error`, `critical`, `down`, `failed`, `failure`, `open`, `active`.

These count as **resolved**: `resolved`, `ok`, `recovered`, `recovery`, `up`, `success`, `succeeded`, `closed`, `normal`, `inactive`.

Case doesn't matter. Other values are kept but get no symbol.

### Severity [#severity]

These values make the push time-sensitive, unless the status is resolved: `critical`, `crit`, `high`, `error`, `fatal`, `emergency`, `page`, `p1`, `p2`, `disaster`, `major`.

### Duplicates [#duplicates]

If the same Event ID arrives twice, you get one push. Without an Event ID, Opush uses a hash of the body, so a tool that resends the exact same request won't push twice.

## Field mapping [#field-mapping]

Each template is a set of rules, one per field. On the integration's page, under **Fields**, you can change any rule. Leave a field empty to use the template's rule.

- `{{path}}` reads a value. Use dots for objects and `[0]` for list items: `{{alerts[0].labels.severity}}`. `{{alerts.0.labels.severity}}` works too.
- `{{a|b|c}}` uses the first one that has a value.
- Text outside the braces is kept as is: `{{host}} is down`.
- If none of the `{{…}}` in a rule find a value, the field is left out.
- Each field is cut to 500 characters.

For example, Home Assistant can send:

```json
{ "entity": "Front door", "new_state": { "state": "open", "last_changed": "10:02" }, "priority": "high" }
```

With these rules:

| Field | Rule |
|---|---|
| Title | `{{entity}} is {{new_state.state}}` |
| Message | `Changed at {{new_state.last_changed}}` |
| Severity | `{{priority}}` |

You get "Front door is open" with "Changed at 10:02", as a time-sensitive push.

## Templates [#templates]

<Tabs items={["Generic JSON", "Alertmanager", "Grafana", "Datadog"]}>
<Tab value="Generic JSON">

Reads common field names:

| Field | Rule |
|---|---|
| Title | `{{title\|subject\|name\|alertname\|event}}` |
| Message | `{{message\|body\|text\|description\|msg\|summary}}` |
| Link | `{{url\|link\|href}}` |
| Status | `{{status\|state}}` |
| Severity | `{{level\|severity\|priority}}` |
| Event ID | `{{id\|event_id\|uuid}}` |

Good for your own scripts and for tools whose JSON you can shape yourself.

</Tab>
<Tab value="Alertmanager">

Add a receiver to your Alertmanager config:

```yaml
receivers:
  - name: opush
    webhook_configs:
      - url: https://opu.sh/v1/hooks/YOUR_HOOK_ID
        send_resolved: true
        http_config:
          authorization:
            credentials: YOUR_TOKEN
```

Keep `send_resolved: true`, or you won't get the ✅ when an alert clears.

The template reads the alert name from `commonLabels.alertname`, the message from `commonAnnotations.summary` or `description`, the status from `status`, and the severity from `commonLabels.severity`. The link is `externalURL`. For an alert `HighCPU` with the summary "CPU above 90% on web-1", you get `🔴 HighCPU`, then `✅ HighCPU` when it resolves.

</Tab>
<Tab value="Grafana">

1. In Grafana, open **Alerting › Contact points** and add a contact point of type **Webhook**.
2. Paste the **URL with token**. Or paste the payload URL and set the Authorization header to `Bearer` with your token.
3. Use the contact point in a notification policy, then test it.

Grafana sends the Alertmanager format with a few extra fields. The template reads `commonLabels.alertname` (or `title`) as the title, `commonAnnotations.summary` (or `message`) as the message, and `status` (or `state`) as the status.

</Tab>
<Tab value="Datadog">

1. In Datadog, open **Integrations › Webhooks** and add a webhook.
2. Paste the **URL with token** as the URL.
3. Keep the default `title`, `body` and `id` in the payload, and add `transition`, `link` and `priority`:

```json
{
  "id": "$ID",
  "title": "$EVENT_TITLE",
  "body": "$EVENT_MSG",
  "transition": "$ALERT_TRANSITION",
  "link": "$LINK",
  "priority": "$PRIORITY"
}
```

4. Mention the webhook in a monitor's message to send alerts to it.

`transition` gives the 🔴 and ✅, `priority` P1 or P2 makes the push time-sensitive, and `link` opens the monitor.

</Tab>
</Tabs>

<Callout type="info" title="Keep the token private">
Anyone with the token can push to you through this integration. If it leaks, remove the integration and create a new one.
</Callout>
