summaryrefslogtreecommitdiffstats
path: root/library/Director/Objects/IcingaService.php
diff options
context:
space:
mode:
Diffstat (limited to 'library/Director/Objects/IcingaService.php')
-rw-r--r--library/Director/Objects/IcingaService.php107
1 files changed, 17 insertions, 90 deletions
diff --git a/library/Director/Objects/IcingaService.php b/library/Director/Objects/IcingaService.php
index 9479ef7..cbf9ca5 100644
--- a/library/Director/Objects/IcingaService.php
+++ b/library/Director/Objects/IcingaService.php
@@ -8,7 +8,6 @@ use Icinga\Module\Director\Data\PropertiesFilter;
use Icinga\Module\Director\Db;
use Icinga\Module\Director\Db\Cache\PrefetchCache;
use Icinga\Module\Director\DirectorObject\Automation\ExportInterface;
-use Icinga\Module\Director\Exception\DuplicateKeyException;
use Icinga\Module\Director\IcingaConfig\IcingaConfig;
use Icinga\Module\Director\IcingaConfig\IcingaConfigHelper as c;
use Icinga\Module\Director\IcingaConfig\IcingaLegacyConfigHelper as c1;
@@ -170,94 +169,6 @@ class IcingaService extends IcingaObject implements ExportInterface
}
/**
- * @return object
- * @deprecated please use \Icinga\Module\Director\Data\Exporter
- * @throws \Icinga\Exception\NotFoundError
- */
- public function export()
- {
- // TODO: ksort in toPlainObject?
- $props = (array) $this->toPlainObject();
- $props['fields'] = $this->loadFieldReferences();
- ksort($props);
-
- return (object) $props;
- }
-
- /**
- * @param $plain
- * @param Db $db
- * @param bool $replace
- * @return IcingaService
- * @throws DuplicateKeyException
- * @throws \Icinga\Exception\NotFoundError
- */
- public static function import($plain, Db $db, $replace = false)
- {
- $properties = (array) $plain;
- $name = $properties['object_name'];
- if ($properties['object_type'] !== 'template') {
- throw new InvalidArgumentException(sprintf(
- 'Can import only Templates, got "%s" for "%s"',
- $properties['object_type'],
- $name
- ));
- }
- $key = [
- 'object_type' => 'template',
- 'object_name' => $name
- ];
-
- if ($replace && static::exists($key, $db)) {
- $object = static::load($key, $db);
- } elseif (static::exists($key, $db)) {
- throw new DuplicateKeyException(
- 'Service Template "%s" already exists',
- $name
- );
- } else {
- $object = static::create([], $db);
- }
-
- // $object->newFields = $properties['fields'];
- unset($properties['fields']);
- $object->setProperties($properties);
-
- return $object;
- }
-
- /**
- * @deprecated please use \Icinga\Module\Director\Data\FieldReferenceLoader
- * @return array
- */
- protected function loadFieldReferences()
- {
- $db = $this->getDb();
-
- $res = $db->fetchAll(
- $db->select()->from([
- 'sf' => 'icinga_service_field'
- ], [
- 'sf.datafield_id',
- 'sf.is_required',
- 'sf.var_filter',
- ])->join(['df' => 'director_datafield'], 'df.id = sf.datafield_id', [])
- ->where('service_id = ?', $this->get('id'))
- ->order('varname ASC')
- );
-
- if (empty($res)) {
- return [];
- } else {
- foreach ($res as $field) {
- $field->datafield_id = (int) $field->datafield_id;
- }
-
- return $res;
- }
- }
-
- /**
* @param string $key
* @return $this
*/
@@ -473,6 +384,11 @@ class IcingaService extends IcingaObject implements ExportInterface
}
}
+ protected function rendersConditionalTemplate(): bool
+ {
+ return $this->getRenderingZone() === self::ALL_NON_GLOBAL_ZONES;
+ }
+
/**
* @return bool
*/
@@ -667,11 +583,22 @@ class IcingaService extends IcingaObject implements ExportInterface
protected function getDefaultZone(IcingaConfig $config = null)
{
+ // Hint: this isn't possible yet, as we're unable to render dependent apply rules to multiple zones as well
+ // if ($this->isTemplate()) {
+ // return self::ALL_NON_GLOBAL_ZONES;
+ // }
if ($this->get('host_id') === null) {
return parent::getDefaultZone();
} else {
- return $this->getRelatedObject('host', $this->get('host_id'))
+ $zone = $this->getRelatedObject('host', $this->get('host_id'))
->getRenderingZone($config);
+
+ // Hint: this avoids problems with host templates rendered to all non-global zones
+ if ($zone === self::ALL_NON_GLOBAL_ZONES) {
+ $zone = $this->connection->getDefaultGlobalZoneName();
+ }
+
+ return $zone;
}
}