<?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 How to find max(_time) for sourcetypes &amp;amp; host by sourcetype host? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-max-time-for-sourcetypes-amp-host-by-sourcetype-host/m-p/643840#M223041</link>
    <description>&lt;P&gt;I found the following search to identify Missing / New sourcetypes and made a few changes.&lt;BR /&gt;I am getting data and my next enhancement is to add the latest date/time a sourcetype was 'seen'.&lt;/P&gt;
&lt;P&gt;Here is the search I am starting with:&lt;/P&gt;
&lt;P&gt;index=anIndex earliest=-4d latest=now&lt;BR /&gt;| eval recent=if(_time&amp;gt;(now()-129600 ),1,0) ```&amp;lt;--- No Logs in 1.5 Days ```&lt;BR /&gt;| stats count(eval(recent=1)) AS CurrentCount count(eval(recent=0)) AS HistoricalCount BY sourcetype host&lt;BR /&gt;| where ( (CurrentCount &amp;lt; 1 AND HistoricalCount &amp;gt; 0) OR ( CurrentCount &amp;gt; 0 AND HistoricalCount &amp;lt; 1)) ```&amp;lt;--- Missing &amp;amp; New```&lt;BR /&gt;| eval status=case(CurrentCount &amp;gt; 0 AND HistoricalCount &amp;gt; 0, "OK",&lt;BR /&gt;CurrentCount &amp;lt; 1 AND HistoricalCount &amp;gt; 0, "MISSING",&lt;BR /&gt;CurrentCount &amp;gt; 0 AND HistoricalCount &amp;lt; 1, "NEW",&lt;BR /&gt;1=1,"Unknown" )&lt;BR /&gt;| sort sourcetype&lt;BR /&gt;| table status host sourcetype CurrentCount HistoricalCount&lt;/P&gt;
&lt;P&gt;I think this is returning the last time a sourcetype was seen:&lt;/P&gt;
&lt;P&gt;index=anIndex earliest=-2d latest=now&lt;BR /&gt;| stats max(_time) as last_searched by sourcetype host&lt;BR /&gt;| eval lastTime=strftime(last_searched, "%m/%d/%y %H:%M:%S")&lt;BR /&gt;| sort sourcetype host&lt;BR /&gt;| table host sourcetype lastTime&lt;/P&gt;
&lt;P&gt;But, when I try to add these two lines into my original query I do not get any data ?&lt;/P&gt;
&lt;P&gt;| stats max(_time) as last_searched by sourcetype host&lt;BR /&gt;| eval lastTime=strftime(last_searched, "%m/%d/%y %H:%M:%S")&lt;/P&gt;
&lt;P&gt;I have tried placing it in several different places but always get 'No Results found...'&lt;BR /&gt;What am I missing ?&lt;/P&gt;</description>
    <pubDate>Fri, 19 May 2023 12:07:07 GMT</pubDate>
    <dc:creator>sjringo</dc:creator>
    <dc:date>2023-05-19T12:07:07Z</dc:date>
    <item>
      <title>How to find max(_time) for sourcetypes &amp; host by sourcetype host?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-max-time-for-sourcetypes-amp-host-by-sourcetype-host/m-p/643840#M223041</link>
      <description>&lt;P&gt;I found the following search to identify Missing / New sourcetypes and made a few changes.&lt;BR /&gt;I am getting data and my next enhancement is to add the latest date/time a sourcetype was 'seen'.&lt;/P&gt;
