summaryrefslogtreecommitdiffstats
path: root/library/Director/Objects/IcingaObject.php
diff options
context:
space:
mode:
Diffstat (limited to 'library/Director/Objects/IcingaObject.php')
-rw-r--r--library/Director/Objects/IcingaObject.php94
1 files changed, 51 insertions, 43 deletions
diff --git a/library/Director/Objects/IcingaObject.php b/library/Director/Objects/IcingaObject.php
index 04ae32b..3b6236d 100644
--- a/library/Director/Objects/IcingaObject.php
+++ b/library/Director/Objects/IcingaObject.php
@@ -27,6 +27,7 @@ use RuntimeException;
abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
{
const RESOLVE_ERROR = '(unable to resolve)';
+ const ALL_NON_GLOBAL_ZONES = '(all non-global zones)';
protected $keyName = 'object_name';
@@ -63,9 +64,6 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
protected $type;
- /* key/value!! */
- protected $booleans = [];
-
// Property suffixed with _id must exist
protected $relations = [
// property => PropertyClass
@@ -142,11 +140,6 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
return $this->connection;
}
- public function propertyIsBoolean($property)
- {
- return array_key_exists($property, $this->booleans);
- }
-
public function propertyIsInterval($property)
{
return array_key_exists($property, $this->intervalProperties);
@@ -771,10 +764,6 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
return $this;
}
- if ($this->propertyIsBoolean($key)) {
- return parent::set($key, DbDataFormatter::normalizeBoolean($value));
- }
-
// e.g. zone_id
if ($this->propertyIsRelation($key)) {
return $this->setRelation($key, $value);
@@ -906,20 +895,20 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
$type = strtolower($this->getType());
$query = $this->db->select()->from(
- ['gr' => "icinga_${type}group_${type}_resolved"],
+ ['gr' => "icinga_{$type}group_{$type}_resolved"],
['g.object_name']
)->join(
- ['g' => "icinga_${type}group"],
- "g.id = gr.${type}group_id",
+ ['g' => "icinga_{$type}group"],
+ "g.id = gr.{$type}group_id",
[]
)->joinLeft(
- ['go' => "icinga_${type}group_${type}"],
- "go.${type}group_id = gr.${type}group_id AND go.${type}_id = " . (int) $id,
+ ['go' => "icinga_{$type}group_{$type}"],
+ "go.{$type}group_id = gr.{$type}group_id AND go.{$type}_id = " . (int) $id,
[]
)->where(
- "gr.${type}_id = ?",
+ "gr.{$type}_id = ?",
(int) $id
- )->where("go.${type}_id IS NULL")->order('g.object_name');
+ )->where("go.{$type}_id IS NULL")->order('g.object_name');
return $this->db->fetchCol($query);
}
@@ -1812,9 +1801,21 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
return;
}
- $config->configFile(
- 'zones.d/' . $this->getRenderingZone($config) . '/' . $this->getRenderingFilename()
- )->addObject($this);
+ foreach ($this->getRenderingZones($config) as $zone) {
+ $config->configFile(
+ 'zones.d/' . $zone . '/' . $this->getRenderingFilename()
+ )->addObject($this);
+ }
+ }
+
+ protected function getRenderingZones(IcingaConfig $config): array
+ {
+ $zone = $this->getRenderingZone($config);
+ if ($zone === self::ALL_NON_GLOBAL_ZONES) {
+ return $config->listNonGlobalZones();
+ }
+
+ return [$zone];
}
public function getRenderingFilename()
@@ -2193,7 +2194,12 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
protected function renderSuffix()
{
- return "}\n\n";
+ $prefix = '';
+ if ($this->rendersConditionalTemplate()) {
+ $prefix = '} ';
+ }
+
+ return "$prefix}\n\n";
}
protected function renderLegacySuffix()
@@ -2418,14 +2424,25 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
protected function renderObjectHeader()
{
+ $prefix = '';
+ $renderedName = c::renderString($this->getObjectName());
+ if ($this->rendersConditionalTemplate()) {
+ $prefix = sprintf('if (! get_template(%s, %s)) { ', $this->getType(), $renderedName);
+ }
return sprintf(
- "%s %s %s {\n",
+ "%s%s %s %s {\n",
+ $prefix,
$this->getObjectTypeName(),
$this->getType(),
- c::renderString($this->getObjectName())
+ $renderedName
);
}
+ protected function rendersConditionalTemplate(): bool
+ {
+ return false;
+ }
+
public function getLegacyObjectType()
{
return strtolower($this->getType());
@@ -2674,16 +2691,16 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
/** @var DbObject $class */
$class = DbObjectTypeRegistry::classByType($type);
+ if ($keyColumn === null && is_array($class::create()->getKeyName())) {
+ return $class::loadAll($db, $query);
+ }
+
if ($keyColumn === null) {
if (method_exists($class, 'getKeyColumnName')) {
$keyColumn = $class::getKeyColumnName();
}
}
- if (is_array($class::create()->getKeyName())) {
- return $class::loadAll($db, $query);
- }
-
if (PrefetchCache::shouldBeUsed()
&& $query === null
&& $keyColumn === static::getKeyColumnName()
@@ -2890,11 +2907,14 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
}
}
}
+ if ($this->propertyIsInterval($k) && is_string($v) && ctype_digit($v)) {
+ $v = (int) $v;
+ }
// TODO: Do not ship null properties based on flag?
if (!$skipDefaults || $this->differsFromDefaultValue($k, $v)) {
if ($k === 'disabled' || $this->propertyIsBoolean($k)) {
- $props[$k] = $this->booleanForDbValue($v);
+ $props[$k] = DbDataFormatter::booleanForDbValue($v);
} else {
$props[$k] = $v;
}
@@ -3005,18 +3025,6 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
return (object) $props;
}
- protected function booleanForDbValue($value)
- {
- if ($value === 'y') {
- return true;
- }
- if ($value === 'n') {
- return false;
- }
-
- return $value; // let this fail elsewhere, if not null
- }
-
public function listImportNames()
{
if ($this->gotImports()) {
@@ -3161,7 +3169,7 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
if ($this->differsFromDefaultValue($k, $v)) {
if ($k === 'disabled' || $this->propertyIsBoolean($k)) {
- $props[$k] = $this->booleanForDbValue($v);
+ $props[$k] = DbDataFormatter::booleanForDbValue($v);
} else {
$props[$k] = $v;
}