Splunk Search

Strange behaviour with count in stats when using macros

sohrab
Explorer

I have a macro which is in the format:

match($field$,"regex1") OR match($field$,"regex2") OR ...

When I use it in snippet like this:

| stats count(mvcount(mvfilter(`macro-name(field=fieldName)`))>0) AS something

While the search is running, I can see "something" gets incremented but suddenly drops to 0 when the search is finalised. If I run the above again but replace the macro invocation with its actual macro content, i.e.:

| stats count(mvcount(mvfilter(match(fieldName,"regex1") OR match(fieldName,"regex2") OR ...))>0) AS something

"something" actually returns a non-zero result. Another experiment I tried was the following instead of the stats:

| where mvcount(mvfilter(`macro-name(field=fieldName)`))>0

And the number of the results I get back is identical to value of "something" in the last stats snippet.

So it seems to me there is something about using macros inside the count function, that Splunk cannot handle. Am I doing something wrong or is this a known limitation?

Tags (3)
0 Karma

woodcock
Esteemed Legend

You are calling your macro wrong. You should call it as macro-name(fieldname). There might be more wrong, but this problem is fatal.

0 Karma

sohrab
Explorer

I have encountered similar issues when using stats in a saved search which is called via "savedsearch" command.

0 Karma
Get Updates on the Splunk Community!

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

Splunk APM: New Product Features + Community Office Hours Recap!

Howdy Splunk Community! Over the past few months, we’ve had a lot going on in the world of Splunk Application ...

Index This | Forward, I’m heavy; backward, I’m not. What am I?

April 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...