コード例 #1
0
ファイル: PostSave.php プロジェクト: NicolasLarrouy/centreon
 /**
  * @param CentreonMain\Events\PostSave $event
  */
 public static function execute(PostSaveEvent $event)
 {
     $parameters = $event->getParameters();
     $extraParameters = $event->getExtraParameters();
     if (isset($extraParameters['centreon-configuration'])) {
         if ($event->getObjectName() === 'aclresource') {
             if (isset($extraParameters['centreon-configuration']['aclresource_hosts'])) {
                 $hostIds = array_filter(array_map('trim', explode(',', $extraParameters['centreon-configuration']['aclresource_hosts'])));
                 HostRepository::updateHostAcl($event->getAction(), $event->getObjectId(), $hostIds);
             }
             if (isset($extraParameters['centreon-configuration']['aclresource_host_tags'])) {
                 $hostTagIds = array_filter(array_map('trim', explode(',', $extraParameters['centreon-configuration']['aclresource_host_tags'])));
                 HostTagRepository::updateHostTagAcl($event->getAction(), $event->getObjectId(), $hostTagIds);
             }
             if (isset($extraParameters['centreon-configuration']['aclresource_services'])) {
                 $serviceIds = array_filter(array_map('trim', explode(',', $extraParameters['centreon-configuration']['aclresource_services'])));
                 ServiceRepository::updateServiceAcl($event->getAction(), $event->getObjectId(), $serviceIds);
             }
             if (isset($extraParameters['centreon-configuration']['aclresource_service_tags'])) {
                 $serviceTagIds = array_filter(array_map('trim', explode(',', $extraParameters['centreon-configuration']['aclresource_service_tags'])));
                 ServiceTagRepository::updateServiceTagAcl($event->getAction(), $event->getObjectId(), $serviceTagIds);
             }
             if (isset($extraParameters['centreon-configuration']['aclresource_all_hosts'])) {
                 $allHosts = $extraParameters['centreon-configuration']['aclresource_all_hosts'];
                 HostRepository::updateAllHostsAcl($event->getAction(), $event->getObjectId(), $allHosts);
             } else {
                 HostRepository::updateAllHostsAcl($event->getAction(), $event->getObjectId(), '0');
             }
         }
     }
 }
コード例 #2
0
 /**
  * @param CentreonEngine\Events\GetMacroHost $event
  */
 public static function execute(MacroHostEvent $event)
 {
     /* Macros for Host */
     $hosts = array_keys(HostRepository::getHostsByPollerId($event->getPollerId()));
     foreach ($hosts as $hostId) {
         $arrCustomMacro = CustomMacroRepository::loadHostCustomMacro($hostId);
         foreach ($arrCustomMacro as $customMacro) {
             $event->setMacro($hostId, $customMacro['macro_name'], $customMacro['macro_value']);
         }
     }
 }
コード例 #3
0
 /**
  * 
  */
 public function validate($value, $params = array(), $sContext = 'server')
 {
     if (isset($params['extraParams']['host_active_checks_enabled']) && $params['extraParams']['host_active_checks_enabled'] == "0") {
         $reponse = array('success' => true, 'error' => '');
         return $reponse;
     }
     if (!isset($value) || $value === " " || $value == "") {
         // case : UI or API with host-templates params
         if (isset($params['extraParams']['host_hosttemplates']) && $params['extraParams']['host_hosttemplates'] != " ") {
             $tplIds = explode(',', $params['extraParams']['host_hosttemplates']);
             foreach ($tplIds as $tplId) {
                 if (!empty($tplId)) {
                     $template = Hosttemplate::get($tplId);
                     $childTemplates = HostRepository::getTemplateChain($tplId, array(), -1, true);
                     if (!empty($template['command_command_id'])) {
                         $reponse = array('success' => true, 'error' => '');
                         return $reponse;
                     }
                     foreach ($childTemplates as $childTemplate) {
                         if (!empty($childTemplate['command_command_id'])) {
                             $reponse = array('success' => true, 'error' => '');
                             return $reponse;
                         }
                     }
                 }
             }
         } else {
             if (isset($params['object_id'])) {
                 // case : Only UI without host-templates params
                 $childTemplates = HostRepository::getTemplateChain($params['object_id'], array(), -1, true);
                 foreach ($childTemplates as $childTemplate) {
                     if (!empty($childTemplate['command_command_id']) || $childTemplate['command_command_id'] == "0") {
                         $reponse = array('success' => true, 'error' => '');
                         return $reponse;
                     }
                 }
             }
         }
         $reponse = array('success' => false, 'error' => 'No check command set on the host and its templates');
     } else {
         $reponse = array('success' => true, 'error' => '');
     }
     return $reponse;
 }
