Splunk Search

using eval to define actions

PaulaCom
Path Finder

Morning All 

 

I need some help with an spl i am using to define actions requried 

this is my curretn spl which is working fine 


| table cn manager accountExpires mail action
| eval action = case(manager = "NULL", "Manager to be added to account", match(accountExpires, "(never)"), "Apply Expiry Date",1=1,"no action required")

from the above i can see when an expiry date is nt set then the action is to set an expiry date and when the manager is NULL we need to apply a manager

However, there are some cases where the manager is null and also the expiry date is set then we need to do both actions. Currently with the above logic only one action is being noted

I have tried to incorporate both using the following logic but am getting an error 

| table cn manager accountExpires mail action
| eval action = case(manager = "NULL", "Manager to be added to account", match(accountExpires, "(never)"), "Apply Expiry Date", match(accountExpires, "(never)") OR case(manager = "NULL"), "set expiry date and manager"1=1,"no action required")

Appreciate any help or direction on this

thanks

 

P 

 

Labels (1)
0 Karma

livehybrid
SplunkTrust
SplunkTrust

Hi @PaulaCom 

case() returns the value for the first condition that matches, then stops, it never combines conditions, which is why the "both true" scenario collapses into whichever branch is listed first. Your second attempt also has a syntax error: case(manager = "NULL") isn't valid (case needs condition/value pairs), and there's a missing comma before 1=1.

You could try to build the individual flags first with if(), then combine them:

| table cn manager accountExpires mail
| eval needManager=if(manager="NULL",1,0)
| eval needExpiry=if(match(accountExpires,"(never)"),1,0)
| eval action=case(
    needManager=1 AND needExpiry=1,"Set expiry date and manager",
    needManager=1,"Manager to be added to account",
    needExpiry=1,"Apply Expiry Date",
    1=1,"no action required")
| fields - needManager needExpiry

 

This evaluates both conditions independently first, so you can test any combination (including both true) explicitly, rather than relying on case()'s single-match, first-true behaviour.

🌟 Did this answer help you? If so, please consider:

    • Adding karma to show it was useful
    • Marking it as the solution if it resolved your issue
    • Commenting if you need any clarification

Your feedback encourages the volunteers in this community to continue contributing.

PaulaCom
Path Finder

thank you this worked perfectly 

appreciate your input and explaination - makes total sense

 

thanks again 

P 

0 Karma

richgalloway
SplunkTrust
SplunkTrust

If your problem is resolved, then please click the "Accept as Solution" button to help future readers.

---
If this reply helps you, Karma would be appreciated.
0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @PaulaCom ,

good for you, see next time!

let us know if we can help you more, or, please, accept one answer for the other people of Community.

Ciao and happy splunking

Giuseppe

P.S.: Karma Points are appreciated by all the contributors 😉

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @PaulaCom ,

I see three errors in your SPL:

between "set expiry date and manager" and 1=1 you need a comma.

the condition for "set expiry date and manager" should be an AND condition not OR.

the condition "set expiry date and manager" should be listed as first condition, because otherwise one of the previous conditions will win.

Ciao.

Giuseppe

Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Accelerate Splunk App Development with AI

  Learn how to automate the repetitive parts of your build cycle.   Watch On-Demand   Replay the Accelerate ...

Splunk Agent Observability: Measuring AI Value with Splunk Tokenomics on AWS

The AI landscape is moving faster than ever, and our latest 2026 State of Observability report provides the ...

Enterprise Security Watch Party: What’s New in 8.8 - Recap

Splunk Community HQ hosted a Splunk Enterprise Security Watch Party: What’s New In ES 8.8 last Thursday. I had ...