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

Show affected objects in the object detail for failed dependencies #1072

Merged
merged 1 commit into from
Oct 31, 2024
Merged
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
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())
nilmerg marked this conversation as resolved.
Show resolved Hide resolved
->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'
nilmerg marked this conversation as resolved.
Show resolved Hide resolved
], 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
Loading