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!

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 ...