<?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: Conditional Eval based on value in the field in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Conditional-Eval-based-on-value-in-the-field/m-p/424628#M121772</link>
    <description>&lt;P&gt;I tried with &lt;CODE&gt;case&lt;/CODE&gt; as well, but does not help.&lt;/P&gt;</description>
    <pubDate>Tue, 10 Jul 2018 22:54:59 GMT</pubDate>
    <dc:creator>abhisheks2412</dc:creator>
    <dc:date>2018-07-10T22:54:59Z</dc:date>
    <item>
      <title>Conditional Eval based on value in the field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Conditional-Eval-based-on-value-in-the-field/m-p/424626#M121770</link>
      <description>&lt;P&gt;I am trying to use transaction command to correlate two event types. I need to correlate events based on value in "id" part of the following searches.&lt;BR /&gt;
Search 1:- event=A somefield=job_type-id &lt;BR /&gt;
        For Eg:- event=end somefield=job1-AAAAAAAAA&amp;#11;&lt;BR /&gt;
Search 2:- event=B job_type=id&lt;BR /&gt;
        For Eg:- event=start job1=AAAAAAAAA&lt;BR /&gt;
        Can contain multiple job_types in single event&lt;/P&gt;

&lt;P&gt;Search 1 can contain 4 different types of "job_type", like, job1, job2, job3 and job4. Search 1 will only contain one "job_type" for any given event. Value of "id" is not extracted in any field.&lt;BR /&gt;
Search 2 contains the above 4 types of jobs with corresponding "id". But, few Search 2 events can have multiple job_types. For Eg:- event=start job1=AAAAAAAAA job2=BBBBBBBB&lt;/P&gt;

&lt;P&gt;I am using following transaction search,&lt;/P&gt;

&lt;P&gt;(Search 1) OR (Search 2)&lt;BR /&gt;
| rex somefield=(?&amp;gt;type&amp;gt;\w+\d)-(?&amp;gt;id&amp;gt;.*)&amp;#11;&lt;BR /&gt;
| eval newfield=if(len(id)&amp;gt;0,id,if(len(job1)&amp;gt;0,job1,if(len(job2)&amp;gt;0,job2,if(len(job3)&amp;gt;0,job3,if(job4)&amp;gt;0,job4,""))))&amp;#11;&lt;BR /&gt;
| transaction newfield keepevicted=true maxspan=1m&amp;#11;&lt;BR /&gt;
| where eventcount &amp;lt; 2&amp;#11;&lt;BR /&gt;
| table _raw type id&lt;/P&gt;

&lt;P&gt;Above search works fine, but when Search 1 contains job3 as job_type and Search 2 contains job1 and job3. It does not correlates events. This is expected as in "eval" condition job1 is given preference.&lt;/P&gt;

&lt;P&gt;I wanted to know if there is a way to reorder the "eval" condition based on job_type in Search 1, something like below (it does not works),&lt;/P&gt;

&lt;P&gt;| eval a = if(len(id)&amp;gt;0,id,if(len(job1)&amp;gt;0,job1,if(len(job2)&amp;gt;0,job2,if(len(job3)&amp;gt;0,job3,if(job4)&amp;gt;0,job4,""))))&lt;BR /&gt;
| eval b = if(len(id)&amp;gt;0,id,if(len(job2)&amp;gt;0,job2,if(len(job1)&amp;gt;0,job1,if(len(job3)&amp;gt;0,job3,if(job4)&amp;gt;0,job4,""))))&lt;BR /&gt;
| eval c = if(len(id)&amp;gt;0,id,if(len(job3)&amp;gt;0,job3,if(len(job2)&amp;gt;0,job2,if(len(job1)&amp;gt;0,job1,if(job4)&amp;gt;0,job4,""))))&amp;#11;&lt;BR /&gt;
| eval d = if(len(id)&amp;gt;0,id,if(len(job4)&amp;gt;0,job4,if(len(job2)&amp;gt;0,job2,if(len(job3)&amp;gt;0,job3,if(job1)&amp;gt;0,job1,""))))&lt;BR /&gt;
| eval newfield=case(&lt;BR /&gt;
     type=job1, a,&lt;BR /&gt;
     type=job2, b,&lt;BR /&gt;
     type=job3, c,&amp;#11;&lt;BR /&gt;&lt;BR /&gt;
     type=job4, d,&lt;BR /&gt;
     1 == 1, "NULL"&lt;BR /&gt;
)&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 20:18:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Conditional-Eval-based-on-value-in-the-field/m-p/424626#M121770</guid>
      <dc:creator>abhisheks2412</dc:creator>
      <dc:date>2020-09-29T20:18:33Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Eval based on value in the field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Conditional-Eval-based-on-value-in-the-field/m-p/424627#M121771</link>
      <description>&lt;P&gt;The &lt;CODE&gt;case&lt;/CODE&gt; command can help here.&lt;/P&gt;

&lt;P&gt;Something in the spirit of &lt;CODE&gt;eval a = case (len(id) &amp;gt; 0,id, len(job1) &amp;gt; 0, job1, ....&lt;/CODE&gt;...&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jul 2018 00:04:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Conditional-Eval-based-on-value-in-the-field/m-p/424627#M121771</guid>
      <dc:creator>ddrillic</dc:creator>
      <dc:date>2018-07-10T00:04:31Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Eval based on value in the field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Conditional-Eval-based-on-value-in-the-field/m-p/424628#M121772</link>
      <description>&lt;P&gt;I tried with &lt;CODE&gt;case&lt;/CODE&gt; as well, but does not help.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jul 2018 22:54:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Conditional-Eval-based-on-value-in-the-field/m-p/424628#M121772</guid>
      <dc:creator>abhisheks2412</dc:creator>
      <dc:date>2018-07-10T22:54:59Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Eval based on value in the field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Conditional-Eval-based-on-value-in-the-field/m-p/424629#M121773</link>
      <description>&lt;P&gt;So, if I'm reading this correctly...&lt;/P&gt;

&lt;P&gt;In event 2, which job do you want to match on?  &lt;/P&gt;

&lt;P&gt;Could you provide samples of the four possible styles of events for each of search 1 and search 2?  Obviously, redact information that shouldn't get out, but also keep in mind we're data people - we can read data and also sometimes if you obfuscate too well we "lose sight of what it is you are doing".  Also, most information isn't as secret as people think.  &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jul 2018 13:43:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Conditional-Eval-based-on-value-in-the-field/m-p/424629#M121773</guid>
      <dc:creator>Richfez</dc:creator>
      <dc:date>2018-07-11T13:43:01Z</dc:date>
    </item>
  </channel>
</rss>

