<?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 How to find duration between multiple events for multiple occurrences? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-duration-between-multiple-events-for-multiple/m-p/611752#M212683</link>
    <description>&lt;P&gt;Hi all, I'm hoping that someone can help / point me in the right direction.&lt;/P&gt;
&lt;P&gt;I have two events which are being fed into Splunk, one being a raise of an event flag, the other being the removal of the event flag.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Raising&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Sep 2 10:32:45 SOFTWARE CEF:0|SOFTWARE|CLIENT|42|Agent Log Event|Agent Log Event|high|id=123 shost=Management start=2022-09-02 10:32:42 cs1Label=Affected Agents cs1=[SERVERNAME] (ip: None, component_id: ID) msg='AgentMissing' status flag was raised&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Removal&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Sep 2 10:34:33 SOFTWARE CEF:0|SOFTWARE|CLIENT|42|Agent Log Event|Agent Log Event|high|id=123 shost=Management start=2022-09-02 10:34:33 cs1Label=Affected Agents cs1=[SERVERNAME] (ip: None, component_id: ID) msg='AgentMissing' status flag was removed&lt;/P&gt;
&lt;P&gt;After some browsing online &amp;amp; through the Splunk support pages I have been able to put together the following query:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;(index=[INDEX] *agentmissing*) ("msg='AgentMissing' status flag was raised" OR "msg='AgentMissing' status flag was removed")
| rex field=_raw ".*\)\s+(?&amp;lt;status&amp;gt;.*)"
| stats latest(_time) as flag_finish by connection_type
| join connection_type
[ search index=[INDEX] ("msg='AgentMissing' status flag was raised") connection_type=*
| stats min(_time) as flag_start by connection_type]
| eval difference=flag_finish-flag_start
| eval flag_start=strftime(flag_start, "%Y-%m-%d %H:%M")
| eval flag_finish=strftime(flag_finish, "%Y-%m-%d %H:%M")
| eval difference=strftime(difference,"%H:%M:%S")
| table connection_type, flag_start, flag_finish, difference
| rename connection_type as Hostname, flag_start as "Flag Raised Time", flag_finish as "Flag End Time", difference as "Total Time"
| sort - difference&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The above is working, however as I am using the "stats latest" command it is only showing the latest occurrence of the event.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MLL9_0-1662117311650.png" style="width: 999px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/21292iD6E599C545371769/image-size/large?v=v2&amp;amp;px=999" role="button" title="MLL9_0-1662117311650.png" alt="MLL9_0-1662117311650.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;However, I would like to display the time between these events for multiple occurrences. So as an example of the above, it was between 7:47 &amp;amp; 9:31, I would also like to see flags for other time occurrences.&lt;/P&gt;
&lt;P&gt;TIA! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 02 Sep 2022 14:35:42 GMT</pubDate>
    <dc:creator>MLL9</dc:creator>
    <dc:date>2022-09-02T14:35:42Z</dc:date>
    <item>
      <title>How to find duration between multiple events for multiple occurrences?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-duration-between-multiple-events-for-multiple/m-p/611752#M212683</link>
      <description>&lt;P&gt;Hi all, I'm hoping that someone can help / point me in the right direction.&lt;/P&gt;
