<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to dynamically  route logs uto multiple indexes and sourcetypes based on file path and filename in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/How-to-dynamically-route-logs-uto-multiple-indexes-and/m-p/499805#M85187</link>
    <description>&lt;P&gt;Hi,&lt;BR /&gt;
I am working on OS log onboarding data under multiple hostname folders and these hostname folders are located at same file path.&lt;BR /&gt;
My plan is to dynamically onboard these logs to indexes based on relevant hostname with dynamic sourcetype set based on filename text.&lt;/P&gt;

&lt;P&gt;My logs directory structure:&lt;BR /&gt;
&lt;CODE&gt;\opt\myAPP\host1\filename_type1.log&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;\opt\myAPP\host2\filename_type2.log&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;\opt\myAPP\host3\filename_type3.log&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Expected index name from foldername: &lt;BR /&gt;
&lt;CODE&gt;indexname_host1&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;indexname_host2&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;indexname_host3&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Expected sourcetype name from filename :&lt;BR /&gt;
&lt;CODE&gt;sourcetype_type1&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;sourcetype_type2&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;sourcetype_type3&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Following are the configuration am using at inputs.conf , where index=route is just placeholder and no such index is created:&lt;BR /&gt;
`[monitor:///opt/myAPP/.../*.log]&lt;BR /&gt;
host_segment = 3&lt;BR /&gt;
index = route&lt;BR /&gt;
sourcetype = reroute_1&lt;BR /&gt;
whitelist = (host1|host4|host5)&lt;/P&gt;

&lt;P&gt;[monitor:///opt/myAPP/.../*.log]&lt;BR /&gt;
host_segment = 3&lt;BR /&gt;
index = route&lt;BR /&gt;
sourcetype = reroute_2&lt;BR /&gt;
whitelist = (host2)&lt;/P&gt;

&lt;P&gt;[monitor:///opt/myAPP/.../*.log]&lt;BR /&gt;
host_segment = 3&lt;BR /&gt;
index = route&lt;BR /&gt;
sourcetype = reroute_3&lt;BR /&gt;
whitelist = (host3)`&lt;/P&gt;

&lt;P&gt;At props.conf&lt;BR /&gt;
`[reroute_1]&lt;BR /&gt;
TRANSFORMS-sourcetype = overridesourcetype1&lt;BR /&gt;
TRANSFORMS-index = overrideindex&lt;/P&gt;

&lt;P&gt;[reroute_2]&lt;BR /&gt;
TRANSFORMS-sourcetype = overridesourcetype2&lt;BR /&gt;
TRANSFORMS-index = overrideindex&lt;/P&gt;

&lt;P&gt;[reroute_3]&lt;BR /&gt;
TRANSFORMS-sourcetype = overridesourcetype3&lt;BR /&gt;
TRANSFORMS-index = overrideindex&lt;BR /&gt;
&lt;CODE&gt;&lt;BR /&gt;
at transforms.conf :&lt;BR /&gt;
&lt;/CODE&gt;[overridesourcetype1]&lt;BR /&gt;
SOURCE_KEY = MetaData:Source&lt;BR /&gt;
DEST_KEY = MetaData:Sourcetype&lt;BR /&gt;
REGEX = source::\/opt\/myAPP\/\w+\/filename_(\w+).*&lt;BR /&gt;
FORMAT = sourcetype::sourcetype_$1&lt;/P&gt;

&lt;P&gt;[overridesourcetype2]&lt;BR /&gt;
SOURCE_KEY = MetaData:Source&lt;BR /&gt;
DEST_KEY = MetaData:Sourcetype&lt;BR /&gt;
REGEX = source::\/opt\/myAPP\/\w+\/filename_(\w+).*&lt;BR /&gt;
FORMAT = sourcetype::sourcetype_$1&lt;/P&gt;

&lt;P&gt;[overridesourcetype3]&lt;BR /&gt;
SOURCE_KEY = MetaData:Source&lt;BR /&gt;
DEST_KEY = MetaData:Sourcetype&lt;BR /&gt;
REGEX = source::\/opt\/myAPP\/\w+\/filename_(\w+).*&lt;BR /&gt;
FORMAT = sourcetype::sourcetype_$1&lt;/P&gt;

&lt;P&gt;[overrideindex]&lt;BR /&gt;
SOURCE_KEY = MetaData:Source&lt;BR /&gt;
REGEX = source::\/opt\/myAPP\/(\w+).*&lt;BR /&gt;
DEST_KEY = &lt;EM&gt;MetaData:Index&lt;BR /&gt;
FORMAT = index&lt;/EM&gt;$1`&lt;/P&gt;

