From a3af8d73581c9a056c0ee025c7994c7af88b1482 Mon Sep 17 00:00:00 2001 From: hyahiaoui-ext <97593234+hyahiaoui-ext@users.noreply.github.com> Date: Sun, 3 Jul 2022 22:26:54 +0100 Subject: [PATCH] fix(platform) : Issue with cross databases query when the name contains some characters (#11279) --- .../centreon_performance_service.class.php | 3 ++- www/api/class/centreon_topcounter.class.php | 17 +++++++++-------- .../configuration/configServers/DB-Func.php | 16 ++++++++-------- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/www/api/class/centreon_performance_service.class.php b/www/api/class/centreon_performance_service.class.php index 15446f21782..5a4728a5617 100644 --- a/www/api/class/centreon_performance_service.class.php +++ b/www/api/class/centreon_performance_service.class.php @@ -114,7 +114,8 @@ public function getList() } if ($excludeAnomalyDetection) { - $additionalCondition .= 'AND s.service_id NOT IN (SELECT service_id FROM ' . $conf_centreon['db'] . '.mod_anomaly_service) '; + $additionalCondition .= 'AND s.service_id NOT IN (SELECT service_id + FROM `' . $conf_centreon['db'] . '`.mod_anomaly_service) '; } if (isset($this->arguments['hostgroup'])) { $additionalCondition .= 'AND (hg.host_id = i.host_id ' . diff --git a/www/api/class/centreon_topcounter.class.php b/www/api/class/centreon_topcounter.class.php index 263b5589ec3..a276098b4e2 100644 --- a/www/api/class/centreon_topcounter.class.php +++ b/www/api/class/centreon_topcounter.class.php @@ -847,19 +847,20 @@ protected function checkChangeState($pollerId, $lastRestart) $query = "SELECT * FROM log_action WHERE action_log_date > $lastRestart " . "AND ((object_type = 'host' AND ((action_type = 'd' AND object_id IN (SELECT host_id FROM hosts)) " . - "OR object_id IN (SELECT host_host_id FROM " . - $conf_centreon['db'] . ".ns_host_relation WHERE nagios_server_id = '$pollerId'))) " . + "OR object_id IN (SELECT host_host_id FROM `" . + $conf_centreon['db'] . "`.ns_host_relation WHERE nagios_server_id = '$pollerId'))) " . "OR (object_type = 'service' AND ((action_type = 'd' AND object_id IN (SELECT service_id FROM services)) OR " . - "object_id IN (SELECT service_service_id FROM " . - $conf_centreon['db'] . ".ns_host_relation nhr, " . $conf_centreon['db'] . ".host_service_relation hsr " . + "object_id IN (SELECT service_service_id FROM `" . + $conf_centreon['db'] . "`.ns_host_relation nhr, `" . $conf_centreon['db'] . "`.host_service_relation hsr " . "WHERE nagios_server_id = '$pollerId' AND hsr.host_host_id = nhr.host_host_id)))" . "OR (object_type = 'servicegroup' AND ((action_type = 'd' AND object_id IN (SELECT DISTINCT servicegroup_id " . - "FROM services_servicegroups)) OR object_id IN (SELECT DISTINCT servicegroup_sg_id FROM " . - $conf_centreon['db'] . ".servicegroup_relation sgr, " . $conf_centreon['db'] . ".ns_host_relation nhr " . + "FROM services_servicegroups)) OR object_id IN (SELECT DISTINCT servicegroup_sg_id FROM `" . + $conf_centreon['db'] . "`.servicegroup_relation sgr, + `" . $conf_centreon['db'] . "`.ns_host_relation nhr " . "WHERE sgr.host_host_id = nhr.host_host_id AND nhr.nagios_server_id = '$pollerId')))" . "OR (object_type = 'hostgroup' AND ((action_type = 'd' AND object_id IN (SELECT DISTINCT hostgroup_id " . - "FROM hosts_hostgroups)) OR object_id IN (SELECT DISTINCT hr.hostgroup_hg_id FROM " . - $conf_centreon['db'] . ".hostgroup_relation hr, " . $conf_centreon['db'] . ".ns_host_relation nhr " . + "FROM hosts_hostgroups)) OR object_id IN (SELECT DISTINCT hr.hostgroup_hg_id FROM `" . + $conf_centreon['db'] . "`.hostgroup_relation hr, `" . $conf_centreon['db'] . "`.ns_host_relation nhr " . "WHERE hr.host_host_id = nhr.host_host_id AND nhr.nagios_server_id = '$pollerId'))))"; try { diff --git a/www/include/configuration/configServers/DB-Func.php b/www/include/configuration/configServers/DB-Func.php index 4ab87047a30..83b150d1c7f 100644 --- a/www/include/configuration/configServers/DB-Func.php +++ b/www/include/configuration/configServers/DB-Func.php @@ -1066,7 +1066,7 @@ function getChangeState(array $pollers): array UNION SELECT instance_id, COUNT(*) as num_logs, MAX(action_log_date) as action_log_date FROM log_action INNER JOIN ( - SELECT nagios_server_id as instance_id, host_host_id as host_id FROM {$conf_centreon['db']}.ns_host_relation + SELECT nagios_server_id as instance_id, host_host_id as host_id FROM `{$conf_centreon['db']}`.ns_host_relation WHERE nagios_server_id IN ($pollersSearch) ) AS subtable ON log_action.object_id = subtable.host_id WHERE log_action.object_type = 'host' AND action_log_date > $lastRestart GROUP BY subtable.instance_id @@ -1082,7 +1082,7 @@ function getChangeState(array $pollers): array SELECT instance_id, COUNT(*) as num_logs, MAX(action_log_date) as action_log_date FROM log_action INNER JOIN ( SELECT nagios_server_id as instance_id, service_service_id as service_id - FROM {$conf_centreon['db']}.ns_host_relation nhr, {$conf_centreon['db']}.host_service_relation hsr + FROM `{$conf_centreon['db']}`.ns_host_relation nhr, `{$conf_centreon['db']}`.host_service_relation hsr WHERE nagios_server_id IN ($pollersSearch) AND hsr.host_host_id = nhr.host_host_id ) AS subtable ON log_action.object_id = subtable.service_id @@ -1099,7 +1099,7 @@ function getChangeState(array $pollers): array SELECT instance_id, COUNT(*) as num_logs, MAX(action_log_date) as action_log_date FROM log_action INNER JOIN ( SELECT nhr.nagios_server_id as instance_id, servicegroup_sg_id as servicegroup_id - FROM {$conf_centreon['db']}.servicegroup_relation sgr, {$conf_centreon['db']}.ns_host_relation nhr + FROM `{$conf_centreon['db']}`.servicegroup_relation sgr, `{$conf_centreon['db']}`.ns_host_relation nhr WHERE nhr.nagios_server_id IN ($pollersSearch) AND sgr.host_host_id = nhr.host_host_id ) AS subtable ON log_action.object_id = subtable.servicegroup_id @@ -1116,7 +1116,7 @@ function getChangeState(array $pollers): array SELECT instance_id, COUNT(*) as num_logs, MAX(action_log_date) as action_log_date FROM log_action INNER JOIN ( SELECT nhr.nagios_server_id as instance_id, hostgroup_hg_id as hostgroup_id - FROM {$conf_centreon['db']}.hostgroup_relation hr, {$conf_centreon['db']}.ns_host_relation nhr + FROM `{$conf_centreon['db']}`.hostgroup_relation hr, `{$conf_centreon['db']}`.ns_host_relation nhr WHERE nhr.nagios_server_id IN ($pollersSearch) AND hr.host_host_id = nhr.host_host_id ) AS subtable ON log_action.object_id = subtable.hostgroup_id @@ -1176,7 +1176,7 @@ function checkChangeState(int $poller_id, int $last_restart): bool ) OR object_id IN ( SELECT host_host_id - FROM {$conf_centreon['db']}.ns_host_relation + FROM `{$conf_centreon['db']}`.ns_host_relation` WHERE nagios_server_id = $poller_id ) ) @@ -1194,7 +1194,7 @@ function checkChangeState(int $poller_id, int $last_restart): bool ) OR object_id IN ( SELECT service_service_id - FROM {$conf_centreon['db']}.ns_host_relation nhr, {$conf_centreon['db']}.host_service_relation hsr + FROM `{$conf_centreon['db']}`.ns_host_relation nhr, `{$conf_centreon['db']}`.host_service_relation hsr WHERE nagios_server_id = $poller_id AND hsr.host_host_id = nhr.host_host_id ) @@ -1214,7 +1214,7 @@ function checkChangeState(int $poller_id, int $last_restart): bool ) OR object_id IN ( SELECT DISTINCT servicegroup_sg_id - FROM {$conf_centreon['db']}.servicegroup_relation sgr, {$conf_centreon['db']}.ns_host_relation nhr + FROM `{$conf_centreon['db']}`.servicegroup_relation sgr, `{$conf_centreon['db']}`.ns_host_relation nhr WHERE sgr.host_host_id = nhr.host_host_id AND nhr.nagios_server_id = $poller_id ) @@ -1234,7 +1234,7 @@ function checkChangeState(int $poller_id, int $last_restart): bool ) OR object_id IN ( SELECT DISTINCT hr.hostgroup_hg_id - FROM {$conf_centreon['db']}.hostgroup_relation hr, {$conf_centreon['db']}.ns_host_relation nhr + FROM `{$conf_centreon['db']}`.hostgroup_relation hr, `{$conf_centreon['db']}`.ns_host_relation nhr WHERE hr.host_host_id = nhr.host_host_id AND nhr.nagios_server_id = $poller_id )