Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

962 B
Raw Blame
package unifiedresources

import "strings"

func normalizeComparableHostname(hostname string) string {
	host := strings.TrimSpace(strings.ToLower(hostname))
	host = strings.TrimSuffix(host, ".")
	if host == "" {
		return ""
	}
	if NormalizeIP(host) != "" {
		return ""
	}
	return host
}

// HostnamesEquivalent reports whether two hostnames refer to the same host
// when one side may use the short hostname and the other the fully-qualified
// hostname. Distinct fully-qualified hostnames remain distinct even when they
// share the same short name.
func HostnamesEquivalent(a, b string) bool {
	left := normalizeComparableHostname(a)
	right := normalizeComparableHostname(b)
	if left == "" || right == "" {
		return false
	}
	if left == right {
		return true
	}

	leftShort := NormalizeHostname(left)
	rightShort := NormalizeHostname(right)
	if leftShort == "" || leftShort != rightShort {
		return false
	}

	return left == leftShort || right == rightShort
}