Add V2/Source hook for icinga-notifications-web#1369
Conversation
ded5a93 to
c3c926f
Compare
c3c926f to
9f7ac77
Compare
7d02f46 to
680cc30
Compare
|
I reduced the |
912ca23 to
f1465b1
Compare
497472d to
f027079
Compare
f027079 to
ee166d4
Compare
4da5fe6 to
bb489df
Compare
bb489df to
b6cf2b9
Compare
BastianLedererIcinga
left a comment
There was a problem hiding this comment.
This is what I noticed for the current state, but some of it may no longer apply once the changes regarding jsonPath are implemented.
| } | ||
|
|
||
| $path = preg_replace('/^(?:host|service)\.vars\./', '', $column); | ||
| $path = substr($path, strlen($var->name) + 1); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
db6b104 to
d26bc38
Compare
nilmerg
left a comment
There was a problem hiding this comment.
Didn't look at the hook implementation yet.
3bdd5d6 to
4488a9f
Compare
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.
7c5626b to
a86ebbf
Compare
| 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]; | ||
| } |
There was a problem hiding this comment.
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().
a86ebbf to
36ff1b1
Compare
This PR adds a new
V2/Sourcehook implementation to integrate with theV2/SourceHookinterface fromicinga-notifications-web.Changes:
V2/Sourcehook: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 obsoletetypeparam. Since theV2hook does not support filter targets, this parameter is no longer needed.resolves: #1365
require: Icinga/icinga-notifications-web#469