コード例 #4
0
ファイル: CircularDependency.php プロジェクト: rk4an/centreon
 /**
  * 
  */
 public function validate($value, $params = array(), $sContext = 'server')
 {
     $result = true;
     $resultError = _("Circular redundancy detected");
     if (isset($params['object']) && ($params['object'] === 'host' || $params['object'] === 'hosttemplate')) {
         $objectStack = explode(',', trim($value));
         foreach ($objectStack as $hostId) {
             if (isset($params['object_id']) && $hostId == $params['object_id']) {
                 $result = false;
             }
             $listHostId = HostRepository::getTemplateChain($hostId, array(), -1);
             foreach ($listHostId as $hostTemplateId) {
                 if (isset($params['object_id']) && $hostTemplateId['id'] == $params['object_id']) {
                     $result = false;
                 }
             }
         }
     } else {
         if (isset($params['object']) && ($params['object'] === 'service' || $params['object'] === 'servicetemplate')) {
             $serviceId = $value;
             $listServiceId = ServiceRepository::getListTemplates($serviceId);
             if (isset($params['object_id']) && $serviceId == $params['object_id']) {
                 $result = false;
             }
             foreach ($listServiceId as $serviceTemplateId) {
                 if (isset($params['object_id']) && $serviceTemplateId == $params['object_id']) {
                     $result = false;
                 }
             }
         }
     }
     if ($sContext == 'client') {
         $reponse = $result;
     } else {
         $reponse = array('success' => $result, 'error' => $resultError);
     }
     return $reponse;
 }
コード例 #5
0
 /**
  * Display the configuration snapshot of a host
  * with template inheritance
  *
  * @method get
  * @route /hosttemplate/snapshotslide/[i:id]
  */
 public function snapshotslideAction()
 {
     $params = $this->getParams();
     $data = HostTemplateRepository::getInheritanceValues($params['id'], true);
     $host = HostTemplate::get($params['id'], 'host_name');
     $data['host_name'] = $host['host_name'];
     $data['icon'] = HostRepository::getIconImage($data['host_name']);
     $hostConfiguration = HostRepository::formatDataForSlider($data);
     /*
     $aDataRealTime = HostRealtime::get($params['id']);
     $hostReal = HostRepository::formatDataForSlider($aDataRealTime);
     
     $servicesStatus = ServiceRealTimeRepository::countAllStatusForHost($params['id']);
     */
     $edit_url = $this->router->getPathFor("/centreon-configuration/hosttemplate/" . $params['id']);
     $this->router->response()->json(array('hostConfig' => $hostConfiguration, 'edit_url' => $edit_url, 'success' => true));
 }
コード例 #6
0
ファイル: ServiceDatatable.php プロジェクト: rk4an/centreon
 /**
  * 
  * @param array $resultSet
  */
 protected function formatDatas(&$resultSet)
 {
     $previousHost = '';
     HostRepository::setObjectClass('\\CentreonConfiguration\\Models\\Host');
     $router = Di::getDefault()->get('router');
     foreach ($resultSet as &$myServiceSet) {
         // Keep up
         $save = $myServiceSet['service_activate'];
         unset($myServiceSet['service_activate']);
         // Set host_name
         if ($myServiceSet['host_name'] === $previousHost) {
             $myServiceSet['host_name'] = '';
         } else {
             $previousHost = $myServiceSet['host_name'];
             $myServiceSet['host_name'] = '<span class="icoListing">' . HostRepository::getIconImage($myServiceSet['host_name']) . '</span>' . $myServiceSet['host_name'];
         }
         // Set Scheduling
         $myServiceSet['service_normal_check_interval'] = ServiceRepository::formatNotificationOptions(ServiceRepository::getMyServiceField($myServiceSet['service_id'], 'service_normal_check_interval'));
         $myServiceSet['service_retry_check_interval'] = ServiceRepository::formatNotificationOptions(ServiceRepository::getMyServiceField($myServiceSet['service_id'], 'service_normal_check_interval'));
         $myServiceSet['service_max_check_attempts'] = ServiceRepository::getMyServiceField($myServiceSet['service_id'], 'service_max_check_attempts');
         // Get Real Service Description
         if (!$myServiceSet["service_description"]) {
             $myServiceSet["service_description"] = ServiceRepository::getMyServiceAlias($myServiceSet['service_template_model_stm_id']);
         }
         $sideMenuCustom = new SlideMenu($myServiceSet['service_id']);
         $events = Di::getDefault()->get('events');
         $events->emit('centreon-configuration.slide.menu.service', array($sideMenuCustom));
         $myServiceSet['DT_RowData']['right_side_menu_list'] = $sideMenuCustom->getMenu();
         $myServiceSet['DT_RowData']['right_side_default_menu'] = $sideMenuCustom->getDefaultMenu();
         // Set Tpl Chain
         $tplStr = null;
         $tplArr = ServiceRepository::getMyServiceTemplateModels($myServiceSet["service_template_model_stm_id"]);
         $idServiceTpl = $myServiceSet["service_template_model_stm_id"];
         if (!is_null($tplArr)) {
             $tplRoute = str_replace("//", "/", $router->getPathFor('/centreon-configuration/servicetemplate/[i:id]', array('id' => $tplArr['id'])));
             $tplStr .= '<span><a href="' . $tplRoute . '">' . $tplArr['description'] . '</a></span>';
             $myServiceSet['service_template_model_stm_id'] = $tplStr;
         }
         $myServiceSet['service_description'] = '<span class="icoListing">' . ServiceRepository::getIconImage($myServiceSet['service_id']) . '</span>' . $myServiceSet['service_description'];
         $myServiceSet['service_description'] .= '</a><a href="#">';
         $myServiceSet['service_description'] .= ServiceRealTimeRepository::getStatusBadge(ServiceRealTimeRepository::getStatus($myServiceSet["host_id"], $myServiceSet["service_id"]));
         $myServiceSet['service_activate'] = $save;
         /* Get personal tags */
         $myServiceSet['tagname'] = '';
         $aTagUsed = array();
         $aTags = TagsRepository::getList('service', $myServiceSet['service_id'], 0, 0);
         foreach ($aTags as $oTags) {
             if (!in_array($oTags['id'], $aTagUsed)) {
                 $aTagUsed[] = $oTags['id'];
                 $myServiceSet['tagname'] .= TagsRepository::getTag('service', $myServiceSet['service_id'], $oTags['id'], $oTags['text'], $oTags['user_id'], 1);
             }
         }
         $myServiceSet['tagname'] .= TagsRepository::getAddTag('service', $myServiceSet['service_id']);
     }
 }
