Пример #1
0
 /**
  * Constructor
  *
  * @param int $serviceId The service ID
  * @param int $startTime The start time for graph
  * @param int $endTime The end time for graph
  */
 public function __construct($serviceId, $startTime, $endTime)
 {
     $di = Di::getDefault();
     $dbconn = $di->get('db_centreon');
     /* Get the list of metrics */
     $query = "SELECT i.index_id, i.service_description, m.metric_id, m.metric_name, m.unit_name, m.warn, m.warn_low, m.crit, m.crit_low, m.min, m.max\n            FROM rt_index_data i, rt_metrics m\n            WHERE i.service_id = :service_id\n                AND i.index_id = m.index_id\n                AND m.hidden = '0'";
     $stmt = $dbconn->prepare($query);
     $stmt->bindParam(':service_id', $serviceId);
     $stmt->execute();
     /* List of service template */
     $svcTmpls = ServiceRepository::getListTemplates($serviceId);
     /* Get the graph template */
     $graphInfos = null;
     foreach ($svcTmpls as $svcTmplId) {
         $graphInfos = GraphTemplate::getByServiceTemplate($svcTmplId);
         if (count($graphInfos) > 0) {
             break;
         }
     }
     while ($row = $stmt->fetch()) {
         $metric = array('id' => $row['metric_id'], 'unit' => $row['unit_name'], 'color' => null, 'legend' => $row['metric_name'], 'is_negative' => false, 'graph_type' => 'line');
         if (count($graphInfos) > 0 && isset($graphInfos['metrics'][$row['metric_name']])) {
             $metric = array_merge($metric, $graphInfos['metrics'][$row['metric_name']]);
         }
         $this->metrics[] = $metric;
     }
     parent::__construct($startTime, $endTime);
 }
Пример #2
0
 /**
  * @param CentreonMain\Events\PostSave $event
  */
 public static function execute(PostSaveEvent $event)
 {
     $parameters = $event->getParameters();
     $extraParameters = $event->getExtraParameters();
     if (isset($extraParameters['centreon-configuration'])) {
         if ($event->getObjectName() === 'aclresource') {
             if (isset($extraParameters['centreon-configuration']['aclresource_hosts'])) {
                 $hostIds = array_filter(array_map('trim', explode(',', $extraParameters['centreon-configuration']['aclresource_hosts'])));
                 HostRepository::updateHostAcl($event->getAction(), $event->getObjectId(), $hostIds);
             }
             if (isset($extraParameters['centreon-configuration']['aclresource_host_tags'])) {
                 $hostTagIds = array_filter(array_map('trim', explode(',', $extraParameters['centreon-configuration']['aclresource_host_tags'])));
                 HostTagRepository::updateHostTagAcl($event->getAction(), $event->getObjectId(), $hostTagIds);
             }
             if (isset($extraParameters['centreon-configuration']['aclresource_services'])) {
                 $serviceIds = array_filter(array_map('trim', explode(',', $extraParameters['centreon-configuration']['aclresource_services'])));
                 ServiceRepository::updateServiceAcl($event->getAction(), $event->getObjectId(), $serviceIds);
             }
             if (isset($extraParameters['centreon-configuration']['aclresource_service_tags'])) {
                 $serviceTagIds = array_filter(array_map('trim', explode(',', $extraParameters['centreon-configuration']['aclresource_service_tags'])));
                 ServiceTagRepository::updateServiceTagAcl($event->getAction(), $event->getObjectId(), $serviceTagIds);
             }
             if (isset($extraParameters['centreon-configuration']['aclresource_all_hosts'])) {
                 $allHosts = $extraParameters['centreon-configuration']['aclresource_all_hosts'];
                 HostRepository::updateAllHostsAcl($event->getAction(), $event->getObjectId(), $allHosts);
             } else {
                 HostRepository::updateAllHostsAcl($event->getAction(), $event->getObjectId(), '0');
             }
         }
     }
 }
