Splunk Search

I have been trying to use the CASE function in splunk, but my results are not correct

NanSplk01
Communicator

This is my search.  I brings back Not Known for every field instead of the correct case name:

index=websphere websphere_logEventType=*
| stats count(websphere_logEventType) BY websphere_logEventType
| eval websphere_logEventType=case(websphere_logEventType=I, "INFO",websphere_logEventType=E, "ERROR", websphere_logEventType=W, "WARNING", websphere_logEventType=D, DEBUG, true(),"Not Known" )

 

What am I missing that will bring the count and the case that the count is for instead of always the Not Known case?

Labels (3)
Tags (1)
0 Karma
1 Solution

NanSplk01
Communicator

Thanks, I used a similar configuration and now it works.  I had to use the == rather than the =

index=websphere websphere_logEventType=*
| stats count(websphere_logEventType) BY websphere_logEventType
| eval websphere_logEventType=case(websphere_logEventType=="I", "INFO",websphere_logEventType=="E", "ERROR", websphere_logEventType=="W", "WARNING", websphere_logEventType=="D", DEBUG, true(),"Not Known" )
| dedup websphere_logEventType

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust

Assuming websphere_logEventType is a string, try something like this

| eval websphere_logEventType=case(websphere_logEventType="I", "INFO",websphere_logEventType="E", "ERROR", websphere_logEventType="W", "WARNING", websphere_logEventType="D", "DEBUG", true(),"Not Known" )

Otherwise, I, E, W and D are treated as field names (which don't appear to exist, hence the case evaluates to "Not Known")

0 Karma

sainag_splunk
Splunk Employee
Splunk Employee

Hey @NanSplk01 try 

... | eval websphere_logEventType=case(websphere_logEventType=I, "INFO", websphere_logEventType=E, "ERROR", websphere_logEventType=W, "WARNING", websphere_logEventType=D, "DEBUG", 1=1, "Not Known")






If this Helps, Please Upvote.

If this helps, Upvote!!!!
Together we make the Splunk Community stronger 
0 Karma

NanSplk01
Communicator

Thanks, I used a similar configuration and now it works.  I had to use the == rather than the =

index=websphere websphere_logEventType=*
| stats count(websphere_logEventType) BY websphere_logEventType
| eval websphere_logEventType=case(websphere_logEventType=="I", "INFO",websphere_logEventType=="E", "ERROR", websphere_logEventType=="W", "WARNING", websphere_logEventType=="D", DEBUG, true(),"Not Known" )
| dedup websphere_logEventType
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...