예제 #1
0
파일: notify.py 프로젝트: ovwane/Sentry
    def rule_notify(self, event, futures):
        rules = []
        for future in futures:
            rules.append(future.rule)
            if not future.kwargs:
                continue
            raise NotImplementedError(
                'The default behavior for notification de-duplication does not support args'
            )

        project = event.group.project
        if hasattr(self, 'notify_digest') and digests.enabled(project):
            get_digest_option = lambda key: ProjectOption.objects.get_value(
                project,
                get_digest_option_key(self.get_conf_key(), key),
            )
            digest_key = unsplit_key(self, event.group.project)
            immediate_delivery = digests.add(
                digest_key,
                event_to_record(event, rules),
                increment_delay=get_digest_option('increment_delay'),
                maximum_delay=get_digest_option('maximum_delay'),
            )
            if immediate_delivery:
                deliver_digest.delay(digest_key)

        else:
            notification = Notification(event=event, rules=rules)
            self.notify(notification)
예제 #2
0
파일: notify.py 프로젝트: haojiang1/sentry
    def rule_notify(self, event, futures):
        rules = []
        for future in futures:
            rules.append(future.rule)
            if not future.kwargs:
                continue
            raise NotImplementedError('The default behavior for notification de-duplication does not support args')

        if hasattr(self, 'notify_digest'):
            project = event.group.project

            # If digest delivery is disabled, we still need to send a
            # notification -- we also need to check rate limits, since
            # ``should_notify`` skips this step if the plugin supports digests.
            if not features.has('projects:digests:deliver', project):
                if self.__is_rate_limited(event.group, event):
                    logger = logging.getLogger('sentry.plugins.{0}'.format(self.get_conf_key()))
                    logger.info('Notification for project %r dropped due to rate limiting', project)
                    return

                notification = Notification(event=event, rules=rules)
                self.notify(notification)

            if features.has('projects:digests:store', project):
                key = unsplit_key(self, event.group.project)
                if digests.add(key, event_to_record(event, rules)):
                    deliver_digest.delay(key)

        else:
            notification = Notification(event=event, rules=rules)
            self.notify(notification)
예제 #3
0
    def rule_notify(self, event, futures):
        rules = []
        for future in futures:
            rules.append(future.rule)
            if not future.kwargs:
                continue
            raise NotImplementedError('The default behavior for notification de-duplication does not support args')

        project = event.group.project
        if hasattr(self, 'notify_digest') and digests.enabled(project):
            get_digest_option = lambda key: ProjectOption.objects.get_value(
                project,
                get_digest_option_key(self.get_conf_key(), key),
            )
            digest_key = unsplit_key(self, event.group.project)
            immediate_delivery = digests.add(
                digest_key,
                event_to_record(event, rules),
                increment_delay=get_digest_option('increment_delay'),
                maximum_delay=get_digest_option('maximum_delay'),
            )
            if immediate_delivery:
                deliver_digest.delay(digest_key)

        else:
            notification = Notification(
                event=event,
                rules=rules,
            )
            self.notify(notification)
예제 #4
0
    def rule_notify(
        self,
        event: Any,
        futures: Sequence[Any],
        target_type: ActionTargetType,
        target_identifier: Optional[int] = None,
    ) -> None:
        metrics.incr("mail_adapter.rule_notify")
        rules = []
        extra = {
            "event_id": event.event_id,
            "group_id": event.group_id,
            "is_from_mail_action_adapter": True,
            "target_type": target_type.value,
            "target_identifier": target_identifier,
        }
        log_event = "dispatched"
        for future in futures:
            rules.append(future.rule)
            extra["rule_id"] = future.rule.id
            if not future.kwargs:
                continue
            raise NotImplementedError(
                "The default behavior for notification de-duplication does not support args"
            )

        project = event.group.project
        extra["project_id"] = project.id

        if digests.enabled(project):

            def get_digest_option(key):
                return ProjectOption.objects.get_value(
                    project, get_digest_option_key("mail", key))

            digest_key = unsplit_key(event.group.project, target_type,
                                     target_identifier)
            extra["digest_key"] = digest_key
            immediate_delivery = digests.add(
                digest_key,
                event_to_record(event, rules),
                increment_delay=get_digest_option("increment_delay"),
                maximum_delay=get_digest_option("maximum_delay"),
            )
            if immediate_delivery:
                deliver_digest.delay(digest_key)
            else:
                log_event = "digested"

        else:
            notification = Notification(event=event, rules=rules)
            self.notify(notification, target_type, target_identifier)

        logger.info("mail.adapter.notification.%s" % log_event, extra=extra)
예제 #5
0
    def rule_notify(self, event, futures):
        from sentry.models import ProjectOption  # Django 1.9 setup issue
        rules = []
        extra = {
            'event_id': event.id,
            'group_id': event.group_id,
            'plugin': self.slug,
        }
        log_event = 'dispatched'
        for future in futures:
            rules.append(future.rule)
            extra['rule_id'] = future.rule.id
            if not future.kwargs:
                continue
            raise NotImplementedError(
                'The default behavior for notification de-duplication does not support args'
            )

        project = event.group.project
        extra['project_id'] = project.id
        if hasattr(self, 'notify_digest') and digests.enabled(project):

            def get_digest_option(key):
                return ProjectOption.objects.get_value(
                    project,
                    get_digest_option_key(self.get_conf_key(), key),
                )

            digest_key = unsplit_key(self, event.group.project)
            extra['digest_key'] = digest_key
            immediate_delivery = digests.add(
                digest_key,
                event_to_record(event, rules),
                increment_delay=get_digest_option('increment_delay'),
                maximum_delay=get_digest_option('maximum_delay'),
            )
            if immediate_delivery:
                deliver_digest.delay(digest_key)
            else:
                log_event = 'digested'

        else:
            notification = Notification(
                event=event,
                rules=rules,
            )
            self.notify(notification)

        self.logger.info('notification.%s' % log_event, extra=extra)
