<?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: Can timestamp be conditional according to data content in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Can-timestamp-be-conditional-according-to-data-content/m-p/161636#M185995</link>
    <description>&lt;P&gt;good luck.&lt;/P&gt;</description>
    <pubDate>Mon, 02 Dec 2013 12:18:46 GMT</pubDate>
    <dc:creator>kristian_kolb</dc:creator>
    <dc:date>2013-12-02T12:18:46Z</dc:date>
    <item>
      <title>Can timestamp be conditional according to data content</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-timestamp-be-conditional-according-to-data-content/m-p/161630#M185989</link>
      <description>&lt;P&gt;My csv data contains a number of timestamps.  I want the timestamp field to be conditional on the result of another field, say field 12.  So if I compare field 12 in each row for "X" then I want to use the timestamp from field 15th and if field 12 contains "Y", I want to use field 10 for the timestamp.&lt;/P&gt;

&lt;P&gt;Currently I am splitting my log file into two based on the field 12 value and then defining 2 different sourcetypes, each with a different TIME_PREFIX value in props.conf, but wondered if I could avoid that step and have a single sourcetype.&lt;/P&gt;

&lt;P&gt;Following Ayn and Kristian Kolb's comments, here's more detail&lt;/P&gt;

&lt;P&gt;These are the two standard lines of data&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Course A,_scorm12_ar123,Custom Asset,username1,First,Last,Branch Sales,Group Id1,Group Path,0,2013-11-07,2013-11-07,2,0,,,In Progress,,,,35,14,Direct sales
Course B,_scorm12_cf411,Custom Asset,username2,First,Last,Group name,Group Id2,Group Path2,0,2013-11-16,2013-11-20,3,0,,2013-11-17,Completed,,100.00,100.00,35,62,Indirect sales
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The first is a course in progress (field 17) and started on 2013-11-07 (field 11)&lt;BR /&gt;
The second is a course completed (field 17) and started on 2013-11-16 (field 11) and completed on 2013-11-17 (field 16).&lt;/P&gt;

