<?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: Compare two values from extracted fields - if match increment counter in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Compare-two-values-from-extracted-fields-if-match-increment/m-p/345522#M102375</link>
    <description>&lt;P&gt;@splunk_95 - try this.  This is a count of all items in A where there was a match the same day in B. &lt;/P&gt;

&lt;P&gt;index="..." source="log a" OR source="log b" &lt;BR /&gt;
  | bin _time span=1d&lt;BR /&gt;
  | eval matchvalue = if( source="log a",A,B)&lt;BR /&gt;
  | stats values(source) as source, count(source="log a") as CountA, count(source="log b") as CountB by _time matchvalue&lt;BR /&gt;
  | where mvcount(source)&amp;gt;1&lt;BR /&gt;
  | stats sum(CountA) as count by _time&lt;BR /&gt;
  | timechart span=1d count&lt;/P&gt;</description>
    <pubDate>Wed, 09 Aug 2017 20:13:58 GMT</pubDate>
    <dc:creator>DalJeanis</dc:creator>
    <dc:date>2017-08-09T20:13:58Z</dc:date>
    <item>
      <title>Compare two values from extracted fields - if match increment counter</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compare-two-values-from-extracted-fields-if-match-increment/m-p/345508#M102361</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;

&lt;P&gt;Having read a few similar threads I realised they do not quite ask what I need so decided to post a new thread.&lt;/P&gt;

&lt;P&gt;I have two extracted fields both 5 digits long lets say:&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;A = 12345&lt;/STRONG&gt;  &lt;STRONG&gt;B=12345&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;I extracted these two field each from different sources (&lt;STRONG&gt;source 1 = "log a"     and source 2 = "log b"&lt;/STRONG&gt;) over a &lt;STRONG&gt;1 day interval.&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;Now lets say we get:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;**source 1 = log a           and **                                           **source 2 = log b**                 
A = 12345                                                              B = 98765
A = 23456                                                              B = 12345 
A = 34678                                                              B = 87878
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;As matching values could be any instance of the other field (as shown above) it may be required to iterate through all values..(unless anyone can think of a better idea.. I essentially need to check the value in log A has made it log B).  &lt;/P&gt;

&lt;P&gt;If it has I would like to increment another field by 1 for every 'match' made.  This would then be shown using a timechart.&lt;/P&gt;

&lt;P&gt;I am fairly new to splunk so have found the answer may be using the &lt;CODE&gt;eval&lt;/CODE&gt; command as follows:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="..." source="log a" OR source="log b" | eval match= match + 1|where A==B | timechart span =1d count (match)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Its the 'iterator' (like in c++ say) bit im having a bit of trouble with... not sure how to get it to check each instance of A against every value of B.  &lt;/P&gt;

&lt;P&gt;Also just to say A and B are extracted fields already.&lt;/P&gt;

&lt;P&gt;IF any feels this may be too performance heavy and have a better idea I'm all ears &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt; &lt;/P&gt;

&lt;P&gt;Thanks for any help in advance&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2017 12:31:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compare-two-values-from-extracted-fields-if-match-increment/m-p/345508#M102361</guid>
      <dc:creator>splunk_95</dc:creator>
      <dc:date>2017-08-02T12:31:54Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two values from extracted fields - if match increment counter</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compare-two-values-from-extracted-fields-if-match-increment/m-p/345509#M102362</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;index="..." source="log a" OR source="log b" | eval match=if(A==B,1,0) | timechart span =1d sum(match)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 02 Aug 2017 13:37:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compare-two-values-from-extracted-fields-if-match-increment/m-p/345509#M102362</guid>
      <dc:creator>3no</dc:creator>
      <dc:date>2017-08-02T13:37:48Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two values from extracted fields - if match increment counter</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compare-two-values-from-extracted-fields-if-match-increment/m-p/345510#M102363</link>
      <description>&lt;P&gt;Thank you for the reply, though I would like to learn exactly how this answer works (for my splunk development).&lt;/P&gt;

&lt;P&gt;Does that eval command check A against every instance of B? Sorry if that is a silly question.. I just cant see what logic makes it check that, kinda like the 'foreach' command in c#. &lt;/P&gt;

