go.mondoo.com/cnquery@v0.0.0-20231005093811-59568235f6ea/providers/os/resources/smbios/smbios.go (about)

     1  // Copyright (c) Mondoo, Inc.
     2  // SPDX-License-Identifier: BUSL-1.1
     3  
     4  package smbios
     5  
     6  import (
     7  	"errors"
     8  
     9  	"go.mondoo.com/cnquery/providers-sdk/v1/inventory"
    10  	"go.mondoo.com/cnquery/providers/os/connection/shared"
    11  )
    12  
    13  type SmBiosInfo struct {
    14  	BIOS          BiosInfo
    15  	SysInfo       SysInfo
    16  	BaseBoardInfo BaseBoardInfo
    17  	ChassisInfo   ChassisInfo
    18  }
    19  
    20  type BiosInfo struct {
    21  	Vendor      string
    22  	Version     string
    23  	ReleaseDate string
    24  }
    25  
    26  type SysInfo struct {
    27  	Vendor       string
    28  	Model        string
    29  	Version      string
    30  	SerialNumber string
    31  	UUID         string
    32  	Familiy      string
    33  	SKU          string
    34  }
    35  
    36  type BaseBoardInfo struct {
    37  	Vendor       string
    38  	Model        string
    39  	Version      string
    40  	SerialNumber string
    41  	AssetTag     string
    42  }
    43  
    44  type ChassisInfo struct {
    45  	Vendor       string
    46  	Model        string
    47  	Version      string
    48  	SerialNumber string
    49  	AssetTag     string
    50  	Type         string
    51  }
    52  
    53  // https://en.wikipedia.org/wiki/System_Management_BIOS
    54  // https://www.dmtf.org/sites/default/files/standards/documents/DSP0134_3.4.0.pdf
    55  // There are also tools (https://github.com/digitalocean/go-smbios) out there to parse
    56  // the memory dump directly, but this would require to transfer large amount of data \
    57  // for remove access, therefore we restrict the data to what is exposed in /sys/class/dmi/id/
    58  type SmBiosManager interface {
    59  	Name() string
    60  	Info() (*SmBiosInfo, error)
    61  }
    62  
    63  func ResolveManager(conn shared.Connection, pf *inventory.Platform) (SmBiosManager, error) {
    64  	var biosM SmBiosManager
    65  
    66  	// check darwin before unix since darwin is also a unix
    67  	if pf.IsFamily("darwin") {
    68  		biosM = &OSXSmbiosManager{provider: conn, platform: pf}
    69  	} else if pf.IsFamily("linux") {
    70  		biosM = &LinuxSmbiosManager{provider: conn}
    71  	} else if pf.IsFamily("windows") {
    72  		biosM = &WindowsSmbiosManager{provider: conn}
    73  	}
    74  
    75  	if biosM == nil {
    76  		return nil, errors.New("could not detect suitable smbios manager for platform: " + pf.Name)
    77  	}
    78  
    79  	return biosM, nil
    80  }