Reference
Audit
The audit endpoints of the HTTP API.
GET /audit/events
Search the audit trail, newest first.
Only Admins can call this endpoint, and an Admin service-account key can too; an agent run reaches it only when its requester is an Admin. Returns the audit events in the window that match q, newest first by occurred_at and then id, 100 a page unless limit or a Query DSL size says otherwise. Page with next_cursor: the pages of one search never repeat or skip an event, and events recorded after the first page do not move later pages. A search is itself recorded as audit.search with the query as sent (cut at 4 KiB), its form, the window and the row count, once per caller and query text in 10 minutes, so paging through or refreshing one search adds no events; a refused query is recorded as a failed audit.search every time.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
q |
query | string |
The filter, in one of three forms: KQL by default (action:dashboard.* and outcome:denied), Lucene after a lucene: prefix, or a Query DSL body that starts with { and may carry query, size and aggs. Empty matches every event in the window. GET /audit/fields lists the fields; the audit query reference in the guide has examples. |
since |
query | string |
Start of the window, inclusive, as an RFC 3339 time, epoch milliseconds or a relative time such as now-7d; 24 hours before until when left out. |
until |
query | string |
End of the window, exclusive, in the same forms; now when left out. The window is at most 366 days. |
cursor |
query | string |
The next_cursor of the previous page. It pins the window of the first page, so since and until are ignored with it, and it is refused with another q. |
limit |
query | integer |
Events per page, 1 to 1000; 100 by default, or the size of a Query DSL body. Between 1 and 1000. |
Responses
| Status | Description | Body |
|---|---|---|
200 |
One page of events. | AuditEventList |
400 |
since or until is not a time, the window is empty or longer than 366 days, limit is out of range, or the cursor is unreadable or belongs to another query (invalid_request). |
Error |
401 |
Authentication is missing or invalid. | Error |
403 |
The caller is not an Admin, or is a key below the Admin role (forbidden_role). |
Error |
422 |
The filter cannot run: query_invalid with the parser’s message and, for a parse error, start and end, the byte offsets in q to underline; query_timeout when the read runs longer than 30 seconds. |
AuditQueryError |
500 |
The server failed to handle the request. | Error |
GET /audit/events/{id}
Read one audit event with the other events of its request and its agent run.
Only Admins can call this endpoint, and an Admin service-account key can too; an agent run reaches it only when its requester is an Admin. same_request holds up to 50 events with the same request_id within an hour of the event, and same_run up to 50 events with the same run_id within a day of it, newest first; each list includes the event itself. This read is itself recorded as audit.search with view event and the query id:<id>, once per caller and event in 10 minutes; an id that names no event is recorded as a failed audit.search every time.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
id (required) |
path | string (uuid) |
Responses
| Status | Description | Body |
|---|---|---|
200 |
The event. | AuditEventDetail |
401 |
Authentication is missing or invalid. | Error |
403 |
The caller is not an Admin, or is a key below the Admin role (forbidden_role). |
Error |
404 |
No audit event has this id (not_found). |
Error |
422 |
The read ran longer than 30 seconds (query_timeout). |
AuditQueryError |
500 |
The server failed to handle the request. | Error |
GET /audit/facets
Count the top values of one field among the matching audit events.
Only Admins can call this endpoint, and an Admin service-account key can too; an agent run reaches it only when its requester is an Admin. Returns the most frequent values of field among the events in the window that match q, most frequent first, ties by value; events where the field is empty are not counted. This read is itself recorded as audit.search with view facets, the field, the query as sent (cut at 4 KiB), its form, the window and the row count, once per caller and query text in 10 minutes; a refused query is recorded every time.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
q |
query | string |
The filter, in one of three forms: KQL by default (action:dashboard.* and outcome:denied), Lucene after a lucene: prefix, or a Query DSL body that starts with { and may carry query, size and aggs. Empty matches every event in the window. GET /audit/fields lists the fields; the audit query reference in the guide has examples. |
since |
query | string |
Start of the window, inclusive, as an RFC 3339 time, epoch milliseconds or a relative time such as now-7d; 24 hours before until when left out. |
until |
query | string |
End of the window, exclusive, in the same forms; now when left out. The window is at most 366 days. |
field (required) |
query | string |
The field to count, such as actor_name or action; GET /audit/fields lists them. |
limit |
query | integer |
Values to return, 1 to 100; 10 by default. Between 1 and 100. |
Responses
| Status | Description | Body |
|---|---|---|
200 |
The counted values. | AuditFacets |
400 |
field is missing, the window is not valid or limit is out of range (invalid_request). |
Error |
401 |
Authentication is missing or invalid. | Error |
403 |
The caller is not an Admin, or is a key below the Admin role (forbidden_role). |
Error |
422 |
The filter cannot run: query_invalid with the parser’s message and, for a parse error, start and end, the byte offsets in q to underline, or an unknown or uncountable field; query_timeout when the read runs longer than 30 seconds. |
AuditQueryError |
500 |
The server failed to handle the request. | Error |
GET /audit/histogram
Count the matching audit events over time.
Only Admins can call this endpoint, and an Admin service-account key can too; an agent run reaches it only when its requester is an Admin. Splits the window into buckets of one step, the smallest of 1s, 5s, 10s, 30s, 1m, 5m, 10m, 30m, 1h, 3h, 6h, 12h and 1d that gives at most buckets buckets, and counts the matching events in each; empty buckets are included, oldest first. This read is itself recorded as audit.search with view histogram, the query as sent (cut at 4 KiB), its form, the window and the row count, once per caller and query text in 10 minutes; a refused query is recorded every time.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
q |
query | string |
The filter, in one of three forms: KQL by default (action:dashboard.* and outcome:denied), Lucene after a lucene: prefix, or a Query DSL body that starts with { and may carry query, size and aggs. Empty matches every event in the window. GET /audit/fields lists the fields; the audit query reference in the guide has examples. |
since |
query | string |
Start of the window, inclusive, as an RFC 3339 time, epoch milliseconds or a relative time such as now-7d; 24 hours before until when left out. |
until |
query | string |
End of the window, exclusive, in the same forms; now when left out. The window is at most 366 days. |
buckets |
query | integer |
The most buckets wanted, 1 to 200. Between 1 and 200. Default 60. |
Responses
| Status | Description | Body |
|---|---|---|
200 |
The counts. | AuditHistogram |
400 |
The window is not valid or buckets is out of range (invalid_request). |
Error |
401 |
Authentication is missing or invalid. | Error |
403 |
The caller is not an Admin, or is a key below the Admin role (forbidden_role). |
Error |
422 |
The filter cannot run: query_invalid with the parser’s message and, for a parse error, start and end, the byte offsets in q to underline; query_timeout when the read runs longer than 30 seconds. |
AuditQueryError |
500 |
The server failed to handle the request. | Error |
GET /audit/aggregate
Run the aggs of a Query DSL body over the matching audit events.
Only Admins can call this endpoint, and an Admin service-account key can too; an agent run reaches it only when its requester is an Admin. q must be a Query DSL body with aggs: date_histogram, terms, cardinality, value_count, count, min, max, avg, sum and percentiles, up to three levels, one bucket aggregation per level. Each row holds one key per level, in levels order (a time for date_histogram, a value for terms), the doc_count of the bucket and one value per entry of metrics. An aggregation that would produce more than 100,000 rows is refused with its reason. This read is itself recorded as audit.search with view aggregate, the query as sent (cut at 4 KiB), its form, the window and the row count, once per caller and query text in 10 minutes; a refused query is recorded every time.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
q |
query | string |
The filter, in one of three forms: KQL by default (action:dashboard.* and outcome:denied), Lucene after a lucene: prefix, or a Query DSL body that starts with { and may carry query, size and aggs. Empty matches every event in the window. GET /audit/fields lists the fields; the audit query reference in the guide has examples. |
since |
query | string |
Start of the window, inclusive, as an RFC 3339 time, epoch milliseconds or a relative time such as now-7d; 24 hours before until when left out. |
until |
query | string |
End of the window, exclusive, in the same forms; now when left out. The window is at most 366 days. |
Responses
| Status | Description | Body |
|---|---|---|
200 |
The aggregation rows. | AuditAggregation |
400 |
The window is not valid (invalid_request). |
Error |
401 |
Authentication is missing or invalid. | Error |
403 |
The caller is not an Admin, or is a key below the Admin role (forbidden_role). |
Error |
422 |
The filter cannot run: query_invalid with the parser’s message and, for a parse error, start and end, the byte offsets in q to underline, or the body has no aggs or asks for more rows than the limit, with the reason; query_timeout when the read runs longer than 30 seconds. |
AuditQueryError |
500 |
The server failed to handle the request. | Error |
GET /audit/fields
List the fields an audit query can use.
Only Admins can call this endpoint, and an Admin service-account key can too; an agent run reaches it only when its requester is an Admin. Each field has its name, its aliases, its type, what it holds and, for an enum, its values, for autocomplete and for agents writing a query.
Responses
| Status | Description | Body |
|---|---|---|
200 |
The fields. | AuditFieldList |
401 |
Authentication is missing or invalid. | Error |
403 |
The caller is not an Admin, or is a key below the Admin role (forbidden_role). |
Error |
500 |
The server failed to handle the request. | Error |
GET /audit/stream
Follow new audit events that match a query as Server-Sent Events.
Only Admins can call this endpoint, and an Admin service-account key can too. The stream starts with retry: 3000 and an event: ready whose data is {} and whose id is the position the stream starts from, so a client cut off before the first event resumes from it. Each event after that is a frame of id: <position>, event: audit and the event JSON of listAuditEvents as data, in the order the events were committed, for every new event that matches q. Without Last-Event-ID the stream sends only events committed after it opened, and never one that occurred more than 10 minutes before it opened. A frame’s id is <xid>-<seq>-<microseconds>, its position in the trail and the event’s time; a reconnecting client sends the id of the last frame it handled and the stream continues with every matching event committed after it whose time is at most 10 minutes before that event’s, however long the client was away. A Last-Event-ID whose event is more than 24 hours old answers 400; read the gap with listAuditEvents and open a new stream. An event can arrive a few seconds after it was recorded, because the trail is written in batches and read every 2 seconds. A : ping comment arrives every 5 seconds; at each ping the server re-reads the caller’s credentials and role, and a caller who is no longer an Admin, or whose credential is gone, gets an event: forbidden with the forbidden_role body and the stream ends. The stream also ends when the server shuts down, and after 30 minutes; clients reconnect. Opening the stream is recorded once as audit.search with the query as sent, its form and the start of what it can send; the events it delivers are not recorded one by one. A caller may hold 5 audit streams and the process 20, and one more answers 429. Each read of the trail runs under a 5 second statement timeout, one at a time; a stream whose read times out twice in a row sends an event: error with an AuditQueryError body of code query_too_expensive and ends.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
q |
query | string |
The filter, in the same three forms as listAuditEvents; empty follows every event. A Query DSL size and aggs are ignored. |
Last-Event-ID |
header | string |
The id of the last frame the client handled. |
Responses
| Status | Description | Body |
|---|---|---|
200 |
An open text/event-stream. |
text/event-stream |
400 |
Last-Event-ID is not the id of a frame of this stream, or its event is more than 24 hours old (invalid_request). |
Error |
401 |
Authentication is missing or invalid. | Error |
403 |
The caller is not an Admin, or is a key below the Admin role (forbidden_role). |
Error |
422 |
The filter cannot be read (query_invalid), with the parser’s message and the byte offsets start and end in q. |
AuditQueryError |
429 |
The caller already holds 5 open audit streams, or the process 20 (too_many_streams). |
Error |
500 |
The server failed to handle the request. | Error |
503 |
The server is shutting down (shutting_down). |
Error |
GET /audit/export
Download the matching audit events as NDJSON or CSV.
Only Admins can call this endpoint, and an Admin service-account key can too; an agent run reaches it only when its requester is an Admin. Streams the events in the window that match q, newest first, one JSON object per line in the shape of listAuditEvents, or CSV with a header row and data as JSON text. An export stops at 1,000,000 rows, the value of the X-Export-Row-Limit header; narrow the window to read more. A complete export ends with the trailer X-Export-Truncated, true when more matching events existed past the limit and false otherwise. When a read fails after the first rows were sent, the server cuts the connection off instead of ending the response, so a client sees an unexpected end of the body and knows the export is incomplete. Before each page of 1,000 rows after the first, the server re-reads the caller’s credentials and role; a caller who is no longer an Admin is cut off the same way, and the export is recorded as denied with forbidden_role. Recorded as audit.export with the query as sent (cut at 4 KiB), its form, the window, the format and the row count.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
q |
query | string |
The filter, in one of three forms: KQL by default (action:dashboard.* and outcome:denied), Lucene after a lucene: prefix, or a Query DSL body that starts with { and may carry query, size and aggs. Empty matches every event in the window. GET /audit/fields lists the fields; the audit query reference in the guide has examples. |
since |
query | string |
Start of the window, inclusive, as an RFC 3339 time, epoch milliseconds or a relative time such as now-7d; 24 hours before until when left out. |
until |
query | string |
End of the window, exclusive, in the same forms; now when left out. The window is at most 366 days. |
format |
query | "ndjson", "csv" |
Default "ndjson". |
Responses
| Status | Description | Body |
|---|---|---|
200 |
The events. | application/x-ndjson, text/csv |
400 |
format is not ndjson or csv, or the window is not valid (invalid_request). |
Error |
401 |
Authentication is missing or invalid. | Error |
403 |
The caller is not an Admin, or is a key below the Admin role (forbidden_role). |
Error |
422 |
The filter cannot run: query_invalid with the parser’s message and, for a parse error, start and end, the byte offsets in q to underline; query_timeout when the read runs longer than 30 seconds. |
AuditQueryError |
500 |
The server failed to handle the request. | Error |
Generated from api/openapi.yaml at c770e5e0. Report a problem.