# Datadog monitor alert notifications on your phone

> Get a push notification when a Datadog monitor triggers, warns, stops reporting data, or recovers, with priority following the monitor's P1–P5.

- Company: Datadog (https://www.justpush.io/recipes/datadog)
- Event: `monitor` (Monitor alert)
- Tags: Developer tools, Monitoring
- Install: https://studio.justpush.io/recipes/datadog/monitor-alert
- Web page: https://www.justpush.io/recipes/datadog/monitor-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 Datadog, open Integrations > Webhooks and add a new webhook named justpush.
3. Paste your webhook URL (shown in Studio after install) as the URL and replace the payload with the one from the setup notes below.
4. Add @webhook-justpush to the message of every monitor that should notify you.
5. In **Integrations → Webhooks**, add a webhook named **justpush** with the URL above, and replace its payload with this:
6. ```json
7. {
8. "source": "datadog",
9. "title": "$EVENT_TITLE",
10. "transition": "$ALERT_TRANSITION",
11. "priority": "$ALERT_PRIORITY",
12. "hostname": "$HOSTNAME",
13. "link": "$LINK",
14. "snapshot": "$SNAPSHOT",
15. "org": "$ORG_NAME"
16. }
17. ```
18. Then add **`@webhook-justpush`** to the message of each monitor that should notify you.
19. The template leaves out `$EVENT_MSG` on purpose: a monitor message with quotes or line breaks could produce invalid JSON. Datadog doesn't sign webhook requests, 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
// Datadog → monitor alert
// Fires when a Datadog monitor that mentions @webhook-justpush triggers, warns,
// has no data, or recovers. Uses the custom payload from INSTALL.md.
// Docs: https://docs.datadoghq.com/integrations/webhooks/

// $ALERT_TRANSITION values, how to label them, and the default priority.
const TRANSITIONS = {
    Triggered: { emoji: "🔴", priority: 1 },
    "Re-Triggered": { emoji: "🔴", priority: 1 },
    Renotify: { emoji: "🔴", priority: 1, suffix: " (still alerting)" },
    Warn: { emoji: "🟠", priority: 0 },
    "Re-Warn": { emoji: "🟠", priority: 0 },
    "No Data": { emoji: "⚪", priority: 0, suffix: " (no data)" },
    Recovered: { emoji: "✅", priority: -1 },
}

// $ALERT_PRIORITY → push priority for alerts (P1 pages you, P5 barely whispers).
const PRIORITIES = { P1: 2, P2: 1, P3: 1, P4: 0, P5: -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 }] : []
}

// Datadog leaves "$VARIABLE" untouched when it has no value; treat that as missing.
function text(value) {
    return typeof value === "string" && value.trim() && !/^\$[A-Z_]+$/.test(value.trim()) ? value.trim() : null
}

function handleRequest(request) {
    const body = request.body || {}

    // Guard: only payloads from the JustPush template in INSTALL.md.
    if (body.source !== "datadog" || !text(body.title)) {
        console.log("Not a JustPush Datadog payload — skipping")
        return null
    }

    // Unknown transitions are treated as an alert rather than dropped.
    const transition = pick(TRANSITIONS, text(body.transition), TRANSITIONS.Triggered)
    const recovered = transition === TRANSITIONS.Recovered

    // Event titles look like "[Triggered on {host:web-1}] High CPU on web-1"; the state is
    // already in the emoji, so keep just the monitor name and the scope.
    const match = text(body.title).match(/^\[[^\]]*?(?: on (.+?))?\]\s*(.+)$/)
    const name = match ? match[2] : text(body.title)
    // "{host:web-1}" reads better without the braces.
    const scope = match?.[1]?.replace(/[{}]/g, "")

    const alerting = transition.priority >= 1
    const priority = alerting ? pick(PRIORITIES, text(body.priority), transition.priority) : transition.priority
    const details = [scope ?? text(body.hostname), text(body.priority)].filter(Boolean)

    return {
        title: `${transition.emoji} ${recovered ? "Recovered: " : ""}${name}${transition.suffix ?? ""}`,
        message: details.join(" · ") || text(body.transition) || "Monitor alert",
        topic: "Datadog",
        priority,
        buttons: [...link(text(body.link), "View in Datadog"), ...link(text(body.snapshot), "View graph")],
    }
}
```

## Datadog monitor webhook payload (sample)

```json
{
  "org": "Acme",
  "link": "https://app.datadoghq.com/monitors/123456?group=host%3Aweb-1",
  "title": "[Triggered on {host:web-1}] High CPU on web-1",
  "source": "datadog",
  "hostname": "web-1",
  "priority": "P2",
  "snapshot": "https://p.datadoghq.com/snapshot/view/dd-snapshots-prod/org_1/2026-09-29/abc123.png",
  "transition": "Triggered"
}
```

## 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 Datadog 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.
