def outer_task_success_callback(context, email): subject = "[Airflow] DAG {0} - Task {1}: Success".format( context['task_instance_key_str'].split('__')[0], context['task_instance_key_str'].split('__')[1]) html_content = """ DAG: {0}<br> Task: {1}<br> Succeeded on: {2} """.format(context['task_instance_key_str'].split('__')[0], context['task_instance_key_str'].split('__')[1], datetime.now()) send_email_smtp(email, subject, html_content)
def send_email(context): subject = "[Airflow] DAG {0} - Task {1}: Success".format( context['task_instance_key_str'].split('__')[0], context['task_instance_key_str'].split('__')[1] ) html_content = """ DAG: {0}<br> Task: {1}<br> Succeeded on: {2} """.format( context['task_instance_key_str'].split('__')[0], context['task_instance_key_str'].split('__')[1], datetime.now() ) send_email_smtp('*****@*****.**', subject, html_content)
def notify_email(contextDict, **kwargs): """Send custom email alerts.""" # email title. title = "Airflow alert: {task_name} Failed".format(**contextDict) # email contents body = """ Hi Everyone, <br> <br> There's been an error in the {task_name} job.<br> <br> Forever yours,<br> Airflow bot <br> """.format(**contextDict) send_email_smtp('*****@*****.**', title, body)
def send_email(self, to, subject, html_content, files=None, dryrun=False, cc=None, bcc=None, mime_subtype='mixed'): log = LoggingMixin().logger try: subject = self.get_subject(subject, html_content) send_email_smtp(to, subject, html_content, files, dryrun, cc, bcc, mime_subtype) except Exception, e: log.info("Custom alert email subject except", e.message, ", use original subject.")
def custom_task_failure_alert(email_list, dag_id, task_id, log_url): subject = ( f"[Airflow] DAG {dag_id.capitalize()} - Task {task_id.capitalize()}: Failed" ) html_content = f""" Hello,<br> <br> The <b>{task_id.capitalize()}</b> task of the <b>{dag_id.capitalize()}</b> DAG has failed.<br> <br> Please visit the Airflow log page at {log_url.replace("localhost", AIRFLOW_SERVER_IP)} for more information.<br> <br> Cheers,<br> Airflow log bot """ send_email_smtp(email_list, subject, html_content)
def send_email_smtp_controller(to, subject, html_content, files=None, dryrun=False, cc=None, bcc=None, mime_subtype='mixed'): log = LoggingMixin().logger custom_alerts = get_custom_alerters() email_context = EmailContext(subject, html_content) for custom_alert in custom_alerts: if custom_alert.sure_called_by_me(email_context): log.info("Sent an alert email by custom %s", custom_alert.__class__) custom_alert.send_email(to, subject, html_content, files, dryrun, cc, bcc, mime_subtype) return log.info("Sent an alert email by default %s", "send_email_smtp") send_email_smtp(to, subject, html_content, files, dryrun, cc, bcc, mime_subtype)