Splunk Search

Want to filter events based on the existence of a field with the same value in a different log

Josh1890
Explorer

Hello, I'm doing a detection for an event on the same index with 2 logs, I want to filter events of Event A based on if the username field exists with the same value in Event B.

I tried doing a sub-search but I get errors

going by the below query, I want to filter Event A by if there are any events from Event B with the same original_user

 

 

 

(index=<my index>) EventType="A" EventType=A
| rename username as original_user
| eval Id= mvindex((newValue),0) 
| eval Name= mvindex((newValue),1) 
    [ search index=<same index> <filtering by a string> 
    | eval src_email= mvindex((newValue),3) 
    | rex field=src_email "(?<original_user>[\w\d\.\-]+\@[\w\d\.]+)" 
    | fields original_user] 
| stats values(*) as *

 

 

 

The above query says my eval is malformed

Is there any way to solve it?
Append/Join?

 

I also tested the query inside the sub-search by itself and it works with no issues

 

Labels (4)
0 Karma

PickleRick
SplunkTrust
SplunkTrust

Apart from what @richgalloway already pointed out the question is what are you trying to do. If you're trying to spawn a subsearch for each event from the base search... that doesn't work this way. You could use map to spawn a separate search for each result row but that's highly ineffective method. You're probably better of with appending two separate result sets and doing some magic on that compound data to get your results.

0 Karma

richgalloway
SplunkTrust
SplunkTrust

It would help to know the error you received, but I suspect it's a syntax error of some sort.  That's because subsearches have to be placed where their results would make semantic sense.

IOW, if the subsearch produces a result like (original_user=foo OR original_user=bar) then this makes no sense.

| eval Name= mvindex((newValue),1) 
    (original_user=foo OR original_user=bar) 
| stats values(*) as *

 Try this, instead

(index=<my index>) EventType="A" EventType=A
| rename username as original_user
| eval Id= mvindex((newValue),0) 
| eval Name= mvindex((newValue),1) 
| search [ search index=<my index> <filtering by a string> 
    | eval src_email= mvindex((newValue),3) 
    | rex field=src_email "(?<original_user>[\w\d\.\-]+\@[\w\d\.]+)" 
    | fields original_user
    | format ] 
| stats values(*) as *

Or this similar query for better performance

(index=<my index>) EventType="A" EventType=A [ search index=<my index> <filtering by a string> 
    | eval src_email= mvindex((newValue),3) 
    | rex field=src_email "(?<original_user>[\w\d\.\-]+\@[\w\d\.]+)" 
    | fields original_user
    | rename original_user as username
    | format ]
| rename username as original_user
| eval Id= mvindex((newValue),0) 
| eval Name= mvindex((newValue),1) 
| stats values(*) as *
---
If this reply helps you, Karma would be appreciated.
0 Karma

Josh1890
Explorer

Thanks, I'll try your suggestion

And yes I agree, I think it's a syntax error, that's the error:
"Error in 'EvalCommand': The expression is malformed."

0 Karma
Get Updates on the Splunk Community!

Upcoming Webinar: Unmasking Insider Threats with Slunk Enterprise Security’s UEBA

Join us on Wed, Dec 10. at 10AM PST / 1PM EST for a live webinar and demo with Splunk experts! Discover how ...

.conf25 technical session recap of Observability for Gen AI: Monitoring LLM ...

If you’re unfamiliar, .conf is Splunk’s premier event where the Splunk community, customers, partners, and ...

A Season of Skills: New Splunk Courses to Light Up Your Learning Journey

There’s something special about this time of year—maybe it’s the glow of the holidays, maybe it’s the ...