<?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: Stats function with additional fields in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Stats-function-with-additional-fields/m-p/515636#M144786</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/59546"&gt;@worldexplorer81&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I understand correctly, you want timestamp from your log entries to be used instead of the initial value of _time. So, for these entries, for example:&lt;/P&gt;&lt;TABLE border="1" width="69.38704884047132%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%"&gt;&lt;STRONG&gt;timestamp&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;&lt;STRONG&gt;jobId&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD width="16.666666666666668%"&gt;&lt;STRONG&gt;statusText&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%"&gt;&lt;FONT color="#00FF00"&gt;2020-08-20 03:18:35.0&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;&lt;FONT color="#00FF00"&gt;887395&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="16.666666666666668%"&gt;&lt;FONT color="#00FF00"&gt;SUCCESS&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%"&gt;2020-08-20 03:18:28.0&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;887395&lt;/TD&gt;&lt;TD width="16.666666666666668%"&gt;RUNNING&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%"&gt;2020-08-20 03:18:28.0&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;887395&lt;/TD&gt;&lt;TD width="16.666666666666668%"&gt;STARTING&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%"&gt;2020-08-20 03:19:35.0&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;1111&lt;/TD&gt;&lt;TD width="16.666666666666668%"&gt;RUNNING&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%"&gt;&lt;FONT color="#00FF00"&gt;2020-08-20 03:20:28.0&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;&lt;FONT color="#00FF00"&gt;1111&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="16.666666666666668%"&gt;&lt;FONT color="#00FF00"&gt;STARTING&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%"&gt;&lt;FONT color="#00FF00"&gt;2020-08-20 04:10:00.0&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;&lt;FONT color="#00FF00"&gt;2222&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="16.666666666666668%"&gt;&lt;FONT color="#00FF00"&gt;RUNNING&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%"&gt;2020-08-20 04:09:00.0&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;2222&lt;/TD&gt;&lt;TD width="16.666666666666668%"&gt;STARTING&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Reset _time to be your timestamp:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval events="2020-08-20 03:18:35.0+887395+SUCCESS|2020-08-20 03:18:28.0+887395+RUNNING|2020-08-20 03:18:28.0+887395+STARTING|2020-08-20 03:19:35.0+1111+RUNNING|2020-08-20 03:20:28.0+1111+STARTING|2020-08-20 04:10:00.0+2222+RUNNING|2020-08-20 04:09:00.0+2222+STARTING" 
| makemv delim="|" events 
| mvexpand events 
| rex field=events "(?&amp;lt;timestamp&amp;gt;.*)\+(?&amp;lt;jobId&amp;gt;.*)\+(?&amp;lt;statusText&amp;gt;.*)"
| eval _time=strptime(timestamp, "%Y-%m-%d %H:%M:%S.0")
| stats latest(statusText) as statusText by jobId&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;By the way, this can be done when your logs are first loaded into your indexes&lt;/P&gt;&lt;P&gt;Using latest (which is based on _time) gives:&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="50%"&gt;&lt;STRONG&gt;jobId&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD width="50%"&gt;&lt;STRONG&gt;statusText&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%"&gt;1111&lt;/TD&gt;&lt;TD width="50%"&gt;STARTING&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%"&gt;2222&lt;/TD&gt;&lt;TD width="50%"&gt;RUNNING&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%"&gt;887395&lt;/TD&gt;&lt;TD width="50%"&gt;SUCCESS&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
    <pubDate>Sun, 23 Aug 2020 13:05:55 GMT</pubDate>
    <dc:creator>ITWhisperer</dc:creator>
    <dc:date>2020-08-23T13:05:55Z</dc:date>
    <item>
      <title>Stats function with additional fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Stats-function-with-additional-fields/m-p/515323#M144672</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;In my splunk events, I have multiple jobsNames and their corresponding statusText. For one jobName, there will be multiple events with different statusText.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to identify all jobNames where their latest/current status is 'Running' .&amp;nbsp; i.e For the latest entry for a&amp;nbsp; specific job, the status should be Running&lt;/P&gt;&lt;P&gt;i tried the below, but the stats by statusText shows all the status for a specific job. As such it does&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=batch firm* | stats latest(timestamp) as Time by jobName, statusText | where statusText=Running&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;An example of some events for one specific job can be as follows. The below job example should not appear in my results as the latest status is 'SUCCESS'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;FYI - The Splunk _time for the 3 events are exactly the same. The differentiation comes in the timestamp field. As such i cannot use latest(statusText)&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;timestamp="2020-08-20 03:18:35.0", eventNum="575452832", jobId="887395", jobName="firm_fisp1_ov_D8117", boxJobName="firm_fisp1_postov_box_1", eventCode="101", eventText="CHANGE_STATUS", statusCode="4", statusText="SUCCESS", alarmCode="0", exitCode="0", machine="frmlxap1p1.prudential.com", runNumber="90859630", attemptNumber="1"

