master
md 199 lines 6.42 KB
Rendered Raw
1 # Query the event feed via Netdata Cloud
2
3 This guide is part of the [`query-netdata-cloud`](./SKILL.md) skill.
4 Read the [SKILL.md prerequisites](./SKILL.md#prerequisites) first.
5
6 The Cloud event feed is an audit + activity log: node lifecycle
7 events, alert transitions, agent connection events, space and room
8 membership changes, and configuration changes. It is served by the
9 **`cloud-feed-service`** (separate microservice from
10 spaceroom/charts) and answers via Elasticsearch under the hood.
11
12 There is no agent-side equivalent. The feed is Cloud-only.
13
14 ---
15
16 ## Endpoint
17
18 `POST /api/v1/feed/search` -- search the feed.
19
20 This is a v1 path (the only supported path for this service today).
21
22 The companion search-lean variant (`/api/v1/feed/search/lean`)
23 returns hits without the full source documents -- use it when you
24 only need aggregations / counts.
25
26 The facets endpoint
27 (`GET /api/v1/feed/static/facets`) returns the supported facet
28 field schema (mostly for UI rendering).
29
30 ## Use the wrapper
31
32 ```bash
33 source "$(git rev-parse --show-toplevel)/.agents/skills/query-netdata-agents/scripts/_lib.sh"
34 agents_load_env
35
36 # Last 10 events in a space.
37 read -r -d '' BODY <<EOF
38 {
39 "space_id": "$SPACE",
40 "page_size": 10
41 }
42 EOF
43
44 agents_query_cloud POST /api/v1/feed/search "$BODY"
45 ```
46
47 ## Body parameters
48
49 | Field | Type | Purpose |
50 |---|---|---|
51 | `space_id` | string (UUID) | **REQUIRED.** Space to search within |
52 | `room_ids` | array<string> | Filter to specific rooms |
53 | `agents` | array<string> | Filter to specific agent ids (`mg` field of nodes) |
54 | `node_ids` | array<string> | Filter to specific node ids (`nd` field) |
55 | `actions` | array<string> | Filter by event action (see enum below) |
56 | `alert_classes`, `alert_components`, `alert_names`, `alert_roles`, `alert_statuses`, `alert_transitions`, `alert_types` | array<string> | Alert-event filters |
57 | `chart_names`, `chart_contexts`, `chart_types` | array<string> | Chart-related event filters |
58 | `from`, `to` | int (Unix-millis) | Time range |
59 | `query` | string | Free-text search |
60 | `page_size` | int | Page size |
61 | `from_offset` | int | Pagination offset |
62
63 ### `actions` enum (verified live)
64
65 Node lifecycle:
66 - `node-created`, `node-removed`, `node-deleted`, `node-restored`
67 - `node-state-live`, `node-state-stale`, `node-state-offline`
68
69 Agent lifecycle:
70 - `agent-connected`, `agent-disconnected`, `agent-claimed`
71
72 Alerts:
73 - `alert-node-transition`, `alert-node_instance-transition`
74
75 User / space / room:
76 - `user-create`, `user-created`
77 - `space-created`, `space-deleted`, `space-settings-changed`
78 - `space-user-added`, `space-user-removed`
79 - `user-space-permissions-changed`
80 - `room-created`, `room-deleted`
81 - `room-user-added`, `room-user-removed`
82 - `user-room-permissions-changed`
83
84 ## Response shape
85
86 ```text
87 {
88 "page_size": <int>,
89 "results": {
90 "hits": {
91 "total": { "value": <int> },
92 "hits": [
93 {
94 "_source": {
95 "@timestamp": "<RFC3339>",
96 "trace": { "id": "<UUID>" },
97 "agent": { "version": "..." },
98 "host": { "id": "<machine_guid>", "name": "<hostname>", ... },
99 "Netdata": { "alert": {...}, "event": {...}, ... },
100 "ecs": { "version": "..." }
101 },
102 "_index": "...",
103 "_id": "...",
104 "_score": <float>
105 },
106 ...
107 ]
108 },
109 "aggregations": {
110 "actions": { "buckets": [...] },
111 "agents": { "buckets": [...] },
112 "alert_classes": { "buckets": [...] },
113 "alert_components":{ "buckets": [...] },
114 "alert_names": { "buckets": [...] },
115 "alert_roles": { "buckets": [...] },
116 ...
117 }
118 }
119 }
120 ```
121
122 The hit fields under `_source` follow the **ECS (Elastic Common
123 Schema) v8.4.0** layout for shared keys (`@timestamp`, `host.*`,
124 `agent.*`, `ecs.*`) plus a Netdata-specific `Netdata.*` envelope
125 that holds the per-event payload.
126
127 ## Common patterns
128
129 ```bash
130 # Last hour of node-state changes.
131 read -r -d '' BODY <<EOF
132 {
133 "space_id": "$SPACE",
134 "actions": ["node-state-live","node-state-stale","node-state-offline"],
135 "from": $(( ($(date +%s) - 3600) * 1000 )),
136 "to": $(( $(date +%s) * 1000 )),
137 "page_size": 50
138 }
139 EOF
140 agents_query_cloud POST /api/v1/feed/search "$BODY" \
141 | jq -r '.results.hits.hits[]._source | "\(.["@timestamp"])\t\(.Netdata.event.action // "?")\t\(.host.name // "?")"'
142
143 # Distribution of alert classes triggered in the last 24h.
144 read -r -d '' BODY <<EOF
145 {
146 "space_id": "$SPACE",
147 "actions": ["alert-node_instance-transition"],
148 "from": $(( ($(date +%s) - 86400) * 1000 )),
149 "to": $(( $(date +%s) * 1000 )),
150 "page_size": 0
151 }
152 EOF
153 agents_query_cloud POST /api/v1/feed/search "$BODY" \
154 | jq -r '.results.aggregations.alert_classes.buckets[] | "\(.key)\t\(.doc_count)"'
155
156 # All space-user-added events for a given account in the last 7 days.
157 ACCT="<account-uuid>"
158 read -r -d '' BODY <<EOF
159 {
160 "space_id": "$SPACE",
161 "actions": ["space-user-added"],
162 "from": $(( ($(date +%s) - 604800) * 1000 )),
163 "to": $(( $(date +%s) * 1000 )),
164 "page_size": 50
165 }
166 EOF
167 agents_query_cloud POST /api/v1/feed/search "$BODY" \
168 | jq --arg id "$ACCT" '.results.hits.hits[] | select(._source.user.id // "" == $id)'
169 ```
170
171 ## Limits and gotchas
172
173 - **`from`/`to` are Unix milliseconds.** Easy to confuse with
174 seconds.
175 - **Total hit count is paginated.** Use `from_offset` to walk
176 past the first page; `total.value` tells you the size.
177 - **`actions` is the most useful facet.** Most queries should
178 start by narrowing by `actions[]`; the per-action `_source`
179 shape varies, so filter first then read the appropriate
180 per-event fields.
181 - **Hits include personal data.** `host.name`, `user.id`,
182 `user.email`, `agent.version`, alert config_hash UUIDs --
183 treat raw responses as semi-sensitive; never paste into
184 committed artifacts.
185 - **Retention is finite.** The feed-service has retention
186 enforcement (`errInvalidRetention` error message in source);
187 very old time windows return errors.
188 - **No agent-side equivalent.** This is the only path to the
189 audit/activity feed; agents do not retain it locally.
190
191 ## See also
192
193 - [query-rooms.md](./query-rooms.md), [query-members.md](./query-members.md)
194 -- the surfaces whose changes generate room-/member-related
195 feed events.
196 - [query-alerts.md](./query-alerts.md) -- alert transitions are
197 also emitted into the feed via `alert-node-transition` and
198 `alert-node_instance-transition` actions, in addition to the
199 per-room alert-transitions endpoint.