/** * 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)); }
/** * 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); } }
/** * 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); } }
/** * 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; }