# Grafana alert notifications on your phone

> Get a push notification when a Grafana alert fires or resolves, with its summary, the affected instance, and buttons to open the panel or silence it.

- Company: Grafana (https://www.justpush.io/recipes/grafana)
- Event: `alert` (Alert)
- Tags: Developer tools, Monitoring
- Install: https://studio.justpush.io/recipes/grafana/alert
- Web page: https://www.justpush.io/recipes/grafana/alert

## Setup

1. Click Install in Studio and sign in. The recipe is added to your account and you get a personal webhook URL.
2. In Grafana, go to Alerting > Contact points and add a contact point.
3. Choose the Webhook integration and paste your webhook URL (shown in Studio after install) as the URL (method POST).
4. Save, then use the contact point in a notification policy or directly in your alert rules. Test sends a sample.
5. Point a **Webhook** contact point (**Alerting → Contact points**) at the URL above, then route alerts to it with a notification policy or directly from your alert rules. Leave the payload on the default; a custom payload template would break the recipe.
6. For the best notifications, give your alert rules:
7. a **`summary`** annotation, which becomes the message
8. a **`severity`** label (`critical`, `warning`, …), which sets the priority
9. Grafana can sign requests (HMAC) or send an Authorization header, but JustPush doesn't check either yet, so keep your endpoint URL private.

## Code

Studio calls `handleRequest(request)` with the incoming webhook (`{ method, headers, body, query, raw }`) and sends the message object it returns. Returning `null` sends nothing.

```js
// Grafana → alert notification
// Fires when Grafana Alerting sends a notification to a Webhook contact point (firing or resolved).
// Docs: https://grafana.com/docs/grafana/latest/alerting/configure-notifications/manage-contact-points/integrations/webhook-notifier/

// The "severity" label, if your rules set one → push priority while firing.
const SEVERITIES = { critical: 2, page: 2, high: 1, error: 1, warning: 0, warn: 0, info: -1 }

// Look a key up in one of the tables above, ignoring inherited names like "toString".
function pick(table, key, fallback) {
    return Object.prototype.hasOwnProperty.call(table, key) ? table[key] : fallback
}

// Only link to real http(s) URLs.
function link(url, cta) {
    return typeof url === "string" && /^https?:\/\//.test(url) ? [{ cta, url }] : []
}

function handleRequest(request) {
    const body = request.body || {}
    const alerts = Array.isArray(body.alerts) ? body.alerts : []

    // Guard: only alert notifications, so anything else on this integration stays quiet.
    if (!alerts.length || !["firing", "resolved"].includes(body.status)) {
        console.log("Not an alert notification — skipping")
        return null
    }

    // One notification can group several alerts; describe the group by its first one.
    const firing = alerts.filter((alert) => alert.status === "firing")
    const shown = firing[0] ?? alerts[0]
    const labels = { ...(body.commonLabels ?? {}), ...(shown.labels ?? {}) }
    const annotations = { ...(body.commonAnnotations ?? {}), ...(shown.annotations ?? {}) }
    const name = labels.alertname ?? "Alert"
    const resolved = body.status === "resolved"

    const title = resolved
        ? `✅ Resolved: ${name}`
        : firing.length > 1
          ? `🔥 ${firing.length} alerts firing: ${name}`
          : `🔥 ${name}`

    // Prefer the human-written summary, then the description, then the triggering value.
    const detail = annotations.summary ?? annotations.description ?? shown.valueString ?? ""
    const where = labels.instance ?? labels.host ?? labels.job
    const message = [detail, where && !String(detail).includes(where) ? where : null].filter(Boolean).join(" — ")

    const severity = String(labels.severity ?? "").toLowerCase()

    return {
        title,
        message: message || (resolved ? "Back to normal" : "Alert is firing"),
        topic: "Grafana",
        priority: resolved ? -1 : pick(SEVERITIES, severity, 1),
        buttons: [
            ...link(shown.panelURL ?? shown.dashboardURL ?? shown.generatorURL, "View panel"),
            ...(resolved ? [] : link(shown.silenceURL, "Silence")),
        ],
    }
}
```

## Grafana alert webhook payload (sample)

```json
{
  "orgId": 1,
  "state": "alerting",
  "title": "[FIRING:1] High CPU Servers (web-1 critical)",
  "alerts": [
    {
      "endsAt": "0001-01-01T00:00:00Z",
      "labels": {
        "instance": "web-1",
        "severity": "critical",
        "alertname": "High CPU",
        "grafana_folder": "Servers"
      },
      "status": "firing",
      "values": {
        "A": 93.2
      },
      "panelURL": "https://grafana.example.com/d/servers?viewPanel=4",
      "startsAt": "2026-09-29T08:01:00Z",
      "silenceURL": "https://grafana.example.com/alerting/silence/new?alertmanager=grafana&matcher=alertname%3DHigh+CPU&matcher=instance%3Dweb-1",
      "annotations": {
        "summary": "CPU above 90% for 5 minutes"
      },
      "fingerprint": "57c6d9296de2ad39",
      "valueString": "[ var='A' labels={instance=web-1} value=93.2 ]",
      "dashboardURL": "https://grafana.example.com/d/servers",
      "generatorURL": "https://grafana.example.com/alerting/grafana/cdz3/view"
    }
  ],
  "status": "firing",
  "message": "**Firing**\n\nValue: A=93.2\nLabels:\n - alertname = High CPU",
  "version": "1",
  "groupKey": "{}:{alertname=\"High CPU\"}",
  "receiver": "JustPush",
  "externalURL": "https://grafana.example.com/",
  "groupLabels": {
    "alertname": "High CPU"
  },
  "commonLabels": {
    "instance": "web-1",
    "severity": "critical",
    "alertname": "High CPU"
  },
  "truncatedAlerts": 0,
  "commonAnnotations": {
    "summary": "CPU above 90% for 5 minutes"
  }
}
```

## FAQ

### Does this work on iPhone and Android?

Yes. Install the JustPush app from the App Store or Google Play and sign in. Every phone signed in to your account gets the notification.

### Do I need to write code?

No. Install the recipe in Studio, paste your webhook URL into Grafana and you are done. The code is there if you want to change the text, the sound or the buttons.

### Can I change what the notification says?

Yes. After install the recipe's code is yours. Edit it in Studio and test it against the sample payload before you save.

### What does it cost?

JustPush is free for 30 days. After that it's $19.99 a year, or $39.99 once. There is no extra charge for recipes.
