def get(self, request, organization): """ Fetches actions that an alert rule can perform for an organization """ if not features.has("organizations:incidents", organization, actor=request.user): raise ResourceDoesNotExist actions = [] # Cache Integration objects in this data structure to save DB calls. provider_integrations = defaultdict(list) for integration in get_available_action_integrations_for_org(organization): provider_integrations[integration.provider].append(integration) for registered_type in AlertRuleTriggerAction.get_registered_types(): # Used cached integrations for each `registered_type` instead of making N calls. if registered_type.integration_provider: actions += [ build_action_response( registered_type, integration=integration, organization=organization ) for integration in provider_integrations[registered_type.integration_provider] ] # Add all alertable SentryApps to the list. elif registered_type.type == AlertRuleTriggerAction.Type.SENTRY_APP: actions += [ build_action_response(registered_type, sentry_app=app) for app in get_alertable_sentry_apps(organization.id, with_metric_alerts=True) ] else: actions.append(build_action_response(registered_type)) return Response(actions, status=status.HTTP_200_OK)
def get_sentry_app_services(self): return [ SentryAppService(app) for app in get_alertable_sentry_apps(self.project.organization_id) ]