Пример #3
0
 /**
  * 
  * @param string $object
  * @param array $params
  */
 public function addMacroAction($object, $params)
 {
     $paramList = $this->parseObjectParams($params);
     //try {
     $repository = $this->repository;
     $sName = $this->objectName;
     $repository::transco($object);
     $aId = $repository::getListBySlugName($object[$sName]);
     if (count($aId) > 0) {
         $objectId = $aId[0]['id'];
     } else {
         throw new \Exception(static::OBJ_NOT_EXIST, 1);
     }
     switch ($this->objectName) {
         case 'hosttemplate':
         case 'host':
             CustomMacroRepository::setAttributesMap(self::$attributesMapHost);
             CustomMacroRepository::transco($paramList);
             if (isset($paramList['host_macro_name']) && isset($paramList['host_macro_value'])) {
                 $formatedParams = array($paramList['host_macro_name'] => array('value' => $paramList['host_macro_value'], 'is_password' => $paramList['is_password']));
             }
             CustomMacroRepository::saveHostCustomMacro($this->objectName, $objectId, $formatedParams, false);
             InputOutput::display("The macro '" . $paramList['host_macro_name'] . "' has been successfully added to the object", true, 'green');
             break;
         case 'servicetemplate':
             CustomMacroRepository::setAttributesMap(self::$attributesMapService);
             CustomMacroRepository::transco($paramList);
             if (isset($paramList['svc_macro_name']) && isset($paramList['svc_macro_value'])) {
                 $formatedParams = array($paramList['svc_macro_name'] => array('value' => $paramList['svc_macro_value'], 'is_password' => $paramList['is_password']));
             }
             CustomMacroRepository::saveServiceCustomMacro($this->objectName, $objectId, $formatedParams, false);
             InputOutput::display("The macro '" . $paramList['svc_macro_name'] . "' has been successfully added to the object", true, 'green');
             break;
         case 'service':
             CustomMacroRepository::setAttributesMap(self::$attributesMapService);
             CustomMacroRepository::transco($paramList);
             $aData = \CentreonConfiguration\Repository\ServiceRepository::getServiceBySlugs($object['service']);
             if (count($aData) == 0) {
                 throw new \Exception(static::OBJ_NOT_EXIST, 1);
             } else {
                 $objectId = $aData['service_id'];
                 $hostId = $aData['host_id'];
             }
             if (isset($paramList['svc_macro_name']) && isset($paramList['svc_macro_value'])) {
                 $formatedParams = array($paramList['svc_macro_name'] => array('value' => $paramList['svc_macro_value'], 'is_password' => $paramList['is_password']));
             }
             CustomMacroRepository::saveServiceCustomMacro($this->objectName, $objectId, $formatedParams, false, $hostId);
             InputOutput::display("The macro '" . $paramList['svc_macro_name'] . "' has been successfully added to the object", true, 'green');
             break;
         default:
             break;
     }
     /*} catch(\Exception $ex) {
           InputOutput::display($ex->getMessage(), true, 'red');
       }*/
 }
Пример #4
0
 /**
  *
  */
 protected function formatDatas(&$resultSet)
 {
     foreach ($resultSet as &$currentResultSet) {
         $tplStr = null;
         $tplArr = ServiceRepository::getMyServiceTemplateModels($currentResultSet['svc_tmpl_id']);
         if (false === is_null($tplArr)) {
             $currentResultSet['svc_tmpl_id'] = $tplArr['description'];
             $currentResultSet['DT_RowData']['name'] = $tplArr['description'];
         }
         $metrics = GraphTemplate::getMetrics($currentResultSet['graph_template_id']);
         $tplStr = '';
         foreach ($metrics as $metric) {
             $tplStr .= '<span style="color: ' . $metric['color'] . '">' . $metric['metric_name'] . '</span>&nbsp;';
         }
         $currentResultSet['metrics'] = $tplStr;
     }
 }
