Splunk Search

Zero count not displaying when stats count is used

Harshi1993
New Member

My query is :

index="stage*" source="*record service*" | eval type=case(like(message, "%successful generated account%"),"Success Accounts",
like(message, "%Granting failed Accounts%"),"Granting failed Accounts", like(message, "%Inbound setup failed accounts%"),"Inbound  failed Accounts")|
stats count as Results by type

I am getting the result as:

type                                               Results

Success Accounts                   10

Granting failed Accounts       20

 

I am unable to get the results for the string  Inbound failed Accounts as the results are zero. I need the output as 

type                                               Results

Success Accounts                   10

Granting failed Accounts       20

Inbound  failed Accounts         0

 

Please help me with the query for displaying the strings with zero count as well

 

Labels (1)
0 Karma

renjith_nair
Legend

Try

index="stage*" source="*record service*" 
| eval type=case(like(message, "%successful generated account%"),"Success Accounts",
like(message, "%Granting failed Accounts%"),"Granting failed Accounts", like(message, "%Inbound setup failed accounts%"),"Inbound  failed Accounts")
|stats count as Results by type
|append [|stats count as Results|eval type="Success Accounts,Granting failed Accounts,Inbound  failed Accounts"|makemv type delim=","|mvexpand type]
|stats sum(Results) by type

 

---
What goes around comes around. If it helps, hit it with Karma 🙂

PickleRick
SplunkTrust
SplunkTrust

It's a typical mistake to want to have knowledge about _what_ was done earlier "down the road" whereas Splunk doesn't work that way.

After a pipe you get only a _result_ of the command from before the pipe. So if any command is supposed to look for - let's say - one of three different values but finds only two of them, the result will only have two of those values and any subsequent command won't have the knowledge that you wanted to search for the third value as well. You only get the results.

So the most obvious workaround in such case as yours is - as @ITWhisperer showed - creating an initial set of "empty" (with a value of zero) result set and then sum this set with your actual result. That way if you don't have any other results, you'll just stay with your static results of zero hits.

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
| append [| makeresults
| eval type=split"Success Accounts|Granting failed Accounts|Inbound  failed Accounts","|")
| mvexpand type
| eval Results=0
| table type Results]
| stats sum(Results) as Results by type
Get Updates on the Splunk Community!

Stay Connected: Your Guide to July Tech Talks, Office Hours, and Webinars!

What are Community Office Hours?Community Office Hours is an interactive 60-minute Zoom series where ...

Updated Data Type Articles, Anniversary Celebrations, and More on Splunk Lantern

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

A Prelude to .conf25: Your Guide to Splunk University

Heading to Boston this September for .conf25? Get a jumpstart by arriving a few days early for Splunk ...