# Rules and events with the API

Rules, sensitivity, known events and feedback with the API. For the plain version, see [When an alert fires](/docs/rules) and [Planned changes and feedback](/docs/events-and-feedback).

Each watch gets its own automatic rules, picked from its own history, so a busy watch and a slow one are judged differently: up to 4 automatic rules per watch, and the same detection on every plan. A rule is written in **times usual**: `1H ×4` fires when the last hour is 4 times its usual level; `24H ×0.3` when a day falls to 30% of usual. Automatic rules can change as CountWatch learns a watch.

## What Matters

Each group says which kinds of change are a problem for its watches: `what_matters`, any of `spikes` (more is bad), `drops` (fewer is bad) and `stops` (counts stop coming); all three by default. A kind that matters alerts at the sensitivity below; one left out alerts only on major changes. A watch follows its group's, or sets its own (PATCH `/v1/watches/{watch_id}` `what_matters`; null: its group's again; `effective_what_matters` is what it runs on).

## Sensitivity

Each watch has a level, `sensitivity` on the watch or its group (PATCH `/v1/watches/{watch_id}` or `/v1/groups/{group_id}`; null on a watch: its group's; `effective_sensitivity` is the level it runs on). **High** (`sensitive`): alerts on smaller changes, so you hear about more problems and get more false alarms. **Balanced** (`balanced`): the default. **Low** (`big`): alerts only on large changes, fewer false alarms, and it may miss smaller problems. CountWatch keeps tuning a watch's automatic rules to its level each week, and a new level tunes them again within minutes; rules you set yourself are never changed and are not part of the level. Each change of the automatic rules is told to the watch's destinations at most once a week (e-mail, Slack, and webhooks as `watch.rules_tuned`), with what changed, why, and about how many alerts a month the old and new rules would have sent on the watch's past. When no rule fits a watch, the import result says so and suggests a fixed limit. A spike the checks held as one 5-minute burst (`held` in explain, `single_event`) is shown on the watch's page for 7 days with a max limit that would alert on bursts like it; `GET /v1/status` (MCP `check_setup`) proposes the same limit once in `next_actions`: set it only after the person agrees.

## Your own rules

`POST /v1/rules` sets a shared rule on a group (`group_id`: every watch in it, now and later; the answer's `fit` lists the watches where a spike or drop rule would alert too often, and `off_where_it_does_not_fit: true` saves it turned off there) or a rule on one watch (`watch_id`: added to its group's; with `replaces`, a shared rule changed for that watch only, or with `off: true` turned off for it): a change `{direction, hours, times_usual}` replaces the automatic rules of its direction (add `min_change`, a count, to alert only when the count is also at least that many above or below the usual: it keeps a small count from alerting), a fixed limit `{bound: max | min, hours, limit}` is added. A rule you set is never changed automatically; the answer estimates how often a watch rule would have alerted. `GET /v1/rules?watch_id=` shows every rule in force (an automatic rule turned off for the watch in the app has `off: true`); `PATCH /v1/rules/{rule_id}` with `off: true` keeps a watch's own rule but never checks it (`off: false` turns it on again); `DELETE /v1/rules/{rule_id}` goes back to automatic.

## Known events

Before a deployment, campaign or maintenance, `POST /v1/events` with `kind` (and `expect` when the default does not fit): a level change holds both directions for up to 6 hours and then accepts the new level once steady; an expected spike or drop holds that direction until `until`; a no_data holds drops and no-data alerts. Held periods are left out of the usual level. Fixed limits are not held. `watch_id: "*"` covers every watch.

## Feedback

`POST /v1/alerts/{alert_id}/feedback` with `real`, `false_alarm`, `expected_change`, `expected` or `new_normal`. Real and false alarms teach the weekly rule choice (automatic rules only; a rule you set stays); `false_alarm` on a Spike or Drop also turns that alert's notifications off (`notifications_off_at`): no reopened or got-worse message, its end only to a webhook or PagerDuty, until another answer; an expected change on an open alert makes its new level the new normal at the next check and closes the alert. `new_normal` answers "New normal?" with yes, and `real` after the question answers no (see Alerts).
