<?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: Updating fields in a lookup through a scheduled search in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Updating-fields-in-a-lookup-through-a-scheduled-search/m-p/215999#M63359</link>
    <description>&lt;P&gt;If you are willing to write some code, I think that the KV store might be an even better alternative, since it supports direct update operations.&lt;/P&gt;</description>
    <pubDate>Thu, 14 Jan 2016 23:58:25 GMT</pubDate>
    <dc:creator>lguinn2</dc:creator>
    <dc:date>2016-01-14T23:58:25Z</dc:date>
    <item>
      <title>Updating fields in a lookup through a scheduled search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Updating-fields-in-a-lookup-through-a-scheduled-search/m-p/215996#M63356</link>
      <description>&lt;P&gt;Fellow Splunkers!&lt;/P&gt;

&lt;P&gt;I am attempting to update fields within a lookup file, and fortunatley there are only 2 fields. I am in attempt to keep track of last login time to a system, which equates to &lt;CODE&gt;user&lt;/CODE&gt; and &lt;CODE&gt;login&lt;/CODE&gt; in a lookup table. &lt;/P&gt;

&lt;P&gt;Here is my search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=myIndex sourcetype=mySourcetype eventtype=userLogin | stats latest(_time) as "login" by user | eval login=login | convert ctime(login) as login | outputlookup login servers_logins.csv
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;EM&gt;sometimes&lt;/EM&gt; the user column will need to be appended with a new user, but mostly it will just be the login time that needs updated. &lt;/P&gt;

&lt;P&gt;We are trying to keep history of when a user logs in for a couple years by appending this file, and use it to disabled inactive accounts. &lt;BR /&gt;
I've read this &lt;A href="https://answers.splunk.com/answers/71011/update-a-single-field-in-lookup-table-from-a-search.html"&gt;answer&lt;/A&gt;, though I can't seem to get this to work for me as i've tried it above. &lt;/P&gt;

&lt;P&gt;I know after I get this right, I can just schedule this search to run everyday in order to keep it up to date.&lt;/P&gt;

&lt;P&gt;Any help would be greatly appreciated&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jan 2016 17:52:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Updating-fields-in-a-lookup-through-a-scheduled-search/m-p/215996#M63356</guid>
      <dc:creator>tmarlette</dc:creator>
      <dc:date>2016-01-06T17:52:35Z</dc:date>
    </item>
    <item>
      <title>Re: Updating fields in a lookup through a scheduled search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Updating-fields-in-a-lookup-through-a-scheduled-search/m-p/215997#M63357</link>
      <description>&lt;P&gt;This is a common problem, and the solution isn't necessarily intuitive. Here is what I would do:&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;First load your lookup with &lt;CODE&gt;inputlookup&lt;/CODE&gt; - this is necessary if we want to ever &lt;EM&gt;update&lt;/EM&gt; our existing data.&lt;/LI&gt;
&lt;LI&gt;Run the search you want to generate the data and append it, or conversely, run the search, and append the lookup. The ordering doesn't matter.&lt;/LI&gt;
&lt;LI&gt;Get the latest value of login and once again split by user with &lt;CODE&gt;stats&lt;/CODE&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;P&gt;Use outputlookup to save the reuslts&lt;/P&gt;

&lt;P&gt;inputlookup server_logins.csv &lt;BR /&gt;
| append&lt;BR /&gt;
    [search index=myIndex sourcetype=mySourcetype eventtype=userLogin &lt;BR /&gt;
    | stats latest(_time) as "login" by user &lt;BR /&gt;
    | eval login=login &lt;BR /&gt;
    | convert ctime(login) as login ] &lt;BR /&gt;
| stats latest(login) as login by user&lt;BR /&gt;
| outputlookup server_logins.csv&lt;BR /&gt;
Now you can just schedule the search to run as often as you would like - adding &lt;CODE&gt;earliest&lt;/CODE&gt; and &lt;CODE&gt;latest&lt;/CODE&gt; to match. &lt;/P&gt;&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Tue, 29 Sep 2020 08:20:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Updating-fields-in-a-lookup-through-a-scheduled-search/m-p/215997#M63357</guid>
      <dc:creator>aljohnson_splun</dc:creator>
      <dc:date>2020-09-29T08:20:25Z</dc:date>
    </item>
    <item>
      <title>Re: Updating fields in a lookup through a scheduled search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Updating-fields-in-a-lookup-through-a-scheduled-search/m-p/215998#M63358</link>
      <description>&lt;P&gt;In similar situations I do something that is comparable to what aljohnson posted but I don't use the append command. Rather I leverage that ability within the lookup command itself.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;search | format with table | inputlookup append=t server_logins.csv | stats max(your time field name) by user | outputlookup server_logins.csv
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;While not needed for this use case you can take this a step further to purge old entries on lookups within the same search. For example if you wanted to dump users from this list after, say, 30 days you could something like&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;search | format with table | inputlookup append=t server_logins.csv | stats max(your time field name) by user | eval current_time = now() | where login_time &amp;gt; (current_time - (86400 * 30)) | outputlookup server_logins.csv
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Jan 2016 12:51:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Updating-fields-in-a-lookup-through-a-scheduled-search/m-p/215998#M63358</guid>
      <dc:creator>Runals</dc:creator>
      <dc:date>2016-01-07T12:51:28Z</dc:date>
    </item>
    <item>
      <title>Re: Updating fields in a lookup through a scheduled search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Updating-fields-in-a-lookup-through-a-scheduled-search/m-p/215999#M63359</link>
      <description>&lt;P&gt;If you are willing to write some code, I think that the KV store might be an even better alternative, since it supports direct update operations.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jan 2016 23:58:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Updating-fields-in-a-lookup-through-a-scheduled-search/m-p/215999#M63359</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2016-01-14T23:58:25Z</dc:date>
    </item>
  </channel>
</rss>

