diff --git a/application/controllers/ServiceController.php b/application/controllers/ServiceController.php index 2857718ae..25f56b729 100644 --- a/application/controllers/ServiceController.php +++ b/application/controllers/ServiceController.php @@ -8,6 +8,7 @@ use Icinga\Exception\NotFoundError; use Icinga\Module\Icingadb\Command\Object\GetObjectCommand; use Icinga\Module\Icingadb\Command\Transport\CommandTransport; +use Icinga\Module\Icingadb\Common\Backend; use Icinga\Module\Icingadb\Common\CommandActions; use Icinga\Module\Icingadb\Common\Links; use Icinga\Module\Icingadb\Common\ServiceLinks; @@ -39,7 +40,6 @@ public function init() $hostName = $this->params->getRequired('host.name'); $query = Service::on($this->getDb()) - ->withColumns(['has_problematic_parent']) ->with([ 'state', 'icon_image', @@ -54,6 +54,10 @@ public function init() Filter::equal('host.name', $hostName) )); + if (Backend::getDbSchemaVersion() >= 6) { + $query->withColumns(['has_problematic_parent']); + } + $this->applyRestrictions($query); /** @var Service $service */ diff --git a/library/Icingadb/Model/Host.php b/library/Icingadb/Model/Host.php index 26e14287b..de17d9039 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; @@ -74,7 +75,7 @@ public function getKeyName() public function getColumns() { - return [ + $columns = [ 'environment_id', 'name_checksum', 'properties_checksum', @@ -112,14 +113,19 @@ 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'; + } + + return $columns; } public function getColumnDefinitions() { - return [ + $columns = [ 'environment_id' => t('Environment Id'), 'name_checksum' => t('Host Name Checksum'), 'properties_checksum' => t('Host Properties Checksum'), @@ -157,9 +163,14 @@ public function getColumnDefinitions() 'zone_name' => t('Zone Name'), 'zone_id' => t('Zone Id'), 'command_endpoint_name' => t('Endpoint Name'), - 'command_endpoint_id' => t('Endpoint Id'), - 'affected_children' => t('Affected Children'), + 'command_endpoint_id' => t('Endpoint Id') ]; + + if (Backend::getDbSchemaVersion() >= 6) { + $columns['affected_children'] = t('Affected Children'); + } + + return $columns; } public function getSearchColumns() diff --git a/library/Icingadb/Model/HostState.php b/library/Icingadb/Model/HostState.php index c9500e5fe..fffe48172 100644 --- a/library/Icingadb/Model/HostState.php +++ b/library/Icingadb/Model/HostState.php @@ -4,6 +4,7 @@ namespace Icinga\Module\Icingadb\Model; +use Icinga\Module\Icingadb\Common\Backend; use Icinga\Module\Icingadb\Common\HostStates; use ipl\Orm\Relations; @@ -24,7 +25,7 @@ public function getKeyName() public function getColumnDefinitions() { - return [ + $columns = [ 'environment_id' => t('Environment Id'), 'state_type' => t('Host State Type'), 'soft_state' => t('Host Soft State'), @@ -53,9 +54,14 @@ public function getColumnDefinitions() 'last_update' => t('Host Last Update'), 'last_state_change' => t('Host Last State Change'), 'next_check' => t('Host Next Check'), - 'next_update' => t('Host Next Update'), - 'affects_children' => t('Host Affects Children'), + 'next_update' => t('Host Next Update') ]; + + if (Backend::getDbSchemaVersion() >= 6) { + $columns['affects_children'] = t('Host Affects Children'); + } + + return $columns; } public function createRelations(Relations $relations) diff --git a/library/Icingadb/Model/Service.php b/library/Icingadb/Model/Service.php index 1568a0574..8836ebeef 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; @@ -70,7 +71,7 @@ public function getKeyName() public function getColumns() { - return [ + $columns = [ 'environment_id', 'name_checksum', 'properties_checksum', @@ -105,14 +106,19 @@ 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'; + } + + return $columns; } public function getColumnDefinitions() { - return [ + $columns = [ 'environment_id' => t('Environment Id'), 'name_checksum' => t('Service Name Checksum'), 'properties_checksum' => t('Service Properties Checksum'), @@ -148,8 +154,13 @@ public function getColumnDefinitions() 'zone_id' => t('Zone Id'), 'command_endpoint_name' => t('Endpoint Name'), 'command_endpoint_id' => t('Endpoint Id'), - 'affected_children' => t('Affected Children') ]; + + if (Backend::getDbSchemaVersion() >= 6) { + $columns['affected_children'] = t('Affected Children'); + } + + return $columns; } public function getSearchColumns() @@ -196,7 +207,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/ServiceState.php b/library/Icingadb/Model/ServiceState.php index a42a4e239..195fe281b 100644 --- a/library/Icingadb/Model/ServiceState.php +++ b/library/Icingadb/Model/ServiceState.php @@ -4,6 +4,7 @@ namespace Icinga\Module\Icingadb\Model; +use Icinga\Module\Icingadb\Common\Backend; use Icinga\Module\Icingadb\Common\ServiceStates; use ipl\Orm\Relations; @@ -26,7 +27,7 @@ public function getKeyName() public function getColumnDefinitions() { - return [ + $columns = [ 'environment_id' => t('Environment Id'), 'state_type' => t('Service State Type'), 'soft_state' => t('Service Soft State'), @@ -55,9 +56,14 @@ public function getColumnDefinitions() 'last_update' => t('Service Last Update'), 'last_state_change' => t('Service Last State Change'), 'next_check' => t('Service Next Check'), - 'next_update' => t('Service Next Update'), - 'affects_children' => t('Service Affects Children'), + 'next_update' => t('Service Next Update') ]; + + if (Backend::getDbSchemaVersion() >= 6) { + $columns['affects_children'] = t('Service Affects Children'); + } + + return $columns; } public function createRelations(Relations $relations) diff --git a/library/Icingadb/Model/State.php b/library/Icingadb/Model/State.php index a4556c1d5..acd11d81b 100644 --- a/library/Icingadb/Model/State.php +++ b/library/Icingadb/Model/State.php @@ -5,6 +5,7 @@ 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; @@ -68,7 +69,7 @@ abstract public function getStateTextTranslated(): string; public function getColumns() { - return [ + $columns = [ 'environment_id', 'state_type', 'soft_state', @@ -99,9 +100,14 @@ public function getColumns() 'last_update', 'last_state_change', 'next_check', - 'next_update', - 'affects_children' + 'next_update' ]; + + if (Backend::getDbSchemaVersion() >= 6) { + $columns[] = 'affects_children'; + } + + 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..1cc91931e 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; @@ -43,6 +44,7 @@ use ipl\Sql\Filter\Exists; use ipl\Web\Widget\CopyToClipboard; use ipl\Web\Widget\EmptyState; +use ipl\Web\Widget\EmptyStateBar; use ipl\Web\Widget\HorizontalKeyValue; use Icinga\Module\Icingadb\Widget\ItemList\CommentList; use Icinga\Module\Icingadb\Widget\PluginOutputContainer; @@ -617,6 +619,17 @@ protected function fetchCustomVars() */ protected function createRootProblems(): ?array { + if (Backend::getDbSchemaVersion() < 6) { + if ($this->object->state->is_reachable) { + return null; + } + + return [ + HtmlElement::create('h2', null, Text::create(t('Root Problems'))), + new EmptyStateBar(t("You're missing out! Upgrade Icinga DB and see the actual root cause here!")) + ]; + } + // If a dependency has failed, then the children are not reachable. Hence, the root problems should not be shown // if the object is reachable. And in case of a service, since, it may be also be unreachable because of its // host being down, only show its root problems if it's really caused by a dependency failure. @@ -669,7 +682,7 @@ protected function createRootProblems(): ?array */ protected function createAffectedObjects(): ?array { - if (! $this->object->state->affects_children) { + if (! isset($this->object->state->affects_children) || ! $this->object->state->affects_children) { return null; } diff --git a/library/Icingadb/Widget/ItemList/StateListItem.php b/library/Icingadb/Widget/ItemList/StateListItem.php index f8704d8a6..58a2f9b9e 100644 --- a/library/Icingadb/Widget/ItemList/StateListItem.php +++ b/library/Icingadb/Widget/ItemList/StateListItem.php @@ -98,7 +98,7 @@ protected function assembleTitle(BaseHtmlElement $title): void Html::tag('span', ['class' => 'state-text'], $this->state->getStateTextTranslated()) )); - if ($this->state->affects_children) { + if (isset($this->state->affects_children) && $this->state->affects_children) { $total = (int) $this->item->affected_children; if ($total > 1000) {