Splunk Search

Can you search for two strings in chronological order (in different log statements)?

jbrenner
Path Finder

In every log statement, we write the user's session ID delimited by hyphens as follows:

 -S:ybiSmNiQxF-

I want to get a count of session IDs that contain two specific message strings (in separate log statements) in a specific order. I don't care if there are intervening log statements.

Example:

2017-08-11 12:51:57,918 INFO - whatever-S:ybiBmNiQxF-whatever STATEMENT1 whatever 
2017-08-11 12:51:57,921 INFO - whatever-S:ybiBmNiQxF-whatever STATEMENT2 whatever 

Is there a way to do this in a Splunk query?

Thanks,
Jonathan

0 Karma

jbrenner
Path Finder

Thanks for pointing me in the right direction. SInce there did not turn out to be any intervening events, I was able to use maxevents=2 with the TRANSACTION command:

index=my_index
            | rex field=_raw "-S:(?<SESSION_ID>\w+)-" | transaction SESSION_ID startswith="STATEMENT1" endswith="STATEMENT2" maxevents=2
0 Karma

somesoni2
SplunkTrust
SplunkTrust

Give this a try (assuming no field extraction was done, if it has, remove the rex commands)

your base search for selecting only STATEMENT1 and STATEMENT2 type of events
| rex "S:(?<sessionID>[^\-]+)\S+\s+(?<Statement>\S+)"
| stats list(Statement) as Statements by sessionID 
| where mvindex(Statements,0)="STATEMENT1" AND mvindex(Statements,1)="STATEMENT2" | stats count
0 Karma

cpetterborg
SplunkTrust
SplunkTrust

Is the sessionID already extracted into a field? If so, then you can use the transaction command to combine the sets of transactions (same sessionID) together and perform functions on those, whether it be counts, check for completed transactions, etc.

If it is not already extracted, then you will have to do a field extraction (either automatic or inline) to use the transaction command. For that you may have to provide more complete example data in order to allow us to help with the field extraction.

0 Karma
Get Updates on the Splunk Community!

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...

Tech Talk | Elevating Digital Service Excellence: The Synergy of Splunk RUM & APM

Elevating Digital Service Excellence: The Synergy of Real User Monitoring and Application Performance ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...