mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-28 16:24:05 +02:00
legacy/IcingaService/ServiceSet: Improve apply rendering
This now renders one object per zone with a list of hosts.
This commit is contained in:
parent
f1dbeca77c
commit
d4d309a704
@ -1847,14 +1847,18 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
|||||||
/**
|
/**
|
||||||
* @codingStandardsIgnoreStart
|
* @codingStandardsIgnoreStart
|
||||||
*/
|
*/
|
||||||
protected function renderLegacyHost_id()
|
protected function renderLegacyHost_id($value)
|
||||||
{
|
{
|
||||||
|
if (is_array($value)) {
|
||||||
|
return c1::renderKeyValue('host_name', c1::renderArray($value));
|
||||||
|
} else {
|
||||||
return $this->renderLegacyRelationProperty(
|
return $this->renderLegacyRelationProperty(
|
||||||
'host',
|
'host',
|
||||||
$this->get('host_id'),
|
$this->get('host_id'),
|
||||||
'host_name'
|
'host_name'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display Name only exists for host/service in Icinga 1
|
* Display Name only exists for host/service in Icinga 1
|
||||||
@ -2365,6 +2369,8 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
|||||||
// @codingStandardsIgnoreEnd
|
// @codingStandardsIgnoreEnd
|
||||||
if ($this instanceof IcingaHostGroup) {
|
if ($this instanceof IcingaHostGroup) {
|
||||||
$c = " # resolved memberships are set via the individual object\n";
|
$c = " # resolved memberships are set via the individual object\n";
|
||||||
|
} elseif ($this instanceof IcingaService) {
|
||||||
|
$c = " # resolved objects are listed here\n";
|
||||||
} else {
|
} else {
|
||||||
$c = " # assign is not supported for " . $this->type . "\n";
|
$c = " # assign is not supported for " . $this->type . "\n";
|
||||||
}
|
}
|
||||||
@ -2947,6 +2953,27 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function mapHostsToZones($names)
|
||||||
|
{
|
||||||
|
$map = array();
|
||||||
|
|
||||||
|
foreach ($names as $hostname) {
|
||||||
|
/** @var IcingaHost $host */
|
||||||
|
$host = IcingaHost::load($hostname, $this->connection);
|
||||||
|
|
||||||
|
$zone = $host->getRenderingZone();
|
||||||
|
if (! array_key_exists($zone, $map)) {
|
||||||
|
$map[$zone] = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
$map[$zone][] = $hostname;
|
||||||
|
}
|
||||||
|
|
||||||
|
ksort($map);
|
||||||
|
|
||||||
|
return $map;
|
||||||
|
}
|
||||||
|
|
||||||
public function getUrlParams()
|
public function getUrlParams()
|
||||||
{
|
{
|
||||||
$params = array();
|
$params = array();
|
||||||
|
@ -198,7 +198,6 @@ class IcingaService extends IcingaObject
|
|||||||
public function renderHost_id()
|
public function renderHost_id()
|
||||||
{
|
{
|
||||||
// @codingStandardsIgnoreEnd
|
// @codingStandardsIgnoreEnd
|
||||||
|
|
||||||
if ($this->hasBeenAssignedToHostTemplate()) {
|
if ($this->hasBeenAssignedToHostTemplate()) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
@ -231,37 +230,16 @@ class IcingaService extends IcingaObject
|
|||||||
|
|
||||||
$assign_filter = $this->get('assign_filter');
|
$assign_filter = $this->get('assign_filter');
|
||||||
$filter = Filter::fromQueryString($assign_filter);
|
$filter = Filter::fromQueryString($assign_filter);
|
||||||
$hosts = HostApplyMatches::forFilter($filter, $conn);
|
$hostnames = HostApplyMatches::forFilter($filter, $conn);
|
||||||
|
|
||||||
$this->set('object_type', 'object');
|
$this->set('object_type', 'object');
|
||||||
$this->set('assign_filter', null);
|
|
||||||
|
|
||||||
foreach ($hosts as $hostname) {
|
foreach ($this->mapHostsToZones($hostnames) as $zone => $names) {
|
||||||
$file = $this->legacyHostnameServicesFile($hostname, $config);
|
$this->set('host_id', $names);
|
||||||
$this->set('host', $hostname);
|
|
||||||
$file->addLegacyObject($this);
|
$config->configFile('director/' . $zone . '/service_apply', '.cfg')
|
||||||
|
->addLegacyObject($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->set('host', null);
|
|
||||||
$this->set('object_type', 'apply');
|
|
||||||
$this->set('assign_filter', $assign_filter);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $hostname
|
|
||||||
* @param IcingaConfig $config
|
|
||||||
* @return \Icinga\Module\Director\IcingaConfig\IcingaConfigFile
|
|
||||||
* @throws \Icinga\Exception\NotFoundError
|
|
||||||
*/
|
|
||||||
protected function legacyHostnameServicesFile($hostname, IcingaConfig $config)
|
|
||||||
{
|
|
||||||
return $config->configFile(
|
|
||||||
sprintf(
|
|
||||||
'director/%s/service_apply',
|
|
||||||
IcingaHost::load($hostname, $this->getConnection())
|
|
||||||
->getRenderingZone($config)
|
|
||||||
),
|
|
||||||
'.cfg'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -273,10 +251,6 @@ class IcingaService extends IcingaObject
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->isApplyRule()) {
|
|
||||||
throw new InvalidArgumentException('Apply Services can not be rendered directly.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$str = parent::toLegacyConfigString();
|
$str = parent::toLegacyConfigString();
|
||||||
|
|
||||||
if (! $this->isDisabled()
|
if (! $this->isDisabled()
|
||||||
|
@ -223,47 +223,25 @@ class IcingaServiceSet extends IcingaObject
|
|||||||
// Delegating this to the service would look, but this way it's faster
|
// Delegating this to the service would look, but this way it's faster
|
||||||
if ($filter = $this->get('assign_filter')) {
|
if ($filter = $this->get('assign_filter')) {
|
||||||
$filter = Filter::fromQueryString($filter);
|
$filter = Filter::fromQueryString($filter);
|
||||||
$hosts = HostApplyMatches::forFilter($filter, $conn);
|
|
||||||
|
$hostnames = HostApplyMatches::forFilter($filter, $conn);
|
||||||
|
} else {
|
||||||
|
$hostnames = array($this->getRelated('host')->object_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($this->mapHostsToZones($hostnames) as $zone => $names) {
|
||||||
|
$file = $config->configFile('director/' . $zone . '/servicesets', '.cfg');
|
||||||
|
$file->addContent($this->getConfigHeaderComment($config));
|
||||||
|
|
||||||
foreach ($this->getServiceObjects() as $service) {
|
foreach ($this->getServiceObjects() as $service) {
|
||||||
$service->set('object_type', 'object');
|
$service->set('object_type', 'object');
|
||||||
|
$service->set('host_id', $names);
|
||||||
|
|
||||||
$this->copyVarsToService($service);
|
$this->copyVarsToService($service);
|
||||||
|
|
||||||
foreach ($hosts as $hostname) {
|
|
||||||
$file = $this->legacyHostnameServicesFile($hostname, $config);
|
|
||||||
$file->addContent($this->getConfigHeaderComment($config));
|
|
||||||
$service->set('host', $hostname);
|
|
||||||
$file->addLegacyObject($service);
|
$file->addLegacyObject($service);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
foreach ($this->getServiceObjects() as $service) {
|
|
||||||
$service->set('object_type', 'object');
|
|
||||||
$service->set('host_id', $this->get('host_id'));
|
|
||||||
foreach ($this->vars() as $k => $var) {
|
|
||||||
$service->$k = $var;
|
|
||||||
}
|
|
||||||
$file = $this->legacyRelatedHostFile($service, $config);
|
|
||||||
$file->addContent($this->getConfigHeaderComment($config));
|
|
||||||
$file->addLegacyObject($service);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function legacyHostnameServicesFile($hostname, IcingaConfig $config)
|
|
||||||
{
|
|
||||||
$host = IcingaHost::load($hostname, $this->getConnection());
|
|
||||||
return $config->configFile(
|
|
||||||
'director/' . $host->getRenderingZone($config) . '/servicesets',
|
|
||||||
'.cfg'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function legacyRelatedHostFile(IcingaService $service, IcingaConfig $config)
|
|
||||||
{
|
|
||||||
return $config->configFile(
|
|
||||||
'director/' . $service->getRelated('host')->getRenderingZone($config) . '/servicesets',
|
|
||||||
'.cfg'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRenderingZone(IcingaConfig $config = null)
|
public function getRenderingZone(IcingaConfig $config = null)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user