Splunk Search

Can I use a macro within a macro?

Dimitri_McKay
Splunk Employee
Splunk Employee

Wondering if it's possible to embed a macro into another macro.

Tags (2)
0 Karma

edschembor
Path Finder

See the Splunk documentation for this: http://docs.splunk.com/Splexicon:Searchmacro

Directly from the docs: "You can also nest search macros within each other."

somesoni2
Revered Legend

Yes it is possible.

Here is one example.
Definition

macros.conf

[getCountStatus(1)]
args = count
definition = eval CountStatus=if($count$>100,"Heavy","Light")
iseval = 0

[getRowColorWithCountStatus(1)]
args = count
definition = `getCountStatus($count$)` | eval RowColor=if(CountStatus="Heavy","Read","Green")
iseval = 0

Usage:

index=_internal earliest=-15m@m  | stats count by sourcetype |`getRowColorWithCountStatus(count)`
Get Updates on the Splunk Community!

Good Sourcetype Naming

When it comes to getting data in, one of the earliest decisions made is what to use as a sourcetype. Often, ...

See your relevant APM services, dashboards, and alerts in one place with the updated ...

As a Splunk Observability user, you have a lot of data you have to manage, prioritize, and troubleshoot on a ...

Splunk App for Anomaly Detection End of Life Announcement

Q: What is happening to the Splunk App for Anomaly Detection?A: Splunk is officially announcing the ...