Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Do not update VM Computer asset if denied by rules #18940

Open
wants to merge 5 commits into
base: 10.0/bugfixes
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/Inventory/Asset/VirtualMachine.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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.
Expand Down