Alert rules

Endpoint: /api/metrics/alert-rules/

Alert rules watch a server’s metrics and raise an alert when a value crosses a threshold, using the data the agent has already sent. Rules are evaluated on Alpacon’s own schedule, about once a minute—see Monitoring rules for how a rule decides to fire and clear.

Requires the Metrics extension to be enabled for the workspace, for every action—including reading the seeded default disk-usage rule that every server carries regardless of plan. That rule is still evaluated on a workspace with the extension off; this API just isn’t how you’d read it there.

List alert rules

Retrieve a paginated list of alert rules.

Request

GET /api/metrics/alert-rules/

Query parameters

ParameterTypeDescription
namestringFilter by rule name
ownerstringFilter by owner username
targetstringFilter by target metric
thresholdnumberFilter by threshold
operatorstringFilter by direction (gte or lte)
devicestringFilter by device
severitystringFilter by severity (critical, warning, info)
is_defaultbooleanFilter by default status
serverUUIDOnly rules attached to this server
exclude_serverUUIDOnly rules not attached to this server
searchstringSearch across name, target, and default status
orderingstringSort order. Default: -added_at
pageintegerPage number
page_sizeintegerResults per page (default: 15, max: 100)

Response

{
  "count": 2,
  "next": null,
  "previous": null,
  "results": [
    {
      "id": "3f1c9b2e-6a4d-4e8f-9b1a-2c3d4e5f6a7b",
      "owner": null,
      "name": "Core disk usage",
      "target": "disk-usage",
      "threshold": 90,
      "operator": "gte",
      "duration_s": 0,
      "recovery_threshold": 85,
      "no_data_after_s": null,
      "device": "",
      "severity": "warning",
      "is_default": true
    },
    {
      "id": "8c4d6e2a-1b3f-4a5c-8d9e-0f1a2b3c4d5e",
      "owner": {
        "id": 1,
        "name": "admin",
        "email": "admin@example.com"
      },
      "name": "Sustained high CPU",
      "target": "cpu-usage",
      "threshold": 80,
      "operator": "gte",
      "duration_s": 300,
      "recovery_threshold": 70,
      "no_data_after_s": 600,
      "device": "",
      "severity": "critical",
      "is_default": false
    }
  ]
}

Required scope: alert_rule:read

Example

curl -X GET "https://your-workspace.us1.alpacon.io/api/metrics/alert-rules/?target=cpu-usage" \
  -H "Authorization: token=\"alpat-xxxxxxxxxxxxxxxxxx\""

Error responses

StatusError codeDescription
400metrics_alert_rule_existsA default rule already exists for this target and device
400metrics_alert_rule_recovery_threshold_invalidrecovery_threshold is not on the recovering side of threshold
400metrics_alert_rule_no_data_window_too_shortno_data_after_s is shorter than this target’s collection interval
400metrics_alert_rule_no_data_window_too_longno_data_after_s is longer than 86400 seconds (24 hours)
400metrics_alert_rule_device_not_supporteddevice was set on a host-wide target (cpu-usage or memory-usage)
400metrics_alert_rule_cannot_be_deletedTried to delete a rule while is_default is still true
401UNAUTHORIZEDInvalid or missing authentication
403FORBIDDENInsufficient permissions, or the Metrics extension isn’t enabled for this workspace
404NOT_FOUNDAlert rule not found
Last updated: