<?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 extract variable field name from log file path and add them to each log line while sending to splunk in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-variable-field-name-from-log-file-path-and-add/m-p/674449#M230863</link>
    <description>&lt;P&gt;Hi Everyone,&lt;BR /&gt;I am using splunk forwarder and I have below requirements&amp;nbsp;&lt;BR /&gt;We have log files under path /opt/airflow/logs/*/*/*/*.log&lt;BR /&gt;for example&amp;nbsp;&lt;BR /&gt;&lt;SPAN class=""&gt;&lt;STRONG&gt;/opt/airflow/logs/getServerInfo/some_run_id/get_uptime/1.log&amp;nbsp;&amp;nbsp;or&amp;nbsp;&lt;BR /&gt;&lt;SPAN class=""&gt;&lt;STRONG&gt;/opt/airflow/logs/build_upgrade/some_run_id/ami_snapshot_task/5.log&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;Now i want to extract the field &lt;STRONG&gt;some_run_id &lt;/STRONG&gt;from the log file path and want to add this&amp;nbsp;&lt;STRONG&gt;&lt;STRONG&gt;some_run_id &lt;/STRONG&gt;&lt;/STRONG&gt;to each log line while sending the logs to splunk&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;Below is my normal logs format&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;[2024-01-17, 03:17:02 UTC] {subprocess.py:89} INFO - PLAY [Gather host information]&lt;BR /&gt;[2024-01-17, 03:17:01 UTC] {taskinstance.py:1262} INFO - Executing &amp;lt;Task(BashOperator): get_os_info&amp;gt; on 2024-01-17 03:16:37+00:00&lt;BR /&gt;[2024-01-17, 03:17:01 UTC] {standard_task_runner.py:52} INFO - Started process 1081826 to run task&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="lia-align-justify"&gt;Now i want below format of logs in splunk (I want this format of logs in splunk not on the actual log files)&lt;BR /&gt;&lt;BR /&gt;some_run_id [2024-01-17, 03:17:02 UTC] {subprocess.py:89} INFO - PLAY [Gather host information]&lt;BR /&gt;some_run_id [2024-01-17, 03:17:01 UTC] {taskinstance.py:1262} INFO - Executing &amp;lt;Task(BashOperator): get_os_info&amp;gt; on 2024-01-17 03:16:37+00:00&lt;BR /&gt;some_run_id [2024-01-17, 03:17:01 UTC] {standard_task_runner.py:52} INFO - Started process 1081826 to run task&lt;BR /&gt;&lt;BR /&gt;Any help is much appreciated !&lt;/P&gt;</description>
    <pubDate>Wed, 17 Jan 2024 05:59:41 GMT</pubDate>
    <dc:creator>Deep</dc:creator>
    <dc:date>2024-01-17T05:59:41Z</dc:date>
    <item>
      <title>How to extract variable field name from log file path and add them to each log line while sending to splunk</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-variable-field-name-from-log-file-path-and-add/m-p/674449#M230863</link>
      <description>&lt;P&gt;Hi Everyone,&lt;BR /&gt;I am using splunk forwarder and I have below requirements&amp;nbsp;&lt;BR /&gt;We have log files under path /opt/airflow/logs/*/*/*/*.log&lt;BR /&gt;for example&amp;nbsp;&lt;BR /&gt;&lt;SPAN class=""&gt;&lt;STRONG&gt;/opt/airflow/logs/getServerInfo/some_run_id/get_uptime/1.log&amp;nbsp;&amp;nbsp;or&amp;nbsp;&lt;BR /&gt;&lt;SPAN class=""&gt;&lt;STRONG&gt;/opt/airflow/logs/build_upgrade/some_run_id/ami_snapshot_task/5.log&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;Now i want to extract the field &lt;STRONG&gt;some_run_id &lt;/STRONG&gt;from the log file path and want to add this&amp;nbsp;&lt;STRONG&gt;&lt;STRONG&gt;some_run_id &lt;/STRONG&gt;&lt;/STRONG&gt;to each log line while sending the logs to splunk&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;Below is my normal logs format&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;[2024-01-17, 03:17:02 UTC] {subprocess.py:89} INFO - PLAY [Gather host information]&lt;BR /&gt;[2024-01-17, 03:17:01 UTC] {taskinstance.py:1262} INFO - Executing &amp;lt;Task(BashOperator): get_os_info&amp;gt; on 2024-01-17 03:16:37+00:00&lt;BR /&gt;[2024-01-17, 03:17:01 UTC] {standard_task_runner.py:52} INFO - Started process 1081826 to run task&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="lia-align-justify"&gt;Now i want below format of logs in splunk (I want this format of logs in splunk not on the actual log files)&lt;BR /&gt;&lt;BR /&gt;some_run_id [2024-01-17, 03:17:02 UTC] {subprocess.py:89} INFO - PLAY [Gather host information]&lt;BR /&gt;some_run_id [2024-01-17, 03:17:01 UTC] {taskinstance.py:1262} INFO - Executing &amp;lt;Task(BashOperator): get_os_info&amp;gt; on 2024-01-17 03:16:37+00:00&lt;BR /&gt;some_run_id [2024-01-17, 03:17:01 UTC] {standard_task_runner.py:52} INFO - Started process 1081826 to run task&lt;BR /&gt;&lt;BR /&gt;Any help is much appreciated !&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jan 2024 05:59:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-variable-field-name-from-log-file-path-and-add/m-p/674449#M230863</guid>
      <dc:creator>Deep</dc:creator>
      <dc:date>2024-01-17T05:59:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract variable field name from log file path and add them to each log line while sending to splunk</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-variable-field-name-from-log-file-path-and-add/m-p/674484#M230871</link>
      <description>&lt;P&gt;Check your events in splunk - there is a Splunk provide field called source which holds the file name from where the event came from. Can you use this to extract the data you want?&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval some_run_id=mvindex(split(source,"/"),5)&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 17 Jan 2024 09:07:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-variable-field-name-from-log-file-path-and-add/m-p/674484#M230871</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2024-01-17T09:07:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract variable field name from log file path and add them to each log line while sending to splunk</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-variable-field-name-from-log-file-path-and-add/m-p/674491#M230875</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;if there is no real reason to add it in ingest phase you should use&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/225168"&gt;@ITWhisperer&lt;/a&gt;&amp;nbsp;'s example.&lt;/P&gt;&lt;P&gt;But if you really need it on ingest time then you can look e.g.&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;A href="https://community.splunk.com/t5/Getting-Data-In/How-to-apply-source-file-date-using-INGEST-as-Time/m-p/596865" target="_blank"&gt;https://community.splunk.com/t5/Getting-Data-In/How-to-apply-source-file-date-using-INGEST-as-Time/m-p/596865&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;&lt;A href="https://community.splunk.com/t5/Getting-Data-In/How-to-get-props-and-transforms-to-extract-time-from-source/td-p/641795" target="_blank"&gt;https://community.splunk.com/t5/Getting-Data-In/How-to-get-props-and-transforms-to-extract-time-from-source/td-p/641795&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;how to use e.g. INGEST_EVAL to manipulate events in ingest phase.&amp;nbsp;&lt;/P&gt;&lt;P&gt;r. Ismo&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jan 2024 09:56:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-variable-field-name-from-log-file-path-and-add/m-p/674491#M230875</guid>
      <dc:creator>isoutamo</dc:creator>
      <dc:date>2024-01-17T09:56:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract variable field name from log file path and add them to each log line while sending to splunk</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-variable-field-name-from-log-file-path-and-add/m-p/674614#M230917</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/214410"&gt;@isoutamo&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;If i choose to extract these fields from file path and append those in ingest phase than below approach will work ?&lt;/P&gt;&lt;P&gt;props.conf&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;[source::&lt;/SPAN&gt;&lt;SPAN class=""&gt;/opt/airflow/logs/*/*/*/*.log&lt;/SPAN&gt;&lt;SPAN class=""&gt;]&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;TRANSFORMS-set_run_id = extract_run_id&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;transform.conf&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;[extract_run_id]&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;INGEST_EVAL = _runid = mvindex(split(source,"/"),5)&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jan 2024 07:31:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-variable-field-name-from-log-file-path-and-add/m-p/674614#M230917</guid>
      <dc:creator>Deep</dc:creator>
      <dc:date>2024-01-18T07:31:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract variable field name from log file path and add them to each log line while sending to splunk</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-variable-field-name-from-log-file-path-and-add/m-p/674617#M230920</link>
      <description>&lt;P&gt;1. I'm not sure if you can easily create fields with names beginning with underscore. I'm not saying you definitely can't but by convention they are internal Splunk's fields so I wouldn't be surprised if you couldn't (or had problems accessing them later).&lt;/P&gt;&lt;P&gt;2. If you already have that info in the source field there is not much point in creating additional indexed field duplicating the value (I could agree that in some very rare cases there could be a use of such an indexed field if that info was stored in the raw event itself but since it's contained in the source which itself is an indexed field, there is not much point in just rewriting it elsewhere).&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jan 2024 07:47:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-variable-field-name-from-log-file-path-and-add/m-p/674617#M230920</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2024-01-18T07:47:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract variable field name from log file path and add them to each log line while sending to splunk</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-variable-field-name-from-log-file-path-and-add/m-p/674625#M230924</link>
      <description>&lt;P&gt;I agree with&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/231884"&gt;@PickleRick&lt;/a&gt;&amp;nbsp;that don't use _ as a prefix for your own fields. I'm not sure if it even works or not?&lt;/P&gt;&lt;P&gt;Also it's usually better to do that on search time not an ingest time.&lt;/P&gt;&lt;P&gt;If you really need it then your solution should work as you show. One thing to remember is that you must put that props&amp;amp;transforms into 1st full splunk instance HF or Indexer from source to splunk indexers to get it working.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jan 2024 09:41:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-variable-field-name-from-log-file-path-and-add/m-p/674625#M230924</guid>
      <dc:creator>isoutamo</dc:creator>
      <dc:date>2024-01-18T09:41:33Z</dc:date>
    </item>
  </channel>
</rss>

