Skip to content

Handle rule filter serialization#469

Open
BastianLedererIcinga wants to merge 6 commits into
mainfrom
rule-filter-handling
Open

Handle rule filter serialization#469
BastianLedererIcinga wants to merge 6 commits into
mainfrom
rule-filter-handling

Conversation

@BastianLedererIcinga
Copy link
Copy Markdown
Contributor

@BastianLedererIcinga BastianLedererIcinga commented Apr 28, 2026

resolve #466

Introduce RuleSerializer to create Json from a configured filter.

Introduce Icinga\Module\Notifications\Hook\V2 which no longer requires serializeRuleFilter() and getRuleFilterTargets() as they are now obsolete.

Adjust EventRuleController to skip target selection use the new RuleSerializer.

require Icinga/ipl-web#376

@cla-bot cla-bot Bot added the cla/signed CLA is signed by all contributors of a PR label Apr 28, 2026
@BastianLedererIcinga BastianLedererIcinga force-pushed the rule-filter-handling branch 2 times, most recently from e3da66a to b8a38fc Compare April 28, 2026 08:02
@BastianLedererIcinga BastianLedererIcinga force-pushed the rule-filter-handling branch 8 times, most recently from d5fe2f5 to 3bf7acb Compare May 7, 2026 08:23
@nilmerg nilmerg self-requested a review May 11, 2026 13:36
Comment thread library/Notifications/Util/RuleSerializer.php Outdated
Introduce a new version of the `SourceHook` interface for v 1.0
`RuleFilterSuggestions` use the relevant functions of the `V2\SourceHook`
to provide suggestions when editing event-rule filters
Copy link
Copy Markdown
Member

@nilmerg nilmerg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't look at the controller or suggestions yet.

*
* @return array<string>
*/
public function getJsonPaths(Condition $condition): array;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This forces integrations to implement a cache of sorts to prevent issuing unnecessary queries in case a database is required. Please pass over all conditions at once.

*
* @return bool
*/
public function shouldShowRelationFor(string $column): bool;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's for the integration to decide. Remove this.

$icon = new Icon('share-nodes');

foreach (Hook::all('Notifications/v1/Source') as $hook) {
foreach (Hook::all('Notifications/v2/Source') as $hook) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's a way to get rid of this loop and getSourceType() in the interface. Right now there can only be a single hook anyway, and that's where Hook::first() comes into play.

Please try to incorporate the source type in the name of the hook for v2. In case of icinga, that'd be: Notifications/v2/IcingaSource

The hook can then be loaded this way:

$hook = Hook::first(sprintf('Notifications/v2/%sSource', \ipl\Stdlib\Str::camel($this->type));

Please note that this fundamentally changes how sources are configured. This way the available integrations cannot be known beforehand (before an event came in) so the type field must be a free text field. This collides with #450 somewhat, but that's already in progress and based on this anyway.

Once #461 is a thing, the source configuration is mainly for generic sources as well. So it doesn't hurt either.

*/
public function getJson(): string
{
$result = ['qs' => (new Renderer($this->filter))->render()];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use QueryString::render()

}

$result['rules'] = $rules;
return $result;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

an empty line before return pls, always unless it's the sole statement in a block.

*
* @return string
*/
protected function preprocessValue(string $value): string
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

asRegularExpression()
toRegularExpression()
createRegularExpression()
🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla/signed CLA is signed by all contributors of a PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Handle rule filter rendering and serialization on our own again

2 participants