<?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: Extract date (timestamp) from raw data and source field in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Extract-date-timestamp-from-raw-data-and-source-field/m-p/412527#M118932</link>
    <description>&lt;P&gt;Hi @ips_mandar,&lt;/P&gt;

&lt;P&gt;This duplicates &lt;A href="https://answers.splunk.com/answers/750976/extract-date-from-filename-source.html"&gt;https://answers.splunk.com/answers/750976/extract-date-from-filename-source.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;You have to use &lt;CODE&gt;INGEST_EVAL&lt;/CODE&gt; for this use-case and apply it as follows for &lt;CODE&gt;props.conf&lt;/CODE&gt; :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[mysourcetype]
TRANSFORMS = myeval
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And &lt;CODE&gt;transforms.conf&lt;/CODE&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[myeval]
INGEST_EVAL= inputDate = substr(source,len(source)-9,6), inputDateEpoch=strptime(inputDate,"%y%m%d"), dateFromEvent=strftime(_time,"%y%m%d"), dateFromEventEpoch=strptime(dateFromEvent,"%y%m%d"), inputDateDelta=dateFromEventEpoch-inputDateEpoch, _time=_time-inputDateDelta
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You can test this on your search assuming that your _time is automatically taken from the event and tagged with the current month and year:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|makeresults 
| eval source="XYLog09229190601.txt" 
| eval inputDate= substr(source,len(source)-9,6),inputDateEpoch=strptime(inputDate,"%y%m%d"),dateFromEvent=strftime(_time,"%y%m%d"),dateFromEventEpoch=strptime(dateFromEvent,"%y%m%d"),inputDateDelta=dateFromEventEpoch-inputDateEpoch,_time=_time-inputDateDelta
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Let me know if that helps.&lt;/P&gt;

&lt;P&gt;Cheers,&lt;BR /&gt;
David&lt;/P&gt;</description>
    <pubDate>Tue, 11 Jun 2019 06:13:31 GMT</pubDate>
    <dc:creator>DavidHourani</dc:creator>
    <dc:date>2019-06-11T06:13:31Z</dc:date>
    <item>
      <title>Extract date (timestamp) from raw data and source field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extract-date-timestamp-from-raw-data-and-source-field/m-p/412526#M118931</link>
      <description>&lt;P&gt;Hi &lt;BR /&gt;
my events looks like-&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  31,04:56:47:928,  abc:0xabc,  49.716720, -59.271553,197
  30,04:56:47:928,  abc:0xabc,  49.716720, -59.271553,197
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;where 31 OR 30 is day of month&lt;BR /&gt;
and source field looks like - &lt;CODE&gt;D:\\abc\\def\\XYLog09229190601.txt.zip:.\\XYLog09229190601.txt&lt;/CODE&gt; &lt;BR /&gt;
from source- &lt;CODE&gt;XYLog09229190601.txt&lt;/CODE&gt; I can know 190601 i.e. 01 June 2019&lt;BR /&gt;
So by which way I can get _time as for first event as 31 MAY 2019 and for second event as 30 May 2019?&lt;BR /&gt;
where day is extracted from event and month is manipulated as the events are always of previous 1-5 days than it shows date in source field.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jun 2019 01:56:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extract-date-timestamp-from-raw-data-and-source-field/m-p/412526#M118931</guid>
      <dc:creator>ips_mandar</dc:creator>
      <dc:date>2019-06-11T01:56:08Z</dc:date>
    </item>
    <item>
      <title>Re: Extract date (timestamp) from raw data and source field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extract-date-timestamp-from-raw-data-and-source-field/m-p/412527#M118932</link>
      <description>&lt;P&gt;Hi @ips_mandar,&lt;/P&gt;

