<?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 are empty emails being sent using map &amp; sendemail commands in my search and how do I prevent this? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Why-are-empty-emails-being-sent-using-map-sendemail-commands-in/m-p/205817#M59854</link>
    <description>&lt;P&gt;Just wanted to comment here about the method of&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | outputcsv TempFile.csv
| ...
| ...
| where comment="MakeSureNoEventsRemain"
| append [|inputcsv Tempfile.csv]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I've been attempting to get something like this working, with no success, and I've just realized why. The [|inputcsv Tempfile.csv] subsearch executes first (as subsearches do), so when the search reaches the line of | append [|inputcsv Tempfile.csv], it appends whatever events existed in the Tempfile.csv at the BEGINING of the search, not what was populated into the file with | outputcsv Tempfile.csv.&lt;/P&gt;

&lt;P&gt;Took me a while to figure this out.&lt;/P&gt;</description>
    <pubDate>Thu, 29 Mar 2018 15:12:25 GMT</pubDate>
    <dc:creator>adamsmith47</dc:creator>
    <dc:date>2018-03-29T15:12:25Z</dc:date>
    <item>
      <title>Why are empty emails being sent using map &amp; sendemail commands in my search and how do I prevent this?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-are-empty-emails-being-sent-using-map-sendemail-commands-in/m-p/205811#M59848</link>
      <description>&lt;P&gt;Hi.  &lt;/P&gt;

&lt;P&gt;I tried to send an email for each event when triggered. I used &lt;CODE&gt;map&lt;/CODE&gt; and &lt;CODE&gt;sendemail&lt;/CODE&gt; commands, but there is an empty email always sent out, regardless if there is any event found.  How can I stop sending an empty email?  Thanks.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=xyz user=U12345 OR user=X12345
| table _time hostname user
| eval report_time=strftime(_time, "%d %b %Y %H:%M:%S")
| eval subject=$report_time$ + ", user, " + $user$ + " logged on to server " + $hostname$
|stats count by subject
| map [ search | eval subject=$subject$ | stats count by subject | fields - count | sendemail server=mail.server.net from=xyz to=abc subject=$result.subject$ sendresults=true] 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Jun 2016 18:13:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-are-empty-emails-being-sent-using-map-sendemail-commands-in/m-p/205811#M59848</guid>
      <dc:creator>splunkrocks2014</dc:creator>
      <dc:date>2016-06-09T18:13:02Z</dc:date>
    </item>
    <item>
      <title>Re: Why are empty emails being sent using map &amp; sendemail commands in my search and how do I prevent this?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-are-empty-emails-being-sent-using-map-sendemail-commands-in/m-p/205812#M59849</link>
      <description>&lt;P&gt;Give this a try&lt;BR /&gt;
&lt;STRONG&gt;Updated&lt;/STRONG&gt; &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=xyz user=U12345 OR user=X12345
 | table _time hostname user
 | eval report_time=strftime(_time, "%d %b %Y %H:%M:%S")
 | eval subject=$report_time$ + ", user, " + $user$ + " logged on to server " + $hostname$
 |stats count by subject
 | map [ | gentimes start=-1 | eval subject="$subject$" |table subject| sendemail server=mail.server.net from=xyz to=abc subject=$result.subject$ sendresults=true format=table inline=true] 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Jun 2016 18:45:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-are-empty-emails-being-sent-using-map-sendemail-commands-in/m-p/205812#M59849</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-06-09T18:45:44Z</dc:date>
    </item>
    <item>
      <title>Re: Why are empty emails being sent using map &amp; sendemail commands in my search and how do I prevent this?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-are-empty-emails-being-sent-using-map-sendemail-commands-in/m-p/205813#M59850</link>
      <description>&lt;P&gt;Hi somesoni2, thank you for your respond.  I am still getting an email with the following contents:&lt;/P&gt;

&lt;P&gt;"Search results.&lt;BR /&gt;
No results found.&lt;BR /&gt;
"&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jun 2016 18:56:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-are-empty-emails-being-sent-using-map-sendemail-commands-in/m-p/205813#M59850</guid>
      <dc:creator>splunkrocks2014</dc:creator>
      <dc:date>2016-06-09T18:56:22Z</dc:date>
    </item>
    <item>
      <title>Re: Why are empty emails being sent using map &amp; sendemail commands in my search and how do I prevent this?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-are-empty-emails-being-sent-using-map-sendemail-commands-in/m-p/205814#M59851</link>
      <description>&lt;P&gt;Try the updated answer.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jun 2016 19:12:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-are-empty-emails-being-sent-using-map-sendemail-commands-in/m-p/205814#M59851</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-06-09T19:12:10Z</dc:date>
    </item>
    <item>
      <title>Re: Why are empty emails being sent using map &amp; sendemail commands in my search and how do I prevent this?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-are-empty-emails-being-sent-using-map-sendemail-commands-in/m-p/205815#M59852</link>
      <description>&lt;P&gt;still getting empty email with the following contents:&lt;/P&gt;

