From fda5a5970de1aec6b72e5f413ea64694cfdaa499 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 23 Feb 2022 14:35:59 +0100 Subject: [PATCH] IdoQuery: Join customvars with only live references --- .../Monitoring/Backend/Ido/Query/IdoQuery.php | 34 ++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/IdoQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/IdoQuery.php index c6bba49ca..ceb5d7431 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/IdoQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/IdoQuery.php @@ -1191,14 +1191,32 @@ abstract class IdoQuery extends DbQuery $this->customVars[strtolower($customvar)] = $alias; - if ($this->hasJoinedVirtualTable('services')) { - $leftcol = 's.' . $type . '_object_id'; - } elseif ($type === 'service') { - $this->requireVirtualTable('services'); - $leftcol = 's.service_object_id'; - } else { - $this->requireVirtualTable('hosts'); - $leftcol = 'h.host_object_id'; + if ($type === 'host') { + if ( + $this instanceof HostserviceproblemsummaryQuery + || $this instanceof ServicecommentQuery + || $this instanceof ServicedowntimeQuery + || $this instanceof ServicecommenthistoryQuery + || $this instanceof ServicedowntimestarthistoryQuery + || $this instanceof ServiceflappingstarthistoryQuery + || $this instanceof ServicegroupQuery + || $this instanceof ServicenotificationQuery + || $this instanceof ServicestatehistoryQuery + || $this instanceof ServicestatusQuery + ) { + $this->requireVirtualTable('services'); + $leftcol = 's.host_object_id'; + } else { + $leftcol = 'ho.object_id'; + if (! $this->hasJoinedTable('ho')) { + $this->requireVirtualTable('hosts'); + } + } + } else { // $type === 'service' + $leftcol = 'so.object_id'; + if (! $this->hasJoinedTable('so')) { + $this->requireVirtualTable('services'); + } } $mapped = $this->getMappedField($leftcol);