diff --git a/doc/82-Changelog.md b/doc/82-Changelog.md index 8eea7b27..15589e57 100644 --- a/doc/82-Changelog.md +++ b/doc/82-Changelog.md @@ -22,6 +22,7 @@ before switching to a new version. * FIX: Commands snapshots now carry fields in your Basket (#1747) * FIX: Cloning services from one Set to another one no longer fails (#1758) * FIX: Blacklisting a Service from a Set on a Host Template is now possible (#1707) +* FIX: Services from a Set assigned to a single Host can be blacklisted (#1616) * FEATURE: Add TimePeriod support to Configuration Baskets (#1735) * FEATURE: RO users could want to see where a configured service originated (#1785) diff --git a/library/Director/Objects/IcingaServiceSet.php b/library/Director/Objects/IcingaServiceSet.php index d8f3793b..ddc1d6c0 100644 --- a/library/Director/Objects/IcingaServiceSet.php +++ b/library/Director/Objects/IcingaServiceSet.php @@ -5,9 +5,11 @@ namespace Icinga\Module\Director\Objects; use Exception; use Icinga\Data\Filter\Filter; use Icinga\Module\Director\Db; +use Icinga\Module\Director\Db\Cache\PrefetchCache; use Icinga\Module\Director\DirectorObject\Automation\ExportInterface; use Icinga\Module\Director\Exception\DuplicateKeyException; use Icinga\Module\Director\IcingaConfig\IcingaConfig; +use Icinga\Module\Director\Resolver\HostServiceBlacklist; use InvalidArgumentException; use RuntimeException; @@ -289,8 +291,10 @@ class IcingaServiceSet extends IcingaObject implements ExportInterface $service->set('object_type', 'apply'); $service->set('assign_filter', $filter); } elseif ($hostId = $this->get('host_id')) { - $service->set('object_type', 'object'); - $service->set('use_var_overrides', 'y'); + $host = $this->getRelatedObject('host', $hostId)->getObjectName(); + if (in_array($host, $this->getBlacklistedHostnames($service))) { + continue; + } $service->set('host_id', $this->get('host_id')); } else { // Service set template without assign filter or host @@ -302,6 +306,23 @@ class IcingaServiceSet extends IcingaObject implements ExportInterface } } + /** + * @return array + */ + public function getBlacklistedHostnames($service) + { + // Hint: if ($this->isApplyRule()) would be nice, but apply rules are + // not enough, one might want to blacklist single services from Sets + // assigned to single Hosts. + if (PrefetchCache::shouldBeUsed()) { + $lookup = PrefetchCache::instance()->hostServiceBlacklist(); + } else { + $lookup = new HostServiceBlacklist($this->getConnection()); + } + + return $lookup->getBlacklistedHostnamesForService($service); + } + protected function getConfigFileWithHeader(IcingaConfig $config) { $file = $config->configFile(