Fix Host/Service restrictions do not work for RedundanyGroup (#1221)

fixes https://github.com/Icinga/icingadb-web/issues/1220
This commit is contained in:
Johannes Meyer 2025-06-17 15:23:32 +02:00 committed by GitHub
commit b703552e65
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 74 additions and 60 deletions

View file

@ -53,13 +53,13 @@ class RedundancygroupController extends Controller
*/
protected function loadGroup(): void
{
$query = RedundancyGroup::on($this->getDb())
->with(['state'])
->filter(Filter::equal('id', $this->groupId));
$query = DependencyNode::on($this->getDb())
->with(['redundancy_group', 'redundancy_group.state'])
->filter(Filter::equal('redundancy_group_id', $this->groupId));
$this->applyRestrictions($query);
$this->group = $query->first();
$this->group = $query->first()?->redundancy_group;
if ($this->group === null) {
$this->httpNotFound($this->translate('Redundancy Group not found'));

View file

@ -13,7 +13,6 @@ use ipl\Orm\Defaults;
use ipl\Orm\Model;
use ipl\Orm\Query;
use ipl\Orm\Relations;
use ipl\Stdlib\Filter;
/**
* Redundancy group model.
@ -86,11 +85,10 @@ class RedundancyGroup extends Model
->through(DependencyNode::class);
}
public function createDefaults(Defaults $defaults)
public function createDefaults(Defaults $defaults): void
{
$defaults->add('summary', function (RedundancyGroup $group) {
$summary = RedundancyGroupSummary::on(Backend::getDb())
->filter(Filter::equal('id', $group->id));
$summary = RedundancyGroupSummary::for($group->id, Backend::getDb());
$this->applyRestrictions($summary);

View file

@ -4,10 +4,11 @@
namespace Icinga\Module\Icingadb\Model;
use InvalidArgumentException;
use ipl\Orm\Query;
use ipl\Sql\Connection;
use ipl\Sql\Expression;
use ipl\Sql\Select;
use ipl\Stdlib\Filter;
/**
* Redundancy group's summary
@ -21,8 +22,10 @@ use ipl\Sql\Select;
* @property int $nodes_unknown_unhandled
* @property int $nodes_warning_handled
* @property int $nodes_warning_unhandled
* @property int $nodes_acknowledged
* @property int $nodes_problems_unacknowledged
*/
class RedundancyGroupSummary extends RedundancyGroup
class RedundancyGroupSummary extends DependencyNode
{
public function getSummaryColumns(): array
{
@ -35,9 +38,9 @@ class RedundancyGroupSummary extends RedundancyGroup
. ' ELSE 0'
. ' END)',
[
'from.to.service_id',
'from.to.service.state.soft_state',
'from.to.host.state.soft_state',
'service_id',
'service.state.soft_state',
'host.state.soft_state',
]
),
'nodes_problem_handled' => new Expression(
@ -47,13 +50,13 @@ class RedundancyGroupSummary extends RedundancyGroup
. ' ELSE 0'
. ' END)',
[
'from.to.service_id',
'from.to.service.state.soft_state',
'from.to.service.state.is_handled',
'from.to.service.state.is_reachable',
'from.to.host.state.soft_state',
'from.to.host.state.is_handled',
'from.to.host.state.is_reachable',
'service_id',
'service.state.soft_state',
'service.state.is_handled',
'service.state.is_reachable',
'host.state.soft_state',
'host.state.is_handled',
'host.state.is_reachable',
]
),
'nodes_problem_unhandled' => new Expression(
@ -63,13 +66,13 @@ class RedundancyGroupSummary extends RedundancyGroup
. ' ELSE 0'
. ' END)',
[
'from.to.service_id',
'from.to.service.state.soft_state',
'from.to.service.state.is_handled',
'from.to.service.state.is_reachable',
'from.to.host.state.soft_state',
'from.to.host.state.is_handled',
'from.to.host.state.is_reachable',
'service_id',
'service.state.soft_state',
'service.state.is_handled',
'service.state.is_reachable',
'host.state.soft_state',
'host.state.is_handled',
'host.state.is_reachable',
]
),
'nodes_pending' => new Expression(
@ -79,9 +82,9 @@ class RedundancyGroupSummary extends RedundancyGroup
. ' ELSE 0'
. ' END)',
[
'from.to.service_id',
'from.to.service.state.soft_state',
'from.to.host.state.soft_state',
'service_id',
'service.state.soft_state',
'host.state.soft_state',
]
),
'nodes_unknown_handled' => new Expression(
@ -90,10 +93,10 @@ class RedundancyGroupSummary extends RedundancyGroup
. ' ELSE 0'
. ' END)',
[
'from.to.service_id',
'from.to.service.state.soft_state',
'from.to.service.state.is_handled',
'from.to.service.state.is_reachable'
'service_id',
'service.state.soft_state',
'service.state.is_handled',
'service.state.is_reachable'
]
),
'nodes_unknown_unhandled' => new Expression(
@ -102,10 +105,10 @@ class RedundancyGroupSummary extends RedundancyGroup
. ' ELSE 0'
. ' END)',
[
'from.to.service_id',
'from.to.service.state.soft_state',
'from.to.service.state.is_handled',
'from.to.service.state.is_reachable'
'service_id',
'service.state.soft_state',
'service.state.is_handled',
'service.state.is_reachable'
]
),
'nodes_warning_handled' => new Expression(
@ -114,10 +117,10 @@ class RedundancyGroupSummary extends RedundancyGroup
. ' ELSE 0'
. ' END)',
[
'from.to.service_id',
'from.to.service.state.soft_state',
'from.to.service.state.is_handled',
'from.to.service.state.is_reachable'
'service_id',
'service.state.soft_state',
'service.state.is_handled',
'service.state.is_reachable'
]
),
'nodes_warning_unhandled' => new Expression(
@ -126,10 +129,10 @@ class RedundancyGroupSummary extends RedundancyGroup
. ' ELSE 0'
. ' END)',
[
'from.to.service_id',
'from.to.service.state.soft_state',
'from.to.service.state.is_handled',
'from.to.service.state.is_reachable'
'service_id',
'service.state.soft_state',
'service.state.is_handled',
'service.state.is_reachable'
]
),
'nodes_acknowledged' => new Expression(
@ -139,9 +142,9 @@ class RedundancyGroupSummary extends RedundancyGroup
. ' ELSE 0'
. ' END)',
[
'from.to.service_id',
'from.to.service.state.is_acknowledged',
'from.to.host.state.is_acknowledged',
'service_id',
'service.state.is_acknowledged',
'host.state.is_acknowledged',
]
),
'nodes_problems_unacknowledged' => new Expression(
@ -151,11 +154,11 @@ class RedundancyGroupSummary extends RedundancyGroup
. ' ELSE 0'
. ' END)',
[
'from.to.service_id',
'from.to.service.state.is_problem',
'from.to.service.state.is_acknowledged',
'from.to.host.state.is_problem',
'from.to.host.state.is_acknowledged',
'service_id',
'service.state.is_problem',
'service.state.is_acknowledged',
'host.state.is_problem',
'host.state.is_acknowledged',
]
)
];
@ -169,17 +172,30 @@ class RedundancyGroupSummary extends RedundancyGroup
$m = $q->getModel();
$q->columns($m->getSummaryColumns());
$q->on($q::ON_SELECT_ASSEMBLED, function (Select $select) use ($q) {
$model = $q->getModel();
$groupBy = $q->getResolver()->qualifyColumnsAndAliases((array) $model->getKeyName(), $model, false);
$select->groupBy($groupBy);
});
return $q;
}
/**
* Get the summary query for the given redundancy group id
*
* @param string $groupId The redundancy group id for summary
* @param Connection $db Db connection to use
*
* @return Query
*/
public static function for(string $groupId, Connection $db): Query
{
return self::on($db)
->filter(Filter::equal('child.redundancy_group.id', $groupId));
}
public function getColumns(): array
{
return array_merge(parent::getColumns(), $this->getSummaryColumns());
}
public function getDefaultSort(): array
{
return [];
}
}