/** * * @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']); } }
/** * 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)); }
/** * * @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); }
/** * * @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']); } }
/** * 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'] = " "; } /* 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()); }
/** * Host detail page * * @method get * @route /host/[i:id] */ public function hostDetailAction() { $params = $this->getParams(); $host = HostdetailRepository::getRealtimeData($params['id']); $this->tpl->assign('hostname', $host[0]['host_name']); $this->tpl->assign('address', $host[0]['host_address']); $this->tpl->assign('host_alias', $host[0]['host_alias']); $this->tpl->assign('host_icon', HostConfRepository::getIconImage($host[0]['host_name'])); $this->tpl->assign('applications', array()); $this->tpl->assign('routeParams', array('id' => $params['id'])); $this->tpl->addCss('cal-heatmap.css')->addCss('centreon.status.css')->addCss('centreon-wizard.css'); $this->tpl->addJs('d3.min.js')->addJs('jquery.sparkline.min.js')->addJs('cal-heatmap.min.js')->addJs('jquery.knob.min.js')->addJs('moment-timezone-with-data.min.js'); $this->tpl->display('file:[CentreonRealtimeModule]host_detail.tpl'); }
/** * * @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); }