Пример #1
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));
 }
Пример #2
0
 public function testGetColumns()
 {
     $this->assertEquals(array('service_id', 'service_template_model_stm_id', 'command_command_id', 'timeperiod_tp_id', 'command_command_id2', 'timeperiod_tp_id2', 'service_description', 'service_alias', 'display_name', 'service_is_volatile', 'service_max_check_attempts', 'service_normal_check_interval', 'service_retry_check_interval', 'service_active_checks_enabled', 'service_passive_checks_enabled', 'initial_state', 'service_parallelize_check', 'service_obsess_over_service', 'service_check_freshness', 'service_freshness_threshold', 'service_event_handler_enabled', 'service_low_flap_threshold', 'service_high_flap_threshold', 'service_flap_detection_enabled', 'service_process_perf_data', 'service_retain_status_information', 'service_retain_nonstatus_information', 'service_notification_interval', 'service_notification_options', 'service_notifications_enabled', 'contact_additive_inheritance', 'cg_additive_inheritance', 'service_inherit_contacts_from_host', 'service_first_notification_delay', 'service_stalking_options', 'service_comment', 'command_command_id_arg', 'command_command_id_arg2', 'service_locked', 'service_register', 'service_activate', 'organization_id', 'environment_id', 'domain_id'), Service::getColumns());
 }
Пример #3
0
 /**
  * Get values for templates
  *
  * @param integer $svcId The service id
  * @param bool $withServiceValues If the service template id is the base for get values
  * @return array
  */
 public static function getInheritanceValues($svcId, $withServiceValues = false)
 {
     $values = array();
     if ($withServiceValues) {
         $tmpl = $svcId;
     } else {
         $tmpl = Service::getParameters($svcId, array('service_template_model_stm_id'));
         $tmpl = $tmpl['service_template_model_stm_id'];
     }
     if (is_null($tmpl)) {
         return $values;
     }
     /* Get template values */
     $values = Servicetemplate::getParameters($tmpl, self::$inheritanceColumns);
     $values = array_filter($values, function ($value) {
         return !is_null($value);
     });
     $tmplNext = Servicetemplate::getParameters($tmpl, array('service_template_model_stm_id'));
     if (is_null($tmplNext['service_template_model_stm_id'])) {
         return $values;
     }
     $values = array_merge(static::getInheritanceValues($tmplNext['service_template_model_stm_id'], true), $values);
     return $values;
 }
Пример #4
0
 /**
  * Deploy services by host templates
  *
  * @param int $hostId
  * @param int $hostTemplateId
  */
 public static function deployServices($hostId, $hostTemplateId = null)
 {
     static $deployedServices = array();
     $db = Di::getDefault()->get('db_centreon');
     $hid = is_null($hostTemplateId) ? $hostId : $hostTemplateId;
     $services = HostServiceRelation::getMergedParameters(array(), array('service_id', 'service_description', 'service_alias'), -1, 0, null, 'ASC', array(HostServiceRelation::getFirstKey() => $hid), 'AND');
     foreach ($services as $service) {
         if (is_null($hostTemplateId)) {
             $deployedServices[$hostId][$service['service_description']] = true;
         } elseif (!isset($deployedServices[$hostId][$service['service_alias']])) {
             $oRepositorie = "CentreonConfiguration\\Repository\\ServiceRepository";
             $oSlugify = new CentreonSlugify(self, $oRepositorie);
             if (!empty($service['service_alias'])) {
                 $sData = $service['service_alias'];
             } else {
                 $sData = $service['service_description'];
             }
             $sHostName = Host::get($hostId, 'host_name');
             $sString = $sHostName['host_name'] . " " . $sData;
             $sSlug = $oSlugify->slug($sString);
             $serviceId = Service::insert(array('service_slug' => $sSlug, 'service_description' => $sData, 'service_template_model_stm_id' => $service['service_id'], 'service_register' => 1, 'service_activate' => 1));
             HostServiceRelation::insert($hostId, $serviceId);
             $deployedServices[$hostId][$service['service_alias']] = true;
         }
     }
     $templates = HostHosttemplateRelation::getTargetIdFromSourceId('host_tpl_id', 'host_host_id', $hid);
     foreach ($templates as $tplId) {
         self::deployServices($hostId, $tplId);
     }
 }
Пример #5
0
 /**
  * Update slug services by host
  *
  * @param int $iHostId
  * @param string $sHostName
  */
 public static function updateSlugServices($iHostId, $sHostName)
 {
     $aServices = array();
     $db = Di::getDefault()->get('db_centreon');
     $repository = "CentreonConfiguration\\Repository\\ServiceRepository";
     $repository::setObjectName("Service");
     $repository::setObjectClass("\\CentreonConfiguration\\Models\\Service");
     $oModel = "CentreonConfiguration\\Models\\Service";
     $oSlugify = new CentreonSlugify($oModel, $repository);
     // get services
     $aHostServices = HostServiceRelation::getMergedParameters(array('host_id'), array('service_id', 'service_description', 'service_alias'), -1, 0, null, "ASC", array('host_id' => $iHostId), "OR");
     foreach ($aHostServices as $key => $oService) {
         $sString = $sHostName . " " . $oService['service_description'];
         $sSlug = $oSlugify->slug($sString);
         Service::updateSlug($oService['service_id'], $sSlug);
     }
 }
