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
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:
Your feedback encourages the volunteers in this community to continue contributing.
thank you this worked perfectly
appreciate your input and explaination - makes total sense
thanks again
P
If your problem is resolved, then please click the "Accept as Solution" button to help future readers.
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 😉
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