<?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: Determine the timing of a sequence of events in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Determine-the-timing-of-a-sequence-of-events/m-p/289480#M160314</link>
    <description>&lt;P&gt;Do you have some sort of transaction ID/primary key which can differentiate two cycles?&lt;/P&gt;</description>
    <pubDate>Wed, 05 Jul 2017 14:49:45 GMT</pubDate>
    <dc:creator>somesoni2</dc:creator>
    <dc:date>2017-07-05T14:49:45Z</dc:date>
    <item>
      <title>Determine the timing of a sequence of events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Determine-the-timing-of-a-sequence-of-events/m-p/289479#M160313</link>
      <description>&lt;P&gt;Hi Splunk users,&lt;/P&gt;

&lt;P&gt;I have a simple request in appearance but I have been thinking about it the whole day without figuring out how to do it with Splunk.&lt;BR /&gt;
My problem is the following: I have 4 types of events: A, B, C and D that occurs in a cycle (i.e. A then B then C then D) but I can have multiple occurences of this loop at the same time, whichi means I have logs like this :&lt;BR /&gt;
&lt;CODE&gt;A B A C B D C D&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;I know that the first B belongs to first A, etc. I thus have 2 cycles in the example above and I would like to determine the sequence duration (2 in this example), each event is of course timestamped.&lt;/P&gt;

&lt;P&gt;I tried with the &lt;CODE&gt;transaction&lt;/CODE&gt; command but it's not working as I want.&lt;/P&gt;

&lt;P&gt;tl;dr : what I want :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;A B A C B D C D
| timing  |
    | timing  |
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;What I have with &lt;CODE&gt;transaction&lt;/CODE&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;A B A C B  D C D
    |timing| 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Jul 2017 12:50:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Determine-the-timing-of-a-sequence-of-events/m-p/289479#M160313</guid>
      <dc:creator>fbehe</dc:creator>
      <dc:date>2017-07-05T12:50:03Z</dc:date>
    </item>
    <item>
      <title>Re: Determine the timing of a sequence of events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Determine-the-timing-of-a-sequence-of-events/m-p/289480#M160314</link>
      <description>&lt;P&gt;Do you have some sort of transaction ID/primary key which can differentiate two cycles?&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jul 2017 14:49:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Determine-the-timing-of-a-sequence-of-events/m-p/289480#M160314</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-07-05T14:49:45Z</dc:date>
    </item>
    <item>
      <title>Re: Determine the timing of a sequence of events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Determine-the-timing-of-a-sequence-of-events/m-p/289481#M160315</link>
      <description>&lt;P&gt;Here's a run-anywhere version of a potential solution.  Required assumption is that the event types can be identified into a single field (here called &lt;CODE&gt;mytype&lt;/CODE&gt;) prior to the &lt;CODE&gt;streamstats&lt;/CODE&gt; verb, and that exactly one of each must occur in your cycle.... &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval mytype="A B A C B D C D" 
| makemv mytype 
| mvexpand mytype
| streamstats count as recno
| eval _time=_time + recno
| fields - recno
| rename COMMENT as "The above just creates test data."

| rename COMMENT as "The solution is as below."
| streamstats count as cycleno by mytype
| transaction cycleno
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;There is an additional consideration here that may be a problem - having to identify the records belonging to the first cycle.  If the extraction starts in the middle of a cycle, these numbers won't correctly meet up.  For instance, if the search time begins at that asterisk, the first C and D will be associated wrongly with the A and B after the asterisk, rather than the one before.  I'm not sure if there is a principled solution to this, since the number of crossovers is potentially infinite.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  A B * A B C D C D
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If I recall correctly, I provided a solution for this a few months back.  It requires running a &lt;CODE&gt;streamstats&lt;/CODE&gt; or &lt;CODE&gt;accum&lt;/CODE&gt; forward across the time frame, using &lt;CODE&gt;reverse&lt;/CODE&gt; and running  a &lt;CODE&gt;streamstats&lt;/CODE&gt; or &lt;CODE&gt;accum&lt;/CODE&gt; backward across the time frame, and then adjusting the results based on the highest positive or negative numbers in each direction.   &lt;/P&gt;</description>
      <pubDate>Wed, 05 Jul 2017 18:23:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Determine-the-timing-of-a-sequence-of-events/m-p/289481#M160315</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-07-05T18:23:09Z</dc:date>
    </item>
    <item>
      <title>Re: Determine the timing of a sequence of events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Determine-the-timing-of-a-sequence-of-events/m-p/289482#M160316</link>
      <description>&lt;P&gt;Hi, I have one in another event that occurs after A, it identifies the item that is doing the cycle&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jul 2017 07:05:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Determine-the-timing-of-a-sequence-of-events/m-p/289482#M160316</guid>
      <dc:creator>fbehe</dc:creator>
      <dc:date>2017-07-06T07:05:35Z</dc:date>
    </item>
    <item>
      <title>Re: Determine the timing of a sequence of events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Determine-the-timing-of-a-sequence-of-events/m-p/289483#M160317</link>
      <description>&lt;P&gt;I tried your solution, I did not quietly understood everypart of it but strange behavior: it returned 4999 events on the last 7 days on 4498 real cycles. Also, each line returned was six times the same event.&lt;/P&gt;

&lt;P&gt;Iteratively, what I want to do is pretty simple, translation into Splunk request is harder than I thought:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;for each event:
    if event A then: //Nth event
        loop to first B
        loop to first C
        loop to first D
        Determine duration by substracting A's timestamp from D's
    //Go to next event, (N+1)th event
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Jul 2017 07:47:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Determine-the-timing-of-a-sequence-of-events/m-p/289483#M160317</guid>
      <dc:creator>fbehe</dc:creator>
      <dc:date>2017-07-06T07:47:54Z</dc:date>
    </item>
    <item>
      <title>Re: Determine the timing of a sequence of events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Determine-the-timing-of-a-sequence-of-events/m-p/289484#M160318</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I started to work on this request again and keeping in mind @somesoni2 's remark about identifiers, I have been able to work this around.&lt;/P&gt;

&lt;P&gt;So the request's principle is the following (dirty):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Make a subsearch to get all A events and their ID
Make a subsearch to get all D events and their ID
Sort results by _time descending order
Get transactions by ID starting with A and ending with D
????
Profit!
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The request is looking something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| append [
    search index etc.
    (A event or ID event for A)
    | rex get ID in a named field
    | transaction startswith="A event" endswith="ID for A event" mvlist=t
    | eval ID=mvindex(ID, 1), event=A
]
| append [
    search index etc.
    (D event or ID event for D)
    | rex get ID in a named field
    | transaction startswith="D event" endswith="ID of D event" mvlist=t
    | eval ID=mvindex(ID, 1), event=D
]
| sort - _time
| transaction ID startswith=eval(event==A) endswith=eval(event==D)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Aug 2017 07:49:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Determine-the-timing-of-a-sequence-of-events/m-p/289484#M160318</guid>
      <dc:creator>fbehe</dc:creator>
      <dc:date>2017-08-30T07:49:12Z</dc:date>
    </item>
  </channel>
</rss>

