posture: ignore not found serial errors

This commit is contained in:
Kristoffer Dalby 2023-11-13 13:45:52 +00:00
parent 86c8ab7502
commit b2d11995c9

View File

@ -8,7 +8,6 @@
package posture
import (
"errors"
"fmt"
"strings"
@ -31,17 +30,17 @@ func getByteFromSmbiosStructure(s *smbios.Structure, specOffset int) uint8 {
// getStringFromSmbiosStructure retrieves a string at the given specOffset.
// Returns an empty string if no string was present.
func getStringFromSmbiosStructure(s *smbios.Structure, specOffset int) (string, error) {
func getStringFromSmbiosStructure(s *smbios.Structure, specOffset int) string {
index := getByteFromSmbiosStructure(s, specOffset)
if index == 0 || int(index) > len(s.Strings) {
return "", errors.New("specified offset does not exist in smbios structure")
return ""
}
str := s.Strings[index-1]
trimmed := strings.TrimSpace(str)
return trimmed, nil
return trimmed
}
// Product Table (Type 1) structure
@ -71,7 +70,6 @@ func init() {
validTables = append(validTables, table)
}
numOfTables = len(validTables)
}
// serialFromSmbiosStructure extracts a serial number from a product,
@ -86,14 +84,7 @@ func serialFromSmbiosStructure(s *smbios.Structure) (string, error) {
)
}
serial, err := getStringFromSmbiosStructure(s, serialNumberOffset)
if err != nil {
return "", fmt.Errorf(
"failed to get serial from %s table: %w",
idToTableName[int(s.Header.Type)],
err,
)
}
serial := getStringFromSmbiosStructure(s, serialNumberOffset)
return serial, nil
}
@ -125,9 +116,11 @@ func GetSerialNumbers(logf logger.Logf) ([]string, error) {
continue
}
if serial != "" {
serials = append(serials, serial)
}
}
}
err = multierr.New(errs...)