• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python helpers.construct_checksum函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中sentry.helpers.construct_checksum函数的典型用法代码示例。如果您正苦于以下问题:Python construct_checksum函数的具体用法?Python construct_checksum怎么用?Python construct_checksum使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了construct_checksum函数的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: process

    def process(self, **kwargs):
        from sentry.helpers import get_filters

        kwargs.setdefault('level', logging.ERROR)
        kwargs.setdefault('server_name', conf.NAME)

        if 'checksum' not in kwargs:
            checksum = construct_checksum(**kwargs)
        else:
            checksum = kwargs['checksum']

        if conf.THRASHING_TIMEOUT and conf.THRASHING_LIMIT:
            cache_key = 'sentry:%s:%s' % (kwargs.get('class_name') or '', checksum)
            added = cache.add(cache_key, 1, conf.THRASHING_TIMEOUT)
            if not added:
                try:
                    thrash_count = cache.incr(cache_key)
                except (KeyError, ValueError):
                    # cache.incr can fail. Assume we aren't thrashing yet, and
                    # if we are, hope that the next error has a successful
                    # cache.incr call.
                    thrash_count = 0
                if thrash_count > conf.THRASHING_LIMIT:
                    return

        for filter_ in get_filters():
            kwargs = filter_(None).process(kwargs) or kwargs
        
        # Make sure all additional data is coerced
        if 'data' in kwargs:
            kwargs['data'] = transform(kwargs['data'])

        return self.send(**kwargs)
开发者ID:Bounder,项目名称:django-sentry,代码行数:33,代码来源:base.py


示例2: process

    def process(self, **kwargs):
        from sentry.helpers import get_filters

        kwargs.setdefault('level', logging.ERROR)
        kwargs.setdefault('server_name', conf.NAME)

        if 'checksum' not in kwargs:
            checksum = construct_checksum(**kwargs)
        else:
            checksum = kwargs['checksum']

        if conf.THRASHING_TIMEOUT and conf.THRASHING_LIMIT:
            cache_key = 'sentry:%s:%s' % (kwargs.get('class_name') or '', checksum)
            added = cache.add(cache_key, 1, conf.THRASHING_TIMEOUT)
            try:
                if not added and cache.incr(cache_key) > conf.THRASHING_LIMIT:
                    return
            except KeyError:
                pass

        for filter_ in get_filters():
            kwargs = filter_(None).process(kwargs) or kwargs
        
        # Make sure all additional data is coerced
        if 'data' in kwargs:
            kwargs['data'] = transform(kwargs['data'])

        return self.send(**kwargs)
开发者ID:swilcox,项目名称:django-sentry,代码行数:28,代码来源:base.py


示例3: from_kwargs

    def from_kwargs(self, **kwargs):
        from sentry.models import Message, GroupedMessage, FilterValue

        URL_MAX_LENGTH = Message._meta.get_field_by_name("url")[0].max_length
        now = datetime.datetime.now()

        view = kwargs.pop("view", None)
        logger_name = kwargs.pop("logger", "root")
        url = kwargs.pop("url", None)
        server_name = kwargs.pop("server_name", conf.CLIENT)
        site = kwargs.pop("site", None)
        data = kwargs.pop("data", {}) or {}

        if url:
            data["url"] = url
            url = url[:URL_MAX_LENGTH]

        checksum = construct_checksum(**kwargs)

        mail = False
        try:
            group, created = GroupedMessage.objects.get_or_create(
                view=view, logger=logger_name, checksum=checksum, defaults=kwargs
            )
            if not created:
                GroupedMessage.objects.filter(pk=group.pk).update(
                    times_seen=models.F("times_seen") + 1, status=0, last_seen=now
                )
                # HACK: maintain appeared state
                if group.status == 1:
                    mail = True
                group.status = 0
                group.last_seen = now
                group.times_seen += 1
                signals.post_save.send(sender=GroupedMessage, instance=group, created=False)
            else:
                mail = True
            instance = Message.objects.create(
                view=view,
                logger=logger_name,
                data=data,
                url=url,
                server_name=server_name,
                site=site,
                checksum=checksum,
                group=group,
                **kwargs
            )
            if server_name:
                FilterValue.objects.get_or_create(key="server_name", value=server_name)
            if site:
                FilterValue.objects.get_or_create(key="site", value=site)
            if logger_name:
                FilterValue.objects.get_or_create(key="logger", value=logger_name)
        except Exception, exc:
            # TODO: should we mail admins when there are failures?
            try:
                logger.exception(u"Unable to process log entry: %s" % (exc,))
            except Exception, exc:
                warnings.warn(u"Unable to process log entry: %s" % (exc,))
