Skip to content

Add hook to include custom variables by default when searching under Overview entries#1046

Merged
nilmerg merged 2 commits into
Icinga:mainfrom
WuerthPhoenix:feature/custom-vars-default-search-1045
Jun 17, 2026
Merged

Add hook to include custom variables by default when searching under Overview entries#1046
nilmerg merged 2 commits into
Icinga:mainfrom
WuerthPhoenix:feature/custom-vars-default-search-1045

Conversation

@oskarnrk

@oskarnrk oskarnrk commented Aug 20, 2024

Copy link
Copy Markdown
Contributor

The hook can be implemented in multiple ways. For example:

Add to run.php

$this->provideHook('Icingadb/SearchColumnsProvider');

SearchColumnsProvider.php

<?php

namespace Icinga\Module\Icingadb\ProvidedHook;

use Icinga\Module\Icingadb\Hook\SearchColumnsProviderHook;
use ipl\Orm\Model;

class SearchColumnsProvider extends SearchColumnsProviderHook
{
    public function retrieveCustomVars(Model $model): array
    {
        switch ($model->getTableName()) {
            case 'host':
                return ['host.vars.hostfoo', 'host.vars.hostbar'];
            case 'service':
                return ['service.vars.servicefoo', 'service.vars.servicebar'];
            default:
                return [];
        }
    }
}

@cla-bot

cla-bot Bot commented Aug 20, 2024

Copy link
Copy Markdown

Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Oscar Zambotti.
This is most likely caused by a git client misconfiguration; please make sure to:

  1. check if your git client is configured with an email to sign commits git config --list | grep email
  2. If not, set it up using git config --global user.email email@example.com
  3. Make sure that the git commit email is configured in your GitHub account settings, see https://github.com/settings/emails

@oskarnrk oskarnrk closed this Aug 20, 2024
@oskarnrk
oskarnrk force-pushed the feature/custom-vars-default-search-1045 branch from 5c2b7d3 to 334aaf8 Compare August 20, 2024 12:59
@cla-bot cla-bot Bot added the cla/signed CLA is signed by all contributors of a PR label Aug 20, 2024
@oskarnrk oskarnrk reopened this Aug 20, 2024
@cla-bot

cla-bot Bot commented Aug 20, 2024

Copy link
Copy Markdown

Thank you for your pull request. Before we can look at it, you'll need to sign a Contributor License Agreement (CLA).

Please follow instructions at https://icinga.com/company/contributor-agreement to sign the CLA.

After that, please reply here with a comment and we'll verify.

Contributors that have not signed yet: @oskarnrk

Details
  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Please contact us if you think this is the case.

  • If you signed the CLA as a corporation, your GitHub username may not have been submitted to us. Please reach out to the responsible person in your organization.

@cla-bot cla-bot Bot removed the cla/signed CLA is signed by all contributors of a PR label Aug 20, 2024
@oskarnrk

Copy link
Copy Markdown
Contributor Author

Thank you for your pull request. Before we can look at it, you'll need to sign a Contributor License Agreement (CLA).

Please follow instructions at https://icinga.com/company/contributor-agreement to sign the CLA.

After that, please reply here with a comment and we'll verify.

Contributors that have not signed yet: @oskarnrk

I signed the ICLA, thanks in advance.

@oskarnrk

Copy link
Copy Markdown
Contributor Author

Is it possibile to retrigger the CLA check? Thanks

@bobapple

Copy link
Copy Markdown
Member

@cla-bot check

@cla-bot cla-bot Bot added the cla/signed CLA is signed by all contributors of a PR label Oct 23, 2024
@oskarnrk

Copy link
Copy Markdown
Contributor Author

Please, is it possible to check this quite old PR? Thanks 😇

@nilmerg

nilmerg commented Feb 26, 2025

Copy link
Copy Markdown
Member

Hi, the reason why (at least for me) no-one looked at this yet, is that this isn't just a small feature. This has so many other parts which might be affected, that I don't want to introduce a half baked solution. (Besides that a new hook also requires us to cover support for it, which I cannot guarantee at all)

