示例#1
0
 /**
  * Execute action 
  *
  * @param \CentreonConfiguration\Events\SynchronizeDatabase $event
  * @throws Exception
  */
 public static function execute(SynchronizeDatabaseEvent $event)
 {
     try {
         BrokerRepository::sendCommand($event->getPollerId(), 'SYNC_CFG_DB;' . $event->getPollerId());
     } catch (\Exception $e) {
         $event->setOutput($e->getMessage());
     }
 }
 /**
  * Execute action 
  *
  * @param \CentreonConfiguration\Events\UpdateDatabase $event
  * @throws Exception
  */
 public static function execute(UpdateDatabaseEvent $event)
 {
     $command = sprintf("[%u] UPDATE_CFG_DB;", time());
     try {
         BrokerRepository::sendCommand($command . $event->getPollerId() . "\n");
     } catch (\Exception $e) {
         $event->setOutput($e->getMessage());
     }
 }
示例#3
0
 /**
  * Execute action 
  *
  * @param \CentreonConfiguration\Events\SynchronizeFiles $event
  * @throws Exception
  */
 public static function execute(SynchronizeFilesEvent $event)
 {
     $endpoints = BrokerRepository::getConfigEndpoints($event->getPollerId());
     foreach ($endpoints as $endpoint) {
         try {
             BrokerRepository::sendCommand($event->getPollerId(), $endpoint . ';DUMP_DIR');
         } catch (\Exception $e) {
             $event->setOutput($e->getMessage());
         }
     }
 }
示例#4
0
 /**
  * @param \CentreonConfiguration\Events\BrokerModule $event
  * @throws \Centreon\Internal\Exception
  */
 public static function execute(BrokerModuleEvent $event)
 {
     /* Retrieve etc and module path */
     $paths = BrokerRepository::getPathsFromPollerId($event->getPollerId());
     /* Set modules */
     if (isset($paths['directory_cbmod']) && isset($paths['directory_config'])) {
         $moduleDir = rtrim($paths['directory_cbmod'], '/');
         $etcDir = rtrim($paths['directory_config'], '/');
         $event->addModule("{$moduleDir}/cbmod.so {$etcDir}/poller-module.xml");
     }
 }
示例#5
0
 /**
  * @param CentreonMain\Events\PostSave $event
  */
 public static function execute(PostSaveEvent $event)
 {
     $parameters = $event->getParameters();
     $extraParameters = $event->getExtraParameters();
     if ($event->getObjectName() === 'poller') {
         foreach ($parameters as $key => $value) {
             $extraParameters['centreon-broker'][$key] = $value;
         }
         if ($event->getAction() === 'update' && !isset($extraParameters['centreon-broker']['tmpl_name'])) {
             $templateName = Poller::getParameters($extraParameters['centreon-broker']['object_id'], 'tmpl_name');
             $extraParameters['centreon-broker']['tmpl_name'] = $templateName['tmpl_name'];
         }
         BrokerRepository::save($event->getObjectId(), $extraParameters['centreon-broker']);
     }
 }
示例#6
0
 public static function execute(ExternalCommand $command)
 {
     // @todo found poller where I am
     $dbconn = Di::getDefault()->get('db_centreon');
     $query = 'SELECT config_id' . ' FROM cfg_centreonbroker' . ' WHERE poller_id = :poller_id' . ' AND config_name = "central-broker"';
     $stmt = $dbconn->prepare($query);
     $stmt->bindParam(':poller_id', $command->getPollerId(), \PDO::PARAM_INT);
     $stmt->execute();
     $row = $stmt->fetch();
     if ($row === false) {
         throw new \Exception("Can't get config id");
     }
     $brokerId = $row['config_id'];
     $nodeEvents = BrokerRepository::getBrokerEndpointFromBrokerId($brokerId, 'node_events');
     $nodeEvent = "";
     if (isset($nodeEvents[0]) && isset($nodeEvents[0]['name'])) {
         $nodeEvent = $nodeEvents[0]['name'];
     }
     if ($command->getType() === 'broker') {
         BrokerRepository::sendCommand($command->getPollerId(), $nodeEvent . ';' . $command->getCommand());
     }
 }
 /**
  * Update a broker
  *
  *
  * @method post
  * @route /broker/update
  */
 public function updateAction()
 {
     $givenParameters = $this->getParams('post');
     $updateSuccessful = true;
     $updateErrorMessage = '';
     try {
         $pollerId = $givenParameters['poller_id'];
         unset($givenParameters['poller_id']);
         \CentreonBroker\Repository\BrokerRepository::save($pollerId, $givenParameters);
     } catch (Exception $e) {
         $updateSuccessful = false;
         $updateErrorMessage = $e->getMessage();
         var_dump($e);
     }
     $this->router = Di::getDefault()->get('router');
     if ($updateSuccessful) {
         unset($_SESSION['form_token']);
         unset($_SESSION['form_token_time']);
         $this->router->response()->json(array('success' => true));
     } else {
         $this->router->response()->json(array('success' => false, 'error' => $updateErrorMessage));
     }
 }
 /**
  * 
  * @param type $formHandler
  * @param type $defaultValues
  * @param type $pollerId
  * @return type
  */
 public static function addPathParams(&$formHandler, &$defaultValues, $pollerId)
 {
     $pathOptions = array('broker_etc_directory' => 'directory_config', 'broker_module_directory' => 'directory_modules', 'broker_data_directory' => 'directory_data', 'broker_logs_directory' => 'directory_logs', 'broker_init_script' => 'init_script');
     $componentList = array();
     foreach (array_keys($pathOptions) as $pOpt) {
         $componentList[] = $pOpt;
         $componentLabel = ucwords(str_replace('_', ' ', $pOpt));
         $formHandler->addStatic(array('name' => $pOpt, 'type' => 'text', 'label' => $componentLabel, 'mandatory' => '1'));
     }
     $currentValues = BrokerRepository::getPathsFromPollerId($pollerId);
     foreach ($currentValues as $cKey => $cValue) {
         $defaultValues[array_search($cKey, $pathOptions)] = $cValue;
     }
     return $componentList;
 }
 /**
  * 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);
 }
示例#10
0
 /**
  *
  * @param \CentreonConfiguration\Events\BrokerFormSave $event
  */
 public static function execute(BrokerPollerConfEvent $event)
 {
     $event->addValues(BrokerRepository::loadValues($event->getPollerId()));
 }