-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
![image](https://github.com/mondoohq/cnquery/assets/1307529/24bef902-b2a0-4ccb-80f4-0d21786a0008) Signed-off-by: Dominik Richter <[email protected]>
- Loading branch information
Showing
2 changed files
with
130 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
// Copyright (c) Mondoo, Inc. | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
package resources | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/cockroachdb/errors" | ||
"go.mondoo.com/cnquery/llx" | ||
"go.mondoo.com/cnquery/providers-sdk/v1/plugin" | ||
"go.mondoo.com/cnquery/providers/os/connection/shared" | ||
"go.mondoo.com/cnquery/providers/os/resources/smbios" | ||
) | ||
|
||
type mqlMachineInternal struct { | ||
smbiosInfo plugin.TValue[*smbios.SmBiosInfo] | ||
} | ||
|
||
func getbiosinfo(runtime *plugin.Runtime) (*smbios.SmBiosInfo, error) { | ||
obj, err := CreateResource(runtime, "machine", map[string]*llx.RawData{}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
machine := obj.(*mqlMachine) | ||
|
||
if machine.smbiosInfo.State&plugin.StateIsSet != 0 { | ||
return machine.smbiosInfo.Data, machine.smbiosInfo.Error | ||
} | ||
|
||
conn := runtime.Connection.(shared.Connection) | ||
pf := conn.Asset().Platform | ||
pm, err := smbios.ResolveManager(conn, pf) | ||
if pm == nil || err != nil { | ||
return nil, fmt.Errorf("could not detect suitable smbios manager for platform") | ||
} | ||
|
||
// retrieve smbios info | ||
biosInfo, err := pm.Info() | ||
if err != nil || biosInfo == nil { | ||
if err == nil { | ||
err = errors.New("could not retrieve smbios info") | ||
} | ||
machine.smbiosInfo = plugin.TValue[*smbios.SmBiosInfo]{Error: err, State: plugin.StateIsSet} | ||
return nil, errors.Wrap(err, "could not retrieve smbios info for platform") | ||
} | ||
|
||
machine.smbiosInfo = plugin.TValue[*smbios.SmBiosInfo]{Data: biosInfo, State: plugin.StateIsSet} | ||
return machine.smbiosInfo.Data, machine.smbiosInfo.Error | ||
} | ||
|
||
func initMachineBios(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) { | ||
if len(args) > 2 { | ||
return args, nil, nil | ||
} | ||
|
||
biosInfo, err := getbiosinfo(runtime) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
return map[string]*llx.RawData{ | ||
"vendor": llx.StringData(biosInfo.BIOS.Vendor), | ||
"version": llx.StringData(biosInfo.BIOS.Version), | ||
"releaseDate": llx.StringData(biosInfo.BIOS.ReleaseDate), | ||
}, nil, nil | ||
} | ||
|
||
func initMachineSystem(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) { | ||
if len(args) > 2 { | ||
return args, nil, nil | ||
} | ||
|
||
biosInfo, err := getbiosinfo(runtime) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
return map[string]*llx.RawData{ | ||
"manufacturer": llx.StringData(biosInfo.SysInfo.Vendor), | ||
"product": llx.StringData(biosInfo.SysInfo.Model), | ||
"version": llx.StringData(biosInfo.SysInfo.Version), | ||
"serial": llx.StringData(biosInfo.SysInfo.SerialNumber), | ||
"uuid": llx.StringData(biosInfo.SysInfo.UUID), | ||
"sku": llx.StringData(biosInfo.SysInfo.SKU), | ||
"family": llx.StringData(biosInfo.SysInfo.Familiy), | ||
}, nil, nil | ||
} | ||
|
||
func initMachineBaseboard(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) { | ||
if len(args) > 2 { | ||
return args, nil, nil | ||
} | ||
|
||
biosInfo, err := getbiosinfo(runtime) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
return map[string]*llx.RawData{ | ||
"manufacturer": llx.StringData(biosInfo.BaseBoardInfo.Vendor), | ||
"product": llx.StringData(biosInfo.BaseBoardInfo.Model), | ||
"version": llx.StringData(biosInfo.BaseBoardInfo.Version), | ||
"serial": llx.StringData(biosInfo.BaseBoardInfo.SerialNumber), | ||
"assetTag": llx.StringData(biosInfo.BaseBoardInfo.AssetTag), | ||
}, nil, nil | ||
} | ||
|
||
func initMachineChassis(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) { | ||
if len(args) > 2 { | ||
return args, nil, nil | ||
} | ||
|
||
biosInfo, err := getbiosinfo(runtime) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
return map[string]*llx.RawData{ | ||
"manufacturer": llx.StringData(biosInfo.ChassisInfo.Vendor), | ||
"version": llx.StringData(biosInfo.ChassisInfo.Version), | ||
"serial": llx.StringData(biosInfo.ChassisInfo.SerialNumber), | ||
"assetTag": llx.StringData(biosInfo.ChassisInfo.AssetTag), | ||
}, nil, nil | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.