Source
DBexecute("INSERT INTO history (itemid, clock, value, ns) VALUES (".zbx_dbstr(self::$data['itemids']['last']).
<?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/>.
**/
require_once dirname(__FILE__).'/../include/CWebTest.php';
/**
* @onBefore prepareItemsData, prepareMapsData, writeValuesToItems
*
* @onAfter clearData
*/
class testExpandExpressionMacros extends CWebTest {
protected static $data = [
'hostgroupid',
'hostids' => [
'last' => null,
'avg' => null,
'min' => null,
'max' => null
],
'itemids' => [
'last' => null,
'avg' => null,
'min' => null,
'max' => null
],
'mapid'
];
public function prepareItemsData() {
// Create hostgroup for hosts with items and graphs.
$hostgroups = CDataHelper::call('hostgroup.create', [
[
'name' => 'Group for macro expand testing'
]
]);
$this->assertArrayHasKey('groupids', $hostgroups);
self::$data['hostgroupid'] = $hostgroups['groupids'][0];
// Create hosts for items and graphs.
$hosts_data = [];
foreach (['Last', 'Avg', 'Min', 'Max'] as $type) {
$hosts_data[] = [
'host' => 'Host for expression macro '.$type,
'groups' => [
['groupid' => self::$data['hostgroupid']]
]
];
}
$hosts = CDataHelper::call('host.create', $hosts_data);
$this->assertArrayHasKey('hostids', $hosts);
$hostids = CDataHelper::getIds('host');
self::$data['hostids']['last'] = $hostids['Host for expression macro Last'];
self::$data['hostids']['avg'] = $hostids['Host for expression macro Avg'];
self::$data['hostids']['min'] = $hostids['Host for expression macro Min'];
self::$data['hostids']['max'] = $hostids['Host for expression macro Max'];
// Create items on previously created hosts.
$items_data = [];
foreach ($hostids as $hostid) {
$items_data[] = [
'hostid' => $hostid,
'name' => 'trapper',
'key_' => 'trapper',
'type' => 2,
'value_type' => 0
];
}
$items = CDataHelper::call('item.create', $items_data);
self::$data['itemids']['last'] = $items['itemids'][0];
self::$data['itemids']['avg'] = $items['itemids'][1];
self::$data['itemids']['min'] = $items['itemids'][2];
self::$data['itemids']['max'] = $items['itemids'][3];
// Create graphs with expression macros in names.