<?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: Before and after values from separate events. in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Before-and-after-values-from-separate-events/m-p/697527#M236949</link>
    <description>&lt;P&gt;Amazing, worked like a charm.&amp;nbsp; &amp;nbsp;Thanks!&lt;/P&gt;</description>
    <pubDate>Tue, 27 Aug 2024 21:43:44 GMT</pubDate>
    <dc:creator>apiprek2</dc:creator>
    <dc:date>2024-08-27T21:43:44Z</dc:date>
    <item>
      <title>Before and after values from separate events.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Before-and-after-values-from-separate-events/m-p/697074#M236855</link>
      <description>&lt;P&gt;Hi, I have a log that tracks user changes to a specific field in a form. The process is as follows:&lt;/P&gt;&lt;P&gt;1. The user accesses the form, which generates a log event with "get" eventtype along with the current value of field1. This can occur several times as the user refreshes the page, or through code behind the scenes that generates an event based on how long the user stays on the page.&lt;BR /&gt;2. The user fills in the form and hits submit, which logs an event with "update" eventtype.&lt;/P&gt;&lt;P&gt;Here's a simplified list of events:&lt;/P&gt;&lt;P&gt;_time, &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; eventtype,&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; sessionid, &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; field1&lt;BR /&gt;10:06&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;update&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; session2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;newvalue3&lt;BR /&gt;10:05&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;get&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; session2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;newvalue2&lt;BR /&gt;09:15 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; update&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; session1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;newvalue2&lt;BR /&gt;09:12 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; get&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; session1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;newvalue1&lt;BR /&gt;09:10 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; get&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; session1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;newvalue1&lt;BR /&gt;09:09 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; update&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; session1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;newvalue1&lt;BR /&gt;09:02 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; get&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; session1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;oldvalue1&lt;BR /&gt;09:01 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; get&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; session1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;oldvalue1&lt;BR /&gt;08:59 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; get&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; session1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;oldvalue1&lt;/P&gt;&lt;P&gt;I'm looking to get the last value of field1 before each "update" eventtype. Basically I'd like to track what the value was before and what it was changed to, something like:&lt;/P&gt;&lt;P&gt;_time,&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Before,&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; After&lt;BR /&gt;10:06&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;newvalue2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; newvalue3&lt;BR /&gt;09:15&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;newvalue1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; newvalue2&lt;BR /&gt;09:09&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;oldvalue1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; newvalue1&lt;/P&gt;&lt;P&gt;I've tried this with a transaction command on the session, but I run into issues with the multiple instances "get" events in the same session, which makes it a little convoluted to extract the running values of field1.&amp;nbsp; I also tried this with a combination of the latest(field1) and earliest(field1), but then this misses any updates that might take place within the session - we sometimes have users who change the value and then change it back. I'd like to capture those events as well.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone have any tips on how to get this accomplished?&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 22 Aug 2024 15:17:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Before-and-after-values-from-separate-events/m-p/697074#M236855</guid>
      <dc:creator>apiprek2</dc:creator>
      <dc:date>2024-08-22T15:17:41Z</dc:date>
    </item>
    <item>
      <title>Re: Before and after values from separate events.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Before-and-after-values-from-separate-events/m-p/697107#M236856</link>
      <description>&lt;P&gt;First, thanks for clearly illustrating raw input, desired output, and the logic to get from there. &amp;nbsp;Transaction is still the easiest way to go. &amp;nbsp;You just need to keep track of which value is which eventtype.&lt;/P&gt;&lt;P&gt;Many people here are familiar with the traditional technique of using string concatenation. &amp;nbsp;I will show a more semantic approach afforded by JSON functions introduced in 8.1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rename _raw as temp ``` only if you want to preserve _raw for later ```
| tojson eventtype, field1
| transaction startswith="eventtype=get" endswith="eventtype=update"
| eval _raw = split(_raw, "
")
| eval Before = json_extract(mvindex(_raw, 0), "field1"), After = json_extract(mvindex(_raw, 1), "field1")
| rename temp as _raw ``` only if you want to preserve _raw for later ```
| fields Before, After&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note: The above is not completely semantic as I am also using the side effect of Splunk's default of lexical order.&lt;/P&gt;&lt;P&gt;Here is an emulation for you to play with and compare with real data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults format=csv data="_time,         eventtype,          sessionid,         field1
10:06,         update,                  session2,           newvalue3
10:05,         get,                          session2,           newvalue2
09:15,         update,                  session1,           newvalue2
09:12,         get,                          session1,           newvalue1
09:10,         get,                          session1,           newvalue1
09:09,         update,                  session1,           newvalue1
09:02,         get,                          session1,           oldvalue1
09:01,         get,                          session1,           oldvalue1
08:59,         get,                          session1,           oldvalue1"
| eval _time = strptime("2024-08-22T" . _time, "%FT%H:%M")
``` data emulation above ```&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output from the above search gives&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="89.5625px" height="25px"&gt;Before&lt;/TD&gt;&lt;TD width="89.578125px" height="25px"&gt;After&lt;/TD&gt;&lt;TD width="166.046875px" height="25px"&gt;_time&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="89.5625px" height="25px"&gt;newvalue2&lt;/TD&gt;&lt;TD width="89.578125px" height="25px"&gt;newvalue3&lt;/TD&gt;&lt;TD width="166.046875px" height="25px"&gt;2024-08-22 10:05:00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="89.5625px" height="25px"&gt;newvalue1&lt;/TD&gt;&lt;TD width="89.578125px" height="25px"&gt;newvalue2&lt;/TD&gt;&lt;TD width="166.046875px" height="25px"&gt;2024-08-22 09:12:00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="89.5625px" height="25px"&gt;oldvalue1&lt;/TD&gt;&lt;TD width="89.578125px" height="25px"&gt;newvalue1&lt;/TD&gt;&lt;TD width="166.046875px" height="25px"&gt;2024-08-22 09:02:00&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Fri, 23 Aug 2024 00:33:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Before-and-after-values-from-separate-events/m-p/697107#M236856</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2024-08-23T00:33:44Z</dc:date>
    </item>
    <item>
      <title>Re: Before and after values from separate events.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Before-and-after-values-from-separate-events/m-p/697527#M236949</link>
      <description>&lt;P&gt;Amazing, worked like a charm.&amp;nbsp; &amp;nbsp;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 27 Aug 2024 21:43:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Before-and-after-values-from-separate-events/m-p/697527#M236949</guid>
      <dc:creator>apiprek2</dc:creator>
      <dc:date>2024-08-27T21:43:44Z</dc:date>
    </item>
  </channel>
</rss>

