Exemplo n.º 1
0
 /**
  * 
  * @param integer $pollerId
  * @return type
  * @throws Exception
  */
 public static function getTemplate($pollerId)
 {
     $paramsPoller = Poller::get($pollerId, 'tmpl_name');
     if (!isset($paramsPoller['tmpl_name']) || is_null($paramsPoller['tmpl_name'])) {
         throw new Exception('Not template defined');
     }
     $tmplName = $paramsPoller['tmpl_name'];
     /* Load template information for poller */
     $listTpl = TemplateManager::buildTemplatesList();
     if (!isset($listTpl[$tmplName])) {
         throw new Exception('The template is not found on list of templates', 255);
     }
     return $listTpl[$tmplName];
 }
Exemplo n.º 2
0
 /**
  * Get broker config from poller id
  *
  * @param int $pollerId
  */
 public static function getBrokerConfigFromPollerId($pollerId)
 {
     $poller = Poller::getParameters($pollerId, 'tmpl_name');
     $tmpl = $poller['tmpl_name'];
     $listTpl = PollerTemplateManager::buildTemplatesList();
     $fileTplList = $listTpl[$tmpl]->getBrokerPath();
     $information = array();
     foreach ($fileTplList as $fileTpl) {
         $information = static::mergeBrokerConf($information, $fileTpl);
     }
     return $information;
 }
 /**
  * Generate configuration files for Centreon Broker
  *
  * @param int $pollerId The poller id
  */
 public function generate($pollerId)
 {
     $dbconn = Di::getDefault()->get('db_centreon');
     $this->pollerId = $pollerId;
     if (!is_dir($this->tmpPath . '/' . $this->pollerId)) {
         mkdir($this->tmpPath . '/' . $this->pollerId);
     }
     /* Get poller template */
     $params = Poller::get($this->pollerId, 'tmpl_name');
     if (!isset($params['tmpl_name']) || is_null($params['tmpl_name'])) {
         throw new Exception('Not template defined');
     }
     $tmplName = $params['tmpl_name'];
     /* Load template information for poller */
     $listTpl = PollerTemplateManager::buildTemplatesList();
     if (!isset($listTpl[$tmplName])) {
         throw new Exception('The template is not found on list of templates');
     }
     $fileTplList = $listTpl[$tmplName]->getBrokerPath();
     //$this->tplInformation = json_decode(file_get_contents($fileTpl), true);
     $this->tplInformation = array();
     foreach ($fileTplList as $fileTpl) {
         $this->tplInformation = BrokerRepository::mergeBrokerConf($this->tplInformation, $fileTpl);
     }
     $this->loadMacros($pollerId);
     /* Get list of configuration files */
     $query = "SELECT config_id, config_name, flush_logs, write_timestamp, name, \n            write_thread_id, event_queue_max_size\n            FROM cfg_centreonbroker c, cfg_pollers p\n            WHERE c.poller_id = p.poller_id\n            AND p.poller_id = :poller_id";
     $stmt = $dbconn->prepare($query);
     $stmt->bindParam(':poller_id', $pollerId, \PDO::PARAM_INT);
     $stmt->execute();
     $result = $stmt->fetchAll();
     foreach ($result as $row) {
         $this->baseConfig['%broker_name%'] = $row['config_name'];
         $this->baseConfig['%poller_name%'] = $row['name'];
         static::generateModule($row);
     }
 }
 /**
  * Returns the template configuration values
  * 
  * @param int $pollerId
  * @return array
  * @throws \Centreon\Internal\Exception
  */
 private static function getTemplateValues($pollerId)
 {
     $templateValues = array();
     /* Retrieve template name  */
     $pollerParam = Poller::get($pollerId, 'tmpl_name');
     if (!isset($pollerParam['tmpl_name']) || is_null($pollerParam['tmpl_name'])) {
         return $templateValues;
     }
     /* Look for template file */
     $config = Di::getDefault()->get('config');
     $centreonPath = rtrim($config->get('global', 'centreon_path'), '/');
     /* Get template engine file */
     $listTpl = PollerTemplateManager::buildTemplatesList();
     if (!isset($listTpl[$pollerParam['tmpl_name']])) {
         throw new Exception('The template is not found on list of templates');
     }
     $jsonFile = $listTpl[$pollerParam['tmpl_name']]->getEnginePath();
     if (!file_exists($jsonFile)) {
         throw new Exception('Engine template file not found: ' . $pollerParam['tmpl_name'] . '.json');
     }
     /* Checks whether or not template file has all the sections */
     $arr = json_decode(file_get_contents($jsonFile), true);
     if (!isset($arr['content']) || !isset($arr['content']['engine']) || !isset($arr['content']['engine']['setup'])) {
         return $templateValues;
     }
     /* Retrieve parameter values */
     foreach ($arr['content']['engine']['setup'] as $setup) {
         if (isset($setup['params'])) {
             foreach ($setup['params'] as $k => $v) {
                 $templateValues[$k] = $v;
             }
         }
     }
     return $templateValues;
 }