Skip to content

Commit

Permalink
Sync: conditional membership sync
Browse files Browse the repository at this point in the history
fixes #2812
  • Loading branch information
Thomas-Gelf committed Oct 11, 2023
1 parent dcf03dc commit d02e430
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/82-Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ This version hasn't been released yet
* FEATURE: regular expression based modifier allows explicit NULL on no match (#2705)
* FEATURE: property modifiers can now be applied based on filters (#2756)
* FEATURE: CIDR notation (network ranges) is supported in such filters (#2757)
* FEATURE: trigger group membership resolution on group sync conditionally (#2812)
* FIX: synchronizing Service (and -Set) Templates has been fixed (#2745, #2217)
* FIX: null properties with Sync policy "ignore" are now being ignored (#2657)
* FIX: Import Source shows available columns for Core API Import (#2763)
Expand Down
20 changes: 20 additions & 0 deletions library/Director/Import/Sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Icinga\Module\Director\Objects\IcingaHost;
use Icinga\Module\Director\Objects\IcingaHostGroup;
use Icinga\Module\Director\Objects\IcingaObject;
use Icinga\Module\Director\Objects\IcingaObjectGroup;
use Icinga\Module\Director\Objects\ImportSource;
use Icinga\Module\Director\Objects\IcingaService;
use Icinga\Module\Director\Objects\SyncProperty;
Expand Down Expand Up @@ -91,6 +92,12 @@ class Sync
/** @var ?DbObjectStore */
protected $store;

/** @var IcingaObjectGroup[] */
protected $modifiedGroups = [];

/** @var IcingaObject[] */
protected $modifiedGroupObjects = [];

/**
* @param SyncRule $rule
* @param ?DbObjectStore $store
Expand Down Expand Up @@ -637,6 +644,9 @@ protected function setResolver($object)
protected function notifyResolvers()
{
if ($resolver = $this->getHostGroupMembershipResolver()) {
if ($this->rule->get('object_type') === 'hostgroup') {
$resolver->setGroups($this->modifiedGroups);
}
$resolver->refreshDb(true);
}

Expand Down Expand Up @@ -760,6 +770,13 @@ protected function processObject($key, $object)
}
}

protected function optionallyTellResolverAboutModifiedGroup(IcingaObjectGroup $group)
{
if (in_array('assign_filter', $group->getModifiedProperties())) {
$this->modifiedGroups[] = $group;
}
}

/**
* @param $key
* @param DbObject|IcingaObject $object
Expand Down Expand Up @@ -866,6 +883,9 @@ public function apply()
}

if ($object->hasBeenModified()) {
if ($object instanceof IcingaObjectGroup) {
$this->optionallyTellResolverAboutModifiedGroup($object);
}
$existing = $object->hasBeenLoadedFromDb();
if ($existing) {
if ($this->store) {
Expand Down

0 comments on commit d02e430

Please sign in to comment.