<?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 How to return string in macro after some logics in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-return-string-in-macro-after-some-logics/m-p/610212#M212198</link>
    <description>&lt;P&gt;I have following eval based macro to return a string, in the end I am expecting macro to return something like "earliest=08/20/2022:18:39:14 latest=08/20/2022:18:55:14"&lt;BR /&gt;so that i can use it in search as follows.&amp;nbsp;&lt;/P&gt;&lt;P&gt;index=main org_name="cards-org" app_name="service-prod"&lt;BR /&gt;`search_range("2022-08-20 19:15:14.104",2)`| table _time msg&lt;/P&gt;&lt;P&gt;But I am getting below error.&amp;nbsp; Please help to understand what is wrong with this and how to achieve this.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;"Error in 'SearchParser': The definition of macro 'search_range(2)' is expected to be an eval expression that returns a string."&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="inherit"&gt;Eval based macro &lt;/FONT&gt;definition&lt;FONT face="inherit"&gt;&amp;nbsp;as follows.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;| makeresults&lt;BR /&gt;|eval Date="$daterange$"&lt;BR /&gt;| eval minutes=$seconds$&lt;BR /&gt;| eval formattedEarlyts = strftime((strptime(Date, "%Y-%m-%d %H:%M:%S.%3N") - (minutes * 60)),"%m/%d/%Y:%H:%M:%S")&lt;BR /&gt;| eval formattedLatestts = strftime((strptime(Date, "%Y-%m-%d %H:%M:%S.%3N") + (minutes * 60)),"%m/%d/%Y:%H:%M:%S")&lt;BR /&gt;| eval timerange= " earliest="+formattedEarlyts+" "+"latest="+formattedLatestts&lt;BR /&gt;| fields - Date minutes formattedEarlyts formattedLatestts&lt;BR /&gt;| eval case (1==1,timerange)&lt;/P&gt;</description>
    <pubDate>Sat, 20 Aug 2022 19:27:59 GMT</pubDate>
    <dc:creator>madhavanv</dc:creator>
    <dc:date>2022-08-20T19:27:59Z</dc:date>
    <item>
      <title>How to return string in macro after some logics</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-return-string-in-macro-after-some-logics/m-p/610212#M212198</link>
      <description>&lt;P&gt;I have following eval based macro to return a string, in the end I am expecting macro to return something like "earliest=08/20/2022:18:39:14 latest=08/20/2022:18:55:14"&lt;BR /&gt;so that i can use it in search as follows.&amp;nbsp;&lt;/P&gt;&lt;P&gt;index=main org_name="cards-org" app_name="service-prod"&lt;BR /&gt;`search_range("2022-08-20 19:15:14.104",2)`| table _time msg&lt;/P&gt;&lt;P&gt;But I am getting below error.&amp;nbsp; Please help to understand what is wrong with this and how to achieve this.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;"Error in 'SearchParser': The definition of macro 'search_range(2)' is expected to be an eval expression that returns a string."&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="inherit"&gt;Eval based macro &lt;/FONT&gt;definition&lt;FONT face="inherit"&gt;&amp;nbsp;as follows.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;| makeresults&lt;BR /&gt;|eval Date="$daterange$"&lt;BR /&gt;| eval minutes=$seconds$&lt;BR /&gt;| eval formattedEarlyts = strftime((strptime(Date, "%Y-%m-%d %H:%M:%S.%3N") - (minutes * 60)),"%m/%d/%Y:%H:%M:%S")&lt;BR /&gt;| eval formattedLatestts = strftime((strptime(Date, "%Y-%m-%d %H:%M:%S.%3N") + (minutes * 60)),"%m/%d/%Y:%H:%M:%S")&lt;BR /&gt;| eval timerange= " earliest="+formattedEarlyts+" "+"latest="+formattedLatestts&lt;BR /&gt;| fields - Date minutes formattedEarlyts formattedLatestts&lt;BR /&gt;| eval case (1==1,timerange)&lt;/P&gt;</description>
      <pubDate>Sat, 20 Aug 2022 19:27:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-return-string-in-macro-after-some-logics/m-p/610212#M212198</guid>
      <dc:creator>madhavanv</dc:creator>
      <dc:date>2022-08-20T19:27:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to return string in macro after some logics</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-return-string-in-macro-after-some-logics/m-p/610215#M212201</link>
      <description>&lt;P&gt;The error is as it says, the macro can only contain an eval expression, not full search commands. &amp;nbsp;For example, you can put&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;$a$&lt;/LI-CODE&gt;&lt;P&gt;in an eval-base macro, or&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;$a$ + $b$&lt;/LI-CODE&gt;&lt;P&gt;or&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;"\"" . strftime((strptime($daterange$, "%Y-%m-%d %H:%M:%S.%3N") - $seconds$ * 60)),"%m/%d/%Y:%H:%M:%S") . "\""&lt;/LI-CODE&gt;&lt;P&gt;in eval-based macro&lt;/P&gt;</description>
      <pubDate>Sat, 20 Aug 2022 21:07:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-return-string-in-macro-after-some-logics/m-p/610215#M212201</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2022-08-20T21:07:23Z</dc:date>
    </item>
  </channel>
</rss>

