Splunk Search

Is it currently possible to somehow create a conditional macro expansion?

shubs
Engager

Hi all,
Is it currently possible to somehow create a conditional macro expansion?

For example, I have different list of hosts and wanted to expand base the macro argument.

`myhosts(old)` would expand to
host=hostname1 OR host=hostname2


`myhosts(new)` would expand to
host=hostname3 OR host=hostname4

I looked into different functions to somehow implement it but could not find a solution 😞
Thank you.

Tags (1)
0 Karma

shubs
Engager

Nice! A simple solution. Thanks 🙂

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Macros are just text expansions. You could build the condition into your macro

("$select$"=="new" AND (host=="hostA" OR host=="hostB")) OR ("$select$"=="old" AND (host=="hostC" OR host=="hostD"))

and use it for example like this

| where `myhosts("old")`
Get Updates on the Splunk Community!

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

Index This | What goes away as soon as you talk about it?

May 2025 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with this month’s ...

What's New in Splunk Observability Cloud and Splunk AppDynamics - May 2025

This month, we’re delivering several new innovations in Splunk Observability Cloud and Splunk AppDynamics ...