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

Commit

Permalink
fix(broker): fix wizard broker configuration with one peer retention (#…
Browse files Browse the repository at this point in the history
…6959)

* fix(broker): fix wizard broker configuration with one peer retention mode

* enh(broker): add poller name in one peer retention configuration name

Refs: #6910 #6978 #6987

* add comments

* fix broker configuration methods

* Remote server add multiple authorized master (#7063)

* fix(remote-server): Update authorizedMaster value using enableRemote
* enh(remote-server): authorize multiple master

* fix syntax error

* improve centcore debug

* fix bam broker configuration on remote server

* test(ut): fix unit tests of remote server

* test(ut): update value of mocked constants
  • Loading branch information
kduret authored and vhr committed Jan 23, 2019
1 parent d9d3fea commit 8d72867
Show file tree
Hide file tree
Showing 100 changed files with 5,548 additions and 4,231 deletions.
3 changes: 0 additions & 3 deletions bin/centreon
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,6 @@ require_once _CENTREON_ETC_ . "/centreon.conf.php";
require_once _CLAPI_CLASS_ . "/centreonAPI.class.php";
require_once _CLAPI_CLASS_ . "/centreonUtils.class.php";

error_reporting(0);
ini_set("display_errors", "Off");

$dbConfig['host'] = $conf_centreon['hostCentreon'];
$dbConfig['username'] = $conf_centreon['user'];
$dbConfig['password'] = $conf_centreon['password'];
Expand Down
5 changes: 5 additions & 0 deletions bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ function loadDependencyInjector()
return new \CentreonDB('centstorage');
};

// Define Centreon Rest Http Client
$dependencyInjector['rest_http'] = function ($c) {
return new \CentreonRestHttp();
};

