/**
  * Add block for send Centreon Broker configuration files
  *
  * @param \XMLWriter $gile The xml file
  */
 private function addConfigCentreonBrokerBlock($file)
 {
     $db = Di::getDefault()->get('db_centreon');
     $sql = "DELETE FROM cfg_centreonbroker_pollervalues WHERE poller_id = ? and name = ?";
     $stmt = $db->prepare($sql);
     /* The path for generate configuration */
     $configGeneratePath = rtrim(Di::getDefault()->get('config')->get('global', 'centreon_generate_tmp_dir'), '/') . '/broker';
     /* Get broker modules list */
     $brokerModules = self::getBrokerModules();
     foreach ($brokerModules as $brokerModule) {
         $name = "central-broker-cfg-broker-poller-module-" . $brokerModule['poller_id'];
         $file->startElement("output");
         $file->writeElement("name", $name);
         $file->writeElement("type", "dump_dir");
         $file->writeElement("path", $configGeneratePath . '/apply/' . $brokerModule['poller_id']);
         $file->writeElement("tagname", "cfg-broker-" . $brokerModule['poller_id']);
         $file->startElement('read_filters');
         $file->writeElement("category", "internal");
         $file->endElement();
         $file->endElement();
         $stmt->execute(array($brokerModule['poller_id'], 'dump_dir_broker'));
         BrokerPollerValues::insert(array('poller_id' => $brokerModule['poller_id'], 'name' => 'dump_dir_broker', 'value' => $name), true);
     }
 }
Exemplo n.º 2
0
 /**
  * Save broker parameters of a node
  *
  * @param int $pollerId
  * @param array $params
  */
 public static function save($pollerId, $params)
 {
     $db = Di::getDefault()->get('db_centreon');
     $arr = array();
     foreach ($params as $k => $v) {
         $arr[$k] = $v;
     }
     /* Save paths */
     /* Test if exists in db */
     $query = "SELECT COUNT(poller_id) as poller\n            FROM cfg_centreonbroker_paths\n            WHERE poller_id = :poller_id";
     $stmt = $db->prepare($query);
     $stmt->bindParam(':poller_id', $pollerId, \PDO::PARAM_INT);
     $stmt->execute();
     $row = $stmt->fetch();
     $stmt->closeCursor();
     $sqlParams = array();
     $sqlParams['poller_id'] = $pollerId;
     if (isset($params['directory_config'])) {
         $sqlParams['directory_config'] = $params['directory_config'];
     }
     if (isset($params['directory_modules'])) {
         $sqlParams['directory_modules'] = $params['directory_modules'];
     }
     if (isset($params['directory_logs'])) {
         $sqlParams['directory_logs'] = $params['directory_logs'];
     }
     if (isset($params['directory_data'])) {
         $sqlParams['directory_data'] = $params['directory_data'];
     }
     if (isset($params['init_script'])) {
         $sqlParams['init_script'] = $params['init_script'];
     }
     if (isset($params['directory_cbmod'])) {
         $sqlParams['directory_cbmod'] = $params['directory_cbmod'];
     }
     if ($row['poller'] > 0) {
         /* Update */
         Broker::update($pollerId, $sqlParams);
         BrokerPollerValues::delete($pollerId, false);
     } else {
         /* Insert */
         Broker::insert($sqlParams, true);
     }
     /* Save extract params */
     $listTpl = PollerTemplateManager::buildTemplatesList();
     $tmpl = "";
     if (isset($params['tmpl_name'])) {
         $tmpl = $params['tmpl_name'];
     }
     if (!isset($listTpl[$tmpl])) {
         return;
     }
     $fileTplList = $listTpl[$tmpl]->getBrokerPath();
     $information = array();
     foreach ($fileTplList as $fileTpl) {
         $information = static::mergeBrokerConf($information, $fileTpl);
     }
     $listType = array('output', 'input', 'logger');
     /* setup */
     foreach ($information['content']['broker']['setup'] as $setup) {
         /* mode */
         foreach ($setup['params']['mode'] as $mode) {
             /* type */
             foreach ($mode as $type => $config) {
                 /* @todo one peer retention */
                 if ($type == 'normal') {
                     /* module */
                     /* Sort for central in first install */
                     $configSorted = array();
                     if ($params['tmpl_name'] == 'Central') {
                         $configTmp = array();
                         foreach ($config as $module) {
                             if ($module['general']['name'] == 'central-broker') {
                                 $configTmp[0] = $module;
                             } else {
                                 if ($module['general']['name'] == 'central-rrd') {
                                     $configTmp[1] = $module;
                                 } else {
                                     if ($module['general']['name'] == 'poller-module') {
                                         $configTmp[2] = $module;
                                     }
                                 }
                             }
                         }
                         for ($i = 0; $i < count($configTmp); $i++) {
                             $configSorted[] = $configTmp[$i];
                         }
                     } else {
                         $configSorted = $config;
                     }
                     foreach ($configSorted as $module) {
                         $configId = static::insertConfig($pollerId, $module['general']['name'], $arr);
                         foreach ($listType as $type) {
                             if (isset($module[$type])) {
                                 $groupNb = 1;
                                 foreach ($module[$type] as $typeInfo) {
                                     /* Key */
                                     foreach ($typeInfo as $key => $value) {
                                         if (is_string($value) && preg_match("/%([\\w_]+|[\\w-]+)%/", $value, $matches)) {
                                             if (isset($params[$matches[1]]) && trim($params[$matches[1]]) !== "") {
                                                 static::insertPollerInfo($pollerId, $matches[1], $params[$matches[1]]);
                                             }
                                         } else {
                                             /* @todo add user infos */
                                         }
                                     }
                                     $groupNb++;
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }