<?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: not sendemail if &amp;quot;Results not found&amp;quot; in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/not-sendemail-if-quot-Results-not-found-quot/m-p/135831#M37163</link>
    <description>&lt;P&gt;See &lt;A href="http://answers.splunk.com/answers/13420/sendemail-to-function-send-email-only-if-there-are-results.html"&gt;http://answers.splunk.com/answers/13420/sendemail-to-function-send-email-only-if-there-are-results.html&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 01 Apr 2015 02:45:35 GMT</pubDate>
    <dc:creator>ben363</dc:creator>
    <dc:date>2015-04-01T02:45:35Z</dc:date>
    <item>
      <title>not sendemail if "Results not found"</title>
      <link>https://community.splunk.com/t5/Splunk-Search/not-sendemail-if-quot-Results-not-found-quot/m-p/135828#M37160</link>
      <description>&lt;P&gt;Hi. I'm trying to selectively send emails (using sendemail); if the output of the query is "No results found" or "No results", I don't want to send emails.&lt;/P&gt;

&lt;P&gt;here's my cli command:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;splunk search "|savedsearch hello|sendemail to=admin@example.com from=server@example.com sendresults=true format=html inline=true subject=splunk_log"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;hello is a generic query returning nothing &lt;/P&gt;</description>
      <pubDate>Wed, 09 Jul 2014 16:13:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/not-sendemail-if-quot-Results-not-found-quot/m-p/135828#M37160</guid>
      <dc:creator>retesi</dc:creator>
      <dc:date>2014-07-09T16:13:23Z</dc:date>
    </item>
    <item>
      <title>Re: not sendemail if "Results not found"</title>
      <link>https://community.splunk.com/t5/Splunk-Search/not-sendemail-if-quot-Results-not-found-quot/m-p/135829#M37161</link>
      <description>&lt;P&gt;Do you execute the search (result of which you want to email) manually on adhoc basis?&lt;/P&gt;</description>
      <pubDate>Wed, 09 Jul 2014 19:55:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/not-sendemail-if-quot-Results-not-found-quot/m-p/135829#M37161</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2014-07-09T19:55:45Z</dc:date>
    </item>
    <item>
      <title>Re: not sendemail if "Results not found"</title>
      <link>https://community.splunk.com/t5/Splunk-Search/not-sendemail-if-quot-Results-not-found-quot/m-p/135830#M37162</link>
      <description>&lt;P&gt;Having the same issue. Is there a way when using the sendemail command to only send email if there are results? &lt;/P&gt;</description>
      <pubDate>Wed, 17 Sep 2014 12:26:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/not-sendemail-if-quot-Results-not-found-quot/m-p/135830#M37162</guid>
      <dc:creator>rdownie</dc:creator>
      <dc:date>2014-09-17T12:26:19Z</dc:date>
    </item>
    <item>
      <title>Re: not sendemail if "Results not found"</title>
      <link>https://community.splunk.com/t5/Splunk-Search/not-sendemail-if-quot-Results-not-found-quot/m-p/135831#M37163</link>
      <description>&lt;P&gt;See &lt;A href="http://answers.splunk.com/answers/13420/sendemail-to-function-send-email-only-if-there-are-results.html"&gt;http://answers.splunk.com/answers/13420/sendemail-to-function-send-email-only-if-there-are-results.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Apr 2015 02:45:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/not-sendemail-if-quot-Results-not-found-quot/m-p/135831#M37163</guid>
      <dc:creator>ben363</dc:creator>
      <dc:date>2015-04-01T02:45:35Z</dc:date>
    </item>
    <item>
      <title>Re: not sendemail if "Results not found"</title>
      <link>https://community.splunk.com/t5/Splunk-Search/not-sendemail-if-quot-Results-not-found-quot/m-p/135832#M37164</link>
      <description>&lt;P&gt;Dirty way to do it, but effective!&lt;/P&gt;

&lt;P&gt;Also a good way to email users who do bad things... &lt;/P&gt;

&lt;P&gt;| eval to=case(_raw!="","whoz-at-who.com") | sendemail to=$result.to$&lt;/P&gt;</description>
      <pubDate>Tue, 10 Nov 2015 15:30:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/not-sendemail-if-quot-Results-not-found-quot/m-p/135832#M37164</guid>
      <dc:creator>sbochniewicz</dc:creator>
      <dc:date>2015-11-10T15:30:45Z</dc:date>
    </item>
    <item>
      <title>Re: not sendemail if "Results not found"</title>
      <link>https://community.splunk.com/t5/Splunk-Search/not-sendemail-if-quot-Results-not-found-quot/m-p/135833#M37165</link>
      <description>&lt;P&gt;Do it like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | rename COMMENT1of3 AS "Splunk sendemail ALWAYS sends email, even when no results found; we address this with 2 settings:"
| rename COMMENT2of3 AS "First, we put 'null()' in 'to' header when no results; this causes 'sendemail' to error."
| rename COMMENT3of3 AS "Last, we use 'graceful=true' so that the search does not log any error for that."
| eval valueForToHeader=if(isnotnull(someFieldNameInYourResults), "YourGoodEmailGoesHere@YourCompany.com", null())
| sendemail
   to=$result.valueForToHeader$
   graceful=true
   ...
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 25 Jul 2018 21:13:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/not-sendemail-if-quot-Results-not-found-quot/m-p/135833#M37165</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2018-07-25T21:13:39Z</dc:date>
    </item>
    <item>
      <title>Re: not sendemail if "Results not found"</title>
      <link>https://community.splunk.com/t5/Splunk-Search/not-sendemail-if-quot-Results-not-found-quot/m-p/135834#M37166</link>
      <description>&lt;P&gt;The caveat of this is that the email address must exist in the resultset, otherwise it assumes it's null. This means all your emails will have the field "valueForToHeader" at the end of all the columns. Could be worse, but could be much better.&lt;/P&gt;

&lt;P&gt;If, in the case that you don't want to email if there are no results, you don't even need to put in an if statement. If there are no events, there can be no event where you can eval a value to a field -- therefore it will still try to send as null.&lt;/P&gt;

&lt;P&gt;Tested the following scenarios:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults | eval to_address="test_address@company.com" | sendemail to=$result.to_address$ subject="Test Email"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This works&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults | eval to_address="test_address@company.com" | table _time | sendemail to=$result.to_address$ subject="Test Email"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This does not work (null to address)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults | eval to_address="test_address@company.com", temp="something" | search temp="somethingelse" | sendemail to=$result.to_address$ subject="Test Email"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This does not work (null to address)&lt;/P&gt;</description>
      <pubDate>Wed, 13 Feb 2019 12:24:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/not-sendemail-if-quot-Results-not-found-quot/m-p/135834#M37166</guid>
      <dc:creator>althomas</dc:creator>
      <dc:date>2019-02-13T12:24:16Z</dc:date>
    </item>
  </channel>
</rss>