开发者ID:danielooi,项目名称:django-sentry,代码行数:60,代码来源:manager.py


示例4: create_from_record

    def create_from_record(self, record, **kwargs):
        """
        Creates an error log for a ``logging`` module ``record`` instance.
        """
        for k in ('url', 'view', 'request', 'data'):
            if not kwargs.get(k):
                kwargs[k] = record.__dict__.get(k)

        kwargs.update({
            'logger': record.name,
            'level': record.levelno,
            'message': force_unicode(record.msg),
            'server_name': conf.NAME,
        })

        # construct the checksum with the unparsed message
        kwargs['checksum'] = construct_checksum(**kwargs)

        # save the message with included formatting
        kwargs['message'] = record.getMessage()

        # If there's no exception being processed, exc_info may be a 3-tuple of None
        # http://docs.python.org/library/sys.html#sys.exc_info
        if record.exc_info and all(record.exc_info):
            return self.create_from_exception(record.exc_info, **kwargs)

        return self.process(
            traceback=record.exc_text,
            **kwargs
        )
开发者ID:iserko,项目名称:django-sentry,代码行数:30,代码来源:base.py


示例5: process

    def process(self, **kwargs):
        from sentry.helpers import get_filters

        kwargs.setdefault("level", logging.ERROR)
        kwargs.setdefault("server_name", conf.NAME)

        checksum = construct_checksum(**kwargs)

        if conf.THRASHING_TIMEOUT and conf.THRASHING_LIMIT:
            cache_key = "sentry:%s:%s" % (kwargs.get("class_name") or "", checksum)
            added = cache.add(cache_key, 1, conf.THRASHING_TIMEOUT)
            try:
                if not added and cache.incr(cache_key) > conf.THRASHING_LIMIT:
                    return
            except KeyError:
                pass

        for filter_ in get_filters():
            kwargs = filter_(None).process(kwargs) or kwargs

        # Make sure all additional data is coerced
        if "data" in kwargs:
            kwargs["data"] = transform(kwargs["data"])

        return self.send(**kwargs)
开发者ID:olchik,项目名称:django-sentry,代码行数:25,代码来源:base.py


示例6: process

    def process(self, **kwargs):
        from sentry.helpers import get_filters

        for filter_ in get_filters():
            kwargs = filter_(None).process(kwargs) or kwargs

        kwargs.setdefault('level', logging.ERROR)
        kwargs.setdefault('server_name', settings.NAME)

        checksum = construct_checksum(**kwargs)

        if settings.THRASHING_TIMEOUT and settings.THRASHING_LIMIT:
            cache_key = 'sentry:%s:%s' % (kwargs.get('class_name'), checksum)
            added = cache.add(cache_key, 1, settings.THRASHING_TIMEOUT)
            if not added:
                try:
                    thrash_count = cache.incr(cache_key)
                except ValueError:
                    # cache.incr can fail. Assume we aren't thrashing yet, and
                    # if we are, hope that the next error has a successful
                    # cache.incr call.
                    thrash_count = 0
                if thrash_count > settings.THRASHING_LIMIT:
                    return

        return self.send(**kwargs)
开发者ID:texastribune,项目名称:django-sentry,代码行数:26,代码来源:base.py


示例7: process

    def process(self, **kwargs):
        from sentry.helpers import get_filters

        for filter_ in get_filters():
            kwargs = filter_(None).process(kwargs) or kwargs

        kwargs.setdefault('level', logging.ERROR)
        kwargs.setdefault('server_name', socket.gethostname())

        checksum = construct_checksum(**kwargs)

        if settings.THRASHING_TIMEOUT and settings.THRASHING_LIMIT:
            cache_key = 'sentry:%s:%s' % (kwargs.get('class_name'), checksum)
            added = cache.add(cache_key, 1, settings.THRASHING_TIMEOUT)
            if not added and cache.incr(cache_key) > settings.THRASHING_LIMIT:
                return

        if settings.REMOTE_URL:
            data = {
                'data': base64.b64encode(pickle.dumps(transform(kwargs)).encode('zlib')),
                'key': settings.KEY,
            }
            req = urllib2.Request(settings.REMOTE_URL, urllib.urlencode(data))

            try:
                response = urllib2.urlopen(req, None, settings.REMOTE_TIMEOUT).read()
            except urllib2.URLError, e:
                logger.exception('Unable to reach Sentry log server')
            except urllib2.HTTPError, e:
                logger.exception('Unable to reach Sentry log server', extra={'body': e.read()})
