<?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 determination in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Duration-determination/m-p/429205#M122783</link>
    <description>&lt;P&gt;Hello Robert,&lt;/P&gt;

&lt;P&gt;I assume you have the fields _time, action (connect|disconnect) and username available; or named something similar.&lt;/P&gt;

&lt;P&gt;If you are missing the _time field, then use the strptime() eval function to create it.&lt;/P&gt;

&lt;P&gt;Now I suggest you use the &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Transaction"&gt;transaction command&lt;/A&gt; as follows:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search
| transaction user startswith=(status="connect") endswith=(status="disconnect")
| eval duration=tostring(duration, "duration")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The transaction command will create the duration field.&lt;/P&gt;

&lt;P&gt;The eval command will convert the duration from the number of seconds to the more human readable format HH:MM:SS.&lt;/P&gt;</description>
    <pubDate>Sat, 26 Jan 2019 18:38:53 GMT</pubDate>
    <dc:creator>whrg</dc:creator>
    <dc:date>2019-01-26T18:38:53Z</dc:date>
    <item>
      <title>Duration determination</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Duration-determination/m-p/429203#M122781</link>
      <description>&lt;P&gt;Here is a sample of a connection that spans the midnight hour into the next day. I'm trying to extract a new field named duration  that contains the difference  between the  connect and disconnect times in a human readable format&lt;/P&gt;

&lt;P&gt;1547514148  2019-01-14  20:02:27    connect johndoe&lt;BR /&gt;
1547530430  2019-01-15  00:33:49    disconnect   johndoe&lt;/P&gt;

&lt;P&gt;I've tried  many different splunk commands such as stats, eval and transaction commands  from many posts here but have been unsuccessful&lt;/P&gt;

&lt;P&gt;Thanks in advance,&lt;BR /&gt;
Robert&lt;/P&gt;</description>
      <pubDate>Sat, 26 Jan 2019 17:34:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Duration-determination/m-p/429203#M122781</guid>
      <dc:creator>roayers</dc:creator>
      <dc:date>2019-01-26T17:34:10Z</dc:date>
    </item>
    <item>
      <title>Re: Duration determination</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Duration-determination/m-p/429204#M122782</link>
      <description>&lt;P&gt;Like this (assuming &lt;CODE&gt;user&lt;/CODE&gt; is the field that owns &lt;CODE&gt;johndoe&lt;/CODE&gt;&lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=YouShouldAlwaysSpecifyAnIndex AND sourcetype=AndSourcetypeToo
| streamstats count(searchmatch("disconnect")) AS sessionID BY user
| stats range(_time) AS duration BY sessionID user
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And then maybe also&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval duration = tostring(duration, "duration")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 26 Jan 2019 18:29:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Duration-determination/m-p/429204#M122782</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-01-26T18:29:25Z</dc:date>
    </item>
    <item>
      <title>Re: Duration determination</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Duration-determination/m-p/429205#M122783</link>
      <description>&lt;P&gt;Hello Robert,&lt;/P&gt;

&lt;P&gt;I assume you have the fields _time, action (connect|disconnect) and username available; or named something similar.&lt;/P&gt;

&lt;P&gt;If you are missing the _time field, then use the strptime() eval function to create it.&lt;/P&gt;

&lt;P&gt;Now I suggest you use the &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Transaction"&gt;transaction command&lt;/A&gt; as follows:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search
| transaction user startswith=(status="connect") endswith=(status="disconnect")
| eval duration=tostring(duration, "duration")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The transaction command will create the duration field.&lt;/P&gt;

&lt;P&gt;The eval command will convert the duration from the number of seconds to the more human readable format HH:MM:SS.&lt;/P&gt;</description>
      <pubDate>Sat, 26 Jan 2019 18:38:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Duration-determination/m-p/429205#M122783</guid>
      <dc:creator>whrg</dc:creator>
      <dc:date>2019-01-26T18:38:53Z</dc:date>
    </item>
    <item>
      <title>Re: Duration determination</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Duration-determination/m-p/429206#M122784</link>
      <description>&lt;P&gt;This generated the following error&lt;BR /&gt;
Error in 'SearchProcessor': Mismatched quotes and/or parenthesis. &lt;/P&gt;</description>
      <pubDate>Sat, 26 Jan 2019 19:42:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Duration-determination/m-p/429206#M122784</guid>
      <dc:creator>roayers</dc:creator>
      <dc:date>2019-01-26T19:42:47Z</dc:date>
    </item>
    <item>
      <title>Re: Duration determination</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Duration-determination/m-p/429207#M122785</link>
      <description>&lt;P&gt;This worked after I changed the field name status to action&lt;/P&gt;

&lt;P&gt;status="connect") endswith=(status="disconnect")  to this &lt;BR /&gt;
action="connect") endswith=(action="disconnect")&lt;/P&gt;</description>
      <pubDate>Sat, 26 Jan 2019 19:42:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Duration-determination/m-p/429207#M122785</guid>
      <dc:creator>roayers</dc:creator>
      <dc:date>2019-01-26T19:42:53Z</dc:date>
    </item>
    <item>
      <title>Re: Duration determination</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Duration-determination/m-p/429208#M122786</link>
      <description>&lt;P&gt;I was missing a &lt;CODE&gt;)&lt;/CODE&gt;.  I updated my answer.  Try it now, @roayers.&lt;/P&gt;</description>
      <pubDate>Sat, 26 Jan 2019 21:43:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Duration-determination/m-p/429208#M122786</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-01-26T21:43:49Z</dc:date>
    </item>
  </channel>
</rss>

