Back to Nightingale

Alert events (historical & active)

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

9.1.18.9 KB
Original Source

Alert events (historical & active)

Fired/recovered alert events. Use these for alert stats, recent-alert summaries, and incident lists. "Historical" = every fired and recovered event ever written (server-side paged); "active" = the events currently firing right now.

Gateway call: GET. Include the /api/n9e prefix in path (e.g. /api/n9e/alert-his-events/list). Response {"ok":true,"status":200,"data":{"dat":<payload>,"err":""}} — read data["dat"]. Protocol + envelope: see ../n9e-api.md.

Endpoints

PathPurposedat shape
/alert-his-events/listHistorical events (fired + recovered), server-side paged. Main endpoint for "last N hours" stats.Pattern A {"list":[<AlertHisEvent>...],"total":N}
/alert-cur-events/listCurrently-active (firing) events, server-side paged.Pattern A {"list":[<AlertCurEvent>...],"total":N}
/alert-his-event/:eidOne historical event by id (:eid in path).Single object — AlertCurEvent shape (the server converts the historical row to cur form; note is_recovered becomes a bool here)
/alert-cur-event/:eidOne active event by id (:eid in path).Single object — AlertCurEvent

Notes:

  • List rows come pre-enriched: notify_groups_obj (resolved user-group objects) is filled on every list row. The :eid detail endpoints additionally fill notify_version and notify_rules.
  • Order: newest first (trigger_time desc).
  • Both :eid endpoints return an AlertCurEvent-shaped object, so read them with the AlertCurEvent field set below (including the type note on is_recovered).

Query parameters (/list endpoints)

ParamTypeRequiredDefaultMeaning
hoursint (string)one time sourceLast N hours window. Sets stime = now - N*3600, etime = now + 24h.
stimeint (unix secs, string)one time source0Window start. Use instead of hours.
etimeint (unix secs, string)one time source0Window end (if stime set but etime omitted, server uses now + 24h).
pint (string)no1Page number, from 1.
limitint (string)no20Page size.
bgidint (string)no0Business-group id. 0/absent = all groups your RBAC allows.
severityint / csv (string)nosee notehis: single int, -1 = all; cur: comma-separated list, empty = all. 1=Critical, 2=Warning, 3=Info.
is_recoveredint (string)no-1his only: 0=firing, 1=recovered, -1=all.
querystringno""Text substring; matches rule_name or tags (space-separated terms are AND-ed).
ridint (string)no0Filter by alert rule id.
datasource_idscsv (string)noFilter by datasource ids.
catestringno$allDatasource category (e.g. prometheus); $all = no filter.
prodscsv (string)no""Rule products/types (e.g. metric,host); empty = all.
my_groupsbool (string)nofalsecur only: restrict to your own business groups.
event_idscsv (string)nocur only: fetch specific event ids.

Always pass a window (hours, or stime/etime). Without one, historical queries default to stime=0 (all time).

Response — dat payload

/list endpoints: Pattern A — dat = {"list": [...], "total": N}; rows are in dat["list"], count in dat["total"]. /:eid endpoints: a single object.

Each historical list row is an AlertHisEvent. Fields marked (computed) are gorm:"-" — derived server-side, not raw DB columns.