@oskarnrk oskarnrk closed this Aug 22, 2025
@oskarnrk
oskarnrk force-pushed the feature/custom-vars-default-search-1045 branch from 1adf706 to fa23e86 Compare August 22, 2025 10:03
@oskarnrk oskarnrk reopened this Aug 22, 2025
@oskarnrk
oskarnrk force-pushed the feature/custom-vars-default-search-1045 branch from 276781c to 02e6fb0 Compare August 22, 2025 12:56

@nilmerg nilmerg left a comment

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.

Since Icinga/ipl-web@91221e2 there's an additional usage of Model::getSearchColumns(). It's intended to provide the same set of columns the searchbar will provide as a default in the same route, but applied in case the user hits enter faster than the default suggestion appears (or rather can be interacted with).

My suggestion to extend this, isolated to Icinga DB Web, is to change \Icinga\Module\Icingadb\Common\SearchControls::createSearchBar to override what the base implementation did. However, for this to work at all, \ipl\Web\Compat\SearchControls::callHandleRequest has be overridden and you have to call $searchBar->handleRequest($this->getServerRequest()).

Comment thread library/Icingadb/Hook/CustomVarsRetrieverHook.php Outdated
Comment thread library/Icingadb/Hook/CustomVarsRetrieverHook.php Outdated
Comment thread library/Icingadb/Hook/CustomVarsRetrieverHook.php Outdated
@gianlucapiccolo
gianlucapiccolo force-pushed the feature/custom-vars-default-search-1045 branch 4 times, most recently from 2b4a8de to dc69402 Compare June 16, 2026 12:54

@nilmerg nilmerg left a comment

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.

looking fine now, but please rebase and fix the conflicts

Comment thread library/Icingadb/Web/Controller.php Outdated
@gianlucapiccolo
gianlucapiccolo force-pushed the feature/custom-vars-default-search-1045 branch from dc69402 to 5767c91 Compare June 16, 2026 13:26
…dated ObjectSuggestions and Controller classes to utilize the new hook for enhanced search functionality
@gianlucapiccolo
gianlucapiccolo force-pushed the feature/custom-vars-default-search-1045 branch from 5767c91 to 512c5b6 Compare June 16, 2026 14:22
…tom variable retrieval and added new SearchColumnProviderHook class
@gianlucapiccolo
gianlucapiccolo force-pushed the feature/custom-vars-default-search-1045 branch from 512c5b6 to 6fb5476 Compare June 17, 2026 08:48

@nilmerg nilmerg left a comment

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.

Looks fine, thanks :)

@nilmerg nilmerg added this to the 1.5.0 milestone Jun 17, 2026
@nilmerg
nilmerg merged commit 17e8498 into Icinga:main Jun 17, 2026
13 checks passed
nilmerg added a commit that referenced this pull request Jun 25, 2026
#1046 introduced two problems
to the `SearchControls` trait.

Returning `false` from `SearchControls::callHandleRequest()` prevents
the ipl-web `SearchControls` trait from calling `handleRequest()` in
both `createSearchBar()` and `createSearchEditor()`.
An implementation of `createSearchEditor()` is added, which explicitly
calls `$editor->handleRequest()` as `createSearchBar()` already does.
Without this no `SearchEditor` in the entire module is usable.

An other problem is that moving the call of
`$searchbar->handleRequest()` also delayed its `assemble()`, so this if
block was entered before the assemble, resulting in the wrapper being
added twice.

```
if (($wrapper = $searchBar->getWrapper()) && ! $wrapper->getWrapper()) {
    // TODO: Remove this once ipl-web v0.7.0 is required
    $searchBar->addWrapper(Html::tag('div', ['class' => 'search-controls']));
}
```
which caused a visual bug:

<img width="447" height="175" alt="Screenshot from 2026-06-25 11-01-42"
src="https://github.com/user-attachments/assets/4e852585-c677-4c70-8f95-631601294de4"
/>

The statement should be safe to remove together with the less that has
the same `TODO`.
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.

Include custom variables automatically when searching on Overview entries

4 participants