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!

See your relevant APM services, dashboards, and alerts in one place with the updated ...

As a Splunk Observability user, you have a lot of data you have to manage, prioritize, and troubleshoot on a ...

Splunk App for Anomaly Detection End of Life Announcement

Q: What is happening to the Splunk App for Anomaly Detection?A: Splunk is officially announcing the ...

Aligning Observability Costs with Business Value: Practical Strategies

 Join us for an engaging Tech Talk on Aligning Observability Costs with Business Value: Practical ...