diff --git a/src/Inventory/Asset/VirtualMachine.php b/src/Inventory/Asset/VirtualMachine.php index 6915751df49..0a91ee7859f 100644 --- a/src/Inventory/Asset/VirtualMachine.php +++ b/src/Inventory/Asset/VirtualMachine.php @@ -306,13 +306,13 @@ protected function createVmComputer() if (property_exists($vm, 'uuid') && $vm->uuid != '') { $computers_vm_id = $this->getExistingVMAsComputer($vm); + $rule = new RuleImportAssetCollection(); + $rule->getCollectionPart(); + $input = (array)$vm; + $input['itemtype'] = \Computer::class; if ($computers_vm_id == 0) { //call rules on current collected data to find item //a callback on rulepassed() will be done if one is found. - $rule = new RuleImportAssetCollection(); - $rule->getCollectionPart(); - $input = (array)$vm; - $input['itemtype'] = \Computer::class; $input['states_id'] = $this->conf->states_id_default > 0 ? $this->conf->states_id_default : 0; $input['entities_id'] = $this->main_asset->getEntityID(); $input = Sanitizer::sanitize($input); @@ -329,12 +329,17 @@ protected function createVmComputer() } else { // Update computer $computervm->getFromDB($computers_vm_id); - $input = (array)$vm; $input['id'] = $computers_vm_id; if ($this->conf->states_id_default != '-1') { $input['states_id'] = $this->conf->states_id_default; } - $computervm->update(Sanitizer::sanitize($input)); + $datarules = $rule->processAllRules($input, [], ['class' => $input['itemtype'], 'return' => true]); + if (isset($datarules['_no_rule_matches']) && ($datarules['_no_rule_matches'] == '1') || isset($datarules['found_inventories'])) { + $computervm->update(Sanitizer::sanitize($input)); + } else { + //refused by rules + continue; + } } //load if new, reload if not.