All Apps and Add-ons

Error when there are no rows to email on

scottsavarese
New Member

I'm using the sendresults command to send emails to users during a saved search. However, when no rows are returned in the search, the command errors saying that it requires a email_to field. So, I created a quick patch which creates an argument for how to handle the no results case and if set will not signal an error. Let me know your thoughts.

Thanks.

host:Desktop me$ diff -ru sendresults sendresults-new
diff -ru sendresults/bin/sendresults.py sendresults-new/bin/sendresults.py
--- sendresults/bin/sendresults.py  2014-06-05 20:27:12.000000000 -0400
+++ sendresults-new/bin/sendresults.py  2017-04-08 09:37:30.000000000 -0400
@@ -196,9 +196,12 @@
    if maxrcpts < 1 :
        logger.error("More than emails would be generated than permitted. Increase your maxrcpts or change your search." % ())
        results = splunk.Intersplunk.generateErrorResults("Error : Field maxrcpts must be greater than 0. Increase your maxrcpts.")
-   elif d2.get('email_to') != len(results) :
-       logger.error("All results must contain a field named email_to with the intended recipient." % ())
-       results = splunk.Intersplunk.generateErrorResults("Error : All results must contain a field named email_to with the intended recipient.")
+   elif d2.get('email_to') != len(results) :
+       if toBool( getarg(argvals, “error_on_no_rows”, “true”) ):
+           logger.error("All results must contain a field named email_to with the intended recipient." % ())
+           results = splunk.Intersplunk.generateErrorResults("Error : All results must contain a field named email_to with the intended recipient.")
+       else:
+           logger.info(“Email not sent: No rows to process”)
    else :
        for event in results :
            d1[event['email_to']].append(event)
Tags (1)
0 Karma
1 Solution

mockd
Path Finder

Hi!

Thanks for that patch. It's a smart idea to the issue.

We are working on a new release of the command and will incorporate this into it.

Thanks,
Derek.

View solution in original post

0 Karma

mockd
Path Finder

Hi!

Thanks for that patch. It's a smart idea to the issue.

We are working on a new release of the command and will incorporate this into it.

Thanks,
Derek.

0 Karma

scottsavarese
New Member

Thanks for the update... Looking forward to the new version

0 Karma
Get Updates on the Splunk Community!

Upcoming Webinar: Unmasking Insider Threats with Slunk Enterprise Security’s UEBA

Join us on Wed, Dec 10. at 10AM PST / 1PM EST for a live webinar and demo with Splunk experts! Discover how ...

.conf25 technical session recap of Observability for Gen AI: Monitoring LLM ...

If you’re unfamiliar, .conf is Splunk’s premier event where the Splunk community, customers, partners, and ...

A Season of Skills: New Splunk Courses to Light Up Your Learning Journey

There’s something special about this time of year—maybe it’s the glow of the holidays, maybe it’s the ...