Field (json)TypeMeaning
idint64Event id (historical id; reused as the active-event id).
catestringDatasource category (e.g. prometheus, host).
is_recoveredint0 = firing, 1 = recovered.
datasource_idint64Datasource id the rule ran against.
clusterstringLegacy datasource cluster name.
group_idint64Business group id.
group_namestringBusiness group name.
hashstringDedup hash (rule_id + vector key); identifies the alert series.
rule_idint64Alert rule id.
rule_namestringAlert rule name (rendered).
rule_notestringAlert rule note/description.
rule_prodstringRule product/type (e.g. metric, host, logging).
rule_algostringAnomaly-detection algorithm; empty for threshold rules.
severityint1=Critical, 2=Warning, 3=Info.
prom_for_durationint"for" duration (seconds) the condition must hold before firing.
prom_qlstringPromQL (Prometheus/legacy rules).
rule_configobjectParsed rule config (structure varies by rule type). (computed)
prom_eval_intervalintRule evaluation interval (seconds).
callbacks[]stringCallback URLs. (computed)
runbook_urlstringRunbook URL.
notify_recoveredintWhether recovery is notified (1/0).
notify_channels[]stringNotify channel keys. (computed)
notify_groups[]stringNotify user-group ids (as strings). (computed)
notify_groups_obj[]UserGroupResolved user-group objects (filled on list rows). (computed)
target_identstringTarget ident (host identifier), if host-scoped.
target_notestringTarget note.
trigger_timeint64Unix seconds when the event triggered.
trigger_valuestringThe value that triggered the alert.
recover_timeint64Unix seconds when recovered (0 while firing).
last_eval_timeint64Unix seconds of the last evaluation for this event.
tags[]stringEvent tags as "k=v" strings. (computed)
original_tags[]stringTags before relabeling. (computed)
annotationsmap[string]stringAnnotation key→value map. (computed)
notify_cur_numberintCurrent notification count for this event.
first_trigger_timeint64Unix seconds of the first trigger in a continuous alert.
extra_configobjectExtra config carried on the event. (computed)
notify_rule_ids[]int64Notify-rule ids (new notification model).
notify_versionint0 = legacy notify, 1 = notify-rules model. (computed)
notify_rules[]Resolved notify rules, each {"id":int64,"name":string}. (computed)

AlertCurEvent — additional/differing fields

The active-event object (and both /:eid responses) shares all fields above, with these differences and additions:

Field (json)TypeMeaning
is_recoveredboolDiffers from his (int): here true/false. (computed)
trigger_valuesstringTrigger value (mirror of trigger_value). (computed)
trigger_values_jsonobject{"values_with_unit": {name → {value, unit, ...}}} — formatted trigger values. (computed)
tags_mapmap[string]stringTags parsed into a key→value map. (computed)
notify_users_obj[]UserResolved notify users (notification pipeline). (computed)
last_sent_timeint64Unix seconds of the last notification sent. (computed)
first_eval_timeint64Unix seconds of the first anomaly detection. (computed)
statusintEvent status flag. (computed)
claimantstringWho claimed/acknowledged the event. (computed)
sub_rule_idint64Sub-rule id (for rules that expand into sub-rules). (computed)
extra_info[]stringExtra info lines. (computed)
targetobjectResolved target object (host details), if any. (computed)
recover_configobjectRecovery configuration for the event. (computed)
rule_hashstringRule hash. (computed)
shot_image_base64map[string]stringScreenshot images, base64-encoded. (computed)
extra_info_map[]map[string]stringExtra info as a list of key→value maps. (computed)
notify_rule_idint64Single notify-rule id (convenience). (computed)
notify_rule_namestringSingle notify-rule name (convenience). (computed)

Example

Request:

json
{"method":"GET","path":"/api/n9e/alert-his-events/list","query":{"hours":"24","limit":"100","p":"1"}}

Response (trimmed):

json
{
  "ok": true,
  "status": 200,
  "data": {
    "dat": {
      "total": 342,
      "list": [
        {
          "id": 90271,
          "cate": "prometheus",
          "is_recovered": 0,
          "datasource_id": 1,
          "group_id": 2,
          "group_name": "ops-team",
          "rule_id": 88,
          "rule_name": "Host CPU usage high",
          "rule_prod": "metric",
          "severity": 2,
          "prom_ql": "cpu_usage_idle < 10",
          "target_ident": "host-01",
          "trigger_time": 1751330400,
          "trigger_value": "6.3",
          "recover_time": 0,
          "last_eval_time": 1751330460,
          "tags": ["ident=host-01", "app=web"],
          "annotations": {"summary": "CPU idle 6.3% on host-01"},
          "notify_groups_obj": [{"id": 3, "name": "ops-oncall"}]
        }
      ]
    },
    "err": ""
  }
}