Source
* Add 'source' property to items ('history' or 'trends'), for the specified time stamp, based on item configuration
<?php declare(strict_types = 0);
/*
** 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 CItemHelper extends CItemGeneralHelper {
/**
* Get item fields default values.
*/
public static function getDefaults(): array {
$general_fields = parent::getDefaults();
return [
'flags' => ZBX_FLAG_DISCOVERY_NORMAL,
'inventory_link' => 0
] + $general_fields;
}
/**
* @param string $src_templateid
* @param array $dst_host
*
* @return bool
*/
public static function cloneTemplateItems(string $src_templateid, array $dst_host): bool {
$src_items = self::getSourceItems([
'templateids' => $src_templateid,
'inherited' => false
]);
$dst_hosts = [$dst_host['templateid'] => $dst_host + ['status' => HOST_STATUS_TEMPLATE]];
return !$src_items || self::copy($src_items, $dst_hosts);
}
/**
* @param string $src_hostid
* @param array $dst_host
*
* @return bool
*/
public static function cloneHostItems(string $src_hostid, array $dst_host): bool {
$src_items = self::getSourceItems([
'hostids' => $src_hostid,
'inherited' => false,
'filter' => ['flags' => ZBX_FLAG_DISCOVERY_NORMAL]
]);
$dst_hosts = [$dst_host['hostid'] => $dst_host];
return !$src_items || self::copy($src_items, $dst_hosts);