<?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 do you interpret string variable as SPL in Map function? in Installation</title>
    <link>https://community.splunk.com/t5/Installation/How-do-you-interpret-string-variable-as-SPL-in-Map-function/m-p/385354#M8874</link>
    <description>&lt;P&gt;You can cheat:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults | eval search = "index=_internal sourcetype=splunkd*" | map [search [makeresults | eval search=$search$ | table search] | stats count by sourcetype]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The subsearch will effectively unwrap the string from its double quotes. Not pretty, but it works...&lt;BR /&gt;
Same thing can be achieved with a macro:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults | eval search = "index=_internal sourcetype=splunkd*" | map search="search `unwrap($search$)` | stats count by sourcetype"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The macro is defined like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[unwrap(1)]
args = arg
definition = $arg$
iseval = 0
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In general, things involving &lt;CODE&gt;map&lt;/CODE&gt; often turn towards the hacky side of life.&lt;/P&gt;</description>
    <pubDate>Thu, 15 Nov 2018 01:47:29 GMT</pubDate>
    <dc:creator>martin_mueller</dc:creator>
    <dc:date>2018-11-15T01:47:29Z</dc:date>
    <item>
      <title>How do you interpret string variable as SPL in Map function?</title>
      <link>https://community.splunk.com/t5/Installation/How-do-you-interpret-string-variable-as-SPL-in-Map-function/m-p/385353#M8873</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Background&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;I have a variety of firewall logs that I use to monitor if specific applications are up and running. If there are no firewall logs about that application, it alerts me if the application is down. I did not want to create an individual alert for each application because that gets difficult to manage. Instead, I want to create one alert that iterates over a lookup .CSV file and tests all cases configured in it. &lt;/P&gt;

&lt;P&gt;The structure of this lookup file is:&lt;BR /&gt;
&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/6082i8CA93D49E7BC791D/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;The Alert SPL is:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| inputlookup device_function_alert.csv 
`comment("Run the below search for each row in the lookup")`
| map maxsearches=1000 search="search index=$index$ host=$host$ source=$source$ sourcetype=$sourcetype$ earliest=$earliest$ $search$
| fields index, host, source, sourcetype, _time
`comment("Append pipe creates a result for events where the search returned nothing")`
| appendpipe [ stats count]
| eval index=\"$index$\"
| eval host=\"$host$\"
| eval source=\"$source$\" 
| eval sourcetype=\"$sourcetype$\" 
| stats earliest(_time) AS oldest_log count by index, host, source, sourcetype
`comment("If there is no earliest time on the logs then no events were found and set count to 0")`
| eval count=if(isnull(oldest_log), 0, count)" 
| where count==0
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Problem&lt;/STRONG&gt;&lt;BR /&gt;
This search works perfectly except for the $search$ variable. The search parser interprets the first line of the map search as&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=firewall_index host="*" source="*" sourcetype="*" earliest="-1h" "src_ip=10.0.0.0 OR src_ip=10.0.0.1 AND dest_url=*"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The $search$ variable was treated as a string and not as SPL. So it searched for literal match of &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;"src_ip=10.0.0.0 OR src_ip=10.0.0.1 AND dest_url=*"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Is there a way in Splunk to have the search parser see a field as SPL and interpret it as such inside a Map function?&lt;/P&gt;</description>
      <pubDate>Wed, 14 Nov 2018 21:46:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Installation/How-do-you-interpret-string-variable-as-SPL-in-Map-function/m-p/385353#M8873</guid>
      <dc:creator>eykrevooh</dc:creator>
      <dc:date>2018-11-14T21:46:45Z</dc:date>
    </item>
    <item>
      <title>Re: How do you interpret string variable as SPL in Map function?</title>
      <link>https://community.splunk.com/t5/Installation/How-do-you-interpret-string-variable-as-SPL-in-Map-function/m-p/385354#M8874</link>
      <description>&lt;P&gt;You can cheat:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults | eval search = "index=_internal sourcetype=splunkd*" | map [search [makeresults | eval search=$search$ | table search] | stats count by sourcetype]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The subsearch will effectively unwrap the string from its double quotes. Not pretty, but it works...&lt;BR /&gt;
Same thing can be achieved with a macro:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults | eval search = "index=_internal sourcetype=splunkd*" | map search="search `unwrap($search$)` | stats count by sourcetype"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The macro is defined like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[unwrap(1)]
args = arg
definition = $arg$
iseval = 0
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In general, things involving &lt;CODE&gt;map&lt;/CODE&gt; often turn towards the hacky side of life.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Nov 2018 01:47:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Installation/How-do-you-interpret-string-variable-as-SPL-in-Map-function/m-p/385354#M8874</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2018-11-15T01:47:29Z</dc:date>
    </item>
    <item>
      <title>Re: How do you interpret string variable as SPL in Map function?</title>
      <link>https://community.splunk.com/t5/Installation/How-do-you-interpret-string-variable-as-SPL-in-Map-function/m-p/385355#M8875</link>
      <description>&lt;P&gt;Thank you! This worked very well! I had been hitting a wall with this problem.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Nov 2018 15:41:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Installation/How-do-you-interpret-string-variable-as-SPL-in-Map-function/m-p/385355#M8875</guid>
      <dc:creator>eykrevooh</dc:creator>
      <dc:date>2018-11-15T15:41:53Z</dc:date>
    </item>
  </channel>
</rss>

