Example #1
0
def EmailSheriff(sheriff, test, anomaly):
  """Sends an email to the sheriff on duty about the given anomaly.

  Args:
    sheriff: sheriff.Sheriff entity.
    test: The graph_data.Test entity associated with the anomaly.
    anomaly: The anomaly.Anomaly entity.
  """
  receivers = email_template.GetSheriffEmails(sheriff)
  if not receivers:
    logging.warn('No email address for %s', sheriff)
    return
  anomaly_info = email_template.GetAlertInfo(anomaly, test)
  mail.send_mail(sender='*****@*****.**',
                 to=receivers,
                 subject=anomaly_info['email_subject'],
                 body=anomaly_info['email_text'],
                 html=anomaly_info['email_html'] + anomaly_info['alerts_link'])
Example #2
0
def EmailSheriff(subscriptions, test, anomaly):
    """Sends an email to subscriptions on duty about the given anomaly.

  Args:
    subscriptions: subscription.Subscription entities.
    test: The graph_data.TestMetadata entity associated with the anomaly.
    anomaly: The anomaly.Anomaly entity.
  """
    receivers = email_template.GetSubscriptionEmails(subscriptions)
    if not receivers:
        logging.warn('No email address for %s', subscriptions)
        return
    anomaly_info = email_template.GetAlertInfo(anomaly, test)
    mail.send_mail(sender='*****@*****.**',
                   to=receivers,
                   subject=anomaly_info['email_subject'],
                   body=anomaly_info['email_text'],
                   html=anomaly_info['email_html'])
    logging.info('Sent single mail to %s', receivers)
Example #3
0
def _EmailBody(anomalies):
  """Returns the html and text versions of the email body."""
  assert anomalies
  html_body = []
  text_body = []
  html_body.append(_EMAIL_HTML_TOTAL_ANOMALIES % len(anomalies))

  anomaly_info = {}
  for anomaly_entity in anomalies:
    test = anomaly_entity.GetTestMetadataKey().get()
    anomaly_info = email_template.GetAlertInfo(anomaly_entity, test)
    html_body.append(anomaly_info['email_html'])
    text_body.append(anomaly_info['email_text'])

  assert anomaly_info
  html_body.append(anomaly_info['alerts_link'])

  # Join details for all anomalies to generate e-mail body.
  html = ''.join(html_body)
  text = ''.join(text_body)
  return html, text