<?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: Correlating a start and stop event with transaction in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Correlating-a-start-and-stop-event-with-transaction/m-p/15918#M2028</link>
    <description>&lt;P&gt;No dice.  I don't care about the duration field, FYI.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;2010/06/18 22:17:08.041|LS-XUBF|foo|0635A84D13|2|1CB0F33E1376C4C
2010/06/15 19:54:24.178|LS-XUCF|foo|0635A84D13|2|1CB0CC475F2180
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 23 Jun 2010 06:13:08 GMT</pubDate>
    <dc:creator>ericdp</dc:creator>
    <dc:date>2010-06-23T06:13:08Z</dc:date>
    <item>
      <title>Correlating a start and stop event with transaction</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Correlating-a-start-and-stop-event-with-transaction/m-p/15916#M2026</link>
      <description>&lt;P&gt;I'm trying to correlate start and stop events and having a much harder time than what the documentation implies in order to make sure that the correlations are accurate.  Say I have 4 events, as follows:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[service timestamp]    |[event]|[item]|[consoleID]|[logonID]|[clientTimestamp]
2010/06/18 22:17:08.041|LS-XUBF|foo   |0635A84D13 |2        |1CB0F33E1376C4C
2010/06/18 22:17:08.041|LS-XUCF|foo   |0635A84D13 |2        |1CB0F33E1DEDC8F
2010/06/15 19:54:24.178|LS-XUBF|foo   |0635A84D13 |2        |1CB0CC475A3ECA0
2010/06/15 19:54:24.178|LS-XUCF|foo   |0635A84D13 |2        |1CB0CC475F2180D
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;LS-XUBF is the start event, and LS-XUCF is the end event.  My goal is to use transaction to group them as follows:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;2010/06/15 19:54:24.178|LS-XUBF|foo|0635A84D13|2|1CB0CC475A3ECA0
2010/06/15 19:54:24.178|LS-XUCF|foo|0635A84D13|2|1CB0CC475F2180D

2010/06/18 22:17:08.041|LS-XUBF|foo|0635A84D13|2|1CB0F33E1376C4C
2010/06/18 22:17:08.041|LS-XUCF|foo|0635A84D13|2|1CB0F33E1DEDC8F
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I've tried several approaches, with limited success.  I think it has something to do with the order that the logs appear in the file, rather than the timestamps on the events.&lt;/P&gt;

&lt;P&gt;"transaction ConsoleId LogonId Item startswith=LS-XUBF endswith=LS-XUCF" sounds like exactly what I want, but it appears to not let the start event and end event have the same timestamp.  As a result, I get one transaction instead of two, with the start from the first collection and the end from the second collection.  Adding "maxevents=2" to this transaction yields the same results.  It looks like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;2010/06/15 19:54:24.178|LS-XUBF|foo|0635A84D13|2|1CB0CC475A3ECA0
2010/06/18 22:17:08.041|LS-XUCF|foo|0635A84D13|2|1CB0F33E1DEDC8F
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;"transaction ConsoleId LogonId Item maxevents=2" groups them exactly how I want, but is error prone.  It's not guaranteed that we'll see an LS-XUCF event after an LS-XUBF event.  The process could start, but never finish and never send the event (for example, if the machine doing the logging loses all power).  This is unlikely, but still possible, and I don't want my data invalidated.&lt;/P&gt;

&lt;P&gt;"transaction ConsoleId LogonId Item maxevents=2 startswith=LS-XUBF" gets me a little closer - I thought this was a perfect way to solve the above inconsistency problem, but instead, I get this, which isn't really any better:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;2010/06/18 22:17:08.041|LS-XUBF|foo|0635A84D13|2|1CB0F33E1376C4C

2010/06/15 19:54:24.178|LS-XUBF|foo|0635A84D13|2|1CB0CC475A3ECA0
2010/06/18 22:17:08.041|LS-XUCF|foo|0635A84D13|2|1CB0F33E1DEDC8F
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;"transaction ConsoleId LogonId Item maxevents=2 endswith=LS-XUCF" looks similar to the above.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;2010/06/15 19:54:24.178|LS-XUCF|foo|0635A84D13|2|1CB0CC475F2180D

