Splunk Search

How to compare nested case statements with eval

anu1729
Loves-to-Learn Lots

Hi,

I am trying to use case keyword to solve a multiple nested statement  but it is just giving me output for the else value, it seems like it is not going inside any other statement to check, Could anyone please help me here. I tired using multiple if statement with eval still I was having the same issue.

Problem statement : I want to compare the value of status-fail and status-success and on the basis of that we need to generate the output

case1 : if value of status-fail =0 and status-success>0 ---> successful logins

case2: if value of status-fail >0 and status-success>0 --->  multi-successful logins

case3: if value of status-fail >0 and status-success=0 ---> multi-fail

case4: if value of status-fail >0  ---> fail logins

Below is the query what I am using :

table hqid, httpStatus | eval status-success=if(httpStatus="200",1,0) | eval status-fail= if(httpStatus != "200",1,0)
| stats sum(status-success) as status-success, sum(status-fail) as status-fail by hqid | eval status = case(status-fail = 0 AND status-success > 0, "successful-logins", status-fail > 0 AND status-success > 0, "multi-success", status-fail > 0 AND status-success=0, "multi-fail", status-fail > 0, "fail",1=1,"Others")

Labels (1)
Tags (1)
0 Karma

anu1729
Loves-to-Learn Lots

Thank you , its working now.

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Try putting the field names with hyphens in in single quotes - something like this (or use fieldnames without hyphens!)

table hqid, httpStatus | eval status-success=if(httpStatus="200",1,0) | eval status-fail= if(httpStatus != "200",1,0)
| stats sum(status-success) as status-success, sum(status-fail) as status-fail by hqid | eval status = case('status-fail' = 0 AND 'status-success' > 0, "successful-logins", 'status-fail' > 0 AND 'status-success' > 0, "multi-success", 'status-fail' > 0 AND 'status-success'=0, "multi-fail", 'status-fail' > 0, "fail",1=1,"Others")
0 Karma
Get Updates on the Splunk Community!

Fueling your curiosity with new Splunk ILT and eLearning courses

At Splunk Education, we’re driven by curiosity—both ours and yours! That’s why we’re committed to delivering ...

Splunk AI Assistant for SPL 1.1.0 | Now Personalized to Your Environment for Greater ...

Splunk AI Assistant for SPL has transformed how users interact with Splunk, making it easier than ever to ...

Unleash Unified Security and Observability with Splunk Cloud Platform

     Now Available on Microsoft AzureOn Demand Now Step boldly into the AI revolution with enhanced security ...