<?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 get the first event time and last event time for field value in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/how-to-get-the-first-event-time-and-last-event-time-for-field/m-p/428336#M191104</link>
    <description>&lt;P&gt;I need to start and end time , by First when status was true and last when status was false, i need to ignore between changes. &lt;/P&gt;

&lt;P&gt;Eg: &lt;BR /&gt;
10:00 - True&lt;BR /&gt;
10:15 - false&lt;BR /&gt;
10:20 - True&lt;BR /&gt;
10:23 - False&lt;BR /&gt;
10:26 - True&lt;BR /&gt;
10:50  - False&lt;/P&gt;

&lt;P&gt;I need to calculate first event as 10:00  and last even as 10:50 , duration wil be 50 mins.&lt;BR /&gt;
To get it , i need unique value as car details in all events&lt;/P&gt;

&lt;P&gt;I need to know how to get it.&lt;/P&gt;</description>
    <pubDate>Tue, 06 Aug 2019 08:03:33 GMT</pubDate>
    <dc:creator>SathyaNarayanan</dc:creator>
    <dc:date>2019-08-06T08:03:33Z</dc:date>
    <item>
      <title>how to get the first event time and last event time for field value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-get-the-first-event-time-and-last-event-time-for-field/m-p/428334#M191102</link>
      <description>&lt;P&gt;Hi Splunkers,&lt;/P&gt;

&lt;P&gt;My events will look like below.&lt;/P&gt;

&lt;P&gt;2019-08-06 10:14:00  TYPE="PLB_1", STATUS="true", CAR="A", PLACE="ABC"&lt;BR /&gt;
2019-08-06 10:16:00  TYPE="PLB_1", STATUS="false", CAR="A", PLACE="ABC"&lt;BR /&gt;
2019-08-06 10:19:00  TYPE="PLB_1", STATUS="true", CAR="A", PLACE="ABC"&lt;BR /&gt;
2019-08-06 10:25:00  TYPE="PLB_1", STATUS="false", CAR="A", PLACE="ABC"&lt;BR /&gt;
2019-08-06 10:40:00  TYPE="PLB_1", STATUS="false", CAR="C", PLACE="ABC"&lt;BR /&gt;
2019-08-06 10:49:00  TYPE="PLB_1", STATUS="false", CAR="C", PLACE="ABC"&lt;BR /&gt;
2019-08-06 10:50:00  TYPE="PLB_2", STATUS="false", CAR="B", PLACE="DEF"&lt;BR /&gt;
2019-08-06 11:14:00  TYPE="PLB_2", STATUS="false", CAR="B", PLACE="DEF"&lt;BR /&gt;
2019-08-06 11:25:00  TYPE="PLB_2", STATUS="false", CAR="B", PLACE="DEF"&lt;/P&gt;

&lt;P&gt;Now i need to get the when the first status as true time till and last status time it was falst as per the PLACE&lt;/P&gt;

&lt;P&gt;So i tried transaction command to combine it startswith=STATUS="true" endswith=STATUS="false" , but in my case status will be changed many time, i need to get the first and last STATUS time.&lt;/P&gt;

&lt;P&gt;Eg: I need to know from time and End time the CAR was parked in that place, so tat i can calculate the duration of parking per PLACE and TYPE perCAR.&lt;/P&gt;

&lt;P&gt;Thanks in advance. &lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 01:36:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-get-the-first-event-time-and-last-event-time-for-field/m-p/428334#M191102</guid>
      <dc:creator>SathyaNarayanan</dc:creator>
      <dc:date>2020-09-30T01:36:47Z</dc:date>
    </item>
    <item>
      <title>Re: how to get the first event time and last event time for field value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-get-the-first-event-time-and-last-event-time-for-field/m-p/428335#M191103</link>
      <description>&lt;P&gt;Bit more clarification will make it easy to help you. &lt;/P&gt;

&lt;P&gt;It's unclear from below statement, how you gonna find start and end time of car parking.&lt;/P&gt;

&lt;P&gt;&lt;EM&gt;"So i tried transaction command to combine it startswith=STATUS="true" endswith=STATUS="false" , **but in my case status will be changed many time&lt;/EM&gt;&lt;EM&gt;, i need to get the first and last STATUS time."&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 01:36:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-get-the-first-event-time-and-last-event-time-for-field/m-p/428335#M191103</guid>
      <dc:creator>jawaharas</dc:creator>
      <dc:date>2020-09-30T01:36:50Z</dc:date>
    </item>
    <item>
      <title>Re: how to get the first event time and last event time for field value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-get-the-first-event-time-and-last-event-time-for-field/m-p/428336#M191104</link>
      <description>&lt;P&gt;I need to start and end time , by First when status was true and last when status was false, i need to ignore between changes. &lt;/P&gt;

&lt;P&gt;Eg: &lt;BR /&gt;
10:00 - True&lt;BR /&gt;
10:15 - false&lt;BR /&gt;
10:20 - True&lt;BR /&gt;
10:23 - False&lt;BR /&gt;
10:26 - True&lt;BR /&gt;
10:50  - False&lt;/P&gt;

