/**
  * @param Core\Events\ManageCommandOptions $event
  */
 public static function execute(ManageCommandOptionsEvent $event)
 {
     $options = $event->getOptions();
     $args = $event->getArgs();
     $newInfos = array();
     if ($event->getObjectName() == 'poller') {
         if ($event->getAction() == 'createAction' && isset($args['template'])) {
             $newInfos = PollerRepository::addCommandTemplateInfos($args['template']);
         } else {
             if ($event->getAction() == 'updateAction' && isset($args['poller'])) {
                 $pollerIds = Poller::getIdByParameter('slug', array($args['poller']));
                 if (isset($pollerIds[0])) {
                     $pollerId = $pollerIds[0];
                     $templateName = Poller::getParameters($pollerId, 'tmpl_name');
                     $newInfos = PollerRepository::addCommandTemplateInfos($templateName['tmpl_name']);
                 }
             }
         }
     }
     foreach ($newInfos as $newInfo) {
         $newOption = array($newInfo['name'] => array('paramType' => 'params', 'help' => '', 'type' => 'string', 'toTransform' => $newInfo['name'], 'multiple' => '', 'required' => '0'));
         if (isset($newInfo['help'])) {
             $newOption[$newInfo['name']]['help'] = $newInfo['help'];
         }
         if (isset($newInfo['require']) && $newInfo['require'] == true && $event->getAction() == 'createAction') {
             $newOption[$newInfo['name']]['required'] = '1';
         }
         $event->addOption($newOption);
     }
 }
Пример #2
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']);
     }
 }
Пример #3
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;
 }
Пример #4
0
 /**
  * 
  * @param array $resultSet
  */
 protected function formatDatas(&$resultSet)
 {
     $router = Di::getDefault()->get('router');
     foreach ($resultSet as &$myHostSet) {
         $myHostSet['host_name'] = '<span class="icoListing">' . HostRepository::getIconImage($myHostSet['host_name']) . '</span>' . $myHostSet['host_name'];
         $sideMenuCustom = new SlideMenu($myHostSet['host_id']);
         $events = Di::getDefault()->get('events');
         $events->emit('centreon-configuration.slide.menu.host', array($sideMenuCustom));
         $myHostSet['DT_RowData']['right_side_menu_list'] = $sideMenuCustom->getMenu();
         $myHostSet['DT_RowData']['right_side_default_menu'] = $sideMenuCustom->getDefaultMenu();
         /* Host State */
         $myHostSet['host_name'] .= RealTimeHostRepository::getStatusBadge(RealTimeHostRepository::getStatus($myHostSet['host_id']));
         /* Poller */
         if (isset($myHostSet["poller_id"]) && $myHostSet["poller_id"] != "") {
             $poller = Poller::getParameters($myHostSet["poller_id"], 'name');
             $myHostSet["poller_id"] = $poller['name'];
         } else {
             $myHostSet["poller_id"] = "";
         }
         /* Templates */
         $myHostSet['host_template'] = "";
         $templates = HostRepository::getTemplateChain($myHostSet['host_id'], array(), 1);
         foreach ($templates as $template) {
             $myHostSet['host_template'] .= '<a href="' . $router->getPathFor("/centreon-configuration/hosttemplate/[i:id]", array('id' => $template['id'])) . '"><i class="icon-template ico-20"></i></a>';
         }
         /* Display human readable the check/retry interval */
         $myHostSet['host_check_interval'] = HumanReadable::convert($myHostSet['host_check_interval'], 's', $units, null, true);
         $myHostSet['host_retry_check_interval'] = HumanReadable::convert($myHostSet['host_retry_check_interval'], 's', $units, null, true);
         /* Get personal tags */
         $myHostSet['tagname'] = '';
         $aTagUsed = array();
         $aTags = TagsRepository::getList('host', $myHostSet['host_id'], 0, 0);
         foreach ($aTags as $oTags) {
             if (!in_array($oTags['id'], $aTagUsed)) {
                 $aTagUsed[] = $oTags['id'];
                 $myHostSet['tagname'] .= TagsRepository::getTag('host', $myHostSet['host_id'], $oTags['id'], $oTags['text'], $oTags['user_id'], 1);
             }
         }
         $myHostSet['tagname'] .= TagsRepository::getAddTag('host', $myHostSet['host_id']);
     }
 }
Пример #5
0
 /**
  * 
  * @param type $sModule
  * @param type $sNameObject
  * @param array $aDatas
  */
 public static function validateDataResource($sModule, $sNameObject, $aDatas)
 {
     $iObjectId = '';
     $return = '';
     $oRepository = $sModule . "\\Repository\\" . ucfirst($sNameObject . "Repository");
     $oModel = $sModule . "\\Models\\" . ucfirst($sNameObject);
     $sChampUnique = $oModel::getUniqueLabelField();
     $sChampPk = $oModel::getPrimaryKey();
     if (isset($aDatas['extraParams'][$sChampUnique])) {
         $sLabel = $aDatas['extraParams'][$sChampUnique];
     }
     if (isset($aDatas['extraParams']['resource_pollers'])) {
         $aPollers = explode(",", $aDatas['extraParams']['resource_pollers']);
         $aPollers = array_map('trim', $aPollers);
         $aPollers = array_diff($aPollers, array(''));
         if (isset($aDatas['extraParams']['resource_name']) && count($aPollers) > 0) {
             $aParams['resources'] = $sLabel;
             foreach ($aPollers as $iIdPoller) {
                 $sPollerName = "";
                 $aPollerName = Poller::getParameters($iIdPoller, 'name');
                 if (is_array($aPollerName) && isset($aPollerName['name']) & !empty($aPollerName['name'])) {
                     $sPollerName = $aPollerName['name'];
                 }
                 $aParams['poller'] = $sPollerName;
                 try {
                     $idReturned = $oRepository::getIdFromUnicity($aParams);
                     $iObjectId = '';
                     if (isset($aDatas['extraParams']['object_id']) && !empty($aDatas['extraParams']['object_id'])) {
                         $iObjectId = $aDatas['extraParams']['object_id'];
                     }
                     $return[] = self::compareResponse($iObjectId, $idReturned);
                 } catch (MissingParameterException $e) {
                     $return[] = 0;
                 }
             }
         }
     }
     return $return;
 }