<?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 do I find the last occurrence of a pattern in an event (based on a transaction) in Knowledge Management</title>
    <link>https://community.splunk.com/t5/Knowledge-Management/How-do-I-find-the-last-occurrence-of-a-pattern-in-an-event-based/m-p/234946#M7950</link>
    <description>&lt;P&gt;Great Answer!&lt;/P&gt;

&lt;P&gt;I was already thinking about evaluating the &lt;CODE&gt;last_state_change&lt;/CODE&gt; before the &lt;CODE&gt;transaction&lt;/CODE&gt; but didn't know that a multi-value field would be created &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Next problem was that the ordering of multi-value fields is lexical by default and not in the event order (which seems very strange to me). So I had to take a lot of steps to solve that.&lt;BR /&gt;
This is what I came up with:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| transaction whatever you want mvlist=state_change
| full_state=mvfilter(state_change!="NULL")
| eval last_state = mvindex(full_state, -1)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The &lt;CODE&gt;mvlist&lt;/CODE&gt; is necessary to get the event order&lt;BR /&gt;
The &lt;CODE&gt;mvfilter&lt;/CODE&gt; is necessary to skip NULL values, which you get if you use &lt;CODE&gt;mvlist&lt;/CODE&gt;, that I had to use "NULL" as a string was also something I didn't expect.&lt;BR /&gt;
The final &lt;CODE&gt;mvindex&lt;/CODE&gt; gives the last known state I needed&lt;/P&gt;

&lt;P&gt;TFTH!&lt;/P&gt;</description>
    <pubDate>Fri, 25 Sep 2015 13:09:32 GMT</pubDate>
    <dc:creator>RickPeters</dc:creator>
    <dc:date>2015-09-25T13:09:32Z</dc:date>
    <item>
      <title>How do I find the last occurrence of a pattern in an event (based on a transaction)</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/How-do-I-find-the-last-occurrence-of-a-pattern-in-an-event-based/m-p/234944#M7948</link>
      <description>&lt;P&gt;I have a search on a application log file which uses &lt;CODE&gt;transaction&lt;/CODE&gt; to combine several events into one based on a common transactionid.&lt;BR /&gt;
In this result &lt;STRONG&gt;I want to find the last occurrence of a certain pattern&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;Given this example transaction event:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;2015-09-24 15:16:59.473 [TaskExecutionEngine-akka.actor.default-dispatcher-15158] {taskId=d4fd6917-158d-407f-bae5-432bb44bc368, username=zijlsm, stepDescription=Running garbage collection on the repository} INFO  c.x.deployit.engine.tasker.Task - Publishing state change UNREGISTERED -&amp;gt; PENDING
2015-09-24 15:16:59.480 [TaskExecutionEngine-akka.actor.default-dispatcher-15158] {taskId=d4fd6917-158d-407f-bae5-432bb44bc368, username=zijlsm, stepDescription=Running garbage collection on the repository} INFO  c.x.deployit.engine.tasker.Task - Publishing state change PENDING -&amp;gt; QUEUED
2015-09-24 15:16:59.481 [TaskExecutionEngine-akka.actor.default-dispatcher-15158] {taskId=d4fd6917-158d-407f-bae5-432bb44bc368, username=zijlsm, stepDescription=Running garbage collection on the repository} INFO  c.x.deployit.engine.tasker.Task - Publishing state change QUEUED -&amp;gt; EXECUTING
2015-09-24 15:17:00.838 [TaskExecutionEngine-akka.actor.default-dispatcher-15158] {taskId=d4fd6917-158d-407f-bae5-432bb44bc368, username=zijlsm, stepDescription=Running garbage collection on the repository} INFO  c.x.deployit.engine.tasker.Task - Publishing state change EXECUTING -&amp;gt; EXECUTED
2015-09-24 15:17:00.838 [TaskExecutionEngine-akka.actor.default-dispatcher-15158] {taskId=d4fd6917-158d-407f-bae5-432bb44bc368, username=zijlsm, stepDescription=Running garbage collection on the repository} INFO  c.x.d.e.tasker.TaskManagingActor - Task [d4fd6917-158d-407f-bae5-432bb44bc368] is completed with state [EXECUTED]
2015-09-24 15:17:01.509 [TaskExecutionEngine-akka.actor.default-dispatcher-15158] {taskId=d4fd6917-158d-407f-bae5-432bb44bc368, username=zijlsm, stepDescription=Running garbage collection on the repository} INFO  c.x.deployit.engine.tasker.Task - Publishing state change EXECUTED -&amp;gt; DONE
2015-09-24 15:17:02.508 [TaskExecutionEngine-akka.actor.default-dispatcher-15158] {taskId=d4fd6917-158d-407f-bae5-432bb44bc368, username=zijlsm, stepDescription=Running garbage collection on the repository} INFO  c.x.d.e.tasker.TaskManagingActor - Task [d4fd6917-158d-407f-bae5-432bb44bc368] is completed with state [DONE]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I want to retrieve the last state change (in this case &lt;STRONG&gt;EXECUTED -&amp;gt; DONE&lt;/STRONG&gt; of which I need only the text &lt;STRONG&gt;DONE&lt;/STRONG&gt;)&lt;BR /&gt;
I tried several regular expression but can't get it to work &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Basic idea was looking for &lt;CODE&gt;-&amp;amp;gt;&lt;/CODE&gt; which is not followed by &lt;CODE&gt;(.*-&amp;amp;gt;.*)&lt;/CODE&gt; (anything containing -&amp;gt;) but I can't get this to work. &lt;/P&gt;

