<?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: Query For Earliest Logon and Latest Log Offs in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Query-For-Earliest-Logon-and-Latest-Log-Offs/m-p/483267#M193312</link>
    <description>&lt;P&gt;If you assume that no logon/logoff sequence will cross a midnight boundary, then...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... your base search here .. index=blah sourcetype=blah
| stats first(_time) as earliest_logon first(ComputerName) as earliest_logon_machine last(_time) as latest_logon last(ComputerName) as latest_logon_machine BY username, date_day
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;As you can imagine, you've left a lot to be desired about most of your search, the fields and so on, but hopefully this gets you on your way.&lt;/P&gt;

&lt;P&gt;Happy Splunking,&lt;BR /&gt;
Rich&lt;/P&gt;</description>
    <pubDate>Tue, 17 Sep 2019 17:47:53 GMT</pubDate>
    <dc:creator>Richfez</dc:creator>
    <dc:date>2019-09-17T17:47:53Z</dc:date>
    <item>
      <title>Query For Earliest Logon and Latest Log Offs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Query-For-Earliest-Logon-and-Latest-Log-Offs/m-p/483265#M193310</link>
      <description>&lt;P&gt;Hello! I need to build a Splunk query that displays the earliest log on and and latest log off times for a user in the same table / chart over the span of 60 days - and let's use Event ID 4624 for log on's and Event ID 4634 for log off's. So here is an example, let's say user John Doe first logged in today at 8am and last logged off at 5pm. I would want the following to be displayed: &lt;/P&gt;

&lt;P&gt;(Day)     (Earliest Logon Time)      (Computer Name for Earliest Logon)      (Latest Log Off Time)       (Computer Name for Latest Log Off)&lt;BR /&gt;
09/17         8am                                        WindowsPC-25                                           5pm                                            WindowsPC-25&lt;BR /&gt;
09/18         8:30am                                     Laptop-25                                                 6pm                                                Laptop-25&lt;BR /&gt;
09/19&lt;BR /&gt;
etc...&lt;BR /&gt;
etc...&lt;/P&gt;</description>
      <pubDate>Tue, 17 Sep 2019 16:11:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Query-For-Earliest-Logon-and-Latest-Log-Offs/m-p/483265#M193310</guid>
      <dc:creator>johann2017</dc:creator>
      <dc:date>2019-09-17T16:11:31Z</dc:date>
    </item>
    <item>
      <title>Re: Query For Earliest Logon and Latest Log Offs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Query-For-Earliest-Logon-and-Latest-Log-Offs/m-p/483266#M193311</link>
      <description>&lt;P&gt;there are tons of answers around this topic in this channel, also, looking on all login logout data for 60 days can become pretty lengthy&lt;/P&gt;

&lt;P&gt;itll be something like this, assuming the user field is &lt;CODE&gt;user&lt;/CODE&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=win*  sourcetype="WinEventLog:security" (EventCode=4634 OR EventCode=4624) user!=*$
| stats min(_time) as first_event max(_time) as last_event by EventCode user
| eval login_first=if(EventCode==4624,first_event,null())
| eval logoff_last=if(EventCode==4634,last_event,null())
| stats values(login_first) as login_first values(logoff_last) as logoff_last by user
| eval length_in_system_sec = logoff_last - login_first
| eval logoff_last_human = strftime(logoff_last, "%c")
| eval logon_first_human = strftime(login_first, "%c")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;hope it helps&lt;/P&gt;</description>
      <pubDate>Tue, 17 Sep 2019 17:36:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Query-For-Earliest-Logon-and-Latest-Log-Offs/m-p/483266#M193311</guid>
      <dc:creator>adonio</dc:creator>
      <dc:date>2019-09-17T17:36:21Z</dc:date>
    </item>
    <item>
      <title>Re: Query For Earliest Logon and Latest Log Offs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Query-For-Earliest-Logon-and-Latest-Log-Offs/m-p/483267#M193312</link>
      <description>&lt;P&gt;If you assume that no logon/logoff sequence will cross a midnight boundary, then...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... your base search here .. index=blah sourcetype=blah
| stats first(_time) as earliest_logon first(ComputerName) as earliest_logon_machine last(_time) as latest_logon last(ComputerName) as latest_logon_machine BY username, date_day
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;As you can imagine, you've left a lot to be desired about most of your search, the fields and so on, but hopefully this gets you on your way.&lt;/P&gt;

