コード例 #1
0
 /**
  * Deploy services
  * Recursive method
  *
  * @param int $hostId
  * @param mixed $hostTemplateId
  * @return void
  */
 protected function deployServices($hostId, $hostTemplateId = null)
 {
     static $tmplRel;
     static $svcObj;
     static $hostSvcRel;
     static $svcExtended;
     if (!isset($tmplRel) && !isset($svcObj) && !isset($hostSvcRel)) {
         $tmplRel = new Centreon_Object_Relation_Host_Template_Host();
         $svcObj = new Centreon_Object_Service();
         $hostSvcRel = new Centreon_Object_Relation_Host_Service();
         $svcExtended = new Centreon_Object_Service_Extended();
     }
     if (!isset($hostTemplateId)) {
         $id = $hostId;
     } else {
         $id = $hostTemplateId;
     }
     $templates = $tmplRel->gethost_tpl_idFromhost_host_id($id);
     foreach ($templates as $templateId) {
         $serviceTemplates = $hostSvcRel->getservice_service_idFromhost_host_id($templateId);
         foreach ($serviceTemplates as $serviceTemplateId) {
             $params = $svcObj->getParameters($serviceTemplateId, array('service_alias'));
             $sql = "SELECT service_id\n                \t\tFROM service s, host_service_relation hsr\n                \t\tWHERE s.service_id = hsr.service_service_id\n                \t\tAND s.service_description = :servicedescription\n                \t\tAND hsr.host_host_id = :hostid\n                \t\tUNION\n                \t\tSELECT service_id\n                \t\tFROM service s, host_service_relation hsr\n                \t\tWHERE s.service_id = hsr.service_service_id\n                \t\tAND s.service_description = :servicedescription\n                \t\tAND hsr.hostgroup_hg_id IN (SELECT hostgroup_hg_id FROM hostgroup_relation WHERE host_host_id = :hostid)";
             $res = $this->db->query($sql, array(':servicedescription' => $params['service_alias'], ':hostid' => $hostId));
             $result = $res->fetchAll();
             if (!count($result)) {
                 $svcId = $svcObj->insert(array('service_description' => $params['service_alias'], 'service_activate' => '1', 'service_register' => '1', 'service_template_model_stm_id' => $serviceTemplateId));
                 $hostSvcRel->insert($hostId, $svcId);
                 $svcExtended->insert(array($svcExtended->getUniqueLabelField() => $svcId));
             }
             unset($res);
         }
         $this->deployServices($hostId, $templateId);
     }
 }
コード例 #2
0
 /**
  * Add a service
  *
  * @param string $parameters
  * @return void
  * @throws CentreonClapiException
  */
 public function add($parameters)
 {
     $params = explode($this->delim, $parameters);
     if (count($params) < $this->nbOfCompulsoryParams) {
         throw new CentreonClapiException(self::MISSINGPARAMETER);
     }
     if ($this->serviceExists($params[self::ORDER_HOSTNAME], $params[self::ORDER_SVCDESC]) == true) {
         throw new CentreonClapiException(self::OBJECTALREADYEXISTS);
     }
     $hostObject = new Centreon_Object_Host();
     $tmp = $hostObject->getIdByParameter($hostObject->getUniqueLabelField(), $params[self::ORDER_HOSTNAME]);
     if (!count($tmp)) {
         throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $params[self::ORDER_HOSTNAME]);
     }
     $hostId = $tmp[0];
     $addParams = array();
     $addParams['service_description'] = $params[self::ORDER_SVCDESC];
     $template = $params[self::ORDER_SVCTPL];
     $tmp = $this->object->getList($this->object->getPrimaryKey(), -1, 0, null, null, array('service_description' => $template, 'service_register' => '0'), "AND");
     if (!count($tmp)) {
         throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $template);
     }
     $addParams['service_template_model_stm_id'] = $tmp[0][$this->object->getPrimaryKey()];
     $this->params = array_merge($this->params, $addParams);
     $serviceId = parent::add();
     $relObject = new Centreon_Object_Relation_Host_Service();
     $relObject->insert($hostId, $serviceId);
     $extended = new Centreon_Object_Service_Extended();
     $extended->insert(array($extended->getUniqueLabelField() => $serviceId));
 }