&lt;P&gt;Also another criteria I had was that this only considered the events over a day so if you only place that threshold on the timechart it should be fine i.e some sort of 'span=1d or _time' is not needed near the eval command?&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2017 13:46:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compare-two-values-from-extracted-fields-if-match-increment/m-p/345510#M102363</guid>
      <dc:creator>splunk_95</dc:creator>
      <dc:date>2017-08-02T13:46:12Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two values from extracted fields - if match increment counter</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compare-two-values-from-extracted-fields-if-match-increment/m-p/345511#M102364</link>
      <description>&lt;P&gt;Yes, it will check for every value of A if it equals a value of B (same as foreach), if it match it will give to "match" the value of 1, else 0. Then you make the sum to know how much occurence you have. &lt;/P&gt;

&lt;P&gt;The span=1d means it will sum "match" over one day, this means that if you make your search over a week you'll get 7 value (one for each day).  I'm not sure to understand your question on that last part&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2017 14:03:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compare-two-values-from-extracted-fields-if-match-increment/m-p/345511#M102364</guid>
      <dc:creator>3no</dc:creator>
      <dc:date>2017-08-02T14:03:06Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two values from extracted fields - if match increment counter</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compare-two-values-from-extracted-fields-if-match-increment/m-p/345512#M102365</link>
      <description>&lt;P&gt;awesome thanks! Just as an extension, if I only wanted to consider only the unique values of A against values of B is that possible?&lt;/P&gt;

&lt;P&gt;so if &lt;/P&gt;

&lt;P&gt;A =12345&lt;BR /&gt;
A= 23456&lt;BR /&gt;
A= 23489&lt;BR /&gt;
A= 12345 (This event would not be compared against all values of B)&lt;/P&gt;

&lt;P&gt;Also the spl doesn't seem to be working I checked the extracted fields and can see matching values in both A and B but match seems to return a value of zero... any idea how best to debug?&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2017 14:13:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compare-two-values-from-extracted-fields-if-match-increment/m-p/345512#M102365</guid>
      <dc:creator>splunk_95</dc:creator>
      <dc:date>2017-08-02T14:13:43Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two values from extracted fields - if match increment counter</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compare-two-values-from-extracted-fields-if-match-increment/m-p/345513#M102366</link>
      <description>&lt;P&gt;No, that's going to check each individual event to see whether the values of A and B on that event match.  Since they are coming from different indexes, match will never be other than 0.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2017 15:05:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compare-two-values-from-extracted-fields-if-match-increment/m-p/345513#M102366</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-08-02T15:05:39Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two values from extracted fields - if match increment counter</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compare-two-values-from-extracted-fields-if-match-increment/m-p/345514#M102367</link>
      <description>&lt;P&gt;This puts the value of &lt;CODE&gt;A&lt;/CODE&gt; or &lt;CODE&gt;B&lt;/CODE&gt; into a single field &lt;CODE&gt;matchfield&lt;/CODE&gt; so you can stats them together.  We  &lt;CODE&gt;bin&lt;/CODE&gt; the &lt;CODE&gt;_time&lt;/CODE&gt; at the 1 day level, and use the value of &lt;CODE&gt;source&lt;/CODE&gt; as an easy proxy for remembering whether it is &lt;CODE&gt;A&lt;/CODE&gt; or &lt;CODE&gt;B&lt;/CODE&gt;.  If there are two different sources, then we know we found both of them.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index="..." source="log a" OR source="log b" 
| bin _time span=1d
| eval matchvalue = if( source="log a",A,B)
| stats values(source) as source by _time matchvalue
| where mvcount(source)&amp;gt;1
| timechart span=1d count
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;HR /&gt;

&lt;P&gt;Updated to include the &lt;CODE&gt;timechart&lt;/CODE&gt; line.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2017 15:12:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compare-two-values-from-extracted-fields-if-match-increment/m-p/345514#M102367</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-08-02T15:12:55Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two values from extracted fields - if match increment counter</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compare-two-values-from-extracted-fields-if-match-increment/m-p/345515#M102368</link>
      <description>&lt;P&gt;Hi thanks for your suggestion.&lt;BR /&gt;&lt;BR /&gt;
Im a little unclear as to how I could get a count of the number of matches.. &lt;/P&gt;

&lt;P&gt;As ideally I would put the number of matches onto a timechart (so one column would be matches and another would be unique matches - &lt;CODE&gt;dc(matches)&lt;/CODE&gt; for example)&lt;/P&gt;