开发者ID:bryanchow,项目名称:django-sentry,代码行数:30,代码来源:base.py


示例8: from_kwargs

    def from_kwargs(self, **kwargs):
        from sentry.models import Message, GroupedMessage, FilterValue
        
        URL_MAX_LENGTH = Message._meta.get_field_by_name('url')[0].max_length
        now = datetime.datetime.now()

        view = kwargs.pop('view', None)
        logger_name = kwargs.pop('logger', 'root')
        url = kwargs.pop('url', None)
        server_name = kwargs.pop('server_name', settings.CLIENT)
        data = kwargs.pop('data', {}) or {}

        if url:
            data['url'] = url
            url = url[:URL_MAX_LENGTH]

        checksum = construct_checksum(**kwargs)

        mail = False
        try:
            group, created = GroupedMessage.objects.get_or_create(
                view=view,
                logger=logger_name,
                checksum=checksum,
                defaults=kwargs
            )
            if not created:
                GroupedMessage.objects.filter(pk=group.pk).update(
                    times_seen=models.F('times_seen') + 1,
                    status=0,
                    last_seen=now,
                )
                # HACK: maintain appeared state
                if group.status == 1:
                    mail = True
                group.status = 0
                group.last_seen = now
                group.times_seen += 1
                signals.post_save.send(sender=GroupedMessage, instance=group, created=False)
            else: 
                mail = True
            instance = Message.objects.create(
                view=view,
                logger=logger_name,
                data=data,
                url=url,
                server_name=server_name,
                checksum=checksum,
                group=group,
                **kwargs
            )
            FilterValue.objects.get_or_create(key='server_name', value=server_name)
            FilterValue.objects.get_or_create(key='logger', value=logger_name)
        except Exception, exc:
            # TODO: should we mail admins when there are failures?
            try:
                logger.exception(u'Unable to process log entry: %s' % (exc,))
            except Exception, exc:
                warnings.warn(u'Unable to process log entry: %s' % (exc,))
开发者ID:texastribune,项目名称:django-sentry,代码行数:59,代码来源:manager.py


示例9: process

    def process(self, **kwargs):
        from sentry.helpers import get_filters

        kwargs.setdefault('level', logging.ERROR)
        kwargs.setdefault('server_name', conf.NAME)

        # save versions of all installed apps
        if 'data' not in kwargs or '__sentry__' not in (kwargs['data'] or {}):
            if kwargs.get('data') is None:
                kwargs['data'] = {}
            kwargs['data']['__sentry__'] = {}

        versions = get_versions()
        kwargs['data']['__sentry__']['versions'] = versions

        if kwargs.get('view'):
            # get list of modules from right to left
            parts = kwargs['view'].split('.')
            module_list = ['.'.join(parts[:idx]) for idx in xrange(1, len(parts)+1)][::-1]
            version = None
            for m in module_list:
                if m in versions:
                    version = versions[m]

            # store our "best guess" for application version
            if version:
                kwargs['data']['__sentry__']['version'] = version

        if 'checksum' not in kwargs:
            checksum = construct_checksum(**kwargs)
        else:
            checksum = kwargs['checksum']

        if conf.THRASHING_TIMEOUT and conf.THRASHING_LIMIT:
            cache_key = 'sentry:%s:%s' % (kwargs.get('class_name') or '', checksum)
            added = cache.add(cache_key, 1, conf.THRASHING_TIMEOUT)
            if not added:
                try:
                    thrash_count = cache.incr(cache_key)
                except (KeyError, ValueError):
                    # cache.incr can fail. Assume we aren't thrashing yet, and
                    # if we are, hope that the next error has a successful
                    # cache.incr call.
                    thrash_count = 0
                if thrash_count > conf.THRASHING_LIMIT:
                    return

        for filter_ in get_filters():
            kwargs = filter_(None).process(kwargs) or kwargs
        
        # Make sure all data is coerced
        kwargs = transform(kwargs)

        return self.send(**kwargs)
