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!

Detecting Remote Code Executions With the Splunk Threat Research Team

WATCH NOWRemote code execution (RCE) vulnerabilities pose a significant risk to organizations. If exploited, ...

Enter the Splunk Community Dashboard Challenge for Your Chance to Win!

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

.conf24 | Session Scheduler is Live!!

.conf24 is happening June 11 - 14 in Las Vegas, and we are thrilled to announce that the conference catalog ...