Пример #1
0
    def operation(self):
        expired_or_expiring = yield self.pgp_validation_check()

        if expired_or_expiring:
            if not GLSettings.memory_copy.disable_admin_notification_emails:
                admins_descs = yield get_admin_users()
                for admin_desc in admins_descs:
                    yield self.send_admin_pgp_alerts(admin_desc, expired_or_expiring)

            if not GLSettings.memory_copy.disable_receiver_notification_emails:
                for receiver_desc in expired_or_expiring:
                    yield self.send_pgp_alerts(receiver_desc)
Пример #2
0
    def operation(self):
        expired_or_expiring = yield self.pgp_validation_check()

        if expired_or_expiring:
            if not GLSettings.memory_copy.disable_admin_notification_emails:
                admins_descs = yield get_admin_users()
                for admin_desc in admins_descs:
                    yield self.send_admin_pgp_alerts(admin_desc,
                                                     expired_or_expiring)

            if not GLSettings.memory_copy.disable_receiver_notification_emails:
                for receiver_desc in expired_or_expiring:
                    yield self.send_pgp_alerts(receiver_desc)
Пример #3
0
    def send_admin_pgp_alerts(self, admin_desc, expired_or_expiring):
        user_language = admin_desc["language"]
        node_desc = yield admin_serialize_node(user_language)
        notification_settings = yield get_notification(user_language)

        fakeevent = OD()
        fakeevent.type = u"admin_pgp_expiration_alert"
        fakeevent.node_info = node_desc
        fakeevent.context_info = None
        fakeevent.receiver_info = None
        fakeevent.tip_info = None
        fakeevent.subevent_info = {"expired_or_expiring": expired_or_expiring}

        subject = Templating().format_template(notification_settings["admin_pgp_alert_mail_title"], fakeevent)
        body = Templating().format_template(notification_settings["admin_pgp_alert_mail_template"], fakeevent)

        admin_users = yield get_admin_users()
        for u in admin_users:
            yield sendmail(u["mail_address"], subject, body)
Пример #4
0
    def send_admin_pgp_alerts(self, admin_desc, expired_or_expiring):
        user_language = admin_desc['language']
        node_desc = yield admin_serialize_node(user_language)
        notification_settings = yield get_notification(user_language)

        fakeevent = OD()
        fakeevent.type = u'admin_pgp_expiration_alert'
        fakeevent.node_info = node_desc
        fakeevent.context_info = None
        fakeevent.receiver_info = None
        fakeevent.tip_info = None
        fakeevent.subevent_info = {'expired_or_expiring': expired_or_expiring}

        subject = Templating().format_template(
            notification_settings['admin_pgp_alert_mail_title'], fakeevent)
        body = Templating().format_template(
            notification_settings['admin_pgp_alert_mail_template'], fakeevent)

        admin_users = yield get_admin_users()
        for u in admin_users:
            yield sendmail(u['mail_address'], subject, body)
Пример #5
0
    def admin_alarm_generate_mail(event_matrix):
        """
        This function put a mail in queue for the Admin, if the
        Admin notification is disable or if another Anomaly has been
        raised in the last 15 minutes, email is not send.
        """
        ret = []

        do_not_stress_admin_with_more_than_an_email_every_minutes = 120

        def replace_keywords(text):
            iterations = 3
            stop = False
            while (stop == False and iterations > 0):
                iterations -= 1
                count = 0
                for keyword, function in KeywordTemplate.iteritems():
                    where = text.find(keyword)
                    if where == -1:
                        continue

                    count += 1

                    text = "%s%s%s" % (text[:where],
                                       function(notification_dict),
                                       text[where + len(keyword):])

                    if count == 0:
                        # finally!
                        stop = True
                        break

        def _disk_anomaly_detail(notification_dict):
            # This happens all the time anomalies are present but disk is ok
            if Alarm.stress_levels['disk_space'] == 0:
                return u''

            if Alarm.stress_levels['disk_space'] == 1:
                return notification_dict['admin_anomaly_disk_low']
            elif Alarm.stress_levels['disk_space'] == 2:
                return notification_dict['admin_anomaly_disk_medium']
            else:
                return notification_dict['admin_anomaly_disk_high']

        def _activities_anomaly_detail(notification_dict):
            # This happens all the time there is not anomalous traffic
            if Alarm.stress_levels['activity'] == 0:
                return u''

            return notification_dict['admin_anomaly_activities']

        def _activity_alarm_level(notification_dict):
            return "%s" % Alarm.stress_levels['activity']

        def _activity_dump(notification_dict):
            retstr = ""

            for event, amount in event_matrix.iteritems():
                if not amount:
                    continue
                retstr = "%s%s%d\n%s" % \
                         (event, (25 - len(event)) * " ", amount, retstr)

            return retstr

        def _node_name(notification_dict):
            return unicode(GLSettings.memory_copy.nodename)

        def _free_disk_space(notification_dict):
            return "%s" % bytes_to_pretty_str(Alarm.latest_measured_freespace)

        def _total_disk_space(notification_dict):
            return "%s" % bytes_to_pretty_str(Alarm.latest_measured_totalspace)

        def _notifications_suppressed(notification_dict):
            if Alarm.stress_levels['notification'] == []:
                return u''
            return "** %s **" % Alarm.stress_levels['notification']

        KeywordTemplate = {
            "%AnomalyDetailDisk%": _disk_anomaly_detail,
            "%AnomalyDetailActivities%": _activities_anomaly_detail,
            "%ActivityAlarmLevel%": _activity_alarm_level,
            "%ActivityDump%": _activity_dump,
            "%NotificationsSuppressed%": _notifications_suppressed,
            "%NodeName%": _node_name,
            "%FreeMemory%": _free_disk_space,
            "%TotalMemory%": _total_disk_space,
        }
        # ------------------------------------------------------------------

        if not (Alarm.stress_levels['activity']
                or Alarm.stress_levels['disk_space']
                or Alarm.stress_levels['notification']):
            # we are lucky! no stress activities detected, no mail needed
            defer.returnValue([])

        if GLSettings.memory_copy.disable_admin_notification_emails:
            defer.returnValue([])

        if Alarm.last_alarm_email:
            if not is_expired(
                    Alarm.last_alarm_email,
                    minutes=
                    do_not_stress_admin_with_more_than_an_email_every_minutes):
                defer.returnValue([])

        admin_users = yield get_admin_users()
        for u in admin_users:
            notification_dict = yield get_notification(u['language'])

            subject = notification_dict['admin_anomaly_mail_title']
            body = notification_dict['admin_anomaly_mail_template']

            replace_keywords(subject)
            replace_keywords(body)

            ret.append({
                'mail_address': u['mail_address'],
                'subject': subject,
                'body': body
            })

        defer.returnValue(ret)
