|
@@ -41,6 +41,7 @@ from sentry.search.events.builder import QueryBuilder
|
|
|
from sentry.search.events.fields import resolve_field
|
|
|
from sentry.services.hybrid_cloud.app import RpcSentryAppInstallation, app_service
|
|
|
from sentry.services.hybrid_cloud.integration import RpcIntegration, integration_service
|
|
|
+from sentry.services.hybrid_cloud.integration.model import RpcOrganizationIntegration
|
|
|
from sentry.shared_integrations.exceptions import DuplicateDisplayNameError
|
|
|
from sentry.snuba.dataset import Dataset
|
|
|
from sentry.snuba.entity_subscription import (
|
|
@@ -1244,6 +1245,10 @@ def get_target_identifier_display_for_integration(type, target_value, *args, **k
|
|
|
target_identifier, target_value = get_alert_rule_trigger_action_pagerduty_service(
|
|
|
target_value, *args, **kwargs
|
|
|
)
|
|
|
+ elif type == AlertRuleTriggerAction.Type.OPSGENIE.value:
|
|
|
+ target_identifier, target_value = get_alert_rule_trigger_action_opsgenie_team(
|
|
|
+ target_value, *args, **kwargs
|
|
|
+ )
|
|
|
else:
|
|
|
raise Exception("Not implemented")
|
|
|
|
|
@@ -1327,6 +1332,25 @@ def get_alert_rule_trigger_action_pagerduty_service(
|
|
|
return service["id"], service["service_name"]
|
|
|
|
|
|
|
|
|
+def get_alert_rule_trigger_action_opsgenie_team(
|
|
|
+ target_value: Optional[str],
|
|
|
+ organization: RpcOrganizationIntegration,
|
|
|
+ integration_id: int,
|
|
|
+ use_async_lookup=False,
|
|
|
+ input_channel_id=None,
|
|
|
+ integrations=None,
|
|
|
+):
|
|
|
+ from sentry.integrations.opsgenie.utils import get_team
|
|
|
+
|
|
|
+ oi = integration_service.get_organization_integration(
|
|
|
+ integration_id=integration_id, organization_id=organization.id
|
|
|
+ )
|
|
|
+ team = get_team(target_value, oi)
|
|
|
+ if not team:
|
|
|
+ raise InvalidTriggerActionError("No Opsgenie team found.")
|
|
|
+ return team["id"], team["team"]
|
|
|
+
|
|
|
+
|
|
|
def get_alert_rule_trigger_action_sentry_app(organization, sentry_app_id, installations):
|
|
|
from sentry.services.hybrid_cloud.app import app_service
|
|
|
|
|
@@ -1380,6 +1404,19 @@ def get_pagerduty_services(organization_id, integration_id) -> List[Tuple[int, s
|
|
|
return [(s["id"], s["service_name"]) for s in services]
|
|
|
|
|
|
|
|
|
+def get_opsgenie_teams(organization_id, integration_id) -> list[Tuple[str, str]]:
|
|
|
+ org_int = integration_service.get_organization_integration(
|
|
|
+ organization_id=organization_id, integration_id=integration_id
|
|
|
+ )
|
|
|
+ if org_int is None:
|
|
|
+ return []
|
|
|
+ teams = []
|
|
|
+ team_table = org_int.config.get("team_table")
|
|
|
+ if team_table:
|
|
|
+ teams = [(team["id"], team["team"]) for team in team_table]
|
|
|
+ return teams
|
|
|
+
|
|
|
+
|
|
|
# TODO: This is temporarily needed to support back and forth translations for snuba / frontend.
|
|
|
# Uses a function from discover to break the aggregate down into parts, and then compare the "field"
|
|
|
# to a list of accepted fields, or a list of fields we need to translate.
|