mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-28 08:14:04 +02:00
legacy: Support service blacklisting
This commit is contained in:
parent
e2bd821d26
commit
67222ef437
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user