Splunk Search

Splunk Query to Generate an n-event sample across sourcetypes in an index

JohnEGones
Communicator

Hi people,

I wonder whether it is possible to run a query that generates a set of n-sample of events for each sourcetype in an index?

In some sense, if the log data has been ingested and conformed properly, this is perhaps not so problematic, you might build a datamodel or just query across the relevant CIM field (alias.)

So lets get specific:

 

index-someIndex sourcetype=someSourceType
| enumerate against some defined key value, say an eventtype
| enumerate all of the eventtypes and pull out any subeventtypes
| list the for 2-5 events for each subeventtype, else just list the 2-5 events for the the eventtype
| table _time, eventtype, subeventtype (NULL if blank), event

 

Labels (3)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust
| fillnull value="NULL" subeventtype
| streamstats count by eventtype subeventtype
| where count < 6

View solution in original post

0 Karma

JohnEGones
Communicator

@ITWhisperer 

Thanks. I have not used streamstats  much before. 

I suppose there is not really a good way to generalize this; since simpler queries like this already assume your data is fairly well-parsed.

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Correct, you need at least one field to do the stats by.

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
| fillnull value="NULL" subeventtype
| streamstats count by eventtype subeventtype
| where count < 6
0 Karma
Get Updates on the Splunk Community!

Splunk Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI!Discover how Splunk’s agentic AI ...

Splunk Enterprise Security 8.x: The Essential Upgrade for Threat Detection, ...

Watch On Demand the Tech Talk on November 6 at 11AM PT, and empower your SOC to reach new heights! Duration: ...

Splunk Observability as Code: From Zero to Dashboard

For the details on what Self-Service Observability and Observability as Code is, we have some awesome content ...