<?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 Re: How can I pull out values in a log path and route it to a specific index? in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/How-can-I-pull-out-values-in-a-log-path-and-route-it-to-a/m-p/337816#M62369</link>
    <description>&lt;P&gt;I'm not seeing any parenthesis in the regex to mark the capture group for the index value.  That should probably be something like...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;REGEX =  .*\/index=([^\/]*)\/.*
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;... the value of the index needs to stop at the first slash, so we define a character class &lt;CODE&gt;[^\/]&lt;/CODE&gt; which is any character EXCEPT a slash.  &lt;/P&gt;

&lt;P&gt;You also need to specify/validate what is going to happen to the index name when no capture is found.  &lt;/P&gt;</description>
    <pubDate>Mon, 13 Mar 2017 15:59:10 GMT</pubDate>
    <dc:creator>DalJeanis</dc:creator>
    <dc:date>2017-03-13T15:59:10Z</dc:date>
    <item>
      <title>How can I pull out values in a log path and route it to a specific index?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-can-I-pull-out-values-in-a-log-path-and-route-it-to-a/m-p/337809#M62362</link>
      <description>&lt;P&gt;I am looking to route logs to different indexes based on a specific value identified in the log path.  For example:&lt;/P&gt;

&lt;P&gt;/var/appl/logs/prod/server.log  &amp;gt;&amp;gt; should go to index=prod&lt;BR /&gt;
/var/appl/logs/dev/server.log &amp;gt;&amp;gt; should go to index=dev&lt;BR /&gt;
/var/appl/logs/imp/server.log &amp;gt;&amp;gt; should go to index=imp&lt;BR /&gt;
/var/appl/logs/test/server.log &amp;gt;&amp;gt; should go to index=test&lt;/P&gt;

&lt;P&gt;The log path will always be the same except for the unique value in the 4th sub-directory, which is where our developers are modifying the path to tell us what index they'd like the data in.  &lt;/P&gt;

&lt;P&gt;We have around 180 indexes in our environment so I don't want to create a unique transforms.conf to accommodate for each one.  I'd like to have one transforms.conf that can pull the unique value from the path and place that log in the corresponding index.&lt;/P&gt;

&lt;P&gt;I haven't been able to find great documentation to help me set this up.  Any assistance would be greatly appreciated!&lt;/P&gt;</description>
      <pubDate>Mon, 06 Mar 2017 18:17:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-can-I-pull-out-values-in-a-log-path-and-route-it-to-a/m-p/337809#M62362</guid>
      <dc:creator>bport15</dc:creator>
      <dc:date>2017-03-06T18:17:49Z</dc:date>
    </item>
    <item>
      <title>Re: How can I pull out values in a log path and route it to a specific index?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-can-I-pull-out-values-in-a-log-path-and-route-it-to-a/m-p/337810#M62363</link>
      <description>&lt;P&gt;It's going to look something like this.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; # transforms.conf 
  [overrideindexbylogpath]
  DEST_KEY =_MetaData:Index
  REGEX =\/var\/appl\/logs\/(.*)\/server\.log
  SOURCE_KEY= ... name of extracted log path field ...
  FORMAT = $1




  #props.conf 
  [ ...definition of which records you want to change...]
  TRANSFORMS-index = overrideindexbylogpath
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;HR /&gt;

&lt;P&gt;I'm a little vague on what level of escaping will be needed on the regex... conf stanza versus search time versus saved search etc have little tweaky variations... but I think that got it correctly.&lt;/P&gt;

&lt;P&gt;Here's a link to a version that works based on the host name field. &lt;/P&gt;

