Source
xxxxxxxxxx
<?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 CopyWidgetsDashboards {
/**
* Create data for Copy widgets test.
*
* !!! Please, add new widgets to "Dashboard for Copying widgets _2" if necessary.
* If "Dashboard for Copying widgets _2" is run out of space, create new dashboard with this exact name:
* "Dashboard for Copying widgets _3", etc.
* Second page on new dashboard for paste widgets should be named "Test_page".
*
* @return array
*/
public static function load() {
$hosts = CDataHelper::createHosts([
[
'host' => 'Host with widgets items',
'groups' => ['groupid' => 4], // Zabbix servers.
'items' => [
[
'name' => 'Widget item',
'key_' => 'key[1]',
'type' => ITEM_TYPE_TRAPPER,
'value_type' => ITEM_VALUE_TYPE_UINT64
]
]
],
[
'host' => 'Host with map for copy widgets',
'groups' => ['groupid' => CDataHelper::call('hostgroup.create',
[['name' => 'Group with maps for copy']])['groupids'][0]
]
]
]);
$itemid = $hosts['itemids']['Host with widgets items:key[1]'];
$hostid = $hosts['hostids']['Host with map for copy widgets'];
$maps = CDataHelper::call('map.create', [
[
'name' => 'Map for widget copies',
'width' => 500,
'height' => 500,
'selements' => [
[
'elements' => [['hostid' => $hostid]],
'elementtype' => SYSMAP_ELEMENT_TYPE_HOST,
'iconid_off' => 186
]
]
]
]);
$mapid = $maps['sysmapids'][0];
$templates = CDataHelper::createTemplates([
[
'host' => 'Template for copy widgets',
'groups' => ['groupid' => 1], // Templates.
'items' => [
[
'name' => 'Templates widget item',
'key_' => 'templ_key[1]',
'type' => ITEM_TYPE_TRAPPER,
'value_type' => ITEM_VALUE_TYPE_UINT64
]
],
'discoveryrules' => [
[
'name' => 'LLD rule for graph prototype widget',
'key_' => 'drule',
'type' => ITEM_TYPE_TRAPPER,
'delay' => 0
]
]
]
]);
$templateid = $templates['templateids']['Template for copy widgets'];
$template_itemid = $templates['itemids']['Template for copy widgets:templ_key[1]'];