Splunk Search

How to make stats count result value become filters in search/dashboard

b1211ry
Explorer

Hi,

I need to call the result value as a filter. like this table below, the second value on column RecipientDomain will call on search as filter. become this query:

index=sec_office365_dlp sourcetype=sec_office365_dlp RecipientDomain=@yahoo.com | stats count by xxx

 

splunk first query.jpg

 

Help please..

 

Labels (1)
0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

You need a subsearch.  The subsearch runs first and selects the value the main search will look for.

index=sec_office365_dlp sourcetype=sec_office365_dlp [ index=sec_office365_dlp sourcetype=sec_office365_dlp RecipientDomain IN (@gmail.com @yahoo.com @hotmail.com) 
  | stats count by RecipientDomain
  | sort limit=2 - count
  | tail 1
  | return RecipientDomain ]
| stats count by xxx

The subsearch selects the last (tail 1) result from the two produced by sort, which is the same as the second of three.

---
If this reply helps you, Karma would be appreciated.

View solution in original post

0 Karma

richgalloway
SplunkTrust
SplunkTrust

How does Splunk know which RecipientDomain value to use?  Is it always the second?

---
If this reply helps you, Karma would be appreciated.
0 Karma

b1211ry
Explorer

Yes @richgalloway , we always use the second one value.

0 Karma

richgalloway
SplunkTrust
SplunkTrust

You need a subsearch.  The subsearch runs first and selects the value the main search will look for.

index=sec_office365_dlp sourcetype=sec_office365_dlp [ index=sec_office365_dlp sourcetype=sec_office365_dlp RecipientDomain IN (@gmail.com @yahoo.com @hotmail.com) 
  | stats count by RecipientDomain
  | sort limit=2 - count
  | tail 1
  | return RecipientDomain ]
| stats count by xxx

The subsearch selects the last (tail 1) result from the two produced by sort, which is the same as the second of three.

---
If this reply helps you, Karma would be appreciated.
0 Karma

b1211ry
Explorer

Thanks for your help @richgalloway .  It works!!👍

 

 

0 Karma
Get Updates on the Splunk Community!

Index This | I’m short for "configuration file.” What am I?

May 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with a Special ...

New Articles from Academic Learning Partners, Help Expand Lantern’s Use Case Library, ...

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Your Guide to SPL2 at .conf24!

So, you’re headed to .conf24? You’re in for a good time. Las Vegas weather is just *chef’s kiss* beautiful in ...