Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide unreachable parents in root problems #1073

Open
wants to merge 6 commits into
base: dependencies
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion library/Icingadb/Model/Behavior/HasProblematicParent.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ public function rewriteColumn($column, ?string $relation = null): ?AliasedExpres
->columns([new Expression('1')])
->utilize('from')
->limit(1)
->filter(Filter::equal('dependency.state.failed', 'y'));
->filter(Filter::any(
Filter::equal('dependency.state.failed', 'y'),
Filter::equal('parent.redundancy_group.state.failed', 'y'),
Filter::equal('parent.redundancy_group.state.is_reachable', 'n')
));

$subQueryResolver = $subQuery->getResolver()->setAliasPrefix('hpp_');
$subQueryTarget = $subQueryResolver->resolveRelation($subQueryModel->getTableName() . '.from')->getTarget();
Expand Down
29 changes: 26 additions & 3 deletions library/Icingadb/Model/RedundancyGroupState.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,23 @@
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.
*
* @property string $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 @@ -40,6 +43,7 @@ public function getColumns(): array
return [
'redundancy_group_id',
'failed',
'is_reachable',
'last_state_change'
];
}
Expand All @@ -51,7 +55,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 @@ -63,9 +68,27 @@ 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);
}
}
}
20 changes: 15 additions & 5 deletions library/Icingadb/Model/UnreachableParent.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,20 @@ 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::equal('redundancy_group.state.failed', 'y')
)
));

return $query;
}
Expand Down Expand Up @@ -144,7 +154,7 @@ private static function selectNodes(Connection $db, Model $root): Select
]);
$nodeQuery->filter(Filter::any(
Filter::equal('dependency.state.failed', 'y'),
Filter::equal('to.redundancy_group.state.failed', 'y')
Filter::equal('to.redundancy_group.state.is_reachable', 'n')
));

$nodeSelect = $nodeQuery->assembleSelect();
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;
}
}
Loading