Splunk Search

How to solve this issue with eval if?

SumanPalisetty
Path Finder

Hi,

I am facing an issue with the eval if condition. Please help.

 

index=main, source=ls.csv
| eval new_field = if(error=200,"sc","cs",if(error=500,"css","ssc"))
| table error new_field

 

 

erro.png

Regards

Suman P.

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

richgalloway
SplunkTrust
SplunkTrust

There are too many arguments to the first if.  Each if function can have only 3 arguments - an expression to test, the value to set if true, and the value to set if false.  If you want nested ifs then it needs to look more like this:

| eval new_field = if(error=200,"sc", if(error=500,"css","ssc"))
---
If this reply helps you, Karma would be appreciated.

View solution in original post

richgalloway
SplunkTrust
SplunkTrust

There are too many arguments to the first if.  Each if function can have only 3 arguments - an expression to test, the value to set if true, and the value to set if false.  If you want nested ifs then it needs to look more like this:

| eval new_field = if(error=200,"sc", if(error=500,"css","ssc"))
---
If this reply helps you, Karma would be appreciated.
Get Updates on the Splunk Community!

Updated Team Landing Page in Splunk Observability

We’re making some changes to the team landing page in Splunk Observability, based on your feedback. The ...

New! Splunk Observability Search Enhancements for Splunk APM Services/Traces and ...

Regardless of where you are in Splunk Observability, you can search for relevant APM targets including service ...

Webinar Recap | Revolutionizing IT Operations: The Transformative Power of AI and ML ...

The Transformative Power of AI and ML in Enhancing Observability   In the realm of IT operations, the ...