pydo.insights.create_alert_rule()

Generated on 13 Nov 2026 from pydo version v0.46.0

Usage

client.insights.create_alert_rule(
    body={
        "spec": {...},
        "status": "ALERT_RULE_STATUS_ACTIVE",
    },
)
Returns JSON Raises HttpResponseError

Description

To create an alert rule, send a POST request to /v2/insights/alert-rules with a spec containing name, query, thresholds, and at least one notification_channels binding. status defaults to ALERT_RULE_STATUS_ACTIVE when omitted. re_alert_duration defaults to RE_ALERT_DURATION_4H when omitted.

query.metric must be a dotted OpenTelemetry name such as do.droplets.cpu_utilization. Underscored Prometheus-style names are rejected with 422 Unprocessable Entity.

Parameters

spec object required
Show child properties
name string required

Example: High CPU

A human-readable name for the alert rule.

query object required

Metrics query that the alert rule evaluates. metric must be a dotted
OpenTelemetry name (for example do.droplets.cpu_utilization). Underscored
Prometheus-style names are rejected. When resource_urns is omitted or empty,
the rule is not scoped to specific resources.

Show child properties
metric string required

Example: do.droplets.cpu_utilization

Dotted OpenTelemetry metric name to evaluate
(for example do.droplets.cpu_utilization).

filters array of objects optional

Optional label filters applied to the metric series.

Show child properties
field string required

Example: host_id

The metric label or field to filter on.

operator string required

Comparison operator for the filter. Allowed values:

- FILTER_OPERATOR_EQUAL = equal
- FILTER_OPERATOR_NOT_EQUAL = not_equal
- FILTER_OPERATOR_LESS_THAN = less_than
- FILTER_OPERATOR_LESS_THAN_OR_EQUAL = less_than_or_equal
- FILTER_OPERATOR_GREATER_THAN = greater_than
- FILTER_OPERATOR_GREATER_THAN_OR_EQUAL = greater_than_or_equal

One of: FILTER_OPERATOR_EQUAL, FILTER_OPERATOR_NOT_EQUAL, FILTER_OPERATOR_LESS_THAN, FILTER_OPERATOR_LESS_THAN_OR_EQUAL, FILTER_OPERATOR_GREATER_THAN, FILTER_OPERATOR_GREATER_THAN_OR_EQUAL

value string required

Example: 12345678

Value compared against the field.

resource_urns array of strings optional

Example: ['do:droplet:12345']

Optional list of DigitalOcean resource URNs the rule applies to. Empty or
omitted means the rule is not scoped to specific resources.

tags array of strings optional

Example: ['env:prod']

Optional resource tags used to select matching resources.

condition object optional

Evaluation condition for the alert rule.

Show child properties
window string optional

Time window over which the metric is evaluated. Allowed values:

- EVALUATION_WINDOW_1M = 1m
- EVALUATION_WINDOW_5M = 5m
- EVALUATION_WINDOW_10M = 10m
- EVALUATION_WINDOW_15M = 15m
- EVALUATION_WINDOW_30M = 30m
- EVALUATION_WINDOW_1H = 1h

One of: EVALUATION_WINDOW_1M, EVALUATION_WINDOW_5M, EVALUATION_WINDOW_10M, EVALUATION_WINDOW_15M, EVALUATION_WINDOW_30M, EVALUATION_WINDOW_1H

thresholds object required

Threshold configuration for the alert rule. At least one of warning or
critical must be set.

Show child properties
warning number optional

Example: 80

Warning threshold value.

critical number optional

Example: 95

Critical threshold value.

operator string required

Comparison operator applied to the aggregated metric value. Allowed
values:

- THRESHOLD_OPERATOR_EQUAL = equal
- THRESHOLD_OPERATOR_LESS_THAN_OR_EQUAL = less_than_or_equal
- THRESHOLD_OPERATOR_LESS_THAN = less_than
- THRESHOLD_OPERATOR_GREATER_THAN = greater_than
- THRESHOLD_OPERATOR_GREATER_THAN_OR_EQUAL = greater_than_or_equal
- THRESHOLD_OPERATOR_NOT_EQUAL = not_equal

