1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
<?php
/*
** Zabbix
** Copyright (C) 2001-2021 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
require_once dirname(__FILE__).'/include/config.inc.php';
$page['file'] = 'screen.import.php';
$page['title'] = _('Configuration import');
$page['type'] = detect_page_type(PAGE_TYPE_HTML);
require_once dirname(__FILE__).'/include/page_header.php';
$fields = [
'rules' => [T_ZBX_STR, O_OPT, null, null, null],
'import' => [T_ZBX_STR, O_OPT, P_SYS|P_ACT, null, null],
'rules_preset' => [T_ZBX_STR, O_OPT, null, null, null]
];
check_fields($fields);
$data = [
'rules' => [
'groups' => ['createMissing' => false],
'hosts' => ['updateExisting' => false, 'createMissing' => false],
'templates' => ['updateExisting' => false, 'createMissing' => false],
'templateScreens' => ['updateExisting' => false, 'createMissing' => false, 'deleteMissing' => false],
'templateLinkage' => ['createMissing' => false, 'deleteMissing' => false],
'applications' => ['createMissing' => false, 'deleteMissing' => false],
'items' => ['updateExisting' => false, 'createMissing' => false, 'deleteMissing' => false],
'discoveryRules' => ['updateExisting' => false, 'createMissing' => false, 'deleteMissing' => false],
'triggers' => ['updateExisting' => false, 'createMissing' => false, 'deleteMissing' => false],
'graphs' => ['updateExisting' => false, 'createMissing' => false, 'deleteMissing' => false],
'httptests' => ['updateExisting' => false, 'createMissing' => false, 'deleteMissing' => false],
'screens' => ['updateExisting' => true, 'createMissing' => true],
'maps' => ['updateExisting' => false, 'createMissing' => false],
'images' => ['updateExisting' => false, 'createMissing' => false],
'mediaTypes' => ['updateExisting' => false, 'createMissing' => false],
'valueMaps' => ['updateExisting' => false, 'createMissing' => false]
],
'rules_preset' => getRequest('rules_preset')
];
if (hasRequest('import')) {
$request_rules = getRequest('rules', []);
foreach ($data['rules'] as $rule_name => $rule) {
if (!array_key_exists($rule_name, $request_rules)) {
$request_rules[$rule_name] = [];
}
foreach (['updateExisting', 'createMissing', 'deleteMissing'] as $option) {
if (array_key_exists($option, $request_rules[$rule_name])) {
$request_rules[$rule_name][$option] = true;
}
elseif (array_key_exists($option, $rule)) {
$request_rules[$rule_name][$option] = false;
}
}
}
$data['rules'] = $request_rules;
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']
]);
if ($result) {
CPagerHelper::resetPage();
}
}
catch (Exception $e) {
error($e->getMessage());
}
show_messages($result, _('Imported successfully'), _('Import failed'));
}
}
$data['backurl'] = (new CUrl('screenconf.php'))
->setArgument('page', CPagerHelper::loadPage('screenconf.php', null))
->getUrl();
echo (new CView('conf.import', $data))->getOutput();
require_once dirname(__FILE__).'/include/page_footer.php';
|