Splunk Search

Using subsearches to narrow down main search to a specific source

anz_leycurav
Explorer

Hi,

Say I'm collecting crash reports into log A (I'm extracting the PID using rex) and the activity leading to said crash I am collecting into log B of another sourcetype. The only way to correlate both is through the PID BUT the twist is that log B _raw does not contain it, the source does. For example:

log A detects crash of session 123
I want to see all events logged into logB_123.log

I would expect the subsearch part to be giving the crash side (log A) but how do i relate this to the main search, in order to direct it to look a specific source using a number I got from log A?

Thanks Vincent.

Tags (1)
0 Karma

martin_mueller
SplunkTrust
SplunkTrust

You can extract the PID from the source field, using rex it'd look like this:

sourcetype=B | rex field=source "_(?<PID>\d+)\.log" | ...

Note, filtering on this will be slow because Splunk has to load everything from B, extract the PID, and then throw out most of the loaded data. It'll be faster if you specify the PID extraction through props.conf like this:

[B]
EXTRACT-PIDinsource = _(?<PID>\d+)\.log in source
0 Karma

martin_mueller
SplunkTrust
SplunkTrust

You can do that once you have a PID field in sourcetype B extracted like shown above.

sourcetype=B [search sourcetype=A some magic filter | dedup PID | fields PID]

The subsearch evaluates to an OR'd list of PID=1234 filters, which are applied against your configured EXTRACT-PIDinsource.

0 Karma

anz_leycurav
Explorer

Thanks Martin, but what I'm after is presenting the events within log B.

Literally I want my search to run like "give me the full list of events found in source X, where the X string contains the PID that's obtained from log A"

Thanks again Vincent.

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

.conf25 Global Broadcast: Don’t Miss a Moment

Hello Splunkers, .conf25 is only a click away.  Not able to make it to .conf25 in person? No worries, you can ...

Observe and Secure All Apps with Splunk

 Join Us for Our Next Tech Talk: Observe and Secure All Apps with SplunkAs organizations continue to innovate ...

What's New in Splunk Observability - August 2025

What's New We are excited to announce the latest enhancements to Splunk Observability Cloud as well as what is ...