2010/06/15 19:54:24.178|LS-XUBF|foo|0635A84D13|2|1CB0CC475A3ECA0
2010/06/18 22:17:08.041|LS-XUCF|foo|0635A84D13|2|1CB0F33E1DEDC8F
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;"transaction ConsoleId LogonId Item maxevents=2 endswith=LS-XUBF" gives me the right results for some reason, but I can't figure out why and this isn't technically want I want.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jun 2010 01:12:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Correlating-a-start-and-stop-event-with-transaction/m-p/15916#M2026</guid>
      <dc:creator>ericdp</dc:creator>
      <dc:date>2010-06-23T01:12:47Z</dc:date>
    </item>
    <item>
      <title>Re: Correlating a start and stop event with transaction</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Correlating-a-start-and-stop-event-with-transaction/m-p/15917#M2027</link>
      <description>&lt;P&gt;I'm wondering if your issue is due to your start/end event occurring on the same second, which could mean that the &lt;CODE&gt;transaction&lt;/CODE&gt; command is seeing these events out of order which could be breaking your startwith/endswith logic, this is just a guess based on some things I've seen before...&lt;/P&gt;

&lt;P&gt;The following is an ugly and inefficient hack, but it should prove/disprove my theory; and if correct, perhaps this will lead to a better solution.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your search | eval _time=if(searchmatch("LS-XUCF"), _time+1, _time) | sort _time | transaction ConsoleId LogonId Item startswith="LS-XUBF" endswith="LS-XUCF" | eval duration=duration-1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The basic idea is to bump your end event to occur after your start event (by shifting the end event by 1 second) and then resorting your events.  We then subtract 1 from the duration to restore the proper duration of the transaction (if you care about that field).&lt;/P&gt;

&lt;P&gt;&lt;/P&gt;&lt;HR /&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;UPDATE:&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;Whoops.  Let's try this again.  I copied your sample event logs to a file on my system to reproduce your transaction search.  And I'm now convinced that my initial suspicion is correct, but my first example search was incorrect.  (Got some of the logic wrong.)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| file /tmp/txn_test | rex "[^|]+\|(?&amp;lt;Event&amp;gt;[^|]+)\|(?&amp;lt;Item&amp;gt;[^| ]+)\s*\|(?&amp;lt;ConsoleID&amp;gt;[^| ]+)\s*\|(?&amp;lt;LogonID&amp;gt;[^| ]+)\s*\|" | eval _time=if(searchmatch("LS-XUBF"), _time+1, _time) | sort _time | transaction ConsoleId LogonId Item startswith="LS-XUBF" endswith="LS-XUCF"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;A perhaps better solution would be to not mess with &lt;CODE&gt;_time&lt;/CODE&gt; at all, but add a temporary field for sorting purposes, and then dropping it again.  Perhaps something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval start_event=if(searchmatch("LS-XUBF"),1,0) | sort _time,start_event | fields - start_event | transaction ConsoleId LogonId Item startswith="LS-XUBF" endswith="LS-XUCF"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It's arguable which approach is "better" (it all comes down to whether or not you think screwing with &lt;CODE&gt;_time&lt;/CODE&gt; is a bad idea or not) but I'll let that up to you.&lt;/P&gt;

&lt;P&gt;&lt;/P&gt;&lt;HR /&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;BTW.  I could also prove this theory using the on-the-fly &lt;CODE&gt;file&lt;/CODE&gt; technique by simply moving the start/end events up and down.  Which is essentially what we are doing with the &lt;CODE&gt;sort&lt;/CODE&gt;.  Remember that splunk returns all events in reverse time order (so latest events are first.)  Therefore in your original sample listing the end events actually occur before the start events.&lt;/P&gt;

