Refactor collectors

Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>
This commit is contained in:
Jan-Otto Kröpke
2023-11-04 20:51:35 +01:00
parent 569f5450cd
commit 0711268d3c
207 changed files with 15220 additions and 13648 deletions

44
pkg/winversion/main.go Normal file
View File

@@ -0,0 +1,44 @@
//go:build windows
package winversion
import (
"fmt"
"strconv"
"golang.org/x/sys/windows/registry"
)
var WindowsVersion string
var WindowsVersionFloat float64
func init() {
var err error
WindowsVersion, WindowsVersionFloat, err = GetWindowsVersion()
if err != nil {
panic(err)
}
}
// GetWindowsVersion reads the version number of the OS from the Registry
// See https://docs.microsoft.com/en-us/windows/desktop/sysinfo/operating-system-version
func GetWindowsVersion() (string, float64, error) {
reg, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows NT\CurrentVersion`, registry.QUERY_VALUE)
if err != nil {
return "", 0, fmt.Errorf("couldn't open registry: %w", err)
}
defer reg.Close()
windowsVersion, _, err := reg.GetStringValue("CurrentVersion")
if err != nil {
return "", 0, fmt.Errorf("couldn't open registry: %w", err)
}
windowsVersionFloat, err := strconv.ParseFloat(windowsVersion, 64)
if err != nil {
return "", 0, fmt.Errorf("couldn't open registry: %w", err)
}
return windowsVersion, windowsVersionFloat, nil
}