Splunk Search

Joining to another sourcetype based on field from one log message and correlating to a different log message in the same log

danoconnl
Explorer

log a
5/14/2015 1pm [1150] <message><trnid>1001</trnid></message>
5/14/2015 1:01pm [1150]elapsed time = 1100

log b
5/14/2015 1pm, trnid=1001, 1200

so log a and b are linked on transaction id, and the two lines in log a are linked by the 1150.

I've got code that will pull the trnid out of the message, I just don't know how to link the two together and then use it to compare the elapsed time in log a to the third number in log b

Dan

Tags (2)
0 Karma
1 Solution

aholzer
Motivator

Depending on what your end goal is you should use either of the following commands:
- Transaction
You'd have to transact on log a's ID, then transact with the trnid to log b. You'd end up with a single event with all three log lines aggregated, and all the fields from all three events would be available in your new aggregated event.

Your search would look something like this:

<base search for both log a and log b> | transaction <log a's id> keeporphans=true | transaction trnid

Make sure to use as many parameters/attributes in each of the transaction commands, because transaction can be an expensive command. Look into things like maxspan, maxpause, startswith, etc

OR
- Join
Basically you'd have to treat every part as a database table and join them separately. You'd end up with all the fields from all the events under a single event, but you would not have all the _raw messages from each event. Also note that join uses subsearches; subsearches are not efficient and have a default 10k limit to resulting events.

Your search would look something like this:

<your base search for log a type 1 events > | join <log a's id> [search <your base search for log a type 2 events> | join trnid [search <base search for log b>

Hope this helps

--- EDIT: fixed typos ---

View solution in original post

aholzer
Motivator

Depending on what your end goal is you should use either of the following commands:
- Transaction
You'd have to transact on log a's ID, then transact with the trnid to log b. You'd end up with a single event with all three log lines aggregated, and all the fields from all three events would be available in your new aggregated event.

Your search would look something like this:

<base search for both log a and log b> | transaction <log a's id> keeporphans=true | transaction trnid

Make sure to use as many parameters/attributes in each of the transaction commands, because transaction can be an expensive command. Look into things like maxspan, maxpause, startswith, etc

OR
- Join
Basically you'd have to treat every part as a database table and join them separately. You'd end up with all the fields from all the events under a single event, but you would not have all the _raw messages from each event. Also note that join uses subsearches; subsearches are not efficient and have a default 10k limit to resulting events.

Your search would look something like this:

<your base search for log a type 1 events > | join <log a's id> [search <your base search for log a type 2 events> | join trnid [search <base search for log b>

Hope this helps

--- EDIT: fixed typos ---

danoconnl
Explorer

Thanks for the help, figured it out

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 ...