/** * Export * * @return void */ public function export() { $elements = $this->object->getList("*", -1, 0, null, null, array("host_register" => $this->register), "AND"); $extendedObj = new Centreon_Object_Host_Extended(); $commandObj = new Centreon_Object_Command(); $tpObj = new Centreon_Object_Timeperiod(); $macroObj = new Centreon_Object_Host_Macro_Custom(); $instanceRel = new Centreon_Object_Relation_Instance_Host(); if ($this->register) { $instElements = $instanceRel->getMergedParameters(array("name"), array("host_name"), -1, 0, null, null, array("host_register" => $this->register), "AND"); } foreach ($elements as $element) { $addStr = $this->action . $this->delim . "ADD"; foreach ($this->insertParams as $param) { $addStr .= $this->delim; if ($param == 'instance') { if ($this->register) { foreach ($instElements as $instElem) { if ($element['host_name'] == $instElem['host_name']) { $addStr .= $instElem['name']; } } } } if ($param != "hostgroup" && $param != "template") { $addStr .= $element[$param]; } } $addStr .= "\n"; echo $addStr; foreach ($element as $parameter => $value) { if (!in_array($parameter, $this->exportExcludedParams) && !is_null($value) && $value != "") { if ($parameter == "timeperiod_tp_id" || $parameter == "timeperiod_tp_id2") { $tmpObj = $tpObj; } elseif ($parameter == "command_command_id" || $parameter == "command_command_id2") { $tmpObj = $commandObj; } if (isset($tmpObj)) { $tmp = $tmpObj->getParameters($value, $tmpObj->getUniqueLabelField()); if (isset($tmp) && isset($tmp[$tmpObj->getUniqueLabelField()])) { $value = $tmp[$tmpObj->getUniqueLabelField()]; } unset($tmpObj); } $value = CentreonUtils::convertLineBreak($value); echo $this->action . $this->delim . "setparam" . $this->delim . $element[$this->object->getUniqueLabelField()] . $this->delim . $this->getClapiActionName($parameter) . $this->delim . $value . "\n"; } } $params = $extendedObj->getParameters($element[$this->object->getPrimaryKey()], array("ehi_notes", "ehi_notes_url", "ehi_action_url", "ehi_icon_image", "ehi_icon_image_alt", "ehi_vrml_image", "ehi_statusmap_image", "ehi_2d_coords", "ehi_3d_coords")); if (isset($params) && is_array($params)) { foreach ($params as $k => $v) { if (!is_null($v) && $v != "") { $v = CentreonUtils::convertLineBreak($v); echo $this->action . $this->delim . "setparam" . $this->delim . $element[$this->object->getUniqueLabelField()] . $this->delim . $this->getClapiActionName($k) . $this->delim . $v . "\n"; } } } $macros = $macroObj->getList("*", -1, 0, null, null, array('host_host_id' => $element[$this->object->getPrimaryKey()]), "AND"); foreach ($macros as $macro) { echo $this->action . $this->delim . "setmacro" . $this->delim . $element[$this->object->getUniqueLabelField()] . $this->delim . $this->stripMacro($macro['host_macro_name']) . $this->delim . $macro['host_macro_value'] . "\n"; } } $cgRel = new Centreon_Object_Relation_Contact_Group_Host(); $elements = $cgRel->getMergedParameters(array("cg_name"), array($this->object->getUniqueLabelField()), -1, 0, null, null, array("host_register" => $this->register), "AND"); foreach ($elements as $element) { echo $this->action . $this->delim . "addcontactgroup" . $this->delim . $element[$this->object->getUniqueLabelField()] . $this->delim . $element['cg_name'] . "\n"; } $contactRel = new Centreon_Object_Relation_Contact_Host(); $elements = $contactRel->getMergedParameters(array("contact_name"), array($this->object->getUniqueLabelField()), -1, 0, null, null, array("host_register" => $this->register), "AND"); foreach ($elements as $element) { echo $this->action . $this->delim . "addcontact" . $this->delim . $element[$this->object->getUniqueLabelField()] . $this->delim . $element['contact_name'] . "\n"; } $htplRel = new Centreon_Object_Relation_Host_Template_Host(); $elements = $htplRel->getMergedParameters(array("host_name as host"), array("host_name as template"), -1, 0, "host,`order`", "ASC", array("h.host_register" => $this->register), "AND"); foreach ($elements as $element) { echo $this->action . $this->delim . "addtemplate" . $this->delim . $element['host'] . $this->delim . $element['template'] . "\n"; } }