@@ -101,6 +101,7 @@ type ConnectionInfo struct {
101101 IP string
102102 Hostname string
103103 TLS bool
104+ FQDN string
104105}
105106
106107// GetLogger returns a logger object with a prefix of "conroller.name" and aditional controller context fields
@@ -646,8 +647,8 @@ func getNodeExporterTargets(nodes []ConnectionInfo) ([]metricstorage.LabeledTarg
646647 nonTLS := []metricstorage.LabeledTarget {}
647648 for _ , node := range nodes {
648649 target := metricstorage.LabeledTarget {
649- IP : fmt .Sprintf ("%s:%d" , node .IP , telemetryv1 .DefaultNodeExporterPort ),
650- Hostname : node .Hostname ,
650+ IP : fmt .Sprintf ("%s:%d" , node .IP , telemetryv1 .DefaultNodeExporterPort ),
651+ FQDN : node .FQDN ,
651652 }
652653 if node .TLS {
653654 tls = append (tls , target )
@@ -885,17 +886,22 @@ func getComputeNodesConnectionInfo(
885886 // we were unable to find an IP or HostName for a node, so we do not go further
886887 return connectionInfo , fmt .Errorf ("failed to find an IP or HostName for node %s" , name )
887888 }
889+
890+ fqdn , _ := getCanonicalHostname (& item )
891+
888892 if TLSEnabled , ok := nodeSetGroup .Vars ["edpm_tls_certs_enabled" ].(bool ); ok && TLSEnabled {
889893 connectionInfo = append (connectionInfo , ConnectionInfo {
890894 IP : address ,
891895 Hostname : name ,
892896 TLS : true ,
897+ FQDN : fqdn ,
893898 })
894899 } else {
895900 connectionInfo = append (connectionInfo , ConnectionInfo {
896901 IP : address ,
897902 Hostname : name ,
898903 TLS : false ,
904+ FQDN : fqdn ,
899905 })
900906 }
901907 }
@@ -974,6 +980,16 @@ func getAddressFromAnsibleHost(item *ansible.Host) (string, discoveryv1.AddressT
974980 return "" , ""
975981}
976982
983+ func getCanonicalHostname (item * ansible.Host ) (string , discoveryv1.AddressType ) {
984+ canonicalHostname := item .Vars ["canonical_hostname" ].(string )
985+ // is it a valid hostname?
986+ if isValidDomain (canonicalHostname ) {
987+ // it is an valid domain name
988+ return canonicalHostname , discoveryv1 .AddressTypeFQDN
989+ }
990+ return "" , ""
991+ }
992+
977993// isValidDomain returns true if the domain is valid.
978994func isValidDomain (domain string ) bool {
979995 domainRegexp := regexp .MustCompile (`^(?i)[a-z0-9-]+(\.[a-z0-9-]+)+\.?$` )
0 commit comments