&lt;P&gt;This duplicates &lt;A href="https://answers.splunk.com/answers/750976/extract-date-from-filename-source.html"&gt;https://answers.splunk.com/answers/750976/extract-date-from-filename-source.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;You have to use &lt;CODE&gt;INGEST_EVAL&lt;/CODE&gt; for this use-case and apply it as follows for &lt;CODE&gt;props.conf&lt;/CODE&gt; :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[mysourcetype]
TRANSFORMS = myeval
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And &lt;CODE&gt;transforms.conf&lt;/CODE&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[myeval]
INGEST_EVAL= inputDate = substr(source,len(source)-9,6), inputDateEpoch=strptime(inputDate,"%y%m%d"), dateFromEvent=strftime(_time,"%y%m%d"), dateFromEventEpoch=strptime(dateFromEvent,"%y%m%d"), inputDateDelta=dateFromEventEpoch-inputDateEpoch, _time=_time-inputDateDelta
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You can test this on your search assuming that your _time is automatically taken from the event and tagged with the current month and year:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|makeresults 
| eval source="XYLog09229190601.txt" 
| eval inputDate= substr(source,len(source)-9,6),inputDateEpoch=strptime(inputDate,"%y%m%d"),dateFromEvent=strftime(_time,"%y%m%d"),dateFromEventEpoch=strptime(dateFromEvent,"%y%m%d"),inputDateDelta=dateFromEventEpoch-inputDateEpoch,_time=_time-inputDateDelta
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Let me know if that helps.&lt;/P&gt;

&lt;P&gt;Cheers,&lt;BR /&gt;
David&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jun 2019 06:13:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extract-date-timestamp-from-raw-data-and-source-field/m-p/412527#M118932</guid>
      <dc:creator>DavidHourani</dc:creator>
      <dc:date>2019-06-11T06:13:31Z</dc:date>
    </item>
    <item>
      <title>Re: Extract date (timestamp) from raw data and source field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extract-date-timestamp-from-raw-data-and-source-field/m-p/412528#M118933</link>
      <description>&lt;P&gt;Thanks @DavidHourani Appreciate your answer..&lt;BR /&gt;
Does it will satisfy all condition ? As I checked another example&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    |makeresults 
 | eval source="dffgfXYLog09229190611.txt" 
 | eval _time="1560136057",a=substr(source,len(source)-9,6),inputDate= substr(source,len(source)-9,6),inputDateEpoch=strptime(inputDate,"%y%m%d"),dateFromEvent=strftime(_time,"%y%m%d"),dateFromEventEpoch=strptime(dateFromEvent,"%y%m%d"),inputDateDelta=dateFromEventEpoch-inputDateEpoch,_time=_time-inputDateDelta
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Here I considered source field as today's date and event _time as yesterday then it should give me manipulated _time as yesterday but it won't.&lt;BR /&gt;
Basic understanding is in file name 1-5 days above in name while event will always be behind 1 -5 days .&lt;BR /&gt;
so basically I want event time as _time .&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jun 2019 08:43:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extract-date-timestamp-from-raw-data-and-source-field/m-p/412528#M118933</guid>
      <dc:creator>ips_mandar</dc:creator>
      <dc:date>2019-06-11T08:43:26Z</dc:date>
    </item>
    <item>
      <title>Re: Extract date (timestamp) from raw data and source field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extract-date-timestamp-from-raw-data-and-source-field/m-p/412529#M118934</link>
      <description>&lt;P&gt;also how _time will automatically picks timestamp as in event only day of month is mentioned.&lt;BR /&gt;
