<?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 eval searchmatch command OR if command in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/eval-searchmatch-command-OR-if-command/m-p/329630#M98108</link>
    <description>&lt;P&gt;Hi, I need some help. I have two fields that mark the status alert, PROBLEM and OK, I'm trying to compare them with the id_field&lt;BR /&gt;
To identify the open alerts. I have a scenario like the following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;field_1      field_2    field_status
 id1          null        problem
 null         id1         ok
 id2          null        problem
 id3          null        problem
 null         id2         ok
 null         id3         ok
 id4          null        problem
 id5          null        problem
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And so on do not have a defined standard arrival time.&lt;BR /&gt;
&amp;nbsp;&lt;BR /&gt;
I've tried with &lt;CODE&gt;index = "main" | table fielf_1, field_2, field_status | eval x = if (searchmatch(field_1 LIKE field_2)1,0)&lt;/CODE&gt;&lt;BR /&gt;
I do not know if I am omitting something in the eval function or if I should consider any other function.&lt;/P&gt;

&lt;P&gt;Expected Result&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;field_1      field_2    field_status         x
 id1          null        problem           1
 null         id1         ok
 id2          null        problem           1
 id3          null        problem           1
 null         id2         ok
 null         id3         ok
 id4          null        problem           0
 id5          null        problem           0
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks for the support, regards.&lt;/P&gt;</description>
    <pubDate>Thu, 13 Apr 2017 17:54:24 GMT</pubDate>
    <dc:creator>joseag</dc:creator>
    <dc:date>2017-04-13T17:54:24Z</dc:date>
    <item>
      <title>eval searchmatch command OR if command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/eval-searchmatch-command-OR-if-command/m-p/329630#M98108</link>
      <description>&lt;P&gt;Hi, I need some help. I have two fields that mark the status alert, PROBLEM and OK, I'm trying to compare them with the id_field&lt;BR /&gt;
To identify the open alerts. I have a scenario like the following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;field_1      field_2    field_status
 id1          null        problem
 null         id1         ok
 id2          null        problem
 id3          null        problem
 null         id2         ok
 null         id3         ok
 id4          null        problem
 id5          null        problem
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And so on do not have a defined standard arrival time.&lt;BR /&gt;
&amp;nbsp;&lt;BR /&gt;
I've tried with &lt;CODE&gt;index = "main" | table fielf_1, field_2, field_status | eval x = if (searchmatch(field_1 LIKE field_2)1,0)&lt;/CODE&gt;&lt;BR /&gt;
I do not know if I am omitting something in the eval function or if I should consider any other function.&lt;/P&gt;

&lt;P&gt;Expected Result&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;field_1      field_2    field_status         x
 id1          null        problem           1
 null         id1         ok
 id2          null        problem           1
 id3          null        problem           1
 null         id2         ok
 null         id3         ok
 id4          null        problem           0
 id5          null        problem           0
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks for the support, regards.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Apr 2017 17:54:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/eval-searchmatch-command-OR-if-command/m-p/329630#M98108</guid>
      <dc:creator>joseag</dc:creator>
      <dc:date>2017-04-13T17:54:24Z</dc:date>
    </item>
    <item>
      <title>Re: eval searchmatch command OR if command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/eval-searchmatch-command-OR-if-command/m-p/329631#M98109</link>
      <description>&lt;P&gt;The searchmatch is useful for matching against raw data (_raw field). Depending upon how you want to compare (they should be equal OR field_1 contains field_2 etc), you can use field compare functions like &lt;CODE&gt;like&lt;/CODE&gt; or &lt;CODE&gt;match&lt;/CODE&gt; or just equal sign.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 13:39:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/eval-searchmatch-command-OR-if-command/m-p/329631#M98109</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2020-09-29T13:39:23Z</dc:date>
    </item>
    <item>
      <title>Re: eval searchmatch command OR if command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/eval-searchmatch-command-OR-if-command/m-p/329632#M98110</link>
      <description>&lt;P&gt;This sets up your test data...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval mydata="id1,NULL,problem id1,NULL,problem NULL,id1,ok id2,NULL,problem id3,NULL,problem NULL,id2,ok NULL,id3,ok id4,NULL,problem id5,NULL,problem"
