/**
  * Get information for a incident for display graph
  *
  * @route /incident/graph
  * @method POST
  */
 public function getIncidentGraphInfoAction()
 {
     $di = Di::getDefault();
     $router = $di->get('router');
     $response = array();
     $action = $router->request()->param('action', null);
     $incidentId = $router->request()->param('incident_id', null);
     if (is_null($incidentId)) {
         $router->response()->code(400);
         return;
     }
     switch ($action) {
         case 'get_info':
             $incident = IncidentsRepository::getIncident($incidentId);
             $fullname = $incident['name'];
             if (false === is_null($incident['description'])) {
                 $fullname .= ' - ' . $incident['description'];
             }
             $response = array('id' => $incident['issue_id'], 'name' => $fullname, 'status' => self::getCssStatus($incident['state']), 'output' => $incident['output'], 'last_update' => Datetime::format($incident['last_state_change']), 'has_children' => $incident['nb_children'] > 0 ? true : false, 'has_parent' => $incident['nb_parents'] > 0 ? true : false, 'parents' => array_map(function ($values) {
                 $parent = array();
                 $parent['id'] = $values['issue_id'];
                 $fullname = $values['name'];
                 if (!is_null($values['description'])) {
                     $fullname .= ' - ' . $values['description'];
                 }
                 $parent['name'] = $fullname;
                 return $parent;
             }, $incident['parents']));
             break;
         case 'getChildren':
             $listChildren = IncidentsRepository::getChildren($incidentId);
             $response = array();
             foreach ($listChildren as $child) {
                 $fullname = $child['name'];
                 if (false === is_null($child['description'])) {
                     $fullname .= ' - ' . $child['description'];
                 }
                 $response[] = array('id' => $child['issue_id'], 'name' => $fullname, 'status' => self::getCssStatus($child['state']), 'output' => $child['output'], 'last_update' => Datetime::format($child['last_state_change']), 'has_children' => $child['nb_children'] > 0 ? true : false, 'has_parent' => $child['nb_parents'] > 0 ? true : false);
             }
             break;
         case 'get_extended_info':
             $status = IncidentsRepository::getListStatus($incidentId);
             $statusList = array();
             foreach ($status as $tmp) {
                 if (false === is_null($tmp['service_id'])) {
                     $statusType = Status::TYPE_SERVICE;
                 } else {
                     $statusType = Status::TYPE_HOST;
                 }
                 $statusList[] = array('id' => $tmp['state'], 'text' => Status::numToString($tmp['state'], $statusType, true), 'datetime' => $tmp['start_time']);
             }
             $response = array('status' => array(array('id' => 2, 'text' => 'Critical', 'datetime' => '2014-05-12 01:03:11'), array('id' => 2, 'text' => 'Critical', 'datetime' => '2014-05-12 01:03:11'), array('id' => 2, 'text' => 'Critical', 'datetime' => '2014-05-12 01:03:11'), array('id' => 2, 'text' => 'Critical', 'datetime' => '2014-05-12 01:03:11')));
             break;
         default:
             $router->response()->code(400);
             return;
     }
     $router->response()->json($response);
 }
 /**
  * Service slider default menu
  *
  * @method get
  * @route /service/incidentslide/[i:id]
  */
 public function slideIncidentsAction()
 {
     $router = Di::getDefault()->get('router');
     $params = $this->getParams();
     $return = array();
     $incidents = IncidentsRepository::getIncidents(null, 'DESC', null, array('i.service_id' => $params['id']));
     foreach ($incidents as $key => $incident) {
         $childIncidents = IncidentsRepository::getChildren($incident['issue_id']);
         foreach ($childIncidents as $childIncident) {
             $incidents[$key]['child_incidents'][] = $childIncident;
         }
     }
     $return['incidents'] = $incidents;
     $return['success'] = true;
     $router->response()->json($return);
 }
Exemple #3
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);
 }