diff --git a/library/Director/Objects/IcingaService.php b/library/Director/Objects/IcingaService.php index f3cedbc3..3d5dabb5 100644 --- a/library/Director/Objects/IcingaService.php +++ b/library/Director/Objects/IcingaService.php @@ -197,7 +197,6 @@ class IcingaService extends IcingaObject */ public function renderHost_id() { - // @codingStandardsIgnoreEnd if ($this->hasBeenAssignedToHostTemplate()) { return ''; } @@ -205,6 +204,28 @@ class IcingaService extends IcingaObject return $this->renderRelationProperty('host', $this->get('host_id'), 'host_name'); } + /** + * @codingStandardsIgnoreStart + */ + protected function renderLegacyHost_id($value) + { + // @codingStandardsIgnoreEnd + if (is_array($value)) { + $blacklisted = $this->getBlacklistedHostnames(); + $c = c1::renderKeyValue('host_name', c1::renderArray(array_diff($value, $blacklisted))); + + // blacklisted in this (zoned) scope? + $bl = array_intersect($blacklisted, $value); + if (! empty($bl)) { + $c .= c1::renderKeyValue('# ignored on', c1::renderArray($bl)); + } + + return $c; + } else { + return parent::renderLegacyHost_id($value); + } + } + /** * @param IcingaConfig $config * @throws IcingaException @@ -237,6 +258,12 @@ class IcingaService extends IcingaObject foreach ($this->mapHostsToZones($hostnames) as $zone => $names) { $this->set('host_id', $names); + $blacklisted = $this->getBlacklistedHostnames(); + $zoneNames = array_diff($names, $blacklisted); + if (empty($zoneNames)) { + continue; + } + $config->configFile('director/' . $zone . '/service_apply', '.cfg') ->addLegacyObject($this); } diff --git a/library/Director/Objects/IcingaServiceSet.php b/library/Director/Objects/IcingaServiceSet.php index e4336197..706f496a 100644 --- a/library/Director/Objects/IcingaServiceSet.php +++ b/library/Director/Objects/IcingaServiceSet.php @@ -230,11 +230,25 @@ class IcingaServiceSet extends IcingaObject $hostnames = array($this->getRelated('host')->object_name); } + $blacklists = []; + foreach ($this->mapHostsToZones($hostnames) as $zone => $names) { $file = $config->configFile('director/' . $zone . '/servicesets', '.cfg'); $file->addContent($this->getConfigHeaderComment($config)); foreach ($this->getServiceObjects() as $service) { + $object_name = $service->object_name; + + if (! array_key_exists($object_name, $blacklists)) { + $blacklists[$object_name] = $service->getBlacklistedHostnames(); + } + + // check if all hosts in the zone ignore this service + $zoneNames = array_diff($names, $blacklists[$object_name]); + if (empty($zoneNames)) { + continue; + } + $service->set('object_type', 'object'); $service->set('host_id', $names);