Kibana Alerting Rules
Core Concepts
A rule has three parts: conditions (what to detect), schedule (how often to check), and actions (what
happens when conditions are met). When conditions are met, the rule creates alerts, which trigger actions via
connectors.
Authentication
All alerting API calls require either API key auth or Basic auth. Every mutating request must include the kbn-xsrf
header.
kbn-xsrf: true
API Reference
Base path: <kibana_url>/api/alerting (or /s/<space_id>/api/alerting for non-default spaces).
| Operation |
Method |
Endpoint |
| Create rule |
POST |
/api/alerting/rule/{id} |
| Update rule |
PUT |
/api/alerting/rule/{id} |
| Get rule |
GET |
/api/alerting/rule/{id} |
| Delete rule |
DELETE |
/api/alerting/rule/{id} |
| Find rules |
GET |
/api/alerting/rules/_find |
| List rule types |
GET |
/api/alerting/rule_types |
| Enable rule |
POST |
/api/alerting/rule/{id}/_enable |
| Disable rule |
POST |
/api/alerting/rule/{id}/_disable |
| Mute all alerts |
POST |
/api/alerting/rule/{id}/_mute_all |
| Unmute all alerts |
POST |
/api/alerting/rule/{id}/_unmute_all |
Creating a Rule
Required Fields
| Field |
Type |
Description |
name |
string |
Display name (does not need to be unique) |
rule_type_id |
string |
The rule type (e.g., .es-query, .index-threshold) |
consumer |
string |
Owning app: alerts, apm, discover, infrastructure, logs, metrics, ml, monitoring, securitySolution, siem, stackAlerts, uptime |
params |
object |
Rule-type-specific parameters |
schedule |
object |
Check interval, e.g., {"interval": "5m"} |
Example: Create an Elasticsearch Query Rule
curl -X POST "https://my-kibana:5601/api/alerting/rule/my-rule-id" \
-H "kbn-xsrf: true" \
-H "Content-Type: application/json" \
-H "Authorization: ApiKey <your-api-key>" \
-d '{
"name": "High error rate",
"rule_type_id": ".es-query",
"consumer": "stackAlerts",
"schedule": { "interval": "5m" },
"params": {
"index": ["logs-*"],
"timeField": "@timestamp",
"esQuery": "{\"query\":{\"match\":{\"log.level\":\"error\"}}}",
"threshold": [100],
"thresholdComparator": ">",
"timeWindowSize": 5,
"timeWindowUnit": "m",
"size": 100
},
"actions": [
{
"id": "my-slack-connector-id",
"group": "query matched",
"params": {
"message": "Alert: {{rule.name}} - {{context.hits}} hits detected"
}
}
],
"tags": ["production", "errors"]
}'
Finding Rules
curl -X GET "https://my-kibana:5601/api/alerting/rules/_find?per_page=20&page=1&search=cpu&sort_field=name&sort_order=asc" \
-H "Authorization: ApiKey <your-api-key>"
Lifecycle Operations
curl -X POST ".../api/alerting/rule/{id}/_enable" -H "kbn-xsrf: true"
curl -X POST ".../api/alerting/rule/{id}/_disable" -H "kbn-xsrf: true"
curl -X POST ".../api/alerting/rule/{id}/_mute_all" -H "kbn-xsrf: true"
curl -X DELETE ".../api/alerting/rule/{id}" -H "kbn-xsrf: true"
Terraform Provider
resource "elasticstack_kibana_alerting_rule" "cpu_alert" {
name = "CPU usage critical"
consumer = "stackAlerts"
rule_type_id = ".index-threshold"
interval = "1m"
enabled = true
params = jsonencode({
index = ["metrics-*"]
timeField = "@timestamp"
aggType = "avg"
aggField = "system.cpu.total.pct"
groupBy = "top"
termField = "host.name"
termSize = 10
threshold = [0.9]
thresholdComparator = ">"
timeWindowSize = 5
timeWindowUnit = "m"
})
tags = ["infrastructure", "production"]
}
Best Practices
- Set action frequency per action, not per rule. The
notify_when field at the rule level is deprecated in favor
of per-action frequency objects.
- Use alert summaries to reduce notification noise. Configure actions to send periodic summaries.
- Always add a recovery action. Rules without a recovery action leave incidents open in PagerDuty, Jira, and
ServiceNow indefinitely.
- Set a reasonable check interval. The minimum recommended interval is
1m.
- Use
alert_delay to suppress transient spikes. Setting {"active": 3} means the alert only fires after 3
consecutive runs match the condition.
- Tag rules consistently. Use tags like
production, staging, team-platform for filtering.
Common Pitfalls
- Missing
kbn-xsrf header. All POST, PUT, DELETE requests require kbn-xsrf: true.
- Wrong
consumer value. Check the rule type's supported consumers via GET /api/alerting/rule_types.
- Immutable fields on update.
rule_type_id and consumer cannot be changed with PUT.
- Rule-level
notify_when is deprecated. Always use frequency inside each action object.
- API key ownership. Rules run using the API key of the user who created them. If that user's permissions change,
the rule may fail silently.
Guidelines
- Include
kbn-xsrf: true on every POST, PUT, and DELETE.
- Set
frequency inside each action object — rule-level notify_when and throttle are deprecated.
rule_type_id and consumer are immutable after creation; delete and recreate the rule to change them.
- Prefix paths with
/s/<space_id>/api/alerting/ for non-default Kibana Spaces.
- Always pair an active action with a
Recovered action to auto-close incidents.
- Run
GET /api/alerting/rule_types first to discover valid consumer values and action group names.
1---2name: kibana-alerting-rules3description: Create and manage Kibana alerting rules via REST API or Terraform. Use when creating, updating, or managing rule lifecycle (enable, disable, mute, snooze) or rules-as-code workflows.4---56# Kibana Alerting Rules78## Core Concepts910A rule has three parts: **conditions** (what to detect), **schedule** (how often to check), and **actions** (what11happens when conditions are met). When conditions are met, the rule creates **alerts**, which trigger **actions** via12**connectors**.1314## Authentication1516All alerting API calls require either API key auth or Basic auth. Every mutating request must include the `kbn-xsrf`17header.1819```http20kbn-xsrf: true21```2223## API Reference2425Base path: `<kibana_url>/api/alerting` (or `/s/<space_id>/api/alerting` for non-default spaces).2627| Operation | Method | Endpoint |28| ----------------- | ------ | ---------------------------------------------------------- |29| Create rule | POST | `/api/alerting/rule/{id}` |30| Update rule | PUT | `/api/alerting/rule/{id}` |31| Get rule | GET | `/api/alerting/rule/{id}` |32| Delete rule | DELETE | `/api/alerting/rule/{id}` |33| Find rules | GET | `/api/alerting/rules/_find` |34| List rule types | GET | `/api/alerting/rule_types` |35| Enable rule | POST | `/api/alerting/rule/{id}/_enable` |36| Disable rule | POST | `/api/alerting/rule/{id}/_disable` |37| Mute all alerts | POST | `/api/alerting/rule/{id}/_mute_all` |38| Unmute all alerts | POST | `/api/alerting/rule/{id}/_unmute_all` |3940## Creating a Rule4142### Required Fields4344| Field | Type | Description |45| -------------- | ------ | ----------------------------------------------------------------------------------------------------------------------------------------------------- |46| `name` | string | Display name (does not need to be unique) |47| `rule_type_id` | string | The rule type (e.g., `.es-query`, `.index-threshold`) |48| `consumer` | string | Owning app: `alerts`, `apm`, `discover`, `infrastructure`, `logs`, `metrics`, `ml`, `monitoring`, `securitySolution`, `siem`, `stackAlerts`, `uptime` |49| `params` | object | Rule-type-specific parameters |50| `schedule` | object | Check interval, e.g., `{"interval": "5m"}` |5152### Example: Create an Elasticsearch Query Rule5354```bash55curl -X POST "https://my-kibana:5601/api/alerting/rule/my-rule-id" \56 -H "kbn-xsrf: true" \57 -H "Content-Type: application/json" \58 -H "Authorization: ApiKey <your-api-key>" \59 -d '{60 "name": "High error rate",61 "rule_type_id": ".es-query",62 "consumer": "stackAlerts",63 "schedule": { "interval": "5m" },64 "params": {65 "index": ["logs-*"],66 "timeField": "@timestamp",67 "esQuery": "{\"query\":{\"match\":{\"log.level\":\"error\"}}}",68 "threshold": [100],69 "thresholdComparator": ">",70 "timeWindowSize": 5,71 "timeWindowUnit": "m",72 "size": 10073 },74 "actions": [75 {76 "id": "my-slack-connector-id",77 "group": "query matched",78 "params": {79 "message": "Alert: {{rule.name}} - {{context.hits}} hits detected"80 }81 }82 ],83 "tags": ["production", "errors"]84 }'85```8687## Finding Rules8889```bash90curl -X GET "https://my-kibana:5601/api/alerting/rules/_find?per_page=20&page=1&search=cpu&sort_field=name&sort_order=asc" \91 -H "Authorization: ApiKey <your-api-key>"92```9394## Lifecycle Operations9596```bash97curl -X POST ".../api/alerting/rule/{id}/_enable" -H "kbn-xsrf: true"98curl -X POST ".../api/alerting/rule/{id}/_disable" -H "kbn-xsrf: true"99curl -X POST ".../api/alerting/rule/{id}/_mute_all" -H "kbn-xsrf: true"100curl -X DELETE ".../api/alerting/rule/{id}" -H "kbn-xsrf: true"101```102103## Terraform Provider104105```hcl106resource "elasticstack_kibana_alerting_rule" "cpu_alert" {107 name = "CPU usage critical"108 consumer = "stackAlerts"109 rule_type_id = ".index-threshold"110 interval = "1m"111 enabled = true112113 params = jsonencode({114 index = ["metrics-*"]115 timeField = "@timestamp"116 aggType = "avg"117 aggField = "system.cpu.total.pct"118 groupBy = "top"119 termField = "host.name"120 termSize = 10121 threshold = [0.9]122 thresholdComparator = ">"123 timeWindowSize = 5124 timeWindowUnit = "m"125 })126127 tags = ["infrastructure", "production"]128}129```130131## Best Practices1321331. **Set action frequency per action, not per rule.** The `notify_when` field at the rule level is deprecated in favor134 of per-action `frequency` objects.1352. **Use alert summaries to reduce notification noise.** Configure actions to send periodic summaries.1363. **Always add a recovery action.** Rules without a recovery action leave incidents open in PagerDuty, Jira, and137 ServiceNow indefinitely.1384. **Set a reasonable check interval.** The minimum recommended interval is `1m`.1395. **Use `alert_delay` to suppress transient spikes.** Setting `{"active": 3}` means the alert only fires after 3140 consecutive runs match the condition.1416. **Tag rules consistently.** Use tags like `production`, `staging`, `team-platform` for filtering.142143## Common Pitfalls1441451. **Missing `kbn-xsrf` header.** All POST, PUT, DELETE requests require `kbn-xsrf: true`.1462. **Wrong `consumer` value.** Check the rule type's supported consumers via `GET /api/alerting/rule_types`.1473. **Immutable fields on update.** `rule_type_id` and `consumer` cannot be changed with PUT.1484. **Rule-level `notify_when` is deprecated.** Always use `frequency` inside each action object.1495. **API key ownership.** Rules run using the API key of the user who created them. If that user's permissions change,150 the rule may fail silently.151152## Guidelines153154- Include `kbn-xsrf: true` on every POST, PUT, and DELETE.155- Set `frequency` inside each action object — rule-level `notify_when` and `throttle` are deprecated.156- `rule_type_id` and `consumer` are immutable after creation; delete and recreate the rule to change them.157- Prefix paths with `/s/<space_id>/api/alerting/` for non-default Kibana Spaces.158- Always pair an active action with a `Recovered` action to auto-close incidents.159- Run `GET /api/alerting/rule_types` first to discover valid `consumer` values and action group names.