&lt;P&gt;From the code you wrote - how would I get the count of number of matches where A==B - &lt;CODE&gt;just stats count(source) by _time matchvalue&lt;/CODE&gt;?&lt;/P&gt;

&lt;P&gt;I have tried to &lt;CODE&gt;stats count (matchvalue)&lt;/CODE&gt; but that didn't seem to work&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2017 17:43:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compare-two-values-from-extracted-fields-if-match-increment/m-p/345515#M102368</guid>
      <dc:creator>splunk_95</dc:creator>
      <dc:date>2017-08-02T17:43:30Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two values from extracted fields - if match increment counter</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compare-two-values-from-extracted-fields-if-match-increment/m-p/345516#M102369</link>
      <description>&lt;P&gt;Every record that reaches the end of the code is exactly one unique match, so &lt;CODE&gt;| stats count by _time&lt;/CODE&gt; is one way, or &lt;CODE&gt;| timechart span=1d count&lt;/CODE&gt; is another.  &lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;If you need to know non-unique matches, then you need to define what you mean.  If there are 4 A records and 5 B records, do you want the non-unique match number to be 4, 5, 8, 9 or 20?  I'll assume 9 for this code, so the meaning of "match" is "records in either file that were matched in the other file".&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  index="..." source="log a" OR source="log b" 
 | bin _time span=1d
 | eval matchvalue = if( source="log a",A,B)
 | stats values(source) as source, count(source="log a") as CountA, count(source="log b") as CountB by _time matchvalue
 | where mvcount(source)&amp;gt;1
 | eval CountMatch = CountA+CountB
 | stats count as DistinctMatchCount, sum(CountMatch) as TotalMatchCount by _time
 | untable _time series count
 | timechart span=1d count by series
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 02 Aug 2017 18:05:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compare-two-values-from-extracted-fields-if-match-increment/m-p/345516#M102369</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-08-02T18:05:41Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two values from extracted fields - if match increment counter</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compare-two-values-from-extracted-fields-if-match-increment/m-p/345517#M102370</link>
      <description>&lt;P&gt;Thanks for your reply.&lt;BR /&gt;
I apologize for the confusion.&lt;BR /&gt;
So my definition for match is "an event in log A which is equivalent to an event in log B"&lt;BR /&gt;
i.e (assume in both logs each event is always 5 digits)&lt;BR /&gt;
log A :&lt;BR /&gt;
A= 12345 &lt;BR /&gt;
A= 23456&lt;BR /&gt;
A= 34567&lt;BR /&gt;
A= 12345&lt;/P&gt;

&lt;P&gt;Suppose log B:&lt;BR /&gt;
B=54321&lt;BR /&gt;
B=98765&lt;BR /&gt;
B=34567&lt;BR /&gt;
B=12345&lt;BR /&gt;
B=12345&lt;/P&gt;

&lt;P&gt;So for non unique 'match' i should get the value of &lt;CODE&gt;CountMatch&lt;/CODE&gt; to equal 3. &lt;BR /&gt;
For a 'unique' (i.e if the two events matched isnt previous match) a previous match I should get the value of 'CountMatch' to be 2 for the example above.  I tried to understand the code above but I dont think it quite does that.. (please correct me if im wrong)?  &lt;/P&gt;

&lt;P&gt;Also does the fact there may be a different number of events in both logs make a difference to the code in your comment?&lt;/P&gt;

&lt;P&gt;Many, many thanks - I have had a lot of problems with this - your help is really appreciated. &lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2017 20:16:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compare-two-values-from-extracted-fields-if-match-increment/m-p/345517#M102370</guid>
      <dc:creator>splunk_95</dc:creator>
      <dc:date>2017-08-02T20:16:43Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two values from extracted fields - if match increment counter</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compare-two-values-from-extracted-fields-if-match-increment/m-p/345518#M102371</link>
      <description>&lt;P&gt;Yes, my bad A and B are not in the same event (as DalJeanis said) &lt;/P&gt;

&lt;P&gt;How about if you try this way :&lt;/P&gt;

&lt;P&gt;index="..."  (source="log a" OR source="log b") | rename B as A | dedup A, source | stats count by A | where count &amp;gt; 1 | table A | stats count &lt;/P&gt;

