aiagent/skill/embedded/builtin/skill-creator/n9e-api.md
Read this before writing any script that queries n9e's own data (alerts, rules,
targets, dashboards…). This file is the index + the rules that apply to every call; the
per-resource files under api/ have the exact params and the full response object
fields. Everything here is verified against n9e source.
An unknown path does not return 404. n9e serves its single-page-app index.html for
any unmatched route, and the gateway hands that HTML string back in data. So a wrong
path fails silently — the script gets HTML (often starting with <!-- ... Copyright ... Nightingale Team) instead of JSON. Do not guess paths by analogy: there is no
/alert-events, no plain /alert-rules, no /dashboards. Take every path from the
per-resource file below; if what you need isn't documented, ask the user to confirm the
real /api/n9e/... request from their browser dev tools rather than guessing.
N9E_SKILL_GATEWAY; talk newline-delimited JSON over it.{"method":"GET","path":"/api/n9e/alert-his-events/list","query":{"hours":"24","limit":"100"}}\n
/api/n9e prefix in path (e.g. /api/n9e/alert-his-events/list). The per-resource files list paths under /api/n9e; prepend it when you build the request.api/data-query.md), where the query goes in a body (a JSON object).
All other writes/deletes are rejected.query values must be STRINGS: {"limit":"100","p":"1"}, not 100. (This applies
to the query map; inside a POST body use native JSON types.){"ok":true,"status":200,"data":<n9e body>} or {"ok":false,"status":<code>,"error":"..."}.data is n9e's envelope: {"dat": <payload>, "err": "", "request_id": "..."} — always read
data["dat"]. On an API error err is non-empty and there is no dat (HTTP is still 200).
Validate every response (this is how you catch a wrong path):
if not resp.get("ok") or not isinstance(resp.get("data"), dict):
raise RuntimeError(f"gateway call failed (wrong path? denied?): {str(resp)[:200]}")
env = resp["data"]
if env.get("err"):
raise RuntimeError(f"n9e api error: {env['err']}")
dat = env["dat"]
dat has two shapes (each per-resource file says which):
dat = {"list": [...], "total": N}. Paginate with p
(page, from 1) + limit. Used by the high-volume event/target endpoints.dat = [ ...items... ]. Everything returned at once,
no server-side paging. Used by config-object lists (rules, boards, mutes, subscribes,
busi-groups, teams).Most business resources come in two variants:
/busi-groups/<resource> with optional gids query
(comma-separated group ids; empty = all groups your RBAC allows)./busi-group/<id>/<resource> — the <id> is required in the path.Events, targets, busi-groups and user-groups are flat (filter with bgid/gids query where supported).
read_file(base="skill-creator", path="api/<file>").
| Resource | File | Endpoints (under /api/n9e) |
|---|---|---|
| Alert events (history + active) | api/alert-events.md | /alert-his-events/list, /alert-cur-events/list, /alert-{his,cur}-event/:eid |
| Alert rules | api/alert-rules.md | /busi-groups/alert-rules, /busi-group/:id/alert-rules, /alert-rule/:arid |
| Targets (hosts) | api/targets.md | /targets, /targets/stats |
| Dashboards (boards) | api/boards.md | /boards, /busi-groups/boards, /busi-group/:id/boards, /board/:bid |
| Alert mutes (silences) | api/alert-mutes.md | /busi-groups/alert-mutes, /busi-group/:id/alert-mutes |
| Alert subscriptions | api/alert-subscribes.md | /busi-groups/alert-subscribes, /busi-group/:id/alert-subscribes |
| Business groups | api/busi-groups.md | /busi-groups, /busi-group/:id |
| Teams (user groups) | api/user-groups.md | /user-groups, /user-group/:id |
| Data query (metrics & logs) | api/data-query.md | POST /ds-query, /query-range-batch, /query-instant-batch, /logs-query … |
| Datasource discovery | api/datasources.md | /datasource/brief (to get a datasource_id before querying) |
Other read endpoints exist under /api/n9e (recording rules /busi-groups/recording-rules,
metric views /metric-views, builtin metrics /builtin-metrics, notify rules /notify-rules,
event pipelines /event-pipelines, …). They're not detailed here — if you need one, confirm
its exact path/params/response with the user before writing to it.
1 = Emergency/Critical (一级), 2 = Warning (二级), 3 = Notice/Info (三级).0 = firing, 1 = recovered.hours=<N> (relative, last N hours) or stime/etime as unix seconds.ok:false, don't script around themDatasource configs /datasource*, notify secrets /notify-channel* /notify-config,
config-center /config, users/tokens /users /user/* /self/token /user-token,
SSO/IdP /sso /ldap /oidc /oauth /cas, datasource proxy /proxy/*, /webhook*,
/password*, and every non-GET method except the read-only data-query POST allowlist
(api/data-query.md). These carry secrets or mutate state.