Beispiel #1
0
def build_action_response(registered_type, integration=None, organization=None, sentry_app=None):
    """
    Build the "available action" objects for the API. Each one can have different fields.

    :param registered_type: One of the registered AlertRuleTriggerAction types.
    :param integration: Optional. The Integration if this action uses a one.
    :param organization: Optional. If this is a PagerDuty action, we need the organization to look up services.
    :param sentry_app: Optional. The SentryApp if this action uses a one.
    :return: The available action object.
    """

    action_response = {
        "type": registered_type.slug,
        "allowedTargetTypes": [
            action_target_type_to_string.get(target_type)
            for target_type in registered_type.supported_target_types
        ],
    }

    if integration:
        action_response["integrationName"] = integration.name
        action_response["integrationId"] = integration.id

        if registered_type.type == AlertRuleTriggerAction.Type.PAGERDUTY:
            action_response["options"] = [
                {"value": service["id"], "label": service["service_name"]}
                for service in get_pagerduty_services(organization, integration.id)
            ]

    elif sentry_app:
        action_response["sentryAppName"] = sentry_app.name
        action_response["sentryAppId"] = sentry_app.id
        action_response["status"] = SentryAppStatus.as_str(sentry_app.status)

    return action_response
Beispiel #2
0
def build_action_response(registered_type,
                          integration=None,
                          organization=None,
                          sentry_app_installation=None):
    """
    Build the "available action" objects for the API. Each one can have different fields.

    :param registered_type: One of the registered AlertRuleTriggerAction types.
    :param integration: Optional. The Integration if this action uses a one.
    :param organization: Optional. If this is a PagerDuty action, we need the organization to look up services.
    :param sentry_app: Optional. The SentryApp if this action uses a one.
    :return: The available action object.
    """

    action_response = {
        "type":
        registered_type.slug,
        "allowedTargetTypes": [
            ACTION_TARGET_TYPE_TO_STRING.get(target_type)
            for target_type in registered_type.supported_target_types
        ],
    }

    if integration:
        action_response["integrationName"] = integration.name
        action_response["integrationId"] = integration.id

        if registered_type.type == AlertRuleTriggerAction.Type.PAGERDUTY:
            action_response["options"] = [{
                "value": service["id"],
                "label": service["service_name"]
            } for service in get_pagerduty_services(organization,
                                                    integration.id)]

    elif sentry_app_installation:
        action_response[
            "sentryAppName"] = sentry_app_installation.sentry_app.name
        action_response["sentryAppId"] = sentry_app_installation.sentry_app_id
        action_response[
            "sentryAppInstallationUuid"] = sentry_app_installation.uuid
        action_response["status"] = SentryAppStatus.as_str(
            sentry_app_installation.sentry_app.status)

        # Sentry Apps can be alertable but not have an Alert Rule UI Component
        component = sentry_app_installation.prepare_sentry_app_components(
            "alert-rule-action")
        if component:
            action_response["settings"] = component.schema.get("settings", {})

    return action_response