Skip to content

Commit

Permalink
VolatileStateResults: Only accept null values for nullable columns
Browse files Browse the repository at this point in the history
  • Loading branch information
nilmerg committed Nov 20, 2024
1 parent 1997f46 commit 10fb640
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions library/Icingadb/Redis/VolatileStateResults.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ protected function applyRedisUpdates($rows)
$showSourceGranted = $this->getAuth()->hasPermission('icingadb/object/show-source');

$getKeysAndBehaviors = function (State $state): array {
return [$state->getColumns(), $this->resolver->getBehaviors($state)];
return [$state->getColumns(), $this->resolver->getBehaviors($state), $state->getColumnDefinitions()];
};

$states = [];
Expand Down Expand Up @@ -140,24 +140,26 @@ protected function applyRedisUpdates($rows)
$states[$type][bin2hex($row->id)] = $row->state;

if (! isset($states[$type]['keys'])) {
[$keys, $behaviors] = $getKeysAndBehaviors($row->state);
[$keys, $behaviors, $definitions] = $getKeysAndBehaviors($row->state);

if (! $showSourceGranted) {
$keys = array_diff($keys, ['check_commandline']);
}

$states[$type]['keys'] = $keys;
$states[$type]['behaviors'] = $behaviors;
$states[$type]['definitions'] = $definitions;
}

if ($type === self::TYPE_SERVICE && $row->host instanceof Host && isset($row->host->id)) {
$states[self::TYPE_HOST][bin2hex($row->host->id)] = $row->host->state;

if (! isset($states[self::TYPE_HOST]['keys'])) {
[$keys, $behaviors] = $getKeysAndBehaviors($row->host->state);
[$keys, $behaviors, $definitions] = $getKeysAndBehaviors($row->host->state);

$states[self::TYPE_HOST]['keys'] = $keys;
$states[self::TYPE_HOST]['behaviors'] = $behaviors;
$states[self::TYPE_HOST]['definitions'] = $definitions;
}
}
}
Expand All @@ -183,16 +185,21 @@ protected function apply(array $states, string $type): void
{
$keys = $states['keys'];
$behaviors = $states['behaviors'];
$definitions = $states['definitions'];

unset($states['keys'], $states['behaviors']);
unset($states['keys'], $states['behaviors'], $states['definitions']);

$results = $type === self::TYPE_SERVICE
? IcingaRedis::fetchServiceState(array_keys($states), $keys)
: IcingaRedis::fetchHostState(array_keys($states), $keys);

foreach ($results as $id => $data) {
foreach ($data as $key => $value) {
$data[$key] = $behaviors->retrieveProperty($value, $key);
if ($value === null && ($definitions[$key]['nullable'] ?? true) === false) {
unset($data[$key]);
} else {
$data[$key] = $behaviors->retrieveProperty($value, $key);
}
}

$states[$id]->setProperties($data);
Expand Down

0 comments on commit 10fb640

Please sign in to comment.