Example #1
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);
     }
 }