<?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: macro with eval-based definition: error - the definition is expected to be an eval expression that returns a string. in Knowledge Management</title>
    <link>https://community.splunk.com/t5/Knowledge-Management/macro-with-eval-based-definition-error-the-definition-is/m-p/453983#M4027</link>
    <description>&lt;P&gt;Sure enough, this worked. Thanks Martin!&lt;/P&gt;</description>
    <pubDate>Wed, 06 Feb 2019 18:56:53 GMT</pubDate>
    <dc:creator>daveloaiza</dc:creator>
    <dc:date>2019-02-06T18:56:53Z</dc:date>
    <item>
      <title>macro with eval-based definition: error - the definition is expected to be an eval expression that returns a string.</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/macro-with-eval-based-definition-error-the-definition-is/m-p/453981#M4025</link>
      <description>&lt;P&gt;Hoping to use a macro to simplify search terms as follows:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=my_index sourcetype=my_sourcetype splunk_servers=`splunk_domain(west)`
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;A macro is set up to take one argument, $splunk_domain$, and the definition is currently as follows:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;case(tostring($splunk_domain$)=="west","*.domain.west",tostring($splunk_domain$)=="east","*.domain.east",tostring($splunk_domain$)=="corp","*.domain.corp",true(),*)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Use eval-based definition option is enabled. I have tried several different combinations of double quotes and the tostring() function on both the case conditions and outputs. I have also tried changing the definition to &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval splunk_server= case(tostring($splunk_domain$)=="west", "*.domain.west",tostring($splunk_domain$)=="east", "*.domain.east",tostring($splunk_domain$)=="corp","*.domain.corp",true(),*)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and changing the search to&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=my_index sourcetype=my_sourcetype `splunk_domain(west)`
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This all seems to return the same "expected string" error message.  Doing all this from the GUI as I don't have access to macros.conf.&lt;/P&gt;

&lt;P&gt;Is this a valid use of macros, and if so, what needs to change so that the expected string is returned?&lt;/P&gt;</description>
      <pubDate>Tue, 05 Feb 2019 20:28:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/macro-with-eval-based-definition-error-the-definition-is/m-p/453981#M4025</guid>
      <dc:creator>daveloaiza</dc:creator>
      <dc:date>2019-02-05T20:28:24Z</dc:date>
    </item>
    <item>
      <title>Re: macro with eval-based definition: error - the definition is expected to be an eval expression that returns a string.</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/macro-with-eval-based-definition-error-the-definition-is/m-p/453982#M4026</link>
      <description>&lt;P&gt;The first definition looks good, except for the final option inside your case expression - &lt;CODE&gt;*&lt;/CODE&gt; is not a string, &lt;CODE&gt;"*"&lt;/CODE&gt; would be. That will get rid of the error message.&lt;/P&gt;

&lt;P&gt;That won't yet get you the results you want though, because as-is the eval expression will treat the &lt;CODE&gt;west&lt;/CODE&gt; you put in as a name, not as a string. You'll have to add quotes around the argument to force a string:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;case("$splunk_domain$"=="west", "*.domain.west", "$splunk_domain$"=="east", "*.domain.east", "$splunk_domain$"=="corp", "*.domain.corp", true(), "*")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Looks weird, but that ^ works.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Feb 2019 21:32:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/macro-with-eval-based-definition-error-the-definition-is/m-p/453982#M4026</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2019-02-05T21:32:51Z</dc:date>
    </item>
    <item>
      <title>Re: macro with eval-based definition: error - the definition is expected to be an eval expression that returns a string.</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/macro-with-eval-based-definition-error-the-definition-is/m-p/453983#M4027</link>
      <description>&lt;P&gt;Sure enough, this worked. Thanks Martin!&lt;/P&gt;</description>
      <pubDate>Wed, 06 Feb 2019 18:56:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/macro-with-eval-based-definition-error-the-definition-is/m-p/453983#M4027</guid>
      <dc:creator>daveloaiza</dc:creator>
      <dc:date>2019-02-06T18:56:53Z</dc:date>
    </item>
  </channel>
</rss>