&lt;P&gt;Search results.&lt;BR /&gt;
subject&lt;BR /&gt;
$subject$&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jun 2016 19:37:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-are-empty-emails-being-sent-using-map-sendemail-commands-in/m-p/205815#M59852</guid>
      <dc:creator>splunkrocks2014</dc:creator>
      <dc:date>2016-06-09T19:37:09Z</dc:date>
    </item>
    <item>
      <title>Re: Why are empty emails being sent using map &amp; sendemail commands in my search and how do I prevent this?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-are-empty-emails-being-sent-using-map-sendemail-commands-in/m-p/205816#M59853</link>
      <description>&lt;P&gt;This is from another Q&amp;amp;A:&lt;BR /&gt;
&lt;A href="https://answers.splunk.com/answers/399434/send-emailed-results-to-an-email-address-in-the-re.html#answer-399515"&gt;https://answers.splunk.com/answers/399434/send-emailed-results-to-an-email-address-in-the-re.html#answer-399515&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;If you need to send a contextually-appropriate subset of results to some people, you can skip the configuration-based email settings and do this in SPL:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | outputcsv TempFile.csv
| stats values(Email_Address) AS emailToHeader | mvexpand emailToHeader
| map search="|inputcsv TempFile.csv | where Email_Addresss=\"$emailToHeader$\"
   | fields - Email_Address
   | sendemail
      sendresults=true inline=true
      server=\"Your.Value.Here\"
      from=\"Your.Value.Here\"
      to=\"$emailToHeader$\"
      subject=\"Your Subject here: \$name\$\"
      message=\"This report alert was generated by \$app\$ Splunk with this search string: \$search\$\""
| where comment="MakeSureNoEventsRemain"
| append [|inputcsv TempFile.csv]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The only downside to this approach is that If the search does not return any results it will produce the following error: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;"Error in "map": Did not find value for required attributes 'emailToHeader'
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is "normal" and I have not found a good way to code around it.&lt;/P&gt;</description>
      <pubDate>Sun, 12 Jun 2016 17:43:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-are-empty-emails-being-sent-using-map-sendemail-commands-in/m-p/205816#M59853</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2016-06-12T17:43:38Z</dc:date>
    </item>
    <item>
      <title>Re: Why are empty emails being sent using map &amp; sendemail commands in my search and how do I prevent this?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-are-empty-emails-being-sent-using-map-sendemail-commands-in/m-p/205817#M59854</link>
      <description>&lt;P&gt;Just wanted to comment here about the method of&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | outputcsv TempFile.csv
| ...
| ...
| where comment="MakeSureNoEventsRemain"
| append [|inputcsv Tempfile.csv]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I've been attempting to get something like this working, with no success, and I've just realized why. The [|inputcsv Tempfile.csv] subsearch executes first (as subsearches do), so when the search reaches the line of | append [|inputcsv Tempfile.csv], it appends whatever events existed in the Tempfile.csv at the BEGINING of the search, not what was populated into the file with | outputcsv Tempfile.csv.&lt;/P&gt;

&lt;P&gt;Took me a while to figure this out.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Mar 2018 15:12:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-are-empty-emails-being-sent-using-map-sendemail-commands-in/m-p/205817#M59854</guid>
      <dc:creator>adamsmith47</dc:creator>
      <dc:date>2018-03-29T15:12:25Z</dc:date>
    </item>
    <item>
      <title>Re: Why are empty emails being sent using map &amp; sendemail commands in my search and how do I prevent this?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-are-empty-emails-being-sent-using-map-sendemail-commands-in/m-p/549959#M156067</link>
      <description>&lt;P&gt;does this finally work? i have a similar query to trigger the sendemail inside the map command, but I got "&lt;SPAN class="t"&gt;2021-04-30&lt;/SPAN&gt; &lt;SPAN class="t"&gt;04:05:59&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN class="t"&gt;276&lt;/SPAN&gt;&lt;SPAN&gt; +&lt;/SPAN&gt;&lt;SPAN class="t"&gt;0000&lt;/SPAN&gt; &lt;SPAN class="t"&gt;ERROR&lt;/SPAN&gt; &lt;SPAN class="t"&gt;sendemail:1428&lt;/SPAN&gt; &lt;SPAN class="t"&gt;-&lt;/SPAN&gt;&lt;SPAN&gt; [&lt;/SPAN&gt;&lt;SPAN class="t"&gt;HTTP&lt;/SPAN&gt; &lt;SPAN class="t"&gt;403&lt;/SPAN&gt;&lt;SPAN&gt;] &lt;/SPAN&gt;&lt;SPAN class="t"&gt;Client&lt;/SPAN&gt; &lt;SPAN class="t"&gt;is&lt;/SPAN&gt; &lt;SPAN class="t"&gt;not&lt;/SPAN&gt; &lt;SPAN class="t"&gt;authorized&lt;/SPAN&gt; &lt;SPAN class="t"&gt;to&lt;/SPAN&gt; &lt;SPAN class="t"&gt;perform&lt;/SPAN&gt; &lt;SPAN class="t"&gt;requested&lt;/SPAN&gt; &lt;SPAN class="t"&gt;action&lt;/SPAN&gt;&lt;SPAN class="t"&gt;" error in&amp;nbsp;index=_internal source=*python.log*, but the sendemail works if I run separately, some post said the script inside map missed the context, do you know how we could fix this?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Apr 2021 06:12:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-are-empty-emails-being-sent-using-map-sendemail-commands-in/m-p/549959#M156067</guid>
      <dc:creator>wangjianiu</dc:creator>
      <dc:date>2021-04-30T06:12:16Z</dc:date>
    </item>
  </channel>
</rss>