timestamp="2020-08-20 03:18:28.0", eventNum="575452821", jobId="887395", jobName="firm_fisp1_ov_D8117", boxJobName="firm_fisp1_postov_box_1", eventCode="101", eventText="CHANGE_STATUS", statusCode="1", statusText="RUNNING", alarmCode="0", text="Executing at WA_AGENT", exitCode="0", machine="frmlxap1p1.prudential.com", runNumber="90859630", attemptNumber="1"

timestamp="2020-08-20 03:18:28.0", eventNum="575452820", jobId="887395", jobName="firm_fisp1_ov_D8117", boxJobName="firm_fisp1_postov_box_1", eventCode="101", eventText="CHANGE_STATUS", statusCode="3", statusText="STARTING", alarmCode="0", exitCode="-21", machine="frmlxap1p1.prudential.com", runNumber="90859630", attemptNumber="1"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help will be appreciated!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Aug 2020 00:46:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Stats-function-with-additional-fields/m-p/515323#M144672</guid>
      <dc:creator>worldexplorer81</dc:creator>
      <dc:date>2020-08-21T00:46:52Z</dc:date>
    </item>
    <item>
      <title>Re: Stats function with additional fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Stats-function-with-additional-fields/m-p/515337#M144678</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/59546"&gt;@worldexplorer81&lt;/a&gt;&amp;nbsp;, I believe this should help&lt;/P&gt;&lt;P&gt;index=batch firm* | stats latest(statusText) as currentStatus by jobName |search&amp;nbsp;&lt;SPAN&gt;currentStatus&lt;/SPAN&gt;=RUNNING&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Please upvote my response, if it helps.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Aug 2020 00:31:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Stats-function-with-additional-fields/m-p/515337#M144678</guid>
      <dc:creator>Nisha18789</dc:creator>
      <dc:date>2020-08-21T00:31:22Z</dc:date>
    </item>
    <item>
      <title>Re: Stats function with additional fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Stats-function-with-additional-fields/m-p/515340#M144681</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/215670"&gt;@Nisha18789&lt;/a&gt;&amp;nbsp;,&amp;nbsp;&lt;/P&gt;&lt;P&gt;unfortunately, that does not work. I forgot to mention that the&amp;nbsp; splunk _time can be exactly the same for 3 events with different status. As such, using latest(statusText) returns a status of STARTING instead of SUCCESS. So i unfortunately cannot use that&lt;/P&gt;</description>
      <pubDate>Fri, 21 Aug 2020 00:45:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Stats-function-with-additional-fields/m-p/515340#M144681</guid>
      <dc:creator>worldexplorer81</dc:creator>
      <dc:date>2020-08-21T00:45:10Z</dc:date>
    </item>
    <item>
      <title>Re: Stats function with additional fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Stats-function-with-additional-fields/m-p/515636#M144786</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/59546"&gt;@worldexplorer81&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I understand correctly, you want timestamp from your log entries to be used instead of the initial value of _time. So, for these entries, for example:&lt;/P&gt;&lt;TABLE border="1" width="69.38704884047132%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%"&gt;&lt;STRONG&gt;timestamp&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;&lt;STRONG&gt;jobId&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD width="16.666666666666668%"&gt;&lt;STRONG&gt;statusText&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%"&gt;&lt;FONT color="#00FF00"&gt;2020-08-20 03:18:35.0&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;&lt;FONT color="#00FF00"&gt;887395&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="16.666666666666668%"&gt;&lt;FONT color="#00FF00"&gt;SUCCESS&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%"&gt;2020-08-20 03:18:28.0&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;887395&lt;/TD&gt;&lt;TD width="16.666666666666668%"&gt;RUNNING&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%"&gt;2020-08-20 03:18:28.0&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;887395&lt;/TD&gt;&lt;TD width="16.666666666666668%"&gt;STARTING&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%"&gt;2020-08-20 03:19:35.0&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;1111&lt;/TD&gt;&lt;TD width="16.666666666666668%"&gt;RUNNING&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%"&gt;&lt;FONT color="#00FF00"&gt;2020-08-20 03:20:28.0&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;&lt;FONT color="#00FF00"&gt;1111&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="16.666666666666668%"&gt;&lt;FONT color="#00FF00"&gt;STARTING&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%"&gt;&lt;FONT color="#00FF00"&gt;2020-08-20 04:10:00.0&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;&lt;FONT color="#00FF00"&gt;2222&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="16.666666666666668%"&gt;&lt;FONT color="#00FF00"&gt;RUNNING&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%"&gt;2020-08-20 04:09:00.0&lt;/TD&gt;&lt;TD width="33.333333333333336%"&gt;2222&lt;/TD&gt;&lt;TD width="16.666666666666668%"&gt;STARTING&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Reset _time to be your timestamp:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval events="2020-08-20 03:18:35.0+887395+SUCCESS|2020-08-20 03:18:28.0+887395+RUNNING|2020-08-20 03:18:28.0+887395+STARTING|2020-08-20 03:19:35.0+1111+RUNNING|2020-08-20 03:20:28.0+1111+STARTING|2020-08-20 04:10:00.0+2222+RUNNING|2020-08-20 04:09:00.0+2222+STARTING" 