&lt;P&gt;However, all the log files are indexed into the index="indexname_host3".&lt;/P&gt;

&lt;P&gt;Is there any way to route this as mentioned under 'Expected'.&lt;/P&gt;

&lt;P&gt;Kindly help...&lt;/P&gt;</description>
    <pubDate>Wed, 30 Sep 2020 03:13:31 GMT</pubDate>
    <dc:creator>harshal_chakran</dc:creator>
    <dc:date>2020-09-30T03:13:31Z</dc:date>
    <item>
      <title>How to dynamically  route logs uto multiple indexes and sourcetypes based on file path and filename</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-dynamically-route-logs-uto-multiple-indexes-and/m-p/499805#M85187</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;
I am working on OS log onboarding data under multiple hostname folders and these hostname folders are located at same file path.&lt;BR /&gt;
My plan is to dynamically onboard these logs to indexes based on relevant hostname with dynamic sourcetype set based on filename text.&lt;/P&gt;

&lt;P&gt;My logs directory structure:&lt;BR /&gt;
&lt;CODE&gt;\opt\myAPP\host1\filename_type1.log&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;\opt\myAPP\host2\filename_type2.log&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;\opt\myAPP\host3\filename_type3.log&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Expected index name from foldername: &lt;BR /&gt;
&lt;CODE&gt;indexname_host1&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;indexname_host2&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;indexname_host3&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Expected sourcetype name from filename :&lt;BR /&gt;
&lt;CODE&gt;sourcetype_type1&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;sourcetype_type2&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;sourcetype_type3&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Following are the configuration am using at inputs.conf , where index=route is just placeholder and no such index is created:&lt;BR /&gt;
`[monitor:///opt/myAPP/.../*.log]&lt;BR /&gt;
host_segment = 3&lt;BR /&gt;
index = route&lt;BR /&gt;
sourcetype = reroute_1&lt;BR /&gt;
whitelist = (host1|host4|host5)&lt;/P&gt;

&lt;P&gt;[monitor:///opt/myAPP/.../*.log]&lt;BR /&gt;
host_segment = 3&lt;BR /&gt;
index = route&lt;BR /&gt;
sourcetype = reroute_2&lt;BR /&gt;
whitelist = (host2)&lt;/P&gt;

&lt;P&gt;[monitor:///opt/myAPP/.../*.log]&lt;BR /&gt;
host_segment = 3&lt;BR /&gt;
index = route&lt;BR /&gt;
sourcetype = reroute_3&lt;BR /&gt;
whitelist = (host3)`&lt;/P&gt;

&lt;P&gt;At props.conf&lt;BR /&gt;
`[reroute_1]&lt;BR /&gt;
TRANSFORMS-sourcetype = overridesourcetype1&lt;BR /&gt;
TRANSFORMS-index = overrideindex&lt;/P&gt;

&lt;P&gt;[reroute_2]&lt;BR /&gt;
TRANSFORMS-sourcetype = overridesourcetype2&lt;BR /&gt;
TRANSFORMS-index = overrideindex&lt;/P&gt;

&lt;P&gt;[reroute_3]&lt;BR /&gt;
TRANSFORMS-sourcetype = overridesourcetype3&lt;BR /&gt;
TRANSFORMS-index = overrideindex&lt;BR /&gt;
&lt;CODE&gt;&lt;BR /&gt;
at transforms.conf :&lt;BR /&gt;
&lt;/CODE&gt;[overridesourcetype1]&lt;BR /&gt;
SOURCE_KEY = MetaData:Source&lt;BR /&gt;
DEST_KEY = MetaData:Sourcetype&lt;BR /&gt;
REGEX = source::\/opt\/myAPP\/\w+\/filename_(\w+).*&lt;BR /&gt;
FORMAT = sourcetype::sourcetype_$1&lt;/P&gt;

&lt;P&gt;[overridesourcetype2]&lt;BR /&gt;
SOURCE_KEY = MetaData:Source&lt;BR /&gt;
DEST_KEY = MetaData:Sourcetype&lt;BR /&gt;
REGEX = source::\/opt\/myAPP\/\w+\/filename_(\w+).*&lt;BR /&gt;
FORMAT = sourcetype::sourcetype_$1&lt;/P&gt;

&lt;P&gt;[overridesourcetype3]&lt;BR /&gt;
SOURCE_KEY = MetaData:Source&lt;BR /&gt;
DEST_KEY = MetaData:Sourcetype&lt;BR /&gt;
REGEX = source::\/opt\/myAPP\/\w+\/filename_(\w+).*&lt;BR /&gt;
FORMAT = sourcetype::sourcetype_$1&lt;/P&gt;

&lt;P&gt;[overrideindex]&lt;BR /&gt;
SOURCE_KEY = MetaData:Source&lt;BR /&gt;
REGEX = source::\/opt\/myAPP\/(\w+).*&lt;BR /&gt;
DEST_KEY = &lt;EM&gt;MetaData:Index&lt;BR /&gt;
FORMAT = index&lt;/EM&gt;$1`&lt;/P&gt;

