Esempio n. 1
0
 /**
  * Display the configuration snapshot of a host
  * with template inheritance
  *
  * @method get
  * @route /host/snapshotslide/[i:id]
  */
 public function snapshotslideAction()
 {
     $params = $this->getParams();
     $data = HostRepository::getInheritanceValues($params['id'], true);
     $host = Host::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/host/" . $params['id']);
     $this->router->response()->json(array('hostConfig' => $hostConfiguration, 'hostReal' => $hostReal, 'servicesStatus' => $servicesStatus, 'edit_url' => $edit_url, 'success' => true));
 }
Esempio n. 2
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);
 }
 public static function formatDataForHeader($data)
 {
     /* Check data */
     $checkdata = array();
     $checkdata[_('id')] = $data['service_id'];
     $host = \CentreonRealtime\Models\Host::get($data['host_id']);
     $host_name = $host['name'];
     if (!empty($data['description'])) {
         $checkdata[_('name')] = $host_name . ' ' . $data['description'];
     }
     $checkdata[_('state')] = $data['state'];
     $checkdata[_('icon')] = "";
     if (!empty($data['icon'])) {
         $checkdata[_('icon')] = $data['icon'];
     }
     $checkdata[_('url')] = "";
     if (!empty($data['url'])) {
         $checkdata[_('url')] = $data['url'];
     }
     $checkdata[_('issue_duration')] = "";
     if (!empty($data['issue_duration'])) {
         $checkdata[_('issue_duration')] = $data['issue_duration'];
     }
     return $checkdata;
 }
Esempio n. 4
0
 /**
  * Get scheduling informations for a specific host
  *
  * @method get
  * @route /host/[i:id]/scheduling-infos
  */
 public function schedulingInfosHostAction()
 {
     $params = $this->getParams();
     $schedulingInfos = HostRealtime::get($params['id'], array('execution_time', 'latency'));
     $poller = HostConf::get($params['id'], 'poller_id');
     $schedulingInfos['poller_name'] = !is_null($poller['poller_id']) ? Poller::get($poller['poller_id'], 'name') : "";
     unset($schedulingInfos['poller_id']);
     $this->router->response()->json(array('scheduling_infos' => $schedulingInfos, 'success' => true));
 }
Esempio n. 5
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);
 }