Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

Commit

Permalink
fix(platform) : Issue with cross databases query when the name contai…
Browse files Browse the repository at this point in the history
…ns some characters (#11321)

* fix(platform) : Issue with cross databases query when the name contains some characters (#11279)

* Applying suggested changes
  • Loading branch information
hyahiaoui-ext authored Jul 5, 2022
1 parent 60b0e9c commit ce41eeb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
3 changes: 2 additions & 1 deletion www/api/class/centreon_performance_service.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ' .
Expand Down
17 changes: 9 additions & 8 deletions www/api/class/centreon_topcounter.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -878,19 +878,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 {
Expand Down
16 changes: 8 additions & 8 deletions www/include/configuration/configServers/DB-Func.php
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,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
Expand All @@ -1084,7 +1084,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
Expand All @@ -1101,7 +1101,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
Expand All @@ -1118,7 +1118,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
Expand Down Expand Up @@ -1178,7 +1178,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
)
)
Expand All @@ -1196,7 +1196,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
)
Expand All @@ -1216,7 +1216,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
)
Expand All @@ -1236,7 +1236,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
)
Expand Down

0 comments on commit ce41eeb

Please sign in to comment.