Пример #5
0
 /**
  * @param CentreonEngine\Events\GetMacroService $event
  */
 public static function execute(MacroServiceEvent $event)
 {
     /* Macros domain for service*/
     $services = array_keys(ServiceRepository::getServicesByPollerId($event->getPollerId()));
     foreach ($services as $serviceId) {
         $arr = ServiceRepository::getDomain($serviceId);
         foreach ($arr as $domainName) {
             $event->setMacro($serviceId, self::MACRO_DOMAIN, $domainName);
         }
     }
     /* Macros domain for service template */
     $servicesTmpl = ServicetemplateRepository::getList('service_id');
     foreach ($servicesTmpl as $serviceTmpl) {
         $arr = ServicetemplateRepository::getDomain($serviceTmpl['service_id']);
         foreach ($arr as $domainName) {
             $event->setMacro($serviceTmpl['service_id'], self::MACRO_DOMAIN, $domainName);
         }
     }
 }
Пример #6
0
 /**
  * 
  */
 public function validate($value, $params = array(), $sContext = 'server')
 {
     $result = true;
     $resultError = _("Circular redundancy detected");
     if (isset($params['object']) && ($params['object'] === 'host' || $params['object'] === 'hosttemplate')) {
         $objectStack = explode(',', trim($value));
         foreach ($objectStack as $hostId) {
             if (isset($params['object_id']) && $hostId == $params['object_id']) {
                 $result = false;
             }
             $listHostId = HostRepository::getTemplateChain($hostId, array(), -1);
             foreach ($listHostId as $hostTemplateId) {
                 if (isset($params['object_id']) && $hostTemplateId['id'] == $params['object_id']) {
                     $result = false;
                 }
             }
         }
     } else {
         if (isset($params['object']) && ($params['object'] === 'service' || $params['object'] === 'servicetemplate')) {
             $serviceId = $value;
             $listServiceId = ServiceRepository::getListTemplates($serviceId);
             if (isset($params['object_id']) && $serviceId == $params['object_id']) {
                 $result = false;
             }
             foreach ($listServiceId as $serviceTemplateId) {
                 if (isset($params['object_id']) && $serviceTemplateId == $params['object_id']) {
                     $result = false;
                 }
             }
         }
     }
     if ($sContext == 'client') {
         $reponse = $result;
     } else {
         $reponse = array('success' => $result, 'error' => $resultError);
     }
     return $reponse;
 }
Пример #7
0
 /**
  * 
  * @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']);
     }
 }
Пример #8
0
 /**
  * Get list of services for a specific host
  * 
  * @method get
  * @route /host/[i:id]/service
  */
 public function hostForServiceAction()
 {
     $requestParam = $this->getParams('named');
     $relationClass = static::$relationMap['host_services'];
     $services = $relationClass::getMergedParameters(array(), array('service_id', 'service_description'), -1, 0, null, "ASC", array('host_id' => $requestParam['id']), "AND");
     $finalServices = array();
     foreach ($services as $service) {
         $finalService = ServicetemplateRepository::getInheritanceValues($service['service_id'], true);
         $finalService['service_id'] = $service['service_id'];
         $finalService['service_description'] = $service['service_description'];
         $finalService = ServiceRepository::formatDataForSlider($finalService);
         $finalServices[] = $finalService;
     }
     $this->router->response()->json(array('service' => $finalServices, 'success' => true));
 }
Пример #9
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);
 }
Пример #10
0
 /**
  * Get the list of inhereted tags
  * @param string $resourceName
  * @param int $resourceId
  * @return array
  */
 public static function getHeritedTags($resourceName, $resourceId)
 {
     $resourceName = self::convertResource($resourceName);
     if (!in_array($resourceName, static::$resourceType)) {
         throw new Exception("This resource type does not support tags.");
     }
     if (empty($resourceId)) {
         return array();
     }
     $aTagUsed = array();
     $aTags = array();
     if ($resourceName == 'host') {
         $templates = HostRepository::getTemplateChain($resourceId, array(), -1);
         foreach ($templates as $template) {
             $aTagsInHost = TagsRepository::getList('host', $template['id'], 1, 0);
             foreach ($aTagsInHost as $oTags) {
                 if (!in_array($oTags['id'], $aTagUsed)) {
                     $aTagUsed[] = $oTags['id'];
                     $aTags[] = $oTags['text'];
                 }
             }
         }
     } elseif ($resourceName == 'service') {
         $templates = ServiceRepository::getListTemplates($resourceId, array(), -1);
         foreach ($templates as $template) {
             $aTagsInSvc = TagsRepository::getList('service', $template, 1, 0);
             foreach ($aTagsInSvc as $oTags) {
                 if (!in_array($oTags['id'], $aTagUsed)) {
                     $aTagUsed[] = $oTags['id'];
                     $aTags[] = $oTags['text'];
                 }
             }
         }
     }
     return array('success' => true, 'values' => $aTags);
 }
