Reporting

How to call a savedsearch with optional arguments

meister245
New Member

Hello everyone,

I'm very new to splunk and I find it very different than what I have worked so far. I am writing saved searches, where I am passing arguments to the search. I'm looking for a solution how would I be able to pass arguments to a search, that default to a value if the parameter was not given.
Something like this:

[My Search]
search = | savedsearch "Sample Search" \
             argument1=$argument1$ \
             argument2=$argument2$ \
             argument3=if(isnull($argument3$), default_value, $argument3$)

Any advice?

Thanks,

Labels (1)
0 Karma

richgalloway
SplunkTrust
SplunkTrust

You could define multiple macros that call your savedsearch. Each macro would have a the same name, but a different number of arguments and would call the savedsearch with the appropriate default value.

---
If this reply helps you, Karma would be appreciated.
0 Karma

meister245
New Member

As added comment, I only want to have 1 search defined, that is multi purpose based on the number of arguments it receives. (minimal code redundancy)

0 Karma
Get Updates on the Splunk Community!

Join Us for Splunk University and Get Your Bootcamp Game On!

If you know, you know! Splunk University is the vibe this summer so register today for bootcamps galore ...

.conf24 | Learning Tracks for Security, Observability, Platform, and Developers!

.conf24 is taking place at The Venetian in Las Vegas from June 11 - 14. Continue reading to learn about the ...

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...