<?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: sendemail to Function - Send email only if there are results in Reporting</title>
    <link>https://community.splunk.com/t5/Reporting/sendemail-to-Function-Send-email-only-if-there-are-results/m-p/73356#M1666</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:14:05 GMT</pubDate>
    <dc:creator>woodcock</dc:creator>
    <dc:date>2018-07-25T21:14:05Z</dc:date>
    <item>
      <title>sendemail to Function - Send email only if there are results</title>
      <link>https://community.splunk.com/t5/Reporting/sendemail-to-Function-Send-email-only-if-there-are-results/m-p/73354#M1664</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I am using the sendemail to function in my search to send emails. I receive the email whenever the search is run as expected. Is there a way to configure the search/sendemail function so that email is only sent out if there are results?&lt;/P&gt;

&lt;P&gt;I am aware that i can accomplish this if use the schedule search with alert functionality and pick generate alerts if events greater than &amp;gt; 0. I cannot use this as i want the results in a csv file. The alert functionality is configured to use inline results and i am not able to modify it for a single search.&lt;/P&gt;</description>
      <pubDate>Sat, 02 Apr 2011 02:31:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/sendemail-to-Function-Send-email-only-if-there-are-results/m-p/73354#M1664</guid>
      <dc:creator>anantshah</dc:creator>
      <dc:date>2011-04-02T02:31:36Z</dc:date>
    </item>
    <item>
      <title>Re: sendemail to Function - Send email only if there are results</title>
      <link>https://community.splunk.com/t5/Reporting/sendemail-to-Function-Send-email-only-if-there-are-results/m-p/73355#M1665</link>
      <description>&lt;P&gt;Well it sounds like you've modified your system to send the emails differently than they are normally sent out?   But for the record, when you use the normal alerting on a scheduled search,  I believe when it sends you the results it attaches them as a CSV file.&lt;/P&gt;

&lt;P&gt;Certainly csv is one of the options when you create an alert in 4.2. &lt;/P&gt;

&lt;P&gt;I think for you, the best option may be to set up your alert to trigger a python script instead of using the native sendemail.  I believe the results of the search are made available to those python scripts and you can then send your own email from python hopefully without a great deal of trouble.   Unfortunately I dont know of any examples you can build off of,  but maybe someone else does. &lt;/P&gt;

&lt;P&gt;the docs for scripted alerting are here: &lt;/P&gt;

