<?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: Implementing condition in search in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Implementing-condition-in-search/m-p/344466#M102041</link>
    <description>&lt;P&gt;[search host="RAone*.jxa.com" OR host="RATwo*.jxa.com" source="/apps/BSA/data/log/bolly-*"  Rotten&lt;BR /&gt;
| stats count &lt;BR /&gt;
| eval search=if(count&amp;gt;0,""error" AND ("apple" OR "orange")",null) )&lt;BR /&gt;
| fields search &lt;BR /&gt;
| format "" "" "" "" "" "" &lt;BR /&gt;
| timechart count ]&lt;/P&gt;

&lt;P&gt;When I run the queried individually (with out nesting in subserach it gives results.&lt;BR /&gt;
But when i run them together like above I get the error "Error in 'eval' command: The expression is malformed. Expected )."&lt;/P&gt;

&lt;P&gt;Just so as you know, rotten;error;apple;orange etc..are words found in logs, they are not Splunk fields.&lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 17:16:18 GMT</pubDate>
    <dc:creator>zacksoft</dc:creator>
    <dc:date>2020-09-29T17:16:18Z</dc:date>
    <item>
      <title>Implementing condition in search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Implementing-condition-in-search/m-p/344452#M102027</link>
      <description>&lt;P&gt;This is  the algorithm of my query. Could someone help me in constructing it.&lt;/P&gt;

&lt;P&gt;If (A happens)&lt;BR /&gt;
   { &lt;BR /&gt;
     Then  ( Execute B Query) &lt;BR /&gt;
        {&lt;BR /&gt;
        }&lt;/P&gt;

&lt;P&gt;"Here A is a query like Host=A OR B, error_happened"&lt;BR /&gt;
"B is a query like Host=A OR B,  usage &lt;BR /&gt;
                              Show in stats/chart,  if 'apple' and 'error' found' &lt;BR /&gt;
                                               if 'orange' and 'error' found &lt;BR /&gt;
                                               if 'grape' and 'error 'found'"&lt;BR /&gt;
Apple/Orange/Grape/Error/Error_happened are not Splunk fields they are just some string/keyword in events.&lt;BR /&gt;
And B query should only execute if A query return any events/lines. If A query returns no events/lines then B shouldn't execute.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 17:16:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Implementing-condition-in-search/m-p/344452#M102027</guid>
      <dc:creator>zacksoft</dc:creator>
      <dc:date>2020-09-29T17:16:56Z</dc:date>
    </item>
    <item>
      <title>Re: Implementing condition in search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Implementing-condition-in-search/m-p/344453#M102028</link>
      <description>&lt;P&gt;you have to use &lt;CODE&gt;eval(if)&lt;/CODE&gt; in conjunction with &lt;CODE&gt;like()&lt;/CODE&gt; on _raw data&lt;/P&gt;

&lt;P&gt;Refer this link, you will get an idea.&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/7.0.1/SearchReference/ConditionalFunctions#like.28TEXT.2C_PATTERN.29"&gt;http://docs.splunk.com/Documentation/Splunk/7.0.1/SearchReference/ConditionalFunctions#like.28TEXT.2C_PATTERN.29&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;let me know if it helps!&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2017 09:16:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Implementing-condition-in-search/m-p/344453#M102028</guid>
      <dc:creator>mayurr98</dc:creator>
      <dc:date>2017-12-13T09:16:46Z</dc:date>
    </item>
    <item>
      <title>Re: Implementing condition in search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Implementing-condition-in-search/m-p/344454#M102029</link>
      <description>&lt;P&gt;Could you give me a psuedo-query using eval(if) and like/_raw  ; A skeleton model query to have an idea how it should be .&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2017 09:36:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Implementing-condition-in-search/m-p/344454#M102029</guid>
      <dc:creator>zacksoft</dc:creator>
      <dc:date>2017-12-13T09:36:41Z</dc:date>
    </item>
    <item>
      <title>Re: Implementing condition in search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Implementing-condition-in-search/m-p/344455#M102030</link>
      <description>&lt;P&gt;eval (Host=A OR B, usage &lt;BR /&gt;
Show in stats/chart, if 'apple' and 'error' found' &lt;BR /&gt;
if 'orange' and 'error' found &lt;BR /&gt;
if 'grape' and 'error 'found'"&lt;BR /&gt;
| stats count by usage)   IF (Host=A OR B, "error_happened")&lt;/P&gt;

&lt;P&gt;i.e.  eval B IF (A happens).&lt;/P&gt;

&lt;P&gt;Is this how it should be composed ?&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2017 09:52:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Implementing-condition-in-search/m-p/344455#M102030</guid>
      <dc:creator>zacksoft</dc:creator>
      <dc:date>2017-12-13T09:52:00Z</dc:date>
    </item>
    <item>
      <title>Re: Implementing condition in search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Implementing-condition-in-search/m-p/344456#M102031</link>
      <description>&lt;P&gt;I am not getting what do you want.&lt;BR /&gt;
Can you please provide some sample input data and also tell us what output do you want?&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2017 09:56:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Implementing-condition-in-search/m-p/344456#M102031</guid>
      <dc:creator>mayurr98</dc:creator>
      <dc:date>2017-12-13T09:56:58Z</dc:date>
    </item>
    <item>
      <title>Re: Implementing condition in search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Implementing-condition-in-search/m-p/344457#M102032</link>
      <description>&lt;P&gt;Let me put it in another way,&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;If (Host = "fruitbasket" "rotten") &lt;BR /&gt;
Then search ("apple" AND "bad") and  ("orange" AND "bad")&lt;BR /&gt;
          and show it in some stats.&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;What I mean here is, if the initial search (Host = "fruitbasket" "rotten") returns any result then I want to search for events containing  keywords ("apple" AND "bad") and  ("orange" AND "bad")..etc.&lt;/P&gt;

&lt;P&gt;Hope I am clear enough.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2017 10:14:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Implementing-condition-in-search/m-p/344457#M102032</guid>
      <dc:creator>zacksoft</dc:creator>
      <dc:date>2017-12-13T10:14:47Z</dc:date>
    </item>
    <item>
      <title>Re: Implementing condition in search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Implementing-condition-in-search/m-p/344458#M102033</link>
      <description>&lt;P&gt;You could use a subsearch, and return null if your condition is unmet. Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[search host=fruitbasket rotten  
| stats count 
| eval search=if(count&amp;gt;0,"bad AND (orange OR apple)",null) 
| fields search 
| format "" "" "" "" "" "" ]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Dec 2017 10:30:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Implementing-condition-in-search/m-p/344458#M102033</guid>
      <dc:creator>jplumsdaine22</dc:creator>
      <dc:date>2017-12-13T10:30:28Z</dc:date>
    </item>
    <item>
      <title>Re: Implementing condition in search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Implementing-condition-in-search/m-p/344459#M102034</link>
      <description>&lt;P&gt;Thanks , I was looking something exactly like this.. a subsearch kind of thing..&lt;/P&gt;

&lt;P&gt;In #4 you  have said "fieds search". What does this line do ?&lt;BR /&gt;
And what about #5 | format "" ""      &amp;lt;-- does it mean to format the output ?&lt;/P&gt;

&lt;P&gt;Would this give the count (timechart) type stating how many events we had with( apple AND bad) &amp;amp; (Orange AND bad)  ?  &lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2017 10:45:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Implementing-condition-in-search/m-p/344459#M102034</guid>
      <dc:creator>zacksoft</dc:creator>
      <dc:date>2017-12-13T10:45:26Z</dc:date>
    </item>
    <item>
      <title>Re: Implementing condition in search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Implementing-condition-in-search/m-p/344460#M102035</link>
      <description>&lt;P&gt;So this subsearch will return a value based on whether or not it discovers events  that match host=fruitbasket rotten . If there are events it will return &lt;CODE&gt;bad AND (orange OR apple)&lt;/CODE&gt;. If there are no events it will return &lt;CODE&gt;NOT OR ()&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;NOT OR ()&lt;/CODE&gt; evaluates to null, so the outer search will return zero events. If you want a timechart as well, then throw a timechart command after the search like so&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[search host=fruitbasket rotten  
| stats count 
| eval search=if(count&amp;gt;0,"bad AND (orange OR apple)",null) 
| fields search 
| format "" "" "" "" "" "" ]
| timechart count
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;For more information on wha the &lt;CODE&gt;fields search&lt;/CODE&gt; and &lt;CODE&gt;format&lt;/CODE&gt; mean have a look at the subsearch documentation &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/Search/Aboutsubsearches"&gt;http://docs.splunk.com/Documentation/Splunk/latest/Search/Aboutsubsearches&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2017 11:15:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Implementing-condition-in-search/m-p/344460#M102035</guid>
      <dc:creator>jplumsdaine22</dc:creator>
      <dc:date>2017-12-13T11:15:29Z</dc:date>
    </item>
    <item>
      <title>Re: Implementing condition in search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Implementing-condition-in-search/m-p/344461#M102036</link>
      <description>&lt;P&gt;Also if this answers your question don't forget to mark the answer as accepted!&lt;/P&gt;

&lt;P&gt;Cheers&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2017 12:35:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Implementing-condition-in-search/m-p/344461#M102036</guid>
      <dc:creator>jplumsdaine22</dc:creator>
      <dc:date>2017-12-13T12:35:27Z</dc:date>
    </item>
    <item>
      <title>Re: Implementing condition in search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Implementing-condition-in-search/m-p/344462#M102037</link>
      <description>&lt;P&gt;The query runs without any error however It doesn't return any events. seems like it isn't finding the keywords error/orange/apple to search.   I put double quote around it , but the expression gets malformed. This is to be noted that error/orange/apple are not splunk fields , but just some words found in events..&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2017 12:40:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Implementing-condition-in-search/m-p/344462#M102037</guid>
      <dc:creator>zacksoft</dc:creator>
      <dc:date>2017-12-13T12:40:24Z</dc:date>
    </item>
    <item>
      <title>Re: Implementing condition in search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Implementing-condition-in-search/m-p/344463#M102038</link>
      <description>&lt;P&gt;Which query returns no events?  &lt;CODE&gt;host=fruitbasket rotten&lt;/CODE&gt; or &lt;CODE&gt;bad AND (orange OR apple)&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2017 13:07:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Implementing-condition-in-search/m-p/344463#M102038</guid>
      <dc:creator>jplumsdaine22</dc:creator>
      <dc:date>2017-12-13T13:07:44Z</dc:date>
    </item>
    <item>
      <title>Re: Implementing condition in search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Implementing-condition-in-search/m-p/344464#M102039</link>
      <description>&lt;P&gt;bad AND (orange OR apple)&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2017 13:23:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Implementing-condition-in-search/m-p/344464#M102039</guid>
      <dc:creator>zacksoft</dc:creator>
      <dc:date>2017-12-13T13:23:54Z</dc:date>
    </item>
    <item>
      <title>Re: Implementing condition in search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Implementing-condition-in-search/m-p/344465#M102040</link>
      <description>&lt;P&gt;I'm a bit confused - If you do a query for &lt;CODE&gt;bad AND (orange OR apple)&lt;/CODE&gt; on its own (without all the subsearch bit) do you get any results? If you get none then the problem is that you have no data, not that the search is being malformed. &lt;/P&gt;

&lt;P&gt;If you think the eval is failing, try this on its own:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|makeresults
| eval search="bad AND (orange OR apple)"
| fields search 
| format "" "" "" "" "" ""
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That's what will get sent to the main search if your condition is true&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2017 14:00:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Implementing-condition-in-search/m-p/344465#M102040</guid>
      <dc:creator>jplumsdaine22</dc:creator>
      <dc:date>2017-12-13T14:00:29Z</dc:date>
    </item>
    <item>
      <title>Re: Implementing condition in search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Implementing-condition-in-search/m-p/344466#M102041</link>
      <description>&lt;P&gt;[search host="RAone*.jxa.com" OR host="RATwo*.jxa.com" source="/apps/BSA/data/log/bolly-*"  Rotten&lt;BR /&gt;
| stats count &lt;BR /&gt;
| eval search=if(count&amp;gt;0,""error" AND ("apple" OR "orange")",null) )&lt;BR /&gt;
| fields search &lt;BR /&gt;
| format "" "" "" "" "" "" &lt;BR /&gt;
| timechart count ]&lt;/P&gt;

&lt;P&gt;When I run the queried individually (with out nesting in subserach it gives results.&lt;BR /&gt;
But when i run them together like above I get the error "Error in 'eval' command: The expression is malformed. Expected )."&lt;/P&gt;

&lt;P&gt;Just so as you know, rotten;error;apple;orange etc..are words found in logs, they are not Splunk fields.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 17:16:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Implementing-condition-in-search/m-p/344466#M102041</guid>
      <dc:creator>zacksoft</dc:creator>
      <dc:date>2020-09-29T17:16:18Z</dc:date>
    </item>
  </channel>
</rss>

