Splunk Search

Subsearch Help

richardphung
Communicator

I have the following search:

index="*" sourcetype=endpoints [search index="*" signature="sig_id" | dedup dest | fields dest ]

Which produces no results.

Doing each of these, independently works...
For example, the subsearch:

index="*" signature="sig_id" | dedup dest | fields dest

gives me a nice stats table with hostname_1, hostname_2, etc.

And if I manually define this in the main search:

 index="*" sourcetype=endpoints hostname_1

I get all of my events.

Tags (1)
0 Karma
1 Solution

woodcock
Esteemed Legend

You should always use | format at the end of your subsearch so that you can see what it is creating. If you had done so, you would have seen that your subsearch is using the field name in the SPL that it generates (like dest="value"). Based on your test search, you need just the value so try this:

index="*" sourcetype=endpoints [search index="*" signature="sig_id" | dedup dest | fields dest | format "(" "" "" "" "OR" ")" | rex field=search mode=sed "s/dest=//g"]

View solution in original post

yassinesakri
Engager

Hi guys, I hope I can borrow your fantastic brains on this one, I have the same concept, I want to check the top failed ip that authenticated afterwards:

<search_for_authenticated_users> ip [<search_for_failed_user>| top limit=100 client_ip | rename clientip AS ip | table ip ] | top  user ip

I hope someone can shed some light, or direct me somewhere where some else has faced the same problem.

0 Karma

woodcock
Esteemed Legend

You should always use | format at the end of your subsearch so that you can see what it is creating. If you had done so, you would have seen that your subsearch is using the field name in the SPL that it generates (like dest="value"). Based on your test search, you need just the value so try this:

index="*" sourcetype=endpoints [search index="*" signature="sig_id" | dedup dest | fields dest | format "(" "" "" "" "OR" ")" | rex field=search mode=sed "s/dest=//g"]

richardphung
Communicator

This is a great tip.

0 Karma

richardphung
Communicator

Figured it out...
the field dest doesn't exist in the main search.. need to rename field:

index="*" sourcetype=endpoints [search index="*" signature="sig_id"  | dedup dest 
    | rename dest AS client_name | table client_name]

woodcock
Esteemed Legend

It is OK to keep the | format in your search, like this:

index="*" sourcetype=endpoints [ search index="*" signature="sig_id"  | dedup dest | rename dest AS client_name | table client_name | format ]
0 Karma

whrg
Motivator

So your subsearch produces a field named "dest". Is there a "dest" field (containing hostname_1, hostname_2, etc.) available in the primary search?

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...