&lt;P&gt;However, all the log files are indexed into the index="indexname_host3".&lt;/P&gt;

&lt;P&gt;Is there any way to route this as mentioned under 'Expected'.&lt;/P&gt;

&lt;P&gt;Kindly help...&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 03:13:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-dynamically-route-logs-uto-multiple-indexes-and/m-p/499805#M85187</guid>
      <dc:creator>harshal_chakran</dc:creator>
      <dc:date>2020-09-30T03:13:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to dynamically  route logs uto multiple indexes and sourcetypes based on file path and filename</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-dynamically-route-logs-uto-multiple-indexes-and/m-p/499806#M85188</link>
      <description>&lt;P&gt;You don't need 3 separate monitors here, just create one and check with following configurations.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;inputs.conf&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[monitor:///opt/myAPP/.../*.log] 
host_segment = 3
index = route 
sourcetype = reroute_1 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;props.conf:&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[reroute_1]
TRANSFORMS-index_routing = route_to_index
TRANSFORMS-sourcetype_routing = route_to_sourcetype
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;transforms.conf&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[route_to_index]
SOURCE_KEY = MetaData:Host
REGEX = host::(.*)
DEST_KEY = _MetaData:Index
FORMAT = indexname_$1

[route_to_sourcetype]
SOURCE_KEY = MetaData:Host
REGEX = host::(.*)
DEST_KEY = MetaData:Sourcetype
FORMAT = sourcetype_$1
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 03 Dec 2019 06:42:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-dynamically-route-logs-uto-multiple-indexes-and/m-p/499806#M85188</guid>
      <dc:creator>manjunathmeti</dc:creator>
      <dc:date>2019-12-03T06:42:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to dynamically  route logs uto multiple indexes and sourcetypes based on file path and filename</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-dynamically-route-logs-uto-multiple-indexes-and/m-p/499807#M85189</link>
      <description>&lt;P&gt;Hi @harshal_chakranarayan,&lt;BR /&gt;
remember that all the knowledge objects in Splunk are related to sourcetype, so if you have different sourcetypes you cannot use (or it's very difficoult) field extractions, eventtypes, tags, etc...; this means that it isn't a good idea to use different sourcetypes!&lt;/P&gt;

&lt;P&gt;At the same time, why do you want to put logs from hosts in different indexes?&lt;BR /&gt;
Usually indexes are choosen based on retention policies and access right, eventually based on quantity of data (e.g. large data flows aren't stored in indexes together with few data flows), not other.&lt;/P&gt;

&lt;P&gt;In other words, Splunk isn't a database and usually logs are stored in indexes which common retention policies and access rights using a limited number of sourcetypes that permits to manage knowledge objects.&lt;BR /&gt;
Logs are searcheable using all their fields like sourcetype host and others.&lt;/P&gt;

&lt;P&gt;Ciao.&lt;BR /&gt;
Giuseppe&lt;/P&gt;</description>
      <pubDate>Tue, 03 Dec 2019 08:33:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-dynamically-route-logs-uto-multiple-indexes-and/m-p/499807#M85189</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2019-12-03T08:33:33Z</dc:date>
    </item>
  </channel>
</rss>