&lt;P&gt;Here is the search I am starting with:&lt;/P&gt;
&lt;P&gt;index=anIndex earliest=-4d latest=now&lt;BR /&gt;| eval recent=if(_time&amp;gt;(now()-129600 ),1,0) ```&amp;lt;--- No Logs in 1.5 Days ```&lt;BR /&gt;| stats count(eval(recent=1)) AS CurrentCount count(eval(recent=0)) AS HistoricalCount BY sourcetype host&lt;BR /&gt;| where ( (CurrentCount &amp;lt; 1 AND HistoricalCount &amp;gt; 0) OR ( CurrentCount &amp;gt; 0 AND HistoricalCount &amp;lt; 1)) ```&amp;lt;--- Missing &amp;amp; New```&lt;BR /&gt;| eval status=case(CurrentCount &amp;gt; 0 AND HistoricalCount &amp;gt; 0, "OK",&lt;BR /&gt;CurrentCount &amp;lt; 1 AND HistoricalCount &amp;gt; 0, "MISSING",&lt;BR /&gt;CurrentCount &amp;gt; 0 AND HistoricalCount &amp;lt; 1, "NEW",&lt;BR /&gt;1=1,"Unknown" )&lt;BR /&gt;| sort sourcetype&lt;BR /&gt;| table status host sourcetype CurrentCount HistoricalCount&lt;/P&gt;
&lt;P&gt;I think this is returning the last time a sourcetype was seen:&lt;/P&gt;
&lt;P&gt;index=anIndex earliest=-2d latest=now&lt;BR /&gt;| stats max(_time) as last_searched by sourcetype host&lt;BR /&gt;| eval lastTime=strftime(last_searched, "%m/%d/%y %H:%M:%S")&lt;BR /&gt;| sort sourcetype host&lt;BR /&gt;| table host sourcetype lastTime&lt;/P&gt;
&lt;P&gt;But, when I try to add these two lines into my original query I do not get any data ?&lt;/P&gt;
&lt;P&gt;| stats max(_time) as last_searched by sourcetype host&lt;BR /&gt;| eval lastTime=strftime(last_searched, "%m/%d/%y %H:%M:%S")&lt;/P&gt;
&lt;P&gt;I have tried placing it in several different places but always get 'No Results found...'&lt;BR /&gt;What am I missing ?&lt;/P&gt;</description>
      <pubDate>Fri, 19 May 2023 12:07:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-max-time-for-sourcetypes-amp-host-by-sourcetype-host/m-p/643840#M223041</guid>
      <dc:creator>sjringo</dc:creator>
      <dc:date>2023-05-19T12:07:07Z</dc:date>
    </item>
    <item>
      <title>Re: Finding max(_time) for sourcetypes &amp; host by sourcetype host ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-max-time-for-sourcetypes-amp-host-by-sourcetype-host/m-p/643841#M223042</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/238212"&gt;@sjringo&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;In the first query the _time field is not a result field, so you obviously cannot use it.&amp;nbsp; Here's a modified query that also returns the max time for each host sourcetype.&amp;nbsp; I've also demonstrated how to use the tstats command to make the query x100 times quicker and more efficient, but you can revert back to scanning _raw events if you prefer.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| tstats max(_time) AS _time WHERE index=anIndex earliest=-4d latest=now BY sourcetype host 
| eval recent=if(_time&amp;gt;(now()-129600 ),1,0) ```&amp;lt;--- No Logs in 1.5 Days ```
| stats max(_time) AS max_time count(eval(recent=1)) AS CurrentCount count(eval(recent=0)) AS HistoricalCount BY sourcetype host
| where ( (CurrentCount &amp;lt; 1 AND HistoricalCount &amp;gt; 0) OR ( CurrentCount &amp;gt; 0 AND HistoricalCount &amp;lt; 1)) ```&amp;lt;--- Missing &amp;amp; New```
| eval status=case(CurrentCount &amp;gt; 0 AND HistoricalCount &amp;gt; 0, "OK",
    CurrentCount &amp;lt; 1 AND HistoricalCount &amp;gt; 0, "MISSING",
    CurrentCount &amp;gt; 0 AND HistoricalCount &amp;lt; 1, "NEW",
    1=1,"Unknown" )
