<?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: How to compare values of a field in a transaction? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-values-of-a-field-in-a-transaction/m-p/238165#M70755</link>
    <description>&lt;P&gt;Thanks. I believe part of your answer will work but, some parts may not. For example, the field, &lt;CODE&gt;yourField&lt;/CODE&gt; will not be a numerical value. It will be a string(IP address) I would like to compare the different &lt;CODE&gt;yourField&lt;/CODE&gt;s in the transaction and if there are more than one, &lt;CODE&gt;newField&lt;/CODE&gt; will become "Multiple Sources"&lt;/P&gt;

&lt;P&gt;EDIT: Is it possible to do the transaction_hour down to half an hour too? Is it like this?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval transaction_hour=strftime(_time,"%H%M")
| eval nighttime=if(transaction_hour&amp;gt;=1800 OR transaction_hour&amp;lt;=0830,"yes","no")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 17 Aug 2016 00:30:37 GMT</pubDate>
    <dc:creator>ZacEsa</dc:creator>
    <dc:date>2016-08-17T00:30:37Z</dc:date>
    <item>
      <title>How to compare values of a field in a transaction?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-values-of-a-field-in-a-transaction/m-p/238163#M70753</link>
      <description>&lt;P&gt;Is it possible to compare values in a transaction?&lt;/P&gt;

&lt;P&gt;I have a transaction with maxspan of 5 minutes, which group events which happened within 5 minutes of each other.&lt;/P&gt;

&lt;P&gt;I want to compare the values of a field inside the transaction, and if the fields are similar, it will create a new value in a new field.&lt;/P&gt;

&lt;P&gt;EDIT: I also want to check if the transactions happen between a certain time range, e.g. 8pm to 5am, and if it falls in the time range, create a new value in a new field too.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Aug 2016 11:15:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-values-of-a-field-in-a-transaction/m-p/238163#M70753</guid>
      <dc:creator>ZacEsa</dc:creator>
      <dc:date>2016-08-16T11:15:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare values of a field in a transaction?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-values-of-a-field-in-a-transaction/m-p/238164#M70754</link>
      <description>&lt;P&gt;Yes, it is possible. However, you haven't given enough information for me to provide detailed information on how to do it. So here is some general information that may help&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; yoursearchhere
| transaction whatever here maxspan=5m
| eval transaction_hour=strftime(_time,"%H")
| eval nighttime=if(transaction_hour&amp;gt;=20 OR transaction_hour&amp;lt;=5,"yes","no")
| eval diff=mvindex(yourField,0) - mvindex(yourField,-1)
| eval newField=if(diff&amp;lt;10,"newValue",null())
| eval newField=if(isnull(mvindex(yourField,0)) OR isnull(mvindex(yourField,-1)),null(),newField)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;with a line by line explanation:&lt;BR /&gt;
line 3 - _time represents the start time of the transaction. From _time, extract the hour.&lt;BR /&gt;
line 4 - if the hour is between 8 pm and 5 am, set the new field "nighttime" to yes, otherwise set it to no&lt;BR /&gt;
line 5 - for a field named "yourField," calculate the difference between the first event in the transaction and the last event in the transaction&lt;BR /&gt;
line 6 - if the difference is less than 10, create a new field and set it to "newValue" otherwise, set the field to null&lt;BR /&gt;
line 7 - also set the newField to null if yourField was null in either the first event or the last event of the transaction&lt;/P&gt;

&lt;P&gt;HTH&lt;/P&gt;</description>
      <pubDate>Tue, 16 Aug 2016 20:23:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-values-of-a-field-in-a-transaction/m-p/238164#M70754</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2016-08-16T20:23:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare values of a field in a transaction?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-values-of-a-field-in-a-transaction/m-p/238165#M70755</link>
      <description>&lt;P&gt;Thanks. I believe part of your answer will work but, some parts may not. For example, the field, &lt;CODE&gt;yourField&lt;/CODE&gt; will not be a numerical value. It will be a string(IP address) I would like to compare the different &lt;CODE&gt;yourField&lt;/CODE&gt;s in the transaction and if there are more than one, &lt;CODE&gt;newField&lt;/CODE&gt; will become "Multiple Sources"&lt;/P&gt;

&lt;P&gt;EDIT: Is it possible to do the transaction_hour down to half an hour too? Is it like this?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval transaction_hour=strftime(_time,"%H%M")
| eval nighttime=if(transaction_hour&amp;gt;=1800 OR transaction_hour&amp;lt;=0830,"yes","no")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 Aug 2016 00:30:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-values-of-a-field-in-a-transaction/m-p/238165#M70755</guid>
      <dc:creator>ZacEsa</dc:creator>
      <dc:date>2016-08-17T00:30:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare values of a field in a transaction?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-values-of-a-field-in-a-transaction/m-p/238166#M70756</link>
      <description>&lt;P&gt;If it only 1 field you want to compare, you can do the normal dedup. Like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;yoursearchhere
 | transaction whatever here maxspan=5m
 | eval transaction_hour=strftime(_time,"%H")
 | eval nighttime=if(transaction_hour&amp;gt;=20 OR transaction_hour&amp;lt;=5,"yes","no")
 | streamstats count
 | mvexpand yourField
 | dedup count yourField
 | mvcombine yourField
 | eval newField=if(mvcount(yourField)&amp;gt;1, "Multi Source", "Single Source")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 Aug 2016 00:54:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-values-of-a-field-in-a-transaction/m-p/238166#M70756</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-08-17T00:54:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare values of a field in a transaction?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-values-of-a-field-in-a-transaction/m-p/238167#M70757</link>
      <description>&lt;P&gt;Unfortunately, it's not only one field.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Aug 2016 01:21:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-values-of-a-field-in-a-transaction/m-p/238167#M70757</guid>
      <dc:creator>ZacEsa</dc:creator>
      <dc:date>2016-08-17T01:21:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare values of a field in a transaction?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-values-of-a-field-in-a-transaction/m-p/238168#M70758</link>
      <description>&lt;P&gt;Try this approach &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;yoursearchhere
