<?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: How to convert my lookup field value to an executable formula? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-my-lookup-field-value-to-an-executable-formula/m-p/217065#M63748</link>
    <description>&lt;P&gt;You can pass a field to an inner search by using &lt;CODE&gt;map&lt;/CODE&gt;.  Take this for example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | inputcsv myFileWithFormulasInFiledCalledFormula | map search="| inputcsv myFileWithFieldsXandY | eval result = $Formula$"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Inside this search you could do the subsearch thing, too.&lt;/P&gt;</description>
    <pubDate>Fri, 26 Feb 2016 03:02:21 GMT</pubDate>
    <dc:creator>woodcock</dc:creator>
    <dc:date>2016-02-26T03:02:21Z</dc:date>
    <item>
      <title>How to convert my lookup field value to an executable formula?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-my-lookup-field-value-to-an-executable-formula/m-p/217057#M63740</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I have a lookup file in which one of the field values is a formula.&lt;/P&gt;

&lt;P&gt;test.csv (lookup file)&lt;BR /&gt;
name,value&lt;BR /&gt;
first,counter*100/2&lt;/P&gt;

&lt;P&gt;This is my search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=main sourcetype="generatedLogs" earliest=-2m|fields name, counter|join name[|inputlookup test.csv|]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Since Splunk considers the field value as text, I cannot execute it as a formula.&lt;BR /&gt;
Is there any possible way to achieve this?&lt;/P&gt;

&lt;P&gt;Thanks in advance.&lt;BR /&gt;
John&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2016 22:41:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-my-lookup-field-value-to-an-executable-formula/m-p/217057#M63740</guid>
      <dc:creator>johnchamp</dc:creator>
      <dc:date>2016-02-23T22:41:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert my lookup field value to an executable formula?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-my-lookup-field-value-to-an-executable-formula/m-p/217058#M63741</link>
      <description>&lt;P&gt;Hi johnchamp,&lt;/P&gt;

&lt;P&gt;you could have the formula split up in the lookup like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;name,value1,value2,value3
first,counter,100,2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and use it in the search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=main sourcetype="generatedLogs" earliest=-2m | fields name, counter | inputlookup append=t test.csv | eval result=value1*value2/value3
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Hope this helps ...&lt;/P&gt;

&lt;P&gt;cheers, MuS&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2016 22:55:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-my-lookup-field-value-to-an-executable-formula/m-p/217058#M63741</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2016-02-23T22:55:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert my lookup field value to an executable formula?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-my-lookup-field-value-to-an-executable-formula/m-p/217059#M63742</link>
      <description>&lt;P&gt;If all else fails, you can write a custom search command to evaluate the formula embedded in a string field.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2016 23:05:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-my-lookup-field-value-to-an-executable-formula/m-p/217059#M63742</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2016-02-23T23:05:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert my lookup field value to an executable formula?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-my-lookup-field-value-to-an-executable-formula/m-p/217060#M63743</link>
      <description>&lt;P&gt;Hi MuS,&lt;/P&gt;

&lt;P&gt;Thanks for the answer.&lt;BR /&gt;
this solution works the formula with the same signature, but i have a different set of formulas by name in lookup table. and i want to make a generalized solution for this requirement. &lt;/P&gt;

&lt;P&gt;Thanks,&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2016 23:07:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-my-lookup-field-value-to-an-executable-formula/m-p/217060#M63743</guid>
      <dc:creator>johnchamp</dc:creator>
      <dc:date>2016-02-23T23:07:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert my lookup field value to an executable formula?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-my-lookup-field-value-to-an-executable-formula/m-p/217061#M63744</link>
      <description>&lt;P&gt;It is possible, although it's not very obvious how to do it. &lt;/P&gt;

&lt;P&gt;You have to use a subsearch for it. &lt;/P&gt;

&lt;P&gt;Here is an example.  My "base search" here in my example is just &lt;CODE&gt;| stats count | fields - count | eval x=12&lt;/CODE&gt;  Which gives a single row with a single field "x" set to "12". &lt;/P&gt;

