Splunk Enterprise

Add dummy row with 0 when count returns 0

jip31
Motivator

Hi

I  need to display 0 in the field "Number of index" if there is no host in this index

I tried but I have no results

Could you help me please??

 

 

| tstats count where (index=agd-*) by host index 
| join host 
    [| inputlookup fo_all] 
| stats dc(index) as "Number of index" by host 
| appendpipe 
    [| stats count as countKO
    | where countKO = 0 ] 
| eval countKO=if(countKO=0,"No host in index",countKO) 
| table countKO

 

 

  

Tags (1)
0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@jip31 

Are you looking something like this?

| tstats count where (index=agd-*) by host index 
| append
    [| inputlookup fo_all] 
| stats dc(index) as countKO by host | eval countKO=if(countKO=0,"No host in index",countKO)

 

0 Karma

jip31
Motivator

Hi

Your code works but I have "No host in index" values and it's not normal...

So i a m always unable to display host with count = 0....

0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@jip31 

Can you please share your expected OP if there is no host in index?? As there are no rec in tstats  search and I think lookup has only host values (correct me if my guessing is wrong).  What should be Output... !!?

 

KV

0 Karma

jip31
Motivator

Is anybody can't help?

0 Karma

inventsekar
SplunkTrust
SplunkTrust

Hi @jip31 ... the if condition was wrong.. pls try this.. (i ran without the inputlookup, when you run it with the inputlookup, it should just be fine i think)

| tstats count where (index=agd-*) by host index  
| stats dc(index) as "Number of index" by host 
| appendpipe 
    [| stats count as countKO
    | where countKO = 0 ] 
| eval countKO=if(countK0="No host in index", "countKO=0", countKO) 
| table countKO

if-condition.jpg

if this resolves your query, pls accept it as answer.. upvote would be appreciated. thanks.

thanks and best regards,
Sekar

PS - If this or any post helped you in any way, pls consider upvoting, thanks for reading !
0 Karma

jip31
Motivator

unfortunately it doesnt works

And i think it's countKO="0" instead "countKO=0" ??

 what I need is to display 0 in the "Number of index" field if the hostname doesnt exists in the index

0 Karma
Get Updates on the Splunk Community!

Index This | What is broken 80% of the time by February?

December 2025 Edition   Hayyy Splunk Education Enthusiasts and the Eternally Curious!    We’re back with this ...

Unlock Faster Time-to-Value on Edge and Ingest Processor with New SPL2 Pipeline ...

Hello Splunk Community,   We're thrilled to share an exciting update that will help you manage your data more ...

Splunk MCP & Agentic AI: Machine Data Without Limits

Discover how the Splunk Model Context Protocol (MCP) Server can revolutionize the way your organization uses ...