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!

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer Certification at ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...