-
Notifications
You must be signed in to change notification settings - Fork 5k
Osquerybeat: emit pack_name and query_name in scheduled query results #51781
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| # Kind can be one of: | ||
| # - breaking-change: a change to previously-documented behavior | ||
| # - deprecation: functionality that is being removed in a later release | ||
| # - bug-fix: fixes a problem in a previous version | ||
| # - enhancement: extends functionality but does not break or fix existing behavior | ||
| # - feature: new functionality | ||
| # - known-issue: problems that we are aware of in a given version | ||
| # - security: impacts on the security of a product or a user’s deployment. | ||
| # - upgrade: important information for someone upgrading from a prior version | ||
| # - other: does not fit into any of the other categories | ||
| kind: bug-fix | ||
|
|
||
| # Change summary; a 80ish characters long description of the change. | ||
| summary: Emit pack_name and query_name in osquerybeat scheduled query results | ||
|
|
||
| # Long description; in case the summary is not enough to describe the change | ||
| # this field accommodate a description without length limits. | ||
| # NOTE: This field will be rendered only for breaking-change and known-issue kinds at the moment. | ||
| description: | | ||
| Scheduled pack queries (both osquery native interval schedules and osquerybeat | ||
| RRULE schedules) now include two additional fields in their result and response | ||
| documents: pack_name, taken from the new optional `pack_name` config field on a | ||
| pack (alongside the existing pack_id), and query_name, taken 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; without them the dashboards cannot render | ||
| those results correctly. | ||
|
|
||
| # Affected component; a word indicating the component this changeset affects. | ||
| component: osquerybeat | ||
|
|
||
| # PR URL; optional; the PR number that added the changeset. | ||
| # If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added. | ||
| # NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number. | ||
| # Please provide it if you are adding a fragment for a different PR. | ||
| #pr: https://github.com/owner/repo/1234 | ||
|
|
||
| # Issue URL; optional; the GitHub issue related to this changeset (either closes or is part of). | ||
| # If not present is automatically filled by the tooling with the issue linked to the PR number. | ||
| #issue: https://github.com/owner/repo/1234 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,6 +49,10 @@ type QueryInfo struct { | |
| Interval int | ||
| // PackID is the policy-defined pack identifier for pack queries; empty for top-level schedule queries. | ||
| PackID string | ||
| // PackName is the policy-defined human-readable pack name for pack queries; empty for top-level schedule queries. | ||
| PackName string | ||
| // QueryName is the query's config map key (pack query name or top-level schedule name). | ||
| QueryName string | ||
| // Profile is whether to collect and publish profile for this query. | ||
| Profile bool | ||
| } | ||
|
|
@@ -293,8 +297,10 @@ func (p *ConfigPlugin) set(inputs []config.InputConfig) (err error) { | |
| osqueryConfig = inputs[0].Osquery | ||
| } | ||
|
|
||
| // Common code to register query with lookup maps, enforce snapshot and increment queries count | ||
| registerQuery := func(name, ns string, qi config.Query, packID string) (config.Query, error) { | ||
| // Common code to register query with lookup maps, enforce snapshot and increment queries count. | ||
| // queryName is the config map key (pack query name or top-level schedule name); packID/packName | ||
| // are the pack identifiers for pack queries and empty for top-level schedule queries. | ||
| registerQuery := func(name, ns string, qi config.Query, packID, packName, queryName string) (config.Query, error) { | ||
| var ecsm ecs.Mapping | ||
| ecsm, err = flattenECSMapping(qi.ECSMapping) | ||
| if err != nil { | ||
|
|
@@ -309,6 +315,8 @@ func (p *ConfigPlugin) set(inputs []config.InputConfig) (err error) { | |
| SpaceID: qi.SpaceID, | ||
| Interval: qi.Interval, | ||
| PackID: packID, | ||
| PackName: packName, | ||
| QueryName: queryName, | ||
| Profile: config.ResolveProfiling(globalProfile, qi.Profiling), | ||
| } | ||
| namespaces[name] = ns | ||
|
|
@@ -327,7 +335,7 @@ func (p *ConfigPlugin) set(inputs []config.InputConfig) (err error) { | |
| if err := config.ValidateQueryScheduleMode(qi); err != nil { | ||
| return fmt.Errorf("osquery.schedule[%q]: %w", name, err) | ||
| } | ||
| qi, err = registerQuery(name, p.namespace, qi, "") | ||
| qi, err = registerQuery(name, p.namespace, qi, "", "", name) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
@@ -348,7 +356,7 @@ func (p *ConfigPlugin) set(inputs []config.InputConfig) (err error) { | |
| if err != nil { | ||
| return fmt.Errorf("osquery.packs[%q].queries[%q]: %w", packName, name, err) | ||
| } | ||
| qi, err = registerQuery(getPackQueryName(packName, name), p.namespace, qi, packID) | ||
| qi, err = registerQuery(getPackQueryName(packName, name), p.namespace, qi, packID, pack.PackName, name) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
@@ -379,7 +387,7 @@ func (p *ConfigPlugin) set(inputs []config.InputConfig) (err error) { | |
| Profiling: stream.Profiling, | ||
| } | ||
|
|
||
| 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For this input/stream-based pack path, |
||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to confirm my understanding: for top-level (non-pack) scheduled queries this passes
queryName = namewith an emptypackName, so those docs would getquery_namebut nopack_name. Is emittingquery_nameon 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.