开发者ID:jpellerin,项目名称:django-sentry,代码行数:54,代码来源:base.py


示例10: _create

    def _create(self, **defaults):
        from models import Message, GroupedMessage
        
        URL_MAX_LENGTH = Message._meta.get_field_by_name('url')[0].max_length
        
        view = defaults.pop('view', None)
        logger_name = defaults.pop('logger', 'root')
        url = defaults.pop('url', None)

        data = defaults.pop('data', {}) or {}
        if url:
            data['url'] = url
            url = url[:URL_MAX_LENGTH]

        instance = Message(
            view=view,
            logger=logger_name,
            data=data,
            url=url,
            server_name=socket.gethostname(),
            **defaults
        )
        instance.checksum = construct_checksum(instance)
        
        if settings.THRASHING_TIMEOUT and settings.THRASHING_LIMIT:
            cache_key = 'sentry:%s:%s' % (instance.class_name, instance.checksum)
            added = cache.add(cache_key, 1, settings.THRASHING_TIMEOUT)
            if not added and cache.incr(cache_key) > settings.THRASHING_LIMIT:
                return

        try:
            group, created = GroupedMessage.objects.get_or_create(
                view=view,
                logger=logger_name,
                checksum=instance.checksum,
                defaults=defaults
            )
            if not created:
                GroupedMessage.objects.filter(pk=group.pk).update(
                    times_seen=models.F('times_seen') + 1,
                    status=0,
                    last_seen=datetime.datetime.now(),
                )
            instance.group = group
            instance.save()
        except Exception, exc:
            try:
                logger.exception(u'Unable to process log entry: %s' % (exc,))
            except Exception, exc:
                warnings.warn(u'Unable to process log entry: %s' % (exc,))
开发者ID:justquick,项目名称:django-sentry,代码行数:50,代码来源:manager.py


示例11: create_from_record

    def create_from_record(self, record, **kwargs):
        """
        Creates an error log for a `logging` module `record` instance.
        """
        for k in ('url', 'view', 'data'):
            if k not in kwargs:
                kwargs[k] = record.__dict__.get(k)
        
        request = getattr(record, 'request', None)
        if request:
            if not kwargs.get('data'):
                kwargs['data'] = {}
            kwargs['data'].update(dict(
                META=request.META,
                POST=request.POST,
                GET=request.GET,
                COOKIES=request.COOKIES,
                raw_post_data=request.raw_post_data,
            ))

            if not kwargs.get('url'):
                kwargs['url'] = request.build_absolute_uri()
        
        kwargs.update({
            'logger': record.name,
            'level': record.levelno,
            'message': force_unicode(record.msg),
            'server_name': conf.NAME,
        })
        
        # construct the checksum with the unparsed message
        kwargs['checksum'] = construct_checksum(**kwargs)
        
        # save the message with included formatting
        kwargs['message'] = record.getMessage()
        
        # If there's no exception being processed, exc_info may be a 3-tuple of None
        # http://docs.python.org/library/sys.html#sys.exc_info
        if record.exc_info and all(record.exc_info):
            return self.create_from_exception(record.exc_info, **kwargs)

        return self.process(
            traceback=record.exc_text,
            **kwargs
        )
开发者ID:Bounder,项目名称:django-sentry,代码行数:45,代码来源:base.py


示例12: process

    def process(self, **kwargs):
        from sentry.helpers import get_filters

        for filter_ in get_filters():
            kwargs = filter_(None).process(kwargs) or kwargs

        kwargs.setdefault("level", logging.ERROR)
        kwargs.setdefault("server_name", settings.NAME)

        checksum = construct_checksum(**kwargs)

        if settings.THRASHING_TIMEOUT and settings.THRASHING_LIMIT:
            cache_key = "sentry:%s:%s" % (kwargs.get("class_name"), checksum)
            added = cache.add(cache_key, 1, settings.THRASHING_TIMEOUT)
            if not added and cache.incr(cache_key) > settings.THRASHING_LIMIT:
                return

        return self.send(**kwargs)
开发者ID:klipstein,项目名称:django-sentry,代码行数:18,代码来源:base.py


