<?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: Transaction - setting finish time to the start of next transaction in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Transaction-setting-finish-time-to-the-start-of-next-transaction/m-p/342551#M101469</link>
    <description>&lt;P&gt;@eli_mz, you can use &lt;CODE&gt;streamstats&lt;/CODE&gt; command with &lt;CODE&gt;current=f&lt;/CODE&gt; and &lt;CODE&gt;window=1&lt;/CODE&gt; settings, to get previous/next value of a field provided it is sorted ascending/descending based on time as per your need.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index="network" sourcetype="DNS" "Updating DNS information" 
     [ search index="network" sourcetype="DNS" "Updating DNS information" host_name=MY_COMPUTER 
     | table host_ip 
     | format] 
| stats first(_time) as start_time by host_ip host_name
| sort - start_time 
| streamstats current=f window=1 last(start_time) as end_time
| eval duration=end_time-start_time
| fieldformat start_time=strftime(start_time,"%c")
| fieldformat end_time=strftime(end_time,"%c")
| table host_ip host_name start_time end_time
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You should also try to move away from transaction to stats to improve performance of your query. You can also use &lt;CODE&gt;min(_time)&lt;/CODE&gt; instead of &lt;CODE&gt;first(_time)&lt;/CODE&gt; in your stats command.&lt;/P&gt;</description>
    <pubDate>Fri, 03 Nov 2017 07:50:42 GMT</pubDate>
    <dc:creator>niketn</dc:creator>
    <dc:date>2017-11-03T07:50:42Z</dc:date>
    <item>
      <title>Transaction - setting finish time to the start of next transaction</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Transaction-setting-finish-time-to-the-start-of-next-transaction/m-p/342550#M101468</link>
      <description>&lt;P&gt;Is it possible to set the end time in a transaction to the start time of the next transaction? So instead of "&lt;STRONG&gt;end_time=_time+duration&lt;/STRONG&gt;" I'd want "&lt;STRONG&gt;end_time=start_of_next_transaction&lt;/STRONG&gt;" (if only that would work! &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt; ). &lt;/P&gt;

&lt;P&gt;I'm trying to write a search (part of a larger search) that will give me the IP address of a host and the date\time that host had said IP address based on DNS logs. I've written the search below that gives me the start and "false" end time of when the host would have had an IP associated with it according to DNS. The assumption I'm making is that the IP will be tied to the host until a new host registers in DNS to that IP, but the transaction below give an end time of the last time the host refreshed in DNS (so the start of the last session). &lt;/P&gt;

&lt;P&gt;Here's an example of the raw logs I'm working with.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;2017-10-20T00:02:10.739976-05:00 198.172.82.22 dns-dnsupdated[12593]: Updating DNS information for MY_COMPUTER-192193176212.st.domain.com:192.193.176.212 which previously had the hostname MY_COMPUTER-1.st.domain.com.&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;Search string:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="network" sourcetype="DNS" "Updating DNS information" 
    [ search index="network" sourcetype="DNS" "Updating DNS information" host_name=MY_COMPUTER 
    | table host_ip 
    | format] 
| transaction host_name 
| eval start_time=_time 
| eval end_time=_time+duration 
| convert ctime(start_time) ctime(end_time)
| search host_name=MY_COMPUTER
| table start_time, end_time, host_name, host_ip
| sort host_ip
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Sep 2020 16:33:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Transaction-setting-finish-time-to-the-start-of-next-transaction/m-p/342550#M101468</guid>
      <dc:creator>eli_mz</dc:creator>
      <dc:date>2020-09-29T16:33:38Z</dc:date>
    </item>
    <item>
      <title>Re: Transaction - setting finish time to the start of next transaction</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Transaction-setting-finish-time-to-the-start-of-next-transaction/m-p/342551#M101469</link>
      <description>&lt;P&gt;@eli_mz, you can use &lt;CODE&gt;streamstats&lt;/CODE&gt; command with &lt;CODE&gt;current=f&lt;/CODE&gt; and &lt;CODE&gt;window=1&lt;/CODE&gt; settings, to get previous/next value of a field provided it is sorted ascending/descending based on time as per your need.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index="network" sourcetype="DNS" "Updating DNS information" 
     [ search index="network" sourcetype="DNS" "Updating DNS information" host_name=MY_COMPUTER 
     | table host_ip 
     | format] 
| stats first(_time) as start_time by host_ip host_name
| sort - start_time 
| streamstats current=f window=1 last(start_time) as end_time
| eval duration=end_time-start_time
| fieldformat start_time=strftime(start_time,"%c")
| fieldformat end_time=strftime(end_time,"%c")
| table host_ip host_name start_time end_time
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You should also try to move away from transaction to stats to improve performance of your query. You can also use &lt;CODE&gt;min(_time)&lt;/CODE&gt; instead of &lt;CODE&gt;first(_time)&lt;/CODE&gt; in your stats command.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Nov 2017 07:50:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Transaction-setting-finish-time-to-the-start-of-next-transaction/m-p/342551#M101469</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-11-03T07:50:42Z</dc:date>
    </item>
    <item>
      <title>Re: Transaction - setting finish time to the start of next transaction</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Transaction-setting-finish-time-to-the-start-of-next-transaction/m-p/342552#M101470</link>
      <description>&lt;P&gt;Thanks @niketnilay; I believe that should do it. I wasn't aware of the streamstats command; it looks like what I'm after is almost exactly what is shown in example 8 of the documentation of it as well! &lt;/P&gt;</description>
      <pubDate>Mon, 06 Nov 2017 13:44:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Transaction-setting-finish-time-to-the-start-of-next-transaction/m-p/342552#M101470</guid>
      <dc:creator>eli_mz</dc:creator>
      <dc:date>2017-11-06T13:44:45Z</dc:date>
    </item>
  </channel>
</rss>