| makemv delim="|" events 
| mvexpand events 
| rex field=events "(?&amp;lt;timestamp&amp;gt;.*)\+(?&amp;lt;jobId&amp;gt;.*)\+(?&amp;lt;statusText&amp;gt;.*)"
| eval _time=strptime(timestamp, "%Y-%m-%d %H:%M:%S.0")
| stats latest(statusText) as statusText by jobId&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;By the way, this can be done when your logs are first loaded into your indexes&lt;/P&gt;&lt;P&gt;Using latest (which is based on _time) gives:&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="50%"&gt;&lt;STRONG&gt;jobId&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD width="50%"&gt;&lt;STRONG&gt;statusText&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%"&gt;1111&lt;/TD&gt;&lt;TD width="50%"&gt;STARTING&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%"&gt;2222&lt;/TD&gt;&lt;TD width="50%"&gt;RUNNING&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%"&gt;887395&lt;/TD&gt;&lt;TD width="50%"&gt;SUCCESS&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Sun, 23 Aug 2020 13:05:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Stats-function-with-additional-fields/m-p/515636#M144786</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2020-08-23T13:05:55Z</dc:date>
    </item>
    <item>
      <title>Re: Stats function with additional fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Stats-function-with-additional-fields/m-p/515813#M144831</link>
      <description>&lt;P&gt;Thanks all - I was able to resolve the issue by adding a 'sort -timestamp' before using latest(statusText)&lt;/P&gt;</description>
      <pubDate>Mon, 24 Aug 2020 15:21:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Stats-function-with-additional-fields/m-p/515813#M144831</guid>
      <dc:creator>worldexplorer81</dc:creator>
      <dc:date>2020-08-24T15:21:22Z</dc:date>
    </item>
  </channel>
</rss>

