Skip to content

Commit bea3691

Browse files
committed
⭐️ use macOS computer name as asset name
1 parent 384d22e commit bea3691

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

providers/os/provider/detector.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"go.mondoo.com/cnquery/v12/providers/os/id/ids"
1818
"go.mondoo.com/cnquery/v12/providers/os/id/machineid"
1919
"go.mondoo.com/cnquery/v12/providers/os/id/sshhostkey"
20+
"go.mondoo.com/cnquery/v12/providers/os/resources/plist"
2021
)
2122

2223
// default id detectors
@@ -52,6 +53,7 @@ func (s *Service) detect(asset *inventory.Asset, conn shared.Connection) error {
5253
return errors.New("failed to detect OS")
5354
}
5455
asset.MergePlatform(pf)
56+
5557
if asset.Platform.Kind == "" {
5658
asset.Platform.Kind = inventory.AssetKindBaremetal
5759
}
@@ -148,3 +150,19 @@ func appendRelatedAssetsFromFingerprint(f *id.PlatformFingerprint, a *inventory.
148150
}
149151
}
150152
}
153+
154+
func (s *Service) assetName(asset *inventory.Asset, conn shared.Connection) {
155+
// for macOS we want to use the computer name, therefore we detect the computer name
156+
if asset.Platform.Name == "macos" {
157+
// run command to get computer name and use it as asset name
158+
f, err := conn.FileSystem().Open("/Library/Preferences/SystemConfiguration/preferences.plist")
159+
if err == nil {
160+
data, err := plist.Decode(f)
161+
if err == nil {
162+
if computerName, ok := data.GetString("System", "System", "ComputerName"); ok {
163+
asset.Name = computerName
164+
}
165+
}
166+
}
167+
}
168+
}

providers/os/provider/provider.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,9 @@ func (s *Service) Connect(req *plugin.ConnectReq, callback plugin.ProviderCallba
305305
}
306306
}
307307

308+
// for some assets we need to do additional asset name detection, eg. macOS
309+
s.assetName(req.Asset, conn)
310+
308311
log.Debug().Str("asset", req.Asset.Name).Msg("detected asset")
309312

310313
var inv *inventory.Inventory

0 commit comments

Comments
 (0)