// Define filesystem
$dependencyInjector['filesystem'] = function ($c) {
return new \Symfony\Component\Filesystem\Filesystem();
Expand Down
3 changes: 2 additions & 1 deletion doc/en/administration_guide/poller/enable_remote.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ Connect to your **Remoter Server** and execute following command::
# /usr/share/centreon/bin/centreon -u admin -p centreon -a enableRemote -o CentreonRemoteServer -v @IP_CENTREON_CENTRAL

.. note::
Replace **@IP_CENTREON_CENTRAL** by the IP of the Centreon server seen by the poller
Replace **@IP_CENTREON_CENTRAL** by the IP of the Centreon server seen by the poller.
You can define multiple IP address using a coma as separator.

This command will enable **Remote Server** mode::

Expand Down
1 change: 1 addition & 0 deletions doc/fr/administration_guide/poller/enable_remote.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ la commande suivante ::

.. note::
Remplacez **@IP_CENTREON_CENTRAL** par l'IP du serveur Centreon vu par le collecteur.
Vous pouvez définir plusieurs adresse IP en utilisant la virgule comme séparateur.

Cette commande va activer le mode **Remote Server** ::

Expand Down
450 changes: 260 additions & 190 deletions lib/perl/centreon/script/centcore.pm

Large diffs are not rendered by default.

106 changes: 106 additions & 0 deletions src/Centreon/Domain/Entity/CfgCentreonBrokerInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php
namespace Centreon\Domain\Entity;

/**
* Entity to manage broker configuration table : cfg_centreonbroker_info
*/
class CfgCentreonBrokerInfo
{
const TABLE = 'cfg_centreonbroker_info';

/**
* @var int the linked config id
*/
private $configId;

/**
* @var string the config group (input, output, log...)
*/
private $configGroup;

/**
* @var int the config group id (its order in flows listing)
*/
private $configGroupId;

/**
* @var int the config group level (eg: categories)
*/
private $configGroupLevel;

/**
* @var string the name of the linked field
*/
private $configKey;

/**
* @var string the value of the linked field
*/
private $configValue;

public function __construct(string $configKey, string $configValue)
{
$this->configKey = $configKey;
$this->configValue = $configValue;
}

public function setConfigId(int $configId): void
{
$this->configId = $configId;
}

public function getConfigId(): int
{
return $this->configId;
}

public function setConfigGroup(string $configGroup): void
{
$this->configGroup = $configGroup;
}

public function getConfigGroup(): string
{
return $this->configGroup;
}

public function setConfigGroupId(int $configGroupId): void
{
$this->configGroupId = $configGroupId;
}

public function getConfigGroupId(): int
{
return $this->configGroupId;
}

public function setConfigGroupLevel(int $configGroupLevel): void
{
$this->configGroupLevel = $configGroupLevel;
}

public function getConfigGroupLevel(): int
{
return $this->configGroupLevel;
}

public function setConfigKey(string $configKey): void
{
$this->configKey = $configKey;
}

public function getConfigKey(): string
{
return $this->configKey;
}

public function setConfigValue(string $configValue): void
{
$this->configValue = $configValue;
}

public function getConfigValue(): string
{
return $this->configValue;
}
}
42 changes: 0 additions & 42 deletions src/Centreon/Domain/Repository/CfgCentreonBorkerInfoRepository.php

This file was deleted.

49 changes: 0 additions & 49 deletions src/Centreon/Domain/Repository/CfgCentreonBorkerRepository.php

This file was deleted.

96 changes: 96 additions & 0 deletions src/Centreon/Domain/Repository/CfgCentreonBrokerInfoRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php
namespace Centreon\Domain\Repository;

use Centreon\Domain\Repository\Interfaces\CfgCentreonBrokerInfoInterface;
use Centreon\Domain\Entity\CfgCentreonBrokerInfo;
use Centreon\Infrastructure\CentreonLegacyDB\ServiceEntityRepository;

/**
* Repository to manage centreon broker flows configuration (input, output...)
*/
class CfgCentreonBrokerInfoRepository extends ServiceEntityRepository implements CfgCentreonBrokerInfoInterface
{
/**
* Get new config group id by config id for a specific flow
* once the config group is got from this method, it is possible to insert a new flow in the broker configuration
*
* @param int $configId the broker configuration id
* @param string $flow the flow type : input, output, log...
* @return int the new config group id
*/
public function getNewConfigGroupId(int $configId, string $flow): int
{
// if there is no config group for a specific flow, first one id is 0
$configGroupId = 0;

$sql = 'SELECT MAX(config_group_id) as max_config_group_id '
. 'FROM cfg_centreonbroker_info cbi '
. 'WHERE config_id = :config_id '
. 'AND config_group = :config_group';
$stmt = $this->db->prepare($sql);
$stmt->bindParam(':config_id', $configId, \PDO::PARAM_INT);
$stmt->bindParam(':config_group', $flow, \PDO::PARAM_STR);
$stmt->execute();

$row = $stmt->fetch();
if (!is_null($row['max_config_group_id'])) {
// to get the new new config group id, we need to increment the max exsting one
$configGroupId = $row['max_config_group_id'] + 1;
}

return $configGroupId;
}

/**
* Insert broker configuration in database (table cfg_centreonbroker_info)
*
* @param CfgCentreonBrokerInfo $brokerInfoEntity the broker info entity
*/
public function add(CfgCentreonBrokerInfo $brokerInfoEntity): void
{
$sql = "INSERT INTO " . $brokerInfoEntity::TABLE . ' '
. '(config_id, config_group, config_group_id, config_key, config_value) '
. 'VALUES (:config_id, :config_group, :config_group_id, :config_key, :config_value)';
$stmt = $this->db->prepare($sql);
$stmt->bindValue(':config_id', $brokerInfoEntity->getConfigId(), \PDO::PARAM_INT);
$stmt->bindValue(':config_group', $brokerInfoEntity->getConfigGroup(), \PDO::PARAM_STR);
$stmt->bindValue(':config_group_id', $brokerInfoEntity->getConfigGroupId(), \PDO::PARAM_INT);
$stmt->bindValue(':config_key', $brokerInfoEntity->getConfigKey(), \PDO::PARAM_STR);
$stmt->bindValue(':config_value', $brokerInfoEntity->getConfigValue(), \PDO::PARAM_STR);
$stmt->execute();
}

/**
* Export
*
* @param int[] $pollerIds
* @return array
*/
public function export(array $pollerIds): array
{
// prevent SQL exception
if (!$pollerIds) {
return [];
}

$ids = join(',', $pollerIds);

$sql = <<<SQL
SELECT t.*
FROM cfg_centreonbroker_info AS t
INNER JOIN cfg_centreonbroker AS cci ON cci.config_id = t.config_id
WHERE cci.ns_nagios_server IN ({$ids})
SQL;

$stmt = $this->db->prepare($sql);
$stmt->execute();

$result = [];

while ($row = $stmt->fetch()) {
$result[] = $row;
}

return $result;
}
}
Loading

0 comments on commit 8d72867

Please sign in to comment.