github.com/jaypipes/ghw@v0.21.1/pkg/chassis/chassis_windows.go (about)

     1  // Use and distribution licensed under the Apache license version 2.
     2  //
     3  // See the COPYING file in the root project directory for full text.
     4  //
     5  
     6  package chassis
     7  
     8  import (
     9  	"github.com/yusufpapurcu/wmi"
    10  
    11  	"github.com/jaypipes/ghw/pkg/util"
    12  )
    13  
    14  const wqlChassis = "SELECT Caption, Description, Name, Manufacturer, Model, SerialNumber, Tag, TypeDescriptions, Version FROM CIM_Chassis"
    15  
    16  type win32Chassis struct {
    17  	Caption          *string
    18  	Description      *string
    19  	Name             *string
    20  	Manufacturer     *string
    21  	Model            *string
    22  	SerialNumber     *string
    23  	Tag              *string
    24  	TypeDescriptions []string
    25  	Version          *string
    26  }
    27  
    28  func (i *Info) load() error {
    29  	// Getting data from WMI
    30  	var win32ChassisDescriptions []win32Chassis
    31  	if err := wmi.Query(wqlChassis, &win32ChassisDescriptions); err != nil {
    32  		return err
    33  	}
    34  	if len(win32ChassisDescriptions) > 0 {
    35  		i.AssetTag = *win32ChassisDescriptions[0].Tag
    36  		i.SerialNumber = *win32ChassisDescriptions[0].SerialNumber
    37  		i.Type = util.UNKNOWN // TODO:
    38  		i.TypeDescription = *win32ChassisDescriptions[0].Model
    39  		i.Vendor = *win32ChassisDescriptions[0].Manufacturer
    40  		i.Version = *win32ChassisDescriptions[0].Version
    41  	}
    42  	return nil
    43  }