Splunk Dev

If statement with multiple tests?

msarro
Builder

Is it possible to do something like this? It would make my life a whole lot easier if this can be done, or at least something like it...

eval if(((TimeTaken>15) AND ((Termination_Cause=="016") OR (Termination_Cause=="017"))),1,0)

When I try it I get an error stating that the expression is malformed. Any advice is appreciated.

Tags (1)
2 Solutions

ayme
Splunk Employee
Splunk Employee

You're not far off

eval foo=if((TimeTaken>15) AND (Termination_Cause=="016" OR Termination_Cause=="017"),1,0)

View solution in original post

araitz
Splunk Employee
Splunk Employee

You should probably post your whole search, there are might be some extra parenthesis in there.

Note that eval takes the form:

eval <my_field> = <my_eval_expression>

Also, I think you can use searchmatch() here more efficiently:

eval case=searchmatch("TimeTaken>15 AND (Termination_Cause="16" OR Termination_Cause="17")")

If case=true, then the event matches the condition.

View solution in original post

araitz
Splunk Employee
Splunk Employee

You should probably post your whole search, there are might be some extra parenthesis in there.

Note that eval takes the form:

eval <my_field> = <my_eval_expression>

Also, I think you can use searchmatch() here more efficiently:

eval case=searchmatch("TimeTaken>15 AND (Termination_Cause="16" OR Termination_Cause="17")")

If case=true, then the event matches the condition.

araitz
Splunk Employee
Splunk Employee

Please comment when voting down an answer. My answer is perfectly valid.

0 Karma

ayme
Splunk Employee
Splunk Employee

You're not far off

eval foo=if((TimeTaken>15) AND (Termination_Cause=="016" OR Termination_Cause=="017"),1,0)

msarro
Builder

This worked, thanks!

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...