<?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: Comparing two multivalue fields in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Comparing-two-multivalue-fields/m-p/534769#M151127</link>
    <description>&lt;P&gt;That should be 'ok' for 8:30 and 'illegal' for 9:15. So there should be 2 'Res' records in this case.&lt;/P&gt;</description>
    <pubDate>Tue, 05 Jan 2021 10:10:15 GMT</pubDate>
    <dc:creator>gcbysc</dc:creator>
    <dc:date>2021-01-05T10:10:15Z</dc:date>
    <item>
      <title>Comparing two multivalue fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Comparing-two-multivalue-fields/m-p/534696#M151101</link>
      <description>&lt;P&gt;I'm trying to compare multiplevalue fields in a search.&lt;/P&gt;&lt;P&gt;My query is below:&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;sourcetype=app2_log OR sourcetype=app1_log | stats values(App1_Login_Time) as App1_Login_Time values (App2_Login_Time) as App2_Login_Time by User | eval res = if(App1_Login_Time &amp;gt; App2_Login_Time, "illegal activity", "ok")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So the output for above query is below.&lt;/P&gt;&lt;TABLE border="1" width="89.6774193548387%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="25%" height="25px"&gt;User&lt;/TD&gt;&lt;TD width="25%" height="25px"&gt;App1_Login_Time&lt;/TD&gt;&lt;TD width="25%" height="25px"&gt;App2_Login_Time&lt;/TD&gt;&lt;TD width="14.793448362090523%" height="25px"&gt;Res&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%" height="25px"&gt;user1&lt;/TD&gt;&lt;TD width="25%" height="25px"&gt;08:41:33&lt;/TD&gt;&lt;TD width="25%" height="25px"&gt;08:55:20&lt;/TD&gt;&lt;TD width="14.793448362090523%" height="25px"&gt;ok&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%" height="25px"&gt;user2&lt;/TD&gt;&lt;TD width="25%" height="25px"&gt;08:43:00&lt;/TD&gt;&lt;TD width="25%" height="25px"&gt;09:01:18&lt;/TD&gt;&lt;TD width="14.793448362090523%" height="25px"&gt;ok&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%" height="25px"&gt;user3&lt;/TD&gt;&lt;TD width="25%" height="25px"&gt;08:40:25&lt;/TD&gt;&lt;TD width="25%" height="25px"&gt;&lt;P&gt;08:10:30&lt;/P&gt;&lt;P&gt;08:20:12&lt;/P&gt;&lt;P&gt;08:30:15&lt;/P&gt;&lt;/TD&gt;&lt;TD width="14.793448362090523%" height="25px"&gt;ok&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%"&gt;user4&lt;/TD&gt;&lt;TD width="25%"&gt;08:30:20&lt;/TD&gt;&lt;TD width="25%"&gt;&lt;P&gt;08:10:05&lt;/P&gt;&lt;/TD&gt;&lt;TD width="14.793448362090523%"&gt;illegal activity&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%" height="25px"&gt;user5&lt;/TD&gt;&lt;TD width="25%" height="25px"&gt;09:35:20&lt;/TD&gt;&lt;TD width="25%" height="25px"&gt;09:50:00&lt;/TD&gt;&lt;TD width="14.793448362090523%" height="25px"&gt;&lt;P&gt;ok&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As you can see, the query check clients login time for both application. If clients are logged in to "app2" before "app1", it will be an illegal activity for my case. My queries output is working for user1,2,4 and 5. User4 logged in to app2 before application1 so in res column it says 'illegal activity'. For user3, it also logged in to app2 before app1 but in res column it says 'ok'. There are many users and I checked most of them. When there are multiple values for an application login time, the query can't compare and give true result. The result for user3 should be like this:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="25%" height="25px"&gt;User&lt;/TD&gt;&lt;TD width="25%" height="25px"&gt;App1_Login_Time&lt;/TD&gt;&lt;TD width="25%" height="25px"&gt;App2_Login_Time&lt;/TD&gt;&lt;TD width="14.793448362090523%" height="25px"&gt;Res&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%" height="25px"&gt;user1&lt;/TD&gt;&lt;TD width="25%" height="25px"&gt;08:41:33&lt;/TD&gt;&lt;TD width="25%" height="25px"&gt;08:55:20&lt;/TD&gt;&lt;TD width="14.793448362090523%" height="25px"&gt;ok&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%" height="25px"&gt;user2&lt;/TD&gt;&lt;TD width="25%" height="25px"&gt;08:43:00&lt;/TD&gt;&lt;TD width="25%" height="25px"&gt;09:01:18&lt;/TD&gt;&lt;TD width="14.793448362090523%" height="25px"&gt;ok&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%" height="25px"&gt;user3&lt;/TD&gt;&lt;TD width="25%" height="25px"&gt;08:40:25&lt;/TD&gt;&lt;TD width="25%" height="25px"&gt;&lt;P&gt;08:10:30&lt;/P&gt;&lt;P&gt;08:20:12&lt;/P&gt;&lt;P&gt;08:30:15&lt;/P&gt;&lt;/TD&gt;&lt;TD width="14.793448362090523%" height="25px"&gt;&lt;P&gt;&lt;STRONG&gt;illegal activity&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;illegal activity&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;illegal activity&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%"&gt;user4&lt;/TD&gt;&lt;TD width="25%"&gt;08:30:20&lt;/TD&gt;&lt;TD width="25%"&gt;&lt;P&gt;08:10:05&lt;/P&gt;&lt;/TD&gt;&lt;TD width="14.793448362090523%"&gt;illegal activity&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%" height="25px"&gt;user5&lt;/TD&gt;&lt;TD width="25%" height="25px"&gt;09:35:20&lt;/TD&gt;&lt;TD width="25%" height="25px"&gt;09:50:00&lt;/TD&gt;&lt;TD width="14.793448362090523%" height="25px"&gt;&lt;P&gt;ok&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So with this output, I need to get 3 "illegal activity" outputs for user3. Also There can be a case where user can log in to "app2" before "app1" 1 time which should considered as "illegal activity" and after that log in to "app1" again and after that "app2" which should considered as "ok".&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="25%"&gt;user 6&lt;/TD&gt;&lt;TD width="25%"&gt;&lt;P&gt;08:30:20&lt;/P&gt;&lt;P&gt;09:15:00&lt;/P&gt;&lt;/TD&gt;&lt;TD width="25%"&gt;&lt;P&gt;08:15:10&lt;/P&gt;&lt;P&gt;09:30:00&lt;/P&gt;&lt;/TD&gt;&lt;TD width="25%"&gt;&lt;P&gt;illegal activity&lt;/P&gt;&lt;P&gt;ok&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Also I need to count the number of illegal activity for specific user.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I couldn't make splunk to do this comparison. Any ideas?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;EDIT:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;There is also a scenario that users login to app1 but they may not login to app2 which is consideres as 'ok' in my case&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="25%" height="25px"&gt;User&lt;/TD&gt;&lt;TD width="25%" height="25px"&gt;App1_Login_Time&lt;/TD&gt;&lt;TD width="25%" height="25px"&gt;App2_Login_Time&lt;/TD&gt;&lt;TD width="25%" height="25px"&gt;Res&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%" height="25px"&gt;user01&lt;/TD&gt;&lt;TD width="25%" height="25px"&gt;08:30:00&lt;/TD&gt;&lt;TD width="25%" height="25px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD width="25%" height="25px"&gt;ok&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Thank you.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jan 2021 06:13:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Comparing-two-multivalue-fields/m-p/534696#M151101</guid>
      <dc:creator>gcbysc</dc:creator>
      <dc:date>2021-01-07T06:13:14Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing two multivalue fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Comparing-two-multivalue-fields/m-p/534702#M151103</link>
      <description>&lt;P&gt;What about these scenarios:&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="25%"&gt;user 7&lt;/TD&gt;&lt;TD width="25%"&gt;&lt;P&gt;09:15:00&lt;/P&gt;&lt;/TD&gt;&lt;TD width="25%"&gt;&lt;P&gt;09:10:10&lt;/P&gt;&lt;P&gt;09:30:00&lt;/P&gt;&lt;/TD&gt;&lt;TD width="25%"&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="25%"&gt;user 8&lt;/TD&gt;&lt;TD width="25%"&gt;&lt;P&gt;08:30:20&lt;/P&gt;&lt;P&gt;09:15:00&lt;/P&gt;&lt;/TD&gt;&lt;TD width="25%"&gt;&lt;P&gt;08:45:10&lt;/P&gt;&lt;/TD&gt;&lt;TD width="25%"&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;How do you determine which log on time to use when determining whether it is illegal activity or not?&lt;/P&gt;</description>
      <pubDate>Mon, 04 Jan 2021 14:38:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Comparing-two-multivalue-fields/m-p/534702#M151103</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2021-01-04T14:38:18Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing two multivalue fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Comparing-two-multivalue-fields/m-p/534750#M151115</link>
      <description>&lt;P&gt;It sound like you could have the case where you can have n values of app 1 login and m values of app 2 login. Dealing with indeterminate numbers of elements in the two MV fields will be challenging, but one option is to have the times as epoch times in the MV field, in which case, you can use numerical comparisons&lt;/P&gt;&lt;P&gt;I think perhaps you could do this by mvexpanding the App1_Login_Time field and then you know you will have a single value.&lt;/P&gt;&lt;P&gt;If you have Splunk 8, the eval+mvmap function will allow you to iterate over the values of the field, performing an operation on that value of the field.&lt;/P&gt;&lt;P&gt;See this query from your example data - it will only with with Splunk 8&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval _raw="User	App1_Login_Time	App2_Login_Time	Res