&lt;P&gt;3no&lt;/P&gt;</description>
      <pubDate>Thu, 03 Aug 2017 09:10:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compare-two-values-from-extracted-fields-if-match-increment/m-p/345518#M102371</guid>
      <dc:creator>3no</dc:creator>
      <dc:date>2017-08-03T09:10:09Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two values from extracted fields - if match increment counter</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compare-two-values-from-extracted-fields-if-match-increment/m-p/345519#M102372</link>
      <description>&lt;P&gt;Hi &lt;BR /&gt;
The search you suggested below didn't seem to work... what would be the best way to debug it? &lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2017 15:05:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compare-two-values-from-extracted-fields-if-match-increment/m-p/345519#M102372</guid>
      <dc:creator>splunk_95</dc:creator>
      <dc:date>2017-08-08T15:05:04Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two values from extracted fields - if match increment counter</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compare-two-values-from-extracted-fields-if-match-increment/m-p/345520#M102373</link>
      <description>&lt;P&gt;index="..." (source="log a" OR source="log b")  // show the data&lt;BR /&gt;&lt;BR /&gt;
| rename B as A                    // rename fields B to field A &lt;BR /&gt;
| dedup A, source                // show the unique value of A by source (so you know which are original A and wich are original B) &lt;BR /&gt;
| stats count by A                // Count by field A &lt;BR /&gt;
| where count &amp;gt; 1               // We take only the field A where the count is superior to 1, because if the value was on A and B count should be 2&lt;BR /&gt;
| table A                               // show this values&lt;BR /&gt;
| stats count                       // return the count &lt;/P&gt;

&lt;P&gt;Try from the beginning and start adding each command to see if it gives you the correct values (when I say command, I mean everything that comes after a pipe "|") &lt;/P&gt;

&lt;P&gt;And let me know how it goes &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; &lt;/P&gt;

&lt;P&gt;3no&lt;/P&gt;</description>
      <pubDate>Wed, 09 Aug 2017 08:24:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compare-two-values-from-extracted-fields-if-match-increment/m-p/345520#M102373</guid>
      <dc:creator>3no</dc:creator>
      <dc:date>2017-08-09T08:24:53Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two values from extracted fields - if match increment counter</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compare-two-values-from-extracted-fields-if-match-increment/m-p/345521#M102374</link>
      <description>&lt;P&gt;hey &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
thanks for the reply.&lt;BR /&gt;
So essentially I feel "rename B as A" is not working however this seems to fail at "where count &amp;gt; 1".  I look through the values of A and the top 10 values the count is 1.  There is also no indication of increase in number of 'A' events after the renaming. &lt;/P&gt;

&lt;P&gt;Do you reckon sorting it by source like the other example would be better?&lt;/P&gt;

&lt;P&gt;I feel the renaming isn't exactly doing what we would like.&lt;/P&gt;

&lt;P&gt;Ideally I can get this out the count of matched values from both logs into a timechart  instead of a table that would be great.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Aug 2017 16:56:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compare-two-values-from-extracted-fields-if-match-increment/m-p/345521#M102374</guid>
      <dc:creator>splunk_95</dc:creator>
      <dc:date>2017-08-09T16:56:53Z</dc:date>
    </item>
    <item>
      <title>Re: Compare two values from extracted fields - if match increment counter</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compare-two-values-from-extracted-fields-if-match-increment/m-p/345522#M102375</link>
      <description>&lt;P&gt;@splunk_95 - try this.  This is a count of all items in A where there was a match the same day in B. &lt;/P&gt;

&lt;P&gt;index="..." source="log a" OR source="log b" &lt;BR /&gt;
  | bin _time span=1d&lt;BR /&gt;
  | eval matchvalue = if( source="log a",A,B)&lt;BR /&gt;
  | stats values(source) as source, count(source="log a") as CountA, count(source="log b") as CountB by _time matchvalue&lt;BR /&gt;
  | where mvcount(source)&amp;gt;1&lt;BR /&gt;
  | stats sum(CountA) as count by _time&lt;BR /&gt;
  | timechart span=1d count&lt;/P&gt;</description>
      <pubDate>Wed, 09 Aug 2017 20:13:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compare-two-values-from-extracted-fields-if-match-increment/m-p/345522#M102375</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-08-09T20:13:58Z</dc:date>
    </item>
  </channel>
</rss>

