From 10fb640b683a2333f064395d2f73c9063036afc8 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 31 Oct 2024 16:42:54 +0100 Subject: [PATCH] VolatileStateResults: Only accept null values for nullable columns --- library/Icingadb/Redis/VolatileStateResults.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) 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);