From 6f636b51efe26fea2b65b1e2bc9f75462dcddc12 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, 15 insertions(+), 2 deletions(-) diff --git a/library/Icingadb/Redis/VolatileStateResults.php b/library/Icingadb/Redis/VolatileStateResults.php index c56db2721..89809ae95 100644 --- a/library/Icingadb/Redis/VolatileStateResults.php +++ b/library/Icingadb/Redis/VolatileStateResults.php @@ -103,6 +103,8 @@ protected function applyRedisUpdates($rows) $keys = []; $hostStateKeys = []; + $definitions = []; + $hostStateDefinitions = []; $showSourceGranted = $this->getAuth()->hasPermission('icingadb/object/show-source'); @@ -139,6 +141,7 @@ protected function applyRedisUpdates($rows) $states[bin2hex($row->id)] = $row->state; if (empty($keys)) { $keys = $row->state->getColumns(); + $definitions = $row->state->getColumnDefinitions(); if (! $showSourceGranted) { $keys = array_diff($keys, ['check_commandline']); } @@ -148,6 +151,7 @@ protected function applyRedisUpdates($rows) $hostStates[bin2hex($row->host->id)] = $row->host->state; if (empty($hostStateKeys)) { $hostStateKeys = $row->host->state->getColumns(); + $hostStateDefinitions = $row->host->state->getColumnDefinitions(); } } } @@ -163,8 +167,13 @@ protected function applyRedisUpdates($rows) } foreach ($results as $id => $data) { + $columnDefinitions = $states[$id]->getColumnDefinitions(); foreach ($data as $key => $value) { - $data[$key] = $behaviors->retrieveProperty($value, $key); + if ($value === null && ! $definitions[$key]['nullable']) { + unset($data[$key]); + } else { + $data[$key] = $behaviors->retrieveProperty($value, $key); + } } $states[$id]->setProperties($data); @@ -173,7 +182,11 @@ protected function applyRedisUpdates($rows) if ($type === 'service' && ! empty($hostStates)) { foreach (IcingaRedis::fetchHostState(array_keys($hostStates), $hostStateKeys) as $id => $data) { foreach ($data as $key => $value) { - $data[$key] = $behaviors->retrieveProperty($value, $key); + if ($value === null && ! $hostStateDefinitions[$key]['nullable']) { + unset($data[$key]); + } else { + $data[$key] = $behaviors->retrieveProperty($value, $key); + } } $hostStates[$id]->setProperties($data);