/** * Export data * * @param string $parameters * @return void */ public function export() { $elements = $this->object->getList("*", -1, 0); foreach ($elements as $element) { $addStr = $this->action . $this->delim . "ADD"; foreach ($this->insertParams as $param) { $addStr .= $this->delim . $element[$param]; } $addStr .= "\n"; echo $addStr; foreach ($element as $parameter => $value) { if (!is_null($value) && $value != "" && !in_array($parameter, $this->exportExcludedParams)) { if ($parameter == "timeperiod_tp_id") { $parameter = self::HOST_NOTIF_TP; $value = $this->tpObject->getObjectName($value); } elseif ($parameter == "timeperiod_tp_id2") { $parameter = self::SVC_NOTIF_TP; $value = $this->tpObject->getObjectName($value); } elseif ($parameter == "contact_lang") { $parameter = "locale"; } $value = CentreonUtils::convertLineBreak($value); echo $this->action . $this->delim . "setparam" . $this->delim . $element[$this->object->getUniqueLabelField()] . $this->delim . $parameter . $this->delim . $value . "\n"; } } $objId = $element[$this->object->getPrimaryKey()]; $this->exportNotifCommands(self::HOST_NOTIF_CMD, $objId, $element[$this->object->getUniqueLabelField()]); $this->exportNotifCommands(self::SVC_NOTIF_CMD, $objId, $element[$this->object->getUniqueLabelField()]); } }
/** * 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])); } }
/** * 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]); } }
/** * 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); } $hostName = $params[0]; $serviceDesc = $params[1]; $relObject = new Centreon_Object_Relation_Host_Service(); $elements = $relObject->getMergedParameters(array("host_id"), array("service_id"), -1, 0, null, null, array("host_name" => $hostName, "service_description" => $serviceDesc), "AND"); if (!count($elements)) { throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $hostName . "/" . $serviceDesc); } $objectId = $elements[0]['service_id']; $extended = false; $commandObject = new CentreonCommand(); switch ($params[2]) { case "check_command": $params[2] = "command_command_id"; $params[3] = $commandObject->getId($params[3]); break; case "check_command_arguments": $params[2] = "command_command_id_arg"; break; case "event_handler": $params[2] = "command_command_id2"; $params[3] = $commandObject->getId($params[3]); break; case "event_handler_arguments": $params[2] = "command_command_id_arg2"; break; case "check_period": $params[2] = "timeperiod_tp_id"; $tpObj = new CentreonTimePeriod(); $params[3] = $tpObj->getTimeperiodId($params[3]); break; case "notification_period": $params[2] = "timeperiod_tp_id2"; $tpObj = new CentreonTimePeriod(); $params[3] = $tpObj->getTimeperiodId($params[3]); break; case "flap_detection_options": break; case "template": $params[2] = "service_template_model_stm_id"; $tmp = $this->object->getList($this->object->getPrimaryKey(), -1, 0, null, null, array('service_description' => $params[3], 'service_register' => '0'), "AND"); if (!count($tmp)) { throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $params[3]); } $params[3] = $tmp[0][$this->object->getPrimaryKey()]; break; case "graphtemplate": $extended = true; $graphObj = new Centreon_Object_Graph_Template(); $tmp = $graphObj->getIdByParameter($graphObj->getUniqueLabelField(), $params[3]); if (!count($tmp)) { throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $params[3]); } $params[2] = "graph_id"; $params[3] = $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; case "service_notification_options": $aNotifs = explode(",", $params[3]); foreach ($aNotifs as $notif) { if (!array_key_exists($notif, self::$aAuthorizedNotificationsOptions)) { throw new CentreonClapiException(self::UNKNOWN_NOTIFICATION_OPTIONS); } } break; default: if (!preg_match("/^service_/", $params[2])) { $params[2] = "service_" . $params[2]; } break; } if ($extended == false) { $updateParams = array($params[2] => $params[3]); if ($params[2] == 'service_description' && $this->serviceExists($hostName, $params[3])) { throw new CentreonClapiException(self::OBJECTALREADYEXISTS); } $this->object->update($objectId, $updateParams); $this->addAuditLog('c', $objectId, $hostName . ' - ' . $serviceDesc, $updateParams); } else { if ($params[2] != "graph_id") { $params[2] = "esi_" . $params[2]; if ($params[2] == "esi_icon_image") { if ($params[3]) { $id = CentreonUtils::getImageId($params[3]); if (is_null($id)) { throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $params[3]); } $params[3] = $id; } else { $params[3] = null; } } } $extended = new Centreon_Object_Service_Extended(); $extended->update($objectId, array($params[2] => $params[3])); $this->addAuditLog('c', $objectId, $hostName . ' - ' . $serviceDesc, array($params[2] => $params[3])); } }