diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcontactQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcontactQuery.php index 8fb31d032..23b0e9014 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcontactQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcontactQuery.php @@ -89,7 +89,7 @@ class HostcontactQuery extends IdoQuery [] )->join( ['co' => $this->prefix . 'objects'], - 'co.object_id = c.contact_object_id AND co.is_active = 1', + 'co.object_id = c.contact_object_id AND co.is_active = 1 AND co.objecttype_id = 10', [] ); @@ -153,7 +153,7 @@ class HostcontactQuery extends IdoQuery [] )->joinLeft( ['ho' => $this->prefix . 'objects'], - 'ho.object_id = h.host_object_id AND ho.is_active = 1', + 'ho.object_id = h.host_object_id AND ho.is_active = 1 AND ho.objecttype_id = 1', [] ); } diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/IdoQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/IdoQuery.php index c925191ae..0fcfc4247 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/IdoQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/IdoQuery.php @@ -1193,14 +1193,31 @@ 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 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); diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecontactQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecontactQuery.php index 5ab787ebe..0a46709e0 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecontactQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecontactQuery.php @@ -89,7 +89,7 @@ class ServicecontactQuery extends IdoQuery [] )->join( ['co' => $this->prefix . 'objects'], - 'co.object_id = c.contact_object_id AND co.is_active = 1', + 'co.object_id = c.contact_object_id AND co.is_active = 1 AND co.objecttype_id = 10', [] ); @@ -163,7 +163,7 @@ class ServicecontactQuery extends IdoQuery [] )->joinLeft( ['ho' => $this->prefix . 'objects'], - 'ho.object_id = h.host_object_id AND ho.is_active = 1', + 'ho.object_id = h.host_object_id AND ho.is_active = 1 AND ho.objecttype_id = 1', [] ); }