Source
<?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
]
]
]
]);
$itemid = $hosts['itemids']['Host with widgets items:key[1]'];
$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]'];
$discoveryruleid = $templates['discoveryruleids']['Template for copy widgets:drule'];
$item_protototypes = CDataHelper::call('itemprototype.create', [
[
'hostid' => $templateid,
'ruleid' => $discoveryruleid,
'name' => 'Template item prototype {#KEY}',
'key_' => 'trap[{#KEY}]',
'type' => ITEM_TYPE_TRAPPER,
'value_type' => ITEM_VALUE_TYPE_UINT64,
'delay' => 0
]
]);
$item_prototypeid = $item_protototypes['itemids'][0];
$graph_protototypes = CDataHelper::call('graphprototype.create', [
[
'name' => 'Template graph prototype {#KEY}',
'width' => 600,
'height' => 300,
'gitems' => [['itemid' => $item_prototypeid, 'color' => '3333FF']]
]
]);