<?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 first logout after login? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-first-logout-after-login/m-p/624237#M217032</link>
    <description>&lt;P&gt;Try again without the &lt;FONT face="courier new,courier"&gt;reverse&lt;/FONT&gt; command.&amp;nbsp; The &lt;FONT face="courier new,courier"&gt;transaction&lt;/FONT&gt; command makes assumptions about the order of events and &lt;FONT face="courier new,courier"&gt;reverse&lt;/FONT&gt; messes with that.&lt;/P&gt;</description>
    <pubDate>Wed, 14 Dec 2022 13:40:08 GMT</pubDate>
    <dc:creator>richgalloway</dc:creator>
    <dc:date>2022-12-14T13:40:08Z</dc:date>
    <item>
      <title>How to get first logout after login?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-first-logout-after-login/m-p/624141#M216988</link>
      <description>&lt;P&gt;I have daily user login/logout data like this:&lt;/P&gt;
&lt;PRE&gt;date,user,action&lt;BR /&gt;2020-04-14 01:00:00,user1,login&lt;BR /&gt;2020-04-14 01:05:00,user2,login&lt;BR /&gt;2020-04-14 01:10:00,user3,login&lt;BR /&gt;2020-04-14 02:40:00,user2,logout&lt;BR /&gt;2020-04-14 02:50:00,user3,logout&lt;BR /&gt;2020-04-14 03:10:00,user2,login&lt;BR /&gt;2020-04-14 03:10:00,user1,logout&lt;BR /&gt;2020-04-14 03:30:00,user3,login&lt;BR /&gt;2020-04-14 04:20:00,user2,logout&lt;/PRE&gt;
&lt;P&gt;Users can login/logout multiple times in a day. A session closes and then new session opens. (like user2) I need to get the duration for every session and there is no session id.&lt;/P&gt;
&lt;P&gt;How can i merge this two events in one row: Login and first logout after login. Like this:&lt;/P&gt;
&lt;PRE&gt;login_date,logout_date,user&lt;BR /&gt;2020-04-14 01:00:00,2020-04-14 03:10:00,user1&lt;BR /&gt;2020-04-14 01:05:00,2020-04-14 02:40:00,user2&lt;BR /&gt;2020-04-14 01:10:00,2020-04-14 02:50:00,user3&lt;BR /&gt;2020-04-14 03:10:00,2020-04-14 04:20:00,user2&lt;BR /&gt;2020-04-14 03:30:00,-,user3&amp;nbsp;&lt;/PRE&gt;</description>
      <pubDate>Tue, 13 Dec 2022 15:17:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-first-logout-after-login/m-p/624141#M216988</guid>
      <dc:creator>alissan</dc:creator>
      <dc:date>2022-12-13T15:17:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to get first logout after login?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-first-logout-after-login/m-p/624163#M216995</link>
      <description>&lt;P&gt;Here's a solution that uses the &lt;FONT face="courier new,courier"&gt;transaction&lt;/FONT&gt; command.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;&amp;lt;your search for events&amp;gt;&amp;gt;
| transaction user startswith="login" endswith="logout" keeporphans=1
| eval login_date=mvindex(date,0), logout_date=mvindex(date, 1)
| table login_date, logout_date, user&lt;/LI-CODE&gt;&lt;P&gt;Perhaps someone else can suggest a solution that does not use the hated &lt;FONT face="courier new,courier"&gt;transaction&lt;/FONT&gt; command.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Dec 2022 16:30:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-first-logout-after-login/m-p/624163#M216995</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2022-12-13T16:30:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to get first logout after login?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-first-logout-after-login/m-p/624229#M217029</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/213957"&gt;@richgalloway&lt;/a&gt;&amp;nbsp;, i tried your suggest.&lt;/P&gt;&lt;P&gt;But the result is wrong:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2022-12-14 at 14.34.34.png" style="width: 999px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/23002i2205C4B5EED8061A/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2022-12-14 at 14.34.34.png" alt="Screenshot 2022-12-14 at 14.34.34.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And i tried this search (this query is too complex, there may be a shorter and safer solution):&lt;/P&gt;&lt;PRE&gt;sourcetype="vpn_duration"&lt;BR /&gt;|reverse&lt;BR /&gt;|eval c1=1&lt;BR /&gt;|streamstats sum(c1) as sum by user,action&lt;BR /&gt;|eval session_id=user+"@@"+sum&lt;BR /&gt;|table date,session_id,action&lt;BR /&gt;|stats list(date) as date_list,list(action) by session_id&lt;BR /&gt;|eval login_date=mvindex(date_list,0), logout_date=mvindex(date_list,-1)&lt;BR /&gt;|eval session_id_temp=split(session_id,"@@")&lt;BR /&gt;|eval username=mvindex(session_id_temp,0)&lt;BR /&gt;|table username,login_date,logout_date&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;Result:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2022-12-14 at 14.39.09.png" style="width: 999px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/23003i67EC57D2E583A010/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2022-12-14 at 14.39.09.png" alt="Screenshot 2022-12-14 at 14.39.09.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Dec 2022 11:52:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-first-logout-after-login/m-p/624229#M217029</guid>
      <dc:creator>alissan</dc:creator>
      <dc:date>2022-12-14T11:52:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to get first logout after login?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-first-logout-after-login/m-p/624237#M217032</link>
      <description>&lt;P&gt;Try again without the &lt;FONT face="courier new,courier"&gt;reverse&lt;/FONT&gt; command.&amp;nbsp; The &lt;FONT face="courier new,courier"&gt;transaction&lt;/FONT&gt; command makes assumptions about the order of events and &lt;FONT face="courier new,courier"&gt;reverse&lt;/FONT&gt; messes with that.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Dec 2022 13:40:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-first-logout-after-login/m-p/624237#M217032</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2022-12-14T13:40:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to get first logout after login?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-first-logout-after-login/m-p/624243#M217035</link>
      <description>&lt;P&gt;It's works. Thank you.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Dec 2022 14:35:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-first-logout-after-login/m-p/624243#M217035</guid>
      <dc:creator>alissan</dc:creator>
      <dc:date>2022-12-14T14:35:43Z</dc:date>
    </item>
  </channel>
</rss>

