Splunk Search

Multi sourcetype search for extracted value

whipstash
Engager

I am having some issues getting this to work correctly. It does not return all the results. I have different records in different sourcetypes under the same index.

sourcetypeA

eventID = computerName.sessionID

infoIWant1 = someinfo1

infoIWant2 = someinfo2

 

SourcetypeB's events are broken into events that I need to correlate.

sourcetypeB

event1-------------------------------------------------------

sessionID= sessionNo1

direction=receive

-----------------------------------------------------------------

 

event2--------------------------------------------------------

sessionID=sessionNo1

direction=send

-----------------------------------------------------------------

 

I attempted the below search using the transaction command to correlate the records in sourcetypeB.

index=INDEX sourcetype=sourcetypeA
| rex field=eventID "\w{0,30}+.(?<sessionID>\d+)"
| do some filter on infoIWant fields here
| join type=inner sessionID
[ search index=INDEX sourcetype=sourcetypeB
| transaction sessionID
| where eventcount==2
| fields sessionID duration ]
|  chart count by duration
Labels (5)
0 Karma

whipstash
Engager

Thanks for your help Giusepe. This is helpful for getting the duration. However, I would also like to table the results from filtering the events in sourcetypeA and having the duration. This solution does not seem to merge the two resulting searches.

ex.

table _time computerName sessionID filteredInfoIWant1 filteredInfoIwant2 duration

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @whipstash ,

add to the stats command, using the values option9 all the fields you need from both the searches:

index=INDEX sourcetype=sourcetypeA
| rex field=eventID "\w{0,30}+.(?<sessionID>\d+)"
| do some filter on infoIWant fields here
| append [ search 
     index=INDEX sourcetype=sourcetypeB
     | stats 
          count AS eventcount
          earliest(_time) AS earliest 
          latest(_time) AS latest 
          BY sessionID
     | eval duration=latest-earliest
     | where eventcount=2
     | fields sessionID duration field3 field4 ]
| stats 
     values(eventID) AS eventID
     values(duration) AS duration
     values(field1) AS field1
     values(field2) AS field2
     values(field3) AS field3
     values(field4) AS field4
     values(count) AS count
     BY sessionID

Ciao.

Giuseppe

 

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @whipstash ,

don't use join command that's a very slow command, use a different approach:

index=INDEX sourcetype=sourcetypeA
| rex field=eventID "\w{0,30}+.(?<sessionID>\d+)"
| do some filter on infoIWant fields here
| append [ search 
     index=INDEX sourcetype=sourcetypeB
     | stats 
          count AS eventcount
          earliest(_time) AS earliest 
          latest(_time) AS latest 
          BY sessionID
     | eval duration=latest-earliest
     | where eventcount=2
     | fields sessionID duration ]
| stats 
     values(eventID) AS eventID
     values(duration) AS duration
     values(count) AS count
     BY sessionID

Please adapt this approach to your real situation.

Ciao.

Giuseppe

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...