Osquerybeat: emit pack_name and query_name in scheduled query results#51781
Osquerybeat: emit pack_name and query_name in scheduled query results#51781marc-gr wants to merge 1 commit into
Conversation
Scheduled pack queries (both osquery native interval schedules and osquerybeat RRULE schedules) now include pack_name and query_name in their result and response documents. pack_name comes from a new optional `pack_name` config field on a pack (alongside the existing pack_id); query_name comes from the pack's queries config map key. Both fields are only emitted when set. These fields are required by the Osquery Manager dashboards, which group and label scheduled query results by pack and query name.
|
Pinging @elastic/sec-windows-platform (Team:Security-Windows Platform) |
🤖 GitHub commentsJust comment with:
|
tomsonpl
left a comment
There was a problem hiding this comment.
Reviewed together with the Kibana (elastic/kibana#276690) and integrations (elastic/integrations#20017) PRs. The pack_name config field and the query_name derived from the queries map key line up cleanly with what Kibana emits and what the integrations mappings expect, so the end-to-end contract looks consistent to me. A couple of clarifying questions inline.
| return fmt.Errorf("osquery.schedule[%q]: %w", name, err) | ||
| } | ||
| qi, err = registerQuery(name, p.namespace, qi, "") | ||
| qi, err = registerQuery(name, p.namespace, qi, "", "", name) |
There was a problem hiding this comment.
Just to confirm my understanding: for top-level (non-pack) scheduled queries this passes queryName = name with an empty packName, so those docs would get query_name but no pack_name. Is emitting query_name on non-pack scheduled queries intended? I ask because the integrations field description phrases both fields as "for scheduled queries that belong to a pack" (elastic/integrations#20017), so I wanted to check whether the behavior or that description should be the source of truth.
| } | ||
|
|
||
| qi, err = registerQuery(getPackQueryName(input.Name, stream.ID), p.namespace, qi, input.Name) | ||
| qi, err = registerQuery(getPackQueryName(input.Name, stream.ID), p.namespace, qi, input.Name, "", stream.ID) |
There was a problem hiding this comment.
For this input/stream-based pack path, packName is passed as "" (so pack_name won't be stamped) while pack_id is set from input.Name. Is this path reachable for Fleet-managed osquery_manager packs, or only for standalone/legacy beats input config? I'm trying to understand whether scheduled docs flowing through here would be missing pack_name and therefore not match the updated dashboard filters, or whether that's expected because Fleet always uses the packs map above.
Proposed commit message
Emit
pack_nameandquery_namein osquerybeat scheduled query results.WHAT:
pack_nameconfig field to packs, next to the existingpack_id.handleQueryResult) and osquerybeat RRULE schedules (recurrenceQueryHandler) — now include two additional fields in their result documents and their synthetic response documents:pack_name: from the newpack_namepack config field.query_name: from the pack'squeriesconfig map key.QueryInfoand emitted only when set. Live/ad-hoc queries are unaffected (they emit neither).WHY:
The Osquery Manager dashboards group and label scheduled query results by pack and query name. Without
pack_name/query_nameon the documents, those dashboards cannot render scheduled pack results correctly.Checklist
./changelog/fragmentsusing the changelog tool.Disruptive User Impact
None. The
pack_namefield is opt-in and both fields are additive; documents without the new config keep their previous shape.pack_idand the existing correlation fields are unchanged.How to test this PR locally
pack_nameand one or more scheduled queries (native interval and/orrrule_schedule):osquery_manager.resultdocuments includepack_name: "My Pack"andquery_name: "uptime", and theosquery_manager.action.responsessynthetic response document includes the same fields.pack_name/query_name.Related issues
Use cases
pack_name/query_namefields.