user1	08:41:33	08:55:20	ok
user2	08:43:00	09:01:18	ok
user3	08:40:25	08:10:30,08:20:12,08:30:15	ok
user4	08:30:20	08:10:05	illegal activity
user5	09:35:20	09:50:00	ok
user6	08:30:20,09:15:00	08:15:10,09:30:00	illegal activity,ok"
| multikv forceheader=1
| fields - _raw _time linecount
| foreach App* Res [ eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;=split(&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;,",") ]
| mvexpand App1_Login_Time
| foreach App* [ eval T_&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;=strptime(&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;,"%T") ]
| eval NewRes=mvmap(T_2_Login_Time,if(T_2_Login_Time-T_1_Login_Time&amp;lt;0,"illegal activity","ok"))
| table User App1_Login_Time App2_Login_Time NewRes Res&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;You can see that NewRes for User3 is now as wanted. User6 results in two rows and on the surface, it looks like it's giving you the right answer, but you will need to validate the possible permutations for multi valued App1 logins to see if that correct in all cases, and then work out how to aggregate the results for User6 to a single row.&lt;/P&gt;&lt;P&gt;Hope this helps&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jan 2021 04:41:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Comparing-two-multivalue-fields/m-p/534750#M151115</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2021-01-05T04:41:13Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing two multivalue fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Comparing-two-multivalue-fields/m-p/534760#M151120</link>
      <description>&lt;P&gt;Hello. We are using splunk 6.5.3 environment so the mvmap function is not supported.&lt;/P&gt;&lt;P&gt;So in order to solve this case, should I use and compare linux epoch time values?&lt;/P&gt;&lt;P&gt;I can convert the App1_Login_Time and App2_Login_Time date information to linux epoch time. Actually, in the first place, splunk indexer get these date values from corresponding databases as Linux epoch time. I change them with `to_char(App1_Login_Time,'DD-MM-YYYY HH24:MI:SS')`so that I can read them in splunk search head. If I don't write this function in indexer, indexer will get those values with epoch time.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jan 2021 08:29:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Comparing-two-multivalue-fields/m-p/534760#M151120</guid>
      <dc:creator>gcbysc</dc:creator>
      <dc:date>2021-01-05T08:29:03Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing two multivalue fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Comparing-two-multivalue-fields/m-p/534762#M151122</link>
      <description>&lt;P&gt;Actually I use first application to determine if it is illegal activity or not.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jan 2021 09:07:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Comparing-two-multivalue-fields/m-p/534762#M151122</guid>
      <dc:creator>gcbysc</dc:creator>
      <dc:date>2021-01-05T09:07:41Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing two multivalue fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Comparing-two-multivalue-fields/m-p/534764#M151123</link>
      <description>&lt;P&gt;So for user 8, is 08:45:10 OK since it is after 08:30:20 or illegal since it is before 09:15:00?&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jan 2021 09:16:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Comparing-two-multivalue-fields/m-p/534764#M151123</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2021-01-05T09:16:29Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing two multivalue fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Comparing-two-multivalue-fields/m-p/534769#M151127</link>
      <description>&lt;P&gt;That should be 'ok' for 8:30 and 'illegal' for 9:15. So there should be 2 'Res' records in this case.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jan 2021 10:10:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Comparing-two-multivalue-fields/m-p/534769#M151127</guid>
      <dc:creator>gcbysc</dc:creator>
      <dc:date>2021-01-05T10:10:15Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing two multivalue fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Comparing-two-multivalue-fields/m-p/534773#M151129</link>
      <description>&lt;LI-CODE lang="markup"&gt;| makeresults
