Exemplo n.º 1
0
 /**
  * Execute the event
  *
  * @param \CentreonMain\Events\Generic $event The object for event
  */
 public static function execute(GenericEvent $event)
 {
     $input = $event->getInput();
     if (false === isset($input['poller_id'])) {
         throw new \InvalidArgumentException();
     }
     $pollerInformation = Engine::get($input['poller_id']);
     $delimiter = '';
     if (isset($input['delimiter'])) {
         $delimiter = $input['delimiter'];
     }
     $keys = array_map(function ($name) use($delimiter) {
         return $delimiter . 'engine_' . $name . $delimiter;
     }, array_keys($pollerInformation));
     $values = array_combine($keys, array_values($pollerInformation));
     $event->setOutput($values);
 }
 /**
  * Load macros for replace in default configuration
  *
  * @param int $pollerId The poller id
  */
 private function loadMacros($pollerId)
 {
     $config = Di::getDefault()->get('config');
     /* Load contant values */
     $this->baseConfig['broker_central_ip'] = getHostByName(getHostName());
     /* Load user value */
     $this->baseConfig = array_merge($this->baseConfig, BrokerRepository::loadValues($pollerId));
     /* Load paths */
     $paths = BrokerRepository::getPathsFromPollerId($pollerId);
     $pathsValue = array_values($paths);
     $pathsKeys = array_map(function ($name) {
         switch ($name) {
             case 'directory_modules':
                 $str = 'modules_directory';
                 break;
             case 'directory_config':
                 $str = 'etc_directory';
                 break;
             case 'directory_logs':
                 $str = 'logs_directory';
                 break;
             case 'directory_data':
                 $str = 'data_directory';
                 break;
             default:
                 $str = '';
                 break;
         }
         return 'global_broker_' . $str;
     }, array_keys($paths));
     $paths = array_combine($pathsKeys, $pathsValue);
     $this->baseConfig = array_merge($this->baseConfig, $paths);
     $this->baseConfig['poller_id'] = $this->pollerId;
     /* Information for database */
     $dbInformation = CentreonDb::parseDsn($config->get('db_centreon', 'dsn'), $config->get('db_centreon', 'username'), $config->get('db_centreon', 'password'));
     $dbKeys = array_map(function ($name) {
         return 'global_' . $name;
     }, array_keys($dbInformation));
     $dbInformation = array_combine($dbKeys, array_values($dbInformation));
     $this->baseConfig = array_merge($dbInformation, $this->baseConfig);
     /* Load general poller information */
     $pollerInformation = Poller::get($pollerId);
     $this->baseConfig['poller_name'] = $pollerInformation['name'];
     /* Load configuration information from Centren Engine */
     $eventObj = new GenericEvent(array('poller_id' => $pollerId));
     Di::getDefault()->get('events')->emit('centreon-broker.poller.configuration', array($eventObj));
     $this->baseConfig = array_merge($eventObj->getOutput(), $this->baseConfig);
     /* get global value in database */
     $globalOptions = BrokerRepository::getGlobalValues();
     $this->baseConfig = array_merge($globalOptions, $this->baseConfig);
     /* Add % in begin and end of keys */
     $keys = array_keys($this->baseConfig);
     $values = array_values($this->baseConfig);
     $keys = array_map(function ($key) {
         return '%' . $key . '%';
     }, $keys);
     $this->baseConfig = array_combine($keys, $values);
 }