Skip to content

Commit

Permalink
fix: resolve JM's review
Browse files Browse the repository at this point in the history
  • Loading branch information
raviks789 committed Oct 31, 2024
1 parent cab45ad commit 86b2ceb
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions library/Icingadb/Widget/Detail/ObjectDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Icinga\Module\Icingadb\Common\Macros;
use Icinga\Module\Icingadb\Compat\CompatHost;
use Icinga\Module\Icingadb\Model\CustomvarFlat;
use Icinga\Module\Icingadb\Model\DependencyEdge;
use Icinga\Module\Icingadb\Model\DependencyNode;
use Icinga\Module\Icingadb\Model\Service;
use Icinga\Module\Icingadb\Model\UnreachableParent;
Expand All @@ -38,6 +39,8 @@
use Icinga\Module\Icingadb\Util\PluginOutput;
use Icinga\Module\Icingadb\Widget\ItemList\DowntimeList;
use Icinga\Module\Icingadb\Widget\ShowMore;
use ipl\Sql\Expression;
use ipl\Sql\Filter\Exists;
use ipl\Web\Widget\CopyToClipboard;
use ipl\Web\Widget\EmptyState;
use ipl\Web\Widget\HorizontalKeyValue;
Expand Down Expand Up @@ -692,15 +695,39 @@ protected function createAffectedObjects(): ?array
'host.state.last_state_change',
'service.state.severity',
'service.state.last_state_change',
'redundancy_group.state.failed',
'redundancy_group.state.last_state_change'
], SORT_DESC);

$failedEdges = DependencyEdge::on($this->getDb())
->utilize('child')
->columns([new Expression('1')])
->filter(Filter::equal('dependency.state.failed', 'y'));

if ($this->object instanceof Host) {
$affectedObjects->filter(Filter::equal('parent.host.id', $this->object->id));
$failedEdges
->filter(Filter::equal('parent.host.id', $this->object->id))
->filter(Filter::unlike('parent.service.id', '*'));
} else {
$affectedObjects->filter(Filter::equal('parent.service.id', $this->object->id));
$failedEdges->filter(Filter::equal('parent.service.id', $this->object->id));
}

$failedEdges->getFilter()->metaData()->set('forceOptimization', false);
$edgeResolver = $failedEdges->getResolver();

$childAlias = $edgeResolver->getAlias(
$edgeResolver->resolveRelation($failedEdges->getModel()->getTableName() . '.child')->getTarget()
);

$affectedObjects->filter(new Exists(
$failedEdges->assembleSelect()
->where(
"$childAlias.id = "
. $affectedObjects->getResolver()
->qualifyColumn('id', $affectedObjects->getModel()->getTableName())
)
));

$this->applyRestrictions($affectedObjects);

return [
Expand Down

0 comments on commit 86b2ceb

Please sign in to comment.