示例13: create_from_record

    def create_from_record(self, record, **kwargs):
        """
        Creates an error log for a `logging` module `record` instance.
        """
        for k in ("url", "view", "data"):
            if k not in kwargs:
                kwargs[k] = record.__dict__.get(k)

        request = getattr(record, "request", None)
        if request:
            if not kwargs.get("data"):
                kwargs["data"] = {}
            kwargs["data"].update(dict(META=request.META, POST=request.POST, GET=request.GET, COOKIES=request.COOKIES))

            if not kwargs.get("url"):
                kwargs["url"] = request.build_absolute_uri()

        kwargs.update(
            {
                "logger": record.name,
                "level": record.levelno,
                "message": force_unicode(record.msg),
                "server_name": conf.NAME,
            }
        )

        # construct the checksum with the unparsed message
        kwargs["checksum"] = construct_checksum(**kwargs)

        # save the message with included formatting
        kwargs["message"] = record.getMessage()

        # If there's no exception being processed, exc_info may be a 3-tuple of None
        # http://docs.python.org/library/sys.html#sys.exc_info
        if record.exc_info and all(record.exc_info):
            return self.create_from_exception(record.exc_info, **kwargs)

        return self.process(traceback=record.exc_text, **kwargs)
开发者ID:kmike,项目名称:django-sentry,代码行数:38,代码来源:base.py


示例14: process

    def process(self, **kwargs):
        "Processes the message before passing it on to the server"
        from sentry.helpers import get_filters

        if kwargs.get('data'):
            # Ensure we're not changing the original data which was passed
            # to Sentry
            kwargs['data'] = kwargs['data'].copy()

        request = kwargs.pop('request', None)
        if request:
            if not kwargs.get('data'):
                kwargs['data'] = {}

            if not request.POST and request.raw_post_data:
                post_data = request.raw_post_data
            else:
                post_data = request.POST

            kwargs['data'].update(dict(
                META=request.META,
                POST=post_data,
                GET=request.GET,
                COOKIES=request.COOKIES,
                REQUEST_USER=request.user,
            ))

            if not kwargs.get('url'):
                kwargs['url'] = request.build_absolute_uri()

        kwargs.setdefault('level', logging.ERROR)
        kwargs.setdefault('server_name', conf.NAME)

        # save versions of all installed apps
        if 'data' not in kwargs or '__sentry__' not in (kwargs['data'] or {}):
            if kwargs.get('data') is None:
                kwargs['data'] = {}
            kwargs['data']['__sentry__'] = {}

        versions = get_versions()
        kwargs['data']['__sentry__']['versions'] = versions

        # Shorten lists/strings
        for k, v in kwargs['data'].iteritems():
            if k == '__sentry__':
                continue
            kwargs['data'][k] = shorten(v)

        if kwargs.get('view'):
            # get list of modules from right to left
            parts = kwargs['view'].split('.')
            module_list = ['.'.join(parts[:idx]) for idx in xrange(1, len(parts)+1)][::-1]
            version = None
            module = None
            for m in module_list:
                if m in versions:
                    module = m
                    version = versions[m]

            # store our "best guess" for application version
            if version:
                kwargs['data']['__sentry__'].update({
                    'version': version,
                    'module': module,
                })

        if 'checksum' not in kwargs:
            checksum = construct_checksum(**kwargs)
        else:
            checksum = kwargs['checksum']

        if conf.THRASHING_TIMEOUT and conf.THRASHING_LIMIT:
            cache_key = 'sentry:%s:%s' % (kwargs.get('class_name') or '', checksum)
            added = cache.add(cache_key, 1, conf.THRASHING_TIMEOUT)
            if not added:
                try:
                    thrash_count = cache.incr(cache_key)
                except (KeyError, ValueError):
                    # cache.incr can fail. Assume we aren't thrashing yet, and
                    # if we are, hope that the next error has a successful
                    # cache.incr call.
                    thrash_count = 0
                if thrash_count > conf.THRASHING_LIMIT:
                    message_id = cache.get('%s:last_message_id' % cache_key)
                    if request:
                        # attach the sentry object to the request
                        request.sentry = {
                            'id': message_id,
                            'thrashed': True,
                        }
                    return message_id

        for filter_ in get_filters():
            kwargs = filter_(None).process(kwargs) or kwargs

        # create ID client-side so that it can be passed to application
        message_id = uuid.uuid4().hex
        kwargs['message_id'] = message_id

        # Make sure all data is coerced