Пример #6
0
    def admin_alarm_generate_mail(event_matrix):
        """
        This function put a mail in queue for the Admin, if the
        Admin notification is disable or if another Anomaly has been
        raised in the last 15 minutes, email is not send.
        """
        ret = []

        do_not_stress_admin_with_more_than_an_email_every_minutes = 120

        def replace_keywords(text):
            iterations = 3
            stop = False
            while (stop == False and iterations > 0):
                iterations -= 1
                count = 0
                for keyword, function in KeywordTemplate.iteritems():
                    where = text.find(keyword)
                    if where == -1:
                        continue

                    count += 1

                    text = "%s%s%s" % (text[:where],
                                       function(notification_dict),
                                       text[where + len(keyword):])

                    if count == 0:
                        # finally!
                        stop = True
                        break

            return text

        def _disk_anomaly_detail(notification_dict):
            # This happens all the time anomalies are present but disk is ok
            if Alarm.stress_levels['disk_space'] == 0:
                return u''

            if Alarm.stress_levels['disk_space'] == 1:
                return notification_dict['admin_anomaly_disk_low']
            elif Alarm.stress_levels['disk_space'] == 2:
                return notification_dict['admin_anomaly_disk_medium']
            else:
                return notification_dict['admin_anomaly_disk_high']

        def _activities_anomaly_detail(notification_dict):
            # This happens all the time there is not anomalous traffic
            if Alarm.stress_levels['activity'] == 0:
                return u''

            return notification_dict['admin_anomaly_activities']

        def _activity_alarm_level(notification_dict):
            return "%s" % Alarm.stress_levels['activity']

        def _activity_dump(notification_dict):
            retstr = ""

            for event, amount in event_matrix.iteritems():
                if not amount:
                    continue
                retstr = "%s%s%d\n%s" % \
                         (event, (25 - len(event)) * " ", amount, retstr)

            return retstr

        def _node_name(notification_dict):
            return unicode(GLSettings.memory_copy.nodename)

        def _free_disk_space(notification_dict):
            return "%s" % bytes_to_pretty_str(Alarm.latest_measured_freespace)

        def _total_disk_space(notification_dict):
            return "%s" % bytes_to_pretty_str(Alarm.latest_measured_totalspace)

        def _notifications_suppressed(notification_dict):
            if Alarm.stress_levels['notification'] == []:
                return u''
            return "** %s **" % Alarm.stress_levels['notification']

        KeywordTemplate = {
            "%AnomalyDetailDisk%": _disk_anomaly_detail,
            "%AnomalyDetailActivities%": _activities_anomaly_detail,
            "%ActivityAlarmLevel%": _activity_alarm_level,
            "%ActivityDump%": _activity_dump,
            "%NotificationsSuppressed%": _notifications_suppressed,
            "%NodeName%": _node_name,
            "%FreeMemory%": _free_disk_space,
            "%TotalMemory%": _total_disk_space,
        }
        # ------------------------------------------------------------------

        if not (Alarm.stress_levels['activity'] or
                    Alarm.stress_levels['disk_space'] or
                    Alarm.stress_levels['notification']):
            # we are lucky! no stress activities detected, no mail needed
            defer.returnValue([])

        if GLSettings.memory_copy.disable_admin_notification_emails:
            defer.returnValue([])

        if Alarm.last_alarm_email:
            if not is_expired(Alarm.last_alarm_email,
                              minutes=do_not_stress_admin_with_more_than_an_email_every_minutes):
                defer.returnValue([])

        admin_users = yield get_admin_users()
        for u in admin_users:
            notification_dict = yield get_notification(u['language'])

            subject = notification_dict['admin_anomaly_mail_title']
            body = notification_dict['admin_anomaly_mail_template']

            subject = replace_keywords(subject)
            body = replace_keywords(body)

            ret.append({
                'mail_address': u['mail_address'],
                'subject': subject,
                'body': body
            })

        defer.returnValue(ret)