&lt;P&gt;For the sake of clarity, when I used this as the contents of my &lt;CODE&gt;/tmp/txn_test&lt;/CODE&gt; file:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;2010/06/18 22:17:08.041|LS-XUCF|foo   |0635A84D13 |2        |1CB0F33E1DEDC8F
2010/06/18 22:17:08.041|LS-XUBF|foo   |0635A84D13 |2        |1CB0F33E1376C4C
2010/06/15 19:54:24.178|LS-XUCF|foo   |0635A84D13 |2        |1CB0CC475F2180D
2010/06/15 19:54:24.178|LS-XUBF|foo   |0635A84D13 |2        |1CB0CC475A3ECA0
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And used this search:  (and I got the correct results)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| file /tmp/txn_test | rex "[^|]+\|(?&amp;lt;Event&amp;gt;[^|]+)\|(?&amp;lt;Item&amp;gt;[^| ]+)\s*\|(?&amp;lt;ConsoleID&amp;gt;[^| ]+)\s*\|(?&amp;lt;LogonID&amp;gt;[^| ]+)\s*\|" | transaction ConsoleId LogonId Item startswith="LS-XUBF" endswith="LS-XUCF"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I am curious as to why your events are out of order in the first place. I thought that splunk preserved the proper order of your events. (I'm not certain of this.)  I'm assuming that in your actual log file that the LS-XUBF line occurs before the LS-XUCF line.  Are you using a load balancer / distributed search?&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jun 2010 02:22:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Correlating-a-start-and-stop-event-with-transaction/m-p/15917#M2027</guid>
      <dc:creator>Lowell</dc:creator>
      <dc:date>2010-06-23T02:22:06Z</dc:date>
    </item>
    <item>
      <title>Re: Correlating a start and stop event with transaction</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Correlating-a-start-and-stop-event-with-transaction/m-p/15918#M2028</link>
      <description>&lt;P&gt;No dice.  I don't care about the duration field, FYI.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;2010/06/18 22:17:08.041|LS-XUBF|foo|0635A84D13|2|1CB0F33E1376C4C
2010/06/15 19:54:24.178|LS-XUCF|foo|0635A84D13|2|1CB0CC475F2180
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 23 Jun 2010 06:13:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Correlating-a-start-and-stop-event-with-transaction/m-p/15918#M2028</guid>
      <dc:creator>ericdp</dc:creator>
      <dc:date>2010-06-23T06:13:08Z</dc:date>
    </item>
    <item>
      <title>Re: Correlating a start and stop event with transaction</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Correlating-a-start-and-stop-event-with-transaction/m-p/15919#M2029</link>
      <description>&lt;P&gt;Whoops.  There was a typo in my first suggestion.  See the update below.  I ran the test on my system, so it should work for you.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jun 2010 21:48:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Correlating-a-start-and-stop-event-with-transaction/m-p/15919#M2029</guid>
      <dc:creator>Lowell</dc:creator>
      <dc:date>2010-06-23T21:48:16Z</dc:date>
    </item>
    <item>
      <title>Re: Correlating a start and stop event with transaction</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Correlating-a-start-and-stop-event-with-transaction/m-p/15920#M2030</link>
      <description>&lt;P&gt;I've tried simply using "| sort clientTimestamp" which appears to sort it properly, but I still get the same issue.  If I use the sort command, should they show up in effectively reverse order, or in the order I expect them?  i.e. should the event that happened chronologically first be at the top or bottom of the results list?&lt;/P&gt;</description>
      <pubDate>Fri, 25 Jun 2010 03:49:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Correlating-a-start-and-stop-event-with-transaction/m-p/15920#M2030</guid>
      <dc:creator>ericdp</dc:creator>
      <dc:date>2010-06-25T03:49:59Z</dc:date>
    </item>
    <item>
      <title>Re: Correlating a start and stop event with transaction</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Correlating-a-start-and-stop-event-with-transaction/m-p/15921#M2031</link>
      <description>&lt;P&gt;You should see the latest events at the top (splunk stores events in reverse time order, and &lt;CODE&gt;transaction&lt;/CODE&gt; assumes this.)  Therefore in the web view, you must see the &lt;CODE&gt;LS-XUCF&lt;/CODE&gt; (end) events appearing above the &lt;CODE&gt;LS-XUBF&lt;/CODE&gt; (start) events for your &lt;CODE&gt;transaction&lt;/CODE&gt; to work.  Here is what gets even more confusing (at least at first):  When looking at the output of the transaction command, each individual transaction will show the individual events in normal time order, so you will see the first event first, and the later events at the end; but the transactions themselves are in reverse time order.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Jun 2010 20:16:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Correlating-a-start-and-stop-event-with-transaction/m-p/15921#M2031</guid>
      <dc:creator>Lowell</dc:creator>
      <dc:date>2010-06-25T20:16:46Z</dc:date>
    </item>
  </channel>
</rss>

