@@ -237,10 +237,12 @@ def _process_vm(self, vm: dict, vm_stats_dict: dict[str, list[dict]], cluster_na
237237 if not self ._should_collect_vm (vm ):
238238 return False
239239
240+ display_hostname = self ._transform_hostname (vm_name )
241+
240242 vm_tags = self .check .base_tags + self ._extract_vm_tags (vm )
241- self ._set_external_tags_for_host (vm_name , vm_tags )
242- self ._report_vm_basic_metrics (vm , vm_name , vm_tags )
243- self ._report_vm_stats (vm_id , vm_name , vm_tags , vm_stats_dict , cluster_name )
243+ self ._set_external_tags_for_host (display_hostname , vm_tags )
244+ self ._report_vm_basic_metrics (vm , display_hostname , vm_tags )
245+ self ._report_vm_stats (vm_id , display_hostname , vm_tags , vm_stats_dict , cluster_name )
244246 return True
245247
246248 def _report_vm_basic_metrics (self , vm : dict , vm_name : str , vm_tags : list [str ]) -> None :
@@ -435,11 +437,13 @@ def _process_single_host(
435437 self .host_count += 1
436438 self .host_names [host_id ] = host_name
437439
440+ display_hostname = self ._transform_hostname (host_name )
441+
438442 host_tags = cluster_tags + self ._extract_host_tags (host )
439- self .check .gauge ("host.count" , 1 , hostname = host_name , tags = host_tags )
440- self ._report_host_status_metrics (host , host_name , host_tags )
441- self ._set_external_tags_for_host (host_name , host_tags )
442- self ._report_host_capacity_metrics (host , host_name , host_tags )
443+ self .check .gauge ("host.count" , 1 , hostname = display_hostname , tags = host_tags )
444+ self ._report_host_status_metrics (host , display_hostname , host_tags )
445+ self ._set_external_tags_for_host (display_hostname , host_tags )
446+ self ._report_host_capacity_metrics (host , display_hostname , host_tags )
443447
444448 try :
445449 stats = self ._get_stats (f"api/clustermgmt/v4.0/stats/clusters/{ cluster_id } /hosts/{ host_id } " )
@@ -449,12 +453,12 @@ def _process_single_host(
449453 stats ,
450454 HOST_STATS_METRICS ,
451455 host_tags ,
452- hostname = host_name ,
456+ hostname = display_hostname ,
453457 extra_tags_by_key = self ._get_disk_status_storage_tags (host_id ),
454458 )
455459 except Exception :
456460 self .check .log .exception (
457- "[%s][%s] Failed to fetch stats for host %s" , self ._pc_label , cluster_name , host_name
461+ "[%s][%s] Failed to fetch stats for host %s" , self ._pc_label , cluster_name , display_hostname
458462 )
459463
460464 host_label = host_name or host_id
@@ -573,6 +577,17 @@ def _set_external_tags_for_host(self, hostname: str, tags: list[str]) -> None:
573577
574578 self .external_tags .append ((hostname , {self .check .__NAMESPACE__ : tags }))
575579
580+ def _transform_hostname (self , hostname : str | None ) -> str | None :
581+ """Apply hostname_transform config to a hostname."""
582+ if not hostname :
583+ return hostname
584+ transform = self .check .config .hostname_transform
585+ if transform == 'upper' :
586+ return hostname .upper ()
587+ if transform == 'lower' :
588+ return hostname .lower ()
589+ return hostname
590+
576591 def _should_collect_vm (self , vm : dict ) -> bool :
577592 """Check if a VM should be collected based on power state and resource filters."""
578593 has_power_state_filter = any (
0 commit comments