Skip to content

Commit

Permalink
fix: Resolve review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
raviks789 committed Oct 8, 2024
1 parent 37daae8 commit 9506986
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 43 deletions.
13 changes: 3 additions & 10 deletions library/Icingadb/Model/RedundancyGroupParentStateSummary.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)'
Expand Down
82 changes: 51 additions & 31 deletions library/Icingadb/Widget/ItemList/RedundancyGroupListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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',
Expand Down Expand Up @@ -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',
Expand All @@ -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', '<hostname> has <state-text>'),
$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', '<hostname> is <state-text>'),
$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
Expand Down
2 changes: 2 additions & 0 deletions library/Icingadb/Widget/ObjectsStatistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -16,6 +17,7 @@
*/
class ObjectsStatistics extends ObjectStatistics
{
/** @var RedundancyGroupParentStateSummary Objects summary */
protected $summary;

public function __construct($summary)
Expand Down
13 changes: 11 additions & 2 deletions public/css/common.less
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 9506986

Please sign in to comment.