From 04b19fe38e01a395d80431eb2dbec49a58380524 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Wed, 18 Dec 2024 13:50:41 +0100 Subject: [PATCH] WIP --- application/controllers/ServiceController.php | 6 +++++- library/Icingadb/Model/Host.php | 15 +++++++++------ library/Icingadb/Model/HostState.php | 12 +++++++++--- library/Icingadb/Model/Service.php | 14 ++++++++------ library/Icingadb/Model/ServiceState.php | 12 +++++++++--- library/Icingadb/Model/State.php | 10 ++++++---- .../Icingadb/Widget/Detail/ObjectDetail.php | 18 +++++++++++++++--- .../Icingadb/Widget/ItemList/StateListItem.php | 2 +- 8 files changed, 62 insertions(+), 27 deletions(-) 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 4820c9e57..de17d9039 100644 --- a/library/Icingadb/Model/Host.php +++ b/library/Icingadb/Model/Host.php @@ -14,7 +14,6 @@ use ipl\Orm\Model; use ipl\Orm\Relations; use ipl\Orm\ResultSet; -use ipl\Sql\Expression; /** * Host model. @@ -116,10 +115,9 @@ public function getColumns() 'command_endpoint_name', 'command_endpoint_id' ]; + if (Backend::getDbSchemaVersion() >= 6) { $columns[] = 'affected_children'; - } else { - $columns['affected_children'] = new Expression('0'); } return $columns; @@ -127,7 +125,7 @@ public function getColumns() public function getColumnDefinitions() { - return [ + $columns = [ 'environment_id' => t('Environment Id'), 'name_checksum' => t('Host Name Checksum'), 'properties_checksum' => t('Host Properties Checksum'), @@ -165,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 02f72cfd6..8836ebeef 100644 --- a/library/Icingadb/Model/Service.php +++ b/library/Icingadb/Model/Service.php @@ -15,7 +15,6 @@ use ipl\Orm\Model; use ipl\Orm\Relations; use ipl\Orm\ResultSet; -use ipl\Sql\Expression; /** * @property string $id @@ -109,11 +108,9 @@ public function getColumns() 'command_endpoint_name', '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; @@ -121,7 +118,7 @@ public function getColumns() public function getColumnDefinitions() { - return [ + $columns = [ 'environment_id' => t('Environment Id'), 'name_checksum' => t('Service Name Checksum'), 'properties_checksum' => t('Service Properties Checksum'), @@ -157,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() 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 219ede2b2..2a4363c31 100644 --- a/library/Icingadb/Model/State.php +++ b/library/Icingadb/Model/State.php @@ -103,10 +103,9 @@ public function getColumns() 'next_check', 'next_update' ]; + if (Backend::getDbSchemaVersion() >= 6) { $columns[] = 'affects_children'; - } else { - $columns['affects_children'] = new Expression("'n'"); } return $columns; @@ -121,10 +120,13 @@ public function createBehaviors(Behaviors $behaviors) 'is_flapping', 'is_overdue', 'is_acknowledged', - 'in_downtime', - 'affects_children' + 'in_downtime' ])); + if (Backend::getDbSchemaVersion() >= 6) { + $behaviors->add(new BoolCast(['affects_children'])); + } + $behaviors->add(new MillisecondTimestamp([ 'last_update', 'last_state_change', diff --git a/library/Icingadb/Widget/Detail/ObjectDetail.php b/library/Icingadb/Widget/Detail/ObjectDetail.php index 132b37e1c..2a3f16269 100644 --- a/library/Icingadb/Widget/Detail/ObjectDetail.php +++ b/library/Icingadb/Widget/Detail/ObjectDetail.php @@ -44,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; @@ -618,13 +619,24 @@ protected function fetchCustomVars() */ protected function createRootProblems(): ?array { + if (Backend::getDbSchemaVersion() < 6 + && ! $this->object->state->is_reachable + && ! $this->object instanceof Service + ) { + return [ + HtmlElement::create('h2', null, Text::create(t('Root Problems'))), + new EmptyStateBar(t('Please update Icinga DB Web module to view root problems.')) + ]; + } + // 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. if ( $this->object->state->is_reachable - || Backend::getDbSchemaVersion() < 6 - || ($this->object instanceof Service && ! $this->object->has_problematic_parent) + || ($this->object instanceof Service + && (! isset($this->object->has_problematic_parent) || ! $this->object->has_problematic_parent) + ) ) { return null; } @@ -671,7 +683,7 @@ protected function createRootProblems(): ?array */ protected function createAffectedObjects(): ?array { - if (! $this->object->state->affects_children || Backend::getDbSchemaVersion() < 6) { + 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) {