mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-28 16:24:05 +02:00
Merge branch 'feature/icinga-legacy-config-13049'
This commit is contained in:
commit
01ef8cb4ba
@ -48,8 +48,19 @@ class HostApplyMatches
|
|||||||
return self::$flatObjects;
|
return self::$flatObjects;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static function raiseLimits()
|
||||||
|
{
|
||||||
|
// Raise limits. TODO: do this in a failsafe way, and only if necessary
|
||||||
|
// Note: IcingaConfig also raises the limit for generation, **but** we need the higher limit for preview.
|
||||||
|
if ((string) ini_get('memory_limit') !== '-1') {
|
||||||
|
ini_set('memory_limit', '1024M');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected static function fetchFlatObjects(Db $db)
|
protected static function fetchFlatObjects(Db $db)
|
||||||
{
|
{
|
||||||
|
self::raiseLimits();
|
||||||
|
|
||||||
Benchmark::measure('HostApplyMatches: prefetching');
|
Benchmark::measure('HostApplyMatches: prefetching');
|
||||||
PrefetchCache::initialize($db);
|
PrefetchCache::initialize($db);
|
||||||
$all = IcingaHost::prefetchAll($db);
|
$all = IcingaHost::prefetchAll($db);
|
||||||
|
@ -2,6 +2,11 @@
|
|||||||
|
|
||||||
namespace Icinga\Module\Director\Objects;
|
namespace Icinga\Module\Director\Objects;
|
||||||
|
|
||||||
|
use Icinga\Data\Filter\Filter;
|
||||||
|
use Icinga\Exception\ProgrammingError;
|
||||||
|
use Icinga\Module\Director\IcingaConfig\IcingaConfig;
|
||||||
|
use Icinga\Module\Director\IcingaConfig\IcingaLegacyConfigHelper as c1;
|
||||||
|
|
||||||
class IcingaHostGroup extends IcingaObjectGroup
|
class IcingaHostGroup extends IcingaObjectGroup
|
||||||
{
|
{
|
||||||
protected $table = 'icinga_hostgroup';
|
protected $table = 'icinga_hostgroup';
|
||||||
@ -10,4 +15,98 @@ class IcingaHostGroup extends IcingaObjectGroup
|
|||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function renderToLegacyConfig(IcingaConfig $config)
|
||||||
|
{
|
||||||
|
if ($this->get('assign_filter') !== null) {
|
||||||
|
$this->renderLegacyApplyToConfig($config);
|
||||||
|
} else {
|
||||||
|
parent::renderToLegacyConfig($config);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param IcingaConfig $config
|
||||||
|
*
|
||||||
|
* @throws ProgrammingError When IcingaConfig deployment mode is not supported
|
||||||
|
*/
|
||||||
|
protected function renderLegacyApplyToConfig(IcingaConfig $config)
|
||||||
|
{
|
||||||
|
$conn = $this->getConnection();
|
||||||
|
|
||||||
|
$filter = Filter::fromQueryString($this->get('assign_filter'));
|
||||||
|
$hosts = HostApplyMatches::forFilter($filter, $conn);
|
||||||
|
$this->set('object_type', 'object');
|
||||||
|
|
||||||
|
$zoneMap = array();
|
||||||
|
|
||||||
|
foreach ($hosts as $hostname) {
|
||||||
|
$host = IcingaHost::load($hostname, $this->connection);
|
||||||
|
|
||||||
|
if (($zoneId = $host->getResolvedProperty('zone_id')) !== null) {
|
||||||
|
$zoneMap[$zoneId][] = $hostname;
|
||||||
|
} else {
|
||||||
|
$zoneMap[0][] = $hostname;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($zoneMap)) {
|
||||||
|
// no hosts matched
|
||||||
|
$file = $this->legacyZoneHostgroupFile($config);
|
||||||
|
$this->properties['hostgroup_members'] = array();
|
||||||
|
$file->addLegacyObject($this);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$allMembers = array();
|
||||||
|
|
||||||
|
foreach ($zoneMap as $zoneId => $members) {
|
||||||
|
$file = $this->legacyZoneHostgroupFile($config, $zoneId);
|
||||||
|
$this->properties['hostgroup_members'] = $members;
|
||||||
|
$file->addLegacyObject($this);
|
||||||
|
|
||||||
|
$allMembers = array_merge($allMembers, $members);
|
||||||
|
}
|
||||||
|
|
||||||
|
$deploymentMode = $config->getDeploymentMode();
|
||||||
|
if ($deploymentMode === 'active-passive') {
|
||||||
|
$this->properties['hostgroup_members'] = $allMembers;
|
||||||
|
$this->legacyZoneHostgroupFile($config, 0)
|
||||||
|
->addLegacyObject($this);
|
||||||
|
} else if ($deploymentMode == 'masterless') {
|
||||||
|
// nothing to add
|
||||||
|
} else {
|
||||||
|
throw new ProgrammingError('Unsupported deployment mode: %s' . $deploymentMode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function legacyZoneHostgroupFile(IcingaConfig $config, $zoneId = null)
|
||||||
|
{
|
||||||
|
if ($zoneId !== null) {
|
||||||
|
$zone = IcingaZone::load($zoneId, $this->getConnection())->getObjectName();
|
||||||
|
} else {
|
||||||
|
$zone = $this->connection->getDefaultGlobalZoneName();
|
||||||
|
}
|
||||||
|
return $config->configFile(
|
||||||
|
'director/' . $zone . '/hostgroups'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function renderLegacyHostgroup_members()
|
||||||
|
{
|
||||||
|
if (empty($this->properties['hostgroup_members'])) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
return c1::renderKeyValue('hostgroup_members', join(',', $this->properties['hostgroup_members']));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Note: rendered with renderLegacyHostgroup_members()
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function renderLegacyAssign_filter()
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -177,7 +177,10 @@ class IcingaService extends IcingaObject
|
|||||||
|
|
||||||
public function renderToLegacyConfig(IcingaConfig $config)
|
public function renderToLegacyConfig(IcingaConfig $config)
|
||||||
{
|
{
|
||||||
if ($this->isApplyRule()) {
|
if ($this->get('service_set_id') !== null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if ($this->isApplyRule()) {
|
||||||
$this->renderLegacyApplyToConfig($config);
|
$this->renderLegacyApplyToConfig($config);
|
||||||
} else {
|
} else {
|
||||||
parent::renderToLegacyConfig($config);
|
parent::renderToLegacyConfig($config);
|
||||||
@ -214,7 +217,7 @@ class IcingaService extends IcingaObject
|
|||||||
|
|
||||||
public function toLegacyConfigString()
|
public function toLegacyConfigString()
|
||||||
{
|
{
|
||||||
if ($this->get('service_set_id')) {
|
if ($this->get('service_set_id') !== null) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user