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!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...