&lt;P&gt;&lt;A href="http://www.splunk.com/base/Documentation/4.2/Admin/Configurescriptedalerts" rel="nofollow"&gt;http://www.splunk.com/base/Documentation/4.2/Admin/Configurescriptedalerts&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 02 Apr 2011 09:06:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/sendemail-to-Function-Send-email-only-if-there-are-results/m-p/73355#M1665</guid>
      <dc:creator>sideview</dc:creator>
      <dc:date>2011-04-02T09:06:25Z</dc:date>
    </item>
    <item>
      <title>Re: sendemail to Function - Send email only if there are results</title>
      <link>https://community.splunk.com/t5/Reporting/sendemail-to-Function-Send-email-only-if-there-are-results/m-p/73356#M1666</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:14:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/sendemail-to-Function-Send-email-only-if-there-are-results/m-p/73356#M1666</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2018-07-25T21:14:05Z</dc:date>
    </item>
    <item>
      <title>Re: sendemail to Function - Send email only if there are results</title>
      <link>https://community.splunk.com/t5/Reporting/sendemail-to-Function-Send-email-only-if-there-are-results/m-p/73357#M1667</link>
      <description>&lt;P&gt;Thank you for the UpVote, @sideview!&lt;/P&gt;</description>
      <pubDate>Mon, 30 Jul 2018 18:23:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/sendemail-to-Function-Send-email-only-if-there-are-results/m-p/73357#M1667</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2018-07-30T18:23:55Z</dc:date>
    </item>
    <item>
      <title>Re: sendemail to Function - Send email only if there are results</title>
      <link>https://community.splunk.com/t5/Reporting/sendemail-to-Function-Send-email-only-if-there-are-results/m-p/73358#M1668</link>
      <description>&lt;P&gt;I agree.  My accepted answer here is from the 4.2 era.    Looking in the docs,  it seems graceful=true  has been there since at least 4.3.   As a wild guess, graceful=true has just been there forever and you could always do this and i just didn't notice until today. &lt;span class="lia-unicode-emoji" title=":grinning_face_with_big_eyes:"&gt;😃&lt;/span&gt;    Agree that yours should be the accepted answer. &lt;/P&gt;</description>
      <pubDate>Mon, 30 Jul 2018 21:19:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/sendemail-to-Function-Send-email-only-if-there-are-results/m-p/73358#M1668</guid>
      <dc:creator>sideview</dc:creator>
      <dc:date>2018-07-30T21:19:02Z</dc:date>
    </item>
    <item>
      <title>Re: sendemail to Function - Send email only if there are results</title>
      <link>https://community.splunk.com/t5/Reporting/sendemail-to-Function-Send-email-only-if-there-are-results/m-p/73359#M1669</link>
      <description>&lt;P&gt;To be fair, this took me weeks to figure out, off and on.  It was challenging.  It seems totally non-intuitive that you can use &lt;CODE&gt;eval&lt;/CODE&gt; when there are no events in your current data set, but evidently calling &lt;CODE&gt;sendemail&lt;/CODE&gt; does something very special that possibly no other commands do, probably because a great deal of effort was put into that command for the express intent of doing exactly what we are trying to disallow!  It really should be a command argument: &lt;CODE&gt;send_when_no_results={true,false}&lt;/CODE&gt;.&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jul 2018 02:17:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/sendemail-to-Function-Send-email-only-if-there-are-results/m-p/73359#M1669</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2018-07-31T02:17:54Z</dc:date>
    </item>
    <item>
      <title>Re: sendemail to Function - Send email only if there are results</title>
      <link>https://community.splunk.com/t5/Reporting/sendemail-to-Function-Send-email-only-if-there-are-results/m-p/73360#M1670</link>
      <description>&lt;P&gt;The above solution works fine except that it is adding the valueForToHeader to the results sent in the email, is there a way to filter out that valueForToHeader column in the result set sent in email?&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jan 2020 16:03:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/sendemail-to-Function-Send-email-only-if-there-are-results/m-p/73360#M1670</guid>
      <dc:creator>anjith05</dc:creator>
      <dc:date>2020-01-24T16:03:00Z</dc:date>
    </item>
    <item>
      <title>Re: sendemail to Function - Send email only if there are results</title>
      <link>https://community.splunk.com/t5/Reporting/sendemail-to-Function-Send-email-only-if-there-are-results/m-p/688215#M12481</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/1406"&gt;@woodcock&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/103"&gt;@sideview&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way i can use sendemail to results of field values.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Details: i have a search results that has set of columns with user and email with different columns. Requirement is when a alert is triggered then results includes with columns: user, user_email, subject, recipient, owner, owner_email then sendemail to ower_email from the values of a results then sends email to&amp;nbsp;&lt;A href="mailto:ownerofuser1234@email.com," target="_blank"&gt;ownerofuser1234@email.com,&lt;/A&gt;&amp;nbsp;&lt;A href="mailto:ownerofuser345@email.com," target="_blank"&gt;ownerofuser345@email.com,&lt;/A&gt;&amp;nbsp;&lt;A href="mailto:ownerofuser567@email.com" target="_blank"&gt;ownerofuser567@email.com&lt;/A&gt;.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, all fields are dynamic and list is large.&amp;nbsp;&lt;/P&gt;&lt;P&gt;eg:&amp;nbsp;&lt;/P&gt;&lt;P&gt;An alert triggered from a search and following are the results of alert.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="16.666666666666668%" height="25px"&gt;&lt;FONT face="arial black,avant garde"&gt;user&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="16.666666666666668%" height="25px"&gt;&lt;FONT face="arial black,avant garde"&gt;user_email&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="16.666666666666668%" height="25px"&gt;&lt;FONT face="arial black,avant garde"&gt;subject&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="16.666666666666668%" height="25px"&gt;&lt;FONT face="arial black,avant garde"&gt;recipient&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="16.666666666666668%" height="25px"&gt;&lt;FONT face="arial black,avant garde"&gt;owner&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="16.666666666666668%" height="25px"&gt;&lt;FONT face="arial black,avant garde"&gt;owner_email&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="16.666666666666668%" height="25px"&gt;user1234&lt;/TD&gt;&lt;TD width="16.666666666666668%" height="25px"&gt;user1234@email.com&lt;/TD&gt;&lt;TD width="16.666666666666668%" height="25px"&gt;cross section from alert 1&lt;/TD&gt;&lt;TD width="16.666666666666668%" height="25px"&gt;recipientname1&lt;/TD&gt;&lt;TD width="16.666666666666668%" height="25px"&gt;ownerofuser1234&lt;/TD&gt;&lt;TD width="16.666666666666668%" height="25px"&gt;ownerofuser1234@email.com&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="16.666666666666668%" height="25px"&gt;user345&lt;/TD&gt;&lt;TD width="16.666666666666668%" height="25px"&gt;user345@email.com&lt;/TD&gt;&lt;TD width="16.666666666666668%" height="25px"&gt;cross section from alert 2&lt;/TD&gt;&lt;TD width="16.666666666666668%" height="25px"&gt;recipientname2&lt;/TD&gt;&lt;TD width="16.666666666666668%" height="25px"&gt;ownerofuser345&lt;/TD&gt;&lt;TD width="16.666666666666668%" height="25px"&gt;ownerofuser345@email.com&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="16.666666666666668%" height="25px"&gt;user567&lt;/TD&gt;&lt;TD width="16.666666666666668%" height="25px"&gt;user567@email.com&lt;/TD&gt;&lt;TD width="16.666666666666668%" height="25px"&gt;cross section from alert 4&lt;/TD&gt;&lt;TD width="16.666666666666668%" height="25px"&gt;recipientname3&lt;/TD&gt;&lt;TD width="16.666666666666668%" height="25px"&gt;ownerofuser567&lt;/TD&gt;&lt;TD width="16.666666666666668%" height="25px"&gt;ownerofuser567@email.com&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 May 2024 20:40:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/sendemail-to-Function-Send-email-only-if-there-are-results/m-p/688215#M12481</guid>
      <dc:creator>sandeepreddy947</dc:creator>
      <dc:date>2024-05-21T20:40:13Z</dc:date>
    </item>
  </channel>
</rss>

