ObjectApplyMatches: fetch allied host groups

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

View File

@ -20,6 +20,7 @@ next (will be 1.9.0)
### User Interface
* FIX: allow switching DB config while connection is failing (#2300)
* FIX: show Override button when all Fields belong to Field Categories (#2303)
* FIX: show Services applied with Rules involving applied Hostgroups (#2313)
* FEATURE: show "deprecated" flag on object attribute inspection (#2312)
next patch release (will be 1.8.1)

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;
}
}
}
}
}