# Change an alarm

Change an alarm's rule or recipients, or stop and resume its notifications.

Replace _alarm-id_ with the alarm's id. Send only the fields to change; the others keep their
values.

**Important:**
Changing what the alarm measures (resource type, resource, metric, dimensions, statistic,
comparison, threshold, period or evaluation periods) resets it to `INSUFFICIENT_DATA`, with the
reason "The alarm was changed and has not been evaluated since.". The reset notifies nobody and adds
no history entry, also when the alarm was in `ALARM`. Changing its name, addresses, webhook or
notifications does not reset it.

## Prerequisites

- Permission for `monitoring:PutMetricAlarm` on the alarm,
  `rn:ews::<organization id>:monitoring:alarm/<alarm id>`.
- In the console, also `monitoring:DescribeAlarms` to open **Alarms**. Without
  `monitoring:PutMetricAlarm` on an alarm, its notification switch is unavailable, with the note
  "Needs monitoring:PutMetricAlarm on this alarm."

## Stop or resume notifications

With notifications stopped, the alarm keeps being evaluated and its state stays current; only the
mail and the webhook stop.

**Console**
1. Open **Monitoring**, then **Alarms**.
2. Open the alarm's action menu and choose **Stop notifications**, or **Resume notifications** for
   an alarm whose notifications are off.

The **Notifies** column shows **off** while they are stopped.

**CLI**
```sh
dcloud monitoring alarms update alarm-id --no-enabled
```

**API**
```http
PUT /monitoring/api/alarms/alarm-id
{ "enabled": false }
```

**Terraform**
Set `enabled = false` on the `dcloud_monitoring_alarm`.

## Change the rule or the recipients

**Console:** not available. The console only stops and resumes notifications; change the rest with the CLI, the API or Terraform.
**CLI**
```sh
dcloud monitoring alarms update alarm-id --threshold 90 --evaluation-periods 5
```

**API**
```http
PUT /monitoring/api/alarms/alarm-id
{ "threshold": 90, "evaluationPeriods": 5, "notifyEmails": ["ops@example.com", "oncall@example.com"] }
```

`notifyEmails` replaces the list; `"webhookUrl": null` removes the webhook. Changing
`resourceType` without `dimensions` leaves the alarm with none.

**Terraform**
Change the arguments of the `dcloud_monitoring_alarm` and apply.

## When the change is refused

The alarm as it would be after the change is checked as a whole:

- `400` "An alarm looks back at most one day (period × evaluation periods)" when the new period
  or evaluation periods, with the other's current value, pass one day; when the request sets both,
  the message starts "evaluationPeriods: ".
- `400` when the new metric is not recorded for the resource type, `404` "Resource not found" for
  a new resource your organization does not have.
- `409` "An alarm named "…" already exists" for a new name that is taken.
- `404` "Alarm not found" when your organization has no such alarm.

## Related

- [How alarms work](how-alarms-work.md)
- [Delete an alarm](delete-an-alarm.md)
- `monitoring.alarms.update` · `dcloud monitoring alarms update` · `dcloud_monitoring_alarm`
