/** * Import configuration data. * * $params structure: * array( * 'format' => 'json'|'xml' * 'source' => configuration data in specified format, * 'rules' => array( * 'hosts' => array('createMissing' => true, 'updateExisting' => false), * 'templates' => array('createMissing' => true, 'updateExisting' => true), * ... * ) * ) * * @param $params * * @return bool */ public function import($params) { $importReader = CImportReaderFactory::getReader($params['format']); $configurationImport = new CConfigurationImport($params['source'], $params['rules']); $configurationImport->setReader($importReader); return $configurationImport->import(); }
/** * Import configuration data. * * $params structure: * array( * 'format' => 'json'|'xml' * 'source' => configuration data in specified format, * 'rules' => array( * 'hosts' => array('createMissing' => true, 'updateExisting' => false), * 'templates' => array('createMissing' => true, 'updateExisting' => true), * ... * ) * ) * * @param $params * * @return bool */ public function import($params) { $importReader = CImportReaderFactory::getReader($params['format']); $configurationImport = new CConfigurationImport($params['source'], $params['rules'], new CImportReferencer(), new CImportedObjectContainer(), new CTriggerExpression()); $configurationImport->setReader($importReader); return $configurationImport->import(); }
/** * Import configuration data. * * $params structure: * array( * 'format' => 'json'|'xml' * 'source' => configuration data in specified format, * 'rules' => array( * 'hosts' => array('createMissing' => true, 'updateExisting' => false), * 'templates' => array('createMissing' => true, 'updateExisting' => true), * ... * ) * ) * * @param $params * * @return bool */ public function import($params) { $importReader = CImportReaderFactory::getReader($params['format']); $data = $importReader->read($params['source']); $data = (new CXmlValidator())->validate($data, $params['format']); $importConverterFactory = new CImportConverterFactory(); $converterChain = new CConverterChain(); $converterChain->addConverter('1.0', $importConverterFactory->getObject('1.0')); $converterChain->addConverter('2.0', $importConverterFactory->getObject('2.0')); $adapter = new CImportDataAdapter(ZABBIX_EXPORT_VERSION, $converterChain); $adapter->load($data); $configurationImport = new CConfigurationImport($params['rules'], new CImportReferencer(), new CImportedObjectContainer(), new CTriggerExpression()); return $configurationImport->import($adapter); }
if (array_key_exists('deleteMissing', $rule)) { $requestRules[$ruleName]['deleteMissing'] = false; } } if (!isset($requestRules[$ruleName]['updateExisting']) && isset($rule['updateExisting'])) { $requestRules[$ruleName]['updateExisting'] = false; } if (!isset($requestRules[$ruleName]['createMissing']) && isset($rule['createMissing'])) { $requestRules[$ruleName]['createMissing'] = false; } if (!isset($requestRules[$ruleName]['deleteMissing']) && isset($rule['deleteMissing'])) { $requestRules[$ruleName]['deleteMissing'] = false; } } $data['rules'] = $requestRules; } if (isset($_FILES['import_file'])) { $result = false; // CUploadFile throws exceptions, so we need to catch them try { $file = new CUploadFile($_FILES['import_file']); $result = API::Configuration()->import(['format' => CImportReaderFactory::fileExt2ImportFormat($file->getExtension()), 'source' => $file->getContent(), 'rules' => $data['rules']]); } catch (Exception $e) { error($e->getMessage()); } show_messages($result, _('Imported successfully'), _('Import failed')); } $view = new CView('conf.import', $data); $view->render(); $view->show(); require_once dirname(__FILE__) . '/include/page_footer.php';
$requestRules[$ruleName]['updateExisting'] = false; } if (isset($rule['createMissing'])) { $requestRules[$ruleName]['createMissing'] = false; } } elseif (!isset($requestRules[$ruleName]['updateExisting']) && isset($rule['updateExisting'])) { $requestRules[$ruleName]['updateExisting'] = false; } elseif (!isset($requestRules[$ruleName]['createMissing']) && isset($rule['createMissing'])) { $requestRules[$ruleName]['createMissing'] = false; } } $data['rules'] = $requestRules; } if (isset($_FILES['import_file'])) { try { $file = new CUploadFile($_FILES['import_file']); $importFormat = CImportReaderFactory::fileExt2ImportFormat($file->getExtension()); $importReader = CImportReaderFactory::getReader($importFormat); $configurationImport = new CConfigurationImport($file->getContent(), $data['rules']); $configurationImport->setReader($importReader); $configurationImport->import(); show_messages(true, _('Imported successfully')); } catch (Exception $e) { error($e->getMessage()); show_messages(false, null, _('Import failed')); } } $view = new CView('conf.import', $data); $view->render(); $view->show(); require_once 'include/page_footer.php';