| eval _raw="User	App1_Login_Time	App2_Login_Time	Res
user1	08:41:33	08:55:20	ok
user2	08:43:00	09:01:18	ok
user3	08:40:25	08:10:30,08:20:12,08:30:15	ok
user4	08:30:20	08:10:05	illegal activity
user5	09:35:20	09:50:00	ok
user6	08:30:20,09:15:00	08:15:10,09:30:00	illegal activity,ok
user7	09:15:00	09:10:10,09:30:00	ok
user8	08:30:20,09:15:00	08:45:10	ok"
| multikv forceheader=1
| fields - _raw _time linecount
| foreach App* Res [ eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;=split(&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;,",") ]
| mvexpand App1_Login_Time
| mvexpand App2_Login_Time
| eval new_Res=if(strptime(App1_Login_Time,"%T")-strptime(App2_Login_Time,"%T") &amp;lt; 0, "ok", "illegal activity")
| stats values(App1_Login_Time) as App1_Login_Time by User, App2_Login_Time, new_Res&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 05 Jan 2021 10:59:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Comparing-two-multivalue-fields/m-p/534773#M151129</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2021-01-05T10:59:10Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing two multivalue fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Comparing-two-multivalue-fields/m-p/534791#M151131</link>
      <description>&lt;P&gt;Your command works like a charm in your example. I'll try to combine this with my sourcetypes, and let you know if it works.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jan 2021 13:47:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Comparing-two-multivalue-fields/m-p/534791#M151131</guid>
      <dc:creator>gcbysc</dc:creator>
      <dc:date>2021-01-05T13:47:21Z</dc:date>
    </item>
  </channel>
</rss>

