def collect_topology(self, response, component_type): """ Process each component type and map those with specific data :param response: Response of each component type endpoint :param component_type: Component type :return: create the component on stackstate API """ if "error" in response: raise DynatraceError(response["error"].get("message"), response["error"].get("code"), component_type) for item in response: item = self.clean_unsupported_metadata(item) data = dict() external_id = item["entityId"] identifiers = [ Identifiers.create_custom_identifier("dynatrace", external_id) ] if component_type == "host": host_identifiers = self.get_host_identifiers(item) identifiers.extend(host_identifiers) # derive useful labels and get labels from dynatrace tags labels = self.get_labels(item) data.update(item) self.filter_item_topology_data(data) data.update({ "identifiers": identifiers, "tags": self.tags, "domain": self.domain, "environment": self.environment, "instance": self.url, "labels": labels }) self.component(external_id, component_type, data) self.collect_relations(item, external_id)
def process_host_topology(self, topology_instance, zabbix_host, stackstate_environment): external_id = "urn:host:/%s" % zabbix_host.host identifiers = list() identifiers.append(Identifiers.create_host_identifier(zabbix_host.host)) identifiers.append(zabbix_host.host) url = topology_instance.get('url') if 'http' in url or 'https' in url: instance_url = url.split("//")[1].split("/")[0] else: instance_url = url.split("/")[0] labels = ['zabbix', 'instance_url:%s' % instance_url] for host_group in zabbix_host.host_groups: labels.append('host group:%s' % host_group.name) data = { 'name': zabbix_host.name, 'host_id': zabbix_host.host_id, 'host': zabbix_host.host, 'layer': 'machines', # use host group of component as StackState domain when there is only one host group 'domain': zabbix_host.host_groups[0].name if len(zabbix_host.host_groups) == 1 else 'Zabbix', 'identifiers': identifiers, 'environment': stackstate_environment, 'host_groups': [host_group.name for host_group in zabbix_host.host_groups], 'labels': labels, 'tags': zabbix_host.tags, 'instance': instance_url } self.component(external_id, "zabbix_host", data=data)
def process_custom_device_identifiers(custom_device): """ Process identifiers for custom devices based on ip address and dns names @param custom_device: Custom Device element from Dynatrace @return Return the set of identifiers """ properties = custom_device.get("properties") identifiers = [] if properties: for dns in properties.get('dnsNames', []): identifiers.append(Identifiers.create_host_identifier(dns)) for ip in properties.get('ipAddress', []): identifiers.append(Identifiers.create_host_identifier(ip)) return identifiers
def get_host_identifiers(self, component): host_identifiers = [] if component.get("esxiHostName"): host_identifiers.append( Identifiers.create_host_identifier( component.get("esxiHostName"))) if component.get("oneAgentCustomHostName"): host_identifiers.append( Identifiers.create_host_identifier( component.get("oneAgentCustomHostName"))) if component.get("azureHostNames"): host_identifiers.append( Identifiers.create_host_identifier( component.get("azureHostNames"))) if component.get("publicHostName"): host_identifiers.append( Identifiers.create_host_identifier( component.get("publicHostName"))) if component.get("localHostName"): host_identifiers.append( Identifiers.create_host_identifier( component.get("localHostName"))) host_identifiers.append( Identifiers.create_host_identifier(component.get("displayName"))) host_identifiers = Identifiers.append_lowercase_identifiers( host_identifiers) return host_identifiers
def _collect_topology(self, response, component_type, instance_info): """ Process each component type and map those with specific data :param response: Response of each component type endpoint :param component_type: Component type :param instance_info: instance configuration :return: create the component on stackstate API """ for item in response: item = self._clean_unsupported_metadata(item) if component_type == "custom-device": dynatrace_component = CustomDevice(item, strict=False) dynatrace_component.validate() else: dynatrace_component = DynatraceComponent(item, strict=False) dynatrace_component.validate() data = {} external_id = dynatrace_component.entityId identifiers = [ Identifiers.create_custom_identifier("dynatrace", external_id) ] self.dynatrace_entities_cache.append( DynatraceCachedEntity(identifiers[0], external_id, dynatrace_component.displayName, component_type)) if component_type == "host": host_identifiers = self._get_host_identifiers( dynatrace_component) identifiers.extend(host_identifiers) if component_type == "custom-device": custom_device_identifiers = self.process_custom_device_identifiers( item) identifiers.extend(custom_device_identifiers) # derive useful labels from dynatrace tags tags = self._get_labels(dynatrace_component) tags.extend(instance_info.instance_tags) data.update(item) self._filter_item_topology_data(data) data.update({ "identifiers": identifiers, "tags": tags, "domain": instance_info.domain, "environments": [instance_info.environment], "instance": instance_info.url, }) self.component(external_id, component_type, data) self._collect_relations(dynatrace_component, external_id, component_type)
def _get_host_identifiers(component): host_identifiers = [] if component.esxiHostName: host_identifiers.append( Identifiers.create_host_identifier(component.esxiHostName)) if component.oneAgentCustomHostName: host_identifiers.append( Identifiers.create_host_identifier( component.oneAgentCustomHostName)) if component.azureHostNames: host_identifiers.append( Identifiers.create_host_identifier(component.azureHostNames)) if component.publicHostName: host_identifiers.append( Identifiers.create_host_identifier(component.publicHostName)) if component.localHostName: host_identifiers.append( Identifiers.create_host_identifier(component.localHostName)) host_identifiers.append( Identifiers.create_host_identifier(component.displayName)) host_identifiers = Identifiers.append_lowercase_identifiers( host_identifiers) return host_identifiers