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)
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)
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): 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) 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)
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): 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) 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)
def get_digest_option(key): return ProjectOption.objects.get_value( project, get_digest_option_key("mail", key))
def handle(self, request, organization, team, project): op = request.POST.get('op') if op == 'enable': self._handle_enable_plugin(request, project) return HttpResponseRedirect(request.path) elif op == 'disable': self._handle_disable_plugin(request, project) return HttpResponseRedirect(request.path) if op == 'save-settings': if digests.enabled(project): digests_form = DigestSettingsForm( data=request.POST, prefix='digests', initial={ 'minimum_delay': project.get_option( get_digest_option_key('mail', 'minimum_delay'), digests.minimum_delay / 60, ), 'maximum_delay': project.get_option( get_digest_option_key('mail', 'maximum_delay'), digests.maximum_delay / 60, ), }, ) else: digests_form = None general_form = NotificationSettingsForm( data=request.POST, prefix='general', initial={ 'subject_prefix': project.get_option('mail:subject_prefix', options.get('mail.subject-prefix')), }, ) if general_form.is_valid() and (digests_form.is_valid() if digests_form is not None else True): project.update_option( 'mail:subject_prefix', general_form.cleaned_data['subject_prefix']) if digests_form is not None: project.update_option( get_digest_option_key('mail', 'minimum_delay'), digests_form.cleaned_data['minimum_delay'] * 60, ) project.update_option( get_digest_option_key('mail', 'maximum_delay'), digests_form.cleaned_data['maximum_delay'] * 60, ) messages.add_message(request, messages.SUCCESS, OK_SETTINGS_SAVED) return HttpResponseRedirect(request.path) else: if digests.enabled(project): digests_form = DigestSettingsForm( prefix='digests', initial={ 'minimum_delay': project.get_option( get_digest_option_key('mail', 'minimum_delay'), digests.minimum_delay, ) / 60, 'maximum_delay': project.get_option( get_digest_option_key('mail', 'maximum_delay'), digests.maximum_delay, ) / 60, }, ) else: digests_form = None general_form = NotificationSettingsForm( prefix='general', initial={ 'subject_prefix': project.get_option('mail:subject_prefix', options.get('mail.subject-prefix')), }, ) enabled_plugins = [] other_plugins = [] for plugin in self._iter_plugins(): if plugin.is_enabled(project): content = plugin.get_notification_doc_html() form = plugin.project_conf_form if form is not None: view = plugin.configure(request=request, project=project) if isinstance(view, HttpResponse): return view enabled_plugins.append((plugin, mark_safe(content + view))) elif content: enabled_plugins.append((plugin, mark_safe(content))) elif plugin.can_configure_for_project(project): other_plugins.append(plugin) is_user_subbed = project.is_user_subscribed_to_mail_alerts( request.user) context = { 'page': 'notifications', 'enabled_plugins': enabled_plugins, 'other_plugins': other_plugins, 'general_form': general_form, 'digests_form': digests_form, 'is_user_subbed': is_user_subbed } return self.respond('sentry/project-notifications.html', context)
def get_digest_option(key): return ProjectOption.objects.get_value( project, get_digest_option_key(self.get_conf_key(), key), )
def handle(self, request, organization, team, project): op = request.POST.get("op") if op == "enable": self._handle_enable_plugin(request, project) return HttpResponseRedirect(request.path) elif op == "disable": self._handle_disable_plugin(request, project) return HttpResponseRedirect(request.path) if op == "save-settings": if digests.enabled(project): digests_form = DigestSettingsForm( data=request.POST, prefix="digests", initial={ "minimum_delay": project.get_option( get_digest_option_key("mail", "minimum_delay"), digests.minimum_delay / 60 ), "maximum_delay": project.get_option( get_digest_option_key("mail", "maximum_delay"), digests.maximum_delay / 60 ), }, ) else: digests_form = None general_form = NotificationSettingsForm( data=request.POST, prefix="general", initial={ "subject_prefix": project.get_option("mail:subject_prefix", options.get("mail.subject-prefix")) }, ) if general_form.is_valid() and (digests_form.is_valid() if digests_form is not None else True): project.update_option("mail:subject_prefix", general_form.cleaned_data["subject_prefix"]) if digests_form is not None: project.update_option( get_digest_option_key("mail", "minimum_delay"), digests_form.cleaned_data["minimum_delay"] * 60 ) project.update_option( get_digest_option_key("mail", "maximum_delay"), digests_form.cleaned_data["maximum_delay"] * 60 ) messages.add_message(request, messages.SUCCESS, OK_SETTINGS_SAVED) return HttpResponseRedirect(request.path) else: if digests.enabled(project): digests_form = DigestSettingsForm( prefix="digests", initial={ "minimum_delay": project.get_option( get_digest_option_key("mail", "minimum_delay"), digests.minimum_delay ) / 60, "maximum_delay": project.get_option( get_digest_option_key("mail", "maximum_delay"), digests.maximum_delay ) / 60, }, ) else: digests_form = None general_form = NotificationSettingsForm( prefix="general", initial={ "subject_prefix": project.get_option("mail:subject_prefix", options.get("mail.subject-prefix")) }, ) enabled_plugins = [] other_plugins = [] for plugin in self._iter_plugins(): if plugin.is_enabled(project): content = plugin.get_notification_doc_html() form = plugin.project_conf_form if form is not None: view = plugin.configure(request, project=project) if isinstance(view, HttpResponse): return view enabled_plugins.append((plugin, mark_safe(content + view))) elif content: enabled_plugins.append((plugin, mark_safe(content))) elif plugin.can_configure_for_project(project): other_plugins.append(plugin) context = { "page": "notifications", "enabled_plugins": enabled_plugins, "other_plugins": other_plugins, "general_form": general_form, "digests_form": digests_form, } return self.respond("sentry/project-notifications.html", context)
def handle(self, request, organization, team, project): op = request.POST.get('op') if op == 'enable': self._handle_enable_plugin(request, project) return HttpResponseRedirect(request.path) elif op == 'disable': self._handle_disable_plugin(request, project) return HttpResponseRedirect(request.path) if op == 'save-settings': if digests.enabled(project): digests_form = DigestSettingsForm( data=request.POST, prefix='digests', initial={ 'minimum_delay': project.get_option( get_digest_option_key('mail', 'minimum_delay'), digests.minimum_delay / 60, ), 'maximum_delay': project.get_option( get_digest_option_key('mail', 'maximum_delay'), digests.maximum_delay / 60, ), }, ) else: digests_form = None general_form = NotificationSettingsForm( data=request.POST, prefix='general', initial={ 'subject_prefix': project.get_option( 'mail:subject_prefix', settings.EMAIL_SUBJECT_PREFIX), }, ) if general_form.is_valid() and (digests_form.is_valid() if digests_form is not None else True): project.update_option('mail:subject_prefix', general_form.cleaned_data['subject_prefix']) if digests_form is not None: project.update_option( get_digest_option_key('mail', 'minimum_delay'), digests_form.cleaned_data['minimum_delay'] * 60, ) project.update_option( get_digest_option_key('mail', 'maximum_delay'), digests_form.cleaned_data['maximum_delay'] * 60, ) messages.add_message( request, messages.SUCCESS, OK_SETTINGS_SAVED) return HttpResponseRedirect(request.path) else: if digests.enabled(project): digests_form = DigestSettingsForm( prefix='digests', initial={ 'minimum_delay': project.get_option( get_digest_option_key('mail', 'minimum_delay'), digests.minimum_delay, ) / 60, 'maximum_delay': project.get_option( get_digest_option_key('mail', 'maximum_delay'), digests.maximum_delay, ) / 60, }, ) else: digests_form = None general_form = NotificationSettingsForm( prefix='general', initial={ 'subject_prefix': project.get_option( 'mail:subject_prefix', settings.EMAIL_SUBJECT_PREFIX), }, ) enabled_plugins = [] other_plugins = [] for plugin in self._iter_plugins(): if plugin.is_enabled(project): content = plugin.get_notification_doc_html() form = plugin.project_conf_form if form is not None: view = plugin.configure(request, project=project) if isinstance(view, HttpResponse): return view enabled_plugins.append((plugin, mark_safe(content + view))) elif content: enabled_plugins.append((plugin, mark_safe(content))) elif plugin.can_configure_for_project(project): other_plugins.append(plugin) context = { 'page': 'notifications', 'enabled_plugins': enabled_plugins, 'other_plugins': other_plugins, 'general_form': general_form, 'digests_form': digests_form, } return self.respond('sentry/project-notifications.html', context)