Splunk Enterprise

Metadata token inside macro

akai
Explorer

Hello,

I have a requirement where I need to have the name of the current running saved search available to itself. And to avoid human error, I am looking for an automated way of doing this.

Based on this question, I can use | eval search_name="$name$" and it works fine, but I was looking into a way of putting that inside a macro. Unfortunately, when doing that, search_name ends up with the literal value "$name$".

Is anyone doing something similar and has a solution? 

Thank you

Labels (2)
0 Karma

VatsalJagani
SplunkTrust
SplunkTrust

Hello @akai ,

The issue is $name$ inside the macro is no longer a token its more of a macro parameter.

In order to fix you need to pass $name$ as a macro argument from the saved search itself.

Define your macro to accept the search name as an argument — e.g., my_macro(1) with argument search_name. And macro definition would be something like this:

[my_macro(1)]
args = search_name
definition = eval search_name=$search_name|s$

 

Then you can call the macro like this:

.....
| `my_macro($name$)`
| table search_name



I hope this helps!!!

Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas     Cisco Live 2026 is almost here, and this ...

What Is the Name of the USB Key Inserted by Bob Smith? (BOTS Hint, Not the Answer)

Hello Splunkers,   So you searched, “what is the name of the usb key inserted by bob smith?”  Not gonna lie… ...

Automating Threat Operations and Threat Hunting with Recorded Future

    Automating Threat Operations and Threat Hunting with Recorded Future June 29, 2026 | Register   Is your ...