<?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 to define a start time for a search based on log message in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-define-a-start-time-for-a-search-based-on-log-message/m-p/446512#M126677</link>
    <description>&lt;P&gt;I have yet to see this worked expected -- and yes imatch was a typo... have a good afternoon! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 02 Jul 2019 18:51:03 GMT</pubDate>
    <dc:creator>dowdag</dc:creator>
    <dc:date>2019-07-02T18:51:03Z</dc:date>
    <item>
      <title>How to define a start time for a search based on log message</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-define-a-start-time-for-a-search-based-on-log-message/m-p/446507#M126672</link>
      <description>&lt;P&gt;Greetings,&lt;/P&gt;

&lt;P&gt;Still confused with Splunk.  &lt;/P&gt;

&lt;P&gt;How do I specify start point to start searching from  - for this application I do not start searching from the head of my Log files.&lt;BR /&gt;
I would like to do something like:&lt;/P&gt;

&lt;P&gt;pseudo code:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  index=* OR index=_* sourcetype=OneOfManyLogFiles* 
earliest = [ search index=_* sourcetype="terminal.log" | return  eval StartSearchFrom=strfTime(if(imatch(Info, "^ApplyPayment\(\) - ManagerId.+PaymentId"), _time),"%Y-%m-%d %H:%M:%S.%3N")   ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This does idea not work....  how is this accomplished?&lt;/P&gt;

&lt;P&gt;When using streamstats the log file that has the string "ApplyPayment" is not included in the final rendered table.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=* OR index=_* sourcetype=OneOfManyLogFiles* 

| eval Action =case(match(Info, "^ApplyPayment\(\) - ManagerId.+PaymentId"),"StartTran" ,
    match(Info, "^Done Merchant Payment"),"EndTran", match(Info, "^Exiting"), "Exiting", 
    match(Info, ""), "Info", 1=1, Action) 
| eval EventTime=strfTime(if(in(Action, "StartTran", "EndTran"), _time,""),"%Y-%m-%d %H:%M:%S.%3N") 
| streamstats count(eval(match(Info, "^ApplyPayment\(\) - ManagerId.+PaymentId"))) AS TranCount BY host
| reverse 
| stats list(Info) As events BY host TranCount
| table TranCount sourcetype _time EventType action CheckNumber TransactionId PaymentId events
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks for any help/ideas on this.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jul 2019 19:17:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-define-a-start-time-for-a-search-based-on-log-message/m-p/446507#M126672</guid>
      <dc:creator>dowdag</dc:creator>
      <dc:date>2019-07-01T19:17:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to define a start time for a search based on log message</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-define-a-start-time-for-a-search-based-on-log-message/m-p/446508#M126673</link>
      <description>&lt;P&gt;can you share some sample data and desired output for search?&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jul 2019 00:47:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-define-a-start-time-for-a-search-based-on-log-message/m-p/446508#M126673</guid>
      <dc:creator>adonio</dc:creator>
      <dc:date>2019-07-02T00:47:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to define a start time for a search based on log message</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-define-a-start-time-for-a-search-based-on-log-message/m-p/446509#M126674</link>
      <description>&lt;P&gt;Well this works:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_internal sourcetype=scheduler earliest="07/01/2019:20:01:39"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So pulling the earliest time from a subsearch would be something like this example that I tested...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_internal sourcetype=scheduler 
    [| makeresults | eval start=relative_time(now(),"-60m") 
| eval earliest=strftime(start, "%m/%d/%Y:%H:%M:%S")
    | return  earliest]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I would think your search should work like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index=* OR index=_* sourcetype=OneOfManyLogFiles*
  [ search index=_* sourcetype="terminal.log" 
  | eval StartSearchFrom=strfTime(if(imatch(Info, "^ApplyPayment\(\) - ManagerId.+PaymentId"), _time),"%m/%d/%Y:%H:%M:%S") 
  | rename StartSearchFrom AS earliest 
  | return earliest ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Make sure you get the format string "%m/%d/%Y:%H:%M:%S" correct... and that StartSearchFrom holds a good timestamp, and you should be good.&lt;/P&gt;

&lt;P&gt;Also watchout for that &lt;STRONG&gt;strfTime()&lt;/STRONG&gt; in your search... that should be &lt;STRONG&gt;strftime()&lt;/STRONG&gt; ,   It's probably just cut/paste issues, but that whole 'eval StartSearchFrom..." line could use some work.&lt;/P&gt;

&lt;P&gt;Hope that helps...&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jul 2019 01:18:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-define-a-start-time-for-a-search-based-on-log-message/m-p/446509#M126674</guid>
      <dc:creator>memarshall63</dc:creator>
      <dc:date>2019-07-02T01:18:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to define a start time for a search based on log message</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-define-a-start-time-for-a-search-based-on-log-message/m-p/446510#M126675</link>
      <description>&lt;P&gt;Marshall,&lt;BR /&gt;
Thanks for your ideas. However this does not work. &lt;BR /&gt;
 Why does &lt;STRONG&gt;_time&lt;/STRONG&gt; have the format of &lt;CODE&gt;"%Y-%m-%d"&lt;/CODE&gt;  and &lt;STRONG&gt;earliest&lt;/STRONG&gt; is &lt;CODE&gt;"%m/%d/%Y"&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;
and if you add milliseconds to 'earliest' string splunk throws an error  -- at least in the free version.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;gt; not happy &amp;lt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Will look at more examples and hope that i will find a solution.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jul 2019 16:33:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-define-a-start-time-for-a-search-based-on-log-message/m-p/446510#M126675</guid>
      <dc:creator>dowdag</dc:creator>
      <dc:date>2019-07-02T16:33:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to define a start time for a search based on log message</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-define-a-start-time-for-a-search-based-on-log-message/m-p/446511#M126676</link>
      <description>&lt;P&gt;Like I said, that "eval StartSearchFrom clause needs work.   I don't believe there's a function called "imatch", and your if() statement doesn't have a 2nd argument.&lt;/P&gt;

&lt;P&gt;The search:&lt;BR /&gt;
    index=_internal sourcetype=scheduler earliest="07/01/2019:20:01:39"&lt;BR /&gt;
works by using the &lt;STRONG&gt;earliest&lt;/STRONG&gt; time modifier.   The documentation says:&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;You can specify an exact time such as&lt;BR /&gt;
earliest="10/5/2016:20:00:00", or a&lt;BR /&gt;
relative time such as earliest=-h or&lt;BR /&gt;
latest=@w6&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;So, that's the format for an exact time that the time modifier expects.   If your time is not in that format, or has the seconds added to it, then it may not work.&lt;/P&gt;

&lt;P&gt;So your success lies in getting your timestamp in that format and in the "earliest" field, before you execute a  "| return earliest" from the subsearch.&lt;/P&gt;

&lt;P&gt;This works, right?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_internal sourcetype=scheduler 
     [| makeresults | eval start=relative_time(now(),"-60m") 
 | eval earliest=strftime(start, "%m/%d/%Y:%H:%M:%S")
     | return  earliest]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;you should just work to replace the stuff inside the strftime() function.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jul 2019 17:03:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-define-a-start-time-for-a-search-based-on-log-message/m-p/446511#M126676</guid>
      <dc:creator>memarshall63</dc:creator>
      <dc:date>2019-07-02T17:03:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to define a start time for a search based on log message</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-define-a-start-time-for-a-search-based-on-log-message/m-p/446512#M126677</link>
      <description>&lt;P&gt;I have yet to see this worked expected -- and yes imatch was a typo... have a good afternoon! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jul 2019 18:51:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-define-a-start-time-for-a-search-based-on-log-message/m-p/446512#M126677</guid>
      <dc:creator>dowdag</dc:creator>
      <dc:date>2019-07-02T18:51:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to define a start time for a search based on log message</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-define-a-start-time-for-a-search-based-on-log-message/m-p/446513#M126678</link>
      <description>&lt;P&gt;What does your search look like and what results are you seeing?  It's got to be pretty close.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jul 2019 17:07:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-define-a-start-time-for-a-search-based-on-log-message/m-p/446513#M126678</guid>
      <dc:creator>memarshall63</dc:creator>
      <dc:date>2019-07-04T17:07:57Z</dc:date>
    </item>
  </channel>
</rss>

