diff --git a/library/Icingadb/Common/IcingaRedis.php b/library/Icingadb/Common/IcingaRedis.php index 0926814fd..319801291 100644 --- a/library/Icingadb/Common/IcingaRedis.php +++ b/library/Icingadb/Common/IcingaRedis.php @@ -152,10 +152,19 @@ protected function fetchState(string $key, array $ids, array $columns): Generato return; } + $desiredProperties = []; + foreach ($columns as $alias => $column) { + if (is_int($alias)) { + $desiredProperties[] = $column; + } else { + $desiredProperties[] = $alias; + } + } + foreach ($results as $i => $json) { if ($json !== null) { $data = json_decode($json, true); - $keyMap = array_fill_keys($columns, null); + $keyMap = array_fill_keys($desiredProperties, null); unset($keyMap['is_overdue']); // Is calculated by Icinga DB, not Icinga 2, hence it's never in redis // TODO: Remove once https://github.com/Icinga/icinga2/issues/9427 is fixed diff --git a/library/Icingadb/Model/Host.php b/library/Icingadb/Model/Host.php index 26e14287b..4820c9e57 100644 --- a/library/Icingadb/Model/Host.php +++ b/library/Icingadb/Model/Host.php @@ -5,6 +5,7 @@ namespace Icinga\Module\Icingadb\Model; use Icinga\Module\Icingadb\Common\Auth; +use Icinga\Module\Icingadb\Common\Backend; use Icinga\Module\Icingadb\Model\Behavior\BoolCast; use Icinga\Module\Icingadb\Model\Behavior\ReRoute; use ipl\Orm\Behavior\Binary; @@ -13,6 +14,7 @@ use ipl\Orm\Model; use ipl\Orm\Relations; use ipl\Orm\ResultSet; +use ipl\Sql\Expression; /** * Host model. @@ -74,7 +76,7 @@ public function getKeyName() public function getColumns() { - return [ + $columns = [ 'environment_id', 'name_checksum', 'properties_checksum', @@ -112,9 +114,15 @@ public function getColumns() 'zone_name', 'zone_id', 'command_endpoint_name', - 'command_endpoint_id', - 'affected_children' + 'command_endpoint_id' ]; + if (Backend::getDbSchemaVersion() >= 6) { + $columns[] = 'affected_children'; + } else { + $columns['affected_children'] = new Expression('0'); + } + + return $columns; } public function getColumnDefinitions() diff --git a/library/Icingadb/Model/Service.php b/library/Icingadb/Model/Service.php index 1568a0574..02f72cfd6 100644 --- a/library/Icingadb/Model/Service.php +++ b/library/Icingadb/Model/Service.php @@ -5,6 +5,7 @@ namespace Icinga\Module\Icingadb\Model; use Icinga\Module\Icingadb\Common\Auth; +use Icinga\Module\Icingadb\Common\Backend; use Icinga\Module\Icingadb\Model\Behavior\BoolCast; use Icinga\Module\Icingadb\Model\Behavior\HasProblematicParent; use Icinga\Module\Icingadb\Model\Behavior\ReRoute; @@ -14,6 +15,7 @@ use ipl\Orm\Model; use ipl\Orm\Relations; use ipl\Orm\ResultSet; +use ipl\Sql\Expression; /** * @property string $id @@ -70,7 +72,7 @@ public function getKeyName() public function getColumns() { - return [ + $columns = [ 'environment_id', 'name_checksum', 'properties_checksum', @@ -105,9 +107,16 @@ public function getColumns() 'zone_name', 'zone_id', 'command_endpoint_name', - 'command_endpoint_id', - 'affected_children' + 'command_endpoint_id' ]; + if (Backend::getDbSchemaVersion() >= 6) { + $columns[] = 'affected_children'; + } else { + $columns['has_problematic_parent'] = new Expression('0'); + $columns['affected_children'] = new Expression('0'); + } + + return $columns; } public function getColumnDefinitions() @@ -196,7 +205,9 @@ public function createBehaviors(Behaviors $behaviors) 'command_endpoint_id' ])); - $behaviors->add(new HasProblematicParent()); + if (Backend::getDbSchemaVersion() >= 6) { + $behaviors->add(new HasProblematicParent()); + } } public function createDefaults(Defaults $defaults) diff --git a/library/Icingadb/Model/State.php b/library/Icingadb/Model/State.php index a4556c1d5..219ede2b2 100644 --- a/library/Icingadb/Model/State.php +++ b/library/Icingadb/Model/State.php @@ -5,12 +5,14 @@ namespace Icinga\Module\Icingadb\Model; use DateTime; +use Icinga\Module\Icingadb\Common\Backend; use Icinga\Module\Icingadb\Common\Icons; use Icinga\Module\Icingadb\Model\Behavior\BoolCast; use ipl\Orm\Behavior\Binary; use ipl\Orm\Behavior\MillisecondTimestamp; use ipl\Orm\Behaviors; use ipl\Orm\Model; +use ipl\Sql\Expression; use ipl\Web\Widget\Icon; /** @@ -68,7 +70,7 @@ abstract public function getStateTextTranslated(): string; public function getColumns() { - return [ + $columns = [ 'environment_id', 'state_type', 'soft_state', @@ -99,9 +101,15 @@ public function getColumns() 'last_update', 'last_state_change', 'next_check', - 'next_update', - 'affects_children' + 'next_update' ]; + if (Backend::getDbSchemaVersion() >= 6) { + $columns[] = 'affects_children'; + } else { + $columns['affects_children'] = new Expression("'n'"); + } + + return $columns; } public function createBehaviors(Behaviors $behaviors) diff --git a/library/Icingadb/Widget/Detail/ObjectDetail.php b/library/Icingadb/Widget/Detail/ObjectDetail.php index 064fb1f02..132b37e1c 100644 --- a/library/Icingadb/Widget/Detail/ObjectDetail.php +++ b/library/Icingadb/Widget/Detail/ObjectDetail.php @@ -14,6 +14,7 @@ use Icinga\Date\DateFormatter; use Icinga\Exception\IcingaException; use Icinga\Module\Icingadb\Common\Auth; +use Icinga\Module\Icingadb\Common\Backend; use Icinga\Module\Icingadb\Common\Database; use Icinga\Module\Icingadb\Common\HostLinks; use Icinga\Module\Icingadb\Common\Icons; @@ -622,6 +623,7 @@ protected function createRootProblems(): ?array // host being down, only show its root problems if it's really caused by a dependency failure. if ( $this->object->state->is_reachable + || Backend::getDbSchemaVersion() < 6 || ($this->object instanceof Service && ! $this->object->has_problematic_parent) ) { return null; @@ -669,7 +671,7 @@ protected function createRootProblems(): ?array */ protected function createAffectedObjects(): ?array { - if (! $this->object->state->affects_children) { + if (! $this->object->state->affects_children || Backend::getDbSchemaVersion() < 6) { return null; }