| bin span=5m _time
| eval whatever=_time."#".whatever
| stats span=5m values(yourField1) as yourField1 values(yourField2) as yourField2  by whatever
| eval transaction_hour=strftime(_time,"%H")
| eval nighttime=if(transaction_hour&amp;gt;=20 OR transaction_hour&amp;lt;=5,"yes","no")
| eval newField=if(mvcount(yourField1)&amp;gt;1, "Multi Source", "Single Source")
| rex field="whatever" "(?&amp;lt;_time&amp;gt;[^#]+)#(?&amp;lt;whatever&amp;gt;.*)"
| fields _time whatever yourField1 yourField2 etc
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 Aug 2016 01:46:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-values-of-a-field-in-a-transaction/m-p/238168#M70758</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-08-17T01:46:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare values of a field in a transaction?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-values-of-a-field-in-a-transaction/m-p/238169#M70759</link>
      <description>&lt;P&gt;Thanks! I just needed the&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval newField=if(mvcount(yourField1)&amp;gt;1, "Multi Source", "Single Source")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 Aug 2016 02:45:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-values-of-a-field-in-a-transaction/m-p/238169#M70759</guid>
      <dc:creator>ZacEsa</dc:creator>
      <dc:date>2016-08-17T02:45:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare values of a field in a transaction?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-values-of-a-field-in-a-transaction/m-p/238170#M70760</link>
      <description>&lt;P&gt;Yeah, I missed that. Please accept this answer to close it out.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Aug 2016 02:50:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-values-of-a-field-in-a-transaction/m-p/238170#M70760</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-08-17T02:50:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare values of a field in a transaction?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-values-of-a-field-in-a-transaction/m-p/238171#M70761</link>
      <description>&lt;P&gt;But I got part of the answer from yours and part of the answer from the other answer. &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Aug 2016 02:54:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-values-of-a-field-in-a-transaction/m-p/238171#M70761</guid>
      <dc:creator>ZacEsa</dc:creator>
      <dc:date>2016-08-17T02:54:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare values of a field in a transaction?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-values-of-a-field-in-a-transaction/m-p/238172#M70762</link>
      <description>&lt;P&gt;@ZacEsa, pick the answer closest to the one that worked and post the final query you used. This will help other users with similar situation find the right answer faster. That's what this community is about. &lt;/P&gt;

&lt;P&gt;The two answers here have one basic difference, one uses the &lt;CODE&gt;transaction&lt;/CODE&gt; (@lguinn) to group events, the other uses &lt;CODE&gt;bin&lt;/CODE&gt; + &lt;CODE&gt;stats&lt;/CODE&gt; to group events.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Aug 2016 10:52:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-values-of-a-field-in-a-transaction/m-p/238172#M70762</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-08-17T10:52:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare values of a field in a transaction?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compare-values-of-a-field-in-a-transaction/m-p/238173#M70763</link>
      <description>&lt;P&gt;Here's what I did. I took part of the two answers on this question and came up with the solution.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;mysearch
| transaction devicename maxspan=5m
| eval transaction_period=strftime(_time,"%H%M")
| eval nighttime=if(transaction_period&amp;gt;=1800 OR transaction_period&amp;lt;=0830, "After Office Hours", "")
| eval attemptcount=if(eventcount&amp;gt;1, "Multiple Attempts", "")
| eval srccount=if(mvcount(srcip)&amp;gt;1, "Multiple Sources", "")
| eval hits=nighttime . "," . attemptcount . "," . srccount
| eval hits=split(hits, ",")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Explanation;&lt;/P&gt;

&lt;P&gt;Line 3 takes the hours and minutes from the time.&lt;BR /&gt;
Line 4 checks if the 24hour time is between 1800 and 0830. If it is, output will be &lt;CODE&gt;After Office Hours&lt;/CODE&gt; else, it will be blank.&lt;BR /&gt;
Line 5 checks if the count within the 5 minutes of transactions is more than 1, if it is, output will be &lt;CODE&gt;Multiple Attempts&lt;/CODE&gt; else, it will be blank.&lt;BR /&gt;
Line 6 checks if there are multiple source IPs in the transaction. If there is, output will be &lt;CODE&gt;Multiple Sources&lt;/CODE&gt; else, it will be blank.&lt;BR /&gt;
Line 7 combines all the outputs into a single field so that I can show it in one field. If used without Line 8, it will show as &lt;CODE&gt;After Office Hours,Multiple Attempts, Multiple Sources&lt;/CODE&gt; if all hits are fulfilled.&lt;BR /&gt;
Line 8 splits by using "," as a delimiter so, the output will be on separate lines as such;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;After Office Hours
Multiple Attempts
Multiple Sources
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you are wondering why I'm using &lt;CODE&gt;""&lt;/CODE&gt; instead of &lt;CODE&gt;null()&lt;/CODE&gt;, it's because if I use &lt;CODE&gt;null()&lt;/CODE&gt;, when I combine the fields, it will show nothing even if only one of the field is &lt;CODE&gt;null()&lt;/CODE&gt;.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Aug 2016 01:52:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compare-values-of-a-field-in-a-transaction/m-p/238173#M70763</guid>
      <dc:creator>ZacEsa</dc:creator>
      <dc:date>2016-08-18T01:52:48Z</dc:date>
    </item>
  </channel>
</rss>

