From 9506986d71018913436c1774aa6e8af914d7fa6c Mon Sep 17 00:00:00 2001 From: raviks789 Date: Wed, 2 Oct 2024 17:10:52 +0200 Subject: [PATCH] fix: Resolve review comments --- .../RedundancyGroupParentStateSummary.php | 13 +-- .../ItemList/RedundancyGroupListItem.php | 82 ++++++++++++------- library/Icingadb/Widget/ObjectsStatistics.php | 2 + public/css/common.less | 13 ++- 4 files changed, 67 insertions(+), 43 deletions(-) diff --git a/library/Icingadb/Model/RedundancyGroupParentStateSummary.php b/library/Icingadb/Model/RedundancyGroupParentStateSummary.php index c2e444686..6cf4cf3a1 100644 --- a/library/Icingadb/Model/RedundancyGroupParentStateSummary.php +++ b/library/Icingadb/Model/RedundancyGroupParentStateSummary.php @@ -13,12 +13,11 @@ /** * Redundancy group's parent nodes summary * - * @property int $objects_down_critical_handled - * @property int $objects_down_critical_unhandled + * @property int $objects_problem_handled + * @property int $objects_problem_unhandled * @property int $objects_pending - * @property int $objects_problems_unacknowledged * @property int $objects_total - * @property int $objects_up_ok + * @property int $objects_ok * @property int $objects_unknown_handled * @property int $objects_unknown_unhandled * @property int $objects_warning_handled @@ -49,12 +48,6 @@ public function getSummaryColumns(): array 'SUM(CASE WHEN redundancy_group_from_to_host_state.soft_state = 99 THEN 1 ELSE 0 END' . ' + CASE WHEN redundancy_group_from_to_service_state.soft_state = 99 THEN 1 ELSE 0 END)' ), - 'objects_problems_unacknowledged' => new Expression( - 'SUM(CASE WHEN redundancy_group_from_to_host_state.is_problem = \'y\'' - . ' AND redundancy_group_from_to_host_state.is_acknowledged = \'n\' THEN 1 ELSE 0 END' - . ' + CASE WHEN redundancy_group_from_to_service_state.is_problem = \'y\'' - . ' AND redundancy_group_from_to_service_state.is_acknowledged = \'n\' THEN 1 ELSE 0 END)' - ), 'objects_total' => new Expression( 'SUM(CASE WHEN redundancy_group_from_to_host.id IS NOT NULL THEN 1 ELSE 0 END)' . '+ SUM(CASE WHEN redundancy_group_from_to_service.id IS NOT NULL THEN 1 ELSE 0 END)' diff --git a/library/Icingadb/Widget/ItemList/RedundancyGroupListItem.php b/library/Icingadb/Widget/ItemList/RedundancyGroupListItem.php index 8389470c1..69fdba148 100644 --- a/library/Icingadb/Widget/ItemList/RedundancyGroupListItem.php +++ b/library/Icingadb/Widget/ItemList/RedundancyGroupListItem.php @@ -9,11 +9,11 @@ use Icinga\Module\Icingadb\Common\ListItemCommonLayout; use Icinga\Module\Icingadb\Model\RedundancyGroup; use Icinga\Module\Icingadb\Model\RedundancyGroupParentStateSummary; +use Icinga\Module\Icingadb\Model\RedundancyGroupState; use Icinga\Module\Icingadb\Util\PluginOutput; use Icinga\Module\Icingadb\Widget\PluginOutputContainer; use Icinga\Module\Icingadb\Widget\ObjectsStatistics; use ipl\Html\BaseHtmlElement; -use ipl\Html\Html; use ipl\Sql\Expression; use ipl\Stdlib\Filter; use ipl\Web\Widget\StateBall; @@ -35,6 +35,38 @@ class RedundancyGroupListItem extends StateListItem protected $baseAttributes = ['class' => ['list-item', 'redundancy-group-list-item']]; + /** @var RedundancyGroupParentStateSummary Objects state summary */ + protected $summary; + + /** @var RedundancyGroupState */ + protected $state; + + /** @var bool Whether the redundancy group has been handled */ + protected $isHandled = false; + + protected function init(): void + { + parent::init(); + + $this->summary = RedundancyGroupParentStateSummary::on($this->getDb()) + ->with([ + 'from', + 'from.to.host', + 'from.to.host.state', + 'from.to.service', + 'from.to.service.state' + ]) + ->filter(Filter::equal('id', $this->item->id)) + ->first(); + + $this->isHandled = $this->state->failed + && ( + $this->summary->objects_problem_handled + || $this->summary->objects_unknown_handled + || $this->summary->objects_warning_handled + ); + } + protected function getStateBallSize(): string { return StateBall::SIZE_LARGE; @@ -56,24 +88,16 @@ protected function createSubject(): BaseHtmlElement protected function assembleVisual(BaseHtmlElement $visual): void { - $visual->addHtml(new StateBall($this->item->state->getStateText(), $this->getStateBallSize())); + $stateBall = new StateBall($this->state->getStateText(), $this->getStateBallSize()); + if ($this->isHandled) { + $stateBall->getAttributes()->add('class', 'handled'); + } + + $visual->addHtml($stateBall); } protected function assembleCaption(BaseHtmlElement $caption): void { - $filter = Filter::equal('id', $this->item->id); - $relations = [ - 'from', - 'from.to.host', - 'from.to.host.state', - 'from.to.service', - 'from.to.service.state' - ]; - - $summary = RedundancyGroupParentStateSummary::on($this->getDb()) - ->with($relations) - ->filter($filter); - $members = RedundancyGroup::on($this->getDb()) ->columns([ 'id' => 'id', @@ -103,8 +127,14 @@ protected function assembleCaption(BaseHtmlElement $caption): void . ' ELSE redundancy_group_from_to_host_state.severity END' ) ]) - ->with($relations) - ->filter($filter) + ->with([ + 'from', + 'from.to.host', + 'from.to.host.state', + 'from.to.service', + 'from.to.service.state' + ]) + ->filter(Filter::equal('id', $this->item->id)) ->orderBy([ 'objects_severity', 'objects_last_state_change', @@ -122,27 +152,17 @@ protected function assembleCaption(BaseHtmlElement $caption): void )); } - $caption->addHtml(new ObjectsStatistics($summary->first())); + $caption->addHtml(new ObjectsStatistics($this->summary)); } protected function assembleTitle(BaseHtmlElement $title): void { - $subject = $this->createSubject(); + $title->addHtml($this->createSubject()); if ($this->state->failed) { - $stateTextElement = Html::sprintf( - t('%s has %s', ' has '), - $subject, - new HtmlElement('span', Attributes::create(['class' => 'state-text']), Text::create('FAILED')) - ); + $title->addHtml(HtmlElement::create('span', null, Text::create(t('has no working objects')))); } else { - $stateTextElement = Html::sprintf( - t('%s is %s', ' is '), - $subject, - new HtmlElement('span', Attributes::create(['class' => 'state-text']), Text::create('OK')) - ); + $title->addHtml(HtmlElement::create('span', null, Text::create(t('has working objects')))); } - - $title->addHtml($stateTextElement); } protected function assemble(): void diff --git a/library/Icingadb/Widget/ObjectsStatistics.php b/library/Icingadb/Widget/ObjectsStatistics.php index 39fb1011b..721b8ec74 100644 --- a/library/Icingadb/Widget/ObjectsStatistics.php +++ b/library/Icingadb/Widget/ObjectsStatistics.php @@ -6,6 +6,7 @@ use Icinga\Chart\Donut; +use Icinga\Module\Icingadb\Model\RedundancyGroupParentStateSummary; use Icinga\Module\Icingadb\Widget\Detail\ObjectStatistics; use ipl\Html\Text; use ipl\Html\ValidHtml; @@ -16,6 +17,7 @@ */ class ObjectsStatistics extends ObjectStatistics { + /** @var RedundancyGroupParentStateSummary Objects summary */ protected $summary; public function __construct($summary) diff --git a/public/css/common.less b/public/css/common.less index c21cdfa31..a32600562 100644 --- a/public/css/common.less +++ b/public/css/common.less @@ -412,8 +412,17 @@ form[name="form_confirm_removal"] { padding: 0 0.25em; } -.state-ball, -.state-badge { +.state-ball { + &.state-unreachable { + background-color: @color-critical; + } + + &.state-reachable { + background-color: @color-ok; + } +} + +.state-badge { &.state-problem { background-color: @color-critical; }