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!

Archived Metrics Now Available for APAC and EMEA realms

We’re excited to announce the launch of Archived Metrics in Splunk Infrastructure Monitoring for our customers ...

Detecting Remote Code Executions With the Splunk Threat Research Team

WATCH NOWRemote code execution (RCE) vulnerabilities pose a significant risk to organizations. If exploited, ...

Enter the Dashboard Challenge and Watch the .conf24 Global Broadcast!

The Splunk Community Dashboard Challenge is still happening, and it's not too late to enter for the week of ...