Skip to content

Add V2/Source hook for icinga-notifications-web#1369

Open
sukhwinder33445 wants to merge 9 commits into
mainfrom
update-notifications-hook
Open

Add V2/Source hook for icinga-notifications-web#1369
sukhwinder33445 wants to merge 9 commits into
mainfrom
update-notifications-hook

Conversation

@sukhwinder33445
Copy link
Copy Markdown
Contributor

@sukhwinder33445 sukhwinder33445 commented Apr 28, 2026

This PR adds a new V2/Source hook implementation to integrate with the V2/SourceHook interface from icinga-notifications-web.

Changes:

  • Add V2/Source hook: getRuleFilterEditor() no longer performs JSON decoding or type checks on $filter — the param now contains the query string directly. Everything else in this method remains the same.
  • SuggestController: Drop now obsolete type param. Since the V2 hook does not support filter targets, this parameter is no longer needed.

resolves: #1365
require: Icinga/icinga-notifications-web#469

@cla-bot cla-bot Bot added the cla/signed CLA is signed by all contributors of a PR label Apr 28, 2026
@sukhwinder33445 sukhwinder33445 force-pushed the update-notifications-hook branch 2 times, most recently from ded5a93 to c3c926f Compare April 28, 2026 07:56
@sukhwinder33445 sukhwinder33445 requested a review from Copilot April 28, 2026 07:56

This comment was marked as resolved.

@sukhwinder33445 sukhwinder33445 force-pushed the update-notifications-hook branch 2 times, most recently from c3c926f to 9f7ac77 Compare April 28, 2026 08:22
@sukhwinder33445 sukhwinder33445 requested a review from Copilot April 28, 2026 08:27
@sukhwinder33445 sukhwinder33445 self-assigned this Apr 28, 2026

This comment was marked as resolved.

@sukhwinder33445 sukhwinder33445 force-pushed the update-notifications-hook branch 2 times, most recently from 7d02f46 to 680cc30 Compare April 28, 2026 09:11
@BastianLedererIcinga
Copy link
Copy Markdown
Contributor

I reduced the SourceHook interface in Icinga/icinga-notifications-web#469, feel free to comment if you'd like anything changed about it.
Adjusting to the new implementation shouldn't be too complicated, the callables that are currently being registered on the SearchEditor in Source::getRuleFilterEditor() can be used to implement the new interface functions with minor adjustments.

@sukhwinder33445 sukhwinder33445 force-pushed the update-notifications-hook branch 3 times, most recently from 912ca23 to f1465b1 Compare May 5, 2026 12:34
@sukhwinder33445 sukhwinder33445 force-pushed the update-notifications-hook branch 4 times, most recently from 497472d to f027079 Compare May 6, 2026 12:40

This comment was marked as resolved.

@sukhwinder33445 sukhwinder33445 force-pushed the update-notifications-hook branch from f027079 to ee166d4 Compare May 6, 2026 14:16
Comment thread library/Icingadb/ProvidedHook/Notifications/V2/Source.php Outdated
@sukhwinder33445 sukhwinder33445 force-pushed the update-notifications-hook branch 2 times, most recently from 4da5fe6 to bb489df Compare May 11, 2026 06:41
@sukhwinder33445 sukhwinder33445 force-pushed the update-notifications-hook branch from bb489df to b6cf2b9 Compare May 11, 2026 06:55
@nilmerg nilmerg self-requested a review May 11, 2026 13:36
Copy link
Copy Markdown
Contributor

@BastianLedererIcinga BastianLedererIcinga left a comment

Choose a reason for hiding this comment

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

This is what I noticed for the current state, but some of it may no longer apply once the changes regarding jsonPath are implemented.

Comment thread library/Icingadb/ProvidedHook/Notifications/V2/Source.php Outdated
}

$path = preg_replace('/^(?:host|service)\.vars\./', '', $column);
$path = substr($path, strlen($var->name) + 1);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is not reliable, take this example:

object Host "simple_array_host" {
    check_command = "dummy"
    address = "127.0.0.1"

    vars.simple_array = ["a", "b", "c"]
}

$column becomes host.vars.simple_array[*]

You strip the host.vars. and are left with simple_array[*] and now this line of code turns that to *], because it assumes that the name it always followed by a dot.

I would suggest to include the $var->name and an optional dot after it in the preg_replace.

return ['customvarid'];
}

private function flattenKeys(array $array, string $originalColumn, array $keys = []): array
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Even when fixing the handling of $path for the mentioned example, flattenKeys does not handle the case of $originalColumn being [*], so it that case would need extra handling by the function or before calling it.

@sukhwinder33445 sukhwinder33445 force-pushed the update-notifications-hook branch 3 times, most recently from db6b104 to d26bc38 Compare May 13, 2026 10:34
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 hook implementation yet.

Comment thread library/Icingadb/Web/Control/SearchBar/ObjectSuggestions.php
Comment thread library/Icingadb/Web/Control/SearchBar/ObjectSuggestions.php
Comment thread library/Icingadb/Data/QueryValuesProvider.php Outdated
Comment thread library/Icingadb/Data/QueryValuesProvider.php Outdated
@sukhwinder33445 sukhwinder33445 force-pushed the update-notifications-hook branch 4 times, most recently from 3bdd5d6 to 4488a9f Compare May 18, 2026 06:59
Decouple value suggestion logic into a standalone `Generator` instance.
This allows callers to fetch column values without any `Suggestions`
context. A plain `foreach` on the provider is enough.

`ObjectSuggestions::fetchValueSuggestions` is reduced to a thin wrapper
that resolves label-to-path input before delegating to the new class.
Moving the code to `QueryValuesProvider` does not seem helpful, as
this covers a rare case that is not really necessary.

To ensure consistency between the suggestions in the search bar and in
`SourceHook`, this must be removed.
Remove the overwritten method `fetchFilterColumns` of `SearchControls`
trait as this optimization is no longer necessary. Since the method is
now only used within its own class, it can be made protected.
The code has been moved directly to the `QueryValuesProvider` class.

`QueryValuesProvider`: The $key variable in the loop is no longer
necessary and has been removed. The yield type must be an array
containing at least the keys `search` and `label` for `searchSuggestion`
to work. Previously these keys were created by wrapper classes.
@sukhwinder33445 sukhwinder33445 force-pushed the update-notifications-hook branch 2 times, most recently from 7c5626b to a86ebbf Compare May 18, 2026 08:46
Comment on lines +107 to +122
try {
$select = $this->query->assembleSelect()->distinct();
} catch (InvalidColumnException $e) {
throw new SearchException(sprintf($this->translate('"%s" is not a valid column'), $e->getColumn()));
}

foreach ($this->query->getDb()->yieldAll($select, PDO::FETCH_COLUMN) as $value) {
// TODO(lippserd): This is a quick and dirty fix for PostgreSQL binary datatypes for which PDO returns
// PHP resources that would cause exceptions since resources are not a valid type for attribute values.
// We need to do it this way as the suggestion implementation bypasses ORM behaviors here and there.
if (is_resource($value)) {
$value = stream_get_contents($value);
}

yield ['search' => $value, 'label' => $value];
}
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 no reason anymore to bypass the orm now. This was only done to be able to use the cursed cursor implementation… So please just enable distinct on the select base and iterate over the orm query instead. In order to know which property to access, without inspecting $columnPath again, give it an alias in the above call to columns().

@sukhwinder33445 sukhwinder33445 force-pushed the update-notifications-hook branch from a86ebbf to 36ff1b1 Compare May 18, 2026 15:20
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.

Implement updated integration for Icinga Notifications Web

4 participants