コード例 #7
0
ファイル: HostController.php プロジェクト: rk4an/centreon
 /**
  * Get command of a Host
  *
  *
  * @method get
  * @route /host/[i:id]/command
  */
 public function getHostCommandAction()
 {
     $requestParam = $this->getParams('named');
     $inerithedCommand = HostRepository::getInheritanceValues($requestParam['id'], true, array('command_command_id'));
     $commandName = "";
     if (isset($inerithedCommand['command_command_id']) && !is_null($inerithedCommand['command_command_id'])) {
         $command = Command::getParameters($inerithedCommand['command_command_id'], 'command_name');
         $commandName = $command['command_name'];
     }
     $this->router->response()->json($commandName);
 }
コード例 #8
0
ファイル: ServiceDatatable.php プロジェクト: rk4an/centreon
 /**
  * 
  * @param array $resultSet
  * @todo fix getIconImage() (perf issue)
  */
 protected function formatDatas(&$resultSet)
 {
     $router = Di::getDefault()->get('router');
     $previousHost = '';
     HostConfigurationRepository::setObjectClass('\\CentreonConfiguration\\Models\\Host');
     foreach ($resultSet as $key => &$myServiceSet) {
         $aTagUsed = array();
         // Set host_name
         $myHostName = Host::get($myServiceSet['host_id'], array('name'));
         $myServiceSet['name'] = $myHostName['name'];
         $sideMenuCustom = new SlideMenu($myServiceSet['service_id']);
         $events = Di::getDefault()->get('events');
         $events->emit('centreon-realtime.slide.menu.service', array($sideMenuCustom));
         $myServiceSet['DT_RowData']['right_side_menu_list'] = $sideMenuCustom->getMenu();
         $myServiceSet['DT_RowData']['right_side_default_menu'] = $sideMenuCustom->getDefaultMenu();
         // @todo remove virtual hosts and virtual services
         if ($myServiceSet['name'] === '_Module_BAM') {
             unset($resultSet[$key]);
             continue;
         }
         if ($myServiceSet['name'] === $previousHost) {
             $myServiceSet['name'] = '';
         } else {
             $previousHost = $myServiceSet['name'];
             $icon = '<span class="icoListing">' . HostConfigurationRepository::getIconImage($myServiceSet['name']) . '</span>';
             $myServiceSet['name'] = $icon . $myServiceSet['name'];
         }
         $icon = '<span class="icoListing">' . ServiceConfigurationRepository::getIconImage($myServiceSet['service_id']) . '</span>';
         /*$myServiceSet['DT_RowData']['right_side_details'] = $router->getPathFor('/centreon-realtime/service/')
               . $myServiceSet['host_id']
               . '/'.$myServiceSet['service_id']
               . '/tooltip';
           */
         $myServiceSet['description'] = '<span>' . $icon . '' . $myServiceSet['description'] . '</span>';
         if ($myServiceSet['state'] != '0' && $myServiceSet['state'] != '4') {
             $acknowledgement = ServiceRealtimeRepository::getAcknowledgementInfos($myServiceSet['service_id']);
             if (count($acknowledgement) > 0) {
                 $myServiceSet['description'] .= ' <i class="fa fa-thumb-tack"></i>';
             }
         }
         if ($myServiceSet['perfdata'] != '') {
             $myServiceSet['ico'] = '<span data-overlay-url="/centreon-realtime/service/' . $myServiceSet['host_id'] . '/' . $myServiceSet['service_id'] . '/graph"><span class="overlay"><i class="fa fa-bar-chart-o"></i></span></span>';
         } else {
             $myServiceSet['ico'] = '';
         }
         $myServiceSet['duration'] = Datetime::humanReadable(time() - $myServiceSet['duration'], Datetime::PRECISION_FORMAT, 2);
         $myServiceSet['last_check'] = Datetime::humanReadable(time() - $myServiceSet['last_check'], Datetime::PRECISION_FORMAT, 2);
         /* Tags */
         $myServiceSet['tagname'] = "";
         $aTags = TagsRepository::getList('service', $myServiceSet['service_id'], 2, 0);
         foreach ($aTags as $oTags) {
             if (!in_array($oTags['id'], $aTagUsed)) {
                 $aTagUsed[] = $oTags['id'];
                 $myServiceSet['tagname'] .= TagsRepository::getTag('service', $myServiceSet['service_id'], $oTags['id'], $oTags['text'], $oTags['user_id'], $oTags['template_id']);
             }
         }
         /*
         $templates = ServiceConfigurationRepository::getListTemplates($myServiceSet['service_id'], array(), -1);
         foreach ($templates as $template) {
             $aTags = TagsRepository::getList('service', $template, 2, 0);
             foreach ($aTags as $oTags) {
                 if (!in_array($oTags['id'], $aTagUsed)) {
                     $aTagUsed[] = $oTags['id'];
                     $myServiceSet['tagname'] .= TagsRepository::getTag('service', $template, $oTags['id'], $oTags['text'], $oTags['user_id'], 1);
                 }
             }
         }
         */
         $myServiceSet['tagname'] .= TagsRepository::getAddTag('service', $myServiceSet['service_id']);
     }
     $resultSet = array_values($resultSet);
 }
