/** * Unset severity * * @param string $parameters * @throws CentreonClapiException */ public function unsetseverity($parameters) { $params = explode($this->delim, $parameters); if (count($params) < 1) { throw new CentreonClapiException(self::MISSINGPARAMETER); } if (($objectId = $this->getObjectId($params[self::ORDER_UNIQUENAME])) != 0) { parent::setparam($objectId, array('level' => null, 'icon_id' => null)); } else { throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $params[self::ORDER_UNIQUENAME]); } }
/** * Set Parameters * * @param string $parameters * @return void * @throws Exception */ public function setparam($parameters) { $params = explode($this->delim, $parameters); if (count($params) < self::NB_UPDATE_PARAMS) { throw new CentreonClapiException(self::MISSINGPARAMETER); } if (($objectId = $this->getObjectId($params[self::ORDER_UNIQUENAME])) != 0) { if ($params[1] == "instance" || $params[1] == "ns_nagios_server") { $params[1] = "ns_nagios_server"; $params[2] = $this->instanceObj->getInstanceId($params[2]); } $updateParams = array($params[1] => $params[2]); parent::setparam($objectId, $updateParams); } else { throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $params[self::ORDER_UNIQUENAME]); } }
/** * Export * * @return void */ public function export() { parent::export(); $sgs = $this->object->getList(array($this->object->getPrimaryKey(), $this->object->getUniqueLabelField())); $relobjSvc = new Centreon_Object_Relation_Service_Group_Service(); $objSvc = new Centreon_Object_Relation_Host_Service(); $relobjHgSvc = new Centreon_Object_Relation_Service_Group_Host_Group_Service(); $objHgSvc = new Centreon_Object_Relation_Host_Group_Service(); foreach ($sgs as $sg) { $sgId = $sg[$this->object->getPrimaryKey()]; $sgName = $sg[$this->object->getUniqueLabelField()]; $existingRelationIds = $relobjSvc->getHostIdServiceIdFromServicegroupId($sgId); foreach ($existingRelationIds as $val) { $elements = $objSvc->getMergedParameters(array('host_name'), array('service_description'), -1, 0, "host_name,service_description", "ASC", array("service_id" => $val['service_id'], "host_id" => $val['host_id']), "AND"); foreach ($elements as $element) { echo $this->action . $this->delim . "addservice" . $this->delim . $sgName . $this->delim . $element['host_name'] . "," . $element['service_description'] . "\n"; } } $existingRelationIds = $relobjHgSvc->getHostGroupIdServiceIdFromServicegroupId($sgId); foreach ($existingRelationIds as $val) { $elements = $objHgSvc->getMergedParameters(array('hg_name'), array('service_description'), -1, 0, null, null, array("hg_id" => $val['hostgroup_id'], "service_id" => $val['service_id']), "AND"); foreach ($elements as $element) { echo $this->action . $this->delim . "addhostgroupservice" . $this->delim . $sgName . $this->delim . $element['hg_name'] . "," . $element['service_description'] . "\n"; } } } }
/** * Constructor * * @return void */ public function __construct() { parent::__construct(); $this->baseParams = array('alias' => '', 'bind_dn' => '', 'bind_pass' => '', 'group_base_search' => '', 'group_filter' => '', 'group_member' => '', 'group_name' => '', 'ldap_auto_import' => '', 'ldap_contact_tmpl' => '', 'ldap_dns_use_domain' => '', 'ldap_search_limit' => '', 'ldap_search_timeout' => '', 'ldap_srv_dns' => '', 'ldap_store_password' => '', 'ldap_template' => '', 'protocol_version' => '', 'user_base_search' => '', 'user_email' => '', 'user_filter' => '', 'user_firstname' => '', 'user_lastname' => '', 'user_name' => '', 'user_pager' => '', 'user_group' => ''); $this->serverParams = array('host_address', 'host_port', 'host_order', 'use_ssl', 'use_tls'); }
/** * Set parameters * * @param string $parameters * @return void * @throws CentreonClapiException */ public function setparam($parameters) { $params = explode($this->delim, $parameters); if (count($params) < self::NB_UPDATE_PARAMS) { throw new CentreonClapiException(self::MISSINGPARAMETER); } $params[self::ORDER_NAME] = str_replace(" ", "_", $params[self::ORDER_NAME]); if (($objectId = $this->getObjectId($params[self::ORDER_NAME])) != 0) { $regularParam = true; if ($params[1] == self::HOST_NOTIF_TP) { $params[1] = "timeperiod_tp_id"; $params[2] = $this->tpObject->getTimeperiodId($params[2]); } elseif ($params[1] == self::SVC_NOTIF_TP) { $params[1] = "timeperiod_tp_id2"; $params[2] = $this->tpObject->getTimeperiodId($params[2]); } elseif ($params[1] == self::HOST_NOTIF_CMD || $params[1] == self::SVC_NOTIF_CMD) { $this->setNotificationCmd($params[1], $objectId, $params[2]); $regularParam = false; } elseif (!preg_match("/^contact_/", $params[1])) { if ($params[1] == "access") { $params[1] = "oreon"; } elseif ($params[1] == "template") { $params[1] = "template_id"; $contactId = $this->getContactID($params[2]); if (!isset($contactId) || !$contactId) { throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $params[2]); } $params[2] = $contactId; } elseif ($params[1] == "authtype") { $params[1] = "auth_type"; } elseif ($params[1] == "lang" || $params[1] == "language" || $params[1] == "locale") { if ($this->checkLang($params[2]) == false) { throw new CentreonClapiException(self::UNKNOWN_LOCALE); } $params[1] = "lang"; } elseif ($params[1] == "password") { $params[1] = "passwd"; $params[2] = md5(trim($params[2])); } elseif ($params[1] == "hostnotifopt") { $params[1] = "host_notification_options"; $aNotifs = explode(",", $params[2]); foreach ($aNotifs as $notif) { if (!array_key_exists($notif, self::$aAuthorizedNotificationsOptions['host'])) { throw new CentreonClapiException(self::UNKNOWN_NOTIFICATION_OPTIONS); } } } elseif ($params[1] == "servicenotifopt") { $params[1] = "service_notification_options"; $aNotifs = explode(",", $params[2]); foreach ($aNotifs as $notif) { if (!array_key_exists($notif, self::$aAuthorizedNotificationsOptions['service'])) { throw new CentreonClapiException(self::UNKNOWN_NOTIFICATION_OPTIONS); } } } $params[1] = "contact_" . $params[1]; } if ($regularParam == true) { $updateParams = array($params[1] => $params[2]); parent::setparam($objectId, $updateParams); } } else { throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $params[self::ORDER_UNIQUENAME]); } }
/** * Set parameters * * @param string $parameters * @return void */ public function setparam($parameters) { $params = explode($this->delim, $parameters); if (count($params) < self::NB_UPDATE_PARAMS) { throw new CentreonClapiException(self::MISSINGPARAMETER); } if (($objectId = $this->getObjectId($params[self::ORDER_UNIQUENAME])) != 0) { if ($params[1] == self::TP_INCLUDE || $params[1] == self::TP_EXCLUDE) { $this->setRelations($params[1], $objectId, $params[2]); } elseif (!preg_match("/^tp_/", $params[1])) { $params[1] = "tp_" . $params[1]; } if ($params[1] != self::TP_INCLUDE && $params[1] != self::TP_EXCLUDE) { $updateParams = array($params[1] => $params[2]); parent::setparam($objectId, $updateParams); } } else { throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $params[self::ORDER_UNIQUENAME]); } }
/** * Constructor * * @return void */ public function __construct() { parent::__construct(); $this->authorizedOptions = array('broker' => array('ndo', 'broker'), 'centstorage' => array('0', '1'), 'enable_perfdata_sync' => array('0', '1'), 'enable_logs_sync' => array('0', '1'), 'gmt' => ISNUM, 'mailer_path_bin' => ISSTRING, 'snmptt_unknowntrap_log_file' => ISSTRING, 'snmpttconvertmib_path_bin' => ISSTRING, 'perl_library_path' => ISSTRING, 'rrdtool_path_bin' => ISSTRING, 'debug_path' => ISSTRING, 'debug_auth' => array('0', '1'), 'debug_nagios_import' => array('0', '1'), 'debug_rrdtool' => array('0', '1'), 'debug_ldap_import' => array('0', '1'), 'enable_autologin' => array('0', '1'), 'interval_length' => ISNUM, 'enable_gmt' => array('0', '1'), 'nagios_path_img' => ISSTRING, 'broker_correlator_script' => ISSTRING); }
/** * Set params * * @param string $parameters * @return void * @throws CentreonClapiException */ public function setparam($parameters = null) { $params = explode($this->delim, $parameters); if (count($params) < self::NB_UPDATE_PARAMS) { throw new CentreonClapiException(self::MISSINGPARAMETER); } if (($objectId = $this->getObjectId($params[self::ORDER_UNIQUENAME])) != 0) { if (in_array($params[1], array('comment', 'name', 'description')) && !preg_match("/^dep_/", $params[1])) { $params[1] = "dep_" . $params[1]; } $updateParams = array($params[1] => $params[2]); parent::setparam($objectId, $updateParams); } else { throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $params[self::ORDER_UNIQUENAME]); } }
/** * Export * * @return void */ public function export() { parent::export(); $obj = new Centreon_Object_Relation_Contact_Group_Contact(); $elements = $obj->getMergedParameters(array("cg_name"), array("contact_name"), -1, 0, "cg_name"); foreach ($elements as $element) { echo $this->action . $this->delim . "addcontact" . $this->delim . $element['cg_name'] . $this->delim . $element['contact_name'] . "\n"; } }
/** * Set Parameters * * @param string $parameters * @return void * @throws Exception */ public function setparam($parameters) { $params = explode($this->delim, $parameters); if (count($params) < self::NB_UPDATE_PARAMS) { throw new CentreonClapiException(self::MISSINGPARAMETER); } if (($objectId = $params[self::ORDER_UNIQUENAME]) != 0) { if ($params[1] == "instance") { $instanceNames = explode("|", $params[self::ORDER_INSTANCE]); $instanceIds = array(); foreach ($instanceNames as $instanceName) { $instanceIds[] = $this->instanceObj->getInstanceId($instanceName); } /* foreach ($instanceIds as $instanceId) { if ($this->isUnique($objectId, $instanceId) == false) { throw new CentreonClapiException(self::MACRO_ALREADY_IN_USE); } } */ $this->setRelations($objectId, $instanceIds); } else { $params[1] = str_replace("value", "line ", $params[1]); if ($params[1] == "name") { $params[2] = "\$" . $params[2] . "\$"; } $params[1] = "resource_" . $params[1]; $updateParams = array($params[1] => $params[2]); parent::setparam($objectId, $updateParams); } } else { throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $params[self::ORDER_UNIQUENAME]); } }
/** * Set parameter * * @param string $parameters * @return void */ public function setparam($parameters = null) { $params = explode($this->delim, $parameters); if (count($params) < self::NB_UPDATE_PARAMS) { throw new CentreonClapiException(self::MISSINGPARAMETER); } $values = array($params[1] => $params[2]); parent::setparam($this->getId($params[0]), $values); }
/** * Set parameters * * @param string $parameters * @throws CentreonClapiException */ public function setparam($parameters) { $params = explode($this->delim, $parameters); if (count($params) < self::NB_UPDATE_PARAMS) { throw new CentreonClapiException(self::MISSINGPARAMETER); } if (($objectId = $this->getObjectId($params[self::ORDER_UNIQUENAME])) != 0) { if (!preg_match("/^command_/", $params[1])) { if (!in_array($params[1], array('graph', 'enable_shell'))) { $params[1] = "command_" . $params[1]; } elseif ($params[1] == "graph") { $params[1] = "graph_id"; } } if ($params[1] == "command_type") { if (!isset($this->typeConversion[$params[2]])) { throw new CentreonClapiException(self::UNKNOWN_CMD_TYPE . ":" . $params[2]); } if (!is_numeric($params[2])) { $params[2] = $this->typeConversion[$params[2]]; } } elseif ($params[1] == "graph_id") { $graphObject = new Centreon_Object_Graph_Template(); $tmp = $graphObject->getIdByParameter($graphObject->getUniqueLabelField(), $params[2]); if (!count($tmp)) { throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $params[2]); } $params[2] = $tmp[0]; } $updateParams = array($params[1] => $params[2]); parent::setparam($objectId, $updateParams); } else { throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $params[self::ORDER_UNIQUENAME]); } }
/** * Magic method * * @param string $name * @param array $args * @return void * @throws CentreonClapiException */ public function __call($name, $arg) { $name = strtolower($name); if (!isset($arg[0])) { throw new CentreonClapiException(self::MISSINGPARAMETER); } $args = explode($this->delim, $arg[0]); $groupIds = $this->object->getIdByParameter($this->object->getUniqueLabelField(), array($args[0])); if (!count($groupIds)) { throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $args[0]); } $groupId = $groupIds[0]; if (preg_match("/^(get|set|add|del)([a-zA-Z_]+)/", $name, $matches)) { $relclass = "Centreon_Object_Relation_Acl_Group_" . ucwords($matches[2]); if (class_exists("Centreon_Object_Acl_" . ucwords($matches[2]))) { $class = "Centreon_Object_Acl_" . ucwords($matches[2]); } elseif ($matches[2] == "contactgroup") { $class = "Centreon_Object_Contact_Group"; $relclass = "Centreon_Object_Relation_Acl_Group_Contact_Group"; } else { $class = "Centreon_Object_" . ucwords($matches[2]); } if (class_exists($relclass) && class_exists($class)) { $relobj = new $relclass(); $obj = new $class(); if ($matches[1] == "get") { $tab = $relobj->getTargetIdFromSourceId($relobj->getSecondKey(), $relobj->getFirstKey(), $groupIds); echo "id" . $this->delim . "name" . "\n"; foreach ($tab as $value) { $tmp = $obj->getParameters($value, array($obj->getUniqueLabelField())); echo $value . $this->delim . $tmp[$obj->getUniqueLabelField()] . "\n"; } } else { if (!isset($args[1])) { throw new CentreonClapiException(self::MISSINGPARAMETER); } $relation = $args[1]; $relations = explode("|", $relation); $relationTable = array(); foreach ($relations as $rel) { $tab = $obj->getIdByParameter($obj->getUniqueLabelField(), array($rel)); if (!count($tab)) { throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $rel); } $relationTable[] = $tab[0]; } if ($matches[1] == "set") { $relobj->delete($groupId); } $existingRelationIds = $relobj->getTargetIdFromSourceId($relobj->getSecondKey(), $relobj->getFirstKey(), array($groupId)); foreach ($relationTable as $relationId) { if ($matches[1] == "del") { $relobj->delete($groupId, $relationId); } elseif ($matches[1] == "set" || $matches[1] == "add") { if (!in_array($relationId, $existingRelationIds)) { $relobj->insert($groupId, $relationId); } } } parent::setparam($groupId, array('acl_group_changed' => '1')); } } else { throw new CentreonClapiException(self::UNKNOWN_METHOD); } } else { throw new CentreonClapiException(self::UNKNOWN_METHOD); } }
/** * Set Parameters * * @param string $parameters * @return void * @throws Exception */ public function setparam($parameters) { $params = explode($this->delim, $parameters); if (count($params) < self::NB_UPDATE_PARAMS) { throw new CentreonClapiException(self::MISSINGPARAMETER); } if (is_numeric($params[0])) { $objectId = $params[0]; } else { $object = $this->object->getIdByParameter($this->object->getUniqueLabelField(), array($params[0])); if (isset($object[0][$this->object->getPrimaryKey()])) { $objectId = $object[0][$this->object->getPrimaryKey()]; } else { throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $params[0]); } } if ($params[1] == "instance") { $instanceNames = explode("|", $params[2]); $instanceIds = array(); foreach ($instanceNames as $instanceName) { $instanceIds[] = $this->instanceObj->getInstanceId($instanceName); } $this->setRelations($objectId, $instanceIds); } else { $params[1] = str_replace("value", "line ", $params[1]); if ($params[1] == "name") { if (!preg_match('/^\\$\\S+\\$$/', $params[2])) { $params[2] = '$' . $params[2] . '$'; } } $params[1] = "resource_" . $params[1]; $updateParams = array($params[1] => $params[2]); parent::setparam($objectId, $updateParams); } }
/** * Set Parameters * * @param string $parameters * @return void * @throws Exception */ public function setparam($parameters) { $params = explode($this->delim, $parameters); if (count($params) < self::NB_UPDATE_PARAMS) { throw new CentreonClapiException(self::MISSINGPARAMETER); } if (($objectId = $this->getObjectId($params[self::ORDER_UNIQUENAME])) != 0) { $params[1] = "acl_res_" . $params[1]; $updateParams = array($params[1] => $params[2]); parent::setparam($objectId, $updateParams); } else { throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $params[self::ORDER_UNIQUENAME]); } }
/** * Set Parameters * * @param string $parameters * @return void * @throws Exception */ public function setparam($parameters) { $params = explode($this->delim, $parameters); if (count($params) < self::NB_UPDATE_PARAMS) { throw new CentreonClapiException(self::MISSINGPARAMETER); } if (($objectId = $this->getObjectId($params[self::ORDER_UNIQUENAME])) != 0) { $commandColumns = array('global_host_event_handler', 'global_service_event_handler', 'host_perfdata_command', 'service_perfdata_command', 'host_perfdata_file_processing_command', 'service_perfdata_file_processing_command', 'ocsp_command', 'ochp_command'); if ($params[1] == "instance" || $params[1] == "nagios_server_id") { $params[1] = "nagios_server_id"; $params[2] = $this->instanceObj->getInstanceId($params[2]); } elseif ($params[1] == "broker_module") { $this->setBrokerModule($objectId, $params[2]); } elseif (preg_match('/(' . implode('|', $commandColumns) . ')/', $params[1], $matches)) { $commandName = $matches[1]; if ($params[2]) { $commandObj = new Centreon_Object_Command(); $res = $commandObj->getIdByParameter($commandObj->getUniqueLabelField(), $params[2]); if (count($res)) { $params[2] = $res[0]; } else { throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $params[2]); } } else { $params[2] = NULL; } } if ($params[1] != "broker_module") { $p = strtolower($params[1]); if ($params[2] == "") { if (isset($this->params[$p]) && $this->params[$p] == 2) { $params[2] = $this->params[$p]; } else { $params[2] = NULL; } } $updateParams = array($params[1] => $params[2]); parent::setparam($objectId, $updateParams); } } else { throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $params[self::ORDER_UNIQUENAME]); } }
/** * Set parameters * * @param string $parameters * @return void * @throws CentreonClapiException */ public function setparam($parameters = null) { $params = explode($this->delim, $parameters); if (count($params) < self::NB_UPDATE_PARAMS) { throw new CentreonClapiException(self::MISSINGPARAMETER); } if (($objectId = $this->getObjectId($params[self::ORDER_UNIQUENAME])) != 0) { $extended = false; $commandObject = new CentreonCommand(); switch ($params[1]) { case "check_command": $params[1] = "command_command_id"; $params[2] = $commandObject->getId($params[2]); break; case "check_command_arguments": $params[1] = "command_command_id_arg1"; break; case "event_handler": $params[1] = "command_command_id2"; $params[2] = $commandObject->getId($params[2]); break; case "event_handler_arguments": $params[1] = "command_command_id_arg2"; break; case "check_period": $params[1] = "timeperiod_tp_id"; $tpObj = new CentreonTimePeriod(); $params[2] = $tpObj->getTimeperiodId($params[2]); break; case "notification_period": $params[1] = "timeperiod_tp_id2"; $tpObj = new CentreonTimePeriod(); $params[2] = $tpObj->getTimeperiodId($params[2]); break; case "contact_additive_inheritance": break; case "cg_additive_inheritance": break; case "flap_detection_options": break; case "notes": $extended = true; break; case "notes_url": $extended = true; break; case "action_url": $extended = true; break; case "icon_image": $extended = true; break; case "icon_image_alt": $extended = true; break; case "vrml_image": $extended = true; break; case "statusmap_image": $extended = true; break; case "2d_coords": $extended = true; break; case "3d_coords": $extended = true; break; default: if (!preg_match("/^host_/", $params[1])) { $params[1] = "host_" . $params[1]; } break; } if ($extended == false) { $updateParams = array($params[1] => $params[2]); parent::setparam($objectId, $updateParams); } else { $params[1] = "ehi_" . $params[1]; if ($params[1] == "ehi_icon_image" || $params[1] == "ehi_statusmap_image" || $params[1] == "ehi_vrml_image") { if ($params[2]) { $id = CentreonUtils::getImageId($params[2]); if (is_null($id)) { throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $params[2]); } $params[2] = $id; } else { $params[2] = null; } } $extended = new Centreon_Object_Host_Extended(); $extended->update($objectId, array($params[1] => $params[2])); } } else { throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $params[self::ORDER_UNIQUENAME]); } }
/** * Export * * @return void */ public function export() { parent::export(); $relObj = new Centreon_Object_Relation_Host_Group_Host(); $hostObj = new Centreon_Object_Host(); $hgFieldName = $this->object->getUniqueLabelField(); $hFieldName = $hostObj->getUniqueLabelField(); $elements = $relObj->getMergedParameters(array($hgFieldName), array($hFieldName), -1, 0, $hgFieldName, null); foreach ($elements as $element) { echo $this->action . $this->delim . "addhost" . $this->delim . $element[$hgFieldName] . $this->delim . $element[$hFieldName] . "\n"; } }
/** * Set Parameters * * @param string $parameters * @return void * @throws Exception */ public function setparam($parameters = null) { if (is_null($parameters)) { throw new CentreonClapiException(self::MISSINGPARAMETER); } $params = explode($this->delim, $parameters); if (count($params) < self::NB_UPDATE_PARAMS) { throw new CentreonClapiException(self::MISSINGPARAMETER); } if (($objectId = $this->getObjectId($params[self::ORDER_UNIQUENAME])) != 0) { if ($params[1] == "manufacturer" || $params[1] == "vendor") { $params[1] = "manufacturer_id"; $params[2] = $this->manufacturerObj->getId($params[2]); } elseif ($params[1] == "status") { $params[1] = "traps_status"; $params[2] = $this->getStatusInt($params[2]); } elseif ($params[1] == "output") { $params[1] = 'traps_args'; } elseif ($params[1] == "matching_mode") { $params[1] = "traps_advanced_treatment"; } elseif (!preg_match('/^traps_/', $params[1])) { $params[1] = 'traps_' . $params[1]; } $params[2] = str_replace("<br/>", "\n", $params[2]); $updateParams = array($params[1] => $params[2]); parent::setparam($objectId, $updateParams); } else { throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $params[self::ORDER_UNIQUENAME]); } }
/** * Export * */ public function export() { // generic add & setparam parent::export(); // handle host relationships $this->exportHostRel(); // handle hostgroup relationships $this->exportHostgroupRel(); // handle service relationships $this->exportServiceRel(); // handle servicegroup relationships $this->exportServicegroupRel(); // handle periods $this->exportPeriods(); }
/** * Set parameters * * @param string $parameters * @return void * @throws CentreonClapiException */ public function setparam($parameters = null) { $params = explode($this->delim, $parameters); if (count($params) < self::NB_UPDATE_PARAMS) { throw new CentreonClapiException(self::MISSINGPARAMETER); } $serviceDesc = $params[0]; $elements = $this->object->getList("service_id", -1, 0, null, null, array('service_description' => $serviceDesc, 'service_register' => 0), "AND"); if (!count($elements)) { throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $serviceDesc); } $objectId = $elements[0]['service_id']; $extended = false; $commandObject = new CentreonCommand(); switch ($params[1]) { case "check_command": $params[1] = "command_command_id"; $params[2] = $commandObject->getId($params[2]); break; case "check_command_arguments": $params[1] = "command_command_id_arg"; break; case "event_handler": $params[1] = "command_command_id2"; $params[2] = $commandObject->getId($params[2]); break; case "event_handler_arguments": $params[1] = "command_command_id_arg2"; break; case "check_period": $params[1] = "timeperiod_tp_id"; $tpObj = new CentreonTimePeriod(); $params[2] = $tpObj->getTimeperiodId($params[2]); break; case "notification_period": $params[1] = "timeperiod_tp_id2"; $tpObj = new CentreonTimePeriod(); $params[2] = $tpObj->getTimeperiodId($params[2]); break; case "flap_detection_options": break; case "template": $params[1] = "service_template_model_stm_id"; $tmp = $this->object->getList($this->object->getPrimaryKey(), -1, 0, null, null, array('service_description' => $params[2], 'service_register' => '0'), "AND"); if (!count($tmp)) { throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $params[2]); } $params[2] = $tmp[0][$this->object->getPrimaryKey()]; break; case "graphtemplate": $extended = true; $graphObj = new Centreon_Object_Graph_Template(); $tmp = $graphObj->getIdByParameter($graphObj->getUniqueLabelField(), $params[2]); if (!count($tmp)) { throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $params[2]); } $params[1] = "graph_id"; $params[2] = $tmp[0]; break; case "contact_additive_inheritance": break; case "cg_additive_inheritance": break; case "notes": $extended = true; break; case "notes_url": $extended = true; break; case "action_url": $extended = true; break; case "icon_image": $extended = true; break; case "icon_image_alt": $extended = true; break; default: if (!preg_match("/^service_/", $params[1])) { $params[1] = "service_" . $params[1]; } break; } if ($extended == false) { $updateParams = array($params[1] => $params[2]); parent::setparam($objectId, $updateParams); } else { if ($params[1] != "graph_id") { $params[1] = "esi_" . $params[1]; if ($params[1] == "esi_icon_image") { if ($params[2]) { $id = CentreonUtils::getImageId($params[2]); if (is_null($id)) { throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $params[2]); } $params[2] = $id; } else { $params[2] = null; } } } $extended = new Centreon_Object_Service_Extended(); $extended->update($objectId, array($params[1] => $params[2])); } }
/** * 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)); }