From 041c2cd170d2583b3ee688f3d01c708eef81d503 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Otto=20Kr=C3=B6pke?= Date: Wed, 19 Mar 2025 22:50:54 +0100 Subject: [PATCH] fix: return Windows 11 as product name, if build number is >= 22000 (#1935) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jan-Otto Kröpke --- internal/collector/os/os.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/internal/collector/os/os.go b/internal/collector/os/os.go index c5cdbfe9..ddbca422 100644 --- a/internal/collector/os/os.go +++ b/internal/collector/os/os.go @@ -20,6 +20,7 @@ import ( "fmt" "log/slog" "strconv" + "strings" "time" "github.com/alecthomas/kingpin/v2" @@ -117,6 +118,11 @@ func (c *Collector) Build(logger *slog.Logger, _ *mi.Session) error { version := windows.RtlGetVersion() + // Microsoft has decided to keep the major version as "10" for Windows 11, including the product name. + if version.BuildNumber >= 22000 { + productName = strings.Replace(productName, " 10 ", " 11 ", 1) + } + c.osInformation = prometheus.NewDesc( prometheus.BuildFQName(types.Namespace, Name, "info"), `Contains full product name & version in labels. Note that the "major_version" for Windows 11 is \"10\"; a build number greater than 22000 represents Windows 11.`, @@ -371,5 +377,5 @@ func (c *Collector) getWindowsVersion() (string, string, error) { return "", "", err } - return productName, strconv.FormatUint(revision, 10), nil + return strings.TrimSpace(productName), strconv.FormatUint(revision, 10), nil }