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.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...