Splunk Search

Index,sourcetype as parameter in search

splunk_learner
Explorer

Hi,
I want search query to read my index name and sourcetype name from config file.So that if there is any change in future,i dont have to edit all of the searches for a particular app.Is there any way to pass parameter from config file to search query for an particular app only.

Tags (2)
0 Karma
1 Solution

jonuwz
Influencer

The usual way to do this is to create a macro called something like get_index_name

Then have the macro return the name of the index.

i.e. the macro would be defined as :

"index=my_index"

Then all your searches in the app start with

`get_index_name`

When you need to update the name of the index, you just alter the definition of the macro in one place and you're set.

View solution in original post

jonuwz
Influencer

The usual way to do this is to create a macro called something like get_index_name

Then have the macro return the name of the index.

i.e. the macro would be defined as :

"index=my_index"

Then all your searches in the app start with

`get_index_name`

When you need to update the name of the index, you just alter the definition of the macro in one place and you're set.

jonuwz
Influencer

I don't think so. Inputs.conf determines where splunk gets data from, it doesn't set variables.

Also - this isn't my idea, Its just i've noticed that this is how some of the most popular apps on splunk-base tackle the problem

0 Karma

splunk_learner
Explorer

Thanks.This seems to be a gud idea.
I was wondering can inputs.config help us in this requirement?

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...