Splunk Search

How to assign value for any field as "0" when no events are there for the field?

abhi04
Path Finder

I have a below query. But the below is not giving results after the July 11 date because there are no events for the Failure. Please help on the below as how we can get failure as "0" for the days where we dont have any failure events. Also the result of the below query have been attached.

index=auto_prod_okta eventType="user.authentication.sso" "target{}.alternateId"=SmartCash earliest=-90d
| rename target{}.alternateId AS "id"
| eval time_day = strftime(_time, "%D")
| stats count(id) as Success by time_day
| join
[ search index=auto_prod_okta "target{}.alternateId"=SmartCash outcome.result="FAILURE" earliest=-90d
| rename target{}.alternateId AS "id"
| eval time_day = strftime(_time, "%D")
| stats dc(id) as Failure by time_day]
| eval TCL=(Success+Failure)
| eval Login_Failure_Percent=round((Failure/TCL)*100,4)
| rename TCL AS Total
| table time_day Failure, Total, Login_Failure_Percent
| sort -time_day

0 Karma
1 Solution

somesoni2
Revered Legend

Give this a try Updated

index=auto_prod_okta (eventType="user.authentication.sso" OR outcome.result="FAILURE") "target{}.alternateId"=SmartCash earliest=-90d 
| eval Success=if(eventType="user.authentication.sso",'target{}.alternateId', null())  
| eval Failure=if('outcome.result'="FAILURE",'target{}.alternateId', null()) 
| timechart span=1d count(Success) as Success dc(Failure) as Failure
| eval time_day = strftime(_time, "%D") 
| eval Total=(Success+Failure) 
| eval Login_Failure_Percent=round((Failure/Total)*100,4) 
| table time_day Failure, Total, Login_Failure_Percent 
| sort -time_day

View solution in original post

somesoni2
Revered Legend

Give this a try Updated

index=auto_prod_okta (eventType="user.authentication.sso" OR outcome.result="FAILURE") "target{}.alternateId"=SmartCash earliest=-90d 
| eval Success=if(eventType="user.authentication.sso",'target{}.alternateId', null())  
| eval Failure=if('outcome.result'="FAILURE",'target{}.alternateId', null()) 
| timechart span=1d count(Success) as Success dc(Failure) as Failure
| eval time_day = strftime(_time, "%D") 
| eval Total=(Success+Failure) 
| eval Login_Failure_Percent=round((Failure/Total)*100,4) 
| table time_day Failure, Total, Login_Failure_Percent 
| sort -time_day

abhi04
Path Finder

This gives me 0 failures for all the days even when the failures are not 0.

0 Karma

somesoni2
Revered Legend

There was single quotes missing in the eval Failure line. Try now.

0 Karma

abhi04
Path Finder

Thanks @somesoni2 . Appreciated your help.

0 Karma

Kawtar
Path Finder

Hello @abhi04,

You should initiate the value with a default value.
Per example:

     1. | eval Login_Failure_Percent  =  0 

Can you try this.

0 Karma
Get Updates on the Splunk Community!

Devesh Logendran, Splunk, and the Singapore Cyber Conquest

At this year’s Splunk University, I had the privilege of chatting with Devesh Logendran, one of the winners in ...

There's No Place Like Chrome and the Splunk Platform

WATCH NOW!Malware. Risky Extensions. Data Exfiltration. End-users are increasingly reliant on browsers to ...

Customer Experience | Join the Customer Advisory Board!

Are you ready to take your Splunk journey to the next level? 🚀 We invite you to join our elite squad ...