コード例 #9
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'];
         /* 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);
         $sideMenuCustom = new SlideMenu($myHostSet['host_id']);
         $events = Di::getDefault()->get('events');
         $events->emit('centreon-configuration.slide.menu.host.template', array($sideMenuCustom));
         //$myHostSet['DT_RowData']['right_side_details'] = $router->getPathFor('/centreon-configuration/host/snapshot/').$myHostSet['host_id'];
         $myHostSet['DT_RowData']['right_side_menu_list'] = $sideMenuCustom->getMenu();
         $myHostSet['DT_RowData']['right_side_default_menu'] = $sideMenuCustom->getDefaultMenu();
         /* 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']);
     }
 }
コード例 #10
0
ファイル: TagsRepository.php プロジェクト: rk4an/centreon
 /**
  * Get the list of inhereted tags
  * @param string $resourceName
  * @param int $resourceId
  * @return array
  */
 public static function getHeritedTags($resourceName, $resourceId)
 {
     $resourceName = self::convertResource($resourceName);
     if (!in_array($resourceName, static::$resourceType)) {
         throw new Exception("This resource type does not support tags.");
     }
     if (empty($resourceId)) {
         return array();
     }
     $aTagUsed = array();
     $aTags = array();
     if ($resourceName == 'host') {
         $templates = HostRepository::getTemplateChain($resourceId, array(), -1);
         foreach ($templates as $template) {
             $aTagsInHost = TagsRepository::getList('host', $template['id'], 1, 0);
             foreach ($aTagsInHost as $oTags) {
                 if (!in_array($oTags['id'], $aTagUsed)) {
                     $aTagUsed[] = $oTags['id'];
                     $aTags[] = $oTags['text'];
                 }
             }
         }
     } elseif ($resourceName == 'service') {
         $templates = ServiceRepository::getListTemplates($resourceId, array(), -1);
         foreach ($templates as $template) {
             $aTagsInSvc = TagsRepository::getList('service', $template, 1, 0);
             foreach ($aTagsInSvc as $oTags) {
                 if (!in_array($oTags['id'], $aTagUsed)) {
                     $aTagUsed[] = $oTags['id'];
                     $aTags[] = $oTags['text'];
                 }
             }
         }
     }
     return array('success' => true, 'values' => $aTags);
 }