&lt;P&gt;and then what comes after that is the peculiar use of a subsearch to take what is really just a string "(x/2)*(x/2)" and evaluate it as the results of an eval command. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count | fields - count | eval x=12 | eval y=[| stats count | fields - count | eval search="(x/2)*(x/2)" ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You'll see the output where x is of course still "12" but there is also a y field whose value is "36", as computed by the formula. &lt;/P&gt;

&lt;P&gt;The key thing is you need to have only one field in the subsearch, and that field MUST be called "search".   This acts as a special case in the subsearch code I believe.   Note that if you try "query" instead of "search", note that this evaluation trick does not work. &lt;/P&gt;

&lt;P&gt;UPDATE: &lt;/P&gt;

&lt;P&gt;Here is some content from the official docs about other differences between the special-cased "query" and "search" field behavior in subsearches - &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.1.8/Search/Changetheformatofsubsearchresults"&gt;http://docs.splunk.com/Documentation/Splunk/6.1.8/Search/Changetheformatofsubsearchresults&lt;/A&gt; &lt;/P&gt;

&lt;P&gt;Why exactly "search" works here and "query" does not, frankly is a bit of a mystery.   I suppose you should just remember that they are different from each other and a bit secretive from the rest of us.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2016 23:09:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-my-lookup-field-value-to-an-executable-formula/m-p/217061#M63744</guid>
      <dc:creator>sideview</dc:creator>
      <dc:date>2016-02-23T23:09:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert my lookup field value to an executable formula?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-my-lookup-field-value-to-an-executable-formula/m-p/217062#M63745</link>
      <description>&lt;P&gt;Ah yes, &lt;CODE&gt;search&lt;/CODE&gt; - I tested with &lt;CODE&gt;query&lt;/CODE&gt;, but that produces a quoted string &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2016 23:11:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-my-lookup-field-value-to-an-executable-formula/m-p/217062#M63745</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2016-02-23T23:11:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert my lookup field value to an executable formula?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-my-lookup-field-value-to-an-executable-formula/m-p/217063#M63746</link>
      <description>&lt;P&gt;Hi sideview,&lt;/P&gt;

&lt;P&gt;thanks for the solution. This is exactly what i was looking for.&lt;BR /&gt;
but one question though,  as we cannot pass a field to the subsearch.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count | fields - count |eval formula="(x/2)*(x/2)" |eval x=12 | eval y=[| stats count | fields - count |eval f=formula|eval search=f ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;how to make the query dynamic?&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2016 23:57:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-my-lookup-field-value-to-an-executable-formula/m-p/217063#M63746</guid>
      <dc:creator>johnchamp</dc:creator>
      <dc:date>2016-02-23T23:57:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert my lookup field value to an executable formula?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-my-lookup-field-value-to-an-executable-formula/m-p/217064#M63747</link>
      <description>&lt;P&gt;Yes.... a big shortcoming.  Since in your case you have to get the formula from the outer search, and since there's no way to pass it into the inner search,  you may be out of luck.    the other "subsearch-ish" looking things in Splunk like join/append/map,  don't allow this  trick (where they can evaluate a string as a SPL expression).     It's quite possible that if you keep looking you'll find one that does though.... &lt;/P&gt;

&lt;P&gt;A custom search command written in python might be better, although of course evaluating strings of untrusted data so as to evaluate arbitrary code is up there on the list of worst security ideas ever, so keep that in mind. &lt;/P&gt;

&lt;P&gt;Also beware in your last comment - you have more than one field coming out of the subsearch and you'll end up with malformed syntax.   You need &lt;EM&gt;only&lt;/EM&gt; the "search" field to come back from the subsearch and here you have a "f" field as well. &lt;/P&gt;</description>
      <pubDate>Wed, 24 Feb 2016 16:36:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-my-lookup-field-value-to-an-executable-formula/m-p/217064#M63747</guid>
      <dc:creator>sideview</dc:creator>
      <dc:date>2016-02-24T16:36:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert my lookup field value to an executable formula?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-convert-my-lookup-field-value-to-an-executable-formula/m-p/217065#M63748</link>
      <description>&lt;P&gt;You can pass a field to an inner search by using &lt;CODE&gt;map&lt;/CODE&gt;.  Take this for example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | inputcsv myFileWithFormulasInFiledCalledFormula | map search="| inputcsv myFileWithFieldsXandY | eval result = $Formula$"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Inside this search you could do the subsearch thing, too.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Feb 2016 03:02:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-convert-my-lookup-field-value-to-an-executable-formula/m-p/217065#M63748</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2016-02-26T03:02:21Z</dc:date>
    </item>
  </channel>
</rss>

