Skip to content

Commit

Permalink
fix: review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
raviks789 committed Oct 10, 2024
1 parent cd3b5a3 commit af32a03
Show file tree
Hide file tree
Showing 10 changed files with 134 additions and 135 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,65 +13,70 @@
/**
* Redundancy group's parent nodes summary
*
* @property int $objects_problem_handled
* @property int $objects_problem_unhandled
* @property int $objects_pending
* @property int $objects_total
* @property int $objects_ok
* @property int $objects_unknown_handled
* @property int $objects_unknown_unhandled
* @property int $objects_warning_handled
* @property int $objects_warning_unhandled
* @property int $nodes_problem_handled
* @property int $nodes_problem_unhandled
* @property int $nodes_pending
* @property int $nodes_total
* @property int $nodes_ok
* @property int $nodes_unknown_handled
* @property int $nodes_unknown_unhandled
* @property int $nodes_warning_handled
* @property int $nodes_warning_unhandled
*/
class RedundancyGroupParentStateSummary extends RedundancyGroup
class DependencyNodeSummary extends RedundancyGroup
{
public function getSummaryColumns(): array
{
return [
'objects_problem_handled' => new Expression(
'SUM(CASE WHEN redundancy_group_from_to_host_state.soft_state = 1'
. ' AND (redundancy_group_from_to_host_state.is_handled = \'y\''
. ' OR redundancy_group_from_to_host_state.is_reachable = \'n\') THEN 1 ELSE 0 END'
. ' + CASE WHEN redundancy_group_from_to_service_state.soft_state = 2'
'nodes_problem_handled' => new Expression(
'SUM(CASE WHEN (redundancy_group_from_to_service.id IS NOT NULL'
. ' AND redundancy_group_from_to_service_state.soft_state = 2'
. ' AND (redundancy_group_from_to_service_state.is_handled = \'y\''
. ' OR redundancy_group_from_to_service_state.is_reachable = \'n\') THEN 1 ELSE 0 END)'
. ' OR redundancy_group_from_to_service_state.is_reachable = \'n\'))'
. ' OR (redundancy_group_from_to_host_state.soft_state = 1'
. ' AND (redundancy_group_from_to_host_state.is_handled = \'y\''
. ' OR redundancy_group_from_to_host_state.is_reachable = \'n\')) THEN 1 ELSE 0 END)'
),
'objects_problem_unhandled' => new Expression(
'SUM(CASE WHEN redundancy_group_from_to_host_state.soft_state = 1'
. ' AND redundancy_group_from_to_host_state.is_handled = \'n\''
. ' AND redundancy_group_from_to_host_state.is_reachable = \'y\' THEN 1 ELSE 0 END'
. ' + CASE WHEN redundancy_group_from_to_service_state.soft_state = 2'
. ' AND redundancy_group_from_to_service_state.is_handled = \'n\''
. ' AND redundancy_group_from_to_service_state.is_reachable = \'y\' THEN 1 ELSE 0 END)'
'nodes_problem_unhandled' => new Expression(
'SUM(CASE WHEN (redundancy_group_from_to_service.id IS NOT NULL'
. ' AND redundancy_group_from_to_service_state.soft_state = 2'
. ' AND (redundancy_group_from_to_service_state.is_handled = \'n\''
. ' OR redundancy_group_from_to_service_state.is_reachable = \'y\'))'
. ' OR (redundancy_group_from_to_host_state.soft_state = 1'
. ' AND (redundancy_group_from_to_host_state.is_handled = \'n\''
. ' OR redundancy_group_from_to_host_state.is_reachable = \'y\')) THEN 1 ELSE 0 END)'
),
'objects_pending' => new Expression(
'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)'
'nodes_pending' => new Expression(
'SUM(CASE WHEN (redundancy_group_from_to_service.id IS NOT NULL'
. ' AND redundancy_group_from_to_service_state.soft_state = 99)'
. ' OR redundancy_group_from_to_host_state.soft_state = 99 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)'
'nodes_total' => new Expression(
'SUM(CASE WHEN redundancy_group_from_to_host.id IS NOT NULL'
. ' OR (redundancy_group_from_to_host.id IS NULL'
. ' AND redundancy_group_from_to_service.id) IS NOT NULL THEN 1 ELSE 0 END)'
),
'objects_ok' => new Expression(
'SUM(CASE WHEN redundancy_group_from_to_host_state.soft_state = 0 THEN 1 ELSE 0 END'
. ' + CASE WHEN redundancy_group_from_to_service_state.soft_state = 0 THEN 1 ELSE 0 END)'
'nodes_ok' => new Expression(
'SUM(CASE WHEN (redundancy_group_from_to_service.id IS NOT NULL'
. ' AND redundancy_group_from_to_service_state.soft_state = 0)'
. ' OR redundancy_group_from_to_service_state.soft_state = 0 THEN 1 ELSE 0 END)'
),
'objects_unknown_handled' => new Expression(
'nodes_unknown_handled' => new Expression(
'SUM(CASE WHEN redundancy_group_from_to_service_state.soft_state = 3'
. ' AND (redundancy_group_from_to_service_state.is_handled = \'y\''
. ' OR redundancy_group_from_to_service_state.is_reachable = \'n\') THEN 1 ELSE 0 END)'
),
'objects_unknown_unhandled' => new Expression(
'nodes_unknown_unhandled' => new Expression(
'SUM(CASE WHEN redundancy_group_from_to_service_state.soft_state = 3'
. ' AND redundancy_group_from_to_service_state.is_handled = \'n\''
. ' AND redundancy_group_from_to_service_state.is_reachable = \'y\' THEN 1 ELSE 0 END)'
),
'objects_warning_handled' => new Expression(
'nodes_warning_handled' => new Expression(
'SUM(CASE WHEN redundancy_group_from_to_service_state.soft_state = 1'
. ' AND (redundancy_group_from_to_service_state.is_handled = \'y\''
. ' OR redundancy_group_from_to_service_state.is_reachable = \'n\') THEN 1 ELSE 0 END)'
),
'objects_warning_unhandled' => new Expression(
'nodes_warning_unhandled' => new Expression(
'SUM(CASE WHEN redundancy_group_from_to_service_state.soft_state = 1'
. ' AND redundancy_group_from_to_service_state.is_handled = \'n\''
. ' AND redundancy_group_from_to_service_state.is_reachable = \'y\' THEN 1 ELSE 0 END)'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@
/**
* State badges for the objects
*/
class ObjectsStateBadges extends StateBadges
class DependencyNodeStateBadges extends StateBadges
{
protected function getType(): string
{
return 'objects';
return 'nodes';
}

protected function getPrefix(): string
{
return 'objects';
return 'nodes';
}

protected function assemble(): void
{
$this->addAttributes(['class' => 'objects-state-badges']);
$this->addAttributes(['class' => 'nodes-state-badges']);

$this->add(array_filter([
$this->createGroup('problem'),
Expand Down
51 changes: 51 additions & 0 deletions library/Icingadb/Widget/DependencyNodeStatistics.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

/* Icinga DB Web | (c) 2024 Icinga GmbH | GPLv2 */

namespace Icinga\Module\Icingadb\Widget;

use Icinga\Chart\Donut;
use Icinga\Module\Icingadb\Model\DependencyNodeSummary;
use Icinga\Module\Icingadb\Widget\Detail\ObjectStatistics;
use ipl\Html\Text;
use ipl\Html\ValidHtml;
use ipl\Html\HtmlString;

/**
* Dependency node statistics
*/
class DependencyNodeStatistics extends ObjectStatistics
{
/** @var DependencyNodeSummary Dependency node summary */
protected $summary;

public function __construct($summary)
{
$this->summary = $summary;
}

protected function createDonut(): ValidHtml
{
$donut = (new Donut())
->addSlice($this->summary->nodes_ok, ['class' => 'slice-state-ok'])
->addSlice($this->summary->nodes_warning_handled, ['class' => 'slice-state-warning-handled'])
->addSlice($this->summary->nodes_warning_unhandled, ['class' => 'slice-state-warning'])
->addSlice($this->summary->nodes_problem_handled, ['class' => 'slice-state-critical-handled'])
->addSlice($this->summary->nodes_problem_unhandled, ['class' => 'slice-state-critical'])
->addSlice($this->summary->nodes_unknown_handled, ['class' => 'slice-state-unknown-handled'])
->addSlice($this->summary->nodes_unknown_unhandled, ['class' => 'slice-state-unknown'])
->addSlice($this->summary->nodes_pending, ['class' => 'slice-state-pending']);

return HtmlString::create($donut->render());
}

protected function createTotal(): ValidHtml
{
return Text::create($this->shortenAmount($this->summary->nodes_total));
}

protected function createBadges(): ValidHtml
{
return new DependencyNodeStateBadges($this->summary);
}
}
2 changes: 1 addition & 1 deletion library/Icingadb/Widget/Detail/ObjectDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ protected function createPluginOutput(): array
'div',
[
'id' => 'check-output-' . $this->object->checkcommand_name,
'class' => ['collapsible', 'check-command-output'],
'class' => 'collapsible',
'data-visible-height' => 100
],
$pluginOutput
Expand Down
61 changes: 30 additions & 31 deletions library/Icingadb/Widget/ItemList/RedundancyGroupListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
use Icinga\Module\Icingadb\Common\Database;
use Icinga\Module\Icingadb\Common\ListItemCommonLayout;
use Icinga\Module\Icingadb\Model\RedundancyGroup;
use Icinga\Module\Icingadb\Model\RedundancyGroupParentStateSummary;
use Icinga\Module\Icingadb\Model\DependencyNodeSummary;
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 Icinga\Module\Icingadb\Widget\DependencyNodeStatistics;
use ipl\Html\BaseHtmlElement;
use ipl\I18n\Translation;
use ipl\Sql\Expression;
use ipl\Stdlib\Filter;
use ipl\Web\Widget\StateBall;
Expand All @@ -32,10 +33,11 @@ class RedundancyGroupListItem extends StateListItem
use ListItemCommonLayout;
use Auth;
use Database;
use Translation;

protected $baseAttributes = ['class' => ['list-item', 'redundancy-group-list-item']];

/** @var RedundancyGroupParentStateSummary Objects state summary */
/** @var DependencyNodeSummary Objects state summary */
protected $summary;

/** @var RedundancyGroupState */
Expand All @@ -48,22 +50,15 @@ 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'
])
$this->summary = DependencyNodeSummary::on($this->getDb())
->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
$this->summary->nodes_problem_handled
|| $this->summary->nodes_unknown_handled
|| $this->summary->nodes_warning_handled
);
}

Expand Down Expand Up @@ -101,28 +96,28 @@ protected function assembleCaption(BaseHtmlElement $caption): void
$members = RedundancyGroup::on($this->getDb())
->columns([
'id' => 'id',
'objects_output' => new Expression(
'CASE WHEN redundancy_group_from_to_host_state.output IS NULL'
'nodes_output' => new Expression(
'CASE WHEN redundancy_group_from_to_host.id IS NULL'
. ' THEN redundancy_group_from_to_service_state.output'
. ' ELSE redundancy_group_from_to_host_state.output END'
),
'objects_long_output' => new Expression(
'CASE WHEN redundancy_group_from_to_host_state.long_output IS NULL'
'nodes_long_output' => new Expression(
'CASE WHEN redundancy_group_from_to_host.id IS NULL'
. ' THEN redundancy_group_from_to_service_state.long_output'
. ' ELSE redundancy_group_from_to_host_state.long_output END'
),
'objects_checkcommand_name' => new Expression(
'CASE WHEN redundancy_group_from_to_host.checkcommand_name IS NULL'
'nodes_checkcommand_name' => new Expression(
'CASE WHEN redundancy_group_from_to_host.id IS NULL'
. ' THEN redundancy_group_from_to_service.checkcommand_name'
. ' ELSE redundancy_group_from_to_host.checkcommand_name END'
),
'objects_last_state_change' => new Expression(
'CASE WHEN redundancy_group_from_to_host_state.last_state_change IS NULL'
'nodes_last_state_change' => new Expression(
'CASE WHEN redundancy_group_from_to_host.id IS NULL'
. ' THEN redundancy_group_from_to_service_state.last_state_change'
. ' ELSE redundancy_group_from_to_host_state.last_state_change END'
),
'objects_severity' => new Expression(
'CASE WHEN redundancy_group_from_to_host_state.severity IS NULL'
'nodes_severity' => new Expression(
'CASE WHEN redundancy_group_from_to_host.id IS NULL'
. ' THEN redundancy_group_from_to_service_state.severity'
. ' ELSE redundancy_group_from_to_host_state.severity END'
)
Expand All @@ -136,8 +131,8 @@ protected function assembleCaption(BaseHtmlElement $caption): void
])
->filter(Filter::equal('id', $this->item->id))
->orderBy([
'objects_severity',
'objects_last_state_change',
'nodes_severity',
'nodes_last_state_change',
], SORT_DESC);

$this->applyRestrictions($members);
Expand All @@ -147,21 +142,25 @@ protected function assembleCaption(BaseHtmlElement $caption): void

if ($data) {
$caption->addHtml(new PluginOutputContainer(
(new PluginOutput($data->objects_output . "\n" . $data->objects_long_output))
->setCommandName($data->objects_checkcommand_name)
(new PluginOutput($data->nodes_output . "\n" . $data->nodes_long_output))
->setCommandName($data->nodes_checkcommand_name)
));
}

$caption->addHtml(new ObjectsStatistics($this->summary));
$caption->addHtml(new DependencyNodeStatistics($this->summary));
}

protected function assembleTitle(BaseHtmlElement $title): void
{
$title->addHtml($this->createSubject());
if ($this->state->failed) {
$title->addHtml(HtmlElement::create('span', null, Text::create(t('has no working objects'))));
$title->addHtml(HtmlElement::create(
'span',
null,
Text::create($this->translate('has no working objects'))
));
} else {
$title->addHtml(HtmlElement::create('span', null, Text::create(t('has working objects'))));
$title->addHtml(HtmlElement::create('span', null, Text::create($this->translate('has working objects'))));
}
}

Expand Down
56 changes: 0 additions & 56 deletions library/Icingadb/Widget/ObjectsStatistics.php

This file was deleted.

2 changes: 1 addition & 1 deletion public/css/common.less
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ div.show-more {
margin-left: 1em / 1.333em; // 1em / h2 font size
}

.object-detail .check-command-output .plugin-output {
.object-detail :not(.caption) > .plugin-output {
.rounded-corners(.25em);
background-color: @gray-lighter;
padding: .5em;
Expand Down
Loading

0 comments on commit af32a03

Please sign in to comment.