Source
unset($trigger['comments'], $trigger['hosts'], $trigger['discoveryRule'], $trigger['flags'], $trigger['state'],
<?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 CTriggerGeneralHelper {
/**
* @param array $src_hosts
* @param string $src_hosts[<src_master_triggerid>][<src_triggerid>] Source host.
* @param array $dst_hosts
* @param array $dst_hosts[<dst_hostid>] Destination host.
*
* @return array [<src_master_triggerid>][<dst_hostid>] = <dst_master_triggerid>
*
* @throws Exception
*/
protected static function getDestinationMasterTriggers(array $src_hosts, array $dst_hosts): array {
if (!$src_hosts) {
return [];
}
$dst_hostids = array_keys($dst_hosts);
$src_master_triggers = API::Trigger()->get([
'output' => ['triggerid', 'description', 'expression', 'recovery_expression'],
'selectHosts' => ['hostid', 'host'],
'triggerids' => array_keys($src_hosts),
'preservekeys' => true
]);
$src_master_triggers = CMacrosResolverHelper::resolveTriggerExpressions($src_master_triggers,
['sources' => ['expression', 'recovery_expression']]
);
$src_descriptions = [];
$dst_master_triggerids = [];
foreach ($src_master_triggers as $src_master_trigger) {
$src_master_trigger_hostids = array_column($src_master_trigger['hosts'], 'hostid');
$src_hostids = [];
foreach ($src_hosts[$src_master_trigger['triggerid']] as $src_host) {
if (in_array($src_host['hostid'], $src_master_trigger_hostids)) {
$src_descriptions[$src_master_trigger['description']] = true;
$src_hostids[$src_host['hostid']] = true;
}
}
if (count($src_hostids) == 1) {
foreach ($dst_hostids as $dst_hostid) {