Splunk Search

How do I join two searches that both include rex field extractions?

IRHM73
Motivator

Hi,

I wonder whether someone may be able to help me please.

I have the following two searches:

index=main auditSource="agent-f" auditType=ServiceSentResponse detail.referrer="*deletion*"  "detail.Location"="/agent/verification-list" 
|rex field="tags.X-Session-ID" "session\-(?<SessionID>[\S]+)"
|stats count(SessionID) as "Number of Clients Deleted" by SessionID

And

index=main auditSource="agent-p" auditType=MetricGetClientListTotal 
| rex field="tags.X-Session-ID" "session\-(?<SessionID>[\S]+)"
| stats count by SessionID detail.agent-code

What I'm trying to do is join them using the SessionID, and then create a table at the end which displays the fields detail.agent-code and Number of Clients Deleted.

I have used join before, but never where regex events have had to be written i.e using 'explicit' rather than 'implicit' events.

I just wonder whether someone may be able to look at this please and offer some guidance on how I may be able to do this.

Many thanks and kind regards

Chris

0 Karma
1 Solution

javiergn
Super Champion

Could you use something like this instead?
Whenever possible try to avoid using join (performance, limits, etc)

(index=main auditSource="agent-f" auditType=ServiceSentResponse detail.referrer="*deletion*"  "detail.Location"="/agent/verification-list") OR (index=main auditSource="agent-p" auditType=MetricGetClientListTotal) 
 |rex field="tags.X-Session-ID" "session\-(?<SessionID>[\S]+)"
 | yourstatsquery

View solution in original post

renjith_nair
Legend

Hello Chris,

A simple join should work here unless you have some other hidden complexities.

 index=main auditSource="agent-f" auditType=ServiceSentResponse detail.referrer="*deletion*"  "detail.Location"="/agent/verification-list" 
 |rex field="tags.X-Session-ID" "session\-(?<SessionID>[\S]+)"
 |stats count(SessionID) as "Number of Clients Deleted" by SessionID
|join SessionID  [search  index=main auditSource="agent-p" auditType=MetricGetClientListTotal 
 | rex field="tags.X-Session-ID" "session\-(?<SessionID>[\S]+)"
 | stats count by SessionID detail.agent-code]|table "Number of Clients Deleted" detail.agent-code

However, somehow you should be able to combine these searches instead of join. Just a suggestion 🙂

---
What goes around comes around. If it helps, hit it with Karma 🙂
0 Karma

IRHM73
Motivator

Hi @renjit.nair, thank you for taking the time to reply to my post. It certainly helps with boosting my knowledge of the 'Join' function. As you will see @javiergn has combined the queries for me.

Many thanks and kind regards

Chris

0 Karma

javiergn
Super Champion

Could you use something like this instead?
Whenever possible try to avoid using join (performance, limits, etc)

(index=main auditSource="agent-f" auditType=ServiceSentResponse detail.referrer="*deletion*"  "detail.Location"="/agent/verification-list") OR (index=main auditSource="agent-p" auditType=MetricGetClientListTotal) 
 |rex field="tags.X-Session-ID" "session\-(?<SessionID>[\S]+)"
 | yourstatsquery

IRHM73
Motivator

Hi @javiergn, I have to admit I initially thought that this wouldn't work because of the 'OR' statement. But this works great.

Many thanks and kind regards

Chris

0 Karma

javiergn
Super Champion

The OR will return events from both audit sources and the rex will extract the field you want.
If you then use stats to count by SessionID, you'll get the totals the way you want because it's present in both event types. Assuming your regex works fine of course.

Let me know if that works

0 Karma

IRHM73
Motivator

Sincere thanks for the confirmation. You will see, probably while you were writing, that I tried the code and amended my response.

Many thanks and kind regards

Chris

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!

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Enhance Security Operations with Automated Threat Analysis in the Splunk EcosystemAre you leveraging ...

What Is Splunk? Here’s What You Can Do with Splunk

Hey Splunk Community, we know you know Splunk. You likely leverage its unparalleled ability to ingest, index, ...

Level Up Your .conf25: Splunk Arcade Comes to Boston

With .conf25 right around the corner in Boston, there’s a lot to look forward to — inspiring keynotes, ...