<?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 include timestamp of most recent event in a comparison between current day and a prior period in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-include-timestamp-of-most-recent-event-in-a-comparison/m-p/382835#M167513</link>
    <description>&lt;P&gt;What about deleting line 9 and then just including &lt;CODE&gt;_time&lt;/CODE&gt; in your table?&lt;/P&gt;</description>
    <pubDate>Sun, 16 Sep 2018 21:18:31 GMT</pubDate>
    <dc:creator>DEAD_BEEF</dc:creator>
    <dc:date>2018-09-16T21:18:31Z</dc:date>
    <item>
      <title>How to include timestamp of most recent event in a comparison between current day and a prior period</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-include-timestamp-of-most-recent-event-in-a-comparison/m-p/382832#M167510</link>
      <description>&lt;P&gt;I have a search that compares the number of events for the current day, &lt;STRONG&gt;for a given combination of fields&lt;/STRONG&gt;, to the daily average over the prior two weeks. The search is pretty involved and is included below for reference. The search &lt;STRONG&gt;works&lt;/STRONG&gt; as intended. There may be ways to simplify the search and I'm open to such feedback, but simplifying the search is not my question. My question is...&lt;/P&gt;

&lt;P&gt;How can I add the timestamp of the most recent occurrence for the combination of fields?&lt;/P&gt;

&lt;P&gt;I've included two screenshots. The first screenshot shows the current results and the second screenshot illustrates the desired results.&lt;/P&gt;

&lt;P&gt;Any advice is appreciated. Thanks&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=xxxxxxxx earliest=@w6-14d latest=@w6
| eval Prior_or_Current="Prior"
| append [search sourcetype=xxxxxxxx earliest=@d
| eval Prior_or_Current="Current"]
| eval dayOfWeek=strftime(_time, "%A")
| eval hourOfDay=strftime(_time, "%H")
| search NOT ((dayOfWeek="Friday" AND hourOfDay&amp;gt;=20) OR (dayOfWeek="saturday" AND hourOfDay&amp;lt;5) OR (dayOfWeek="sunday" AND (hourOfDay&amp;gt;=0 AND hourOfDay&amp;lt;5)))
| eval Event_Date=strftime(_time, "%F")
| rex "msg\=\'(?&amp;lt;msg_first22char&amp;gt;(.{22}))"
| eval Combined_Key=err_transaction_id.",".err_program.",".msg_first22char
| stats count by Event_Date Combined_Key Prior_or_Current
| chart avg(count) over Combined_Key by Prior_or_Current
| eval Prior=if(Prior&amp;gt;"",Prior,0)
| eval Current=if(Current&amp;gt;"",Current,0)
| eval Percent_Change=(Current-Prior)/Prior*100
| eval Percent_Change=if(Percent_Change&amp;gt;"",Percent_Change,if(Prior&amp;gt;0,-100,100))
| eval Percent_Change=round(Percent_Change,0), Prior=round(Prior,0), Current=round(Current,0)
| rename Prior as Prior_Period_Daily_Avg Current as Current_Day_Count
| eval Sort_To_The_Top=if((Prior_Period_Daily_Avg=0 OR (Percent_Change&amp;gt;=50 AND Prior_Period_Daily_Avg&amp;gt;=200) OR (Percent_Change&amp;gt;=100 AND Prior_Period_Daily_Avg&amp;gt;=50) OR (Percent_Change&amp;gt;=500 AND Prior_Period_Daily_Avg&amp;gt;=10) OR Percent_Change&amp;gt;=1000), 0, if(Percent_Change&amp;gt;-1,1,2))
| search Sort_To_The_Top=0
| rex field=Combined_Key "(?&amp;lt;err_transaction_id&amp;gt;[\w|\W]+),(?&amp;lt;err_program&amp;gt;[\w|\W]+),(?&amp;lt;msg_first22chars&amp;gt;[\w|\W]+)"
| rex mode=sed field="err_transaction_id" "s/\'//g" 
| rex mode=sed field="err_program" "s/\'//g"
| sort Sort_To_The_Top -Current_Day_Count -Percent_Change -Prior_Period_Daily_Avg err_transaction_id err_program msg_first22chars
| table err_transaction_id err_program msg_first22chars Prior_Period_Daily_Avg Current_Day_Count Percent_Change
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Current Results&lt;/STRONG&gt;&lt;BR /&gt;
&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/5799i2783EB21A4A7FA35/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Desired Results&lt;/STRONG&gt;&lt;BR /&gt;
&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/5800iF3624E087AB452F9/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 15 Sep 2018 14:04:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-include-timestamp-of-most-recent-event-in-a-comparison/m-p/382832#M167510</guid>
      <dc:creator>djhowie</dc:creator>
      <dc:date>2018-09-15T14:04:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to include timestamp of most recent event in a comparison between current day and a prior period</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-include-timestamp-of-most-recent-event-in-a-comparison/m-p/382833#M167511</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats latest(_time) AS Latest_Occurrence
