From 74025a12fceca169bea1419686a387d55a8280b1 Mon Sep 17 00:00:00 2001 From: Janez T Date: Tue, 10 Dec 2024 13:41:42 +0100 Subject: [PATCH] Refactor system device and serial retrieval to use sysfs instead of dmidecode --- shared/system.go | 13 +++++-------- team/report.go | 11 ++++------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/shared/system.go b/shared/system.go index 160ed48..f7d9aab 100644 --- a/shared/system.go +++ b/shared/system.go @@ -3,8 +3,8 @@ package shared import ( "fmt" "net" + "os" - "os/exec" "strings" "github.com/google/uuid" @@ -29,13 +29,12 @@ func SystemUUID() (string, error) { } func SystemDevice() (string, error) { - cmd := exec.Command("dmidecode", "-s", "system-product-name") - output, err := cmd.Output() + content, err := os.ReadFile("/sys/devices/virtual/dmi/id/product_name") if err != nil { return "", err } - deviceName := strings.TrimSpace(string(output)) + deviceName := strings.TrimSpace(string(content)) if deviceName == "" { return "", fmt.Errorf("unable to retrieve device name") } @@ -44,13 +43,11 @@ func SystemDevice() (string, error) { } func SystemSerial() (string, error) { - cmd := exec.Command("dmidecode", "-s", "system-serial-number") - output, err := cmd.Output() + content, err := os.ReadFile("/sys/devices/virtual/dmi/id/product_serial") if err != nil { return "", err } - - serialNumber := strings.TrimSpace(string(output)) + serialNumber := strings.TrimSpace(string(content)) if serialNumber == "" { return "", fmt.Errorf("unable to retrieve serial number") } diff --git a/team/report.go b/team/report.go index bce6375..4882215 100644 --- a/team/report.go +++ b/team/report.go @@ -4,7 +4,6 @@ import ( "context" "crypto/sha256" "encoding/hex" - "fmt" "net/http" "time" @@ -33,12 +32,10 @@ func CurrentReportingDevice() ReportingDevice { } return ReportingDevice{ - MachineUUID: device.UUID, - MachineName: device.Hostname, - Auth: DeviceAuth(), - LinuxOSVersion: func() string { - return fmt.Sprintf("%s-%s", device.OS, device.Kernel) - }(), + MachineUUID: device.UUID, + MachineName: device.Hostname, + Auth: DeviceAuth(), + LinuxOSVersion: device.OS, ModelName: func() string { modelName, err := shared.SystemDevice() if err != nil {