Back to Nightingale

Alert rules

aiagent/skill/embedded/builtin/skill-creator/api/alert-rules.md

9.1.17.1 KB
Original Source

Alert rules

Alerting rule definitions: what condition fires an event, on which datasource, at what severity, and how the alert is routed to notifications. Use these endpoints to read rule definitions, audit coverage, or summarize how alerting is configured across business groups.

Gateway call: GET. Include the /api/n9e prefix in path. Response {"ok":true,"status":200,"data":{"dat":<payload>,"err":""}} — read data["dat"]. Protocol: see ../n9e-api.md.

Endpoints

PathPurposedat shape
/busi-groups/alert-rulesRules across the groups your RBAC allows.Pattern B — bare array of AlertRule
/busi-group/:id/alert-rulesRules of ONE business group (:id in path).Pattern B — bare array of AlertRule
/alert-rule/:aridOne rule's full definition (:arid in path).single AlertRule object

Query parameters

ParamTypeRequiredDefaultMeaningEndpoint
gidsstring (csv of group ids)noempty = your groups (all groups for admin)Restrict to specific business group ids, e.g. "1,2"./busi-groups/alert-rules
stimestring (unix secs)noStart of a recent-window used to attach a per-rule event count./busi-groups/alert-rules
etimestring (unix secs)noEnd of that recent-window. Pass together with stime./busi-groups/alert-rules

/busi-group/:id/alert-rules and /alert-rule/:arid take no query params (the id is in the path). Stringify all query values (see ../n9e-api.md).

Response — dat payload

Pattern B (bare array) for the two list endpoints; a single object for /alert-rule/:arid. Each rule is an AlertRule (from models/alert_rule.go):

Field (json)TypeMeaning
idint64Rule id.
group_idint64Business group id this rule belongs to.
catestringDatasource category, e.g. prometheus, elasticsearch, mysql, host, tdengine, ck. Drives the shape of rule_config.
datasource_ids[]int64(computed) Resolved datasource ids the rule targets (list-page convenience field; omitted when empty).
datasource_queries[]DatasourceQueryDatasource selectors: each is {match_type, op, values} (how to match which datasources apply).
clusterstringDeprecated (use datasource_queries). Legacy space-separated cluster list.
namestringRule name.
notestringFree-text note; included in notifications.
prodstringProduct line; empty means core n9e.
algorithmstringDetection algorithm; empty = threshold, holtwinters = anomaly.
algo_paramsinterface{}(computed) Parameters for the algorithm (FE-facing form of the stored params).
delayintSeconds to delay evaluation.
severityint1 = Emergency, 2 = Warning, 3 = Notice.
severities[]int(computed) Multiple severities when a rule emits more than one level.
disabledint0 = enabled, 1 = disabled.
prom_for_durationintDeprecated (use cron_pattern). Prometheus for duration, seconds.
prom_qlstringSingle PromQL expression (simple prometheus rules).
rule_configinterface{}(computed) The detection config (queries/thresholds/triggers). Big nested JSON whose structure varies by datasource category cate — do not assume a fixed schema.
event_relabel_config[]*RelabelConfig(computed) Relabel rules applied to generated events.
prom_eval_intervalintEvaluation interval, seconds.
enable_stimestring(computed) Deprecated. Single effective-window start "HH:MM" (FE).
enable_stimes[]string(computed) Effective-window start times (FE).
enable_etimestring(computed) Deprecated. Single effective-window end "HH:MM" (FE).
enable_etimes[]string(computed) Effective-window end times (FE).
enable_days_of_week[]string(computed) Deprecated. Active weekdays (FE).
enable_days_of_weeks[][]string(computed) Active weekdays per window (FE).
enable_in_bgint0 = global, 1 = only within the one business group.
notify_recoveredintWhether to notify on recovery (1) or not (0).
notify_channels[]string(computed) Deprecated. Legacy channel list (sms/voice/email/dingtalk/…).
notify_groups_obj[]UserGroup(computed) Deprecated. Resolved notify user-group objects (FE).
notify_groups[]string(computed) Deprecated. Notify user-group ids (FE).
notify_repeat_stepintRepeat-notify interval, minutes.
notify_max_numberintMax number of repeat notifications.
recover_durationint64Seconds a condition must stay clear before it counts as recovered.
callbacks[]string(computed) Deprecated. Legacy callback URLs (FE).
runbook_urlstringRunbook / SOP URL.
append_tags[]string(computed) Tags appended to events, e.g. service=n9e (FE).
annotationsmap[string]string(computed) Extra annotations attached to events (FE).
extra_configinterface{}(computed) Miscellaneous extra config (FE).
create_atint64Creation time, unix seconds.
create_bystringCreator username.
update_atint64Last-update time, unix seconds.
update_bystringLast-updater username.
uuidint64(computed) Template identifier.
cur_event_countint64(computed) Recent-event count attached when stime/etime are passed to the list endpoint.
update_by_nicknamestring(computed) Display nickname of the last updater (FE).
cron_patternstringCron expression controlling when the rule evaluates.
time_zonestringTimezone for evaluation, e.g. Asia/Shanghai, UTC; empty = default.
notify_rule_ids[]int64Ids of notification rules used for routing (new notify system).
pipeline_configs[]PipelineConfigEvent-pipeline configs bound to this rule.
notify_versionintNotification system version: 0 = old, 1 = new.

Example

Request:

json
{"method":"GET","path":"/api/n9e/busi-groups/alert-rules","query":{"gids":"1,2"}}

Response (trimmed):

json
{
  "ok": true,
  "status": 200,
  "data": {
    "dat": [
      {
        "id": 12,
        "group_id": 1,
        "cate": "prometheus",
        "datasource_queries": [{"match_type": 0, "op": "in", "values": [3]}],
        "name": "Host CPU high",
        "note": "cpu usage over 90% for 5m",
        "prod": "",
        "algorithm": "",
        "severity": 2,
        "disabled": 0,
        "prom_ql": "",
        "rule_config": { "queries": [], "triggers": [] },
        "prom_eval_interval": 15,
        "notify_recovered": 1,
        "notify_repeat_step": 60,
        "recover_duration": 0,
        "runbook_url": "",
        "append_tags": ["team=infra"],
        "cron_pattern": "",
        "time_zone": "Asia/Shanghai",
        "notify_rule_ids": [4],
        "notify_version": 1,
        "cur_event_count": 3,
        "create_by": "root",
        "create_at": 1719800000,
        "update_by": "root",
        "update_at": 1719805000
      }
    ],
    "err": ""
  }
}