<?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: Using the transaction command to determine the length of an &amp;quot;active&amp;quot; session. in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Using-the-transaction-command-to-determine-the-length-of-an-quot/m-p/280080#M84562</link>
    <description>&lt;P&gt;So did this work?&lt;/P&gt;</description>
    <pubDate>Fri, 23 Oct 2015 00:42:33 GMT</pubDate>
    <dc:creator>woodcock</dc:creator>
    <dc:date>2015-10-23T00:42:33Z</dc:date>
    <item>
      <title>Using the transaction command to determine the length of an "active" session.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-the-transaction-command-to-determine-the-length-of-an-quot/m-p/280077#M84559</link>
      <description>&lt;P&gt;I have a system for which I'd like to be able to report on how much time individual users spend logged in.&lt;/P&gt;

&lt;P&gt;However, there are a few constraints:&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;When a user opens a new session, it is logged as a Session_Start event. During this time, a user can either log off (ending their session completely [see Bob below]), or a user can disconnect (say by.. closing their laptop screen), which the application registers as a disconnect, but keeps the session until a 1 hour timeout period passes. At this point the session is terminated (see Carol).&lt;/LI&gt;
&lt;LI&gt;&lt;P&gt;There could also be a scenario where a user gets disconnected but then is able to reconnect (for example, losing wifi while moving between rooms in the office), or closing their screen to go out for a quick lunch. &lt;/P&gt;

&lt;P&gt;_time               UserID  EventType&lt;BR /&gt;
10/14/15 08:00 AM   bob     Session_Start&lt;BR /&gt;
10/14/15 10:00 AM   bob     Session_End&lt;BR /&gt;
10/14/15 08:00 AM   alice   Session_Start&lt;BR /&gt;
10/14/15 08:30 AM   alice   Disconnect&lt;BR /&gt;
10/14/15 09:00 AM   alice   Reconnect&lt;BR /&gt;
10/14/15 10:00 AM   alice   Session_End&lt;BR /&gt;
10/14/15 08:00 AM   carol   Session_Start&lt;BR /&gt;
10/14/15 10:00 AM   carol   Disconnect&lt;BR /&gt;
10/14/15 11:00 AM   carol   Session_End&lt;BR /&gt;
Doing a nice and simple &lt;CODE&gt;transaction&lt;/CODE&gt; is a starting point:&lt;/P&gt;

&lt;P&gt;&lt;SEARCH&gt; | transaction UserID startswith=EventType=Session_Start endswith=EventType=Session_End&lt;BR /&gt;
From there I can easily do a &lt;CODE&gt;timechart span=1d sum(duration) by UserID&lt;/CODE&gt; to get the type of report I want. &lt;/SEARCH&gt;&lt;/P&gt;&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;This works in Bob's case just fine. But for Alice and Carol, they've both been given extra time. Alice disconnected at 8:30, and then reconnected at 9. That gives her an extra 30 minutes on that &lt;CODE&gt;sum(duration)&lt;/CODE&gt;. The sum for Carol is off as well, since he simply closed his laptop screen (for example), and called it a day. The system ended his session an hour later after the timeout passed.&lt;/P&gt;

&lt;P&gt;I'm struggling to find a good way to approach this. At this point, I'd be happy with just solving the issue demonstrated in Carol's case. Solving Alice's scenario would be a bonus.&lt;/P&gt;

&lt;P&gt;Any thoughts?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 07:37:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-the-transaction-command-to-determine-the-length-of-an-quot/m-p/280077#M84559</guid>
      <dc:creator>Ricapar</dc:creator>
      <dc:date>2020-09-29T07:37:17Z</dc:date>
    </item>
    <item>
      <title>Re: Using the transaction command to determine the length of an "active" session.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-the-transaction-command-to-determine-the-length-of-an-quot/m-p/280078#M84560</link>
      <description>&lt;P&gt;You can use expressions in startswith= and endswith=. So, you should be able to do something like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...search... | transaction UserID startswith=(EventType="Session_Start" OR EventType="Reconnect") endswith=(EventType="Session_End" OR EventType="Disconnect")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;See also: &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.3.0/SearchReference/Transaction"&gt;http://docs.splunk.com/Documentation/Splunk/6.3.0/SearchReference/Transaction&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Oct 2015 17:38:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-the-transaction-command-to-determine-the-length-of-an-quot/m-p/280078#M84560</guid>
      <dc:creator>masonmorales</dc:creator>
      <dc:date>2015-10-14T17:38:52Z</dc:date>
    </item>
    <item>
      <title>Re: Using the transaction command to determine the length of an "active" session.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-the-transaction-command-to-determine-the-length-of-an-quot/m-p/280079#M84561</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | reverse | eval SessionID=0 | streamstats current=f count (eval(EventType="Session_Start")) AS SessionID last(EventType) AS prevEventType last(_time) AS prevTime by UserID | eval deltaOnlineSeconds=if(prevEventType="Session_Start" OR prevEventType="Reconnect", _time - prevTime, 0) | stats sum(deltaOnlineSeconds) AS onlineSeconds BY SessionID, UserID
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you would like to roll up it one more time to get total over all sessions, then add this to the end of the previous search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | stats count AS sessions sum(onlineSeconds) AS onlineSeconds BY UserID
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 14 Oct 2015 18:40:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-the-transaction-command-to-determine-the-length-of-an-quot/m-p/280079#M84561</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-10-14T18:40:06Z</dc:date>
    </item>
    <item>
      <title>Re: Using the transaction command to determine the length of an "active" session.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-the-transaction-command-to-determine-the-length-of-an-quot/m-p/280080#M84562</link>
      <description>&lt;P&gt;So did this work?&lt;/P&gt;</description>
      <pubDate>Fri, 23 Oct 2015 00:42:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-the-transaction-command-to-determine-the-length-of-an-quot/m-p/280080#M84562</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-10-23T00:42:33Z</dc:date>
    </item>
  </channel>
</rss>

