<?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: SPL query to check event START... and END (if there is!!??!!) in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/SPL-query-to-check-event-START-and-END-if-there-is/m-p/467903#M131727</link>
    <description>&lt;P&gt;After running some tests,&lt;BR /&gt;
i made this schedule running every 30m.&lt;BR /&gt;
Should, for now, make the "trick", next i monitor the process and (tranks to @to4kawa) plan to optimize with better SPL...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;tag=mytag host=server earliest=-3h|sort + _time|eventstats first(_time) as tSTART last(_time) as tEND|eval RANGE=round((tEND-tSTART)/60)
|eval CHECK_START=if(match(_raw,"Job_Start"),_time,0)
|eval CHECK_END=if(match(_raw,"Job_End"),_time,0)
|stats max(CHECK_START) as START max(CHECK_END) as END last(RANGE) as RANGE
|where START!=0

|eval DUR=round((END-START)/60)|eval PASS=round((now()-START)/60)

|eval msg=""
|eval msg=if( (START=0) AND (END=0),"INFO - NO Job_Start last "+RANGE,msg)|eval nota="already skipped with where above!"
|eval msg=if( (START!=0) AND (END=0) AND (PASS&amp;gt;120),"KO - Job_Start no Job_End after "+PASS,msg)
|eval msg=if( (START!=0) AND (END!=0) AND (DUR&amp;gt;120),"KO - Job_Start with Job_End after "+DUR,msg)
|eval msg=if( (START!=0) AND (END!=0) AND (DUR&amp;lt;=120),"OK - Job_Start with Job_End after "+DUR,msg)
|where msg!=""

|eval host="server"| eval source="mylog"
|eval displaythis="LOG:"+source+"__"+msg+"__[test]" | eval TimeStamp=strftime(now(),"%Y%m%d.%H%M%S") | table TimeStamp host displaythis
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Surely i'm getting out of &lt;EM&gt;Best Practices&lt;/EM&gt; for SPL... but if works, let's do it &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
SPL is great... but could become very complex &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 09 Apr 2020 10:11:16 GMT</pubDate>
    <dc:creator>verbal_666</dc:creator>
    <dc:date>2020-04-09T10:11:16Z</dc:date>
    <item>
      <title>SPL query to check event START... and END (if there is!!??!!)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/SPL-query-to-check-event-START-and-END-if-there-is/m-p/467897#M131721</link>
      <description>&lt;P&gt;I guys.&lt;BR /&gt;
Recently i came in trouble to resolve the "puzzle" described in Title...&lt;/P&gt;

&lt;P&gt;What we need&lt;BR /&gt;
1) Trigger the "Job_Start", always&lt;BR /&gt;
2) Monitor its processation&lt;/P&gt;

&lt;P&gt;Variables&lt;BR /&gt;
1) "Job_Start" is dynamic, i can have it at 01:00 so at 04:30, 15:00 or 17:15 (and so on....h24): &lt;STRONG&gt;so "Job_Start" is the beginning point!!!&lt;/STRONG&gt;&lt;BR /&gt;
2) "Job_End" is the great variable: &lt;EM&gt;it could exists, as NOT AT ALL, and the focal point is to check if IT EXISTS in a range time of max 2h from "Job_Start"&lt;/EM&gt;&lt;/P&gt;

&lt;P&gt;What i originally did,&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;tag=mytag host=server earliest=-3h
|transaction maxspan=120m maxevents=-1 startswith="Job_Start" endswith="Job_End" host,source
|[...........do all if statements by "duration" field]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;... ok, but what if Job never ends???&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;tag=mytag host=server earliest=-3h
|transaction maxspan=120m maxevents=-1 startswith="Job_Start" host,source
|eval CHECK_END=if(match(_raw,"Job_End"),_time,"X")
|[...........do all if statements by "duration" field plus "CHECK_END" variable]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;... ok, this is a good compromise to work...&lt;/P&gt;

&lt;P&gt;Now, what i really scheduled (every 15 minutes), after thinking of possible missing timings or other things...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;tag=mytag host=server earliest=-3h|sort + _time|eventstats first(_time) as tSTART last(_time) as tEND|eval RANGE=round((tEND-tSTART)/60)
|eval CHECK_START=if(match(_raw,"Job_Start"),_time,"X")
|eval CHECK_END=if(match(_raw,"Job_End"),_time,"X")
|stats min(CHECK_START) as START min(CHECK_END) as END last(RANGE) as RANGE
|where START!="X"

|eval DUR=round((END-START)/60)|eval PASS=round((now()-START)/60)

|eval msg=if( (START="X") AND (END="X"),"NO Job_Start last "+RANGE,msg)|eval nota="already skipped with where above!"
|eval msg=if( (START!="X") AND (END="X") AND (PASS&amp;gt;120),"Job_Start no Job_End after "+PASS,msg)
|eval msg=if( (START!="X") AND (END!="X") AND (PASS&amp;gt;120),"Job_Start with Job_End after "+DUR,msg)

|eval host="server"| eval source="mylog"
|eval displaythis="LOG:"+source+"__"+msg+"__[test]" | eval TimeStamp=strftime(now(),"%Y%m%d.%H%M%S") | table TimeStamp host displaythis
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;... the schedule is running... still have to test its real effects...&lt;/P&gt;

&lt;P&gt;Now, some advice or help about what did above, and WHAT COULD BE DONE BETTER AND MORE EFFICIENTLY ?&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 04:53:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/SPL-query-to-check-event-START-and-END-if-there-is/m-p/467897#M131721</guid>
      <dc:creator>verbal_666</dc:creator>
      <dc:date>2020-09-30T04:53:32Z</dc:date>
    </item>
    <item>
      <title>Re: SPL query to check event START... and END (if there is!!??!!)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/SPL-query-to-check-event-START-and-END-if-there-is/m-p/467898#M131722</link>
      <description>&lt;P&gt;... maybe there's already a little "bug", better so,&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|eval msg=if( (START!="X") AND (END!="X") AND (DUR&amp;gt;120),"Job_Start with Job_End after "+DUR,msg)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;... anyway, waiting if the "process" is correct or there's one more efficent.&lt;BR /&gt;
Thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Apr 2020 18:57:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/SPL-query-to-check-event-START-and-END-if-there-is/m-p/467898#M131722</guid>
      <dc:creator>verbal_666</dc:creator>
      <dc:date>2020-04-07T18:57:40Z</dc:date>
    </item>
    <item>
      <title>Re: SPL query to check event START... and END (if there is!!??!!)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/SPL-query-to-check-event-START-and-END-if-there-is/m-p/467899#M131723</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;tag=mytag host=server earliest=-3h 
| reverse
| streamstats count(eval(searchmatch("Job_Start"))) as session by host source
| stats range(eval(if(searchmatch("Job_Start") OR searchmatch("Job_End"),_time,NULL))) as duration by session host source
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Try this and make eval function.&lt;BR /&gt;
This query makes &lt;CODE&gt;duration&lt;/CODE&gt; from &lt;EM&gt;Job_Start&lt;/EM&gt; to &lt;EM&gt;Job_End&lt;/EM&gt; (if exist) by each host and source.&lt;/P&gt;

&lt;P&gt;note: &lt;CODE&gt;duration&lt;/CODE&gt; is sec.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 04:58:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/SPL-query-to-check-event-START-and-END-if-there-is/m-p/467899#M131723</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-09-30T04:58:43Z</dc:date>
    </item>
    <item>
      <title>Re: SPL query to check event START... and END (if there is!!??!!)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/SPL-query-to-check-event-START-and-END-if-there-is/m-p/467900#M131724</link>
      <description>&lt;P&gt;Wow, very very interesting. The original "workaround" is running, i did some minimal change,&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;tag=mytag host=server earliest=-3h|sort + _time|eventstats first(_time) as tSTART last(_time) as tEND|eval RANGE=round((tEND-tSTART)/60)
|eval CHECK_START=if(match(_raw,"Job_Start"),_time,"X")
|eval CHECK_END=if(match(_raw,"Job_End"),_time,"X")
|stats min(CHECK_START) as START min(CHECK_END) as END last(RANGE) as RANGE
|where START!="X"

|eval DUR=round((END-START)/60)|eval PASS=round((now()-START)/60)

|eval msg=""
|eval msg=if( (START="X") AND (END="X"),"NO FileDiscoveryJob:95 last "+RANGE,msg)|eval nota="already skipped with where above!"
|eval msg=if( (START!="X") AND (END="X") AND (PASS&amp;gt;120),"FileDiscoveryJob:95 no AcquisitionAction:264 after "+PASS,msg)
|eval msg=if( (START!="X") AND (END!="X") AND (DUR&amp;gt;120),"FileDiscoveryJob:95 with AcquisitionAction:264 after "+DUR,msg)
|where msg!=""

|eval host="server"| eval source="mylog"
|eval displaythis="LOG:"+source+"__"+msg+"__[test]" | eval TimeStamp=strftime(now(),"%Y%m%d.%H%M%S") | table TimeStamp host displaythis
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But you SPL is extremely efficient and advanced!!!&lt;BR /&gt;
Many thanks, i'll test asap, and maybe do the right correlations with this.&lt;BR /&gt;
Thnaks a lot, very kind!!!&lt;/P&gt;</description>
      <pubDate>Thu, 09 Apr 2020 08:08:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/SPL-query-to-check-event-START-and-END-if-there-is/m-p/467900#M131724</guid>
      <dc:creator>verbal_666</dc:creator>
      <dc:date>2020-04-09T08:08:50Z</dc:date>
    </item>
    <item>
      <title>Re: SPL query to check event START... and END (if there is!!??!!)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/SPL-query-to-check-event-START-and-END-if-there-is/m-p/467901#M131725</link>
      <description>&lt;P&gt;I answered a lot, but this is the first time that I have been pleased like you.&lt;BR /&gt;
Thank you very much　@verbal_666 &lt;/P&gt;</description>
      <pubDate>Thu, 09 Apr 2020 08:15:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/SPL-query-to-check-event-START-and-END-if-there-is/m-p/467901#M131725</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-04-09T08:15:18Z</dc:date>
    </item>
    <item>
      <title>Re: SPL query to check event START... and END (if there is!!??!!)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/SPL-query-to-check-event-START-and-END-if-there-is/m-p/467902#M131726</link>
      <description>&lt;P&gt;You're welcome man... thanks again &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;BR /&gt;
(very smart solution &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; )&lt;/P&gt;</description>
      <pubDate>Thu, 09 Apr 2020 08:34:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/SPL-query-to-check-event-START-and-END-if-there-is/m-p/467902#M131726</guid>
      <dc:creator>verbal_666</dc:creator>
      <dc:date>2020-04-09T08:34:31Z</dc:date>
    </item>
    <item>
      <title>Re: SPL query to check event START... and END (if there is!!??!!)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/SPL-query-to-check-event-START-and-END-if-there-is/m-p/467903#M131727</link>
      <description>&lt;P&gt;After running some tests,&lt;BR /&gt;
i made this schedule running every 30m.&lt;BR /&gt;
Should, for now, make the "trick", next i monitor the process and (tranks to @to4kawa) plan to optimize with better SPL...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;tag=mytag host=server earliest=-3h|sort + _time|eventstats first(_time) as tSTART last(_time) as tEND|eval RANGE=round((tEND-tSTART)/60)
|eval CHECK_START=if(match(_raw,"Job_Start"),_time,0)
|eval CHECK_END=if(match(_raw,"Job_End"),_time,0)
|stats max(CHECK_START) as START max(CHECK_END) as END last(RANGE) as RANGE
|where START!=0

|eval DUR=round((END-START)/60)|eval PASS=round((now()-START)/60)

|eval msg=""
|eval msg=if( (START=0) AND (END=0),"INFO - NO Job_Start last "+RANGE,msg)|eval nota="already skipped with where above!"
|eval msg=if( (START!=0) AND (END=0) AND (PASS&amp;gt;120),"KO - Job_Start no Job_End after "+PASS,msg)
|eval msg=if( (START!=0) AND (END!=0) AND (DUR&amp;gt;120),"KO - Job_Start with Job_End after "+DUR,msg)
|eval msg=if( (START!=0) AND (END!=0) AND (DUR&amp;lt;=120),"OK - Job_Start with Job_End after "+DUR,msg)
|where msg!=""

|eval host="server"| eval source="mylog"
|eval displaythis="LOG:"+source+"__"+msg+"__[test]" | eval TimeStamp=strftime(now(),"%Y%m%d.%H%M%S") | table TimeStamp host displaythis
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Surely i'm getting out of &lt;EM&gt;Best Practices&lt;/EM&gt; for SPL... but if works, let's do it &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
SPL is great... but could become very complex &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Apr 2020 10:11:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/SPL-query-to-check-event-START-and-END-if-there-is/m-p/467903#M131727</guid>
      <dc:creator>verbal_666</dc:creator>
      <dc:date>2020-04-09T10:11:16Z</dc:date>
    </item>
  </channel>
</rss>

