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.

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
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

A Four-Part Event Series: Full Stack Observability For the AI Era

As AI reshapes applications, infrastructure, and the way teams operate, the traditional boundaries of ...

SOC4Kafka - New Kafka Connector Powered by OpenTelemetry

The new SOC4Kafka connector, built on OpenTelemetry, enables the collection of Kafka messages and forwards ...

Event Series: Level up your SOC: Advancing with Splunk Enterprise Security

AI has fundamentally raised the stakes for security operations, and this three-part series is your guide to ...