Splunk Search

Show only fields values found in subsearch

niuk
Engager

I have search like below to show me 'src_ip' and 'count' every last 10 min

index="pan" sourcetype="pan:threat" earliest=-10m action=allowed NOT [| inputlookup Exclusions | fields src_ip] | stats count by src_ip| where count > 10 | sort - count

1.1.1.1 10

2.2.2.2 12

and second search to show only src_ip in last 24h (to eliminate src_ip repeated in any of 10 min periods for last 24h)

index="pan" sourcetype="pan:threat" earliest =-24h action=allowed NOT [| inputlookup Exclusions ] | bin _time span=10m | stats count by _time src_ip | where count > 10 | stats count by src_ip | where count = 1 | fields - count

but combined search to show my only src_ip with count where src_ip is present in subsearch is not working correctly .. because src_ip values are not unique in subsequent 10 min interval

index="pan" sourcetype="pan:threat" earliest=-10m action=allowed NOT [| inputlookup Exclusions | fields src_ip] | stats count by src_ip| where count > 10 | sort - count IN [index="pan" sourcetype="pan:threat" earliest =-24h action=allowed NOT [| inputlookup Exclusions ] | bin _time span=10m | stats count by _time src_ip | where count > 10 | stats count by src_ip | where count = 1 | fields - count]

 

 

 

Labels (2)
0 Karma

richgalloway
SplunkTrust
SplunkTrust

I suspect one reason the combined query is not working correctly is the questionable syntax.  Specifically, the sort - count IN [<subsearch].  Splunk will attempt to sort the results by the count and IN fields as well as the text returned by the subsearch (interpreted as column names).  It may sort results, but they won't be the expected results.

When working with subsearches, always run the subsearch by itself with | format appended to it.  The resulting string is what will be added to the main search and executed.  Make sure the result make sense as part of the main search.

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

niuk
Engager

Appreciate looking at it , I run subsearch with '| format' and got below (...cut output)

 

( ( src_ip="10.1.136.6" ) OR ( src_ip="10.1.2.4" ) OR .....cut output )

 

Does the format of subsearch looks good ? Dont know how to pipe that subsearch other than inserting IN after main search...

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!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

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

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...