&lt;P&gt;I have two events which are being fed into Splunk, one being a raise of an event flag, the other being the removal of the event flag.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Raising&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Sep 2 10:32:45 SOFTWARE CEF:0|SOFTWARE|CLIENT|42|Agent Log Event|Agent Log Event|high|id=123 shost=Management start=2022-09-02 10:32:42 cs1Label=Affected Agents cs1=[SERVERNAME] (ip: None, component_id: ID) msg='AgentMissing' status flag was raised&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Removal&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Sep 2 10:34:33 SOFTWARE CEF:0|SOFTWARE|CLIENT|42|Agent Log Event|Agent Log Event|high|id=123 shost=Management start=2022-09-02 10:34:33 cs1Label=Affected Agents cs1=[SERVERNAME] (ip: None, component_id: ID) msg='AgentMissing' status flag was removed&lt;/P&gt;
&lt;P&gt;After some browsing online &amp;amp; through the Splunk support pages I have been able to put together the following query:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;(index=[INDEX] *agentmissing*) ("msg='AgentMissing' status flag was raised" OR "msg='AgentMissing' status flag was removed")
| rex field=_raw ".*\)\s+(?&amp;lt;status&amp;gt;.*)"
| stats latest(_time) as flag_finish by connection_type
| join connection_type
[ search index=[INDEX] ("msg='AgentMissing' status flag was raised") connection_type=*
| stats min(_time) as flag_start by connection_type]
| eval difference=flag_finish-flag_start
| eval flag_start=strftime(flag_start, "%Y-%m-%d %H:%M")
| eval flag_finish=strftime(flag_finish, "%Y-%m-%d %H:%M")
| eval difference=strftime(difference,"%H:%M:%S")
| table connection_type, flag_start, flag_finish, difference
| rename connection_type as Hostname, flag_start as "Flag Raised Time", flag_finish as "Flag End Time", difference as "Total Time"
| sort - difference&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The above is working, however as I am using the "stats latest" command it is only showing the latest occurrence of the event.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MLL9_0-1662117311650.png" style="width: 999px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/21292iD6E599C545371769/image-size/large?v=v2&amp;amp;px=999" role="button" title="MLL9_0-1662117311650.png" alt="MLL9_0-1662117311650.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;However, I would like to display the time between these events for multiple occurrences. So as an example of the above, it was between 7:47 &amp;amp; 9:31, I would also like to see flags for other time occurrences.&lt;/P&gt;
&lt;P&gt;TIA! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Sep 2022 14:35:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-duration-between-multiple-events-for-multiple/m-p/611752#M212683</guid>
      <dc:creator>MLL9</dc:creator>
      <dc:date>2022-09-02T14:35:42Z</dc:date>
    </item>
    <item>
      <title>Re: Find duration between multiple events, show multiple occurrences.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-duration-between-multiple-events-for-multiple/m-p/611759#M212686</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/249124"&gt;@MLL9&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;did you tried to use?&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| stats earliest(_time) AS earliest latest(_time) AS latest by connection_type&lt;/LI-CODE&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;</description>
      <pubDate>Fri, 02 Sep 2022 11:58:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-duration-between-multiple-events-for-multiple/m-p/611759#M212686</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2022-09-02T11:58:56Z</dc:date>
    </item>
    <item>
      <title>Re: Find duration between multiple events, show multiple occurrences.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-duration-between-multiple-events-for-multiple/m-p/611762#M212689</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/161352"&gt;@gcusello&lt;/a&gt;&amp;nbsp;, thanks for the reply.&lt;/P&gt;&lt;P&gt;Unfortunately yes, I've tried that &amp;amp; its still only shows one results, example below:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="25%"&gt;&lt;STRONG&gt;Hostname&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD width="25%"&gt;&lt;STRONG&gt;Start Time&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD width="25%"&gt;&lt;STRONG&gt;End Time&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD width="25%"&gt;&lt;STRONG&gt;Difference&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%"&gt;Hostname1&lt;/TD&gt;&lt;TD width="25%"&gt;Start Time 1&lt;/TD&gt;&lt;TD width="25%"&gt;End Time 1&lt;/TD&gt;&lt;TD width="25%"&gt;Difference 1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;What I was hoping for was:&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="25%"&gt;&lt;STRONG&gt;Hostname&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD width="25%"&gt;&lt;STRONG&gt;Start Time&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD width="25%"&gt;&lt;STRONG&gt;End Time&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD width="25%"&gt;&lt;STRONG&gt;Difference&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%"&gt;Hostname1&lt;/TD&gt;&lt;TD width="25%"&gt;Start Time 1&lt;/TD&gt;&lt;TD width="25%"&gt;End Time 1&lt;/TD&gt;&lt;TD width="25%"&gt;Difference 1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%"&gt;Hostname1&lt;/TD&gt;&lt;TD width="25%"&gt;Start Time 2&lt;/TD&gt;&lt;TD width="25%"&gt;End Time 2&lt;/TD&gt;&lt;TD width="25%"&gt;Difference 2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%"&gt;Hostname1&lt;/TD&gt;&lt;TD width="25%"&gt;Start Time 3&lt;/TD&gt;&lt;TD width="25%"&gt;End Time 3&lt;/TD&gt;&lt;TD width="25%"&gt;Difference 3&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Fri, 02 Sep 2022 12:30:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-duration-between-multiple-events-for-multiple/m-p/611762#M212689</guid>
      <dc:creator>MLL9</dc:creator>
      <dc:date>2022-09-02T12:30:00Z</dc:date>
    </item>
    <item>
      <title>Re: Find duration between multiple events, show multiple occurrences.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-duration-between-multiple-events-for-multiple/m-p/611763#M212690</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/249124"&gt;@MLL9&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;In this case&amp;nbsp;the only way is the transaction command&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| transaction maxevents=2 connection_type&lt;/LI-CODE&gt;&lt;P&gt;in this way you have a transaction every two events,&lt;/P&gt;&lt;P&gt;for this transaction you have: the "Flag raised time", the "End raised time"="Flag raised time"+duration and you have many transaction for each connection time.&lt;/P&gt;&lt;P&gt;if each transaction has a start message and an end message, you could also use the "startswith" and "endswith" options in thetransaction command.&lt;/P&gt;&lt;P&gt;For more infos see at&amp;nbsp;&lt;A href="https://docs.splunk.com/Documentation/Splunk/9.0.1/SearchReference/Transaction" target="_blank"&gt;https://docs.splunk.com/Documentation/Splunk/9.0.1/SearchReference/Transaction&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;</description>
      <pubDate>Fri, 02 Sep 2022 12:49:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-duration-between-multiple-events-for-multiple/m-p/611763#M212690</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2022-09-02T12:49:55Z</dc:date>
    </item>
    <item>
      <title>Re: Find duration between multiple events, show multiple occurrences.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-duration-between-multiple-events-for-multiple/m-p/611783#M212693</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/161352"&gt;@gcusello&lt;/a&gt;&amp;nbsp;,&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| transaction maxevents=2 connection_type&lt;/LI-CODE&gt;&lt;P&gt;Has pointed me in the right direction &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Sep 2022 15:19:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-duration-between-multiple-events-for-multiple/m-p/611783#M212693</guid>
      <dc:creator>MLL9</dc:creator>
      <dc:date>2022-09-02T15:19:27Z</dc:date>
    </item>
    <item>
      <title>Re: Find duration between multiple events, show multiple occurrences.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-duration-between-multiple-events-for-multiple/m-p/611788#M212695</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/249124"&gt;@MLL9&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;good for you, see next time!&lt;/P&gt;&lt;P&gt;tell me if I can help you more, otherwise, please accept one answer for the other people of Community&lt;/P&gt;&lt;P&gt;Ciao and happy splunking&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;&lt;P&gt;P.S.: Karma Points are appreciated &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Sep 2022 15:28:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-duration-between-multiple-events-for-multiple/m-p/611788#M212695</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2022-09-02T15:28:57Z</dc:date>
    </item>
  </channel>
</rss>

