Splunk Search

How to put found and not found results of search in two different lists

pitmod
Explorer

Hi,

I have the following search and sub-search:

index=someindex source=somesource | search [search index=otherindex source=othersource | fields hostname]

My subsearch generates list of hostnames. As a result I'd like to get list of hosts that have been found by main search and list of hosts that have not been found. 

The hosts not found I'd like to put in one table and the on hosts found apply some filter and present in another table.

 

Labels (2)
0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

Hi @pitmod,

do you want one search (or panel) or two?

if you want two searches, you can run something like these:

Search 1 (included):

index=someindex source=somesource [search index=otherindex source=othersource | fields hostname]
| ...

search 2 (not included):

index=someindex source=somesource NOT search index=otherindex source=othersource | fields hostname]
| ...

If instead you want only one search:

(index=someindex source=somesource) OR (index=otherindex source=othersource)
| stats dc(index) AS dc_index values(index) AS index BY hostname
| eval status=if(dc_index="2", "Both", if(index="someindex","Only someindex","Only otherindex"))
| table hostname status

Al the searches can run if the field hostname is present in both the indexes, if not you have to rename one of them.

Ciao.

Giuseppe

View solution in original post

gcusello
SplunkTrust
SplunkTrust

Hi @pitmod,

do you want one search (or panel) or two?

if you want two searches, you can run something like these:

Search 1 (included):

index=someindex source=somesource [search index=otherindex source=othersource | fields hostname]
| ...

search 2 (not included):

index=someindex source=somesource NOT search index=otherindex source=othersource | fields hostname]
| ...

If instead you want only one search:

(index=someindex source=somesource) OR (index=otherindex source=othersource)
| stats dc(index) AS dc_index values(index) AS index BY hostname
| eval status=if(dc_index="2", "Both", if(index="someindex","Only someindex","Only otherindex"))
| table hostname status

Al the searches can run if the field hostname is present in both the indexes, if not you have to rename one of them.

Ciao.

Giuseppe

pitmod
Explorer

Thanks Giuseppe, the second approach would work for me. The issue is that the fields have different names and format: hostname for someindex is base name and host for otherindex is fqdn. I've tried to run eval and rename like here:

(index=someindex source=somesource) OR (index=otherindex source=othersource)
| eval myhostname=mvindex(split(host,"."),0) 
| rename myhostname as hostname 
| stats dc(index) AS dc_index values(index) AS index BY hostname

but it returns only hostnames for the otherindex search so sth is not right. 

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @pitmod,

if the answer solves your problem, please accept it for the Community, otherwise tell me how can I help you.

Ciao ang good splunking.

Giuseppe

0 Karma

pitmod
Explorer

I fixed it by renaming both fields. Thanks

Tags (1)
0 Karma
Get Updates on the Splunk Community!

Troubleshooting the OpenTelemetry Collector

  In this tech talk, you’ll learn how to troubleshoot the OpenTelemetry collector - from checking the ...

Adoption of Infrastructure Monitoring at Splunk

  Splunk's Growth Engineering team showcases one of their first Splunk product adoption-Splunk Infrastructure ...

Modern way of developing distributed application using OTel

Recently, I had the opportunity to work on a complex microservice using Spring boot and Quarkus to develop a ...