diff --git a/doc/82-Changelog.md b/doc/82-Changelog.md index bdecd8641..f2713683f 100644 --- a/doc/82-Changelog.md +++ b/doc/82-Changelog.md @@ -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) diff --git a/library/Director/Import/Sync.php b/library/Director/Import/Sync.php index 523dfbc83..37a690ef4 100644 --- a/library/Director/Import/Sync.php +++ b/library/Director/Import/Sync.php @@ -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; @@ -91,6 +92,12 @@ class Sync /** @var ?DbObjectStore */ protected $store; + /** @var IcingaObjectGroup[] */ + protected $modifiedGroups = []; + + /** @var IcingaObject[] */ + protected $modifiedGroupObjects = []; + /** * @param SyncRule $rule * @param ?DbObjectStore $store @@ -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); } @@ -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 @@ -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) {