<?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: Input CSV and run search against subset of users in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Input-CSV-and-run-search-against-subset-of-users/m-p/377157#M68255</link>
    <description>&lt;P&gt;Great! Glad it's working. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 15 May 2018 03:06:21 GMT</pubDate>
    <dc:creator>elliotproebstel</dc:creator>
    <dc:date>2018-05-15T03:06:21Z</dc:date>
    <item>
      <title>Input CSV and run search against subset of users</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Input-CSV-and-run-search-against-subset-of-users/m-p/377151#M68249</link>
      <description>&lt;P&gt;I have a list of accounts that I wish to monitor in a csv file, say accounts.csv.&lt;/P&gt;

&lt;P&gt;The file looks like:&lt;BR /&gt;
userid,username&lt;BR /&gt;
joeuser,Joe User&lt;BR /&gt;
jimuser,Jim User&lt;BR /&gt;
Janeuser,Jane User&lt;/P&gt;

&lt;P&gt;And the logs are in the format of:&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;operation&lt;/STRONG&gt;=openedfile &lt;BR /&gt;
&lt;STRONG&gt;UserId&lt;/STRONG&gt;=&lt;A href="mailto:joeuser@domain.com" target="_blank"&gt;joeuser@domain.com&lt;/A&gt;&lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;so i need to compare the CSVs userid field to the UserId (stripping away the @ so they are the same).&lt;/P&gt;

&lt;P&gt;I would like to produce a table showing all the accounts in the csv file and when they performed an activity (or what the activity was). &lt;/P&gt;

&lt;P&gt;The trick is to create a table that shows all users in the CSV (not all that were found in the search - just the CSV), whether or not they performed an action. If they never did anything, then the last_activity field would be blank (or some message like "not logged in"). I can get close by doing something like:&lt;/P&gt;

&lt;P&gt;index=unix_security&lt;BR /&gt;
| dedup userid&lt;BR /&gt;
| rename _time as last_login&lt;BR /&gt;
| append [inputlookup accounts.csv]&lt;BR /&gt;
| table userid name department last_login&lt;BR /&gt;
| sort -userid&lt;/P&gt;

&lt;P&gt;I believe I need to do a join somehow, but I can't seem to get the syntax right, I'm stilling learning this.&lt;/P&gt;

&lt;P&gt;If anyone can provide some pointers that would be greatly appreciated.&lt;/P&gt;

&lt;P&gt;Thanks!&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;EDIT&lt;/STRONG&gt; &lt;BR /&gt;
I found this but can't seem to make the answer work as my userid from my events &amp;amp; csv are a bit different. &lt;/P&gt;

&lt;P&gt;&lt;A href="https://answers.splunk.com/answers/589551/get-last-login-time-based-upon-a-list-of-accounts-1.html" target="_blank"&gt;https://answers.splunk.com/answers/589551/get-last-login-time-based-upon-a-list-of-accounts-1.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 19:22:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Input-CSV-and-run-search-against-subset-of-users/m-p/377151#M68249</guid>
      <dc:creator>cewing082</dc:creator>
      <dc:date>2020-09-29T19:22:53Z</dc:date>
    </item>
    <item>
      <title>Re: Input CSV and run search against subset of users</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Input-CSV-and-run-search-against-subset-of-users/m-p/377152#M68250</link>
      <description>&lt;P&gt;You don't mention where the field &lt;CODE&gt;department&lt;/CODE&gt; comes from (the csv file or the events), so I'm going to assume it's in the csv file. This will need some slight adjustment if &lt;CODE&gt;department&lt;/CODE&gt; is in the base events.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=unix_security 
    [| inputlookup accounts.csv 
    | fields userid 
    | eval userid=userid."@*"] 