Пример #6
0
 /**
  * Used for duplicate a host
  *
  * @param int $sourceObjectId The source host id
  * @param int $duplicateEntries The number entries
  * @return array List of new host id
  */
 public static function duplicate($sourceObjectId, $duplicateEntries = 1)
 {
     $db = Di::getDefault()->get(static::$databaseName);
     $sourceParams = static::getParameters($sourceObjectId, '*');
     if (false === $sourceParams) {
         throw new \Exception(static::OBJ_NOT_EXIST);
     }
     unset($sourceParams['host_id']);
     $originalName = $sourceParams['host_name'];
     $explodeOriginalName = explode('_', $originalName);
     $j = 0;
     if (($count = count($explodeOriginalName)) > 1 && is_numeric($explodeOriginalName[$count - 1])) {
         $originalName = join('_', array_slice($explodeOriginalName, 0, -1));
         $j = $explodeOriginalName[$count - 1];
     }
     $listDuplicateId = array();
     for ($i = 0; $i < $duplicateEntries; $i++) {
         /* Search the unique name for duplicate host */
         do {
             $j++;
             $unique = self::isUnique($originalName . '_' . $j);
         } while (false === $unique);
         $sourceParams['host_name'] = $originalName . '_' . $j;
         /* Insert the duplicate host */
         $lastId = static::insert($sourceParams);
         if (false === is_numeric($lastId)) {
             throw new \Exception("The value is not numeric");
         }
         $listDuplicateId[] = $lastId;
         /* Insert relation */
         /* Duplicate service */
         /*   Get service for the source host */
         $listSvc = HostServiceRelation::getTargetIdFromSourceId('service_service_id', 'host_host_id', $sourceObjectId);
         foreach ($listSvc as $svcId) {
             /* Duplicate service */
             $newSvcId = Service::duplicate($svcId, 1, true);
             if (count($newSvcId) > 0) {
                 /* Attach the new service to the new host */
                 HostServiceRelation::insert($lastId, $newSvcId[0]);
             }
         }
         $db->beginTransaction();
         /* Duplicate macros */
         $queryDupMacros = "INSERT INTO cfg_customvariables_hosts (host_macro_name, host_macro_value, is_password, host_host_id)\n                SELECT host_macro_name, host_macro_value, is_password, " . $lastId . " FROM cfg_customvariables_hosts\n                    WHERE host_host_id = :sourceObjectId";
         $stmt = $db->prepare($queryDupMacros);
         $stmt->bindParam(':sourceObjectId', $sourceObjectId);
         $stmt->execute();
         /* Host template */
         $queryDupTemplate = "INSERT INTO cfg_hosts_templates_relations (host_host_id, host_tpl_id, `order`)\n                SELECT " . $lastId . ", host_tpl_id, `order` FROM cfg_hosts_templates_relations\n                    WHERE host_host_id = :sourceObjectId";
         $stmt = $db->prepare($queryDupTemplate);
         $stmt->bindParam(':sourceObjectId', $sourceObjectId);
         $stmt->execute();
         /* Host global tags */
         $queryDupTag = "INSERT INTO cfg_tags_hosts (tag_id, resource_id)\n                SELECT th.tag_id, " . $lastId . " FROM cfg_tags_hosts th, cfg_tags t\n                    WHERE t.user_id IS NULL AND t.tag_id = th.tag_id AND th.resource_id = :sourceObjectId";
         $stmt = $db->prepare($queryDupTag);
         $stmt->bindParam(':sourceObjectId', $sourceObjectId);
         $stmt->execute();
         $db->commit();
     }
 }
Пример #7
0
 /**
  * Return Service name
  *
  * @param int or array $svcId The service ID
  * @return array
  */
 public static function getName($svcId)
 {
     $di = Di::getDefault();
     $router = $di->get('router');
     $serviceId = Service::getPrimaryKey();
     $serviceDescription = Service::getUniqueLabelField();
     $hostId = Host::getPrimaryKey();
     $hostName = Host::getUniqueLabelField();
     $filters = array($serviceId => $svcId);
     $list = HostServiceRelation::getMergedParameters(array($hostId, $hostName), array($serviceId, $serviceDescription), -1, 0, null, "ASC", $filters, "OR");
     $finalList = array();
     foreach ($list as $obj) {
         $finalList[] = array("id" => $obj[$serviceId], "text" => $obj[$hostName] . ' ' . $obj[$serviceDescription]);
     }
     return $finalList;
 }
Пример #8
0
 /**
  * Get service for a specific kpi
  *
  *
  * @method get
  * @route /indicator/[i:id]/service
  */
 public function serviceForIndicatorAction()
 {
     $di = Di::getDefault();
     $router = $di->get('router');
     $requestParam = $this->getParams('named');
     $relObj = static::$relationMap['indicator_service'];
     $listOfServices = $relObj::getHostIdServiceIdFromKpiId($requestParam['id']);
     $finalList = array();
     if (isset($listOfServices[0]) && !empty($listOfServices[0]['service_id']) && !empty($listOfServices[0]['host_id'])) {
         $serviceDescription = Service::getParameters($listOfServices[0]['service_id'], 'service_description');
         $hostName = Host::getParameters($listOfServices[0]['host_id'], 'host_name');
         $finalList = array("id" => $listOfServices[0]['service_id'] . '_' . $listOfServices[0]['host_id'], "text" => $hostName['host_name'] . ' ' . $serviceDescription['service_description']);
     }
     $router->response()->json($finalList);
 }