| sort sourcetype
| table status host sourcetype CurrentCount HistoricalCount max_time
| stats max(max_time) as last_searched by sourcetype host
| eval lastTime=strftime(last_searched, "%m/%d/%y %H:%M:%S")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp; Hope that helps&lt;/P&gt;</description>
      <pubDate>Thu, 18 May 2023 21:28:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-max-time-for-sourcetypes-amp-host-by-sourcetype-host/m-p/643841#M223042</guid>
      <dc:creator>yeahnah</dc:creator>
      <dc:date>2023-05-18T21:28:51Z</dc:date>
    </item>
    <item>
      <title>Re: Finding max(_time) for sourcetypes &amp; host by sourcetype host ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-max-time-for-sourcetypes-amp-host-by-sourcetype-host/m-p/643845#M223043</link>
      <description>&lt;P&gt;Ok, I had to massage your posting somewhat to work with what I was looking for.&lt;/P&gt;&lt;P&gt;I am aware of TSTATS but struggling to get it to work for the query that I am starting with ?&lt;/P&gt;&lt;P&gt;Here is what I have working:&lt;/P&gt;&lt;P&gt;index=anIndex earliest=-4d latest=now&lt;/P&gt;&lt;P&gt;| eval recent=if(_time&amp;gt;(now()-129600 ),1,0) ```&amp;lt;--- No Logs in 1.5 Days ```&lt;/P&gt;&lt;P&gt;| stats max(_time) AS max_time count(eval(recent=1)) AS CurrentCount count(eval(recent=0)) AS HistoricalCount BY sourcetype host&lt;/P&gt;&lt;P&gt;| where ( (CurrentCount &amp;lt; 1 AND HistoricalCount &amp;gt; 0) OR ( CurrentCount &amp;gt; 0 AND HistoricalCount &amp;lt; 1)) ```&amp;lt;--- Missing &amp;amp; New```&lt;/P&gt;&lt;P&gt;| eval status=case(CurrentCount &amp;gt; 0 AND HistoricalCount &amp;gt; 0, "OK", CurrentCount &amp;lt; 1 AND HistoricalCount &amp;gt; 0, "MISSING", CurrentCount &amp;gt; 0 AND HistoricalCount &amp;lt; 1, "NEW", 1=1,"Unknown" )&lt;/P&gt;&lt;P&gt;| eval lastTime=strftime(max_time, "%m/%d/%y %H:%M:%S")&lt;/P&gt;&lt;P&gt;| sort sourcetype&lt;/P&gt;&lt;P&gt;| rename status AS Status, host AS Host, sourcetype AS "Source Type", CurrentCount AS "Log Entries in 1.5 Days", HistoricalCount AS "Log Entries over 1.5 Days", lastTime AS "Last Log Entry"&lt;/P&gt;&lt;P&gt;| table Status Host "Source Type" "Log Entries in 1.5 Days" "Log Entries over 1.5 Days" "Last Log Entry"&lt;/P&gt;&lt;P&gt;Any help in getting it to work with TSTATS would be appreciated...&lt;/P&gt;</description>
      <pubDate>Fri, 19 May 2023 00:45:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-max-time-for-sourcetypes-amp-host-by-sourcetype-host/m-p/643845#M223043</guid>
      <dc:creator>sjringo</dc:creator>
      <dc:date>2023-05-19T00:45:49Z</dc:date>
    </item>
    <item>
      <title>Re: Finding max(_time) for sourcetypes &amp; host by sourcetype host ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-max-time-for-sourcetypes-amp-host-by-sourcetype-host/m-p/643847#M223045</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/238212"&gt;@sjringo&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Sorry, I had not accounted for you count logic.&amp;nbsp; You can use tstats like this and then apply some logic to the results.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| tstats
    max(_time) AS max_current_time
    count AS CurrentCount
  WHERE index=anIndex earliest=-129600 latest=now
  BY sourcetype host
| append [| tstats
    max(_time) AS max_historical_time
    count AS HistoricalCount
  WHERE index=anIndex earliest=-4d latest=-129600
  BY sourcetype host ]
| stats values(*) AS * BY sourcetype host
| foreach *_time [ eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;_hm=strftime('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;', "%c") ]  ``` not really needed ```
| eval _time=if(max_current_time &amp;gt; max_historical_time OR isnull(max_historical_time), max_current_time, max_historical_time)
| eval status=case(CurrentCount &amp;gt; 0 AND HistoricalCount &amp;gt; 0, "OK", isnull(CurrentCount), "MISSING", isnull(HistoricalCount), "NEW", true(), "Unknown" )
| sort sourcetype
| rename status AS Status, host AS Host, sourcetype AS "Source Type", CurrentCount AS "Log Entries in 1.5 Days", HistoricalCount AS "Log Entries over 1.5 Days"
| table Status Host "Source Type" "Log Entries in 1.5 Days" "Log Entries over 1.5 Days" _time&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;It might not be perfect but will hopefully get you going&lt;/P&gt;</description>
      <pubDate>Fri, 19 May 2023 02:35:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-max-time-for-sourcetypes-amp-host-by-sourcetype-host/m-p/643847#M223045</guid>
      <dc:creator>yeahnah</dc:creator>
      <dc:date>2023-05-19T02:35:07Z</dc:date>
    </item>
    <item>
      <title>Re: Finding max(_time) for sourcetypes &amp; host by sourcetype host ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-max-time-for-sourcetypes-amp-host-by-sourcetype-host/m-p/643888#M223070</link>
      <description>&lt;P&gt;Getting results using your updated TSTATS query.&amp;nbsp; I am going to need a little time to compare data from both queries and mash up the results just to figure out if both results are returning the same results, etc...&lt;/P&gt;&lt;P&gt;But the speed of the query results is better.&amp;nbsp; a few seconds compared to 15 minutes !!!&lt;/P&gt;&lt;P&gt;TSTATS is still a little bit fuzzy but having something that works will help me going forward...&lt;/P&gt;&lt;P&gt;Thanks for your help ...&lt;/P&gt;</description>
      <pubDate>Fri, 19 May 2023 11:09:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-max-time-for-sourcetypes-amp-host-by-sourcetype-host/m-p/643888#M223070</guid>
      <dc:creator>sjringo</dc:creator>
      <dc:date>2023-05-19T11:09:25Z</dc:date>
    </item>
  </channel>
</rss>