Пример #11
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());
 }
Пример #12
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);
 }
Пример #13
0
 /**
  * Display the configuration snapshot of a service
  * with template inheritance
  *
  * @method get
  * @route /servicetemplate/snapshotslide/[i:id]
  */
 public function snapshotslideAction()
 {
     $params = $this->getParams();
     $data = ServiceTemplateRepository::getConfigurationData($params['id']);
     //If service inherits a template
     /*if (isset($data['service_template_model_stm_id'])) {
           $data = ServiceTemplateRepository::getConfigurationData($data['service_template_model_stm_id']);   
       } else {
           $data = ServiceTemplateRepository::getConfigurationData($params['id']);
       }*/
     $serviceConfiguration = ServiceRepository::formatDataForSlider($data);
     $edit_url = $this->router->getPathFor("/centreon-configuration/servicetemplate/" . $params['id']);
     $this->router->response()->json(array('serviceConfig' => $serviceConfiguration, 'edit_url' => $edit_url, 'success' => true));
 }
Пример #14
0
 /**
  * Get relations 
  *
  * @param string $relClass
  * @param int $id
  * @return array 
  */
 public static function getRelationsCustom($relClass, $id)
 {
     $router = Di::getDefault()->get('router');
     $curObj = static::$objectClass;
     if ($relClass::$firstObject == $curObj) {
         $tmp = $relClass::$secondObject;
         $fArr = array("*");
         $sArr = array($tmp::getPrimaryKey(), $tmp::getUniqueLabelField());
     } else {
         $tmp = $relClass::$firstObject;
         $fArr = array("*");
         $sArr = array();
     }
     $cmp = $curObj::getTableName() . '.' . $curObj::getPrimaryKey();
     $list = $relClass::getMergedParameters($fArr, $sArr, -1, 0, null, "ASC", array($cmp => $id), "AND");
     $finalList = array();
     foreach ($list as $obj) {
         $tmpList = ServiceRepository::formatDataForSlider($obj);
         $tmpList['url_edit'] = $router->getPathFor('/centreon-configuration/servicetemplate/' . $obj['service_id']);
         $finalList[] = $tmpList;
     }
     return $finalList;
 }
Пример #15
0
 /**
  * Display the configuration snapshot of a service
  * with template inheritance
  *
  * @method get
  * @route /service/snapshotslide/[i:id]
  */
 public function snapshotslideAction()
 {
     $params = $this->getParams();
     $data = ServiceRepository::getConfigurationData($params['id']);
     $serviceId = Service::getPrimaryKey();
     $serviceDescription = Service::getUniqueLabelField();
     $hostId = Host::getPrimaryKey();
     $hostName = Host::getUniqueLabelField();
     $filters = array($serviceId => $params['id']);
     //If service inherits a template
     if (isset($data['service_template_model_stm_id'])) {
         $data = ServiceRepository::getConfigurationData($data['service_template_model_stm_id']);
     } else {
         $data = ServiceRepository::getConfigurationData($params['id']);
     }
     $list = HostService::getMergedParameters(array($hostId, $hostName), array($serviceId, $serviceDescription), -1, 0, null, "ASC", $filters, "OR");
     foreach ($list as $obj) {
         $data[$serviceDescription] = $obj[$hostName] . '|' . $obj[$serviceDescription];
     }
     $serviceConfiguration = ServiceRepository::formatDataForSlider($data);
     $edit_url = $this->router->getPathFor("/centreon-configuration/service/" . $params['id']);
     $this->router->response()->json(array('serviceConfig' => $serviceConfiguration, 'edit_url' => $edit_url, 'success' => true));
 }
Пример #16
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']);
     }
 }
Пример #17
0
 /**
  * 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);
 }