<?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: Map command breaks when scheduled in Alerting</title>
    <link>https://community.splunk.com/t5/Alerting/Map-command-breaks-when-scheduled/m-p/43508#M544</link>
    <description>&lt;P&gt;Old topic but someone may find it via google looking for a solution.&lt;BR /&gt;
For me saved search with map command, to which $variable$ is passed worked in the following way...&lt;/P&gt;

&lt;P&gt;savedsearch_1:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;foo | map savedsearch_2 var1=$var1$ var2=$var2$
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;savedsearch_2:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;search bar | where var1=$var1$ var2=$var2$ | head 1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Trying different syntax like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    foo | map search="search bar | where var1=\"$var1\" var2=\"var2\" | head 1"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;worked well in interactive search but on saved and scheduled the variables weren't passed to the map command so the search always was returning no results.&lt;/P&gt;</description>
    <pubDate>Wed, 15 Feb 2012 11:14:02 GMT</pubDate>
    <dc:creator>s_n</dc:creator>
    <dc:date>2012-02-15T11:14:02Z</dc:date>
    <item>
      <title>Map command breaks when scheduled</title>
      <link>https://community.splunk.com/t5/Alerting/Map-command-breaks-when-scheduled/m-p/43505#M541</link>
      <description>&lt;P&gt;I am running a custom python search command for custom alerting from Splunk which takes variables from the search query and using the map command to feed the set variables into the script.&lt;/P&gt;

&lt;P&gt;I'll use the &lt;STRONG&gt;sendemail&lt;/STRONG&gt; command as an example;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;host="myserver" "OutOfMemory" | map search="| sendemail to="test@test.com" subject=$host$ server="mailhost""
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This works perfectly when run directly via the GUI search, however if I turn this into a ScheduledSearch using the same query it doesn't work. Splunk logs will indicate that it ran succesfully and didnt encounter any exceptions however my email does not get sent.&lt;/P&gt;

&lt;P&gt;By turning the &lt;STRONG&gt;sendemail&lt;/STRONG&gt; function to echo the output into a text file I can see that nothing happens either. What gets interesting is that if I replace &lt;STRONG&gt;$host$&lt;/STRONG&gt; with &lt;STRONG&gt;"myservername"&lt;/STRONG&gt; and dont use any &lt;STRONG&gt;$variables$&lt;/STRONG&gt; it works!&lt;/P&gt;

&lt;P&gt;I have tried escaping the strings passed to the python script directly within the script when extracting the variables though it has no affect.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;subject=\"\'$host$\'\" 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;By double quoting the above it still works via the GUI, though when scheduled my email sends but with subject as inner quotes - \'\'&lt;/P&gt;

&lt;P&gt;Indicating that the variable is either not being transformed or is replaced with nothing.&lt;/P&gt;

&lt;P&gt;I have tried placing the entire search query again within the sub map search with no affect either...&lt;/P&gt;

&lt;P&gt;Any suggestions would be great, otherwise I'll have to raise a support case.&lt;/P&gt;

&lt;P&gt;&lt;EM&gt;Note: This is on a windows server.&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jul 2011 09:16:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/Map-command-breaks-when-scheduled/m-p/43505#M541</guid>
      <dc:creator>Joshua</dc:creator>
      <dc:date>2011-07-15T09:16:33Z</dc:date>
    </item>
    <item>
      <title>Re: Map command breaks when scheduled</title>
      <link>https://community.splunk.com/t5/Alerting/Map-command-breaks-when-scheduled/m-p/43506#M542</link>
      <description>&lt;P&gt;Workaround developed until a resolution for this method is found.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jul 2011 13:44:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/Map-command-breaks-when-scheduled/m-p/43506#M542</guid>
      <dc:creator>Joshua</dc:creator>
      <dc:date>2011-07-18T13:44:45Z</dc:date>
    </item>
    <item>
      <title>Re: Map command breaks when scheduled</title>
      <link>https://community.splunk.com/t5/Alerting/Map-command-breaks-when-scheduled/m-p/43507#M543</link>
      <description>&lt;P&gt;Your quoting is wrong for the map command.  Try using the subsearch syntax.&lt;BR /&gt;
e.g. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| map [ sendemail to="test@test.com" subject=$host$ server="mailhost"]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;See:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&lt;A href="http://splunk-base.splunk.com/answers/27012/whats-wrong-with-this-map-search-command" target="test_blank"&gt;http://splunk-base.splunk.com/answers/27012/whats-wrong-with-this-map-search-command&lt;/A&gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 26 Sep 2011 22:30:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/Map-command-breaks-when-scheduled/m-p/43507#M543</guid>
      <dc:creator>carasso</dc:creator>
      <dc:date>2011-09-26T22:30:29Z</dc:date>
    </item>
    <item>
      <title>Re: Map command breaks when scheduled</title>
      <link>https://community.splunk.com/t5/Alerting/Map-command-breaks-when-scheduled/m-p/43508#M544</link>
      <description>&lt;P&gt;Old topic but someone may find it via google looking for a solution.&lt;BR /&gt;
For me saved search with map command, to which $variable$ is passed worked in the following way...&lt;/P&gt;

&lt;P&gt;savedsearch_1:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;foo | map savedsearch_2 var1=$var1$ var2=$var2$
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;savedsearch_2:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;search bar | where var1=$var1$ var2=$var2$ | head 1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Trying different syntax like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    foo | map search="search bar | where var1=\"$var1\" var2=\"var2\" | head 1"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;worked well in interactive search but on saved and scheduled the variables weren't passed to the map command so the search always was returning no results.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Feb 2012 11:14:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/Map-command-breaks-when-scheduled/m-p/43508#M544</guid>
      <dc:creator>s_n</dc:creator>
      <dc:date>2012-02-15T11:14:02Z</dc:date>
    </item>
    <item>
      <title>Re: Map command breaks when scheduled</title>
      <link>https://community.splunk.com/t5/Alerting/Map-command-breaks-when-scheduled/m-p/43509#M545</link>
      <description>&lt;P&gt;Just wanted to highlight the fact that the key here is saving a search for the map command to use. Variable names inside a string disappear when run by the scheduler.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Apr 2012 22:15:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/Map-command-breaks-when-scheduled/m-p/43509#M545</guid>
      <dc:creator>tysonstewart</dc:creator>
      <dc:date>2012-04-10T22:15:20Z</dc:date>
    </item>
    <item>
      <title>Re: Map command breaks when scheduled</title>
      <link>https://community.splunk.com/t5/Alerting/Map-command-breaks-when-scheduled/m-p/43510#M546</link>
      <description>&lt;P&gt;Thanks a lot for sharing this approach! It helped me out and I can confirm that it worked for me as solution for the above problem.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Oct 2012 09:31:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/Map-command-breaks-when-scheduled/m-p/43510#M546</guid>
      <dc:creator>traugust</dc:creator>
      <dc:date>2012-10-08T09:31:56Z</dc:date>
    </item>
  </channel>
</rss>

