ObjectApplyMatches: fetch allied host groups

fixes #2313
This commit is contained in:
Thomas Gelf 2021-04-14 09:03:35 +02:00
parent 9de28e7c79
commit cda5f56038
2 changed files with 21 additions and 4 deletions

View File

@ -16,6 +16,7 @@ next (will be 1.8.1)
* FIX: don't fail when showing a Host overriding multiple inherited groups (#2253)
* FIX: deal with inherited values which are invalid for a select box (#2288)
* FIX: Service Set preview inline Service Template links (#2334)
* FIX: show Services applied with Rules involving applied Hostgroups (#2313)
### Icinga Configuration
* FIX: rare race condition, where generated config might miss some files (#2351)

View File

@ -213,10 +213,26 @@ abstract class ObjectApplyMatches
protected function __construct(IcingaObject $object)
{
$this->object = $object;
$this->flatObject = $object->toPlainObject(true, false);
$flat = $object->toPlainObject(true, false);
// Sure, we are flat - but we might still want to match templates.
unset($this->flatObject->imports);
$this->flatObject->templates = $object->listFlatResolvedImportNames();
static::flattenVars($this->flatObject);
unset($flat->imports);
$flat->templates = $object->listFlatResolvedImportNames();
$this->addAppliedGroupsToFlatObject($flat, $object);
static::flattenVars($flat);
$this->flatObject = $flat;
}
protected function addAppliedGroupsToFlatObject($flat, IcingaObject $object)
{
if ($object instanceof IcingaHost) {
$appliedGroups = $object->getAppliedGroups();
if (! empty($appliedGroups)) {
if (isset($flat->groups)) {
$flat->groups = array_merge($flat->groups, $appliedGroups);
} else {
$flat->groups = $appliedGroups;
}
}
}
}
}