コード例 #1
0
 def test_identifier(self):
     identifier = "123"
     assert (
         unsplit_key(self.project, ActionTargetType.ISSUE_OWNERS,
                     identifier) ==
         f"mail:p:{self.project.id}:{ActionTargetType.ISSUE_OWNERS.value}:{identifier}"
     )
コード例 #2
0
ファイル: notify.py プロジェクト: Akashguharoy/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)
コード例 #3
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)
コード例 #4
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)
コード例 #5
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)
コード例 #6
0
ファイル: notify.py プロジェクト: commonlims/commonlims
    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)
コード例 #7
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)
コード例 #8
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)
コード例 #9
0
ファイル: notify.py プロジェクト: midrissi/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):
            digests.add(
                unsplit_key(self, event.group.project),  # TODO: Improve this abstraction.
                event_to_record(event, rules),
            )
        else:
            notification = Notification(event=event, rules=rules)
            self.notify(notification)
コード例 #10
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)
コード例 #11
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)
コード例 #12
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)
コード例 #13
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):
            digests.add(
                unsplit_key(
                    self,
                    event.group.project),  # TODO: Improve this abstraction.
                event_to_record(event, rules),
            )
        else:
            notification = Notification(event=event, rules=rules)
            self.notify(notification)
コード例 #14
0
 def test_no_identifier(self):
     assert (
         unsplit_key(self.project, ActionTargetType.ISSUE_OWNERS, None) ==
         f"mail:p:{self.project.id}:{ActionTargetType.ISSUE_OWNERS.value}:")
コード例 #15
0
 def test_identifier(self):
     identifier = "123"
     assert unsplit_key(self.project, ActionTargetType.ISSUE_OWNERS,
                        identifier) == "mail:p:{}:{}:{}".format(
                            self.project.id,
                            ActionTargetType.ISSUE_OWNERS.value, identifier)
コード例 #16
0
 def test_no_identifier(self):
     assert unsplit_key(self.project, ActionTargetType.ISSUE_OWNERS,
                        None) == "mail:p:{}:{}:".format(
                            self.project.id,
                            ActionTargetType.ISSUE_OWNERS.value)