/**
  * 
  * @param array $resultSet
  */
 protected function formatDatas(&$resultSet)
 {
     $router = Di::getDefault()->get('router');
     foreach ($resultSet as &$myServiceSet) {
         $myServiceSet['service_description'] = '<span class="icoListing">' . ServiceRepository::getIconImage($myServiceSet['service_id']) . '</span>' . $myServiceSet['service_description'];
         // Set Tpl Chain
         $tplStr = null;
         if (isset($myServiceSet["service_template_model_stm_id"])) {
             $tplArr = ServicetemplateRepository::getMyServiceTemplateModels($myServiceSet["service_template_model_stm_id"]);
             $tplRoute = str_replace("//", "/", Di::getDefault()->get('router')->getPathFor('/centreon-configuration/servicetemplate/[i:id]', array('id' => $tplArr['id'])));
             if (isset($tplArr['description'])) {
                 $tplStr .= '<span><a href="' . $tplRoute . '">' . $tplArr['description'] . '</a></span>';
             }
         }
         $sideMenuCustom = new SlideMenu($myServiceSet['service_id']);
         $events = Di::getDefault()->get('events');
         $events->emit('centreon-configuration.slide.menu.service.template', array($sideMenuCustom));
         //$myHostSet['DT_RowData']['right_side_details'] = $router->getPathFor('/centreon-configuration/host/snapshot/').$myHostSet['host_id'];
         $myServiceSet['DT_RowData']['right_side_menu_list'] = $sideMenuCustom->getMenu();
         $myServiceSet['DT_RowData']['right_side_default_menu'] = $sideMenuCustom->getDefaultMenu();
         $myServiceSet['service_template_model_stm_id'] = $tplStr;
         /* Display human readable the check/retry interval */
         $myServiceSet['service_normal_check_interval'] = HumanReadable::convert($myServiceSet['service_normal_check_interval'], 's', $units, null, true);
         $myServiceSet['service_retry_check_interval'] = HumanReadable::convert($myServiceSet['service_retry_check_interval'], 's', $units, null, true);
         /* 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']);
     }
 }
Esempio n. 2
0
 /**
  * 
  * @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']);
     }
 }
Esempio n. 3
0
 /**
  * 
  * @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);
 }
Esempio n. 4
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());
 }
 /**
  * Service slider default menu
  *
  * @method get
  * @route /service/snapshotslide/[i:id]
  */
 public function snapshotslideAction()
 {
     $router = Di::getDefault()->get('router');
     $params = $this->getParams();
     $return = array();
     $service = ServicedetailRepository::getRealtimeData($params['id']);
     $service = $service[0];
     $serviceTemp['name'] = $service['host_name'] . ' ' . $service['service_description'];
     if (!empty($service['acknowledged'])) {
         $serviceTemp['acknowledged'] = 1;
     } else {
         $serviceTemp['acknowledged'] = 0;
     }
     if (isset($service['state_type']) && $service['state_type'] == "1") {
         $serviceTemp['stateHardSoft'] = "Hard";
     } else {
         if (isset($service['state_type']) && $service['state_type'] == "0") {
             $serviceTemp['stateHardSoft'] = "Soft";
         }
     }
     $serviceTemp['last_check'] = Datetime::humanReadable(time() - $service['last_check'], Datetime::PRECISION_FORMAT, 2);
     $serviceTemp['next_check'] = Datetime::humanReadable(time() - $service['next_check'], Datetime::PRECISION_FORMAT, 2);
     $serviceTemp['check_period'] = $service['check_period'];
     $serviceTemp['retry_interval'] = $service['retry_interval'];
     $serviceTemp['check_interval'] = $service['check_interval'];
     $serviceTemp['max_check_attempts'] = $service['max_check_attempts'];
     $serviceTemp['active_checks'] = $service['active_checks'];
     $serviceTemp['passive_checks'] = $service['passive_checks'];
     $serviceTemp['icon'] = ServiceRepositoryConfig::getIconImage($params['id']);
     $serviceTemp['url'] = $router->getPathFor('/centreon-realtime/service/' . $params['id']);
     $return['serviceConfig'] = $serviceTemp;
     $return['success'] = true;
     $router->response()->json($return);
 }
Esempio n. 6
0
 /**
  * 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);
 }