Example #1
0
def floodlight_email(day, alerts):

    for email, table in alerts.items():

        # build email template
        t = EmailTemplate()
        t.align('center')
        t.section(True)

        # when floodlight alerts exist
        issues = sum(1 for row in table if row[5] != 'NORMAL')

        if issues > 0: subject = '%d Floodlight Alerts For %s' % (issues, day)
        else: subject = 'All Floodlights Normal For %s' % day

        t.header(subject)
        t.paragraph(
            'The following floodlights are being monitored.  A status of LOW or HIGH inidcates impressions have changed significantly for the day.  A status of NORMAL means impressions are close to the average for the past 7 days.'
        )
        t.table([
            {
                "name": "Date",
                "type": "STRING"
            },
            {
                "name": "Floodlight",
                "type": "STRING"
            },
            {
                "name": "Activity Id",
                "type": "STRING"
            },
            {
                "name": "Activity",
                "type": "STRING"
            },
            {
                "name": "Impressions",
                "type": "INTEGER"
            },
            {
                "name": "Status",
                "type": "STRING"
            },
        ], table)

        t.paragraph(
            'Your monitored floodlights and recipients are listed in the sheet below.'
        )

        # either way link to the configuration sheet
        t.button('Floodlight Monitoring Sheet',
                 sheets_url(project.task['auth'],
                            project.task['sheet']['sheet']),
                 big=True)
        t.section(False)

        if project.verbose:
            print("FLOODLIGHT MONITOR EMAIL ALERTS", email, len(table))

        # send email template
        send_email(project.task['auth'], email, None, None, subject,
                   t.get_text(), t.get_html())
Example #2
0
def floodlight_email(
        day: str, alerts: dict[str, list[str, str, str, str, int,
                                         str]]) -> None:
    """ Send an email to each alert group with status of all activities.

  The email template will contain all activities for each email address specified in the input sheet.

  Args:
    day - the latest day that was present in all combined reports, used for title of email.
    alerts - Each email in the sheet with a list of activities and statuses.

  Returns:
    Nothing.
  """

    for email, table in alerts.items():

        # build email template
        t = EmailTemplate()
        t.align('center')
        t.section(True)

        # when floodlight alerts exist
        issues = sum(1 for row in table if row[5] != 'NORMAL')

        if issues > 0:
            subject = '%d Floodlight Alerts For %s' % (issues, day)
        else:
            subject = 'All Floodlights Normal For %s' % day

        t.header(subject)
        t.paragraph(
            'The following floodlights are being monitored.  A status of LOW or HIGH inidcates impressions have changed significantly for the day.  A status of NORMAL means impressions are close to the average for the past 7 days.'
        )
        t.table([
            {
                'name': 'Date',
                'type': 'STRING'
            },
            {
                'name': 'Floodlight',
                'type': 'STRING'
            },
            {
                'name': 'Activity Id',
                'type': 'STRING'
            },
            {
                'name': 'Activity',
                'type': 'STRING'
            },
            {
                'name': 'Impressions',
                'type': 'INTEGER'
            },
            {
                'name': 'Status',
                'type': 'STRING'
            },
        ], table)

        t.paragraph(
            'Your monitored floodlights and recipients are listed in the sheet below.'
        )

        # either way link to the configuration sheet
        t.button('Floodlight Monitoring Sheet',
                 sheets_url(project.task['auth'],
                            project.task['sheet']['sheet']),
                 big=True)
        t.section(False)

        if project.verbose:
            print('FLOODLIGHT MONITOR EMAIL ALERTS', email, len(table))

        # send email template
        send_email(project.task['auth'], email, None, None, subject,
                   t.get_text(), t.get_html())