#.........这里部分代码省略.........
开发者ID:iserko,项目名称:django-sentry,代码行数:101,代码来源:base.py


示例15: from_kwargs

    def from_kwargs(self, **kwargs):
        from sentry.models import Message, GroupedMessage, FilterValue

        URL_MAX_LENGTH = Message._meta.get_field_by_name('url')[0].max_length
        now = timezone.now()

        view = kwargs.pop('view', None)
        logger_name = kwargs.pop('logger', 'root')
        url = kwargs.pop('url', None)
        server_name = kwargs.pop('server_name', conf.CLIENT)
        site = kwargs.pop('site', None)
        data = kwargs.pop('data', {}) or {}
        message_id = kwargs.pop('message_id', None)

        if url:
            data['url'] = url
            url = url[:URL_MAX_LENGTH]

        checksum = kwargs.pop('checksum', None)
        if not checksum:
            checksum = construct_checksum(**kwargs)

        mail = False
        try:
            kwargs['data'] = {}

            if 'url' in data:
                kwargs['data']['url'] = data['url']
            if 'version' in data.get('__sentry__', {}):
                kwargs['data']['version'] = data['__sentry__']['version']
            if 'module' in data.get('__sentry__', {}):
                kwargs['data']['module'] = data['__sentry__']['module']

            group, created = GroupedMessage.objects.get_or_create(
                view=view,
                logger=logger_name,
                checksum=checksum,
                # we store some sample data for rendering
                defaults=kwargs
            )
            kwargs.pop('data', None)
            if not created:
                GroupedMessage.objects.filter(pk=group.pk).update(
                    times_seen=models.F('times_seen') + 1,
                    status=0,
                    last_seen=now,
                )
                # HACK: maintain appeared state
                if group.status == 1:
                    mail = True
                group.status = 0
                group.last_seen = now
                group.times_seen += 1
                signals.post_save.send(sender=GroupedMessage, instance=group, created=False)
            else:
                mail = True
            instance = Message.objects.create(
                message_id=message_id,
                view=view,
                logger=logger_name,
                data=data,
                url=url,
                server_name=server_name,
                site=site,
                checksum=checksum,
                group=group,
                **kwargs
            )
            if server_name:
                FilterValue.objects.get_or_create(key='server_name', value=server_name)
            if site:
                FilterValue.objects.get_or_create(key='site', value=site)
            if logger_name:
                FilterValue.objects.get_or_create(key='logger', value=logger_name)
        except Exception, exc:
            # TODO: should we mail admins when there are failures?
            try:
                logger.exception(u'Unable to process log entry: %s' % (exc,))
            except Exception, exc:
                warnings.warn(u'Unable to process log entry: %s' % (exc,))
开发者ID:armicron,项目名称:djbookru,代码行数:80,代码来源:manager.py


示例16: process

    def process(self, **kwargs):
        "Processes the message before passing it on to the server"
        from sentry.helpers import get_filters

        if kwargs.get("data"):
            # Ensure we're not changing the original data which was passed
            # to Sentry
            kwargs["data"] = kwargs["data"].copy()

        request = kwargs.pop("request", None)
        if request:
            if not kwargs.get("data"):
                kwargs["data"] = {}
            kwargs["data"].update(dict(META=request.META, POST=request.POST, GET=request.GET, COOKIES=request.COOKIES))

            if not kwargs.get("url"):
                kwargs["url"] = request.build_absolute_uri()

        kwargs.setdefault("level", logging.ERROR)
        kwargs.setdefault("server_name", conf.NAME)

        # save versions of all installed apps
        if "data" not in kwargs or "__sentry__" not in (kwargs["data"] or {}):
            if kwargs.get("data") is None:
                kwargs["data"] = {}
            kwargs["data"]["__sentry__"] = {}

        versions = get_versions()
        kwargs["data"]["__sentry__"]["versions"] = versions

        if kwargs.get("view"):
            # get list of modules from right to left
            parts = kwargs["view"].split(".")
            module_list = [".".join(parts[:idx]) for idx in xrange(1, len(parts) + 1)][::-1]
            version = None
            module = None
            for m in module_list:
                if m in versions:
                    module = m
                    version = versions[m]

            # store our "best guess" for application version
            if version:
                kwargs["data"]["__sentry__"].update({"version": version, "module": module})

        if "checksum" not in kwargs:
            checksum = construct_checksum(**kwargs)
        else:
            checksum = kwargs["checksum"]

        if conf.THRASHING_TIMEOUT and conf.THRASHING_LIMIT:
            cache_key = "sentry:%s:%s" % (kwargs.get("class_name") or "", checksum)
            added = cache.add(cache_key, 1, conf.THRASHING_TIMEOUT)
            if not added:
                try:
                    thrash_count = cache.incr(cache_key)
                except (KeyError, ValueError):
                    # cache.incr can fail. Assume we aren't thrashing yet, and
                    # if we are, hope that the next error has a successful
                    # cache.incr call.
                    thrash_count = 0
                if thrash_count > conf.THRASHING_LIMIT:
                    message_id = cache.get("%s:last_message_id" % cache_key)
                    if request:
                        # attach the sentry object to the request
                        request.sentry = {"id": message_id, "thrashed": True}
                    return message_id

        for filter_ in get_filters():
            kwargs = filter_(None).process(kwargs) or kwargs

        # create ID client-side so that it can be passed to application
        message_id = uuid.uuid4().hex
        kwargs["message_id"] = message_id

        # Make sure all data is coerced
        kwargs = transform(kwargs)

        self.send(**kwargs)

        if request:
            # attach the sentry object to the request
            request.sentry = {"id": message_id}

        if conf.THRASHING_TIMEOUT and conf.THRASHING_LIMIT:
            # store the last message_id incase we hit thrashing limits
            cache.set("%s:last_message_id" % cache_key, message_id, conf.THRASHING_LIMIT + 5)

        return message_id
