Splunk Search

Can I use a macro within a macro?

Splunk Employee
Splunk Employee

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

Tags (2)
0 Karma

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

SplunkTrust
SplunkTrust

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)`