예제 #6
0
파일: notify.py 프로젝트: keimlink/sentry
    def rule_notify(self, event, futures):
        rules = []
        for future in futures:
            rules.append(future.rule)
            if not future.kwargs:
                continue
            raise NotImplementedError('The default behavior for notification de-duplication does not support args')

        if self.__can_be_digested(event):
            key = unsplit_key(self, event.group.project)
            if digests.add(key, event_to_record(event, rules)):
                deliver_digest.delay(key)
        else:
            notification = Notification(event=event, rules=rules)
            self.notify(notification)
예제 #7
0
파일: notify.py 프로젝트: getsentry/sentry
    def rule_notify(self, event, futures):
        rules = []
        extra = {
            'event_id': event.id,
            'group_id': event.group_id,
            'plugin': self.slug,
        }
        log_event = 'dispatched'
        for future in futures:
            rules.append(future.rule)
            extra['rule_id'] = future.rule.id
            if not future.kwargs:
                continue
            raise NotImplementedError(
                'The default behavior for notification de-duplication does not support args'
            )

        project = event.group.project
        extra['project_id'] = project.id
        if hasattr(self, 'notify_digest') and digests.enabled(project):

            def get_digest_option(key):
                return ProjectOption.objects.get_value(
                    project,
                    get_digest_option_key(self.get_conf_key(), key),
                )

            digest_key = unsplit_key(self, event.group.project)
            extra['digest_key'] = digest_key
            immediate_delivery = digests.add(
                digest_key,
                event_to_record(event, rules),
                increment_delay=get_digest_option('increment_delay'),
                maximum_delay=get_digest_option('maximum_delay'),
            )
            if immediate_delivery:
                deliver_digest.delay(digest_key)
            else:
                log_event = 'digested'

        else:
            notification = Notification(
                event=event,
                rules=rules,
            )
            self.notify(notification)

        self.logger.info('notification.%s' % log_event, extra=extra)
예제 #8
0
    def rule_notify(self, event, futures):
        rules = []
        for future in futures:
            rules.append(future.rule)
            if not future.kwargs:
                continue
            raise NotImplementedError(
                'The default behavior for notification de-duplication does not support args'
            )

        if self.__can_be_digested(event):
            key = unsplit_key(self, event.group.project)
            if digests.add(key, event_to_record(event, rules)):
                deliver_digest.delay(key)
        else:
            notification = Notification(event=event, rules=rules)
            self.notify(notification)
예제 #9
0
파일: notify.py 프로젝트: jargij/sentry
    def rule_notify(self, event, futures):
        rules = []
        for future in futures:
            rules.append(future.rule)
            if not future.kwargs:
                continue
            raise NotImplementedError(
                'The default behavior for notification de-duplication does not support args'
            )

        if hasattr(self, 'notify_digest'):
            project = event.group.project

            # If digest delivery is disabled, we still need to send a
            # notification -- we also need to check rate limits, since
            # ``should_notify`` skips this step if the plugin supports digests.
            if not features.has('projects:digests:deliver', project):
                if self.__is_rate_limited(event.group, event):
                    logger = logging.getLogger('sentry.plugins.{0}'.format(
                        self.get_conf_key()))
                    logger.info(
                        'Notification for project %r dropped due to rate limiting',
                        project)
                    return

                notification = Notification(event=event, rules=rules)
                self.notify(notification)

            if features.has('projects:digests:store', project):
                get_digest_option = lambda key: ProjectOption.objects.get_value(
                    project,
                    '{0}:digests:{1}'.format(self.get_conf_key(), key),
                )
                digest_key = unsplit_key(self, event.group.project)
                immediate_delivery = digests.add(
                    digest_key,
                    event_to_record(event, rules),
                    increment_delay=get_digest_option('increment_delay'),
                    maximum_delay=get_digest_option('maximum_delay'),
                )
                if immediate_delivery:
                    deliver_digest.delay(digest_key)

        else:
            notification = Notification(event=event, rules=rules)
            self.notify(notification)
예제 #10
0
    def rule_notify(self, event, futures):
        rules = []
        extra = {
            "event_id": event.event_id,
            "group_id": event.group_id,
            "plugin": "mail"
        }
        log_event = "dispatched"
        for future in futures:
            rules.append(future.rule)
            extra["rule_id"] = future.rule.id
            if not future.kwargs:
                continue
            raise NotImplementedError(
                "The default behavior for notification de-duplication does not support args"
            )

        project = event.group.project
        extra["project_id"] = project.id
        if digests.enabled(project):

            def get_digest_option(key):
                return ProjectOption.objects.get_value(
                    project, get_digest_option_key("mail", key))

            digest_key = unsplit_key(self, event.group.project)
            extra["digest_key"] = digest_key
            immediate_delivery = digests.add(
                digest_key,
                event_to_record(event, rules),
                increment_delay=get_digest_option("increment_delay"),
                maximum_delay=get_digest_option("maximum_delay"),
            )
            if immediate_delivery:
                deliver_digest.delay(digest_key)
            else:
                log_event = "digested"

        else:
            notification = Notification(event=event, rules=rules)
            self.notify(notification)

        logger.info("mail.notification.%s" % log_event, extra=extra)