Source
* For each host interface an unique reference must be created and then added for all items, discovery rules
<?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/>.
**/
class CConfigurationExportBuilder {
/**
* @var array
*/
protected $data = [];
/**
* @param $version current export version
*/
public function __construct() {
$this->data['version'] = ZABBIX_EXPORT_VERSION;
}
/**
* Get array with formatted export data.
*
* @return array
*/
public function getExport() {
return ['zabbix_export' => $this->data];
}
/**
* Build row structure.
*
* @param array $rule Validation rule for selected tag in 3rd parameter.
* @param array $row Export row.
* @param string $tag Tag name.
* @param string $main_tag Main element (for error reporting).
*
* @throws Exception if row is invalid.
*
* @return mixed
*/
private static function buildArrayRow(array $rule, array $row, string $tag, string $main_tag) {
if (array_key_exists('ex_rules', $rule)) {
$parent_rule = array_intersect_key($rule, array_flip(['ex_default', 'default', 'rule']));
$rule = call_user_func($rule['ex_rules'], $row);
$rule = $parent_rule + $rule;
}
$is_required = (bool) ($rule['type'] & XML_REQUIRED);
$is_string = (bool) ($rule['type'] & XML_STRING);
$is_array = (bool) ($rule['type'] & XML_ARRAY);
$is_indexed_array = (bool) ($rule['type'] & XML_INDEXED_ARRAY);
$has_data = array_key_exists($tag, $row);