Splunk Search

What is the difference between these eval commands in a timechart?

HeinzWaescher
Motivator

Hi,

I'm wondering why I'm getting different results here:

1.

... | timechart span=1d count(eval(if(value>"1", value, null()))) AS count

2.

... | timechart span=1d count(eval(if(value>="2", value, null()))) AS count

Can you help me?

BR
Heinz

Tags (2)
0 Karma
1 Solution

hgrow
Communicator

Hi Heinz,

value>=" 2 " leads to some sort of string comparison instead of value>= 2 wich is the correct numerical comparison. By using " " you transform your numerical value into a string, wich messes up the equation.

Greetings

View solution in original post

woodcock
Esteemed Legend

The count(STUFF) says, if "STUFF" for this event is NOT null, then add 1 to "count". The count(eval(STUFF)) says, if "STUFF" (in this case, it must be an equation) evaluates to "true", then add 1 to "count". So in your case, it is probably not doing what you are expecting because:

These 2 are equivalent to eachother:

... | timechart span=1d count(eval(if(value>"1", value, null()))) AS count
... | timechart span=1d count(eval(value>1)) AS count

And also these 2 are equivalent to eachother:

... | timechart span=1d count(eval(if(value>="2", value, null()))) AS count
... | timechart span=1d count(eval(value>=2)) AS count

Probably what you are trying to do is something like this:

... | eval modValue=if(value>1, value, null()) | timechart span=1d sum(modValue) AS modValueSum
... | eval modValue=if(value>=2, value, null()) | timechart span=1d sum(modValue) AS modValueSum
0 Karma

hgrow
Communicator

Hi Heinz,

value>=" 2 " leads to some sort of string comparison instead of value>= 2 wich is the correct numerical comparison. By using " " you transform your numerical value into a string, wich messes up the equation.

Greetings

HeinzWaescher
Motivator

Oh, of course. Thanks a lot!

Cheers
Heinz

PS: I think you wanted to write value>=2.

0 Karma

hgrow
Communicator

Indeed 😄 Just changed it.

Have a great day!

0 Karma
Get Updates on the Splunk Community!

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...