# Webhook-Format

Source: https://instatus.com/help/de/webhooks

Hier sind die Formate der Webhooks, die Sie erhalten, wenn Sie per Webhook abonniert haben:

**Wenn ein Vorfall hinzugefügt oder aktualisiert wird:**

```json
{
  "meta": {
    "unsubscribe": "",
    "documentation": ""
  },
  "page": {
    "id": "",
    "status_indicator": "",
    "status_description": "",
    "url": ""
  },
  "incident": {
    "backfilled": false,
    "created_at": "",
    "impact": "",
    "name": "",
    "resolved_at": "",
    "status": "",
    "updated_at": "",
    "id": "",
    "url": "",
    "incident_updates": [
      {
        "id": "",
        "incident_id": "",
        "body": "",
        "status": "",
        "created_at": "",
        "updated_at": ""
      }
    ]
  }
}
```

**Wenn eine Wartung hinzugefügt oder aktualisiert wird:**

```json
{
  "meta": {
    "unsubscribe": "",
    "documentation": ""
  },
  "page": {
    "id": "",
    "status_indicator": "",
    "status_description": "",
    "url": ""
  },
  "maintenance": {
    "backfilled": false,
    "created_at": "",
    "impact": "",
    "name": "",
    "resolved_at": "",
    "status": "",
    "updated_at": "",
    "id": "",
    "url": "",
    "duration": "",
    "maintenance_updates": [
      {
        "id": "",
        "maintenance_id": "",
        "body": "",
        "status": "",
        "created_at": "",
        "updated_at": ""
      }
    ]
  }
}
```

**Wenn eine Komponente aktualisiert wird:**

```json
{
  "meta": {
    "unsubscribe": "https://<status-page-domain>/unsubscribe?id=${subscriber.id}&token=${subscriber.unsubscribeToken}",
    "documentation": ""
  },
  "page": {
    "id": "",
    "status_indicator": "",
    "status_description": "",
    "url": ""
  },
  "component_update": {
    "created_at": "",
    "new_status": "",
    "component_id": ""
  },
  "component": {
    "created_at": "",
    "id": "",
    "name": "",
    "status": ""
  }
}
```

### Mögliche Status der Statusseite:

- `UP`
- `HASISSUES`
- `UNDERMAINTENANCE`

### Mögliche Komponentenstatus:

- `OPERATIONAL`
- `UNDERMAINTENANCE`
- `DEGRADEDPERFORMANCE`
- `PARTIALOUTAGE`
- `MAJOROUTAGE`

### Mögliche Vorfallsstatus:

- `INVESTIGATING`
- `IDENTIFIED`
- `MONITORING`
- `RESOLVED`

### Mögliche Wartungsstatus:

- `NOTSTARTEDYET`
- `INPROGRESS`
- `COMPLETED`

## Überprüfung der Webhook-Payload

**Es wird dringend empfohlen, die Webhook-Payload im Webhook-Endpunkt zu validieren.**

Wir signieren Webhook-Payloads mit einem Secret und senden die Signatur im Header `x-instatus-webhook-signature`. Mit dieser Signatur können Sie prüfen, dass der Webhook von Instatus stammt.

### Schritte zur Überprüfung des Webhooks

1. Bewahren Sie Ihr **Webhook-Secret** auf, das Sie beim Abonnieren des Webhooks erzeugt haben (Sie finden es beim Abonnieren einer Seite per Webhook und können es dort auch anpassen).

![Webhook-Secret](https://instatus.com/help/notification/webhook-subscribe-example.png)

2. Richten Sie auf Ihrem Server einen neuen Endpunkt ein, der den Webhook empfängt.

3. Vergleichen Sie die Signatur zur Validierung mit der auf Ihrem Server erzeugten Signatur.

4. Stimmen die Signaturen überein, verarbeiten Sie den Webhook.

#### Codebeispiel

```javascript
import crypto from 'crypto'
import express from 'express'

const app = express()
app.use(express.json())

const WEBHOOK_SECRET = 'your-webhook-secret'

function isVerifiedPayload(payload, signature, secret) {
  const hmac = crypto.createHmac('sha256', secret)
  const digest = hmac.update(JSON.stringify(payload)).digest('hex')
  return crypto.timingSafeEqual(Buffer.from(digest), Buffer.from(signature))
}

app.post('/endpoint/to/webhook', (req, res) => {
  const payload = req.body
  const signature = req.header('x-instatus-webhook-signature')

  if (!signature) {
    return res.status(400).send('Signature missing')
  }

  if (!isVerifiedPayload(payload, signature, WEBHOOK_SECRET)) {
    return res.status(401).send('Invalid signature')
  }

  // Process the valid webhook
  res.status(200).send('Webhook received')
})

app.listen(3000, () => console.log('Server running on port 3000'))
```

### Warum die Überprüfung wichtig ist

- **Sichert die Authentizität**: Stellt sicher, dass der Webhook von unserer Plattform stammt.
- **Verhindert Manipulation**: Erkennt Änderungen an der Payload.
- **Erhöht die Sicherheit**: Schützt vor Replay-Angriffen und unbefugtem Zugriff.