コード例 #11
0
 /**
  * Convert the list of events for web output
  *
  * @param array $listEvents The list of events
  * @return array The datas for infinite scroll
  */
 private function convertListEventLogs($listEvents)
 {
     HostRepository::setObjectClass('\\CentreonConfiguration\\Models\\Host');
     /* Convert data for output */
     $lastDateCount = 0;
     $lastDate = null;
     $firstDate = null;
     $data = array();
     foreach ($listEvents as $log) {
         if ($lastDate != $log['datetime']) {
             $lastDate = $log['datetime'];
             $lastDateCount = 0;
         }
         if (is_null($firstDate)) {
             $firstDate = $log['datetime'];
         }
         $lastDateCount++;
         if (isset($log['host']) && $log['host'] !== "") {
             $log['host_logo'] = HostRepository::getIconImage($log['host']);
         }
         if (isset($log['service']) && $log['service'] !== "") {
             $log['service_logo'] = ServiceRepository::getIconImage($log['service']);
         }
         if ($log['type'] != '') {
             if ($log['type'] == 1) {
                 $log['type'] = 'HARD';
             } else {
                 $log['type'] = 'SOFT';
             }
         } else {
             $log['type'] = "&nbsp;";
         }
         /* Translate the status id */
         if (isset($log['service_id']) && isset($log['host_id']) && $log['status'] !== '') {
             try {
                 $log['status_text'] = Status::numToString($log['status'], Status::TYPE_SERVICE, true);
             } catch (\OutOfBoundsException $e) {
                 $log['status_text'] = "";
             }
         } elseif (!isset($log['service_id']) && $log['status'] !== '') {
             try {
                 $log['status_text'] = Status::numToString($log['status'], Status::TYPE_HOST, true);
             } catch (\OutOfBoundsException $e) {
                 $log['status_text'] = "";
             }
         } else {
             if ($log['status'] !== '') {
                 try {
                     $log['status_text'] = Status::numToString($log['status'], Status::TYPE_EVENT, true);
                 } catch (\OutOfBoundsException $e) {
                     $log['status_text'] = "";
                 }
             }
         }
         if ($log['msg_type'] != 1 && $log['msg_type'] != 0) {
             $log['status_css'] = '';
             $log['border_color'] = 'centreon-border-info';
         } elseif ($log['msg_type'] == 1) {
             $log['status_css'] = 'centreon-status-h-' . $log['status'];
             $log['border_color'] = 'centreon-border-status-h-' . $log['status'];
         } else {
             $log['status_css'] = 'centreon-status-s-' . $log['status'];
             $log['border_color'] = 'centreon-border-status-s-' . $log['status'];
         }
         /* For test */
         $log['object_name'] = "";
         $object_name = array();
         if (isset($log['host']) && $log['host'] !== "") {
             $object_name[] = $log['host'];
         }
         if (isset($log['service']) && $log['service'] !== "") {
             $object_name[] = $log['service'];
         }
         if (count($object_name) > 0) {
             $log['object_name'] = join(' - ', $object_name);
         } else {
             $log['object_name'] = 'Other';
         }
         $log['logo'] = "<i class='fa fa-gear'></i>";
         if (isset($log['service_logo'])) {
             $log['logo'] = $log['service_logo'];
         } else {
             if (isset($log['host_logo'])) {
                 $log['logo'] = $log['host_logo'];
             }
         }
         if (isset($log['output'])) {
             $log['description'] = $log['output'];
         }
         $data[] = $log;
     }
     return array('data' => $data, 'lastTimeEntry' => $lastDate, 'nbEntryForLastTime' => $lastDateCount, 'recentTime' => $firstDate, 'facets' => array());
 }
コード例 #12
0
ファイル: HostController.php プロジェクト: rk4an/centreon
 /**
  * Display the realtime snapshot of a host
  *
  * @method get
  * @route /host/snapshotslide/[i:id]
  */
 public function snapshotslideAction()
 {
     $params = $this->getParams();
     $data['configurationData'] = HostConfRepository::getInheritanceValues($params['id'], true);
     $data['configurationData']['host_id'] = $params['id'];
     $host = HostConf::get($params['id'], 'host_name');
     $data['configurationData']['host_name'] = $host['host_name'];
     $data['realtimeData'] = HostRealtime::get($params['id']);
     $hostInformations = HostRepository::formatDataForSlider($data);
     $servicesStatus = ServiceRepository::countAllStatusForHost($params['id']);
     $view_url = $this->router->getPathFor("/centreon-realtime/host/" . $params['id']);
     $this->router->response()->json(array('hostInformations' => $hostInformations, 'servicesStatus' => $servicesStatus, 'view_url' => $view_url, 'success' => true));
 }
