/**
  * Add action
  *
  * @param string $parameters
  * @return void
  */
 public function add($parameters)
 {
     $params = explode($this->delim, $parameters);
     if (count($params) < $this->nbOfCompulsoryParams) {
         throw new CentreonClapiException(self::MISSINGPARAMETER);
     }
     $addParams = array();
     $addParams[$this->object->getUniqueLabelField()] = $params[self::ORDER_UNIQUENAME];
     $addParams['alias'] = $params[self::ORDER_ALIAS];
     $this->params = array_merge($this->params, $addParams);
     $this->checkParameters();
     parent::add();
 }
 /**
  * Add action
  *
  * @param string $parameters
  * @return void
  */
 public function add($parameters)
 {
     $params = explode($this->delim, $parameters);
     if (count($params) < $this->nbOfCompulsoryParams) {
         throw new CentreonClapiException(self::MISSINGPARAMETER);
     }
     $addParams = array();
     $addParams[$this->object->getUniqueLabelField()] = $params[self::ORDER_UNIQUENAME];
     $addParams['ns_nagios_server'] = $this->instanceObj->getInstanceId($params[self::ORDER_INSTANCE]);
     $this->params = array_merge($this->params, $addParams);
     $this->checkParameters();
     parent::add();
 }
 /**
  * Add a service template
  *
  * @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_SVCDESC]) == true) {
         throw new CentreonClapiException(self::OBJECTALREADYEXISTS);
     }
     $addParams = array();
     $addParams['service_description'] = $params[self::ORDER_SVCDESC];
     $addParams['service_alias'] = $params[self::ORDER_SVCALIAS];
     $template = $params[self::ORDER_SVCTPL];
     if ($template) {
         $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();
     $extended = new Centreon_Object_Service_Extended();
     $extended->insert(array($extended->getUniqueLabelField() => $serviceId));
 }
 /**
  * Add a contact
  *
  * @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);
     }
     $addParams = array();
     $addParams[$this->object->getUniqueLabelField()] = $params[self::ORDER_UNIQUENAME];
     $addParams['host_alias'] = $params[self::ORDER_ALIAS];
     $addParams['host_address'] = $params[self::ORDER_ADDRESS];
     $templates = explode("|", $params[self::ORDER_TEMPLATE]);
     $templateIds = array();
     foreach ($templates as $template) {
         if ($template) {
             $tmp = $this->object->getIdByParameter($this->object->getUniqueLabelField(), $template);
             if (count($tmp)) {
                 $templateIds[] = $tmp[0];
             } else {
                 throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $template);
             }
         }
     }
     $instanceName = $params[self::ORDER_POLLER];
     $instanceObject = new Centreon_Object_Instance();
     if ($this->action == "HOST") {
         if ($instanceName) {
             $tmp = $instanceObject->getIdByParameter($instanceObject->getUniqueLabelField(), $instanceName);
             if (!count($tmp)) {
                 throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $instanceName);
             }
             $instanceId = $tmp[0];
         } else {
             throw new CentreonClapiException(self::MISSING_INSTANCE);
         }
     }
     $hostgroups = explode("|", $params[self::ORDER_HOSTGROUP]);
     $hostgroupIds = array();
     $hostgroupObject = new Centreon_Object_Host_Group();
     foreach ($hostgroups as $hostgroup) {
         if ($hostgroup) {
             $tmp = $hostgroupObject->getIdByParameter($hostgroupObject->getUniqueLabelField(), $hostgroup);
             if (count($tmp)) {
                 $hostgroupIds[] = $tmp[0];
             } else {
                 throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $hostgroup);
             }
         }
     }
     $this->params = array_merge($this->params, $addParams);
     $this->checkParameters();
     $hostId = parent::add();
     $i = 1;
     $templateRelationObject = new Centreon_Object_Relation_Host_Template_Host();
     foreach ($templateIds as $templateId) {
         $templateRelationObject->insert($templateId, $hostId, $i);
         $i++;
     }
     $hostgroupRelationObject = new Centreon_Object_Relation_Host_Group_Host();
     foreach ($hostgroupIds as $hostgroupId) {
         $hostgroupRelationObject->insert($hostgroupId, $hostId);
     }
     if (isset($instanceId)) {
         $instanceRelationObject = new Centreon_Object_Relation_Instance_Host();
         $instanceRelationObject->insert($instanceId, $hostId);
     }
     $extended = new Centreon_Object_Host_Extended();
     $extended->insert(array($extended->getUniqueLabelField() => $hostId));
 }
 /**
  * Add a contact
  *
  * @param string $parameters
  * @throws CentreonClapiException
  */
 public function add($parameters)
 {
     $params = explode($this->delim, $parameters);
     if (count($params) < $this->nbOfCompulsoryParams) {
         throw new CentreonClapiException(self::MISSINGPARAMETER);
     }
     $addParams = array();
     $params[self::ORDER_UNIQUENAME] = str_replace(" ", "_", $params[self::ORDER_UNIQUENAME]);
     $addParams[$this->object->getUniqueLabelField()] = $params[self::ORDER_UNIQUENAME];
     $addParams['contact_name'] = $params[self::ORDER_NAME];
     $addParams['contact_email'] = $params[self::ORDER_MAIL];
     $addParams['contact_passwd'] = md5($params[self::ORDER_PASS]);
     $addParams['contact_admin'] = $params[self::ORDER_ADMIN];
     $addParams['contact_oreon'] = $params[self::ORDER_ACCESS];
     if ($this->checkLang($params[self::ORDER_LANG]) == false) {
         throw new CentreonClapiException(self::UNKNOWN_LOCALE);
     }
     $addParams['contact_lang'] = $params[self::ORDER_LANG];
     $addParams['contact_auth_type'] = $params[self::ORDER_AUTHTYPE];
     $this->params = array_merge($this->params, $addParams);
     $this->checkParameters();
     parent::add();
 }
 /**
  * Add action
  *
  * @param string $parameters
  * @return void
  */
 public function add($parameters)
 {
     $params = explode($this->delim, $parameters);
     if (count($params) < $this->nbOfCompulsoryParams) {
         throw new CentreonClapiException(self::MISSINGPARAMETER);
     }
     $addParams = array();
     $instanceNames = explode("|", $params[self::ORDER_INSTANCE]);
     $instanceIds = array();
     foreach ($instanceNames as $instanceName) {
         $instanceIds[] = $this->instanceObj->getInstanceId($instanceName);
     }
     foreach ($instanceIds as $instanceId) {
         if ($this->isUnique("\$" . $params[self::ORDER_UNIQUENAME] . "\$", $instanceId) == false) {
             throw new CentreonClapiException(self::MACRO_ALREADY_IN_USE);
         }
     }
     $addParams[$this->object->getUniqueLabelField()] = "\$" . $params[self::ORDER_UNIQUENAME] . "\$";
     $addParams['resource_line'] = $params[self::ORDER_VALUE];
     $addParams['resource_comment'] = $params[self::ORDER_COMMENT];
     $this->params = array_merge($this->params, $addParams);
     $resourceId = parent::add();
     $this->setRelations($resourceId, $instanceIds);
 }
 /**
  * Add a command
  *
  * @param string $parameters
  * @throws CentreonClapiException
  */
 public function add($parameters)
 {
     $params = explode($this->delim, $parameters);
     if (count($params) < $this->nbOfCompulsoryParams) {
         throw new CentreonClapiException(self::MISSINGPARAMETER);
     }
     $addParams = array();
     $addParams[$this->object->getUniqueLabelField()] = $params[self::ORDER_UNIQUENAME];
     if (!isset($this->typeConversion[$params[self::ORDER_TYPE]])) {
         throw new CentreonClapiException(self::UNKNOWN_CMD_TYPE . ":" . $params[self::ORDER_TYPE]);
     }
     $addParams['command_type'] = is_numeric($params[self::ORDER_TYPE]) ? $params[self::ORDER_TYPE] : $this->typeConversion[$params[self::ORDER_TYPE]];
     $addParams['command_line'] = $params[self::ORDER_COMMAND];
     $this->params = array_merge($this->params, $addParams);
     $this->checkParameters();
     parent::add();
 }
 /**
  * Add action
  *
  * @param string $parameters
  * @return void
  */
 public function add($parameters)
 {
     $params = explode($this->delim, $parameters);
     if (count($params) < $this->nbOfCompulsoryParams) {
         throw new CentreonClapiException(self::MISSINGPARAMETER);
     }
     $addParams = array();
     $addParams[$this->object->getUniqueLabelField()] = $params[self::ORDER_UNIQUENAME];
     $addParams['nagios_server_id'] = $this->instanceObj->getInstanceId($params[self::ORDER_INSTANCE]);
     $addParams['nagios_comment'] = $params[self::ORDER_COMMENT];
     $this->params = array_merge($this->params, $addParams);
     $this->checkParameters();
     $objectId = parent::add();
     $this->setBrokerModule($objectId, "/usr/lib/nagios/ndomod.o config_file=/etc/nagios/ndomod.cfg");
 }
 /**
  * Add action
  *
  * @param string $parameters
  * @return void
  */
 public function add($parameters)
 {
     $params = explode($this->delim, $parameters);
     if (count($params) < $this->nbOfCompulsoryParams) {
         throw new CentreonClapiException(self::MISSINGPARAMETER);
     }
     $addParams = array();
     $addParams[$this->object->getUniqueLabelField()] = $params[self::ORDER_UNIQUENAME];
     $addParams['ns_ip_address'] = $params[self::ORDER_ADDRESS];
     $addParams['ssh_port'] = $params[self::ORDER_SSH_PORT];
     $addParams['monitoring_engine'] = $params[self::ORDER_MONITORING_ENGINE];
     if ($addParams['ns_ip_address'] == "127.0.0.1" || strtolower($addParams['ns_ip_address']) == "localhost") {
         $this->params['localhost'] = '1';
     }
     $this->params = array_merge($this->params, $addParams);
     $this->checkParameters();
     parent::add();
 }