| makemv mydata | mvexpand mydata 
| rex field=mydata "(?&amp;lt;field_1&amp;gt;[^,]*),(?&amp;lt;field_2&amp;gt;[^,]*),(?&amp;lt;field_status&amp;gt;.*)"
| eval field_1 = if(field_1="NULL",null(),field_1)
| eval field_2 = if(field_2="NULL",null(),field_2)
| streamstats count
| eval _time = _time +count
| table _time field_1 field_2 field_status
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This gets you your desired value for x...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval myid=coalesce(field_1,field_2)
| eventstats count(field_2) as x by myid
| eval x = if(isnull(field_1),null(),x)
| table _time field_1 field_2 field_status  x 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;HR /&gt;

&lt;P&gt;Assumptions the sample code is based on...&lt;/P&gt;

&lt;P&gt;When an alert occurs, a record is created with the ID in field_1 and "problem" in field_status.&lt;BR /&gt;&lt;BR /&gt;
When an alert is cleared, a record is created with the ID in field_2 and "ok" in field_status.&lt;BR /&gt;&lt;BR /&gt;
For any record with "problem" in field_status, you want to flag the record with 1 if it has been later cleared, and 0 if it has not.&lt;/P&gt;

&lt;P&gt;For purposes of the above code, we've assumed that each ID can only appear once in the file in field_1 and once in field_2.  The _time in the above code (an the record order) has no effect on the outcome.&lt;/P&gt;

&lt;P&gt;On the other hand, if the same ID can appear multiple times and you want to know if there has been an ok record after this particular problem record, then _time is required and a different version is needed, as below&lt;/P&gt;

&lt;P&gt;The sample data generator, with a few cases added...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval mydata="id1,NULL,problem id1,NULL,problem NULL,id1,ok id2,NULL,problem id3,NULL,problem NULL,id2,ok NULL,id3,ok id4,NULL,problem id5,NULL,problem id2,NULL,problem NULL,id5,ok"
| makemv mydata | mvexpand mydata 
| rex field=mydata "(?&amp;lt;field_1&amp;gt;[^,]*),(?&amp;lt;field_2&amp;gt;[^,]*),(?&amp;lt;field_status&amp;gt;.*)"
| eval field_1 = if(field_1="NULL",null(),field_1)
| eval field_2 = if(field_2="NULL",null(),field_2)
| streamstats count
| eval _time = _time +count
| table _time field_1 field_2 field_status
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The _time based code...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval myid=coalesce(field_1,field_2)
| eval probtime=if(field_status="problem",_time,null())
| eval oktime=if(field_status="ok",_time,null())
| eventstats max(*time) as max*time by myid
| eval x = case(isnull(probtime),null(),probtime&amp;lt;maxoktime,1,true(),0)
| table _time field_1 field_2 field_status  x 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Sep 2020 13:40:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/eval-searchmatch-command-OR-if-command/m-p/329632#M98110</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2020-09-29T13:40:25Z</dc:date>
    </item>
    <item>
      <title>Re: eval searchmatch command OR if command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/eval-searchmatch-command-OR-if-command/m-p/329633#M98111</link>
      <description>&lt;P&gt;@joseag - if your problem has been solved, please accept a solution.  If you solved it a different way, please post your version of the solution as an answer, and accept your own answer.&lt;/P&gt;</description>
      <pubDate>Thu, 18 May 2017 18:04:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/eval-searchmatch-command-OR-if-command/m-p/329633#M98111</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-05-18T18:04:30Z</dc:date>
    </item>
  </channel>
</rss>

