Skip to content

Commit

Permalink
Hide unreachable parents in root problems (#1073)
Browse files Browse the repository at this point in the history
  • Loading branch information
nilmerg authored Jan 15, 2025
2 parents 8e5a816 + 30269ef commit 1eb1e72
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 20 deletions.
31 changes: 28 additions & 3 deletions library/Icingadb/Model/RedundancyGroupState.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
namespace Icinga\Module\Icingadb\Model;

use DateTime;
use Icinga\Module\Icingadb\Common\Icons;
use ipl\Orm\Behavior\Binary;
use ipl\Orm\Behavior\BoolCast;
use ipl\Orm\Behavior\MillisecondTimestamp;
use ipl\Orm\Behaviors;
use ipl\Orm\Model;
use ipl\Orm\Query;
use ipl\Orm\Relations;
use ipl\Web\Widget\Icon;

/**
* Redundancy group state model.
Expand All @@ -20,6 +22,7 @@
* @property string $environment_id
* @property string $redundancy_group_id
* @property bool $failed
* @property bool $is_reachable
* @property DateTime $last_state_change
*
* @property RedundancyGroup|Query $redundancy_group
Expand All @@ -42,6 +45,7 @@ public function getColumns(): array
'environment_id',
'redundancy_group_id',
'failed',
'is_reachable',
'last_state_change'
];
}
Expand All @@ -54,7 +58,8 @@ public function createBehaviors(Behaviors $behaviors): void
'redundancy_group_id'
]));
$behaviors->add(new BoolCast([
'failed'
'failed',
'is_reachable'
]));
$behaviors->add(new MillisecondTimestamp([
'last_state_change'
Expand All @@ -66,9 +71,29 @@ public function createRelations(Relations $relations): void
$relations->belongsTo('redundancy_group', RedundancyGroup::class);
}

/**
* Get the state text for the redundancy group state
*
* Do not use this method to label the state of a redundancy group.
*
* @return string
*/
public function getStateText(): string
{
// The method should only be called to fake state balls and not to show the group's state
return $this->failed ? 'unreachable' : 'reachable';
return $this->failed ? 'critical' : 'ok';
}

/**
* Get the state icon
*
* @return ?Icon
*/
public function getIcon(): ?Icon
{
if (! $this->is_reachable) {
return new Icon(Icons::UNREACHABLE);
}

return null;
}
}
21 changes: 17 additions & 4 deletions library/Icingadb/Model/UnreachableParent.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,23 @@ public static function on(Connection $db, Model $root = null): Query
self::selectNodes($db, $root),
'unreachable_parent',
true
)->where([
'unreachable_parent.level > ?' => 0,
'unreachable_parent.is_group_member = ?' => 0
]);
);

$query->filter(Filter::all(
Filter::greaterThan('level', 0),
Filter::equal('is_group_member', 0),
Filter::any(
Filter::equal('service.state.affects_children', 'y'),
Filter::all(
Filter::unlike('service_id', '*'),
Filter::equal('host.state.affects_children', 'y')
),
Filter::all(
Filter::equal('redundancy_group.state.failed', 'y'),
Filter::equal('redundancy_group.state.is_reachable', 'y')
)
)
));

return $query;
}
Expand Down
2 changes: 1 addition & 1 deletion library/Icingadb/Widget/Detail/RedundancyGroupDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected function createExtensions(): array
*/
protected function createRootProblems(): ?array
{
if (! $this->group->state->failed) {
if ($this->group->state->is_reachable) {
return null;
}

Expand Down
5 changes: 4 additions & 1 deletion library/Icingadb/Widget/Detail/RedundancyGroupHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ public function __construct(RedundancyGroup $object, RedundancyGroupSummary $sum

protected function assembleVisual(BaseHtmlElement $visual): void
{
$visual->addHtml(new StateBall($this->object->state->getStateText(), $this->getStateBallSize()));
$stateBall = new StateBall($this->object->state->getStateText(), $this->getStateBallSize());
$stateBall->add($this->object->state->getIcon());

$visual->addHtml($stateBall);
}

protected function assembleTitle(BaseHtmlElement $title): void
Expand Down
5 changes: 4 additions & 1 deletion library/Icingadb/Widget/ItemList/RedundancyGroupListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ protected function createSubject(): Link

protected function assembleVisual(BaseHtmlElement $visual): void
{
$visual->addHtml(new StateBall($this->state->getStateText(), $this->getStateBallSize()));
$stateBall = new StateBall($this->state->getStateText(), $this->getStateBallSize());
$stateBall->add($this->state->getIcon());

$visual->addHtml($stateBall);
}

protected function assembleCaption(BaseHtmlElement $caption): void
Expand Down
10 changes: 0 additions & 10 deletions public/css/common.less
Original file line number Diff line number Diff line change
Expand Up @@ -412,13 +412,3 @@ form[name="form_confirm_removal"] {
padding: 0 0.25em;
.rounded-corners();
}

.state-ball {
&.state-unreachable {
background-color: @color-critical;
}

&.state-reachable {
background-color: @color-ok;
}
}

0 comments on commit 1eb1e72

Please sign in to comment.