&lt;P&gt;Happy Splunking,&lt;BR /&gt;
Rich&lt;/P&gt;</description>
      <pubDate>Tue, 17 Sep 2019 17:47:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Query-For-Earliest-Logon-and-Latest-Log-Offs/m-p/483267#M193312</guid>
      <dc:creator>Richfez</dc:creator>
      <dc:date>2019-09-17T17:47:53Z</dc:date>
    </item>
    <item>
      <title>Re: Query For Earliest Logon and Latest Log Offs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Query-For-Earliest-Logon-and-Latest-Log-Offs/m-p/483268#M193313</link>
      <description>&lt;P&gt;To be more specific, I will be using this for one user. So I only need to plug in one username at a time for this search. &lt;/P&gt;</description>
      <pubDate>Tue, 17 Sep 2019 19:14:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Query-For-Earliest-Logon-and-Latest-Log-Offs/m-p/483268#M193313</guid>
      <dc:creator>johann2017</dc:creator>
      <dc:date>2019-09-17T19:14:08Z</dc:date>
    </item>
    <item>
      <title>Re: Query For Earliest Logon and Latest Log Offs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Query-For-Earliest-Logon-and-Latest-Log-Offs/m-p/483269#M193314</link>
      <description>&lt;P&gt;add the name to the search after &lt;CODE&gt;user=&lt;/CODE&gt; if the field is indeed &lt;CODE&gt;user&lt;/CODE&gt; or you can just put the name string in the search ...&lt;/P&gt;</description>
      <pubDate>Tue, 17 Sep 2019 19:28:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Query-For-Earliest-Logon-and-Latest-Log-Offs/m-p/483269#M193314</guid>
      <dc:creator>adonio</dc:creator>
      <dc:date>2019-09-17T19:28:50Z</dc:date>
    </item>
    <item>
      <title>Re: Query For Earliest Logon and Latest Log Offs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Query-For-Earliest-Logon-and-Latest-Log-Offs/m-p/483270#M193315</link>
      <description>&lt;P&gt;It works for me, but I was unable to figure out how to add the computer name to it.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Sep 2019 21:42:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Query-For-Earliest-Logon-and-Latest-Log-Offs/m-p/483270#M193315</guid>
      <dc:creator>cboillot</dc:creator>
      <dc:date>2019-09-17T21:42:53Z</dc:date>
    </item>
    <item>
      <title>Re: Query For Earliest Logon and Latest Log Offs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Query-For-Earliest-Logon-and-Latest-Log-Offs/m-p/483271#M193316</link>
      <description>&lt;P&gt;Also, for one of the times it gave me the time in seconds instead of hours:minutes:seconds.. how would I fix that&lt;/P&gt;</description>
      <pubDate>Tue, 17 Sep 2019 22:10:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Query-For-Earliest-Logon-and-Latest-Log-Offs/m-p/483271#M193316</guid>
      <dc:creator>johann2017</dc:creator>
      <dc:date>2019-09-17T22:10:03Z</dc:date>
    </item>
    <item>
      <title>Re: Query For Earliest Logon and Latest Log Offs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Query-For-Earliest-Logon-and-Latest-Log-Offs/m-p/483272#M193317</link>
      <description>&lt;P&gt;just add the field that represent computer name in the query after the &lt;CODE&gt;by&lt;/CODE&gt; clause in every &lt;CODE&gt;stats&lt;/CODE&gt; line &lt;BR /&gt;
also here is the duration in Hours Minutes Seconds and Days&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=win*  sourcetype="WinEventLog:security" (EventCode=4634 OR EventCode=4624) 
| stats min(_time) as first_event max(_time) as last_event by EventCode user ComputerName
| eval login_first=if(EventCode==4624,first_event,null())
| eval logoff_last=if(EventCode==4634,last_event,null())
| stats values(login_first) as login_first values(logoff_last) as logoff_last by user ComputerName
| eval duration_in_system_sec = logoff_last - login_first
| eval logoff_last_human = strftime(logoff_last, "%c")
| eval logon_first_human = strftime(login_first, "%c")
| eval duration_human = tostring(duration_in_system_sec, "duration")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 17 Sep 2019 23:53:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Query-For-Earliest-Logon-and-Latest-Log-Offs/m-p/483272#M193317</guid>
      <dc:creator>adonio</dc:creator>
      <dc:date>2019-09-17T23:53:16Z</dc:date>
    </item>
  </channel>
</rss>

