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 Oct 31, 2024
1 parent 51ae9da commit 6f636b5
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions library/Icingadb/Redis/VolatileStateResults.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ protected function applyRedisUpdates($rows)

$keys = [];
$hostStateKeys = [];
$definitions = [];
$hostStateDefinitions = [];

$showSourceGranted = $this->getAuth()->hasPermission('icingadb/object/show-source');

Expand Down Expand Up @@ -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']);
}
Expand All @@ -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();
}
}
}
Expand All @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 6f636b5

Please sign in to comment.