コード例 #13
0
 /**
  * 
  * @param array $resultSet
  */
 protected function formatDatas(&$resultSet)
 {
     foreach ($resultSet as $key => &$myHostSet) {
         $sideMenuCustom = new SlideMenu($myHostSet['host_id']);
         $events = Di::getDefault()->get('events');
         $events->emit('centreon-realtime.slide.menu.host', array($sideMenuCustom));
         $myHostSet['DT_RowData']['right_side_menu_list'] = $sideMenuCustom->getMenu();
         $myHostSet['DT_RowData']['right_side_default_menu'] = $sideMenuCustom->getDefaultMenu();
         $aTagUsed = array();
         // @todo remove virtual hosts and virtual services
         if ($myHostSet['name'] === '_Module_BAM') {
             unset($resultSet[$key]);
             continue;
         }
         // Set host_name
         $myHostSet['name'] = '<span class="icoListing">' . HostConfigurationRepository::getIconImage($myHostSet['name']) . '</span>' . $myHostSet['name'];
         if ($myHostSet['state'] != '0' && $myHostSet['state'] != '4') {
             $acknowledgement = HostRealtimeRepository::getAcknowledgementInfos($myHostSet['host_id']);
             if (count($acknowledgement) > 0) {
                 $myHostSet['name'] .= ' <i class="fa fa-thumb-tack"></i>';
             }
         }
         $myHostSet['duration'] = Datetime::humanReadable(time() - $myHostSet['duration'], Datetime::PRECISION_FORMAT, 2);
         $myHostSet['last_check'] = Datetime::humanReadable(time() - $myHostSet['last_check'], Datetime::PRECISION_FORMAT, 2);
         /* Tags */
         $myHostSet['tagname'] = "";
         /*
                     $aTags = TagsRepository::getList('host', $myHostSet['host_id'], 2, 0);
                     foreach ($aTags as $oTags) {
            $myHostSet['tagname'] .= TagsRepository::getTag('host', $myHostSet['host_id'], $oTags['id'], $oTags['text'], $oTags['user_id'], $oTags['template_id']);
                     }
         * 
         */
         $aTags = TagsRepository::getList('host', $myHostSet['host_id'], 2, 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'], $oTags['template_id']);
             }
         }
         //Get tags affected by the template
         $templates = HostConfigurationRepository::getTemplateChain($myHostSet['host_id'], array(), -1);
         foreach ($templates as $template) {
             $aTags = TagsRepository::getList('host', $template['id'], 2, 0);
             foreach ($aTags as $oTags) {
                 if (!in_array($oTags['id'], $aTagUsed)) {
                     $aTagUsed[] = $oTags['id'];
                     $myHostSet['tagname'] .= TagsRepository::getTag('host', $template['id'], $oTags['id'], $oTags['text'], $oTags['user_id'], 1);
                 }
             }
         }
         $myHostSet['tagname'] .= TagsRepository::getAddTag('host', $myHostSet['host_id']);
     }
     $resultSet = array_values($resultSet);
 }
コード例 #14
0
ファイル: HostRepository.php プロジェクト: rk4an/centreon
 /**
  * Deploy services by host templates
  *
  * @param int $hostId
  * @param int $hostTemplateId
  */
 public static function deployServices($hostId, $hostTemplateId = null)
 {
     static $deployedServices = array();
     $aServices = array();
     $db = Di::getDefault()->get('db_centreon');
     //get host template
     $aHostTemplates = HostRepository::getTemplateChain($hostId, array(), -1);
     // get host services
     $aHostServices = HostServiceRelation::getMergedParameters(array('host_id'), array('service_id', 'service_description', 'service_alias', 'inherited'), -1, 0, null, "ASC", array('host_id' => $hostId), "OR");
     // get all service templates linked to a host by its host templates
     $aHostServiceTemplates = array();
     foreach ($aHostTemplates as $oHostTemplate) {
         $aHostTemplateServiceTemplates = HostTemplateServiceTemplateRelation::getMergedParameters(array('host_id'), array('service_id', 'service_description', 'service_alias'), -1, 0, null, "ASC", array('host_id' => $oHostTemplate['id']), "OR");
         // Remove services with same description
         foreach ($aHostTemplateServiceTemplates as $oHostTemplateServiceTemplate) {
             if (!isset($aHostServiceTemplates[$oHostTemplateServiceTemplate['service_alias']])) {
                 $aHostServiceTemplates[$oHostTemplateServiceTemplate['service_alias']] = $oHostTemplateServiceTemplate;
             }
         }
     }
     // get services linked to the host
     $aServicesDescription = array_values(array_column($aHostServices, 'service_description'));
     $repository = "CentreonConfiguration\\Repository\\ServiceRepository";
     $repository::setRelationMap(array("service_hosts" => "\\CentreonConfiguration\\Models\\Relation\\Service\\Host", "service_parents" => "\\CentreonConfiguration\\Models\\Relation\\Service\\Serviceparents", "service_children" => "\\CentreonConfiguration\\Models\\Relation\\Service\\Servicechildren"));
     $repository::setObjectName("Service");
     $repository::setObjectClass("\\CentreonConfiguration\\Models\\Service");
     $oModel = "CentreonConfiguration\\Models\\Service";
     $oSlugify = new CentreonSlugify($oModel, $repository);
     $db->beginTransaction();
     $aTemplateServicesDescription = array_keys($aHostServiceTemplates);
     foreach ($aHostServices as $service) {
         if ($service['inherited'] == 1 && !in_array($service['service_description'], $aTemplateServicesDescription)) {
             Service::delete($service['service_id']);
         }
     }
     // create services which don't yet exist
     foreach ($aHostServiceTemplates as $oHostServiceTemplate) {
         if (!in_array($oHostServiceTemplate['service_alias'], $aServicesDescription)) {
             $sHostName = Host::get($hostId, 'host_name');
             if (isset($sHostName['host_name'])) {
                 $sString = $sHostName['host_name'] . " " . $oHostServiceTemplate['service_alias'];
             } else {
                 $sString = $oHostServiceTemplate['service_alias'];
             }
             $sSlug = $oSlugify->slug($sString);
             if (!empty($oHostServiceTemplate['service_alias'])) {
                 $sData = $oHostServiceTemplate['service_alias'];
             } else {
                 $sData = $oHostServiceTemplate['service_description'];
             }
             $newService['service_slug'] = $sSlug;
             $newService['service_description'] = $sData;
             $newService['service_template_model_stm_id'] = $oHostServiceTemplate['service_id'];
             $newService['service_register'] = 1;
             $newService['service_activate'] = 1;
             $newService['organization_id'] = Di::getDefault()->get('organization');
             $newService['inherited'] = 1;
             $serviceId = Service::insert($newService);
             HostServiceRelation::insert($hostId, $serviceId);
             ServiceHostTemplateRelation::insert($serviceId, $oHostServiceTemplate['host_id']);
         }
     }
     $db->commit();
 }