| table Latest_Occurrence
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 16 Sep 2018 02:21:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-include-timestamp-of-most-recent-event-in-a-comparison/m-p/382833#M167511</guid>
      <dc:creator>DEAD_BEEF</dc:creator>
      <dc:date>2018-09-16T02:21:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to include timestamp of most recent event in a comparison between current day and a prior period</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-include-timestamp-of-most-recent-event-in-a-comparison/m-p/382834#M167512</link>
      <description>&lt;P&gt;Thanks for the reply. I understand that the stats command can be used to compute the latest timestamp. The problem is figuring out how to work it into the overall search. I tried inserting the stats, along with tabling all fields referenced in the subsequent portions of the search, but it doesn't work. I get zero results. See lines 9 and 10. Thanks&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=xxxxxxxx earliest=@w6-14d latest=@w6
| eval Prior_or_Current="Prior"
| append [search sourcetype=xxxxxxxx earliest=@d
| eval Prior_or_Current="Current"]
| eval dayOfWeek=strftime(_time, "%A")
| eval hourOfDay=strftime(_time, "%H")
| search NOT ((dayOfWeek="Friday" AND hourOfDay&amp;gt;=20) OR (dayOfWeek="saturday" AND hourOfDay&amp;lt;5) OR (dayOfWeek="sunday" AND (hourOfDay&amp;gt;=0 AND hourOfDay&amp;lt;5)))
| eval Event_Date=strftime(_time, "%F")
| stats latest(_time) AS Latest_Occurrence
| table err_transaction_id err_program msg Prior_or_Current Event_Date Latest_Occurrence
| rex "msg\=\'(?&amp;lt;msg_first22char&amp;gt;(.{22}))"
| eval Combined_Key=err_transaction_id.",".err_program.",".msg_first22char
| stats count by Event_Date Combined_Key Prior_or_Current
| chart avg(count) over Combined_Key by Prior_or_Current
| eval Prior=if(Prior&amp;gt;"",Prior,0)
| eval Current=if(Current&amp;gt;"",Current,0)
| eval Percent_Change=(Current-Prior)/Prior*100
| eval Percent_Change=if(Percent_Change&amp;gt;"",Percent_Change,if(Prior&amp;gt;0,-100,100))
| eval Percent_Change=round(Percent_Change,0), Prior=round(Prior,0), Current=round(Current,0)
| rename Prior as Prior_Period_Daily_Avg Current as Current_Day_Count
| eval Sort_To_The_Top=if((Prior_Period_Daily_Avg=0 OR (Percent_Change&amp;gt;=50 AND Prior_Period_Daily_Avg&amp;gt;=200) OR (Percent_Change&amp;gt;=100 AND Prior_Period_Daily_Avg&amp;gt;=50) OR (Percent_Change&amp;gt;=500 AND Prior_Period_Daily_Avg&amp;gt;=10) OR Percent_Change&amp;gt;=1000), 0, if(Percent_Change&amp;gt;-1,1,2))
| search Sort_To_The_Top=0
| rex field=Combined_Key "(?&amp;lt;err_transaction_id&amp;gt;[\w|\W]+),(?&amp;lt;err_program&amp;gt;[\w|\W]+),(?&amp;lt;msg_first22chars&amp;gt;[\w|\W]+)"
| rex mode=sed field="err_transaction_id" "s/\'//g" 
| rex mode=sed field="err_program" "s/\'//g"
| sort Sort_To_The_Top -Current_Day_Count -Percent_Change -Prior_Period_Daily_Avg err_transaction_id err_program msg_first22chars
| table err_transaction_id err_program msg_first22chars Prior_Period_Daily_Avg Current_Day_Count Latest_Occurrence Percent_Change
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 16 Sep 2018 13:56:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-include-timestamp-of-most-recent-event-in-a-comparison/m-p/382834#M167512</guid>
      <dc:creator>djhowie</dc:creator>
      <dc:date>2018-09-16T13:56:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to include timestamp of most recent event in a comparison between current day and a prior period</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-include-timestamp-of-most-recent-event-in-a-comparison/m-p/382835#M167513</link>
      <description>&lt;P&gt;What about deleting line 9 and then just including &lt;CODE&gt;_time&lt;/CODE&gt; in your table?&lt;/P&gt;</description>
      <pubDate>Sun, 16 Sep 2018 21:18:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-include-timestamp-of-most-recent-event-in-a-comparison/m-p/382835#M167513</guid>
      <dc:creator>DEAD_BEEF</dc:creator>
      <dc:date>2018-09-16T21:18:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to include timestamp of most recent event in a comparison between current day and a prior period</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-include-timestamp-of-most-recent-event-in-a-comparison/m-p/382836#M167514</link>
      <description>&lt;P&gt;I have not tried that, but I don't expect that will work. The search in question does not output every event. The search computes the daily count of events, based upon a combination of selected fields, to the daily average over the prior two weeks. The intent is to include the latest timestamp for the combination of fields.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Sep 2018 00:43:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-include-timestamp-of-most-recent-event-in-a-comparison/m-p/382836#M167514</guid>
      <dc:creator>djhowie</dc:creator>
      <dc:date>2018-09-17T00:43:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to include timestamp of most recent event in a comparison between current day and a prior period</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-include-timestamp-of-most-recent-event-in-a-comparison/m-p/382837#M167515</link>
      <description>&lt;P&gt;When you say the latest timestamp for the combination of fields, there must be some timestamp within the log that holds those fields.  Could you eval the &lt;CODE&gt;_time&lt;/CODE&gt; of each of those fields, compare them, and then return the latest one?  It doesn't sound pretty but it may be an option.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Sep 2018 13:22:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-include-timestamp-of-most-recent-event-in-a-comparison/m-p/382837#M167515</guid>
      <dc:creator>DEAD_BEEF</dc:creator>
      <dc:date>2018-09-17T13:22:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to include timestamp of most recent event in a comparison between current day and a prior period</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-include-timestamp-of-most-recent-event-in-a-comparison/m-p/382838#M167516</link>
      <description>&lt;P&gt;I understand how to get the latest time. The problem is I cannot figure out how to incorporate it &lt;STRONG&gt;into the overall search to achieve the desired results without breaking the existing functionality&lt;/STRONG&gt;.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Sep 2018 14:48:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-include-timestamp-of-most-recent-event-in-a-comparison/m-p/382838#M167516</guid>
      <dc:creator>djhowie</dc:creator>
      <dc:date>2018-09-17T14:48:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to include timestamp of most recent event in a comparison between current day and a prior period</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-include-timestamp-of-most-recent-event-in-a-comparison/m-p/515117#M167517</link>
      <description>&lt;P&gt;How can I make Latest_Occurrence value readable. Currently, it's of the following value, for example,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;1597896470&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I'd like it to be for example,&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2020-08-19 22:40:37&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Aug 2020 05:48:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-include-timestamp-of-most-recent-event-in-a-comparison/m-p/515117#M167517</guid>
      <dc:creator>yshen</dc:creator>
      <dc:date>2020-08-20T05:48:34Z</dc:date>
    </item>
  </channel>
</rss>

