get serial number on posix closes amidaware/tacticalrmm#1683

This commit is contained in:
wh1te909 2024-01-27 02:53:08 +00:00
parent 4a79b3dce3
commit ff9c271c76
2 changed files with 28 additions and 0 deletions

View File

@ -472,6 +472,30 @@ func (a *Agent) GetWMIInfo() map[string]interface{} {
} }
} }
switch runtime.GOOS {
case "linux":
baseboard, err := ghw.Baseboard()
if err != nil {
a.Logger.Debugln("ghw.Baseboard()", err)
wmiInfo["serialnumber"] = "n/a"
} else {
wmiInfo["serialnumber"] = baseboard.SerialNumber
}
case "darwin":
opts := a.NewCMDOpts()
serialCmd := `ioreg -l | grep IOPlatformSerialNumber | grep -o '"IOPlatformSerialNumber" = "[^"]*"' | awk -F'"' '{print $4}'`
opts.Command = serialCmd
out := a.CmdV2(opts)
if out.Status.Error != nil {
a.Logger.Debugln("ioreg get serial number: ", out.Status.Error.Error())
wmiInfo["serialnumber"] = "n/a"
} else {
wmiInfo["serialnumber"] = removeNewlines(out.Stdout)
}
default:
wmiInfo["serialnumber"] = "n/a"
}
if len(cpus) == 0 { if len(cpus) == 0 {
wmiInfo["cpus"] = []string{makeModel} wmiInfo["cpus"] = []string{makeModel}
} }

View File

@ -307,6 +307,10 @@ func removeWinNewLines(s string) string {
return strings.ReplaceAll(s, "\r\n", "\n") return strings.ReplaceAll(s, "\r\n", "\n")
} }
func removeNewlines(s string) string {
return strings.ReplaceAll(s, "\n", "")
}
func stringInSlice(a string, list []string) bool { func stringInSlice(a string, list []string) bool {
for _, b := range list { for _, b := range list {
if b == a { if b == a {