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

Commit

Permalink
fix(remote-server): fix simple remote server creation (#7936)
Browse files Browse the repository at this point in the history
Refs: BAM-748
  • Loading branch information
kduret authored Oct 9, 2019
1 parent 39c9587 commit a026674
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ public function collectDataFromAdditionalRemoteServers(): void
{
$isRemoteServerWizard = (new ServerWizardIdentity)->requestConfigurationIsRemote();

if (!$isRemoteServerWizard) {
$linkedRemotes= isset($_POST['linked_remote_slaves']) ? $_POST['linked_remote_slaves'] : [];
$linkedRemotes = [];
if (!$isRemoteServerWizard && isset($_POST['linked_remote_slaves'])) {
$linkedRemotes = $_POST['linked_remote_slaves'];
}

$this->additionalRemotes = $this->getPollersToLink($linkedRemotes); // set and instantiate linked pollers
Expand Down
73 changes: 42 additions & 31 deletions www/include/configuration/configGenerate/xml/moveFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,43 +73,54 @@
global $generatePhpErrors;
global $dependencyInjector;

$generatePhpErrors = array();
$generatePhpErrors = [];
$pollers = explode(',', $_POST['poller']);

// Add task to export files if there is a remote
$idBindString = str_repeat('?,', count($pollers));
$idBindString = rtrim($idBindString, ',');
$queryRemotes =<<<SQL
SELECT ns1.id, ns1.ns_ip_address AS ip,
rs.centreon_path, rs.http_method, rs.http_port, rs.no_check_certificate, rs.no_proxy
FROM nagios_server AS ns1
JOIN remote_servers AS rs ON rs.ip = ns1.ns_ip_address
JOIN nagios_server AS ns2 ON ns1.id = ns2.remote_id
WHERE ns2.id IN ({$idBindString})
UNION
SELECT ns1.id, ns1.ns_ip_address AS ip,
rs.centreon_path, rs.http_method, rs.http_port, rs.no_check_certificate, rs.no_proxy
FROM nagios_server AS ns1
JOIN remote_servers AS rs ON rs.ip = ns1.ns_ip_address
JOIN rs_poller_relation AS rspr ON rspr.remote_server_id = ns1.id
WHERE rspr.poller_server_id IN ({$idBindString})
SQL;

$remotesStatement = $pearDB->query($queryRemotes, array_merge($pollers, $pollers));
$remotesResults = $remotesStatement->fetchAll(PDO::FETCH_ASSOC);
$pollerParams = [];
foreach ($pollers as $pollerId) {
$pollerParams[':poller_' . $pollerId] = $pollerId;
}
$statementRemotes = $pearDB->prepare('
SELECT ns.id, ns.ns_ip_address AS ip,
rs.centreon_path, rs.http_method, rs.http_port, rs.no_check_certificate, rs.no_proxy
FROM nagios_server AS ns
JOIN remote_servers AS rs ON rs.ip = ns.ns_ip_address
WHERE ns.id IN (' . implode(',', array_keys($pollerParams)) . ')
UNION
SELECT ns1.id, ns1.ns_ip_address AS ip,
rs.centreon_path, rs.http_method, rs.http_port, rs.no_check_certificate, rs.no_proxy
FROM nagios_server AS ns1
JOIN remote_servers AS rs ON rs.ip = ns1.ns_ip_address
JOIN nagios_server AS ns2 ON ns1.id = ns2.remote_id
WHERE ns2.id IN (' . implode(',', array_keys($pollerParams)) . ')
UNION
SELECT ns1.id, ns1.ns_ip_address AS ip,
rs.centreon_path, rs.http_method, rs.http_port, rs.no_check_certificate, rs.no_proxy
FROM nagios_server AS ns1
JOIN remote_servers AS rs ON rs.ip = ns1.ns_ip_address
JOIN rs_poller_relation AS rspr ON rspr.remote_server_id = ns1.id
WHERE rspr.poller_server_id IN (' . implode(',', array_keys($pollerParams)) . ')
');
foreach ($pollerParams as $key => $value) {
$statementRemotes->bindValue($key, $value, \PDO::PARAM_INT);
}
$statementRemotes->execute();
$remotesResults = $statementRemotes->fetchAll(PDO::FETCH_ASSOC);

if (!empty($remotesResults)) {
foreach ($remotesResults as $remote) {
$queryLinked =<<<SQL
SELECT id
FROM nagios_server
WHERE remote_id = {$remote['id']}
UNION
SELECT poller_server_id AS id
FROM rs_poller_relation
WHERE remote_server_id = {$remote['id']}
SQL;
$linkedStatement = $pearDB->query($queryLinked);
$linkedStatement = $pearDB->prepare('
SELECT id
FROM nagios_server
WHERE remote_id = :remote_id
UNION
SELECT poller_server_id AS id
FROM rs_poller_relation
WHERE remote_server_id = :remote_id
');
$linkedStatement->bindValue(':remote_id', $remote['id'], \PDO::PARAM_INT);
$linkedStatement->execute();
$linkedResults = $linkedStatement->fetchAll(PDO::FETCH_ASSOC);

$exportParams = [
Expand Down

0 comments on commit a026674

Please sign in to comment.