Add support for scheduled queries to run at startup#8554
Merged
zwass merged 7 commits intoMar 25, 2025
Merged
Conversation
f0d188e to
cb8c10d
Compare
zwass
approved these changes
Mar 11, 2025
zwass
left a comment
Member
There was a problem hiding this comment.
Approved assuming no issue with my comment. Please take a look at that.
Comment on lines
+285
to
+294
| Config::get().scheduledQueries(([&i, &first_query_runs]( | ||
| const std::string& name, | ||
| const ScheduledQuery& query) { | ||
| bool query_has_not_run = | ||
| first_query_runs.find(name) == first_query_runs.end(); | ||
| if ((query.splayed_interval > 0 && i % query.splayed_interval == 0) || | ||
| (query.startup_priority != UINT64_MAX && query_has_not_run)) { | ||
| if (query_has_not_run) { | ||
| first_query_runs.insert(name); | ||
| } |
Member
There was a problem hiding this comment.
Is name here going to be the full name prefixed by the pack name? If not, is it possible that there's a bug in which two queries with the same name in different packs cause a collision in this code?
Contributor
Author
There was a problem hiding this comment.
name here is the full name with the prefix as well.
osquery/osquery/config/config.cpp
Lines 481 to 488 in 9e3535a
osquery/osquery/config/config.cpp
Lines 472 to 479 in 9e3535a
Contributor
Author
There was a problem hiding this comment.
A pack structure similar to:
"packs": {
"test_pack_2": {
"queries": {
"test_startup_2": {...}
}
}
}
outputs: pack_test_pack_2_test_startup_2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds a new field for scheduled queries
startup_prioritywhich if set to a non-default value will run queries in ascending order once osqueryd starts theSchedulerRunner.I've tested this a fair amount on MacOS, and I've attached time table of my tests showing when osqueryd initialized and when it executed the defined scheduled queries.
Time Table.csv
Here are some logs also showing the example change: