Splunk Search

How to get stats count value as 0, if there are no events for that value in splunk search.

guptap2
New Member

We have 7 different filetypes, we are trying to get count of each filetype in table. If count of any of them is 0, it should be displayed, but somehow in my query it is removing the row of the filetype having count 0.

Query :
index=sap_bam sourcetype=sap_d059 earliest=-6h filetype=Billing OR filetype=SalesOrder OR filetype=Clearing OR filetype=Delivery OR filetype=ReturnOrder OR filetype=M39COGSSIT OR filetype=M39AcutualRevenueRec
| dedup source
| eventstats count by filetype
| dedup filetype
| rename count as filecount
| eval alertme=if((filecount=0) OR isnull(filecount),1,0)
| fields sourcetype filetype filecount alertme
| table filetype filecount alertme

Result is :

alertme filecount filecount
SalesOrder 6 0
Billing 6 0
Delivery 6 0
ReturnOrder 6 0
Clearing 5 0
M39COGSSIT 3 0

Tags (1)
0 Karma

kmaron
Motivator

try this

| stats count 
| eval filetype="Billing,SalesOrder,Clearing,Delivery,ReturnOrder,M39COGSSIT,M39AcutualRevenueRec" 
| makemv delim="," filetype 
| mvexpand filetype 
| append 
    [ index=sap_bam sourcetype=sap_d059 earliest=-6h filetype=Billing OR filetype=SalesOrder OR filetype=Clearing OR filetype=Delivery OR filetype=ReturnOrder OR filetype=M39COGSSIT OR filetype=M39AcutualRevenueRec 
    | dedup source] 
| stats sum(eval(if(isnull(_time),0,1))) as filecount by filetype 
| eval alertme=if(filecount=0,1,0) 
| table filetype filecount alertme
0 Karma
Get Updates on the Splunk Community!

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...