<?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 Why is transaction not working when finding time between events? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Why-is-transaction-not-working-when-finding-time-between-events/m-p/635423#M220760</link>
    <description>&lt;P&gt;I'm new to Splunk, so apologies if this is a silly question.&lt;/P&gt;
&lt;P&gt;I have a log file that reads:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="c"&gt;2023-03-22 00:57:09,517 INFO  TestScript - Generating reports with date of 20230321 and thread pool size of 5
...
...
2023-03-22 00:59:23,681 INFO  MultiTestScript - Multi Test report generation completed successfully!&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and I am trying to extract the elapsed time between these two events.&lt;/P&gt;
&lt;P&gt;If I try this search&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;&amp;lt;search terms&amp;gt; | transaction startswith="Generating reports" endswith="report generation completed"&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I get no results found.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I search for the two halves of the transaction separately, i.e.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;&amp;lt;search terms&amp;gt; | transaction startswith="Generating reports"&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;&amp;lt;search terms&amp;gt; | transaction endswith="report generation completed"&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the search returns the appropriate part of the log file.&lt;/P&gt;
&lt;P&gt;As soon I combine the startswith= and endswith= fields in a single search, however, I get no results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This query works properly with another log file. The only difference I can see between the files is that the file that works contains multiple transactions (i.e. "Generating report"/"report generation completed" pairs) while the files that won't work contain only one.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 22 Mar 2023 20:25:05 GMT</pubDate>
    <dc:creator>algol2</dc:creator>
    <dc:date>2023-03-22T20:25:05Z</dc:date>
    <item>
      <title>Why is transaction not working when finding time between events?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-transaction-not-working-when-finding-time-between-events/m-p/635423#M220760</link>
      <description>&lt;P&gt;I'm new to Splunk, so apologies if this is a silly question.&lt;/P&gt;
&lt;P&gt;I have a log file that reads:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="c"&gt;2023-03-22 00:57:09,517 INFO  TestScript - Generating reports with date of 20230321 and thread pool size of 5
...
...
2023-03-22 00:59:23,681 INFO  MultiTestScript - Multi Test report generation completed successfully!&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and I am trying to extract the elapsed time between these two events.&lt;/P&gt;
&lt;P&gt;If I try this search&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;&amp;lt;search terms&amp;gt; | transaction startswith="Generating reports" endswith="report generation completed"&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I get no results found.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I search for the two halves of the transaction separately, i.e.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;&amp;lt;search terms&amp;gt; | transaction startswith="Generating reports"&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;&amp;lt;search terms&amp;gt; | transaction endswith="report generation completed"&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the search returns the appropriate part of the log file.&lt;/P&gt;
&lt;P&gt;As soon I combine the startswith= and endswith= fields in a single search, however, I get no results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This query works properly with another log file. The only difference I can see between the files is that the file that works contains multiple transactions (i.e. "Generating report"/"report generation completed" pairs) while the files that won't work contain only one.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Mar 2023 20:25:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-transaction-not-working-when-finding-time-between-events/m-p/635423#M220760</guid>
      <dc:creator>algol2</dc:creator>
      <dc:date>2023-03-22T20:25:05Z</dc:date>
    </item>
    <item>
      <title>Re: Can't get transaction to work when finding time between events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-transaction-not-working-when-finding-time-between-events/m-p/635428#M220763</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/254996"&gt;@algol2&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;That's a bit strange, for sure.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Try adding the following parameters and see if that makes a difference...&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| transaction maxevents=2 keepevicted=true keeporphans=true startswith="Generating reports" endswith="report generation completed" &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;BR /&gt;&lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Transaction?ref=hk" target="_blank"&gt;https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Transaction?ref=hk&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Hope it helps&lt;/P&gt;</description>
      <pubDate>Wed, 22 Mar 2023 01:05:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-transaction-not-working-when-finding-time-between-events/m-p/635428#M220763</guid>
      <dc:creator>yeahnah</dc:creator>
      <dc:date>2023-03-22T01:05:46Z</dc:date>
    </item>
    <item>
      <title>Re: Can't get transaction to work when finding time between events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-transaction-not-working-when-finding-time-between-events/m-p/635429#M220764</link>
      <description>&lt;P&gt;Hey,&lt;/P&gt;&lt;P&gt;It certainly made a difference, the search now returns thousands of hits.&amp;nbsp; It looks like it returns the lines I want, but also everything in between, in two-line chunks.&lt;/P&gt;&lt;P&gt;I removed the&amp;nbsp;maxevents=2 argument, which reduces the hit count to 11, but Splunk is still gathering up all these extra entries that don't contain the startswith= or endswith= terms.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Mar 2023 01:14:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-transaction-not-working-when-finding-time-between-events/m-p/635429#M220764</guid>
      <dc:creator>algol2</dc:creator>
      <dc:date>2023-03-22T01:14:52Z</dc:date>
    </item>
    <item>
      <title>Re: Can't get transaction to work when finding time between events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-transaction-not-working-when-finding-time-between-events/m-p/635431#M220766</link>
      <description>&lt;P&gt;The transaction command works best when there is a key field (e.g. correlation ID) shared between events that tie the events together.&amp;nbsp; In this case it can only go on time order, which, depending on what is logging the output, may not be a very reliable way to pair events.&lt;BR /&gt;&lt;BR /&gt;It really comes down to what you are trying to achieve.&amp;nbsp; Is it just the total time between the first event (startswith) and the very last event (endswith)?&amp;nbsp; If so, then something like the stats command would be better and far more efficient...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;search term ... ("Generating reports") OR ("report generation completed")
| eval type=if(searchmatch("Generating reports"), "startswith", "endswith")
| stats min(eval(if(type="startswith", _time, ""))) AS start
        max(eval(if(type="endswith", _time, ""))) AS end
| eval duration=end - start
      ,duration_hm=tostring(duration, "duration")
| foreach start end [ eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;=strftime('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;', "%c") ]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;It's important to be clear in what you are aiming to achieve.&lt;BR /&gt;&lt;BR /&gt;Hope this helps&lt;BR /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Mar 2023 01:53:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-transaction-not-working-when-finding-time-between-events/m-p/635431#M220766</guid>
      <dc:creator>yeahnah</dc:creator>
      <dc:date>2023-03-22T01:53:33Z</dc:date>
    </item>
  </channel>
</rss>

