Splunk Search

Using `eval` to match all values (or existence) of a field

flow2k
Explorer

Often, we can use eval(myField=someValue)) with aggregate functions like count and avg, as well as time function like per_day, to process matching events. Is there a way for eval to match all values (or equivalently, the existence) of a field? This would be useful for searches like:
timechart per_second(eval(status>-9999))

I tried timechart per_second(eval(status=*)) to no avail.

0 Karma

elliotproebstel
Champion

You can use eval(isnotnull(status)) to test for the existence of a field.

tiagofbmm
Influencer

Hi

I believe the following is what you are looking for.

index=_internal
| timechart count(eval(source like "%")) as src

Let me know please

flow2k
Explorer

Thanks for the answer, but I believe the issue with using count instead of per_second (as in my original post) is that it depends on the span - I will get different answers if span=1h vs span=1min. Would you agree?

0 Karma

tiagofbmm
Influencer

Sorry I tested count and only now tested per_second. The results are coherent though, any aggregation function works the same here.

Answering to your question, yes surely you'll get different results depending on your timespan, because granularity is changing. It is acceptable and somehow expected to produce different results

0 Karma

flow2k
Explorer

Okay, I tried this and it works too. Why does this work - is there documentation on this syntax? Thanks!

0 Karma

tiagofbmm
Influencer

This works because the eval functions the same way as the syntax of the where command. The "%" replaces the "*".

Feel free to accept the answer if you think it clarified your question

0 Karma
Get Updates on the Splunk Community!

Index This | I’m short for "configuration file.” What am I?

May 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with a Special ...

New Articles from Academic Learning Partners, Help Expand Lantern’s Use Case Library, ...

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Your Guide to SPL2 at .conf24!

So, you’re headed to .conf24? You’re in for a good time. Las Vegas weather is just *chef’s kiss* beautiful in ...