One of: THRESHOLD_OPERATOR_EQUAL, THRESHOLD_OPERATOR_LESS_THAN_OR_EQUAL, THRESHOLD_OPERATOR_LESS_THAN, THRESHOLD_OPERATOR_GREATER_THAN, THRESHOLD_OPERATOR_GREATER_THAN_OR_EQUAL, THRESHOLD_OPERATOR_NOT_EQUAL

notification_channels array of objects optional

Notification channels to notify when the rule fires.

Show child properties
notification_channel_id string required

Example: 550e8400-e29b-41d4-a716-446655440000

ID of an existing notification channel owned by the account.

notify_on array of strings optional

Example: ['SEVERITY_CRITICAL']

Severities that trigger this channel. Allowed values:

- SEVERITY_WARNING = warning
- SEVERITY_CRITICAL = critical

re_alert_duration string optional

Minimum wait before re-notifying a still-firing alert. Defaults to
RE_ALERT_DURATION_4H on create when omitted. Allowed values:

- RE_ALERT_DURATION_30M = 30m
- RE_ALERT_DURATION_1H = 1h
- RE_ALERT_DURATION_4H = 4h
- RE_ALERT_DURATION_NEVER = never

One of: RE_ALERT_DURATION_30M, RE_ALERT_DURATION_1H, RE_ALERT_DURATION_4H, RE_ALERT_DURATION_NEVER

status string optional

Desired alert rule status. Allowed values:

- ALERT_RULE_STATUS_ACTIVE = active
- ALERT_RULE_STATUS_PAUSED = paused

One of: ALERT_RULE_STATUS_ACTIVE, ALERT_RULE_STATUS_PAUSED

Request Sample

Show Request Sample
import os
from pydo import Client

client = Client(token=os.environ.get("DIGITALOCEAN_TOKEN"))

req = {
  "spec": {
    "name": "High CPU",
    "query": {
      "metric": "do.droplets.cpu_utilization",
      "resource_urns": [
        "do:droplet:12345"
      ],
      "tags": [
        "env:prod"
      ]
    },
    "condition": {
      "window": "EVALUATION_WINDOW_5M"
    },
    "thresholds": {
      "warning": 80,
      "critical": 95,
      "operator": "THRESHOLD_OPERATOR_GREATER_THAN"
    },
    "notification_channels": [
      {
        "notification_channel_id": "550e8400-e29b-41d4-a716-446655440000",
        "notify_on": [
          "SEVERITY_CRITICAL"
        ]
      }
    ],
    "re_alert_duration": "RE_ALERT_DURATION_4H"
  }
}

resp = client.insights.create_alert_rule(body=req)

Response Example

Show Response Example
{
  "alert_rule": {
    "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
    "spec": {
      "name": "High CPU",
      "query": {
        "metric": "do.droplets.cpu_utilization",
        "resource_urns": [
          "do:droplet:12345"
        ],
        "tags": [
          "env:prod"
        ]
      },
      "condition": {
        "window": "EVALUATION_WINDOW_5M"
      },
      "thresholds": {
        "warning": 80,
        "critical": 95,
        "operator": "THRESHOLD_OPERATOR_GREATER_THAN"
      },
      "notification_channels": [
        {
          "notification_channel_id": "550e8400-e29b-41d4-a716-446655440000",
          "notify_on": [
            "SEVERITY_CRITICAL"
          ]
        }
      ],
      "re_alert_duration": "RE_ALERT_DURATION_4H"
    },
    "status": "ALERT_RULE_STATUS_ACTIVE",
    "created_at": "2026-09-03T10:00:00Z",
    "updated_at": "2026-09-03T10:00:00Z"
  }
}

More Information

See /v2/insights/alert-rules in the API reference for additional detail on responses, headers, parameters, and more.

We can't find any results for your search.

Try using different keywords or simplifying your search terms.