<?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: Why nested macros using the same argument wont work when the argument has strings in double quotes? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Why-nested-macros-using-the-same-argument-wont-work-when-the/m-p/633783#M220121</link>
    <description>&lt;P&gt;Yes, that is what we thought, but since we dont know how much nesting depth we are going to use, we just cant hardcode the escaped backslashes all the way down.&lt;/P&gt;</description>
    <pubDate>Wed, 08 Mar 2023 18:03:20 GMT</pubDate>
    <dc:creator>joshiro</dc:creator>
    <dc:date>2023-03-08T18:03:20Z</dc:date>
    <item>
      <title>Why nested macros using the same argument wont work when the argument has strings in double quotes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-nested-macros-using-the-same-argument-wont-work-when-the/m-p/633194#M219957</link>
      <description>&lt;P&gt;We have this scenario where two nested macros using the same argument raises an error at the parsing of the second one because of the double quotes in the arguments dissapear.&lt;BR /&gt;&lt;BR /&gt;If we define the two macros as the following:&lt;BR /&gt;"test_args2(1)" -&amp;gt; `test_args("$args$")`&lt;BR /&gt;"test_args(1)" -&amp;gt; | eval arguments = $args$&lt;BR /&gt;&lt;BR /&gt;And then run the following search:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
`test_arguments2("[| makeresults | eval arguments = tostring(floor(relative_time(_time, "@y"))) | return $arguments]")`
| table arguments&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;It raises the following error:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="joshiro_0-1677856355494.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/24180iFBC0222E6922FB19/image-size/medium?v=v2&amp;amp;px=400" role="button" title="joshiro_0-1677856355494.png" alt="joshiro_0-1677856355494.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;And the search log shows that after expanding the first macro then it removes the double quotations from the argument:&lt;/P&gt;&lt;PRE&gt;PARSING: | makeresults \n`test_arguments2("[| makeresults | eval arguments = tostring(floor(relative_time(_time, "@y"))) | return $arguments]")`\n| table arguments
AFTER EXPANDING MACROS: | makeresults \n| eval arguments = [| makeresults | eval arguments = tostring(floor(relative_time(_time, @y))) | return $arguments]\n| table arguments&lt;/PRE&gt;&lt;P&gt;It doesnt work either if we scape the doble quotes as:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
`test_arguments2("[| makeresults | eval arguments = tostring(floor(relative_time(_time, \"@y\"))) | return $arguments]")`
| table arguments​&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;Has anyone encounter a similar issue? How did you get around it or solve it?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Mar 2023 15:21:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-nested-macros-using-the-same-argument-wont-work-when-the/m-p/633194#M219957</guid>
      <dc:creator>joshiro</dc:creator>
      <dc:date>2023-03-03T15:21:54Z</dc:date>
    </item>
    <item>
      <title>Re: Why nested macros using the same argument wont work when the argument has strings in double quotes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-nested-macros-using-the-same-argument-wont-work-when-the/m-p/633612#M220071</link>
      <description>&lt;P&gt;We managed get a workaround this issue by creating a third macro with the whole string we are passing as the argument:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;`args` -&amp;gt; | makeresults | eval arguments = tostring(floor(relative_time(_time, "@y"))) | return $arguments&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Now we can run he following SPL without the parsing error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
`test_arguments2("[`args`]")`
| table arguments&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;BR /&gt;By using the third macro with the arguments, we avoid Splunk to parse the arguments directly and removing the double quotes.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2023 17:23:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-nested-macros-using-the-same-argument-wont-work-when-the/m-p/633612#M220071</guid>
      <dc:creator>joshiro</dc:creator>
      <dc:date>2023-03-07T17:23:37Z</dc:date>
    </item>
    <item>
      <title>Re: Why nested macros using the same argument wont work when the argument has strings in double quotes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-nested-macros-using-the-same-argument-wont-work-when-the/m-p/633638#M220083</link>
      <description>&lt;P&gt;You're expanding arguments twice so you might need escaping them twice.&lt;/P&gt;&lt;P&gt;Like&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;`test_arguments2("\"[| makeresults | eval arguments = tostring(floor(relative_time(_time, \"@y\"))) | return $arguments]\"")`&lt;/LI-CODE&gt;&lt;P&gt;The '@y' part could also use escaping backslashes so that it turns into \\\"@y\\\"&lt;/P&gt;&lt;P&gt;Yes, nested (un)escaping can be a PITA&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2023 20:35:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-nested-macros-using-the-same-argument-wont-work-when-the/m-p/633638#M220083</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2023-03-07T20:35:11Z</dc:date>
    </item>
    <item>
      <title>Re: Why nested macros using the same argument wont work when the argument has strings in double quotes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-nested-macros-using-the-same-argument-wont-work-when-the/m-p/633749#M220113</link>
      <description>&lt;P&gt;Thanks for the feedback.&lt;BR /&gt;&lt;BR /&gt;This approach is also working correctly, no longer raises the same error when removes the double quotes from the "@y".&lt;BR /&gt;But it wont work if you nest the macros more than 2 times.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Mar 2023 16:08:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-nested-macros-using-the-same-argument-wont-work-when-the/m-p/633749#M220113</guid>
      <dc:creator>joshiro</dc:creator>
      <dc:date>2023-03-08T16:08:10Z</dc:date>
    </item>
    <item>
      <title>Re: Why nested macros using the same argument wont work when the argument has strings in double quotes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-nested-macros-using-the-same-argument-wont-work-when-the/m-p/633770#M220117</link>
      <description>&lt;P&gt;It should work. But you'll need so much more escaping that your head will spin since all escaped backslashes will need escaping again. (same goes often in bash scripts - my record was something similar to&amp;nbsp; \\\\\\\\" &lt;span class="lia-unicode-emoji" title=":rolling_on_the_floor_laughing:"&gt;🤣&lt;/span&gt;)&lt;/P&gt;</description>
      <pubDate>Wed, 08 Mar 2023 16:53:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-nested-macros-using-the-same-argument-wont-work-when-the/m-p/633770#M220117</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2023-03-08T16:53:44Z</dc:date>
    </item>
    <item>
      <title>Re: Why nested macros using the same argument wont work when the argument has strings in double quotes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-nested-macros-using-the-same-argument-wont-work-when-the/m-p/633783#M220121</link>
      <description>&lt;P&gt;Yes, that is what we thought, but since we dont know how much nesting depth we are going to use, we just cant hardcode the escaped backslashes all the way down.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Mar 2023 18:03:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-nested-macros-using-the-same-argument-wont-work-when-the/m-p/633783#M220121</guid>
      <dc:creator>joshiro</dc:creator>
      <dc:date>2023-03-08T18:03:20Z</dc:date>
    </item>
  </channel>
</rss>

