|
@@ -8,24 +8,54 @@ sentry.tasks.post_process
|
|
|
|
|
|
from __future__ import absolute_import
|
|
|
|
|
|
-from hashlib import md5
|
|
|
+import logging
|
|
|
|
|
|
from django.conf import settings
|
|
|
+from hashlib import md5
|
|
|
+
|
|
|
from sentry.plugins import plugins
|
|
|
+from sentry.rules import rules
|
|
|
from sentry.tasks.base import instrumented_task
|
|
|
from sentry.utils.safe import safe_execute
|
|
|
|
|
|
|
|
|
+rules_logger = logging.getLogger('sentry.errors.rules')
|
|
|
+
|
|
|
+
|
|
|
+def condition_matches(project, condition, **kwargs):
|
|
|
+ condition_cls = rules.get(condition['id'])
|
|
|
+ if condition_cls is None:
|
|
|
+ rules_logger.error('Unregistered condition %r', condition['id'])
|
|
|
+ return
|
|
|
+
|
|
|
+ condition_inst = condition_cls(project)
|
|
|
+ return safe_execute(condition_inst.passes, **kwargs)
|
|
|
+
|
|
|
+
|
|
|
+# TODO(dcramer): cache this
|
|
|
+def get_rules(project):
|
|
|
+ from sentry.models import Rule
|
|
|
+
|
|
|
+ return list(Rule.objects.filter(project=project))
|
|
|
+
|
|
|
+
|
|
|
@instrumented_task(
|
|
|
name='sentry.tasks.post_process.post_process_group',
|
|
|
queue='triggers')
|
|
|
-def post_process_group(group, event, **kwargs):
|
|
|
+def post_process_group(group, event, is_new, is_regression, is_sample, **kwargs):
|
|
|
"""
|
|
|
Fires post processing hooks for a group.
|
|
|
"""
|
|
|
- for plugin in plugins.for_project(group.project):
|
|
|
- plugin_post_process_group.delay(
|
|
|
- plugin.slug, group=group, event=event, **kwargs)
|
|
|
+ from sentry.models import Project
|
|
|
+
|
|
|
+ project = Project.objects.get_from_cache(id=group.project_id)
|
|
|
+
|
|
|
+ child_kwargs = {
|
|
|
+ 'event': event,
|
|
|
+ 'is_new': is_new,
|
|
|
+ 'is_regression': is_regression,
|
|
|
+ 'is_sample': is_sample,
|
|
|
+ }
|
|
|
|
|
|
if settings.SENTRY_ENABLE_EXPLORE_CODE:
|
|
|
record_affected_code.delay(group=group, event=event)
|
|
@@ -33,6 +63,53 @@ def post_process_group(group, event, **kwargs):
|
|
|
if settings.SENTRY_ENABLE_EXPLORE_USERS:
|
|
|
record_affected_user.delay(group=group, event=event)
|
|
|
|
|
|
+ for plugin in plugins.for_project(project):
|
|
|
+ plugin_post_process_group.delay(
|
|
|
+ plugin.slug, group=group, **child_kwargs)
|
|
|
+
|
|
|
+ for rule in get_rules(project):
|
|
|
+ match = rule.data.get('action_match', 'all')
|
|
|
+ condition_list = rule.data.get('conditions', ())
|
|
|
+ if not condition_list:
|
|
|
+ pass
|
|
|
+ elif match == 'all':
|
|
|
+ if not all(condition_matches(project, c, **child_kwargs) for c in condition_list):
|
|
|
+ continue
|
|
|
+ elif match == 'any':
|
|
|
+ if not any(condition_matches(project, c, **child_kwargs) for c in condition_list):
|
|
|
+ continue
|
|
|
+ else:
|
|
|
+ rules_logger.error('Unsupported action_match %r for rule %d',
|
|
|
+ match, rule.id)
|
|
|
+ continue
|
|
|
+
|
|
|
+ execute_rule.delay(
|
|
|
+ rule_id=rule.id,
|
|
|
+ **child_kwargs
|
|
|
+ )
|
|
|
+
|
|
|
+
|
|
|
+@instrumented_task(
|
|
|
+ name='sentry.tasks.post_process.execute_rule',
|
|
|
+ queue='triggers')
|
|
|
+def execute_rule(rule_id, event, **kwargs):
|
|
|
+ """
|
|
|
+ Fires post processing hooks for a rule.
|
|
|
+ """
|
|
|
+ from sentry.models import Project, Rule
|
|
|
+
|
|
|
+ rule = Rule.objects.get(id=rule_id)
|
|
|
+ project = Project.objects.get_from_cache(id=event.project_id)
|
|
|
+
|
|
|
+ for action in rule.data.get('actions', ()):
|
|
|
+ action_cls = rules.get(action['id'])
|
|
|
+ if action_cls is None:
|
|
|
+ rules_logger.error('Unregistered action %r', action['id'])
|
|
|
+ continue
|
|
|
+
|
|
|
+ action_inst = action_cls(project)
|
|
|
+ safe_execute(action_inst.after, event=event, **kwargs)
|
|
|
+
|
|
|
|
|
|
@instrumented_task(
|
|
|
name='sentry.tasks.post_process.plugin_post_process_group',
|