<?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 Need to get latest sets of events in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Need-to-get-latest-sets-of-events/m-p/355973#M170105</link>
    <description>&lt;P&gt;I have a dbinput configured to pull data from SQL table on a daily basis. So I am getting few events each day in a index called A. The count of these index varies. Now on a dashboard, I want to display recent set of events from index A without asking user to select any time range.&lt;/P&gt;

&lt;P&gt;It may happen that due to some reason dbinput may not work for few days but still I need to get the latest available events from a index. Note that on a daily basis there will be multiple events coming from dbinput.&lt;/P&gt;</description>
    <pubDate>Mon, 23 Apr 2018 14:31:35 GMT</pubDate>
    <dc:creator>santosh_sshanbh</dc:creator>
    <dc:date>2018-04-23T14:31:35Z</dc:date>
    <item>
      <title>Need to get latest sets of events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-to-get-latest-sets-of-events/m-p/355973#M170105</link>
      <description>&lt;P&gt;I have a dbinput configured to pull data from SQL table on a daily basis. So I am getting few events each day in a index called A. The count of these index varies. Now on a dashboard, I want to display recent set of events from index A without asking user to select any time range.&lt;/P&gt;

&lt;P&gt;It may happen that due to some reason dbinput may not work for few days but still I need to get the latest available events from a index. Note that on a daily basis there will be multiple events coming from dbinput.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Apr 2018 14:31:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-to-get-latest-sets-of-events/m-p/355973#M170105</guid>
      <dc:creator>santosh_sshanbh</dc:creator>
      <dc:date>2018-04-23T14:31:35Z</dc:date>
    </item>
    <item>
      <title>Re: Need to get latest sets of events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-to-get-latest-sets-of-events/m-p/355974#M170106</link>
      <description>&lt;P&gt;Can you try:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| metadata type=sourcetypes index=A | rename totalCount as Count firstTime as "First Event" lastTime as "Last Event" recentTime as "Last Update" | fieldformat Count=tostring(Count, "commas") | fieldformat "First Event"=strftime('First Event', "%c") | fieldformat "Last Event"=strftime('Last Event', "%c") | fieldformat "Last Update"=strftime('Last Update', "%c")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 23 Apr 2018 16:52:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-to-get-latest-sets-of-events/m-p/355974#M170106</guid>
      <dc:creator>p_gurav</dc:creator>
      <dc:date>2018-04-23T16:52:55Z</dc:date>
    </item>
    <item>
      <title>Re: Need to get latest sets of events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-to-get-latest-sets-of-events/m-p/355975#M170107</link>
      <description>&lt;P&gt;@p_gurav showed oyu a nice way to capture the data about the last event and when it took place.&lt;BR /&gt;
if you want to see the event itself, try the &lt;CODE&gt;|head&lt;/CODE&gt; command and set the time to always capture something&lt;BR /&gt;
so assuming you set the time picker to last 72 hours and you are searching &lt;CODE&gt;...index=A ... | head 100&lt;/CODE&gt; will give you the first 100 results (or the last 100 events indexed) from that search&lt;/P&gt;</description>
      <pubDate>Mon, 23 Apr 2018 17:53:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-to-get-latest-sets-of-events/m-p/355975#M170107</guid>
      <dc:creator>adonio</dc:creator>
      <dc:date>2018-04-23T17:53:40Z</dc:date>
    </item>
    <item>
      <title>Re: Need to get latest sets of events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-to-get-latest-sets-of-events/m-p/355976#M170108</link>
      <description>&lt;P&gt;Try like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=A sourcetype=YourSourcetypeHere [| tstats max(_time) as lastTime WHERE index=A sourcetype=YourSourcetypeHere earliest=-30d | eval earliest=relative_time(lastTime,"@d") | eval latest=relative_time(lastTime,"@d+1d") | table earliest latest | format]
|..rest of your search
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The subsearch looks back 30 days worth of data and gets the most recent _time value. Then it generate the timerange for the main search with earliest being start of the day of the most recent _time value it found and latest being the end of the day of the most recent _time value. E.g. if last data was received on 04/15/2018 18:00, the earliest would be 04/15/2018 00:00 04/16/2018 00:00 so that all events from that day are shown in the main search.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Apr 2018 18:23:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-to-get-latest-sets-of-events/m-p/355976#M170108</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-04-23T18:23:37Z</dc:date>
    </item>
    <item>
      <title>Re: Need to get latest sets of events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-to-get-latest-sets-of-events/m-p/355977#M170109</link>
      <description>&lt;P&gt;Theoratically the logic seems correct. But I am getting below error with this &lt;/P&gt;

&lt;P&gt;Error in 'search' command: Unable to parse the search: 'AND' operator is missing a clause on the left hand side.&lt;/P&gt;

&lt;P&gt;If I just run the subquery I am getting below results. Search field has some data&lt;/P&gt;

&lt;P&gt;earliest    latest  search&lt;BR /&gt;
        ( ( earliest="1524528000.000000" AND latest="1524614400.000000" ) )&lt;/P&gt;

&lt;P&gt;Another issue is somehow tstats max(_time) is giving todays date but there is no data in the index for last 2 days. Not sure why it is showing today's date for max event.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Apr 2018 06:42:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-to-get-latest-sets-of-events/m-p/355977#M170109</guid>
      <dc:creator>santosh_sshanbh</dc:creator>
      <dc:date>2018-04-24T06:42:54Z</dc:date>
    </item>
  </channel>
</rss>

