# Alerts

An incident opens after a monitor's `failureThreshold` consecutive failures or errors (default 2) and recovers on the next pass. Alerts go to your channels through routing rules. Missed schedules and other coverage errors never open incidents. Set this up once; the web app's Alerts page and `waitcher alert` do the same thing.

## 1. Add a channel

| Kind | Sends to | Credential |
| --- | --- | --- |
| `account-email` | Your verified sign-in address, up to 50 emails a day | None. Create it in the web app ("Email me at my sign-in address") or with `alert channel save` (CLI 0.2.1 or later; sign in again if an older CLI signed you in) |
| `slack` | A Slack incoming webhook | The webhook URL |
| `webhook` | Your HTTPS endpoint, as JSON | The endpoint URL |
| `email` | Any address, through your own Resend account | Your Resend API key; set `from` and `to` |

```json
{ "name": "Team Slack", "kind": "slack", "enabled": true }
```

```sh
waitcher alert channel save --file slack.json --credential-file ./private/slack-webhook-url
waitcher alert channel list
waitcher alert channel test --id CHANNEL_ID --yes     # sends a real notification
```

Credentials are write-only: pass them with `--credential-file` or `--credential-stdin`, never in the JSON. New channels are paused unless `"enabled": true`; saving never sends a test. To edit, save with `--id CHANNEL_ID` and `expectedRevision` in the JSON.

## 2. Route events to it

```json
{
  "monitorId": "*",
  "channelIds": ["CHANNEL_ID"],
  "events": ["incident", "recovered"],
  "cooldownSeconds": 900,
  "expectedRevision": 0
}
```

```sh
waitcher alert policy save --file routing.json
waitcher alert policy list
```

- `monitorId: "*"` is the account default. A rule for one monitor (its ID) or one project (`projectId` instead of `monitorId`) replaces the default for those monitors.
- `cooldownSeconds` (0 to 86,400) suppresses repeats of the same event on the same channel.
- `expectedRevision` is 0 to create and the current revision to edit.

## Maintenance windows

```json
{ "name": "Release", "monitorId": "*", "startsAt": 1793174400000, "endsAt": 1793178000000, "enabled": true }
```

```sh
waitcher alert maintenance save --file window.json
waitcher alert maintenance list
```

Windows silence notifications, not checks: runs and incidents continue. Times are UTC epoch milliseconds, at most seven days per window. Silenced notifications are not sent later.

## Delivery

`waitcher alert deliveries` and `waitcher alert attempts --id DELIVERY_ID` show what was sent. Delivery is at least once with up to five attempts; Slack may show a duplicate after an uncertain failure. "Accepted" means the provider took it, not that someone read it.
