Permalink
Browse files

Cleanup filter and processor apis

  • Loading branch information...
1 parent 551d710 commit 321231bc185ea87bb03a119aa53fc080f6ecd67a @dcramer committed Sep 11, 2011
Showing with 77 additions and 54 deletions.
  1. +6 −7 sentry/client/base.py
  2. +1 −1 sentry/conf/__init__.py
  3. +41 −18 sentry/core/processors.py
  4. +0 −23 sentry/utils/__init__.py
  5. +26 −2 sentry/web/filters.py
  6. +3 −3 sentry/web/views.py
View
@@ -17,12 +17,12 @@
import uuid
import urllib2
-from sentry import app
-
import sentry
+from sentry import app
+from sentry.core import processors
+from sentry.models import Group, Event
from sentry.utils import get_versions, transform
from sentry.utils.api import get_mac_signature, get_auth_header
-from sentry.models import Group, Event
class ModuleProxyCache(dict):
def __missing__(self, key):
@@ -156,17 +156,16 @@ def capture(self, event_type, tags=None, data=None, date=None, time_spent=None,
# if thrash_count > app.config['THRASHING_LIMIT']:
# return
- # for filter_ in get_filters():
+ # for filter_ in filters.all():
# kwargs = filter_(None).process(kwargs) or kwargs
# create ID client-side so that it can be passed to application
event_id = uuid.uuid4().hex
# Run the data through processors
- PROCESSORS = app.config['PROCESSORS']
- for processor in PROCESSORS:
- data.update(self.module_cache[processor](data))
+ for processor in processors.all():
+ data.update(self.module_cache[processor].process(data))
# Make sure all data is coerced
data = transform(data)
View
@@ -90,7 +90,7 @@ class SentryConfig(object):
}
PROCESSORS = (
- 'sentry.core.processors.sanitize_passwords_processor',
+ 'sentry.core.processors.SantizePasswordsProcessor',
)
# Controls how long entries should stay along before the
View
@@ -6,27 +6,50 @@
:license: BSD, see LICENSE for more details.
"""
+import logging
+
+from sentry import app
+
+_CACHE = None
+def all(from_cache=True):
+ global _CACHE
+
+ if _CACHE is None or not from_cache:
+ modules = []
+ for path in app.config['PROCESSORS']:
+ module_name, class_name = path.rsplit('.', 1)
+ try:
+ module = __import__(module_name, {}, {}, class_name)
+ handler = getattr(module, class_name)
+ except Exception:
+ logger = logging.getLogger(__name__)
+ logger.exception('Unable to import %s' % (path,))
+ continue
+ modules.append(handler())
+
+ _CACHE = modules
+
+ for f in _CACHE:
+ yield f
+
class Processor(object):
- def process(self, data):
+ def process(self, data, **kwargs):
resp = self.get_data(data)
if resp:
- data['extra'].update(resp)
+ data = resp
return data
-
- def get_data(self, data):
- return {}
-def sanitize_passwords_processor(data):
- """ Asterisk out passwords from password fields in frames.
+class SantizePasswordsProcessor(Processor):
+ """
+ Asterisk out passwords from password fields in frames.
"""
- if 'sentry.interfaces.Stacktrace' in data:
- if 'frames' in data['sentry.interfaces.Stacktrace']:
- for frame in data['sentry.interfaces.Stacktrace']['frames']:
- if 'vars' in frame:
- for k,v in frame['vars'].iteritems():
- if k.startswith('password'):
- # store mask as a fixed length for security
- frame['vars'][k] = '*'*16
- return data
-
-#class SantizePasswordsProcessor(Processor):
+ def process(self, data, **kwargs):
+ if 'sentry.interfaces.Stacktrace' in data:
+ if 'frames' in data['sentry.interfaces.Stacktrace']:
+ for frame in data['sentry.interfaces.Stacktrace']['frames']:
+ if 'vars' in frame:
+ for k,v in frame['vars'].iteritems():
+ if k.startswith('password'):
+ # store mask as a fixed length for security
+ frame['vars'][k] = '*'*16
+ return data
View
@@ -16,31 +16,8 @@
from types import ClassType, TypeType
import sentry
-from sentry import app
from sentry.utils.encoding import force_unicode
-FILTER_CACHE = None
-def get_filters(from_cache=True):
- global FILTER_CACHE
-
- if FILTER_CACHE is None or not from_cache:
- filters = []
- for key, path in app.config['FILTERS']:
- module_name, class_name = path.rsplit('.', 1)
- try:
- module = __import__(module_name, {}, {}, class_name)
- handler = getattr(module, class_name)
- except Exception:
- logger = logging.getLogger('sentry.web.filters')
- logger.exception('Unable to import %s' % (path,))
- continue
- filters.append(handler(key))
-
- FILTER_CACHE = filters
-
- for f in FILTER_CACHE:
- yield f
-
def construct_checksum(level=logging.ERROR, class_name='', traceback='', message='', **kwargs):
checksum = hashlib.md5(str(level))
checksum.update(class_name or '')
View
@@ -9,10 +9,34 @@
# Widget api is pretty ugly
from __future__ import absolute_import
-from sentry import app
-from sentry.models import Tag
+import logging
+
from flask import request
from jinja2 import Markup, escape
+from sentry import app
+from sentry.models import Tag
+
+_CACHE = None
+def all(from_cache=True):
+ global _CACHE
+
+ if _CACHE is None or not from_cache:
+ modules = []
+ for key, path in app.config['FILTERS']:
+ module_name, class_name = path.rsplit('.', 1)
+ try:
+ module = __import__(module_name, {}, {}, class_name)
+ handler = getattr(module, class_name)
+ except Exception:
+ logger = logging.getLogger(__name__)
+ logger.exception('Unable to import %s' % (path,))
+ continue
+ modules.append(handler(key))
+
+ _CACHE = modules
+
+ for f in _CACHE:
+ yield f
class Widget(object):
def __init__(self, filter):
View
@@ -19,8 +19,8 @@
from sentry import app
from sentry.core.plugins import GroupActionProvider
from sentry.models import Group, Event, EventType
+from sentry.web import filters
from sentry.web.templatetags import with_priority
-from sentry.utils import get_filters
from sentry.utils.shortcuts import get_object_or_404
uuid_re = re.compile(r'^[a-z0-9]{32}$')
@@ -111,7 +111,7 @@ def search():
@login_required
@app.route('/')
def index():
- filter_list = list(get_filters())
+ filter_list = list(filters.all())
try:
page = int(request.args.get('p', 1))
@@ -159,7 +159,7 @@ def ajax_handler():
if op == 'poll':
filters = []
- for filter_ in get_filters():
+ for filter_ in filters.all():
filters.append(filter_(request))
event_list = Group.objects

0 comments on commit 321231b

Please sign in to comment.