&lt;P&gt;I need to calculate first event as 10:00  and last even as 10:50 , duration wil be 50 mins.&lt;BR /&gt;
To get it , i need unique value as car details in all events&lt;/P&gt;

&lt;P&gt;I need to know how to get it.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Aug 2019 08:03:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-get-the-first-event-time-and-last-event-time-for-field/m-p/428336#M191104</guid>
      <dc:creator>SathyaNarayanan</dc:creator>
      <dc:date>2019-08-06T08:03:33Z</dc:date>
    </item>
    <item>
      <title>Re: how to get the first event time and last event time for field value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-get-the-first-event-time-and-last-event-time-for-field/m-p/428337#M191105</link>
      <description>&lt;P&gt;@SathyaNarayanan try the following run anywhere example. You can play around with the search filter as per your need.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval data="2019-08-06 10:14:00 TYPE=\"PLB_1\", STATUS=\"true\", CAR=\"A\", PLACE=\"ABC\";2019-08-06 10:16:00 TYPE=\"PLB_1\", STATUS=\"false\", CAR=\"A\", PLACE=\"ABC\";2019-08-06 10:19:00 TYPE=\"PLB_1\", STATUS=\"true\", CAR=\"A\", PLACE=\"ABC\";2019-08-06 10:25:00 TYPE=\"PLB_1\", STATUS=\"false\", CAR=\"A\", PLACE=\"ABC\";2019-08-06 10:40:00 TYPE=\"PLB_1\", STATUS=\"false\", CAR=\"C\", PLACE=\"ABC\";2019-08-06 10:49:00 TYPE=\"PLB_1\", STATUS=\"false\", CAR=\"C\", PLACE=\"ABC\";2019-08-06 10:50:00 TYPE=\"PLB_2\", STATUS=\"false\", CAR=\"B\", PLACE=\"DEF\";2019-08-06 11:14:00 TYPE=\"PLB_2\", STATUS=\"false\", CAR=\"B\", PLACE=\"DEF\";2019-08-06 11:25:00 TYPE=\"PLB_2\", STATUS=\"false\", CAR=\"B\", PLACE=\"DEF\";"
| makemv data delim=";"
| mvexpand data
| rename data as _raw
| rex "^(?&amp;lt;time&amp;gt;[^\s]+\s[^\s]+)\s"
| eval _time=strptime(time,"%Y-%m-%d %H:%M:%S")
| fields - time
| KV
| sort _time
| stats min(_time) as _time max(_time) as LatestTime first(STATUS) as FirstStatus last(STATUS) as LastStatus values(STATUS) as STATUS by TYPE
| search FirstStatus="true" AND LastStatus=false STATUS IN ("true","false")
| eval duration=tostring(LatestTime-_time,"duration")
| fields - LatestTime
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;PS: Commands from &lt;CODE&gt;| makeresults&lt;/CODE&gt; till &lt;CODE&gt;| sort _time&lt;/CODE&gt; generate data as per your use case. Please try out and confirm!&lt;/P&gt;</description>
      <pubDate>Tue, 06 Aug 2019 08:30:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-get-the-first-event-time-and-last-event-time-for-field/m-p/428337#M191105</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2019-08-06T08:30:45Z</dc:date>
    </item>
    <item>
      <title>Re: how to get the first event time and last event time for field value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-get-the-first-event-time-and-last-event-time-for-field/m-p/428338#M191106</link>
      <description>&lt;P&gt;@niketnilay &lt;/P&gt;

&lt;P&gt;thanks,&lt;/P&gt;

&lt;P&gt;It worked for me, now i have one more doubt, for example when the park in not used for some time in between, the duration calculates that also, how to more accurate in the duration.&lt;/P&gt;

&lt;P&gt;Eg:- &lt;/P&gt;

&lt;P&gt;10:00 - True&lt;BR /&gt;
10:15 - false&lt;BR /&gt;
10:20 - True&lt;BR /&gt;
10:23 - False&lt;BR /&gt;
10:26 - True&lt;BR /&gt;
10:50 - False&lt;/P&gt;

&lt;P&gt;i need to calculate 10:00 to 10:15. then 10:20 to 10:23 and 10:26 to 10:50 , so the duration will be 15 + 3 + 24 = 42.&lt;/P&gt;

&lt;P&gt;As per your query it will be 10:00 to 10:50 , so duration will be 50 mins.&lt;/P&gt;

&lt;P&gt;thanks in advance &lt;/P&gt;</description>
      <pubDate>Wed, 07 Aug 2019 06:24:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-get-the-first-event-time-and-last-event-time-for-field/m-p/428338#M191106</guid>
      <dc:creator>SathyaNarayanan</dc:creator>
      <dc:date>2019-08-07T06:24:48Z</dc:date>
    </item>
  </channel>
</rss>

