diff --git a/library/Icingadb/Redis/VolatileStateResults.php b/library/Icingadb/Redis/VolatileStateResults.php index 43446d681..e49f84a17 100644 --- a/library/Icingadb/Redis/VolatileStateResults.php +++ b/library/Icingadb/Redis/VolatileStateResults.php @@ -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 = []; @@ -140,7 +140,7 @@ 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']); @@ -148,16 +148,18 @@ protected function applyRedisUpdates($rows) $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; } } } @@ -183,8 +185,9 @@ 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) @@ -192,7 +195,11 @@ protected function apply(array $states, string $type): void 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);