<?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 do you purge a lookup table of values over 30 days? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-purge-a-lookup-table-of-values-over-30-days/m-p/415300#M119581</link>
    <description>&lt;P&gt;Since some of the old entries in the existing lookup are using the old definition of date_last_seen it wont work with the data math since they are strings. You will need to purge those manually for now. Going forward the date math will take care of everything &lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 23:34:29 GMT</pubDate>
    <dc:creator>pkeenan87</dc:creator>
    <dc:date>2020-09-29T23:34:29Z</dc:date>
    <item>
      <title>How do you purge a lookup table of values over 30 days?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-purge-a-lookup-table-of-values-over-30-days/m-p/415297#M119578</link>
      <description>&lt;P&gt;So I have a search that runs hourly over a lookup table which I have created that includes IP, ticket number, date_added, date_last_seen. Every hour, I search for the IPs on this list across the logs to see the last time we have seen the IP. I currently use the below search to achieve this, which may not be the simplest way for me to do this.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=blah| lookup suspicious_list.csv suspect_ip as src_ip OUTPUT Ticket_num date_added date_last_seen | search Ticket_num="*" | rename src_ip as suspect_ip | eval time=strftime(_time, "%H:%M:%S %m-%d-%y") | eval date_last_seen=time | table suspect_ip, Ticket_num, date_added, date_last_seen | inputlookup append=t suspicious_list.csv | dedup suspect_ip | outputlookup suspicious_list.csv
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I would like to have this search remove entries that have a date_last_seen value that is from greater than 30 days ago. I had issues setting this search up to begin with due to the multiple lookups, but I can't seem to figure out the best way to work with comparing the times. I tried something like the following but was not successful. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; sourcetype=blah| lookup suspicious_list.csv suspect_ip as src_ip OUTPUT Ticket_num date_added date_last_seen | search Ticket_num="*" | eval diff=(_time - newt_t) | where diff &amp;lt; 2436985 | rename src_ip as suspect_ip | eval time=strftime(_time, "%H:%M:%S %m-%d-%y") | eval date_last_seen=time | table suspect_ip, Ticket_num, date_added, date_last_seen | inputlookup append=t suspicious_list.csv | dedup suspect_ip | outputlookup suspicious_list.csv
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Sep 2020 23:29:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-purge-a-lookup-table-of-values-over-30-days/m-p/415297#M119578</guid>
      <dc:creator>JakeInfoSec</dc:creator>
      <dc:date>2020-09-29T23:29:48Z</dc:date>
    </item>
    <item>
      <title>Re: How do you purge a lookup table of values over 30 days?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-purge-a-lookup-table-of-values-over-30-days/m-p/415298#M119579</link>
      <description>&lt;P&gt;The relative time function should be useful here: &lt;A href="https://docs.splunk.com/Documentation/Splunk/7.2.4/SearchReference/DateandTimeFunctions#relative_time.28X.2CY.29" target="_blank"&gt;https://docs.splunk.com/Documentation/Splunk/7.2.4/SearchReference/DateandTimeFunctions#relative_time.28X.2CY.29&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Something like this right before your outputlookup command should get rid of all the entries older than thirty days&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=blah
| lookup suspicious_list.csv suspect_ip as src_ip OUTPUT Ticket_num date_added date_last_seen 
| search Ticket_num="*" 
| rename src_ip as suspect_ip 
| eval date_last_seen=_time  
| table suspect_ip, Ticket_num, date_added, date_last_seen 
| inputlookup append=t suspicious_list.csv 
| where date_last_seen &amp;gt; relative_time(now(), "-30d@d")
| outputlookup suspicious_list.csv
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It looks like right now date_last_seen field is a string, keeping it in the numerical format will help us perform the date math&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 23:34:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-purge-a-lookup-table-of-values-over-30-days/m-p/415298#M119579</guid>
      <dc:creator>pkeenan87</dc:creator>
      <dc:date>2020-09-29T23:34:22Z</dc:date>
    </item>
    <item>
      <title>Re: How do you purge a lookup table of values over 30 days?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-purge-a-lookup-table-of-values-over-30-days/m-p/415299#M119580</link>
      <description>&lt;P&gt;Oh wow yeah that relative_time is useful. I still seem to not be getting the correct results that I am looking for, the search still seems to be returning some values that have a date of "22:44:00 11-10-18" and now all my new updated times are in the Unix time format. &lt;/P&gt;

&lt;P&gt;Below is what I am using &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; sourcetype=blah
 | lookup suspicious_list.csv suspect_ip as src_ip OUTPUT Ticket_num date_added date_last_seen 
 | search Ticket_num="*" 
 | rename src_ip as suspect_ip 
 | eval date_last_seen=_time  
 | table suspect_ip, Ticket_num, date_added, date_last_seen 
 | inputlookup append=t suspicious_list.csv 
 | where date_last_seen &amp;gt; relative_time(now(), "-30d@d")
 | dedup SIRT_suspect_identifier
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 05 Mar 2019 21:27:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-purge-a-lookup-table-of-values-over-30-days/m-p/415299#M119580</guid>
      <dc:creator>JakeInfoSec</dc:creator>
      <dc:date>2019-03-05T21:27:54Z</dc:date>
    </item>
    <item>
      <title>Re: How do you purge a lookup table of values over 30 days?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-purge-a-lookup-table-of-values-over-30-days/m-p/415300#M119581</link>
      <description>&lt;P&gt;Since some of the old entries in the existing lookup are using the old definition of date_last_seen it wont work with the data math since they are strings. You will need to purge those manually for now. Going forward the date math will take care of everything &lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 23:34:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-purge-a-lookup-table-of-values-over-30-days/m-p/415300#M119581</guid>
      <dc:creator>pkeenan87</dc:creator>
      <dc:date>2020-09-29T23:34:29Z</dc:date>
    </item>
    <item>
      <title>Re: How do you purge a lookup table of values over 30 days?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-purge-a-lookup-table-of-values-over-30-days/m-p/415301#M119582</link>
      <description>&lt;P&gt;First of all, always store your times as &lt;CODE&gt;time_t&lt;/CODE&gt; values (AKA &lt;CODE&gt;epoch&lt;/CODE&gt;, which is an integer); never as a formatted time.&lt;BR /&gt;
When you pull the data back in, DO NOT convert it with &lt;CODE&gt;eval&lt;/CODE&gt;, instead use &lt;CODE&gt;fieldformat&lt;/CODE&gt; so that when you write it back out, it is still a &lt;CODE&gt;time_t&lt;/CODE&gt;.  Better yet, just keep the time value as &lt;CODE&gt;_time&lt;/CODE&gt; which has an implied &lt;CODE&gt;fieldformat&lt;/CODE&gt; already. This makes the math and other work very easy, like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=foo sourcetype=bar
| other command stuff here
| inputlookup append=t YourLookupHere
| dedup YourByFieldsHere
| where _time &amp;gt;= relative_time(now(), "-30d@d")
| outputlookup YourLookupHere
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Mar 2019 08:13:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-purge-a-lookup-table-of-values-over-30-days/m-p/415301#M119582</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-03-06T08:13:53Z</dc:date>
    </item>
  </channel>
</rss>

