<?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 that returns the most recent event for a sourcetype on every host? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-that-returns-the-most-recent-event-for-a/m-p/139827#M38488</link>
    <description>&lt;P&gt;Sorry, maybe I explained this incorrectly.  I have a bunch of host that forward logs to Splunk in the form of a csv line every min.  I want to do a search of every host, but only get the last line of the log that has been forwarded by the host.  So instead of searching every event on each host, I just need to grab the last event for a sourcetype.&lt;/P&gt;</description>
    <pubDate>Thu, 09 Apr 2015 16:24:19 GMT</pubDate>
    <dc:creator>chadman</dc:creator>
    <dc:date>2015-04-09T16:24:19Z</dc:date>
    <item>
      <title>How to write a search that returns the most recent event for a sourcetype on every host?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-that-returns-the-most-recent-event-for-a/m-p/139825#M38486</link>
      <description>&lt;P&gt;I have a csv file on every computer and need to just search the last event for eveyy host.  I can't get a search to work without searching every event on every host.  I have used dedup, but it still searches every host.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Apr 2015 15:08:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-that-returns-the-most-recent-event-for-a/m-p/139825#M38486</guid>
      <dc:creator>chadman</dc:creator>
      <dc:date>2015-04-09T15:08:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search that returns the most recent event for a sourcetype on every host?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-that-returns-the-most-recent-event-for-a/m-p/139826#M38487</link>
      <description>&lt;P&gt;Here is an expensive way with ugly output using the &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.2.2/SearchReference/Map"&gt;map command&lt;/A&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count 
| eval host="host_a,host_b,host_c" 
| makemv delim="," host 
| mvexpand host 
| map search="search host=$host$ | head 1 "
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Using your CSV file it might look like this...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count 
| inputlookup=host_csv 
| map search="search host=$host$ | head 1 "
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;/P&gt;&lt;H4&gt;Better Solution&lt;/H4&gt;Actually, host info can be queried by metadata so this &lt;A href="http://answers.splunk.com/answers/52891/most-recent-event-from-each-source.html"&gt;"Most recent event from each source?" answer&lt;/A&gt; from Ayn may be adapted to solve this problem more neatly.&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Apr 2015 15:57:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-that-returns-the-most-recent-event-for-a/m-p/139826#M38487</guid>
      <dc:creator>bwooden</dc:creator>
      <dc:date>2015-04-09T15:57:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search that returns the most recent event for a sourcetype on every host?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-that-returns-the-most-recent-event-for-a/m-p/139827#M38488</link>
      <description>&lt;P&gt;Sorry, maybe I explained this incorrectly.  I have a bunch of host that forward logs to Splunk in the form of a csv line every min.  I want to do a search of every host, but only get the last line of the log that has been forwarded by the host.  So instead of searching every event on each host, I just need to grab the last event for a sourcetype.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Apr 2015 16:24:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-that-returns-the-most-recent-event-for-a/m-p/139827#M38488</guid>
      <dc:creator>chadman</dc:creator>
      <dc:date>2015-04-09T16:24:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search that returns the most recent event for a sourcetype on every host?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-that-returns-the-most-recent-event-for-a/m-p/139828#M38489</link>
      <description>&lt;P&gt;Here is what I use now and it works, but I think it's seaching every event.  I only want it to look at the last event for every host to speed up the search.  sourcetype="my source"  |  where Available_D &amp;lt; 100 | dedup host | sort Available_D a  |table host,Available_D &lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 19:30:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-that-returns-the-most-recent-event-for-a/m-p/139828#M38489</guid>
      <dc:creator>chadman</dc:creator>
      <dc:date>2020-09-28T19:30:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search that returns the most recent event for a sourcetype on every host?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-that-returns-the-most-recent-event-for-a/m-p/139829#M38490</link>
      <description>&lt;P&gt;I'd probably abstract this into a lookup file holding state.  Specifically, keep in your lookup file the most recent event per host.  When you update it incrementally, it is cheap -- and getting the current state from the lookup is super cheap.&lt;/P&gt;

&lt;P&gt;A similar answer is here:&lt;/P&gt;

&lt;P&gt;&lt;A href="http://answers.splunk.com/answers/216701/how-to-send-an-alert-email-the-first-time-since-th.html"&gt;http://answers.splunk.com/answers/216701/how-to-send-an-alert-email-the-first-time-since-th.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Apr 2015 21:22:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-that-returns-the-most-recent-event-for-a/m-p/139829#M38490</guid>
      <dc:creator>dwaddle</dc:creator>
      <dc:date>2015-04-09T21:22:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search that returns the most recent event for a sourcetype on every host?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-that-returns-the-most-recent-event-for-a/m-p/139830#M38491</link>
      <description>&lt;P&gt;I tried that, but have not gotten it to work yet.  I would think there would be an eaiser way to work with the last line from every host.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Apr 2015 12:46:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-that-returns-the-most-recent-event-for-a/m-p/139830#M38491</guid>
      <dc:creator>chadman</dc:creator>
      <dc:date>2015-04-14T12:46:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search that returns the most recent event for a sourcetype on every host?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-that-returns-the-most-recent-event-for-a/m-p/139831#M38492</link>
      <description>&lt;P&gt;I will try to bake up a concrete example today/tonight of doing this via lookup.  Check this space.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Apr 2015 13:07:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-that-returns-the-most-recent-event-for-a/m-p/139831#M38492</guid>
      <dc:creator>dwaddle</dc:creator>
      <dc:date>2015-04-14T13:07:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search that returns the most recent event for a sourcetype on every host?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-that-returns-the-most-recent-event-for-a/m-p/139832#M38493</link>
      <description>&lt;P&gt;great, let me know if you come up with something&lt;/P&gt;</description>
      <pubDate>Wed, 15 Apr 2015 15:40:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-that-returns-the-most-recent-event-for-a/m-p/139832#M38493</guid>
      <dc:creator>chadman</dc:creator>
      <dc:date>2015-04-15T15:40:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search that returns the most recent event for a sourcetype on every host?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-that-returns-the-most-recent-event-for-a/m-p/139833#M38494</link>
      <description>&lt;P&gt;Hi chadman&lt;BR /&gt;
to get last value of a host  field you can use last() function with stats cammand &lt;/P&gt;

&lt;P&gt;see the following serch code&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    sourcetype="my source" | where Available_D &amp;lt; 100 | dedup host |stats last(host) as last_host| sort Available_D a |table  last_host  Available_D 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 15 Apr 2015 16:05:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-that-returns-the-most-recent-event-for-a/m-p/139833#M38494</guid>
      <dc:creator>chimell</dc:creator>
      <dc:date>2015-04-15T16:05:04Z</dc:date>
    </item>
  </channel>
</rss>

