Skip to content

Commit

Permalink
Show affected objects in the object detail for failed dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
raviks789 committed Oct 31, 2024
1 parent a7fb07b commit 4f47f6e
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
1 change: 1 addition & 0 deletions library/Icingadb/Widget/Detail/HostDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ protected function assemble()
401 => $this->createDowntimes(),
500 => $this->createGroups(),
501 => $this->createNotifications(),
510 => $this->createAffectedObjects(),
600 => $this->createCheckStatistics(),
601 => $this->createPerformanceData(),
700 => $this->createCustomVars(),
Expand Down
80 changes: 80 additions & 0 deletions library/Icingadb/Widget/Detail/ObjectDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
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;
use Icinga\Module\Icingadb\Redis\VolatileStateResults;
Expand All @@ -37,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 @@ -657,4 +661,80 @@ protected function createRootProblems(): ?array
)
];
}

/**
* Create a list of objects affected by the object that is a part of failed dependency
*
* @return ?BaseHtmlElement[]
*/
protected function createAffectedObjects(): ?array
{
if (! $this->object->state->affects_children) {
return null;
}

$affectedObjects = DependencyNode::on($this->getDb())
->with([
'redundancy_group',
'redundancy_group.state',
'host',
'host.state',
'host.icon_image',
'host.state.last_comment',
'service',
'service.state',
'service.icon_image',
'service.state.last_comment',
'service.host',
'service.host.state'
])
->setResultSetClass(VolatileStateResults::class)
->limit(5)
->orderBy([
'host.state.severity',
'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) {
$failedEdges
->filter(Filter::equal('parent.host.id', $this->object->id))
->filter(Filter::unlike('parent.service.id', '*'));
} else {
$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 [
HtmlElement::create('h2', null, Text::create(t('Affected Objects'))),
(new DependencyNodeList($affectedObjects))->setEmptyStateMessage(
t('You are not authorized to view these objects.')
)
];
}
}
1 change: 1 addition & 0 deletions library/Icingadb/Widget/Detail/ServiceDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ protected function assemble()
401 => $this->createDowntimes(),
500 => $this->createGroups(),
501 => $this->createNotifications(),
510 => $this->createAffectedObjects(),
600 => $this->createCheckStatistics(),
601 => $this->createPerformanceData(),
700 => $this->createCustomVars(),
Expand Down

0 comments on commit 4f47f6e

Please sign in to comment.