/** * 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)); }
/** * * @param array $resultSet */ protected function formatDatas(&$resultSet) { $router = Di::getDefault()->get('router'); foreach ($resultSet as &$myHostSet) { $myHostSet['host_name'] = '<span class="icoListing">' . HostRepository::getIconImage($myHostSet['host_name']) . '</span>' . $myHostSet['host_name']; $sideMenuCustom = new SlideMenu($myHostSet['host_id']); $events = Di::getDefault()->get('events'); $events->emit('centreon-configuration.slide.menu.host', array($sideMenuCustom)); $myHostSet['DT_RowData']['right_side_menu_list'] = $sideMenuCustom->getMenu(); $myHostSet['DT_RowData']['right_side_default_menu'] = $sideMenuCustom->getDefaultMenu(); /* Host State */ $myHostSet['host_name'] .= RealTimeHostRepository::getStatusBadge(RealTimeHostRepository::getStatus($myHostSet['host_id'])); /* Poller */ if (isset($myHostSet["poller_id"]) && $myHostSet["poller_id"] != "") { $poller = Poller::getParameters($myHostSet["poller_id"], 'name'); $myHostSet["poller_id"] = $poller['name']; } else { $myHostSet["poller_id"] = ""; } /* Templates */ $myHostSet['host_template'] = ""; $templates = HostRepository::getTemplateChain($myHostSet['host_id'], array(), 1); foreach ($templates as $template) { $myHostSet['host_template'] .= '<a href="' . $router->getPathFor("/centreon-configuration/hosttemplate/[i:id]", array('id' => $template['id'])) . '"><i class="icon-template ico-20"></i></a>'; } /* Display human readable the check/retry interval */ $myHostSet['host_check_interval'] = HumanReadable::convert($myHostSet['host_check_interval'], 's', $units, null, true); $myHostSet['host_retry_check_interval'] = HumanReadable::convert($myHostSet['host_retry_check_interval'], 's', $units, null, true); /* Get personal tags */ $myHostSet['tagname'] = ''; $aTagUsed = array(); $aTags = TagsRepository::getList('host', $myHostSet['host_id'], 0, 0); foreach ($aTags as $oTags) { if (!in_array($oTags['id'], $aTagUsed)) { $aTagUsed[] = $oTags['id']; $myHostSet['tagname'] .= TagsRepository::getTag('host', $myHostSet['host_id'], $oTags['id'], $oTags['text'], $oTags['user_id'], 1); } } $myHostSet['tagname'] .= TagsRepository::getAddTag('host', $myHostSet['host_id']); } }
/** * * @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); }
/** * 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); }