Loading...
Loading...
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.
npx skill4agent add elastic/agent-skills kibana-alerting-ruleskbn-xsrfkbn-xsrf: trueallread<kibana_url>/api/alerting/s/<space_id>/api/alerting| Operation | Method | Endpoint |
|---|---|---|
| Create rule | POST | |
| Update rule | PUT | |
| Get rule | GET | |
| Delete rule | DELETE | |
| Find rules | GET | |
| List rule types | GET | |
| Enable rule | POST | |
| Disable rule | POST | |
| Mute all alerts | POST | |
| Unmute all alerts | POST | |
| Mute alert | POST | |
| Unmute alert | POST | |
| Update API key | POST | |
| Create snooze | POST | |
| Delete snooze | DELETE | |
| Health check | GET | |
| Field | Type | Description |
|---|---|---|
| string | Display name (does not need to be unique) |
| string | The rule type (e.g., |
| string | Owning app: |
| object | Rule-type-specific parameters |
| object | Check interval, e.g., |
| Field | Type | Description |
|---|---|---|
| array | Actions to run when conditions are met (each references a connector) |
| array | Tags for organizing rules |
| boolean | Whether the rule runs immediately (default: true) |
| string | |
| object | Alert only after N consecutive matches, e.g., |
| object/null | Override flapping detection settings |
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"
},
"frequency": {
"summary": false,
"notify_when": "onActionGroupChange"
}
}
],
"tags": ["production", "errors"]
}'rule_type_id.index-threshold.es-queryparamsGET /api/alerting/rule_typesPUT /api/alerting/rule/{id}rule_type_idconsumercurl -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>"per_pagepagesearchdefault_search_operatorsearch_fieldssort_fieldsort_orderhas_referencefieldsfilterfilter_consumersfilterfilter=alert.attributes.tags:"production"# Enable
curl -X POST ".../api/alerting/rule/{id}/_enable" -H "kbn-xsrf: true"
# Disable
curl -X POST ".../api/alerting/rule/{id}/_disable" -H "kbn-xsrf: true"
# Mute all alerts
curl -X POST ".../api/alerting/rule/{id}/_mute_all" -H "kbn-xsrf: true"
# Mute specific alert
curl -X POST ".../api/alerting/rule/{rule_id}/alert/{alert_id}/_mute" -H "kbn-xsrf: true"
# Delete
curl -X DELETE ".../api/alerting/rule/{id}" -H "kbn-xsrf: true"elasticstackelasticstack_kibana_alerting_ruleterraform {
required_providers {
elasticstack = {
source = "elastic/elasticstack"
}
}
}
provider "elasticstack" {
kibana {
endpoints = ["https://my-kibana:5601"]
api_key = var.kibana_api_key
}
}
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"]
}paramsjsonencode()elasticstack_kibana_action_connectorterraform import elasticstack_kibana_alerting_rule.my_rule <space_id>/<rule_id>defaultPreview feature — available from Elastic Stack 9.3 and Elastic Cloud Serverless. APIs may change.
params: {}eventcurl -X PUT "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",
"schedule": { "interval": "5m" },
"params": { ... },
"actions": [
{
"id": "<workflow-id>",
"group": "query matched",
"params": {},
"frequency": { "summary": false, "notify_when": "onActionGroupChange" }
}
]
}'enabled: true{{ event }}kibana-connectorsgroupparamsfrequencygroup"query matched""Recovered"GET /api/alerting/rule_typesfrequency.summarytruefalsefrequency.notify_whenonActionGroupChangeonActiveAlertonThrottleIntervalfrequency.throttle"10m"onThrottleInterval{{rule.name}}{{context.*}}{{alerts.new.count}}EvalMathFormatDateParseHjsonkibana-connectorsnotify_whenfrequency"summary": truethrottleonActionGroupChangeonActiveAlertonThrottleInterval"30m"eventAction: "resolve"Recovered1mxpack.alerting.rules.minimumScheduleInterval.valuealert_delay{"active": 3}flappingserver.publicBaseUrlserver.publicBaseUrlkibana.yml{{rule.url}}{{kibanaBaseUrl}}productionstagingteam-platform/s/<space_id>/kbn-xsrfkbn-xsrf: trueconsumerobservabilityinfrastructureGET /api/alerting/rule_typesrule_type_idconsumernotify_whenthrottlefrequency/api/alerting/rule/{id}_update_api_keyxpack.alerting.rules.run.actions.maxxpack.alerting.rules.run.timeout5mrule_type_id: ".index-threshold"aggField: "system.cpu.total.pct"threshold: [0.9]timeWindowSize: 5"threshold met"RecoveredGET /api/alerting/rules/_findfilter=alert.attributes.tags:"production"sort_field=namePOST /api/alerting/rule/abc123/_disable_enablekbn-xsrf: truefrequencynotify_whenthrottlerule_type_idconsumer/s/<space_id>/api/alerting/RecoveredGET /api/alerting/rule_typesconsumeralert_delayflapping