def _cloud_function_resp_to_monitored_entities(page: Dict[Text, Any], svc_def: GCPService): """ Create CustomDevice instanace from google api response.""" items = page.get("items", []) if not items: return [] page_id = page.get("id", None) if page_id is None: return [] project_id = _extract_label(page_id, 1) zone_id = _extract_label(page_id, 2) mappings = { "resource.labels.instance_id": lambda x: x.get("id", ""), "resource.labels.zone": lambda x: zone_id, "resource.labels.project_id": lambda x: project_id, } entities = [] for cd in items: ips = [ interface.get("networkIP", "") for interface in cd.get("networkInterfaces", []) ] tags = cd.get("tags", {}).get("items", []) entities.append(Entity( id=get_func_create_entity_id(mappings)(cd, svc_def), display_name=cd.get("name", ""), group=svc_def.technology_name, ip_addresses=frozenset(ips), listen_ports=frozenset(), favicon_url="no-gcp-icon-available", dtype=svc_def.technology_name, properties=_get_properties(cd), tags=frozenset(tags), dns_names=frozenset() )) return entities
if (group_index < 0) or (group_index > 3): raise ValueError("Expected group_index <0,3>") match = export_labels_regex.match(gfun_name) if not match: raise ValueError("Filestore instance name should adhere to expected schema") return match.group(group_index) LabelToApiResponseMapping: LabelToApiRspMapping = { "resource.labels.project_id": lambda x: _extract_label(x.get("name", ""), 1), "resource.labels.location": lambda x: _extract_label(x.get("name", ""), 2), "resource.labels.instance_name": lambda x: _extract_label(x.get("name", ""), 3) } create_entity_id = get_func_create_entity_id(LabelToApiResponseMapping) def _get_properties(rsp: Dict[Text, Any]) -> Iterable[CdProperty]: """ Retrieve key properties to be passed onto dynatrace server. """ return [ CdProperty("State", rsp.get("state", "N/A")), CdProperty("Tier", rsp.get("tier", "N/A")) ] def _filestore_instance_resp_to_monitored_entities(page: Dict[Text, Any], svc_def: GCPService): """ Create CustomDevice instance from google api response.""" return [ Entity( id=create_entity_id(cd, svc_def),