From b1f7923711a46ea885bde4b6c489e61697cbfe3c Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Mon, 18 Dec 2017 09:53:41 +0100 Subject: [PATCH 1/2] Ido: Allow custom variables to be mapped If you filter by host custom variables and the query does not have the services table joined, our query implementation calls the joinHosts method. Then, the column for the JOIN ON condition is automatically set to h.host_object_id. But it may be required by the query to call joinServices and use s.host_object_id instead of h.host_object_id because the query does not use any host related table at all. This is now possible when h.host_object_id is mapped to s.host_object_id: class ServicesRelatedQuery { protected $columnMap = array( 'hosts' => array( 'h.host_object_id' => 's.host_object_id' ) ); protected function joinHosts() { $this->requireVirtualTable('services'); } } --- .../library/Monitoring/Backend/Ido/Query/IdoQuery.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/IdoQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/IdoQuery.php index a43f59416..1983c3b31 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/IdoQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/IdoQuery.php @@ -964,6 +964,12 @@ abstract class IdoQuery extends DbQuery $leftcol = 'h.host_object_id'; } + $mapped = $this->getMappedField($leftcol); + if ($mapped !== null) { + $this->requireColumn($leftcol); + $leftcol = $mapped; + } + $joinOn = sprintf( $this->customVarsJoinTemplate, $leftcol, From 93ec798c6b7412201b4b661a1c1a9467e0c2a67d Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Mon, 18 Dec 2017 10:35:16 +0100 Subject: [PATCH 2/2] Ido: Map h.host_object_id to s.host_object_id in the ServicegroupQuery This is required to make filters work which filter by host custom variables without using any host related table. --- .../Backend/Ido/Query/ServicegroupQuery.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicegroupQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicegroupQuery.php index 62c3577f8..5d0deb64e 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicegroupQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicegroupQuery.php @@ -18,6 +18,9 @@ class ServicegroupQuery extends IdoQuery 'hostgroups' => array( 'hostgroup_name' => 'hgo.name1' ), + 'hosts' => array( + 'h.host_object_id' => 's.host_object_id' + ), 'instances' => array( 'instance_name' => 'i.instance_name' ), @@ -70,6 +73,16 @@ class ServicegroupQuery extends IdoQuery ); } + /** + * Join hosts + * + * This is required to make filters work which filter by host custom variables. + */ + protected function joinHosts() + { + $this->requireVirtualTable('services'); + } + /** * Join instances */