IcingaService: blacklisting on Host Templates...

...is now supported

fixes #1707
This commit is contained in:
Thomas Gelf 2019-02-15 00:08:23 +01:00
parent 32b71c922c
commit 7da91d747f
2 changed files with 21 additions and 4 deletions

View File

@ -21,6 +21,7 @@ before switching to a new version.
* FIX: Snapshots for Baskets with Dependencies are now possible (#1739)
* 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)
* FEATURE: Add TimePeriod support to Configuration Baskets (#1735)
* FEATURE: RO users could want to see where a configured service originated (#1785)

View File

@ -497,6 +497,7 @@ class IcingaService extends IcingaObject implements ExportInterface
/**
* @return string
* @throws \Icinga\Exception\NotFoundError
*/
protected function renderCustomExtensions()
{
@ -513,16 +514,31 @@ class IcingaService extends IcingaObject implements ExportInterface
}
$blacklist = $this->getBlacklistedHostnames();
if (! empty($blacklist)) {
if (count($blacklist) === 1) {
$blacklistedTemplates = [];
$blacklistedHosts = [];
foreach ($blacklist as $hostname) {
if (IcingaHost::load($hostname, $this->connection)->isTemplate()) {
$blacklistedTemplates[] = $hostname;
} else {
$blacklistedHosts[] = $hostname;
}
}
foreach ($blacklistedTemplates as $template) {
$output .= sprintf(
" ignore where %s in host.templates\n",
c::renderString($template)
);
}
if (! empty($blacklistedHosts)) {
if (count($blacklistedHosts) === 1) {
$output .= sprintf(
" ignore where host.name == %s\n",
c::renderString($blacklist[0])
c::renderString($blacklistedHosts[0])
);
} else {
$output .= sprintf(
" ignore where host.name in %s\n",
c::renderArray($blacklist)
c::renderArray($blacklistedHosts)
);
}
}