# Webhook (https://raaqeb.dev/docs/api/webhooks)

> محتوى JSON الذي يرسله راقب إلى قناة Webhook لكل نوع إشعار، وما يستقبله Webhook المشترك.

يرسل راقب نوعين من Webhook. تستقبل [قناة Webhook](https://raaqeb.dev/docs/notifications/webhook) إشعارات المشغّل موقّعةً وفق مواصفة Standard Webhooks. أما المشترك الذي اشترك في صفحة حالة عبر Webhook فيستقبل إشعارات المشترك غير موقّعة، بالمحتوى الذي يرسله Atlassian Statuspage.

يحمل كل طلب POST الترويسة `webhook-id`، وهي نفسها في كل إعادة محاولة ليتخلص المستقبل من النسخة المكررة، والترويسة `webhook-timestamp`. وإذا أجاب المستقبل بغير `2xx`، وصله الطلب من جديد بعد 30 ثانية، ثم بعد دقيقتين، ثم بعد 10 دقائق.

## قناة Webhook

لكل نوع إشعار محتوى واحد، يميّزه حقل `type`. وتشرح صفحة القناة [كيف تتحقق من التوقيع](https://raaqeb.dev/docs/notifications/webhook).

### التعطّل

**POST** `monitor.down`

Monitor down

Sent when an outage opens: the first check that confirms the monitor is down. A late heartbeat is down for a heartbeat monitor.

الترويسات:

- `webhook-id` (الترويسة): `string`. The notification's id: the same on every retry, so a receiver can drop a duplicate.
- `webhook-timestamp` (الترويسة): `string` يطابق `^[0-9]+$`. When this attempt was made, in Unix seconds.
- `webhook-signature` (الترويسة): `string`. `v1,` and the base64 HMAC-SHA256 of `<webhook-id>.<webhook-timestamp>.<body>`, keyed with the bytes that the base64 after the signing secret's `whsec_` prefix decodes to.

المحتوى, `application/json`:

```ts
{
  // What the event is about.
  data: {
    // The monitor the event is about, as it was when the notification was queued.
    monitor: {
      // The monitor's page in the admin area, at the public address; absent when the install stores none.
      adminUrl?: string; // uri
      // The monitor's check type.
      checkType: "http" | "tcp" | "dns" | "postgres" | "mysql" | "redis" | "docker" | "heartbeat";
      // The monitor's id.
      id: string;
      // The monitor's name.
      name: string;
      // The URL, `host:port` or name the check reaches; null for a heartbeat monitor.
      target: string | null;
    };
    // The admin area's new-incident page for this monitor; absent when the install stores no public address.
    incidentUrl?: string; // uri
    // Why the check failed.
    reason: "ok" | "timeout" | "dns_failed" | "connection_refused" | "connection_failed" | "certificate_expired" | "certificate_invalid" | "unexpected_status" | "assertion_failed" | "slow" | "too_many_redirects" | "heartbeat_late" | "unknown" | "dns_mismatch" | "auth_failed" | "query_failed" | "container_not_found" | "container_not_running" | "container_restarting" | "container_paused" | "container_dead" | "container_unhealthy" | "tls_required" | "smtp_no_greeting" | "smtp_stalled";
  };
  // When the event happened: the start of the check that raised it, in UTC.
  timestamp: string; // date-time
  // The notification's type.
  type: "monitor.down";
}
```

الاستجابات:

- `2XX`: Received. Any other answer, a redirect included, is a failed attempt, tried again 30 seconds, 2 minutes and 10 minutes later.

### التعافي

**POST** `monitor.recovered`

Monitor recovered

Sent when the outage closes: the first check that is no longer down.

الترويسات:

- `webhook-id` (الترويسة): `string`. The notification's id: the same on every retry, so a receiver can drop a duplicate.
- `webhook-timestamp` (الترويسة): `string` يطابق `^[0-9]+$`. When this attempt was made, in Unix seconds.
- `webhook-signature` (الترويسة): `string`. `v1,` and the base64 HMAC-SHA256 of `<webhook-id>.<webhook-timestamp>.<body>`, keyed with the bytes that the base64 after the signing secret's `whsec_` prefix decodes to.

المحتوى, `application/json`:

```ts
{
  // What the event is about.
  data: {
    // The monitor the event is about, as it was when the notification was queued.
    monitor: {
      // The monitor's page in the admin area, at the public address; absent when the install stores none.
      adminUrl?: string; // uri
      // The monitor's check type.
      checkType: "http" | "tcp" | "dns" | "postgres" | "mysql" | "redis" | "docker" | "heartbeat";
      // The monitor's id.
      id: string;
      // The monitor's name.
      name: string;
      // The URL, `host:port` or name the check reaches; null for a heartbeat monitor.
      target: string | null;
    };
    // How long the outage lasted, in milliseconds.
    downtimeMs: integer;
  };
  // When the event happened: the start of the check that raised it, in UTC.
  timestamp: string; // date-time
  // The notification's type.
  type: "monitor.recovered";
}
```

الاستجابات:

- `2XX`: Received. Any other answer, a redirect included, is a failed attempt, tried again 30 seconds, 2 minutes and 10 minutes later.

### بدء التعثّر

**POST** `monitor.degraded_started`

Monitor degraded started

Sent when a check succeeds but is slower than the monitor's degraded threshold.

الترويسات:

- `webhook-id` (الترويسة): `string`. The notification's id: the same on every retry, so a receiver can drop a duplicate.
- `webhook-timestamp` (الترويسة): `string` يطابق `^[0-9]+$`. When this attempt was made, in Unix seconds.
- `webhook-signature` (الترويسة): `string`. `v1,` and the base64 HMAC-SHA256 of `<webhook-id>.<webhook-timestamp>.<body>`, keyed with the bytes that the base64 after the signing secret's `whsec_` prefix decodes to.

المحتوى, `application/json`:

```ts
{
  // What the event is about.
  data: {
    // The monitor the event is about, as it was when the notification was queued.
    monitor: {
      // The monitor's page in the admin area, at the public address; absent when the install stores none.
      adminUrl?: string; // uri
      // The monitor's check type.
      checkType: "http" | "tcp" | "dns" | "postgres" | "mysql" | "redis" | "docker" | "heartbeat";
      // The monitor's id.
      id: string;
      // The monitor's name.
      name: string;
      // The URL, `host:port` or name the check reaches; null for a heartbeat monitor.
      target: string | null;
    };
    // Why the check is degraded.
    reason: "ok" | "timeout" | "dns_failed" | "connection_refused" | "connection_failed" | "certificate_expired" | "certificate_invalid" | "unexpected_status" | "assertion_failed" | "slow" | "too_many_redirects" | "heartbeat_late" | "unknown" | "dns_mismatch" | "auth_failed" | "query_failed" | "container_not_found" | "container_not_running" | "container_restarting" | "container_paused" | "container_dead" | "container_unhealthy" | "tls_required" | "smtp_no_greeting" | "smtp_stalled";
  };
  // When the event happened: the start of the check that raised it, in UTC.
  timestamp: string; // date-time
  // The notification's type.
  type: "monitor.degraded_started";
}
```

الاستجابات:

- `2XX`: Received. Any other answer, a redirect included, is a failed attempt, tried again 30 seconds, 2 minutes and 10 minutes later.

### انتهاء التعثّر

**POST** `monitor.degraded_ended`

Monitor degraded ended

Sent when a check is up again after the monitor was degraded. A degraded monitor that goes down sends only `monitor.down`.

الترويسات:

- `webhook-id` (الترويسة): `string`. The notification's id: the same on every retry, so a receiver can drop a duplicate.
- `webhook-timestamp` (الترويسة): `string` يطابق `^[0-9]+$`. When this attempt was made, in Unix seconds.
- `webhook-signature` (الترويسة): `string`. `v1,` and the base64 HMAC-SHA256 of `<webhook-id>.<webhook-timestamp>.<body>`, keyed with the bytes that the base64 after the signing secret's `whsec_` prefix decodes to.

المحتوى, `application/json`:

```ts
{
  // What the event is about.
  data: {
    // The monitor the event is about, as it was when the notification was queued.
    monitor: {
      // The monitor's page in the admin area, at the public address; absent when the install stores none.
      adminUrl?: string; // uri
      // The monitor's check type.
      checkType: "http" | "tcp" | "dns" | "postgres" | "mysql" | "redis" | "docker" | "heartbeat";
      // The monitor's id.
      id: string;
      // The monitor's name.
      name: string;
      // The URL, `host:port` or name the check reaches; null for a heartbeat monitor.
      target: string | null;
    };
  };
  // When the event happened: the start of the check that raised it, in UTC.
  timestamp: string; // date-time
  // The notification's type.
  type: "monitor.degraded_ended";
}
```

الاستجابات:

- `2XX`: Received. Any other answer, a redirect included, is a failed attempt, tried again 30 seconds, 2 minutes and 10 minutes later.

### التذكير

**POST** `monitor.reminder`

Monitor reminder

Sent every so many minutes, as the monitor's reminder sets, while it stays down and its outage is not acknowledged.

الترويسات:

- `webhook-id` (الترويسة): `string`. The notification's id: the same on every retry, so a receiver can drop a duplicate.
- `webhook-timestamp` (الترويسة): `string` يطابق `^[0-9]+$`. When this attempt was made, in Unix seconds.
- `webhook-signature` (الترويسة): `string`. `v1,` and the base64 HMAC-SHA256 of `<webhook-id>.<webhook-timestamp>.<body>`, keyed with the bytes that the base64 after the signing secret's `whsec_` prefix decodes to.

المحتوى, `application/json`:

```ts
{
  // What the event is about.
  data: {
    // The monitor the event is about, as it was when the notification was queued.
    monitor: {
      // The monitor's page in the admin area, at the public address; absent when the install stores none.
      adminUrl?: string; // uri
      // The monitor's check type.
      checkType: "http" | "tcp" | "dns" | "postgres" | "mysql" | "redis" | "docker" | "heartbeat";
      // The monitor's id.
      id: string;
      // The monitor's name.
      name: string;
      // The URL, `host:port` or name the check reaches; null for a heartbeat monitor.
      target: string | null;
    };
    // How long the monitor has been down, in milliseconds.
    downForMs: integer;
    // The reason the outage opened with.
    reason: "ok" | "timeout" | "dns_failed" | "connection_refused" | "connection_failed" | "certificate_expired" | "certificate_invalid" | "unexpected_status" | "assertion_failed" | "slow" | "too_many_redirects" | "heartbeat_late" | "unknown" | "dns_mismatch" | "auth_failed" | "query_failed" | "container_not_found" | "container_not_running" | "container_restarting" | "container_paused" | "container_dead" | "container_unhealthy" | "tls_required" | "smtp_no_greeting" | "smtp_stalled";
  };
  // When the event happened: the start of the check that raised it, in UTC.
  timestamp: string; // date-time
  // The notification's type.
  type: "monitor.reminder";
}
```

الاستجابات:

- `2XX`: Received. Any other answer, a redirect included, is a failed attempt, tried again 30 seconds, 2 minutes and 10 minutes later.

### قرب انتهاء الشهادة

**POST** `monitor.certificate_expiring`

Monitor certificate expiring

Sent when an HTTPS monitor's certificate expires within the monitor's warning threshold, then once more within one day. A new certificate starts over.

الترويسات:

- `webhook-id` (الترويسة): `string`. The notification's id: the same on every retry, so a receiver can drop a duplicate.
- `webhook-timestamp` (الترويسة): `string` يطابق `^[0-9]+$`. When this attempt was made, in Unix seconds.
- `webhook-signature` (الترويسة): `string`. `v1,` and the base64 HMAC-SHA256 of `<webhook-id>.<webhook-timestamp>.<body>`, keyed with the bytes that the base64 after the signing secret's `whsec_` prefix decodes to.

المحتوى, `application/json`:

```ts
{
  // What the event is about.
  data: {
    // The monitor the event is about, as it was when the notification was queued.
    monitor: {
      // The monitor's page in the admin area, at the public address; absent when the install stores none.
      adminUrl?: string; // uri
      // The monitor's check type.
      checkType: "http" | "tcp" | "dns" | "postgres" | "mysql" | "redis" | "docker" | "heartbeat";
      // The monitor's id.
      id: string;
      // The monitor's name.
      name: string;
      // The URL, `host:port` or name the check reaches; null for a heartbeat monitor.
      target: string | null;
    };
    // The monitor's certificate.
    certificate: {
      // Whole days left, rounded down.
      daysLeft: integer;
      // When the certificate expires, in UTC.
      notAfter: string; // date-time
    };
  };
  // When the event happened: the start of the check that raised it, in UTC.
  timestamp: string; // date-time
  // The notification's type.
  type: "monitor.certificate_expiring";
}
```

الاستجابات:

- `2XX`: Received. Any other answer, a redirect included, is a failed attempt, tried again 30 seconds, 2 minutes and 10 minutes later.

### الرسالة التجريبية

**POST** `channel.test`

Channel test

Sent when the operator presses the channel's send test.

الترويسات:

- `webhook-id` (الترويسة): `string`. The notification's id: the same on every retry, so a receiver can drop a duplicate.
- `webhook-timestamp` (الترويسة): `string` يطابق `^[0-9]+$`. When this attempt was made, in Unix seconds.
- `webhook-signature` (الترويسة): `string`. `v1,` and the base64 HMAC-SHA256 of `<webhook-id>.<webhook-timestamp>.<body>`, keyed with the bytes that the base64 after the signing secret's `whsec_` prefix decodes to.

المحتوى, `application/json`:

```ts
{
  // What the test is about.
  data: {
    // The channel being tested.
    channel: {
      // The channel's id.
      id: string;
      // The channel's name.
      name: string;
    };
  };
  // When the operator asked for the test, in UTC.
  timestamp: string; // date-time
  // The notification's type.
  type: "channel.test";
}
```

الاستجابات:

- `2XX`: Received. Any other answer, a redirect included, is a failed attempt, tried again 30 seconds, 2 minutes and 10 minutes later.

## Webhook المشترك

### التأكيد

**POST** `subscription.confirmation`

Subscription confirmation

Sent to a subscriber's webhook first, when it subscribes: the link to the page where a person confirms the subscription by pressing its button, within 48 hours. Nothing else is sent until then.

الترويسات:

- `webhook-id` (الترويسة): `string`. The notification's id: the same on every retry, so a receiver can drop a duplicate.
- `webhook-timestamp` (الترويسة): `string` يطابق `^[0-9]+$`. When this attempt was made, in Unix seconds.

المحتوى, `application/json`:

```ts
{
  // The subscription's page, where the subscriber confirms.
  confirmUrl: string;
  // The status page subscribed to.
  page: {
    // The status page's id.
    id: string;
    // The page's title.
    name: string;
    // The page's plain address in the subscription language, on its custom domain or the public address.
    url: string;
  };
  // One sentence in the subscription language saying what to do.
  text: string;
  // When the visitor subscribed, in UTC.
  timestamp: string; // date-time
  // The body's type.
  type: "subscription.confirmation";
}
```

الاستجابات:

- `2XX`: Received. Any other answer, a redirect included, is a failed attempt, tried again 30 seconds, 2 minutes and 10 minutes later.

### أحداث الحوادث والصيانة

تشترك الأحداث السبعة كلها في محتوى واحد، واسم الحدث في حقل `meta.event`.

**POST** `incident.published`

**POST** `incident.updated`

**POST** `maintenance.scheduled`

**POST** `maintenance.rescheduled`

**POST** `maintenance.started`

**POST** `maintenance.completed`

**POST** `maintenance.cancelled`

- `incident.published`: Sent to a subscriber's webhook when an incident on a component the page shows is published, in the body Statuspage sends its webhook subscribers; a maintenance window is an incident with impact maintenance. Its text is in the subscription language, else the page language, and its links lead to the subscription language's views. On the update that first names a component, `old_status` is the status the page showed for it just before; an incident opened before Raaqeb kept that status says `operational`.
- `incident.updated`: Sent to a subscriber's webhook when an incident on a component the page shows gets an update, the resolving one included, in the body Statuspage sends its webhook subscribers; a maintenance window is an incident with impact maintenance. Its text is in the subscription language, else the page language, and its links lead to the subscription language's views. On the update that first names a component, `old_status` is the status the page showed for it just before; an incident opened before Raaqeb kept that status says `operational`.
- `maintenance.scheduled`: Sent to a subscriber's webhook when a maintenance window on a component the page shows is scheduled, in the body Statuspage sends its webhook subscribers; a maintenance window is an incident with impact maintenance. Its text is in the subscription language, else the page language, and its links lead to the subscription language's views. Its update lists no component, since scheduling changes no status. Not sent for a window that starts in the current minute, which sends `maintenance.started` alone.
- `maintenance.rescheduled`: Sent to a subscriber's webhook when an edit moves the start or end of a maintenance window on a component the page shows, in the body Statuspage sends its webhook subscribers; a maintenance window is an incident with impact maintenance. Its text is in the subscription language, else the page language, and its links lead to the subscription language's views. An edit moved the window's start or end, while scheduled or in progress: `scheduled_for` and `scheduled_until` carry the new times, `status` its stage, and its update, stamped with the edit, lists no component, since new times change no status. Not sent when the start or the end moves to the current minute, which sends `maintenance.started` or `maintenance.completed` instead.
- `maintenance.started`: Sent to a subscriber's webhook when a maintenance window on a component the page shows starts, in the body Statuspage sends its webhook subscribers; a maintenance window is an incident with impact maintenance. Its text is in the subscription language, else the page language, and its links lead to the subscription language's views. Its update lists each of the page's affected components with `old_status` the status it held before and `new_status` `under_maintenance`.
- `maintenance.completed`: Sent to a subscriber's webhook when a maintenance window on a component the page shows ends, in the body Statuspage sends its webhook subscribers; a maintenance window is an incident with impact maintenance. Its text is in the subscription language, else the page language, and its links lead to the subscription language's views. Its update lists each of the page's affected components with `old_status` `under_maintenance` and `new_status` the status it holds after.
- `maintenance.cancelled`: Sent to a subscriber's webhook when a maintenance window on a component the page shows is cancelled before it starts, in the body Statuspage sends its webhook subscribers; a maintenance window is an incident with impact maintenance. Its text is in the subscription language, else the page language, and its links lead to the subscription language's views. A scheduled window was cancelled before it started: the window has `status` `completed` and `resolved_at` the cancel's time, as Statuspage ends a maintenance, and this event's name is how a consumer tells a cancel from an end. Its update lists no component, since the window never moved a status, and its `shortlink` is the page's plain address, since the window's own view is gone.

الترويسات:

- `webhook-id` (الترويسة): `string`. The notification's id: the same on every retry, so a receiver can drop a duplicate.
- `webhook-timestamp` (الترويسة): `string` يطابق `^[0-9]+$`. When this attempt was made, in Unix seconds.

المحتوى, `application/json`:

```ts
{
  // The incident, or the maintenance window as an incident with impact maintenance.
  incident: {
    // The page's components it affects.
    components: {
      // A group's members, by id; only on a group.
      components?: string[];
      // When the component, or the page for a group, was created, in UTC.
      created_at: string; // date-time
      // The component's description; null when it has none, and on a group.
      description: string | null;
      // Whether this is a component group.
      group: boolean;
      // The group a component sits in on this page; null outside one.
      group_id: string | null;
      // The component's or the group's id.
      id: string;
      // The component's or the group's name.
      name: string;
      // Always false: the page shows every component it lists.
      only_show_if_degraded: false;
      // The status page's id.
      page_id: string;
      // Its place in the page's order, from 1; a group's members count from 1 inside it.
      position: integer;
      // True on a component, false on a group, as Statuspage marks them.
      showcase: boolean;
      // Always null: Raaqeb has no data for it.
      start_date: null;
      // The component's or the group's status level.
      status: "operational" | "under_maintenance" | "degraded_performance" | "partial_outage" | "major_outage";
      // When it last changed, in UTC.
      updated_at: string; // date-time
    }[];
    // When it was opened, in UTC.
    created_at: string; // date-time
    // The incident's id.
    id: string;
    // The incident's impact level.
    impact: "none" | "minor" | "major" | "critical";
    // Its updates, newest first.
    incident_updates: {
      // The components the update set a status on, each with the one it held before.
      affected_components: {
        // The component's id.
        code: string;
        // The component's name.
        name: string;
        // The status level the update set on it.
        new_status: "operational" | "under_maintenance" | "degraded_performance" | "partial_outage" | "major_outage";
        // The status level it held before.
        old_status: "operational" | "under_maintenance" | "degraded_performance" | "partial_outage" | "major_outage";
      }[];
      // What the update says.
      body: string;
      // When it was posted, in UTC.
      created_at: string; // date-time
      custom_tweet: null;
      // Always true: subscribers are told of every update.
      deliver_notifications: boolean;
      display_at: string; // date-time
      // The update's id.
      id: string;
      // The id of the incident it belongs to.
      incident_id: string;
      // The stage it moved the incident to.
      status: "investigating" | "identified" | "monitoring" | "resolved";
      tweet_id: null;
      updated_at: string; // date-time
    }[];
    // When an update moved it to monitoring, in UTC; null if none did.
    monitoring_at: string | null; // date-time
    // The incident's title.
    name: string;
    page_id: string;
    reminder_intervals: null;
    // When it was resolved, in UTC; null while it is open.
    resolved_at: string | null; // date-time
    // The incident's view on this page.
    shortlink: string;
    started_at: string; // date-time
    // The incident's stage.
    status: "investigating" | "identified" | "monitoring" | "resolved";
    updated_at: string; // date-time
  } | {
    components: {
      components?: string[];
      created_at: string; // date-time
      description: string | null;
      group: boolean;
      group_id: string | null;
      id: string;
      name: string;
      only_show_if_degraded: false;
      page_id: string;
      position: integer;
      showcase: boolean;
      start_date: null;
      status: "operational" | "under_maintenance" | "degraded_performance" | "partial_outage" | "major_outage";
      updated_at: string; // date-time
    }[];
    // When the window was created, in UTC.
    created_at: string; // date-time
    // The maintenance window's id.
    id: string;
    // Always maintenance: Statuspage's impact for a maintenance.
    impact: "maintenance";
    // The window's description as one update at its stage.
    incident_updates: {
      affected_components: {
        code: string;
        name: string;
        new_status: "operational" | "under_maintenance" | "degraded_performance" | "partial_outage" | "major_outage";
        old_status: "operational" | "under_maintenance" | "degraded_performance" | "partial_outage" | "major_outage";
      }[];
      body: string;
      created_at: string; // date-time
      custom_tweet: null;
      deliver_notifications: boolean;
      display_at: string; // date-time
      id: string;
      incident_id: string;
      // The window's stage.
      status: "scheduled" | "in_progress" | "completed";
      tweet_id: null;
      updated_at: string; // date-time
    }[];
    monitoring_at: null;
    // The window's title.
    name: string;
    page_id: string;
    // When the window ended or was cancelled, in UTC; null before.
    resolved_at: string | null; // date-time
    // When the window starts, in UTC.
    scheduled_for: string; // date-time
    // When the window ends, in UTC.
    scheduled_until: string; // date-time
    // The window's view on this page.
    shortlink: string;
    started_at: string; // date-time
    status: "scheduled" | "in_progress" | "completed";
    updated_at: string; // date-time
  };
  // What Raaqeb adds to Statuspage's body.
  meta: {
    // The OpenAPI document that describes this body.
    documentation: string;
    // The event's name.
    event: "incident.published" | "incident.updated" | "maintenance.scheduled" | "maintenance.rescheduled" | "maintenance.started" | "maintenance.completed" | "maintenance.cancelled";
    // Opens the subscription's page, where the subscriber unsubscribes.
    unsubscribe: string;
  };
  // The status page the event came from.
  page: {
    id: string;
    // Statuspage's sentence for the indicator, such as All Systems Operational.
    status_description: string;
    // How bad the page is, worst last: none, maintenance, minor, major or critical.
    status_indicator: "none" | "maintenance" | "minor" | "major" | "critical";
  };
}
```

الاستجابات:

- `2XX`: Received. Any other answer, a redirect included, is a failed attempt, tried again 30 seconds, 2 minutes and 10 minutes later.