&lt;P&gt;My latest try was this &lt;CODE&gt;rex field=_raw "(?m).*(-&amp;amp;gt; )(?!(.*-&amp;amp;gt;.*))(?&amp;amp;lt;curstate&amp;amp;gt;.*)"&lt;/CODE&gt; bit this just captures the first state (&lt;STRONG&gt;PENDING&lt;/STRONG&gt;)&lt;/P&gt;

&lt;P&gt;I've been trying for quite some time now and any help would be welcome.&lt;BR /&gt;
I could try and do this without using the transaction by taking just the last event with a state transition, however I also need the other events in this transaction the don't contain state transitions but other interesting fields (hurraah for this log format in which the aplication logs using a lot of different formats and the only recurring attribute is the &lt;STRONG&gt;taskId&lt;/STRONG&gt;)&lt;/P&gt;</description>
      <pubDate>Thu, 24 Sep 2015 13:59:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/How-do-I-find-the-last-occurrence-of-a-pattern-in-an-event-based/m-p/234944#M7948</guid>
      <dc:creator>RickPeters</dc:creator>
      <dc:date>2015-09-24T13:59:23Z</dc:date>
    </item>
    <item>
      <title>Re: How do I find the last occurrence of a pattern in an event (based on a transaction)</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/How-do-I-find-the-last-occurrence-of-a-pattern-in-an-event-based/m-p/234945#M7949</link>
      <description>&lt;P&gt;If you define fields based on the events, then when you group the events into a transaction, the fields will become multi-valued.&lt;/P&gt;

&lt;P&gt;So, defining the state change field before creating your transaction might be helpful:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| your search here
| rex "state change\s*(?&amp;lt;state_change&amp;gt;.*)" 
| transaction here
| eval last_state_change = mvindex(state_change,-1)
| eval last_state_change = replace(last_state_change,".*?-\&amp;gt;\s*(.*)","\1")
| whatever you want to do next
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This picks off the last value for the state_change field and then does a replace that keeps only the portion of the field following the &lt;CODE&gt;-&amp;gt;&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;HTH!&lt;/P&gt;</description>
      <pubDate>Thu, 24 Sep 2015 17:16:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/How-do-I-find-the-last-occurrence-of-a-pattern-in-an-event-based/m-p/234945#M7949</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2015-09-24T17:16:04Z</dc:date>
    </item>
    <item>
      <title>Re: How do I find the last occurrence of a pattern in an event (based on a transaction)</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/How-do-I-find-the-last-occurrence-of-a-pattern-in-an-event-based/m-p/234946#M7950</link>
      <description>&lt;P&gt;Great Answer!&lt;/P&gt;

&lt;P&gt;I was already thinking about evaluating the &lt;CODE&gt;last_state_change&lt;/CODE&gt; before the &lt;CODE&gt;transaction&lt;/CODE&gt; but didn't know that a multi-value field would be created &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Next problem was that the ordering of multi-value fields is lexical by default and not in the event order (which seems very strange to me). So I had to take a lot of steps to solve that.&lt;BR /&gt;
This is what I came up with:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| transaction whatever you want mvlist=state_change
| full_state=mvfilter(state_change!="NULL")
| eval last_state = mvindex(full_state, -1)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The &lt;CODE&gt;mvlist&lt;/CODE&gt; is necessary to get the event order&lt;BR /&gt;
The &lt;CODE&gt;mvfilter&lt;/CODE&gt; is necessary to skip NULL values, which you get if you use &lt;CODE&gt;mvlist&lt;/CODE&gt;, that I had to use "NULL" as a string was also something I didn't expect.&lt;BR /&gt;
The final &lt;CODE&gt;mvindex&lt;/CODE&gt; gives the last known state I needed&lt;/P&gt;

