Icinga / icingadb-web

Icinga DB Web – UI for Icinga DB – Provides a graphical interface to your Icinga monitoring
GNU General Public License v2.0
65 stars 21 forks source link

Some combinations of [Host|Service] queries with custom var filters return wrong results #1022

Open RincewindsHat opened 4 months ago

RincewindsHat commented 4 months ago

Describe the bug

Some queries using the ~ (tilde) operator return wrong (empty) results when search hosts or services.

To Reproduce

Try something like this:

  1. /icingaweb2/icingadb/hosts?host.vars.distro=debian&host.vars.transport_mode~icinga_agent shows no results
  2. /icingaweb2/icingadb/hosts?host.vars.distro~debian&host.vars.transport_mode~icinga_agent shows the correct results. (Note: = operator in the first condition vs. ~ in the second query)

Your Environment

Include as many relevant details about the environment you experienced the problem in.

Additional context

When exporting the quries with &format=sql I get this diff between the two queries above (diff query-problem.sql.fmt query-tilde-tilde.sql.fmt):

101,102c101,104
<                        AND ((sub_customvar_flat.flatname = 'transport_mode')
<                             AND (sub_customvar_flat.flatvalue = 'icinga_agent'))))
---
>                        OR ((sub_customvar_flat.flatname = 'transport_mode')
>                            AND (sub_customvar_flat.flatvalue = 'icinga_agent'))
>                      GROUP BY sub_customvar_flat_host.id
>                      HAVING COUNT(DISTINCT sub_customvar_flat.id) >= 2))
167,168c169,172
<                        AND ((sub_customvar_flat.flatname = 'transport_mode')
<                             AND (sub_customvar_flat.flatvalue = 'icinga_agent'))))
---
>                        OR ((sub_customvar_flat.flatname = 'transport_mode')
>                            AND (sub_customvar_flat.flatvalue = 'icinga_agent'))
>                      GROUP BY sub_customvar_flat_host.id
>                      HAVING COUNT(DISTINCT sub_customvar_flat.id) >= 2))

By playing around with some combinations, I noticed, that the GROUP BY and HAVING part seems to be missing from the problematic query.

nilmerg commented 4 months ago

This is a an old limitation now popping up because of the distinction between = and ~. It can be bypassed by using either = or ~ exclusively.

There is no simple fix, I'm afraid. Once we change this, filters such as host.check_interval>=60&host.check_interval<=300 must still return the same results as they do now.