diff --git a/doc/en/Presentation.rst b/doc/en/Presentation.rst index 5e0c3d6..3ca76b9 100644 --- a/doc/en/Presentation.rst +++ b/doc/en/Presentation.rst @@ -13,6 +13,12 @@ solution. It also allows not to use WAN interconnections for example. This interface is not compatible with poller which receives data from many pollers. +.. warning:: + Warning version 1.6 uses a new ACLs management system. + All ACLs initially created on the Centreon Poller Display interface will be removed. + Only the contacts ACLs related to objects supervised by the collector will be synchronized. + + Centreon Poller Display allows to build the following architecture: .. image :: /images/eschema.png diff --git a/doc/fr/Presentation.rst b/doc/fr/Presentation.rst index 93b3397..44b23c5 100644 --- a/doc/fr/Presentation.rst +++ b/doc/fr/Presentation.rst @@ -16,6 +16,11 @@ interface peut être également utilisée comme solution de secours. Cela permet Cette interface n'est pas compatible avec un poller recevant les données collectés de plusieurs pollers. +.. warning:: + Attention la version 1.6 utilise un nouveau système de gestion des ACLs. + Toutes les ACLs initialement créées sur l'interface Centreon Poller Display vont être supprimées. + Seules les ACLs des contacts liés à des objets supervisés par le collecteur seront synchronisées. + Centreon Poller Display permet alors de mettre en place l’architecture suivante : .. image :: /images/eschema.png diff --git a/tests/centreon-poller-display-central/php/class/configGenerate/centreon/AclTopologyRelationTest.php b/tests/centreon-poller-display-central/php/class/configGenerate/centreon/AclTopologyRelationTest.php new file mode 100644 index 0000000..88946b2 --- /dev/null +++ b/tests/centreon-poller-display-central/php/class/configGenerate/centreon/AclTopologyRelationTest.php @@ -0,0 +1,123 @@ + '1', + 'acl_topo_name' => 'toto' + ), + array( + 'acl_topo_id' => '4', + 'acl_topo_name' => 'tutu' + ) + ); + self::$objectListOut = array( + array( + 'topology_topology_id' => '2', + 'acl_topo_id' => '1' + ), + array( + 'topology_topology_id' => '3', + 'acl_topo_id' => '4' + ) + ); + + + } + + public function tearDown() + { + self::$db = null; + } + + public function testGetList() + { + self::$db->addResultSet( + 'SELECT * FROM acl_topology_relations WHERE acl_topo_id IN (1,4)', + array( + array( + 'topology_topology_id' => '2', + 'acl_topo_id' => '1' + ), + array( + 'topology_topology_id' => '3', + 'acl_topo_id' => '4' + ) + ) + ); + + $sql = self::$acl->getList(self::$objectListIn); + $this->assertEquals($sql, self::$objectListOut); + } + + public function testGenerateSql() + { + self::$db->addResultSet( + 'SELECT topology_name, topology_page FROM topology WHERE topology_id = 2', + array( + array( + 'topology_page' => '20', + 'topology_name' => 'toto' + ) + ) + ); + self::$db->addResultSet( + 'SELECT topology_name, topology_page FROM topology WHERE topology_id = 3', + array( + array( + 'topology_page' => '30', + 'topology_name' => 'tutu' + ) + ) + ); + + $expectedResult = 'DELETE FROM acl_topology_relations; +TRUNCATE acl_topology_relations; +INSERT INTO `acl_topology_relations` (`topology_topology_id`,`acl_topo_id`) +SELECT (SELECT topology_id FROM topology WHERE topology_name = "toto" AND topology_page = "20"),\'1\' +WHERE (SELECT topology_id FROM topology WHERE topology_name = "toto" AND topology_page = "20"); +INSERT INTO `acl_topology_relations` (`topology_topology_id`,`acl_topo_id`) +SELECT (SELECT topology_id FROM topology WHERE topology_name = "tutu" AND topology_page = "30"),\'4\' +WHERE (SELECT topology_id FROM topology WHERE topology_name = "tutu" AND topology_page = "30"); +'; + + $sql = self::$acl->generateSql(self::$objectListOut); + $this->assertEquals($sql, $expectedResult); + } +} diff --git a/tests/centreon-poller-display-central/php/class/configGenerate/centreon/AclTopologyTest.php b/tests/centreon-poller-display-central/php/class/configGenerate/centreon/AclTopologyTest.php new file mode 100644 index 0000000..77acaf3 --- /dev/null +++ b/tests/centreon-poller-display-central/php/class/configGenerate/centreon/AclTopologyTest.php @@ -0,0 +1,100 @@ + '1', + 'acl_group_id' => '1', + 'acl_topology_id' => '1' + ), + array( + 'agt_id' => '2', + 'acl_group_id' => '3', + 'acl_topology_id' => '4' + ) + ); + + self::$objectListOut = array( + array( + 'acl_topo_id' => '1', + 'acl_topo_name' => 'toto' + ), + array( + 'acl_topo_id' => '4', + 'acl_topo_name' => 'tutu' + ) + ); + } + + public function tearDown() + { + self::$db = null; + } + + public function testGetList() + { + self::$db->addResultSet( + 'SELECT * FROM acl_topology WHERE acl_topo_id IN (1,4)', + array( + array( + 'acl_topo_id' => '1', + 'acl_topo_name' => 'toto' + ), + array( + 'acl_topo_id' => '4', + 'acl_topo_name' => 'tutu' + ) + ) + ); + + $sql = self::$acl->getList(self::$objectListIn); + $this->assertEquals($sql, self::$objectListOut); + } + + public function testGenerateSql() + { + + $expectedResult = 'DELETE FROM acl_topology; +TRUNCATE acl_topology; +INSERT INTO `acl_topology` (`acl_topo_id`,`acl_topo_name`) VALUES (\'1\',\'toto\'),(\'4\',\'tutu\');'; + + $sql = self::$acl->generateSql(self::$objectListOut); + $this->assertEquals($sql, $expectedResult); + } +} diff --git a/www/modules/centreon-poller-display-central/core/class/configGenerate/Centreon.php b/www/modules/centreon-poller-display-central/core/class/configGenerate/Centreon.php index ae6afd4..7c33674 100644 --- a/www/modules/centreon-poller-display-central/core/class/configGenerate/Centreon.php +++ b/www/modules/centreon-poller-display-central/core/class/configGenerate/Centreon.php @@ -41,6 +41,8 @@ use \CentreonPollerDisplayCentral\ConfigGenerate\Centreon\AclGroupContactgroupsRelation; use \CentreonPollerDisplayCentral\ConfigGenerate\Centreon\AclGroupContactsRelation; use \CentreonPollerDisplayCentral\ConfigGenerate\Centreon\AclGroupTopology; +use \CentreonPollerDisplayCentral\ConfigGenerate\Centreon\AclTopology; +use \CentreonPollerDisplayCentral\ConfigGenerate\Centreon\AclTopologyRelation; use \CentreonPollerDisplayCentral\ConfigGenerate\Centreon\AclGroups; use \CentreonPollerDisplayCentral\ConfigGenerate\Centreon\AclResources; use \CentreonPollerDisplayCentral\ConfigGenerate\Centreon\AclResourcesGroupRelation; @@ -117,6 +119,8 @@ public function generateObjects($poller_id) $oAclGroupContactgroupsRelation = new AclGroupContactgroupsRelation($db, $poller_id); $oAclGroupContactsRelation = new AclGroupContactsRelation($db, $poller_id); $oAclGroupTopology = new AclGroupTopology($db, $poller_id); + $oAclTopology = new AclTopology($db, $poller_id); + $oAclTopologyRelation = new AclTopologyRelation($db, $poller_id); $oAclGroups = new AclGroups($db, $poller_id); $oAclResources = new AclResources($db, $poller_id); $oAclResourcesGroupRelation = new AclResourcesGroupRelation($db, $poller_id); @@ -159,8 +163,9 @@ public function generateObjects($poller_id) $oServicegroup = new Servicegroup($db, $poller_id); $oServicegroupRelation = new ServicegroupRelation($db, $poller_id); + $sql = ''; - $sql .= $this->setForeignKey(0). "\n\n"; + $sql .= $this->setForeignKey(0) . "\n\n"; $nagiosServerList = $oNagiosServer->getList(); $sql .= $oNagiosServer->generateSql($nagiosServerList) . "\n\n"; @@ -288,6 +293,12 @@ public function generateObjects($poller_id) $aclGroupTopologyList = $oAclGroupTopology->getList($aclGroupsList); $sql .= $oAclGroupTopology->generateSql($aclGroupTopologyList) . "\n\n"; + $aclTopologyList = $oAclTopology->getList($aclGroupTopologyList); + $sql .= $oAclTopology->generateSql($aclTopologyList) . "\n\n"; + + $aclTopologyRelationList = $oAclTopologyRelation->getList($aclTopologyList); + $sql .= $oAclTopologyRelation->generateSql($aclTopologyRelationList) . "\n\n"; + $aclGroupActionsRelationList = $oAclGroupActionsRelation->getList($aclGroupsList); $sql .= $oAclGroupActionsRelation->generateSql($aclGroupActionsRelationList) . "\n\n"; diff --git a/www/modules/centreon-poller-display-central/core/class/configGenerate/centreon/AclGroups.php b/www/modules/centreon-poller-display-central/core/class/configGenerate/centreon/AclGroups.php index f251c01..bfaedcf 100644 --- a/www/modules/centreon-poller-display-central/core/class/configGenerate/centreon/AclGroups.php +++ b/www/modules/centreon-poller-display-central/core/class/configGenerate/centreon/AclGroups.php @@ -95,4 +95,22 @@ public function getList($clauseContactObject = null, $clauseContactgObject = nul return $list; } + + /** + * + * @param type $objects + * @return string + */ + protected function generateInsertQuery($objects) + { + foreach ($objects as &$object) { + foreach ($object as $key => &$value) { + if ($key == "acl_group_changed") { + $value = 1; + } + } + } + + return parent::generateInsertQuery($objects); + } } diff --git a/www/modules/centreon-poller-display-central/core/class/configGenerate/centreon/AclTopology.php b/www/modules/centreon-poller-display-central/core/class/configGenerate/centreon/AclTopology.php new file mode 100644 index 0000000..ac35f39 --- /dev/null +++ b/www/modules/centreon-poller-display-central/core/class/configGenerate/centreon/AclTopology.php @@ -0,0 +1,87 @@ +. + * + * Linking this program statically or dynamically with other modules is making a + * combined work based on this program. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this program give Centreon + * permission to link this program with independent modules to produce an executable, + * regardless of the license terms of these independent modules, and to copy and + * distribute the resulting executable under terms of Centreon choice, provided that + * Centreon also meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module which is not + * derived from this program. If you modify this program, you may extend this + * exception to your version of the program, but you are not obliged to do so. If you + * do not wish to do so, delete this exception statement from your version. + * + * For more information : contact@centreon.com + * + */ + +namespace CentreonPollerDisplayCentral\ConfigGenerate\Centreon; + +use CentreonPollerDisplayCentral\ConfigGenerate\Object; + +class AclTopology extends Object +{ + + /** + * @var table + */ + protected $table = 'acl_topology'; + + /** + * @var array + * columns wanted + */ + protected $columns = array( + '*' + ); + + public function getList($clauseObject = null) + { + $aclTopology = $clauseObject; + $errors = array_filter($aclTopology); + if (empty($errors)) { + return ''; + } + + $first = true; + $clauseQuery = ' WHERE acl_topo_id IN ('; + foreach ($aclTopology as $acl) { + if (!$first) { + $clauseQuery .= ','; + } + $clauseQuery .= $acl['acl_topology_id']; + $first = false; + } + $clauseQuery .= ')'; + + $list = array(); + $query = 'SELECT ' . implode(',', $this->columns) . ' ' + . 'FROM ' . $this->table . $clauseQuery; + + $result = $this->db->query($query); + + while ($row = $result->fetch(\PDO::FETCH_ASSOC)) { + $list[] = $row; + } + + return $list; + } +} diff --git a/www/modules/centreon-poller-display-central/core/class/configGenerate/centreon/AclTopologyRelation.php b/www/modules/centreon-poller-display-central/core/class/configGenerate/centreon/AclTopologyRelation.php new file mode 100644 index 0000000..7962b23 --- /dev/null +++ b/www/modules/centreon-poller-display-central/core/class/configGenerate/centreon/AclTopologyRelation.php @@ -0,0 +1,135 @@ +. + * + * Linking this program statically or dynamically with other modules is making a + * combined work based on this program. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this program give Centreon + * permission to link this program with independent modules to produce an executable, + * regardless of the license terms of these independent modules, and to copy and + * distribute the resulting executable under terms of Centreon choice, provided that + * Centreon also meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module which is not + * derived from this program. If you modify this program, you may extend this + * exception to your version of the program, but you are not obliged to do so. If you + * do not wish to do so, delete this exception statement from your version. + * + * For more information : contact@centreon.com + * + */ + +namespace CentreonPollerDisplayCentral\ConfigGenerate\Centreon; + +use CentreonPollerDisplayCentral\ConfigGenerate\Object; + +class AclTopologyRelation extends Object +{ + + /** + * @var table + */ + protected $table = 'acl_topology_relations'; + + /** + * @var array + * columns wanted + */ + protected $columns = array( + '*' + ); + + public function getList($clauseObject = null) + { + $aclTopology = $clauseObject; + $errors = array_filter($aclTopology); + if (empty($errors)) { + return ''; + } + + $first = true; + $clauseQuery = ' WHERE acl_topo_id IN ('; + foreach ($aclTopology as $acl) { + if (!$first) { + $clauseQuery .= ','; + } + $clauseQuery .= $acl['acl_topo_id']; + $first = false; + } + $clauseQuery .= ')'; + + $list = array(); + $query = 'SELECT ' . implode(',', $this->columns) . ' ' + . 'FROM ' . $this->table . $clauseQuery; + + $result = $this->db->query($query); + + while ($row = $result->fetch(\PDO::FETCH_ASSOC)) { + $list[] = $row; + } + + return $list; + } + + /** + * + * @param type $objects + * @return string + */ + protected function generateInsertQuery($objects) + { + $insertQuery = ''; + if (!empty($objects)) { + if (implode(',', $this->columns) == '*') { + $this->columns = array_keys($objects[0]); + } + foreach ($objects as $object) { + $topologyDesc = $this->getTopologyDesc($object['topology_topology_id']); + $topologyQuery = '(SELECT topology_id FROM topology ' . + 'WHERE topology_name = "' . $topologyDesc['topology_name'] . '" ' . + 'AND topology_page = "' . $topologyDesc['topology_page'] . '")'; + + $insertQuery .= 'INSERT INTO `' . $this->table . '` (`' . implode('`,`', $this->columns) . '`) ' . "\n"; + $insertQuery .= 'SELECT * FROM (SELECT '; + $values = array(); + foreach ($object as $key => $value) { + if (is_null($value)) { + $values[] = 'NULL'; + } elseif ($key == 'topology_topology_id') { + $values[] = $topologyQuery; + } else { + $values[] = $this->db->quote($value); + } + } + $insertQuery .= implode(',', $values) . ') as tmp WHERE ' . $topologyQuery . "; \n"; + } + } + + return $insertQuery; + } + + public function getTopologyDesc($id) + { + if (empty($id)) { + return ''; + } + $query = 'SELECT topology_name, topology_page FROM topology WHERE topology_id = ' . $id; + $result = $this->db->query($query); + $row = $result->fetch(\PDO::FETCH_ASSOC); + return $row; + } +}