&lt;P&gt;TFTH!&lt;/P&gt;</description>
      <pubDate>Fri, 25 Sep 2015 13:09:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/How-do-I-find-the-last-occurrence-of-a-pattern-in-an-event-based/m-p/234946#M7950</guid>
      <dc:creator>RickPeters</dc:creator>
      <dc:date>2015-09-25T13:09:32Z</dc:date>
    </item>
    <item>
      <title>Re: How do I find the last occurrence of a pattern in an event (based on a transaction)</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/How-do-I-find-the-last-occurrence-of-a-pattern-in-an-event-based/m-p/234947#M7951</link>
      <description>&lt;P&gt;Dang, I forgot that it sorts the multi-value fields - how annoying.  And "NULL" seems weird, can you use one of the following?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;full_state=mvfilter(isnotnull(state_change))

full_state=mvfilter(state_change!=null())
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;AFAIK, there is actually no keyword called NULL, even though that is implied in the documentation.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Sep 2015 17:47:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/How-do-I-find-the-last-occurrence-of-a-pattern-in-an-event-based/m-p/234947#M7951</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2015-09-25T17:47:10Z</dc:date>
    </item>
    <item>
      <title>Re: How do I find the last occurrence of a pattern in an event (based on a transaction)</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/How-do-I-find-the-last-occurrence-of-a-pattern-in-an-event-based/m-p/234948#M7952</link>
      <description>&lt;P&gt;Hi, I tried your suggestions:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;state_change!=null()&lt;/CODE&gt; delivers a &lt;CODE&gt;Error in 'eval' command: Typechecking failed. The '!-' operator received different types.&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;isnotnull(state_change)&lt;/CODE&gt; does not hit an error, but does not work as intended (it sees "NULL" values as real values)&lt;/P&gt;

&lt;P&gt;I really think that the conversion of the separate events into a multivalue field has some kind of error when not sorting lexically. It should not add the NULL values as strings "NULL" to the multivalue field as it seems to do now?&lt;/P&gt;

&lt;P&gt;thanks for all the help and the follow-up !&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2015 07:09:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/How-do-I-find-the-last-occurrence-of-a-pattern-in-an-event-based/m-p/234948#M7952</guid>
      <dc:creator>RickPeters</dc:creator>
      <dc:date>2015-09-28T07:09:57Z</dc:date>
    </item>
    <item>
      <title>Re: How do I find the last occurrence of a pattern in an event (based on a transaction)</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/How-do-I-find-the-last-occurrence-of-a-pattern-in-an-event-based/m-p/234949#M7953</link>
      <description>&lt;P&gt;I agree with you, that is just weird. I assume that the string "NULL" appears nowhere in the data?&lt;/P&gt;

&lt;P&gt;Quick question, how are you forming the transaction? Or better said, what are the parameters that you use to the transaction command?&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2015 21:02:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/How-do-I-find-the-last-occurrence-of-a-pattern-in-an-event-based/m-p/234949#M7953</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2015-09-28T21:02:57Z</dc:date>
    </item>
    <item>
      <title>Re: How do I find the last occurrence of a pattern in an event (based on a transaction)</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/How-do-I-find-the-last-occurrence-of-a-pattern-in-an-event-based/m-p/234950#M7954</link>
      <description>&lt;P&gt;I use this &lt;CODE&gt;transaction&lt;/CODE&gt; statement:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;transaction taskId maxpause=120m maxevents=30000 mvlist=state_change
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I'm still tuning the &lt;CODE&gt;maxpause&lt;/CODE&gt; and &lt;CODE&gt;maxevents&lt;/CODE&gt; parameters based on real transactions. These are tasks running in a task scheduler. Some of them are really long and contain lots of steps. Most of them are ready running within a few minutes, but is specific cases (error situation) a task does not end correctly and stays as a kind of zombie in the system (hence the long maxpause). It's a bit brute force, but Splunk seems to handle this pretty wel &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2015 05:42:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/How-do-I-find-the-last-occurrence-of-a-pattern-in-an-event-based/m-p/234950#M7954</guid>
      <dc:creator>RickPeters</dc:creator>
      <dc:date>2015-09-30T05:42:38Z</dc:date>
    </item>
  </channel>
</rss>

