<?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 to write a search to only display entries added in the last 24 hours based on a time field from a lookup CSV file? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-only-display-entries-added-in-the-last/m-p/219355#M64462</link>
    <description>&lt;P&gt;Hey ng87,&lt;/P&gt;

&lt;P&gt;Have you tried using &lt;CODE&gt;relative_time&lt;/CODE&gt;?&lt;/P&gt;

&lt;P&gt;And example of how this could be used(I'll eval them first so you can see the usage):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your search | eval start_time=relative_time(now(), "-24h") | where ((date_added &amp;gt; strftime(start_time, "%Y-%m-%dT%H:%M:%S")) AND (date_added &amp;lt; strftime(now(), "%Y-%m-%dT%H:%M:%S")))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Here's a doc about date and times: &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.4.0/SearchReference/Commontimeformatvariables"&gt;http://docs.splunk.com/Documentation/Splunk/6.4.0/SearchReference/Commontimeformatvariables&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 21 Apr 2016 09:03:35 GMT</pubDate>
    <dc:creator>ktugwell_splunk</dc:creator>
    <dc:date>2016-04-21T09:03:35Z</dc:date>
    <item>
      <title>How to write a search to only display entries added in the last 24 hours based on a time field from a lookup CSV file?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-only-display-entries-added-in-the-last/m-p/219354#M64461</link>
      <description>&lt;P&gt;I have a .csv file as a lookup file that gets updated daily with new records.&lt;/P&gt;

&lt;P&gt;It has a number of fields, one being &lt;STRONG&gt;date_added&lt;/STRONG&gt; (example field format: &lt;CODE&gt;2016-04-17T04:23:40&lt;/CODE&gt;). I am after an easy way to be able to display only the entries added in the last 24 hours (in the ideal world, something like date_added=-24h) .&lt;BR /&gt;
Reason I am after this is I am creating a Splunk report that will take the new entries added to this CSV and then do a subsearch.&lt;/P&gt;

&lt;P&gt;Any ideas how this can be done? &lt;/P&gt;</description>
      <pubDate>Thu, 21 Apr 2016 08:48:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-only-display-entries-added-in-the-last/m-p/219354#M64461</guid>
      <dc:creator>ng87</dc:creator>
      <dc:date>2016-04-21T08:48:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search to only display entries added in the last 24 hours based on a time field from a lookup CSV file?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-only-display-entries-added-in-the-last/m-p/219355#M64462</link>
      <description>&lt;P&gt;Hey ng87,&lt;/P&gt;

&lt;P&gt;Have you tried using &lt;CODE&gt;relative_time&lt;/CODE&gt;?&lt;/P&gt;

&lt;P&gt;And example of how this could be used(I'll eval them first so you can see the usage):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your search | eval start_time=relative_time(now(), "-24h") | where ((date_added &amp;gt; strftime(start_time, "%Y-%m-%dT%H:%M:%S")) AND (date_added &amp;lt; strftime(now(), "%Y-%m-%dT%H:%M:%S")))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Here's a doc about date and times: &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.4.0/SearchReference/Commontimeformatvariables"&gt;http://docs.splunk.com/Documentation/Splunk/6.4.0/SearchReference/Commontimeformatvariables&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Apr 2016 09:03:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-only-display-entries-added-in-the-last/m-p/219355#M64462</guid>
      <dc:creator>ktugwell_splunk</dc:creator>
      <dc:date>2016-04-21T09:03:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search to only display entries added in the last 24 hours based on a time field from a lookup CSV file?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-only-display-entries-added-in-the-last/m-p/219356#M64463</link>
      <description>&lt;P&gt;works a dream!!! cheers mate&lt;/P&gt;</description>
      <pubDate>Thu, 21 Apr 2016 09:14:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-only-display-entries-added-in-the-last/m-p/219356#M64463</guid>
      <dc:creator>ng87</dc:creator>
      <dc:date>2016-04-21T09:14:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search to only display entries added in the last 24 hours based on a time field from a lookup CSV file?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-only-display-entries-added-in-the-last/m-p/219357#M64464</link>
      <description>&lt;P&gt;Hey ng87,&lt;/P&gt;

&lt;P&gt;Have you tried using &lt;CODE&gt;relative_time&lt;/CODE&gt;?&lt;/P&gt;

&lt;P&gt;And example of how this could be used(I'll eval them first so you can see the usage):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your search | eval start_time=relative_time(now(), "-24h") | where ((date_added &amp;gt; strftime(start_time, "%Y-%m-%dT%H:%M:%S")) AND (date_added &amp;lt; strftime(now(), "%Y-%m-%dT%H:%M:%S")))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Here's a doc about date and times: &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.4.0/SearchReference/Commontimeformatvariables"&gt;http://docs.splunk.com/Documentation/Splunk/6.4.0/SearchReference/Commontimeformatvariables&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Apr 2016 09:16:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-only-display-entries-added-in-the-last/m-p/219357#M64464</guid>
      <dc:creator>ktugwell_splunk</dc:creator>
      <dc:date>2016-04-21T09:16:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search to only display entries added in the last 24 hours based on a time field from a lookup CSV file?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-only-display-entries-added-in-the-last/m-p/219358#M64465</link>
      <description>&lt;P&gt;Cool! Glad it worked.&lt;/P&gt;

&lt;P&gt;I've just posted it as the answer, please accept it if you don't mind &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Apr 2016 09:17:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-only-display-entries-added-in-the-last/m-p/219358#M64465</guid>
      <dc:creator>ktugwell_splunk</dc:creator>
      <dc:date>2016-04-21T09:17:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search to only display entries added in the last 24 hours based on a time field from a lookup CSV file?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-only-display-entries-added-in-the-last/m-p/219359#M64466</link>
      <description>&lt;P&gt;You could also create a time-based lookup: &lt;/P&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/6.4.0/Knowledge/Usefieldlookupstoaddinformationtoyourevents#Configure_a_time-based_lookup"&gt;http://docs.splunk.com/Documentation/Splunk/6.4.0/Knowledge/Usefieldlookupstoaddinformationtoyourevents#Configure_a_time-based_lookup&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/6.4.0/Knowledge/Configureatime-boundedlookup"&gt;http://docs.splunk.com/Documentation/Splunk/6.4.0/Knowledge/Configureatime-boundedlookup&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Make sure your max and min offset times are correctly configured. For instance, if max offset is 3600 seconds: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;# transforms.conf
[mylookup]
filename = mylookup.csv
max_offset_secs = 3600
time_field = timestamp
time_format = %Y-%m-%d %H:%M:%S
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And your lookup is as follows:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;timestamp, index, value
2016-04-20 10:00:00, _internal, value1
2016-04-19 09:00:00, _internal, value2
2016-04-10 16:00:00, _internal, value3
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And assuming the current date is: 2016-04-21 10:00:00.&lt;/P&gt;

&lt;P&gt;Then the following query will only return value1:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_internal earliest=-24h | lookup mylookup index OUTPUT value | dedup value | table value
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Whereas the following will return no results:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_internal earliest=-23h | lookup mylookup index OUTPUT value | dedup value | table value
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And the following will return values 1 and 2:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_internal earliest=-3d | lookup mylookup index OUTPUT value | dedup value | table value
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Hope that helps.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Apr 2016 09:37:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-only-display-entries-added-in-the-last/m-p/219359#M64466</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2016-04-21T09:37:46Z</dc:date>
    </item>
  </channel>
</rss>