开发者ID:djbook-ru,项目名称:djbookru,代码行数:89,代码来源:base.py


示例17: save

 def save(self, *args, **kwargs):
     if not self.checksum:
         self.checksum = construct_checksum(**self.__dict__)
     super(Message, self).save(*args, **kwargs)
开发者ID:johnpaulett,项目名称:django-sentry,代码行数:4,代码来源:models.py


示例18: from_kwargs

    def from_kwargs(self, **kwargs):
        from sentry.models import Message, GroupedMessage, FilterValue
        URL_MAX_LENGTH = Message._meta.get_field_by_name('url')[0].max_length

        name = kwargs.pop('name', None)
        message_type = kwargs.pop("message_type", conf.LOG)
        project = kwargs.pop("project")

        site = kwargs.pop('site', None)
        test_result = kwargs.pop('test_result', None)

        # Log specific
        logger_name = kwargs.pop('logger', '')
        url = kwargs.pop('url', None)
        data = kwargs.pop('data', {}) or {}
        if url:
            data['url'] = url
            url = url[:URL_MAX_LENGTH]

        checksum = construct_checksum(**kwargs)
        mail = False
        try:
            if 'url' in data:
                kwargs['data'] = {'url': data['url']}
            group, created = self._get_or_create_group_message(message_type, name,
                                                               checksum, project,
                                                               test_result, kwargs)
            kwargs.pop('data', None)
            if not created:
                self._update_counters(group)
            else: 
                mail = True

            instance = Message.objects.create(
                name=name,
                message_type=message_type,
                project=project,
                checksum=checksum,
                group=group,

                logger=logger_name,
                data=data,
                url=url,
                site=site,
                test_result=test_result,
                **kwargs
            )
            if site:
                print FilterValue.objects.all()
                
                FilterValue.objects.get_or_create(key='site__servername', value=site.servername, label=site.servername)
#            if site:
#                FilterValue.objects.get_or_create(key='site', value=site.id, label=site.name)
            if site:
                FilterValue.objects.get_or_create(key='project', value=project.id, label=project.name)
            if logger_name:
                FilterValue.objects.get_or_create(key='logger', value=logger_name, label=logger_name)
            if test_result:
                FilterValue.objects.get_or_create(key='test_result', value=test_result, label=test_result)
        except Exception, exc:
            # TODO: should we mail admins when there are failures?
            try:
                logger.exception(u'Unable to process log entry: %s' % (exc,))
            except Exception, exc:
                warnings.warn(u'Unable to process log entry: %s' % (exc,))
开发者ID:olchik,项目名称:django-sentry,代码行数:65,代码来源:manager.py



注:本文中的sentry.helpers.construct_checksum函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python helpers.transform函数代码示例发布时间:2022-05-27
下一篇:
Python filters.get_filters函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap