<?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: Duration of two events by status! in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Duration-of-two-events-by-status/m-p/312464#M164789</link>
    <description>&lt;P&gt;You can probably do this by using &lt;CODE&gt;reverse&lt;/CODE&gt; and &lt;CODE&gt;dedup&lt;/CODE&gt; command. Are both ip and status an extracted fields? If yes, something like this would work.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search | reverse | dedup ip status | stats range(_time) by ip
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 27 Nov 2017 16:14:29 GMT</pubDate>
    <dc:creator>somesoni2</dc:creator>
    <dc:date>2017-11-27T16:14:29Z</dc:date>
    <item>
      <title>Duration of two events by status!</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Duration-of-two-events-by-status/m-p/312462#M164787</link>
      <description>&lt;P&gt;hi,&lt;BR /&gt;
my raw data look like this:&lt;/P&gt;

&lt;P&gt;12:01:11:000 ip: "123.456.789" = "1"&lt;BR /&gt;
12:01:12:000 ip: "123.456.789" = "1"&lt;BR /&gt;
12:01:13:000 ip: "123.456.789" = "1"&lt;BR /&gt;
12:01:14:000 ip: "123.456.789" = "2"&lt;BR /&gt;
12:01:15:000 ip: "123.456.789" = "2"&lt;BR /&gt;
12:01:16:000 ip: "123.456.789" = "1"&lt;BR /&gt;
12:01:17:000 ip: "123.456.789" = "1"&lt;/P&gt;

&lt;P&gt;Now i want to calculate the duration only between the first event of "1" and "2". In other words, the duration when the ip shows the status "1". I tried some transaction and streamstats commands but nothing worked properly.&lt;/P&gt;

&lt;P&gt;Thanks for your help!&lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2017 14:11:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Duration-of-two-events-by-status/m-p/312462#M164787</guid>
      <dc:creator>reschal</dc:creator>
      <dc:date>2017-11-27T14:11:25Z</dc:date>
    </item>
    <item>
      <title>Re: Duration of two events by status!</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Duration-of-two-events-by-status/m-p/312463#M164788</link>
      <description>&lt;P&gt;You could try with the transaction command:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=&amp;lt;your_index&amp;gt; sourcetype=&amp;lt;your_sourcetype&amp;gt;
| transaction ip endswith=value=2
| eval keep=mvfilter(match(value, "1"))
| where keep=1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Assuming you are extracting the ip under field "ip" and values 1/2 under field "value"&lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2017 15:46:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Duration-of-two-events-by-status/m-p/312463#M164788</guid>
      <dc:creator>damien_chillet</dc:creator>
      <dc:date>2017-11-27T15:46:01Z</dc:date>
    </item>
    <item>
      <title>Re: Duration of two events by status!</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Duration-of-two-events-by-status/m-p/312464#M164789</link>
      <description>&lt;P&gt;You can probably do this by using &lt;CODE&gt;reverse&lt;/CODE&gt; and &lt;CODE&gt;dedup&lt;/CODE&gt; command. Are both ip and status an extracted fields? If yes, something like this would work.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search | reverse | dedup ip status | stats range(_time) by ip
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 27 Nov 2017 16:14:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Duration-of-two-events-by-status/m-p/312464#M164789</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-11-27T16:14:29Z</dc:date>
    </item>
    <item>
      <title>Re: Duration of two events by status!</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Duration-of-two-events-by-status/m-p/312465#M164790</link>
      <description>&lt;P&gt;(I loaded your sample data into my test box then I did a field extraction for the IP and another for CODE.)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=main sourcetype=reschal2 | sort _time
| table _time, CODE
| streamstats range(_time) as DURATION by CODE reset_on_change=true
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Those commands will show you how long it was "1", then "2" then "1" again.&lt;/P&gt;

&lt;P&gt;Here are some screenshots....&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/3936i147679A359344107/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2017 20:00:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Duration-of-two-events-by-status/m-p/312465#M164790</guid>
      <dc:creator>lycollicott</dc:creator>
      <dc:date>2017-11-27T20:00:38Z</dc:date>
    </item>
    <item>
      <title>Re: Duration of two events by status!</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Duration-of-two-events-by-status/m-p/312466#M164791</link>
      <description>&lt;P&gt;Don't know why the screenshot isn't displaying and the site won't let me upload another.  &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt; &lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2017 20:22:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Duration-of-two-events-by-status/m-p/312466#M164791</guid>
      <dc:creator>lycollicott</dc:creator>
      <dc:date>2017-11-27T20:22:08Z</dc:date>
    </item>
    <item>
      <title>Re: Duration of two events by status!</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Duration-of-two-events-by-status/m-p/312467#M164792</link>
      <description>&lt;P&gt;I would change &lt;CODE&gt;| sort _time&lt;/CODE&gt;  to &lt;CODE&gt;| sort 0 _time&lt;/CODE&gt; in order to avoid it to be truncated after 10K rows (default limit). &lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2017 20:51:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Duration-of-two-events-by-status/m-p/312467#M164792</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-11-27T20:51:29Z</dc:date>
    </item>
    <item>
      <title>Re: Duration of two events by status!</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Duration-of-two-events-by-status/m-p/312468#M164793</link>
      <description>&lt;P&gt;Thank you. Your answer works great. By adding&lt;/P&gt;

&lt;P&gt;|table _time duration |eval duration=tostring(duration,"duration")| sort -_time&lt;/P&gt;

&lt;P&gt;i get a proper solution!&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 17:01:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Duration-of-two-events-by-status/m-p/312468#M164793</guid>
      <dc:creator>reschal</dc:creator>
      <dc:date>2020-09-29T17:01:22Z</dc:date>
    </item>
    <item>
      <title>Re: Duration of two events by status!</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Duration-of-two-events-by-status/m-p/312469#M164794</link>
      <description>&lt;P&gt;Yea, i forgot to mention duration would be stored under duration field, that's great you found it!&lt;/P&gt;

&lt;P&gt;Thanks for accepting my answer and happy Splunking!&lt;/P&gt;</description>
      <pubDate>Tue, 28 Nov 2017 09:36:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Duration-of-two-events-by-status/m-p/312469#M164794</guid>
      <dc:creator>damien_chillet</dc:creator>
      <dc:date>2017-11-28T09:36:15Z</dc:date>
    </item>
  </channel>
</rss>

