diff --git a/datadog_sync/model/monitors.py b/datadog_sync/model/monitors.py index 07a9bcbd..aa26d852 100644 --- a/datadog_sync/model/monitors.py +++ b/datadog_sync/model/monitors.py @@ -16,7 +16,11 @@ class Monitors(BaseResource): resource_type = "monitors" resource_config = ResourceConfig( - resource_connections={"monitors": ["query"], "roles": ["restricted_roles"], "synthetics_tests": []}, + resource_connections={ + "monitors": ["query"], + "roles": ["restricted_roles"], + "service_level_objectives": ["query"], + }, base_path="/api/v1/monitor", excluded_attributes=[ "id", @@ -44,7 +48,7 @@ def import_resource(self, _id: Optional[str] = None, resource: Optional[Dict] = resource = source_client.get(self.resource_config.base_path + f"/{_id}").json() resource = cast(dict, resource) - if resource["type"] in ("synthetics alert", "slo alert"): + if resource["type"] == "synthetics alert": return self.resource_config.source_resources[str(resource["id"])] = resource @@ -80,6 +84,7 @@ def delete_resource(self, _id: str) -> None: def connect_id(self, key: str, r_obj: Dict, resource_to_connect: str) -> Optional[List[str]]: monitors = self.config.resources[resource_to_connect].resource_config.destination_resources synthetics_tests = self.config.resources["synthetics_tests"].resource_config.destination_resources + slos = self.config.resources["service_level_objectives"].resource_config.destination_resources if r_obj.get("type") == "composite" and key == "query": failed_connections = [] @@ -100,6 +105,15 @@ def connect_id(self, key: str, r_obj: Dict, resource_to_connect: str) -> Optiona failed_connections.append(_id) r_obj[key] = (r_obj[key].replace("#", "")).strip() return failed_connections + elif resource_to_connect == "service_level_objectives" and r_obj.get("type") == "slo alert" and key == "query": + failed_connections = [] + if res := re.search('error_budget\("(.*)"\)\.', r_obj[key]): + _id = res.group(1) + if _id in slos: + r_obj[key] = re.sub(_id, slos[_id]["id"], r_obj[key]) + else: + failed_connections.append(_id) + return failed_connections elif key == "query": return None else: diff --git a/datadog_sync/utils/resources_manager.py b/datadog_sync/utils/resources_manager.py index f91686ca..64dc7ce5 100644 --- a/datadog_sync/utils/resources_manager.py +++ b/datadog_sync/utils/resources_manager.py @@ -21,7 +21,7 @@ def __init__(self, config: Configuration) -> None: self.all_resources: Dict[str, str] = {} # mapping of all resources to its resource_type self.all_cleanup_resources: Dict[str, str] = {} # mapping of all resources to cleanup self.dependencies_graph: Dict[str, Set[str]] = {} # dependency graph - self.all_missing_resources: Dict[str, str] = {} # mapping of all missing resources imported + self.all_missing_resources: Dict[str, str] = {} # mapping of all missing resources imported self.missing_resources_queue: deque = deque() # queue for missing resources for resource_type in config.resources_arg: