def serialize(self, obj, attrs, user, **kwargs): from sentry.incidents.serializers import ACTION_TARGET_TYPE_TO_STRING result = { "id": str(obj.id), "alertRuleTriggerId": str(obj.alert_rule_trigger_id), "type": AlertRuleTriggerAction.get_registered_type( AlertRuleTriggerAction.Type(obj.type)).slug, "targetType": ACTION_TARGET_TYPE_TO_STRING[AlertRuleTriggerAction.TargetType( obj.target_type)], "targetIdentifier": self.get_identifier_from_action(obj), "inputChannelId": self.get_input_channel_id(obj), "integrationId": obj.integration_id, "sentryAppId": obj.sentry_app_id, "dateCreated": obj.date_added, "desc": self.human_desc(obj), } # Check if action is a Sentry App that has Alert Rule UI Component settings if obj.sentry_app_id and obj.sentry_app_config: result["settings"] = obj.sentry_app_config return result
def validate_target_type(self, target_type): try: return AlertRuleTriggerAction.TargetType(target_type) except ValueError: raise serializers.ValidationError( "Invalid target_type, valid values are %s" % [item.value for item in AlertRuleTriggerAction.TargetType])
def serialize(self, obj, attrs, user): from sentry.incidents.endpoints.serializers import action_target_type_to_string return { "id": str(obj.id), "alertRuleTriggerId": str(obj.alert_rule_trigger_id), "type": AlertRuleTriggerAction.get_registered_type( AlertRuleTriggerAction.Type(obj.type)).slug, "targetType": action_target_type_to_string[AlertRuleTriggerAction.TargetType( obj.target_type)], "targetIdentifier": self.get_identifier_from_action(obj), "integrationId": obj.integration_id, "sentryAppId": obj.sentry_app_id, "dateCreated": obj.date_added, "desc": self.human_desc(obj), }
def assert_action_serialized(self, action, result): assert result["id"] == six.text_type(action.id) assert result["alertRuleTriggerId"] == six.text_type( action.alert_rule_trigger_id) assert (result["type"] == AlertRuleTriggerAction.get_registered_type( AlertRuleTriggerAction.Type(action.type)).slug) assert (result["targetType"] == action_target_type_to_string[ AlertRuleTriggerAction.TargetType(action.target_type)]) assert result["targetIdentifier"] == action.target_identifier assert result["integrationId"] == action.integration_id assert result["dateCreated"] == action.date_added
def serialize(self, obj, attrs, user): from sentry.incidents.endpoints.serializers import action_target_type_to_string return { "id": six.text_type(obj.id), "alertRuleTriggerId": six.text_type(obj.alert_rule_trigger_id), "type": AlertRuleTriggerAction.get_registered_type( AlertRuleTriggerAction.Type(obj.type) ).slug, "targetType": action_target_type_to_string[ AlertRuleTriggerAction.TargetType(obj.target_type) ], "targetIdentifier": obj.target_display if obj.target_display is not None else obj.target_identifier, "integrationId": obj.integration_id, "dateCreated": obj.date_added, }
def test_not_updated_fields(self): self.create_member(user=self.user, organization=self.organization, role="owner", teams=[self.team]) self.login_as(self.user) with self.feature("organizations:incidents"): resp = self.get_valid_response( self.organization.slug, self.alert_rule.id, self.trigger.id, self.action.id, type=AlertRuleTriggerAction.get_registered_type( AlertRuleTriggerAction.Type(self.action.type)).slug, targetType=action_target_type_to_string[ AlertRuleTriggerAction.TargetType( self.action.target_type)], targetIdentifier=self.action.target_identifier, ) # Alert rule should be exactly the same assert resp.data == serialize(self.action)