IcingaServiceSet: skip Service on single host...

...when blacklisted

fixes #1616
This commit is contained in:
Thomas Gelf 2019-02-15 00:48:05 +01:00
parent 7da91d747f
commit 85ed54f932
2 changed files with 24 additions and 2 deletions

View File

@ -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)

View File

@ -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(