Back to Nightingale

Alert subscriptions

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

9.1.16.0 KB
Original Source

Alert subscriptions

Alert subscriptions ("subscribes") are rules that subscribe a user group (or, in the new notify model, a set of notify rules) to alert events matching a filter — by rule, product, datasource, severity, tags, and busi-group. A subscription can also redefine routing for the matched events in the legacy model: override severity, notification channels, and webhooks before the event is delivered.

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-subscribesSubscriptions across your busi groups (admin sees all).Pattern B (bare array)
/busi-group/:id/alert-subscribesSubscriptions of one busi group (:id in path).Pattern B (bare array)

Query parameters

ParamTypeRequiredDefaultMeaningEndpoint
gidsstring (csv)Noall your groupsComma-separated busi-group ids to filter by; empty = every group you can see./busi-groups/alert-subscribes
No query params; group is taken from the :id path segment./busi-group/:id/alert-subscribes

Response — dat payload

(Pattern B bare array.) Each subscription is an AlertSubscribe:

Field (json)TypeMeaning
idint64Subscription id.
namestringSubscription name.
disabledint0 = enabled, 1 = disabled.
group_idint64Busi-group id this subscription belongs to.
prodstringProduct / monitoring type it subscribes (e.g. metric, host, anomaly, logging); empty = any.
catestringDatasource category filter (e.g. prometheus, host); empty = any.
datasource_ids[]int64(computed) Datasource ids the subscription matches; [0] means all datasources.
clusterstringLegacy: effective clusters, space-separated (superseded by datasource_ids).
rule_idint64Legacy: single subscribed alert-rule id (superseded by rule_ids).
severities[]int(computed) Subscribed severities to match (1 = Emergency, 2 = Warning, 3 = Notice).
for_durationint64Only match events that have persisted at least this many seconds (0 = no delay).
rule_namestring(computed) Legacy: name of rule_id.
tagsarrayTag matchers on the event's tags — array of TagFilter (see below); all must match.
redefine_severityint0/1 — whether to override the event's severity with new_severity.
new_severityintNew severity applied when redefine_severity = 1 (1/2/3).
redefine_channelsint0/1 — whether to override the event's notify channels with new_channels.
new_channelsstringNew notify channels (space-separated) applied when redefine_channels = 1.
user_group_idsstringLegacy notify: space-separated user-group ids to notify.
user_groups[]UserGroup(computed) Resolved user-group objects for user_group_ids.
redefine_webhooksint0/1 — whether to override the event's webhooks with webhooks.
webhooks[]string(computed) Webhook URLs applied when redefine_webhooks = 1.
extra_configany(computed) Arbitrary extra configuration (parsed from stored JSON).
notestringFree-text description.
create_bystringCreator username.
create_atint64Create time (unix seconds).
update_bystringLast updater username.
update_atint64Last update time (unix seconds).
update_by_nicknamestring(computed) Display nickname of update_by.
busi_groupsarrayBusi-group matchers — array of TagFilter (see below) filtering which busi groups' events match.
rule_ids[]int64Subscribed alert-rule ids (v6; replaces rule_id). Empty = match any rule.
notify_rule_ids[]int64New notify model: notify-rule ids used when notify_version = 1.
notify_versionint0 = legacy notify (user groups + channels/webhooks overrides), 1 = new notify-rule model (notify_rule_ids).
rule_names[]string(computed) Names for each id in rule_ids.

TagFilter sub-type (used by tags and busi_groups)

Each matcher object has these json fields:

Field (json)TypeMeaning
keystringTag key to match (for busi_groups the key is typically group_name).
funcstringMatch operator: ==, =~, in, !=, !~, not in.
opstringAlias of func (fallback when func is empty).
valueanyValue to compare against (string, or list/regex depending on func).

Example

Request:

json
{"method":"GET","path":"/api/n9e/busi-groups/alert-subscribes","query":{}}

Response (trimmed):

json
{
  "ok": true,
  "status": 200,
  "data": {
    "dat": [
      {
        "id": 12,
        "name": "escalate disk alerts to oncall",
        "disabled": 0,
        "group_id": 2,
        "prod": "metric",
        "cate": "prometheus",
        "datasource_ids": [0],
        "cluster": "",
        "rule_id": 0,
        "severities": [1, 2],
        "for_duration": 0,
        "rule_name": "",
        "tags": [
          {"key": "app", "func": "==", "op": "==", "value": "mysql"}
        ],
        "redefine_severity": 1,
        "new_severity": 1,
        "redefine_channels": 0,
        "new_channels": "",
        "user_group_ids": "3 5",
        "user_groups": [{"id": 3, "name": "oncall"}],
        "redefine_webhooks": 0,
        "webhooks": [],
        "extra_config": null,
        "note": "",
        "create_by": "root",
        "create_at": 1719800000,
        "update_by": "root",
        "update_at": 1719803600,
        "update_by_nickname": "Root",
        "busi_groups": [],
        "rule_ids": [101, 102],
        "notify_rule_ids": [],
        "notify_version": 0,
        "rule_names": ["disk usage high", "disk will fill in 24h"]
      }
    ],
    "err": ""
  }
}