Skip to content

A free open source IT asset/license management system

Added canonicalMarketingName and canonicalModelNumber to host record

snipeb5ceed92d952
diff --git a/app/SyncAdapters/HostInventoryRecord.php b/app/SyncAdapters/HostInventoryRecord.php
index 55bdcce919..987e09a0db 100644
--- a/app/SyncAdapters/HostInventoryRecord.php
+++ b/app/SyncAdapters/HostInventoryRecord.php
@@ -45,5 +45,12 @@ readonly class HostInventoryRecord
// device or the adapter doesn't emit group data.
public ?string $vendorGroupId = null,
public array $extra = [],
+ // Shared identity hints produced by AppleDB enrichment (null
+ // for non-Apple adapters and whenever enrichment is off).
+ // Each Apple-capable adapter populates these during normalize()
+ // via the UsesAppleDbEnrichment trait's canonicalIdentityFor
+ // helper when the per-instance toggle is on.
+ public ?string $canonicalMarketingName = null,
+ public ?string $canonicalModelNumber = null,
) {}
}
diff --git a/app/SyncAdapters/SyncsHostFromRecord.php b/app/SyncAdapters/SyncsHostFromRecord.php
index 6b1a31bd97..673fec1e49 100644
--- a/app/SyncAdapters/SyncsHostFromRecord.php
+++ b/app/SyncAdapters/SyncsHostFromRecord.php
@@ -1119,6 +1119,39 @@ trait SyncsHostFromRecord
private static function resolveModelIdByName(string $modelName, ?SyncAdapterInstance $instance = null, ?HostInventoryRecord $record = null): int
{
+ $canonicalModelNumber = $record?->canonicalModelNumber;
+ $canonicalMarketingName = $record?->canonicalMarketingName;
+
+ // When AppleDB enrichment updated
+ // canonical values on the model record, consolidate rows across
+ // adapters that emit the same hardware under different
+ // vendor name strings (e.g. ABM's long marketing name vs.
+ // Fleet's short osquery name for the same productType).
+ // Primary clause finds-by-name-and-number. Fallback clause
+ // picks up rows a prior sync named differently but tagged
+ // with the same canonical marketing name.
+ if ($canonicalModelNumber !== null) {
+ $query = AssetModel::query()
+ ->where('model_number', $canonicalModelNumber)
+ ->where(function ($q) use ($modelName, $canonicalMarketingName) {
+ $q->where('name', $modelName);
+ if ($canonicalMarketingName !== null) {
+ $q->orWhere('mfg_marketing_name', $canonicalMarketingName);
+ }
+ });
+
+ $model = $query->first();
+ if ($model !== null) {
+ $perRecordId = self::perRecordCategoryId($instance, $record);
+ if ($perRecordId !== null && $model->category_id !== $perRecordId) {
+ $model->category_id = $perRecordId;
+ $model->save();
+ }
+
+ return $model->id;
+ }
+ }
+
$model = AssetModel::where('name', $modelName)->first();
if ($model !== null) {
// Re-sync the category ONLY when the adapter has a
@@ -1141,6 +1174,12 @@ trait SyncsHostFromRecord
$model->name = $modelName;
$model->category_id = self::categoryIdFor($instance, $record);
$model->manufacturer_id = self::manufacturerIdFor($record);
+ if ($canonicalModelNumber !== null) {
+ $model->model_number = $canonicalModelNumber;
+ }
+ if ($canonicalMarketingName !== null) {
+ $model->mfg_marketing_name = $canonicalMarketingName;
+ }
$adapter = $instance?->adapter();
if ($adapter instanceof SyncAdapter) {
$model->fieldset_id = $adapter->defaultFieldsetId();