<?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: User login in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/User-login/m-p/565156#M196889</link>
    <description>&lt;P&gt;I thought about this one for a while and the elegant solution eluded me (I had some horrible ideas with table/transpose and the running foreach... yuck).&lt;/P&gt;&lt;P&gt;But then I had an epiphany &lt;span class="lia-unicode-emoji" title=":rolling_on_the_floor_laughing:"&gt;🤣&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I was focusing too much on events in their natural order whereas the key to do it properly is sorting.&lt;/P&gt;&lt;P&gt;Firstly, you do&lt;/P&gt;&lt;PRE&gt;| sort user + _time&lt;/PRE&gt;&lt;P&gt;So you have batches of events concerning the same user sorted by time.&lt;/P&gt;&lt;P&gt;Now we need to find a way to get the time of the previous login. Luckily, Splunk has a nice feature called autoregress which copies a value of a field from previous event(s).&lt;/P&gt;&lt;P&gt;So we copy the previous login time (and user to filter out moments in which we switch from one user to another).&lt;/P&gt;&lt;PRE&gt;| autoregress _time as oldtime p=1 | autoregress user as olduser&lt;/PRE&gt;&lt;P&gt;Now we have all the data needed to find our culprits&lt;/P&gt;&lt;PRE&gt;| where user=olduser AND _time-oldtime&amp;gt;90*86400&lt;/PRE&gt;&lt;P&gt;And voila, you have your logins after long period of inactivity. As a bonus you also have the time of previous login (although it could use some formating &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Sat, 28 Aug 2021 20:18:16 GMT</pubDate>
    <dc:creator>PickleRick</dc:creator>
    <dc:date>2021-08-28T20:18:16Z</dc:date>
    <item>
      <title>User login</title>
      <link>https://community.splunk.com/t5/Splunk-Search/User-login/m-p/565140#M196883</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;A newbie to Splunk here. I have found the query for&amp;nbsp; login info for users on a host:&amp;nbsp;&lt;/P&gt;&lt;P&gt;index=os&amp;nbsp; source=var/log/secure&amp;nbsp; host=myhost process=sshd&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to trigger an alert if a user&amp;nbsp; who has logged in before,&amp;nbsp; logs in to the host after more than 90 days. Could someone please help me how to write a query .&amp;nbsp;&lt;/P&gt;&lt;P&gt;So the user should not have logged in for more than 90 days on the host.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 28 Aug 2021 10:33:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/User-login/m-p/565140#M196883</guid>
      <dc:creator>RanjithaN99</dc:creator>
      <dc:date>2021-08-28T10:33:20Z</dc:date>
    </item>
    <item>
      <title>Re: User login</title>
      <link>https://community.splunk.com/t5/Splunk-Search/User-login/m-p/565141#M196884</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/237871"&gt;@RanjithaN99&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;you could run a search like this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=os  source=var/log/secure  host=myhost process=sshd earliest=-180d@d latest=now
| transaction user maxevents=2
| eval duration=duration/86400
| where duration&amp;gt;90 OR eventcount=1&lt;/LI-CODE&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;</description>
      <pubDate>Sat, 28 Aug 2021 10:42:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/User-login/m-p/565141#M196884</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2021-08-28T10:42:27Z</dc:date>
    </item>
    <item>
      <title>Re: User login</title>
      <link>https://community.splunk.com/t5/Splunk-Search/User-login/m-p/565142#M196885</link>
      <description>&lt;P&gt;Thank you so much. Really helped me!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 28 Aug 2021 11:13:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/User-login/m-p/565142#M196885</guid>
      <dc:creator>RanjithaN99</dc:creator>
      <dc:date>2021-08-28T11:13:19Z</dc:date>
    </item>
    <item>
      <title>Re: User login</title>
      <link>https://community.splunk.com/t5/Splunk-Search/User-login/m-p/565144#M196886</link>
      <description>&lt;P&gt;Correct me if I'm wrong but this way you'll miss sequences of events like this:&lt;/P&gt;&lt;P&gt;- login at day 2 (transaction starts here)&lt;/P&gt;&lt;P&gt;- login at day 14 (transaction ends here)&lt;/P&gt;&lt;P&gt;- login at day 123 (new transaction ends here)&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;</description>
      <pubDate>Sat, 28 Aug 2021 12:21:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/User-login/m-p/565144#M196886</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2021-08-28T12:21:00Z</dc:date>
    </item>
    <item>
      <title>Re: User login</title>
      <link>https://community.splunk.com/t5/Splunk-Search/User-login/m-p/565156#M196889</link>
      <description>&lt;P&gt;I thought about this one for a while and the elegant solution eluded me (I had some horrible ideas with table/transpose and the running foreach... yuck).&lt;/P&gt;&lt;P&gt;But then I had an epiphany &lt;span class="lia-unicode-emoji" title=":rolling_on_the_floor_laughing:"&gt;🤣&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I was focusing too much on events in their natural order whereas the key to do it properly is sorting.&lt;/P&gt;&lt;P&gt;Firstly, you do&lt;/P&gt;&lt;PRE&gt;| sort user + _time&lt;/PRE&gt;&lt;P&gt;So you have batches of events concerning the same user sorted by time.&lt;/P&gt;&lt;P&gt;Now we need to find a way to get the time of the previous login. Luckily, Splunk has a nice feature called autoregress which copies a value of a field from previous event(s).&lt;/P&gt;&lt;P&gt;So we copy the previous login time (and user to filter out moments in which we switch from one user to another).&lt;/P&gt;&lt;PRE&gt;| autoregress _time as oldtime p=1 | autoregress user as olduser&lt;/PRE&gt;&lt;P&gt;Now we have all the data needed to find our culprits&lt;/P&gt;&lt;PRE&gt;| where user=olduser AND _time-oldtime&amp;gt;90*86400&lt;/PRE&gt;&lt;P&gt;And voila, you have your logins after long period of inactivity. As a bonus you also have the time of previous login (although it could use some formating &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 28 Aug 2021 20:18:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/User-login/m-p/565156#M196889</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2021-08-28T20:18:16Z</dc:date>
    </item>
    <item>
      <title>Re: User login</title>
      <link>https://community.splunk.com/t5/Splunk-Search/User-login/m-p/565172#M196895</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/231884"&gt;@PickleRick&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;you spoke of loging with an interval greater than 90 days, you didn't spoke ok start and end transaction.&lt;/P&gt;&lt;P&gt;How is it possible to identify start and end transaction?&lt;/P&gt;&lt;P&gt;Using those strings you can use the same method adding startswith and endswith options on transaction command.&lt;/P&gt;&lt;P&gt;so if in the starting transaction there's the string "start" and in the ending transaction there's the string "end", you could try something like this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=os  source=var/log/secure  host=myhost process=sshd earliest=-180d@d latest=now
| transaction user maxevents=2 startswith="start" endswith="end"
| eval duration=duration/86400
| where duration&amp;gt;90 OR eventcount=1&lt;/LI-CODE&gt;&lt;P&gt;for more infos see the command transaction (&lt;A href="https://docs.splunk.com/Documentation/Splunk/8.2.2/SearchReference/Transaction" target="_blank"&gt;https://docs.splunk.com/Documentation/Splunk/8.2.2/SearchReference/Transaction&lt;/A&gt;).&lt;/P&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;</description>
      <pubDate>Sun, 29 Aug 2021 16:24:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/User-login/m-p/565172#M196895</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2021-08-29T16:24:46Z</dc:date>
    </item>
    <item>
      <title>Re: User login</title>
      <link>https://community.splunk.com/t5/Splunk-Search/User-login/m-p/565201#M196909</link>
      <description>&lt;P&gt;I don't know why you assume that there needs to be a transaction.&lt;/P&gt;&lt;P&gt;And you keep misunderstanding the question.&lt;/P&gt;&lt;P&gt;There are no separate types of events to detect.&lt;/P&gt;&lt;P&gt;As I wrote earlier, let's assume you have a sequence of login events:&lt;/P&gt;&lt;P&gt;Day ,User&lt;BR /&gt;1,user1&lt;BR /&gt;2,user1&lt;BR /&gt;13,user2&lt;BR /&gt;14,user3&lt;BR /&gt;27,user1&lt;BR /&gt;40,user1&lt;BR /&gt;51,user2&lt;BR /&gt;54,user3&lt;BR /&gt;72,user2&lt;BR /&gt;82,user3&lt;BR /&gt;101,user2&lt;BR /&gt;110,user3&lt;BR /&gt;140,user1&lt;/P&gt;&lt;P&gt;The original poster's question was how to detect events like user1's login at day 140 (since previous login was over 90 ays earlier). Your transaction-based solution won't do:&lt;/P&gt;&lt;PRE&gt;| makeresults&lt;BR /&gt;| eval _raw="Day,User&lt;BR /&gt;1,user1&lt;BR /&gt;2,user1&lt;BR /&gt;13,user2&lt;BR /&gt;14,user3&lt;BR /&gt;27,user1&lt;BR /&gt;40,user1&lt;BR /&gt;51,user2&lt;BR /&gt;54,user3&lt;BR /&gt;72,user2&lt;BR /&gt;82,user3&lt;BR /&gt;101,user2&lt;BR /&gt;110,user3&lt;BR /&gt;140,user1" &lt;BR /&gt;| multikv noheader=f &lt;BR /&gt;| fields Day User&lt;BR /&gt;| transaction User maxevents=2 &lt;BR /&gt;| table Day User&lt;/PRE&gt;&lt;P&gt;It results with:&lt;/P&gt;&lt;PRE&gt;Day,User&lt;BR /&gt;"1 2",user1&lt;BR /&gt;"13 51",user2&lt;BR /&gt;"14 54",user3&lt;BR /&gt;"27 40",user1&lt;BR /&gt;140,user1&lt;BR /&gt;"110 82",user3&lt;BR /&gt;"101 72",user2&lt;/PRE&gt;&lt;P&gt;As you can see, we miss the user1's login at day 140 completely.&lt;/P&gt;&lt;P&gt;Transaction won't do because it just measures separate non-overlapping periods whereas we need a sliding window.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Aug 2021 07:25:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/User-login/m-p/565201#M196909</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2021-08-30T07:25:55Z</dc:date>
    </item>
  </channel>
</rss>

