<?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: search using a variable as condition in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/search-using-a-variable-as-condition/m-p/129243#M35132</link>
    <description>&lt;P&gt;Hi Martin,&lt;/P&gt;

&lt;P&gt;thank you for the response, in my case i needed to use case as i have more than 4 conditions to look at and then determine the value.  However i was able to get around it using&lt;/P&gt;

&lt;P&gt;....| where eval xyz=Case()| table...&lt;/P&gt;

&lt;P&gt;thanks!&lt;/P&gt;</description>
    <pubDate>Mon, 08 Jun 2015 23:04:08 GMT</pubDate>
    <dc:creator>nekbote</dc:creator>
    <dc:date>2015-06-08T23:04:08Z</dc:date>
    <item>
      <title>search using a variable as condition</title>
      <link>https://community.splunk.com/t5/Splunk-Search/search-using-a-variable-as-condition/m-p/129240#M35129</link>
      <description>&lt;P&gt;Hola Splunkers,&lt;/P&gt;

&lt;P&gt;I want to consolidate two dynamic drilldowns in a table. Each drilldown is passing the same token $token$, and my table should display the relevant events (all the events come from the same source)&lt;/P&gt;

&lt;P&gt;I'm trying to keep things simple, and I'm very close to make it work.&lt;/P&gt;

&lt;P&gt;My 1st problem is:  I coudn't find a simple way to verify is the $token$ has a default value or has a "legal" value. (isnull ie)&lt;/P&gt;

&lt;P&gt;So, I've decided to use the same variable for both graphs....$type_tok$, which leads to my 2nd problem. I cannot execute a search with a condition in a variable.&lt;/P&gt;

&lt;P&gt;From the graph#1, the values in the token are:  "SUCCESS", "ERROR", "UNDEF".  (A value in the field Response)&lt;BR /&gt;
From the graph #2, the values are: A01, D03, F05  (always  number in the 2nd position) (A value in the field Result)&lt;/P&gt;

&lt;P&gt;So I'm trying to distinguish between the two sources, checking if the 2nd character in the token is a number, so in my table, Im trying something  like:&lt;/P&gt;

&lt;P&gt;...| eval condition=if(isint(substr($type_tok$,2,1)), "Response=$type_tok$", "Result=$type_tok$")| search condition |  table _time, Id, error, Type, EndTime&lt;/P&gt;

&lt;P&gt;But of course, it doesn't work. The eval fails, and the search never works.&lt;/P&gt;

&lt;P&gt;I tried a simple search with a variable with and without $, but I couldn't make it work.&lt;BR /&gt;
... | eval test="Respons=SUCCESS" | search $test$&lt;/P&gt;

&lt;P&gt;I know it is possible to trigger saved search, but I prefer not to do it.&lt;/P&gt;

&lt;P&gt;Any advice?&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 17:36:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/search-using-a-variable-as-condition/m-p/129240#M35129</guid>
      <dc:creator>snemiro_514</dc:creator>
      <dc:date>2020-09-28T17:36:53Z</dc:date>
    </item>
    <item>
      <title>Re: search using a variable as condition</title>
      <link>https://community.splunk.com/t5/Splunk-Search/search-using-a-variable-as-condition/m-p/129241#M35130</link>
      <description>&lt;P&gt;You can move your &lt;CODE&gt;if()&lt;/CODE&gt; expression into an eval-based macro and use that in your main search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;some key words `your_if_macro("$type_tok$")` | table ...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The macro is evaluated once before the search runs, and the string returned by the &lt;CODE&gt;if()&lt;/CODE&gt; expression is inserted into the search string. Hence you can calculate both the field name and field value you're filtering for!&lt;/P&gt;</description>
      <pubDate>Wed, 17 Sep 2014 23:09:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/search-using-a-variable-as-condition/m-p/129241#M35130</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-09-17T23:09:41Z</dc:date>
    </item>
    <item>
      <title>Re: search using a variable as condition</title>
      <link>https://community.splunk.com/t5/Splunk-Search/search-using-a-variable-as-condition/m-p/129242#M35131</link>
      <description>&lt;P&gt;Was this ever resolved...is there a solution?&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jun 2015 02:14:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/search-using-a-variable-as-condition/m-p/129242#M35131</guid>
      <dc:creator>nekbote</dc:creator>
      <dc:date>2015-06-02T02:14:10Z</dc:date>
    </item>
    <item>
      <title>Re: search using a variable as condition</title>
      <link>https://community.splunk.com/t5/Splunk-Search/search-using-a-variable-as-condition/m-p/129243#M35132</link>
      <description>&lt;P&gt;Hi Martin,&lt;/P&gt;

&lt;P&gt;thank you for the response, in my case i needed to use case as i have more than 4 conditions to look at and then determine the value.  However i was able to get around it using&lt;/P&gt;

&lt;P&gt;....| where eval xyz=Case()| table...&lt;/P&gt;

&lt;P&gt;thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jun 2015 23:04:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/search-using-a-variable-as-condition/m-p/129243#M35132</guid>
      <dc:creator>nekbote</dc:creator>
      <dc:date>2015-06-08T23:04:08Z</dc:date>
    </item>
    <item>
      <title>Re: search using a variable as condition</title>
      <link>https://community.splunk.com/t5/Splunk-Search/search-using-a-variable-as-condition/m-p/129244#M35133</link>
      <description>&lt;P&gt;&lt;CODE&gt;case()&lt;/CODE&gt; will work in eval-based macros as well.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jun 2015 21:50:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/search-using-a-variable-as-condition/m-p/129244#M35133</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2015-06-11T21:50:36Z</dc:date>
    </item>
    <item>
      <title>Re: search using a variable as condition</title>
      <link>https://community.splunk.com/t5/Splunk-Search/search-using-a-variable-as-condition/m-p/129245#M35134</link>
      <description>&lt;P&gt;Thanks Martin!!&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jun 2015 23:24:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/search-using-a-variable-as-condition/m-p/129245#M35134</guid>
      <dc:creator>nekbote</dc:creator>
      <dc:date>2015-06-12T23:24:15Z</dc:date>
    </item>
  </channel>
</rss>

