Splunk Search

Why won't If statement evaluate as true?

anjuliwyles
Engager

When I place event.code into an if statement, it will not evaluate as true

 

Currently I have this code:

index = windows-security event.code IN (4624)
| eval Success=if(event.code = "4624", 1, 0)
| stats count by Success

 

Success always evaluates to 0. I have tried using

match(event.code, "4624")

match(event.code, '4624')

match(event.code, ".+")

like(event.code, "4624")

like(event.code, '4624')

I even tried event.code = event.code

 

Always 0.

Labels (1)
0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

Since event.code probably is an integer have you tried 

 

| eval Success=if(event.code = 4624, 1, 0)

 

It's possible Splunk is struggling with the field name.  Try renaming it before the conditional.

 

| rename event.* as *
| eval Success = if(code=4624, 1, 0)

 

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

View solution in original post

richgalloway
SplunkTrust
SplunkTrust

Since event.code probably is an integer have you tried 

 

| eval Success=if(event.code = 4624, 1, 0)

 

It's possible Splunk is struggling with the field name.  Try renaming it before the conditional.

 

| rename event.* as *
| eval Success = if(code=4624, 1, 0)

 

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

anjuliwyles
Engager

Renaming the field worked! Thank you

Get Updates on the Splunk Community!

Splunk Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI! Discover how Splunk’s agentic AI ...

[Puzzles] Solve, Learn, Repeat: Dereferencing XML to Fixed-length events

This challenge was first posted on Slack #puzzles channelFor a previous puzzle, I needed a set of fixed-length ...

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

What are Community Office Hours? Community Office Hours is an interactive 60-minute Zoom series where ...