mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-31 01:34:12 +02:00
Sync: detect combined keys, e.g. host/service
This commit is contained in:
parent
93da0fe06c
commit
6c66f60ccc
@ -231,6 +231,24 @@ class Sync
|
|||||||
|
|
||||||
$sourceColumns = $this->prepareSourceColumns($properties);
|
$sourceColumns = $this->prepareSourceColumns($properties);
|
||||||
|
|
||||||
|
$keyPattern = null;
|
||||||
|
if ($rule->object_type === 'service') {
|
||||||
|
$hasHost = false;
|
||||||
|
$hasObjectName = false;
|
||||||
|
foreach ($properties as $key => $property) {
|
||||||
|
if ($property->destination_field === 'host') {
|
||||||
|
$hasHost = $property->source_expression;
|
||||||
|
}
|
||||||
|
if ($property->destination_field === 'object_name') {
|
||||||
|
$hasObjectName = $property->source_expression;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($hasHost !== false && $hasObjectName !== false) {
|
||||||
|
$keyPattern = sprintf('%s!%s', $hasHost, $hasObjectName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($sources as $source) {
|
foreach ($sources as $source) {
|
||||||
$sourceId = $source->id;
|
$sourceId = $source->id;
|
||||||
$key = $source->key_column;
|
$key = $source->key_column;
|
||||||
@ -239,6 +257,20 @@ class Sync
|
|||||||
|
|
||||||
$imported[$sourceId] = array();
|
$imported[$sourceId] = array();
|
||||||
foreach ($rows as $row) {
|
foreach ($rows as $row) {
|
||||||
|
if ($keyPattern) {
|
||||||
|
$key = $this->fillVariables($keyPattern, $row);
|
||||||
|
if (array_key_exists($key, $imported[$sourceId])) {
|
||||||
|
throw new IcingaException(
|
||||||
|
'Trying to import row "%s" (%s) twice: %s VS %s',
|
||||||
|
$key,
|
||||||
|
$keyPattern,
|
||||||
|
json_encode($imported[$sourceId][$key]),
|
||||||
|
json_encode($row)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
if (! property_exists($row, $key)) {
|
if (! property_exists($row, $key)) {
|
||||||
throw new IcingaException(
|
throw new IcingaException(
|
||||||
'There is no key column "%s" in this row from "%s": %s',
|
'There is no key column "%s" in this row from "%s": %s',
|
||||||
@ -247,12 +279,20 @@ class Sync
|
|||||||
json_encode($row)
|
json_encode($row)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
if (! $rule->matches($row)) {
|
if (! $rule->matches($row)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($keyPattern) {
|
||||||
|
$imported[$sourceId][$key] = $row;
|
||||||
|
} else {
|
||||||
$imported[$sourceId][$row->$key] = $row;
|
$imported[$sourceId][$row->$key] = $row;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $imported;
|
return $imported;
|
||||||
}
|
}
|
||||||
@ -388,6 +428,7 @@ class Sync
|
|||||||
$this->removeForeignListEntries($objects, $properties);
|
$this->removeForeignListEntries($objects, $properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: directly work on existing objects, remember imported keys, then purge
|
||||||
$newObjects = $this->prepareNewObjects(
|
$newObjects = $this->prepareNewObjects(
|
||||||
$rule,
|
$rule,
|
||||||
$properties,
|
$properties,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user