Skip to content

Commit

Permalink
Refactor system device and serial retrieval to use sysfs instead of d…
Browse files Browse the repository at this point in the history
…midecode
  • Loading branch information
dz0ny committed Dec 10, 2024
1 parent 17659f3 commit 74025a1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
13 changes: 5 additions & 8 deletions shared/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package shared
import (
"fmt"
"net"
"os"

"os/exec"
"strings"

"github.com/google/uuid"
Expand All @@ -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")
}
Expand All @@ -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")
}
Expand Down
11 changes: 4 additions & 7 deletions team/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"crypto/sha256"
"encoding/hex"
"fmt"
"net/http"
"time"

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 74025a1

Please sign in to comment.