Dashboards & Visualizations

How to set an index dynamically

a212830
Champion

Hi,

Is is possible to set an index value dynamically?

I have the following paths:

/opt/fimt/../../filea

/opt/ctg/../../filea

/opt/fpcms/../../filea

More and more are going to be added in the future, and rather than hardcode values, we were thinking of setting a default index (main) and then setup a props/transforms to look at the second part of the path, and then, based upon that value, route the events to a certain index.

So, if the path included fimt, go to one index, ctg another.... Has anyone done something like this?

rashi83
Path Finder

@esix_splunk - IS there any way to index with correct app name is not there , then it should create that index on the fly.

0 Karma

esix_splunk
Splunk Employee
Splunk Employee

You can set this at index time based on the source metadata. Depending on your Splunk architecture, this will need to placed at the proper HF/IDX layer.

 [send_to_index_by_source1]
 SOURCE_KEY = MetaData:Source
 REGEX = ^source::/opt/fimt/../../filea
 DEST_KEY = _MetaData:Index
 FORMAT = myindex

See this post : https://answers.splunk.com/answers/148341/how-to-assign-syslog-file-to-specific-index-based-on-file-...

a212830
Champion

Thanks. My index name doesn't match what is that in that part of the path, so I can't just map them. Was thinking more along the lines of a case statement (or it's equivalent). Is that possible?

0 Karma

sloshburch
Splunk Employee
Splunk Employee

I don't understand. Is the index name always a certain part of the path? If not, maybe share more about where you want to pull the index name from.

0 Karma

somesoni2
Revered Legend

The case statement equivalent here would be to create that many transforms stanza for each combination. [send_to_index_by_source1] [send_to_index_by_source2] ... for each variation of sources.

0 Karma

a212830
Champion

Thanks. Is there anyway to look at just the second part of the source path?

0 Karma

somesoni2
Revered Legend

It will be like this

[send_to_index_by_source1]
  SOURCE_KEY = MetaData:Source
  REGEX = ^source::/opt/([^/]+)/../../filea
  DEST_KEY = _MetaData:Index
  FORMAT = index::$1
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 ...