| stats latest(_time) AS last_login BY userid 
| rex field=userid "^(?&amp;lt;userid&amp;gt;[^@]+)"
| append [| inputlookup accounts.csv | eval last_login=0 ]
| stats max(last_login) AS last_login, latest(username) AS name, latest(department) AS department BY userid
| sort - userid
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;As you mentioned that you're still learning, I'll walk through it, chunk by chunk.  First, we gather events relating only to the users in the csv by using a subsearch to gather the &lt;CODE&gt;userid&lt;/CODE&gt; values and adding &lt;CODE&gt;"@*"&lt;/CODE&gt; to the end of each one, as you mentioned that the raw events contain the full email address but the csv file contains the username (portion of the email before the @ sign). If all the userids belong to the same domain, you might replace &lt;CODE&gt;"@*"&lt;/CODE&gt; with &lt;CODE&gt;"@yourdomain.com"&lt;/CODE&gt; or whatnot.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=unix_security 
    [| inputlookup accounts.csv 
    | fields userid 
    | eval userid=userid."@*"] 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;After that, I replaced your &lt;CODE&gt;dedup&lt;/CODE&gt; command with this stats call:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats latest(_time) AS last_login BY userid 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This more efficiently returns the latest value of _time for each userid, which also dedups the results.  I next truncate the userid values from the raw events:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex field=userid "^(?&amp;lt;userid&amp;gt;[^@]+)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then I append in the whole list from the csv, and add &lt;CODE&gt;last_login=0&lt;/CODE&gt; to each user so that this call:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats max(last_login) AS last_login, latest(username) AS name, latest(department) AS department BY userid
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;can either preserve the 0 (if the user was not seen in the raw events) or carry through the last_login value from the events. This also preserves the username and department if they were in the csv. If you need to extract them from the raw events, you'll need to add &lt;CODE&gt;latest(username) AS name, latest(department) AS department&lt;/CODE&gt; to the first stats call, as well.  Finally, I preserve the sorting you intended:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| sort - userid
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I hope this is helpful!&lt;/P&gt;</description>
      <pubDate>Tue, 08 May 2018 17:50:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Input-CSV-and-run-search-against-subset-of-users/m-p/377152#M68250</guid>
      <dc:creator>elliotproebstel</dc:creator>
      <dc:date>2018-05-08T17:50:52Z</dc:date>
    </item>
    <item>
      <title>Re: Input CSV and run search against subset of users</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Input-CSV-and-run-search-against-subset-of-users/m-p/377153#M68251</link>
      <description>&lt;P&gt;I'm trying to run this and it's not returning any results, i think the problem lies here (?)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index=unix_security 
     [| inputlookup accounts.csv 
     | fields userid 
     | eval userid=userid."@*"] 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;my csv contains userids but my events actually contain full email address (userid@domain) &lt;/P&gt;</description>
      <pubDate>Tue, 08 May 2018 20:26:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Input-CSV-and-run-search-against-subset-of-users/m-p/377153#M68251</guid>
      <dc:creator>cewing082</dc:creator>
      <dc:date>2018-05-08T20:26:05Z</dc:date>
    </item>
    <item>
      <title>Re: Input CSV and run search against subset of users</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Input-CSV-and-run-search-against-subset-of-users/m-p/377154#M68252</link>
      <description>&lt;P&gt;This line should be accounting for that:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval userid=userid."@*"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That should transform a userid from the csv file, such as &lt;CODE&gt;jsmith&lt;/CODE&gt; and turn it into &lt;CODE&gt;jsmith@*&lt;/CODE&gt;. So then the result of this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=unix_security 
    [| inputlookup accounts.csv 
    | fields userid 
    | eval userid=userid."@*"] 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;would be a search like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=unix_security (userid="jsmith@*" OR userid="dburns@*" OR userid="alews@*" ...)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But of course I believe you when you say it's not working, so let's start with this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| inputlookup accounts.csv 
| fields userid 
| eval userid=userid."@*"
| format
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Does that return something like &lt;CODE&gt;userid="jsmith@*" OR userid="dburns@*" OR userid="alews@*" ...&lt;/CODE&gt;?&lt;BR /&gt;
If so, then you could manually troubleshoot by running this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index=unix_security 
| stats latest(_time) AS last_login BY userid 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;See if the list of &lt;CODE&gt;userid&lt;/CODE&gt; values contains users from the csv - and, in particular, users whose &lt;CODE&gt;userid&lt;/CODE&gt; values match that pattern of &lt;CODE&gt;jsmith@*&lt;/CODE&gt;, etc. Let me know if you find the discrepancy, and I can help you adjust the search as needed.&lt;/P&gt;</description>
      <pubDate>Wed, 09 May 2018 14:22:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Input-CSV-and-run-search-against-subset-of-users/m-p/377154#M68252</guid>
      <dc:creator>elliotproebstel</dc:creator>
      <dc:date>2018-05-09T14:22:17Z</dc:date>
    </item>
    <item>
      <title>Re: Input CSV and run search against subset of users</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Input-CSV-and-run-search-against-subset-of-users/m-p/377155#M68253</link>
      <description>&lt;P&gt;Any luck on this? Do you still want some help?&lt;/P&gt;</description>
      <pubDate>Mon, 14 May 2018 15:20:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Input-CSV-and-run-search-against-subset-of-users/m-p/377155#M68253</guid>
      <dc:creator>elliotproebstel</dc:creator>
      <dc:date>2018-05-14T15:20:13Z</dc:date>
    </item>
    <item>
      <title>Re: Input CSV and run search against subset of users</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Input-CSV-and-run-search-against-subset-of-users/m-p/377156#M68254</link>
      <description>&lt;P&gt;You're the man - thanks so much. This got me exactly where I wanted to be!&lt;/P&gt;</description>
      <pubDate>Mon, 14 May 2018 16:19:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Input-CSV-and-run-search-against-subset-of-users/m-p/377156#M68254</guid>
      <dc:creator>cewing082</dc:creator>
      <dc:date>2018-05-14T16:19:59Z</dc:date>
    </item>
    <item>
      <title>Re: Input CSV and run search against subset of users</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Input-CSV-and-run-search-against-subset-of-users/m-p/377157#M68255</link>
      <description>&lt;P&gt;Great! Glad it's working. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 15 May 2018 03:06:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Input-CSV-and-run-search-against-subset-of-users/m-p/377157#M68255</guid>
      <dc:creator>elliotproebstel</dc:creator>
      <dc:date>2018-05-15T03:06:21Z</dc:date>
    </item>
  </channel>
</rss>

