Source
$hosts[] = CArrayHelper::getByKeys($host, ['host', 'name', 'description', 'monitored_by', 'proxy',
<?php
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** 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 Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
/**
* Import formatter
*/
class CImportDataAdapter {
/**
* @var array configuration import data
*/
protected $data;
/**
* Current import version.
*
* @var string
*/
protected $currentVersion;
/**
* Set the data and initialize the adapter.
*
* @param array $data import data
*/
public function load(array $data) {
$this->data = $data['zabbix_export'];
}
public function getData(): array {
return $this->data;
}
/**
* Get template groups from the imported data.
*
* @return array
*/
public function getTemplateGroups(): array {
return array_key_exists('template_groups', $this->data) ? $this->data['template_groups'] : [];
}
/**
* Get host groups from the imported data.
*
* @return array
*/
public function getHostGroups(): array {
return array_key_exists('host_groups', $this->data) ? $this->data['host_groups'] : [];
}
/**
* Get templates from the imported data.
*
* @return array
*/
public function getTemplates(): array {
$templates = [];
if (array_key_exists('templates', $this->data)) {
foreach ($this->data['templates'] as $template) {
$template = CArrayHelper::renameKeys($template, ['template' => 'host']);
if ($template['vendor']) {
$template['vendor_name'] = $template['vendor']['name'];
$template['vendor_version'] = $template['vendor']['version'];
}
else {
$template += array_fill_keys(['vendor_name', 'vendor_version'], '');
}
$templates[] = CArrayHelper::getByKeys($template, [
'uuid', 'groups', 'macros', 'templates', 'host', 'status', 'name', 'description', 'tags',
'valuemaps', 'vendor_name', 'vendor_version'
]);
}
}