basic concept is file is copied in one folder where the files will contain data of yesterday/day before yesterday and this folder is monitored in splunk.&lt;BR /&gt;
exact day only can be identified from each event and in event only day is mentioned and no month or year.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jun 2019 08:47:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extract-date-timestamp-from-raw-data-and-source-field/m-p/412529#M118934</guid>
      <dc:creator>ips_mandar</dc:creator>
      <dc:date>2019-06-11T08:47:41Z</dc:date>
    </item>
    <item>
      <title>Re: Extract date (timestamp) from raw data and source field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extract-date-timestamp-from-raw-data-and-source-field/m-p/412530#M118935</link>
      <description>&lt;P&gt;It will take day and time from the event, then for the month and year it will auto configure them to the time they were indexed&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jun 2019 09:17:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extract-date-timestamp-from-raw-data-and-source-field/m-p/412530#M118935</guid>
      <dc:creator>DavidHourani</dc:creator>
      <dc:date>2019-06-11T09:17:51Z</dc:date>
    </item>
    <item>
      <title>Re: Extract date (timestamp) from raw data and source field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extract-date-timestamp-from-raw-data-and-source-field/m-p/412531#M118936</link>
      <description>&lt;P&gt;but below query will not give desired result of _time as yesterday&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;     |makeresults 
  | eval source="dffgfXYLog09229190611.txt" 
  | eval _time="1560136057",a=substr(source,len(source)-9,6),inputDate= substr(source,len(source)-9,6),inputDateEpoch=strptime(inputDate,"%y%m%d"),dateFromEvent=strftime(_time,"%y%m%d"),dateFromEventEpoch=strptime(dateFromEvent,"%y%m%d"),inputDateDelta=dateFromEventEpoch-inputDateEpoch,_time=_time-inputDateDelta
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 11 Jun 2019 09:24:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extract-date-timestamp-from-raw-data-and-source-field/m-p/412531#M118936</guid>
      <dc:creator>ips_mandar</dc:creator>
      <dc:date>2019-06-11T09:24:59Z</dc:date>
    </item>
    <item>
      <title>Re: Extract date (timestamp) from raw data and source field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extract-date-timestamp-from-raw-data-and-source-field/m-p/412532#M118937</link>
      <description>&lt;P&gt;Hello &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/95326"&gt;@ips_mandar&lt;/a&gt; ,&lt;BR /&gt;
I feel that I may be missing part of what you are asking for, but allow me to propose the following solution...&lt;BR /&gt;
I have settings that will extract the date from the name of the file and the time of day from the event. Here are the sample events...&lt;BR /&gt;
source= /Users/hansmaldonado/testing/dffgfXYLog09229190611.txt&lt;BR /&gt;
_raw=30,04:56:47:928,  abc:0xabc,  49.716720, -59.271553,197&lt;/P&gt;

&lt;P&gt;If we assume that the last 6 digits in the source field represent the date, and if we assume that the time of day comes from "04:56:47:928" within the raw event, here are the settings that will extract _time as "06/11/2019 04:56:47.928"...&lt;/P&gt;

&lt;P&gt;props.conf&lt;BR /&gt;
[timestamp:test:splunkanswers]&lt;BR /&gt;
TRANSFORMS-timestampeval = splunkanswers&lt;BR /&gt;
DATETIME_CONFIG = &lt;BR /&gt;
LINE_BREAKER = ([\r\n]+)&lt;BR /&gt;
NO_BINARY_CHECK = true&lt;BR /&gt;
SHOULD_LINEMERGE = false&lt;BR /&gt;
category = Custom&lt;BR /&gt;
pulldown_type = true&lt;/P&gt;

&lt;P&gt;transforms.conf&lt;BR /&gt;
[splunkanswers]&lt;BR /&gt;
INGEST_EVAL=date=strptime(replace(source,".*(?=\d{6})",""), "%y%m%d"),date:=strftime(date,"%m/%d/%Y"),newtime=strftime(_time,"%H:%M:%S.%3N"),timestamp=date." ".newtime,_time:=strptime(timestamp,"%m/%d/%Y %H:%M:%S.%3N")&lt;/P&gt;

&lt;P&gt;Note the syntax of ":=", which is required for INGEST_EVAL if you are performing operations on fields that already have values AND if you want to keep the new value. If you use "=", you will end up with multiple values for the fields.&lt;/P&gt;

&lt;P&gt;My solution requires that you make the source/name of the file reflective of the date of the events, then we pull the time of day from the event. &lt;/P&gt;

&lt;P&gt;Please let me know if this solution is acceptable for your needs. If not, please clarify how I might edit the solution to fit your use case.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 01:53:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extract-date-timestamp-from-raw-data-and-source-field/m-p/412532#M118937</guid>
      <dc:creator>hmaldonado</dc:creator>
      <dc:date>2020-09-30T01:53:14Z</dc:date>
    </item>
  </channel>
</rss>

