<?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: pick the last value in an array? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/pick-the-last-value-in-an-array/m-p/477605#M134018</link>
    <description>&lt;PRE&gt;&lt;CODE&gt;sourcetype="linux_messages_syslog" uuid="*" 
| reverse
| stats min(_time) as _time count as eventcount range(_time) as duration list(status) as status by uuid
| table _time duration eventcount status
| rex field=status mode=sed "s/started//g"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you do not care &lt;EM&gt;status&lt;/EM&gt; order, change from &lt;CODE&gt;list()&lt;/CODE&gt;  to &lt;CODE&gt;values()&lt;/CODE&gt; .&lt;/P&gt;</description>
    <pubDate>Sat, 22 Feb 2020 06:57:30 GMT</pubDate>
    <dc:creator>to4kawa</dc:creator>
    <dc:date>2020-02-22T06:57:30Z</dc:date>
    <item>
      <title>pick the last value in an array?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/pick-the-last-value-in-an-array/m-p/477601#M134014</link>
      <description>&lt;P&gt;(Apologies in advance since I am not even sure what question to ask and how to ask it. I'll rewrite it once I get a better idea of how to ask it.)&lt;/P&gt;

&lt;P&gt;Grouping events via &lt;CODE&gt;transaction&lt;/CODE&gt; correctly produces multiple results for some fields:&lt;/P&gt;

&lt;P&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/8440i41F1249823B360A9/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;The problem is that certain standard functions such as color formatting (e.g. make "failed" cells red) and post-transaction filtering (e.g. &lt;CODE&gt;search status!=success&lt;/CODE&gt;) on that field no longer work.&lt;/P&gt;

&lt;P&gt;How do I remove the "started" value from the values in the &lt;CODE&gt;status&lt;/CODE&gt; field? Or perhaps, how do I evaluate a new field such as &lt;CODE&gt;last_status&lt;/CODE&gt; that is equal to the &lt;CODE&gt;status&lt;/CODE&gt; value in the last event in the group?&lt;/P&gt;

&lt;P&gt;(I've looked at the related questions and Splunk docs and the solutions - mostly using &lt;CODE&gt;mvexpand&lt;/CODE&gt; and similar commands, and couldn 't figure out how to extract single values out of what appears to be an array of them.&lt;/P&gt;

&lt;P&gt;The search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="linux_messages_syslog" uuid="*" 
| transaction uuid
| table _time duration eventcount status
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;P.S. Please assume &lt;CODE&gt;transaction&lt;/CODE&gt; is a must and I cannot use &lt;CODE&gt;stats&lt;/CODE&gt; instead of it.&lt;/P&gt;

&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Sat, 22 Feb 2020 02:27:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/pick-the-last-value-in-an-array/m-p/477601#M134014</guid>
      <dc:creator>mitag</dc:creator>
      <dc:date>2020-02-22T02:27:59Z</dc:date>
    </item>
    <item>
      <title>Re: pick the last value in an array?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/pick-the-last-value-in-an-array/m-p/477602#M134015</link>
      <description>&lt;P&gt;The short answer is that &lt;CODE&gt;mvindex (status, -1)&lt;/CODE&gt; seems to provide the last value in a field (&lt;CODE&gt;status&lt;/CODE&gt; in this case) that contains an array of values.&lt;/P&gt;

&lt;P&gt;To expand:&lt;/P&gt;

&lt;P&gt;Looks like this modified search gives me the last value in a field containing an array of them:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="linux_messages_syslog" uuid="*" 
| transaction uuid
| eval status_last = mvindex (status, -1)
| table _time duration eventcount status_last
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;... and I have yet to figure out how to remove "started" from the array altogether. Something like this in Python:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;list(filter(lambda a: a != "started", status))
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 22 Feb 2020 02:48:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/pick-the-last-value-in-an-array/m-p/477602#M134015</guid>
      <dc:creator>mitag</dc:creator>
      <dc:date>2020-02-22T02:48:03Z</dc:date>
    </item>
    <item>
      <title>Re: pick the last value in an array?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/pick-the-last-value-in-an-array/m-p/477603#M134016</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;....
| streamstats window=1 last(status) as last_status
| eval status=if(last_status="started",mvindex(status,0,mvcount(status)-2),status)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;CODE&gt;P.S. Please assume transaction is a must&lt;/CODE&gt; OK, I see. but,&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="linux_messages_syslog" uuid="*"
| reverse
| stats min(_time) as _time count as eventcount range(_time) as duration list(status) as status by uuid
| table _time duration eventcount status
| streamstats window=1 last(status) as last_status
| eval status=if(last_status="started",mvindex(status,0,mvcount(status)-2),status)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 22 Feb 2020 02:53:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/pick-the-last-value-in-an-array/m-p/477603#M134016</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-02-22T02:53:11Z</dc:date>
    </item>
    <item>
      <title>Re: pick the last value in an array?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/pick-the-last-value-in-an-array/m-p/477604#M134017</link>
      <description>&lt;P&gt;Thank you! Your stats version is about twice as fast as the "transaction" one:&lt;/P&gt;

&lt;P&gt;Transaction:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;This search has completed and has returned 96 results by scanning 7,295 events in 0.936 seconds
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Stats:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;This search has completed and has returned 96 results by scanning 7,295 events in 0.487 seconds
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Would you have an idea how to remove "started" from the table altogether?&lt;/P&gt;</description>
      <pubDate>Sat, 22 Feb 2020 05:49:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/pick-the-last-value-in-an-array/m-p/477604#M134017</guid>
      <dc:creator>mitag</dc:creator>
      <dc:date>2020-02-22T05:49:27Z</dc:date>
    </item>
    <item>
      <title>Re: pick the last value in an array?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/pick-the-last-value-in-an-array/m-p/477605#M134018</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;sourcetype="linux_messages_syslog" uuid="*" 
| reverse
| stats min(_time) as _time count as eventcount range(_time) as duration list(status) as status by uuid
| table _time duration eventcount status
| rex field=status mode=sed "s/started//g"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you do not care &lt;EM&gt;status&lt;/EM&gt; order, change from &lt;CODE&gt;list()&lt;/CODE&gt;  to &lt;CODE&gt;values()&lt;/CODE&gt; .&lt;/P&gt;</description>
      <pubDate>Sat, 22 Feb 2020 06:57:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/pick-the-last-value-in-an-array/m-p/477605#M134018</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-02-22T06:57:30Z</dc:date>
    </item>
  </channel>
</rss>

