FG
10/07/2024, 9:41 PMosquery> select DISTINCT level from unified_log where timestamp > -1 and timestamp > (select unix_time - 86400 from time) AND level != 'default';
+-------+
| level |
+-------+
| |
| error |
+-------+
FG
10/07/2024, 9:42 PMBrad Girardeau
10/07/2024, 10:17 PMgrahamgilbert
10/08/2024, 3:11 AMFG
10/08/2024, 2:04 PMFG
10/08/2024, 2:05 PMlog
command and limits how many logs will be sent to the predicate filter? Thank you.Brad Girardeau
10/08/2024, 4:03 PMlog
does)FG
10/08/2024, 4:19 PMBrad Girardeau
10/08/2024, 4:58 PMlog
directly (similar to MacAdmins extension), where the predicate is applied before the max_rows filtering:
select * from unified_log where predicate = 'logType = "debug"' and timestamp > (select unix_time - 60 from time) and max_rows = 100 limit 10;
Bumping max_rows to a much higher limit shows the debug logs are there, but are getting filtered out too early by max_rows instead of doing the level
column filter early:
select * from unified_log where level = 'debug' and timestamp > (select unix_time - 60 from time) and max_rows = 10000 limit 10;
select * from unified_log where level = 'debug' and timestamp > (select unix_time - 60 from time) and max_rows = 100 limit 10;
Brad Girardeau
10/08/2024, 4:58 PMosqueryi --planner
you'll see the reason for this behavior is that level
constraint is not passed to the unified_log
table implementation, so it's done as a post query filter in the SQL engine instead. It looks like this is actually a bug, and level
should get passed into the table by setting additional=True
in the schema here.FG
10/08/2024, 5:07 PMFG
10/08/2024, 5:08 PMosquery> select message, predicate, subsystem, process from unified_log where timestamp > -1 and max_rows = 1000 AND level = 'debug';
osquery planner: xBestIndex Evaluating constraints for table: unified_log [index=0 column=0 term=0 usable=1]
osquery planner: xBestIndex Adding index constraint for table: unified_log [column=timestamp arg_index=1 op=4]
osquery planner: xBestIndex Evaluating constraints for table: unified_log [index=1 column=11 term=1 usable=1]
osquery planner: xBestIndex Adding index constraint for table: unified_log [column=max_rows arg_index=2 op=2]
osquery planner: xBestIndex Evaluating constraints for table: unified_log [index=2 column=10 term=2 usable=1]
osquery planner: xBestIndex Recording constraint set for table: unified_log [cost=1.000000 size=2 idx=37]
osquery planner: xOpen Opening cursor (35) for table: unified_log
osquery planner: xFilter Filtering called for table: unified_log [constraint_count=1 argc=2 idx=37]
osquery planner: xFilter Adding constraint to cursor (35): timestamp > -1
osquery planner: xFilter Adding constraint to cursor (35): max_rows = 1000
osquery planner: Scanning rows for cursor (35)
osquery planner: xFilter unified_log generate returned row count:1000
osquery planner: Closing cursor (35)
FG
10/08/2024, 5:10 PMFG
10/09/2024, 2:12 PM