1# Copyright 2015 The Chromium Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5"""Provides a function for emailing an alert to a sheriff on duty.""" 6 7import logging 8 9from google.appengine.api import mail 10 11from dashboard import email_template 12 13 14def EmailSheriff(sheriff, test, anomaly): 15 """Sends an email to the sheriff on duty about the given anomaly. 16 17 Args: 18 sheriff: sheriff.Sheriff entity. 19 test: The graph_data.Test entity associated with the anomaly. 20 anomaly: The anomaly.Anomaly entity. 21 """ 22 receivers = email_template.GetSheriffEmails(sheriff) 23 if not receivers: 24 logging.warn('No email address for %s', sheriff) 25 return 26 anomaly_info = email_template.GetAlertInfo(anomaly, test) 27 mail.send_mail(sender='gasper-alerts@google.com', 28 to=receivers, 29 subject=anomaly_info['email_subject'], 30 body=anomaly_info['email_text'], 31 html=anomaly_info['email_html'] + anomaly_info['alerts_link']) 32