<?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: Can we include OR/AND operator in a transaction in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Can-we-include-OR-AND-operator-in-a-transaction/m-p/405748#M117289</link>
    <description>&lt;P&gt;@amunag439 I would recommend using stats instead of transaction for this scenario&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; &amp;lt;yourCurrentCodeToGetTimeMsgAndID&amp;gt;
|  stats list(msg) as msg_all values(msg) as msg_unique min(_time) as _time max(_time) as latest_time by id
|  eval duration=latest_time-_time
|  fields - latest_time
|  eval startswith=mvindex(msg_all,0),endswith=mvindex(msg_all,mvcount(msg_all)-1)
|  fields - msg_all msg_unique
|  search startswith="Begin Process" endswith="*"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Following is a run anywhere example based on sample data and details provided. It looks only for startswith condition. Endwith any value is accepted (you can explicitly set to Success and Fail as well if there are only two final messages in your data).&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|  makeresults
|  eval _time=relative_time(now(),"-1d")
|  eval data="id=11111 msg=Begin process;id=11111 msg=check;id=11111 msg=Success;id=22222 msg=Begin process;id=22222 msg=check;id=22222 msg=Fail"
|  makemv data delim=";"
|  mvexpand data
|  rename data as _raw
|  KV
|  eval msg=replace(msg,"Begin","Begin Process")
|  eval delta_duration=random()
|  eval delta_duration=substr(delta_duration,1,3)
|  accum delta_duration
|  eval _time=_time+delta_duration
|  fields - _raw delta_duration
|  stats list(msg) as msg_all values(msg) as msg_unique min(_time) as _time max(_time) as latest_time by id
|  eval duration=latest_time-_time
|  fields - latest_time
|  eval startswith=mvindex(msg_all,0),endswith=mvindex(msg_all,mvcount(msg_all)-1)
|  fields - msg_all msg_unique
|  search startswith="Begin Process" endswith="*"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 24 Jul 2019 18:40:25 GMT</pubDate>
    <dc:creator>niketn</dc:creator>
    <dc:date>2019-07-24T18:40:25Z</dc:date>
    <item>
      <title>Can we include OR/AND operator in a transaction</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-we-include-OR-AND-operator-in-a-transaction/m-p/405747#M117288</link>
      <description>&lt;P&gt;I have the following log sets, one for success case and one for the failure case&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Success:
id=11111 msg=Begin process...
id=11111 msg=check
id=11111 msg=Success...

failure:
id=22222 msg=Begin process...
id=22222 msg=check
id=22222 msg=Fail...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Here I want to check the time between the events using the transaction.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;host=* sourcetype=** source="*/example.log" "Begin process*" OR "Success*"
  | transaction traceId startswith="Begin process" endswith="Success" 
  | table traceId duration _time
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Above query will give me the transactions of a success case only. &lt;BR /&gt;
Can we use &lt;CODE&gt;AND&lt;/CODE&gt; Operator in the &lt;CODE&gt;endswith&lt;/CODE&gt; so that I can check the duration between events irrespective of it being a success or failure?&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jul 2019 18:18:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-we-include-OR-AND-operator-in-a-transaction/m-p/405747#M117288</guid>
      <dc:creator>amunag439</dc:creator>
      <dc:date>2019-07-24T18:18:56Z</dc:date>
    </item>
    <item>
      <title>Re: Can we include OR/AND operator in a transaction</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-we-include-OR-AND-operator-in-a-transaction/m-p/405748#M117289</link>
      <description>&lt;P&gt;@amunag439 I would recommend using stats instead of transaction for this scenario&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; &amp;lt;yourCurrentCodeToGetTimeMsgAndID&amp;gt;
|  stats list(msg) as msg_all values(msg) as msg_unique min(_time) as _time max(_time) as latest_time by id
|  eval duration=latest_time-_time
|  fields - latest_time
|  eval startswith=mvindex(msg_all,0),endswith=mvindex(msg_all,mvcount(msg_all)-1)
|  fields - msg_all msg_unique
|  search startswith="Begin Process" endswith="*"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Following is a run anywhere example based on sample data and details provided. It looks only for startswith condition. Endwith any value is accepted (you can explicitly set to Success and Fail as well if there are only two final messages in your data).&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|  makeresults
|  eval _time=relative_time(now(),"-1d")
|  eval data="id=11111 msg=Begin process;id=11111 msg=check;id=11111 msg=Success;id=22222 msg=Begin process;id=22222 msg=check;id=22222 msg=Fail"
|  makemv data delim=";"
|  mvexpand data
|  rename data as _raw
|  KV
|  eval msg=replace(msg,"Begin","Begin Process")
|  eval delta_duration=random()
|  eval delta_duration=substr(delta_duration,1,3)
|  accum delta_duration
|  eval _time=_time+delta_duration
|  fields - _raw delta_duration
|  stats list(msg) as msg_all values(msg) as msg_unique min(_time) as _time max(_time) as latest_time by id
|  eval duration=latest_time-_time
|  fields - latest_time
|  eval startswith=mvindex(msg_all,0),endswith=mvindex(msg_all,mvcount(msg_all)-1)
|  fields - msg_all msg_unique
|  search startswith="Begin Process" endswith="*"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Jul 2019 18:40:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-we-include-OR-AND-operator-in-a-transaction/m-p/405748#M117289</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2019-07-24T18:40:25Z</dc:date>
    </item>
    <item>
      <title>Re: Can we include OR/AND operator in a transaction</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-we-include-OR-AND-operator-in-a-transaction/m-p/405749#M117290</link>
      <description>&lt;P&gt;@niketnilay in the failure case what if there are few more logs? if Fail is not a final log, how do we approach that?&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jul 2019 18:43:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-we-include-OR-AND-operator-in-a-transaction/m-p/405749#M117290</guid>
      <dc:creator>amunag439</dc:creator>
      <dc:date>2019-07-24T18:43:18Z</dc:date>
    </item>
    <item>
      <title>Re: Can we include OR/AND operator in a transaction</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-we-include-OR-AND-operator-in-a-transaction/m-p/405750#M117291</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/182728"&gt;@amunag439&lt;/a&gt; the query that I have provided is similar to what transaction will do when there is starts with condition but ends with can be anything.&lt;/P&gt;

&lt;P&gt;If you want other more specific conditions you will have to play with msg_unique which has all distinct values of msg field present for specific ids. Final 2 pipes need to change as follows.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  |  fields - msg_all
  |  search startswith="Begin Process" endswith="*"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;msg_unique=Success AND msg_unique=Fail.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 01:30:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-we-include-OR-AND-operator-in-a-transaction/m-p/405750#M117291</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2020-09-30T01:30:04Z</dc:date>
    </item>
    <item>
      <title>Re: Can we include OR/AND operator in a transaction</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-we-include-OR-AND-operator-in-a-transaction/m-p/405751#M117292</link>
      <description>&lt;P&gt;There is only one use case where the use of &lt;CODE&gt;transaction&lt;/CODE&gt; is merited but this command scales so poorly that I am not even going to mention it.  Stop using &lt;CODE&gt;transaction&lt;/CODE&gt;; try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;host=* sourcetype=** source="*/example.log" "Begin process*" OR "Success*" OR "Failure*"
| streamstats count(eval(searchmatch("Success* OR Failure*"))) AS sessionID BY traceId
| stats range(_time) AS duration list(_raw) AS events min(_time) AS _time BY traceId sessionID
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 26 Jul 2019 21:12:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-we-include-OR-AND-operator-in-a-transaction/m-p/405751#M117292</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-07-26T21:12:12Z</dc:date>
    </item>
  </channel>
</rss>

