IcingaServiceSet: implement target zone for...

...resolved v1 apply rules
This commit is contained in:
Thomas Gelf 2016-11-07 12:42:27 +01:00
parent 2c1f745c4e
commit 7e749da982
2 changed files with 35 additions and 7 deletions

View File

@ -45,6 +45,17 @@ class IcingaConfigFile
return $this;
}
public function addContent($content)
{
if ($this->content === null) {
$this->content = $content;
} else {
$this->content .= $content;
}
$this->checksum = null;
return $this;
}
public function getObjectCount()
{
return $this->cntObject;

View File

@ -133,7 +133,11 @@ class IcingaServiceSet extends IcingaObject
protected function getConfigHeaderComment(IcingaConfig $config)
{
if ($config->isLegacy()) {
$comment = "## Service Set '%s'\n\n";
if ($this->get('assign_filter')) {
$comment = "## applied Service Set '%s'\n\n";
} else {
$comment = "## Service Set '%s' on this host\n\n";
}
} else {
$comment = "/** Service Set '%s' **/\n\n";
}
@ -162,12 +166,6 @@ class IcingaServiceSet extends IcingaObject
// Loop over all services belonging to this set
// generate every service with host_name host1,host2... -> not yet. And Zones?
$file = $config->configFile(
// TODO: zones.d?
'zones.d/' . $this->getRenderingZone($config) . '/servicesets'
);
$file->prepend($this->getConfigHeaderComment($config));
$conn = $this->getConnection();
// Delegating this to the service would look, but this way it's faster
@ -179,22 +177,41 @@ class IcingaServiceSet extends IcingaObject
$this->copyVarsToService($service);
foreach ($hosts as $hostname) {
$file = $this->legacyHostnameServicesFile($hostname, $config);
$file->addContent($this->getConfigHeaderComment($config));
$service->set('host', $hostname);
$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)
{
return $config->configFile(
'director/' . IcingaHost::load($hostname, $this->getConnection())->getRenderingZone($config) . '/servicesets'
);
}
protected function legacyRelatedHostFile(IcingaService $service, IcingaConfig $config)
{
return $config->configFile(
'director/' . $service->getRelated('host')->getRenderingZone($config) . '/servicesets'
);
}
public function getRenderingZone(IcingaConfig $config = null)
{
if ($this->get('host_id') === null) {