&lt;P&gt;I tried two TIME_PREFIX settings&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;TIME_PREFIX=^(((\"[^\"]*\",)|([^,]*,)){15}|((\"[^\"]*\",)|([^,]*,)){10})
TIME_PREFIX=^(((\"[^\"]*\",)|([^,]*,)){10}|((\"[^\"]*\",)|([^,]*,)){15})
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In the first case, _time is set to the completion date or the 'previous' record's time if the course in In Progress.  In the second case, the _time is always set to the start date.&lt;/P&gt;

&lt;P&gt;I don't suppose I can look ahead BEYOND the wanted time field to check for the value of field 17 to then extract the time from a field BEFORE...??&lt;/P&gt;

&lt;P&gt;I guess if the Completed|In Progress text was before the time field I could include that in the pattern, but the docs for TIME_PREFIX say the time is extracted from the text following the regex match.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Dec 2013 02:58:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-timestamp-be-conditional-according-to-data-content/m-p/161630#M185989</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2013-12-02T02:58:37Z</dc:date>
    </item>
    <item>
      <title>Re: Can timestamp be conditional according to data content</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-timestamp-be-conditional-according-to-data-content/m-p/161631#M185990</link>
      <description>&lt;P&gt;If you can specify a &lt;CODE&gt;TIME_PREFIX&lt;/CODE&gt; that matches one at a time you can do this. Otherwise the answer is most likely no. But something like&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;TIME_PREFIX = ...,Y,...,|...,N,...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;should work, where you give one regex that matches as far as you want in case the field is "Y" and another one for when the field is "N".&lt;/P&gt;</description>
      <pubDate>Mon, 02 Dec 2013 09:19:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-timestamp-be-conditional-according-to-data-content/m-p/161631#M185990</guid>
      <dc:creator>Ayn</dc:creator>
      <dc:date>2013-12-02T09:19:42Z</dc:date>
    </item>
    <item>
      <title>Re: Can timestamp be conditional according to data content</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-timestamp-be-conditional-according-to-data-content/m-p/161632#M185991</link>
      <description>&lt;P&gt;Not too sure how Splunk would treat this, but it &lt;EM&gt;might&lt;/EM&gt; work. The (untested) example below assumes that you have space-separated fields, and that the fields themselves do NOT contain any spaces.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;TIME_PREFIX = ^((\S+\s+){11}X\s+\S+\s+\S+\s+|(\S+\s+){9}(?=\S+\s+\S+\s+Y))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Also, depending on the size of the events, you may need to increase the &lt;CODE&gt;MAX_TIMESTAMP_LOOKAHED&lt;/CODE&gt;.&lt;BR /&gt;
If this approach does not work, it may be better to use your current strategy, with two different sourcetypes. &lt;/P&gt;

&lt;P&gt;For more qualified help, you should consider posting a few sample events.&lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;UPDATE:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;Course A,_scorm12_ar123,Custom Asset,username1,First,Last,Branch Sales,Group Id1,Group Path,0,&lt;/CODE&gt;&lt;STRONG&gt;2013-11-07&lt;/STRONG&gt;&lt;CODE&gt;,2013-11-07,2,0,,,&lt;/CODE&gt;&lt;STRONG&gt;In Progress&lt;/STRONG&gt;&lt;CODE&gt;,,,,35,14,Direct sales&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;Course B,_scorm12_cf411,Custom Asset,username2,First,Last,Group name,Group Id2,Group Path2,0,2013-11-16,2013-11-20,3,0,,&lt;/CODE&gt;&lt;STRONG&gt;2013-11-17,Completed&lt;/STRONG&gt;&lt;CODE&gt;,,100.00,100.00,35,62,Indirect sales&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Given that I've understood you correctly, the above date fields are the ones you want, based on the &lt;STRONG&gt;Completed/In Progress&lt;/STRONG&gt; status.&lt;/P&gt;

&lt;P&gt;I would try this with the following regex in TIME_PREFIX (but note that it may not work at all, I haven't tested it);&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;TIME_PREFIX = ^(([^,]*,){10}(?=([^,]*,){6}In Progress)|([^,]*,){15}(?=[^,]*,Completed))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Good luck,&lt;/P&gt;

&lt;P&gt;/K&lt;/P&gt;

&lt;P&gt;EDIT: typo&lt;BR /&gt;
EDIT2: picked the wrong field in the first event - corrected now.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Dec 2013 09:56:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-timestamp-be-conditional-according-to-data-content/m-p/161632#M185991</guid>
      <dc:creator>kristian_kolb</dc:creator>
      <dc:date>2013-12-02T09:56:22Z</dc:date>
    </item>
    <item>
      <title>Re: Can timestamp be conditional according to data content</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-timestamp-be-conditional-according-to-data-content/m-p/161633#M185992</link>
      <description>&lt;P&gt;I'm too slow by a mile, I see.  &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Dec 2013 09:58:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-timestamp-be-conditional-according-to-data-content/m-p/161633#M185992</guid>
      <dc:creator>kristian_kolb</dc:creator>
      <dc:date>2013-12-02T09:58:08Z</dc:date>
    </item>
    <item>
      <title>Re: Can timestamp be conditional according to data content</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-timestamp-be-conditional-according-to-data-content/m-p/161634#M185993</link>
      <description>&lt;P&gt;Thanks, I'll try this out in the morning, late here!&lt;/P&gt;</description>
      <pubDate>Mon, 02 Dec 2013 11:01:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-timestamp-be-conditional-according-to-data-content/m-p/161634#M185993</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2013-12-02T11:01:17Z</dc:date>
    </item>
    <item>
      <title>Re: Can timestamp be conditional according to data content</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-timestamp-be-conditional-according-to-data-content/m-p/161635#M185994</link>
      <description>&lt;P&gt;Thanks, I should be able to map that to my data, so I'll try it in the morning!&lt;/P&gt;</description>
      <pubDate>Mon, 02 Dec 2013 11:01:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-timestamp-be-conditional-according-to-data-content/m-p/161635#M185994</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2013-12-02T11:01:58Z</dc:date>
    </item>
    <item>
      <title>Re: Can timestamp be conditional according to data content</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-timestamp-be-conditional-according-to-data-content/m-p/161636#M185995</link>
      <description>&lt;P&gt;good luck.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Dec 2013 12:18:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-timestamp-be-conditional-according-to-data-content/m-p/161636#M185995</guid>
      <dc:creator>kristian_kolb</dc:creator>
      <dc:date>2013-12-02T12:18:46Z</dc:date>
    </item>
    <item>
      <title>Re: Can timestamp be conditional according to data content</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-timestamp-be-conditional-according-to-data-content/m-p/161637#M185996</link>
      <description>&lt;P&gt;Thanks Ayn, see my updated description.  I guess I'll have to use my existing strategy, but thanks for the great idea.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Dec 2013 22:55:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-timestamp-be-conditional-according-to-data-content/m-p/161637#M185996</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2013-12-02T22:55:28Z</dc:date>
    </item>
    <item>
      <title>Re: Can timestamp be conditional according to data content</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-timestamp-be-conditional-according-to-data-content/m-p/161638#M185997</link>
      <description>&lt;P&gt;Thanks Kristian, see my updated description.  I guess I'll have to use my existing strategy, but thanks for the great idea.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Dec 2013 22:55:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-timestamp-be-conditional-according-to-data-content/m-p/161638#M185997</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2013-12-02T22:55:50Z</dc:date>
    </item>
    <item>
      <title>Re: Can timestamp be conditional according to data content</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-timestamp-be-conditional-according-to-data-content/m-p/161639#M185998</link>
      <description>&lt;P&gt;Well, to answer your question on wheter you can 'look beyond' the timestamp for a field value, yes you can. It's called a positive lookahead, and is seen in my example above. &lt;/P&gt;

&lt;P&gt;The second regex &lt;CODE&gt;(\S+\s+){9}(?=\S+\s+\S+\s+Y)&lt;/CODE&gt; will match a position after 9 sequences (i.e. just before field 10) of non-space-characters-followed-by-space. But only if this is followed by a &lt;CODE&gt;Y&lt;/CODE&gt; in field 12. &lt;/P&gt;

&lt;P&gt;Btw, I don't really understand your regexes, i.e. they dont make sense to me. And I'm quite sure that you can only specify &lt;CODE&gt;TIME_PREFIX&lt;/CODE&gt; once per stanza in props.conf. One of them will be discarded.&lt;/P&gt;

&lt;P&gt;/k&lt;/P&gt;</description>
      <pubDate>Tue, 03 Dec 2013 09:03:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-timestamp-be-conditional-according-to-data-content/m-p/161639#M185998</guid>
      <dc:creator>kristian_kolb</dc:creator>
      <dc:date>2013-12-03T09:03:17Z</dc:date>
    </item>
    <item>
      <title>Re: Can timestamp be conditional according to data content</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-timestamp-be-conditional-according-to-data-content/m-p/161640#M185999</link>
      <description>&lt;P&gt;Did you try the updated TIME_PREFIX reges? It'd be fun to know if it worked or not.&lt;/P&gt;

&lt;P&gt;/k&lt;/P&gt;</description>
      <pubDate>Thu, 05 Dec 2013 08:55:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-timestamp-be-conditional-according-to-data-content/m-p/161640#M185999</guid>
      <dc:creator>kristian_kolb</dc:creator>
      <dc:date>2013-12-05T08:55:26Z</dc:date>
    </item>
  </channel>
</rss>