コード例 #15
0
 /**
  * Get the value from template
  *
  * @param int $hostId The host template Id
  * @param bool $isBase If the host template id is the base for get values
  * @return array
  */
 public static function getInheritanceValues($hostId, $isBase = false, $columns = array())
 {
     $values = array();
     $templates = HostRepository::getTemplateChain($hostId, array(), -1);
     if ($isBase) {
         array_unshift($templates, array('id' => $hostId));
     }
     foreach ($templates as $template) {
         if (count($columns) > 0) {
             $inheritanceValues = static::getInheritanceValues($template['id'], false, $columns);
             $tmplValues = Hosttemplate::getParameters($template['id'], $columns);
         } else {
             $inheritanceValues = static::getInheritanceValues($template['id']);
             $tmplValues = Hosttemplate::getParameters($template['id'], self::$inheritanceColumns);
         }
         $tmplValues = array_filter($tmplValues, function ($value) {
             return !is_null($value);
         });
         $tmplValues = array_merge($inheritanceValues, $tmplValues);
         $values = array_merge($tmplValues, $values);
     }
     return $values;
 }
コード例 #16
0
ファイル: Status.php プロジェクト: NicolasLarrouy/centreon
 /**
  * Execute the event
  *
  * @param \CentreonMain\Events\Status $event The event object
  */
 public static function execute(StatusEvent $event)
 {
     $router = Di::getDefault()->get('router');
     $arrayStatusService = array('success', 'warning', 'critical', 'unknown', 'pending');
     $arrayStatusHost = array('success', 'critical', 'unreachable', '', 'pending');
     $totalHosts = 0;
     $totalServices = 0;
     $incidents = IncidentsRepository::getIncidents();
     $issues = array();
     foreach ($incidents as $incident) {
         if (is_null($incident['service_desc'])) {
             $state = $arrayStatusHost[$incident['state']];
             if (empty($issues[$state]['nb_hosts'])) {
                 $issues[$state]['nb_hosts'] = 0;
             }
             if (empty($issues[$state]['total_impacts'])) {
                 $issues[$state]['total_impacts'] = 0;
             }
             if (!isset($issues[$state]['objects']['hosts']) || count($issues[$state]['objects']['hosts']) < 5) {
                 $hostsTemp = IncidentsRepository::formatDataForHeader($incident, 'host');
                 $hostsTemp['icon'] = HostRepositoryConfig::getIconImagePath($incident['host_id']);
                 $hostsTemp['url'] = $router->getPathFor('/centreon-realtime/host/' . $incident['host_id']);
                 $duration = Datetime::humanReadable(time() - $incident['stimestamp'], Datetime::PRECISION_FORMAT, 2);
                 $hostsTemp['since'] = $duration;
                 $issues[$state]['objects']['hosts'][] = $hostsTemp;
             }
             $childIncidents = IncidentsRepository::getChildren($incident['issue_id']);
             $issues[$state]['nb_hosts'] = $issues[$state]['nb_hosts'] + 1;
             $issues[$state]['total_impacts'] = $issues[$state]['total_impacts'] + count($childIncidents);
         } else {
             $state = $arrayStatusService[$incident['state']];
             if (empty($issues[$state]['nb_services'])) {
                 $issues[$state]['nb_services'] = 0;
             }
             if (empty($issues[$state]['total_impacts'])) {
                 $issues[$state]['total_impacts'] = 0;
             }
             if (!isset($issues[$state]['objects']['services']) || count($issues[$state]['objects']['services']) < 5) {
                 $serviceTemp = IncidentsRepository::formatDataForHeader($incident, 'service');
                 $serviceTemp['icon'] = ServiceRepositoryConfig::getIconImage($incident['service_id']);
                 $serviceTemp['url'] = $router->getPathFor('/centreon-realtime/service/' . $incident['service_id']);
                 $duration = Datetime::humanReadable(time() - $incident['stimestamp'], Datetime::PRECISION_FORMAT, 2);
                 $serviceTemp['since'] = $duration;
                 $issues[$state]['objects']['services'][] = $serviceTemp;
             }
             $childIncidents = IncidentsRepository::getChildren($incident['issue_id']);
             $issues[$state]['nb_services'] = $issues[$state]['nb_services'] + 1;
             $issues[$state]['total_impacts'] = $issues[$state]['total_impacts'] + count($childIncidents);
         }
     }
     $hosts = \CentreonRealtime\Models\Host::getList();
     $configurationobjects = array();
     $configurationobjects['pending']['nb_hosts'] = 0;
     $configurationobjects['unreachable']['nb_hosts'] = 0;
     foreach ($hosts as $host) {
         $totalHosts++;
         $state = $arrayStatusHost[$host['state']];
         if ($host['state'] == "4") {
             $configurationobjects['pending']['nb_hosts']++;
             $hostsTemp = $host;
             $duration = Datetime::humanReadable(time() - $host['last_update'], Datetime::PRECISION_FORMAT, 2);
             $hostsTemp['icon'] = HostRepositoryConfig::getIconImagePath($host['host_id']);
             $hostsTemp['url'] = $router->getPathFor('/centreon-realtime/host/' . $host['host_id']);
             $hostsTemp['since'] = $duration;
             $hostsTemp['state'] = $state;
             $configurationobjects['pending']['objects']['hosts'][] = HostRepository::formatDataForHeader($hostsTemp);
         } else {
             if ($host['state'] == "3") {
                 $configurationobjects['unreachable']['nb_hosts']++;
                 $hostsTemp = $host;
                 $duration = Datetime::humanReadable(time() - $host['last_update'], Datetime::PRECISION_FORMAT, 2);
                 $hostsTemp['icon'] = HostRepositoryConfig::getIconImagePath($host['host_id']);
                 $hostsTemp['url'] = $router->getPathFor('/centreon-realtime/host/' . $host['host_id']);
                 $hostsTemp['since'] = $duration;
                 $hostsTemp['state'] = $state;
                 $configurationobjects['unreachable']['objects']['hosts'][] = HostRepository::formatDataForHeader($hostsTemp);
             }
         }
     }
     $services = \CentreonRealtime\Models\Service::getList();
     $configurationobjects['pending']['nb_services'] = 0;
     $configurationobjects['unknown']['nb_services'] = 0;
     foreach ($services as $service) {
         $totalServices++;
         $state = $arrayStatusService[$service['state']];
         if ($service['state'] == "4") {
             $configurationobjects['pending']['nb_services']++;
             $serviceTemp = $service;
             $duration = Datetime::humanReadable(time() - $service['last_update'], Datetime::PRECISION_FORMAT, 2);
             $serviceTemp['icon'] = ServiceRepositoryConfig::getIconImage($service['service_id']);
             $serviceTemp['url'] = $router->getPathFor('/centreon-realtime/service/' . $service['service_id']);
             $serviceTemp['since'] = $duration;
             $serviceTemp['state'] = $state;
             $configurationobjects['pending']['objects']['services'][] = ServiceRepository::formatDataForHeader($serviceTemp);
         } else {
             if ($service['state'] == "3") {
                 $configurationobjects['unknown']['nb_services']++;
                 $serviceTemp = $service;
                 $duration = Datetime::humanReadable(time() - $service['last_update'], Datetime::PRECISION_FORMAT, 2);
                 $serviceTemp['icon'] = ServiceRepositoryConfig::getIconImage($service['service_id']);
                 $serviceTemp['url'] = $router->getPathFor('/centreon-realtime/service/' . $service['service_id']);
                 $serviceTemp['since'] = $duration;
                 $serviceTemp['state'] = $state;
                 $configurationobjects['unknown']['objects']['services'][] = ServiceRepository::formatDataForHeader($serviceTemp);
             }
         }
     }
     //Get pollers infos
     $pollersStatus = PollerRepository::pollerStatus();
     $pollers = array();
     $pollers['stopped']['nb_pollers'] = 0;
     $pollers['unreachable']['nb_pollers'] = 0;
     foreach ($pollersStatus as $poller) {
         if ($poller['running'] != "1") {
             $pollers['stopped']['nb_pollers']++;
             $pollerTemp = PollerRepository::formatDataForHeader($poller);
             $duration = Datetime::humanReadable(time() - $poller['last_alive'], Datetime::PRECISION_FORMAT, 2);
             $pollerTemp['url'] = $router->getPathFor('/centreon-configuration/poller/' . $poller['instance_id']);
             $pollerTemp['since'] = $duration;
             $pollers['stopped']['objects'][] = $pollerTemp;
         } else {
             if ($poller['disconnect'] == "1") {
                 $pollers['unreachable']['nb_pollers']++;
                 $pollerTemp = PollerRepository::formatDataForHeader($poller);
                 $duration = Datetime::humanReadable(time() - $poller['last_alive'], Datetime::PRECISION_FORMAT, 2);
                 $pollerTemp['url'] = $router->getPathFor('/centreon-configuration/poller/' . $poller['instance_id']);
                 $pollerTemp['since'] = $duration;
                 $pollers['unreachable']['objects'][] = $pollerTemp;
             }
         }
     }
     $event->addStatus('issues', $issues);
     $states = $event->getStatus('states');
     if (empty($states)) {
         $states = array();
     }
     $states['configurationObjects'] = $configurationobjects;
     $states['pollers'] = $pollers;
     $event->addStatus('states', $states);
     $event->addStatus('totalHosts', $totalHosts);
     $event->addStatus('totalServices', $totalServices);
 }