&lt;P&gt;&lt;A href="https://answers.splunk.com/answers/507081/rename-index-based-on-host-and-index-name.html#comment-506626"&gt;https://answers.splunk.com/answers/507081/rename-index-based-on-host-and-index-name.html#comment-506626&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Mar 2017 19:04:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-can-I-pull-out-values-in-a-log-path-and-route-it-to-a/m-p/337810#M62363</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-03-06T19:04:32Z</dc:date>
    </item>
    <item>
      <title>Re: How can I pull out values in a log path and route it to a specific index?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-can-I-pull-out-values-in-a-log-path-and-route-it-to-a/m-p/337811#M62364</link>
      <description>&lt;P&gt;Thanks &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/203121"&gt;@DalJeanis&lt;/a&gt;.  The actual path we have includes several wildcards since we're pulling logs from containers.  How would the format $1 know to pull from the (.*) if we have the following (where prod is in the index)?&lt;/P&gt;

&lt;P&gt;Actual log path located in inputs.conf:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[monitor:///var/lib/origin/openshift*/pods/*/volumes/kubernetes*/log-dir/prod/dataportal-deployment*/*/catalina*.log]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is what the transforms.conf would look like using wildcards, but not sure if it would actually work:&lt;/P&gt;

&lt;P&gt;[override_index_by_log_path]&lt;BR /&gt;
SOURCE_KEY = MetaData:Source&lt;BR /&gt;
REGEX = &lt;CODE&gt;\/var\/lib\/origin\/openshift*\/pods\/*\/volumes\/kubernetes*\/log-dir\/(.*)\/*\/*\/*.log&lt;/CODE&gt;&lt;BR /&gt;
DEST_KEY = _MetaData:Index&lt;BR /&gt;
FORMAT = $1&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 13:07:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-can-I-pull-out-values-in-a-log-path-and-route-it-to-a/m-p/337811#M62364</guid>
      <dc:creator>bport15</dc:creator>
      <dc:date>2020-09-29T13:07:06Z</dc:date>
    </item>
    <item>
      <title>Re: How can I pull out values in a log path and route it to a specific index?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-can-I-pull-out-values-in-a-log-path-and-route-it-to-a/m-p/337812#M62365</link>
      <description>&lt;P&gt;Can you be sure how close to the final name the &lt;CODE&gt;prod&lt;/CODE&gt; or &lt;CODE&gt;dev&lt;/CODE&gt;  etc will be?  is it always two before the last slash? Here's one you can try...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;   REGEX=.*\/(prod|dev|imp|test)\/[^\/]*\/[^\/]*\/.*\.log
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It works over at regex101.com against this input...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;/GEORGE/HENRY/var/lib/origin/openshiftWILMA/pods/LUKE/volumes/kubernetes/log-dir/prod/dataportal-deploymentDANA/BETTY/catalina.log
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 Mar 2017 20:39:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-can-I-pull-out-values-in-a-log-path-and-route-it-to-a/m-p/337812#M62365</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-03-06T20:39:29Z</dc:date>
    </item>
    <item>
      <title>Re: How can I pull out values in a log path and route it to a specific index?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-can-I-pull-out-values-in-a-log-path-and-route-it-to-a/m-p/337813#M62366</link>
      <description>&lt;P&gt;So, our indexes don't have a standard naming convention.  Some have "prod", "test", "non prod" in the name, depending on the application (online_prod, online_test, appname_prod, appname_nonprod, appname_n, etc) and it depends on the environment as well.  We do, however, have a standard log file path that we've implemented so the name of the index is included in the file path and will always be in the 9th sub-directory.  &lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 13:07:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-can-I-pull-out-values-in-a-log-path-and-route-it-to-a/m-p/337813#M62366</guid>
      <dc:creator>bport15</dc:creator>
      <dc:date>2020-09-29T13:07:11Z</dc:date>
    </item>
    <item>
      <title>Re: How can I pull out values in a log path and route it to a specific index?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-can-I-pull-out-values-in-a-log-path-and-route-it-to-a/m-p/337814#M62367</link>
      <description>&lt;P&gt;I can definitely try your suggestion above and try to catch all of the various environments we have.  I'll keep you posted!&lt;/P&gt;</description>
      <pubDate>Mon, 06 Mar 2017 21:04:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-can-I-pull-out-values-in-a-log-path-and-route-it-to-a/m-p/337814#M62367</guid>
      <dc:creator>bport15</dc:creator>
      <dc:date>2017-03-06T21:04:29Z</dc:date>
    </item>
    <item>
      <title>Re: How can I pull out values in a log path and route it to a specific index?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-can-I-pull-out-values-in-a-log-path-and-route-it-to-a/m-p/337815#M62368</link>
      <description>&lt;P&gt;I was able to request our developers add "index=" into the path, so this is what my transforms.conf looks like.  I'm pushing that out today and will update this thread if everything works as expected.&lt;/P&gt;

&lt;P&gt;Transforms.conf&lt;BR /&gt;
[override_index_by_log_path]&lt;BR /&gt;
SOURCE_KEY = MetaData:Source&lt;BR /&gt;
REGEX = &lt;CODE&gt;.*\/index=.*\/.*&lt;/CODE&gt;&lt;BR /&gt;
DEST_KEY = _MetaData:Index&lt;BR /&gt;
FORMAT = $1&lt;/P&gt;

&lt;P&gt;Props.conf&lt;BR /&gt;
TRANSFORMS-route_index_to_log = override_index_by_log_path&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 13:12:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-can-I-pull-out-values-in-a-log-path-and-route-it-to-a/m-p/337815#M62368</guid>
      <dc:creator>bport15</dc:creator>
      <dc:date>2020-09-29T13:12:45Z</dc:date>
    </item>
    <item>
      <title>Re: How can I pull out values in a log path and route it to a specific index?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-can-I-pull-out-values-in-a-log-path-and-route-it-to-a/m-p/337816#M62369</link>
      <description>&lt;P&gt;I'm not seeing any parenthesis in the regex to mark the capture group for the index value.  That should probably be something like...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;REGEX =  .*\/index=([^\/]*)\/.*
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;... the value of the index needs to stop at the first slash, so we define a character class &lt;CODE&gt;[^\/]&lt;/CODE&gt; which is any character EXCEPT a slash.  &lt;/P&gt;

&lt;P&gt;You also need to specify/validate what is going to happen to the index name when no capture is found.  &lt;/P&gt;</description>
      <pubDate>Mon, 13 Mar 2017 15:59:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-can-I-pull-out-values-in-a-log-path-and-route-it-to-a/m-p/337816#M62369</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-03-13T15:59:10Z</dc:date>
    </item>
    <item>
      <title>Re: How can I pull out values in a log path and route it to a specific index?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-can-I-pull-out-values-in-a-log-path-and-route-it-to-a/m-p/337817#M62370</link>
      <description>&lt;P&gt;Good catch, thank you.  Modifying now.......&lt;/P&gt;</description>
      <pubDate>Mon, 13 Mar 2017 20:10:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-can-I-pull-out-values-in-a-log-path-and-route-it-to-a/m-p/337817#M62370</guid>
      <dc:creator>bport15</dc:creator>
      <dc:date>2017-03-13T20:10:45Z</dc:date>
    </item>
    <item>
      <title>Re: How can I pull out values in a log path and route it to a specific index?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-can-I-pull-out-values-in-a-log-path-and-route-it-to-a/m-p/337818#M62371</link>
      <description>&lt;P&gt;I finally got this working!&lt;/P&gt;

&lt;P&gt;This is what I had to put in my transforms.conf.  I ended up having the developers put "index=" in the log path and this is the final result:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;TRANSFORMS.CONF

    [override_index_by_log_path_2]
    SOURCE_KEY = MetaData:Source
    REGEX = .*\/log-dir\/index=([^\/]*)\/.*
    DEST_KEY = _MetaData:Index
    FORMAT = $1

PROPS.CONF

[servicelog]
TRANSFORMS-route_index_to_log_servicelog = override_index_by_log_path_2
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Mar 2017 03:12:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-can-I-pull-out-values-in-a-log-path-and-route-it-to-a/m-p/337818#M62371</guid>
      <dc:creator>bport15</dc:creator>
      <dc:date>2017-03-22T03:12:07Z</dc:date>
    </item>
  </channel>
</rss>

