Source
* 'url' => 'http://zabbix/ui/triggers.php?context=host&filter_hostids[]={HOST.ID1}&filter_hostids[]={HOST.ID2}&filter_set=1'
<?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 CMacrosResolver extends CMacrosResolverGeneral {
/**
* Supported macros resolving scenarios.
*
* @const array
*/
const CONFIGS = [
'httpTestName' => ['host', 'interfaceWithoutPort', 'user'],
'hostInterfaceIpDns' => ['host', 'agentInterface', 'user'],
'hostInterfaceIpDnsAgentPrimary' => ['host', 'user'],
'hostInterfaceDetailsSecurityname' => ['user'],
'hostInterfaceDetailsAuthPassphrase' => ['user'],
'hostInterfaceDetailsPrivPassphrase' => ['user'],
'hostInterfaceDetailsContextName' => ['user'],
'hostInterfaceDetailsCommunity' => ['user'],
'hostInterfacePort' => ['user'],
'widgetURL' => ['host', 'hostId', 'interfaceWithoutPort', 'user'],
'widgetURLUser' => ['user']
];
/**
* Resolve macros with or without macro functions.
*
* Macros examples:
* user: {$MACRO1}, {$MACRO2}, ...
* host: {HOSTNAME}, {HOST.HOST}, {HOST.NAME}
* ip: {IPADDRESS}, {HOST.IP}, {HOST.DNS}, {HOST.CONN}
* item: {ITEM.LASTVALUE}, {ITEM.VALUE}
*
* @param array $options
* @param string $options['config']
* @param array $options['data']
*
* @return array
*/
public static function resolve(array $options) {
return self::resolveTexts($options['data'], self::CONFIGS[$options['config']]);
}
/**
* Batch resolving macros in text using host id.
*
* @param array $data (as $hostid => array(texts))
* @param array $config
*
* @return array (as $hostid => array(texts))
*/
private static function resolveTexts(array $data, array $config) {
$types = [];
if (in_array('host', $config)) {
$types['macros']['host'] = ['{HOSTNAME}', '{HOST.HOST}', '{HOST.NAME}'];
}
if (in_array('hostId', $config)) {
$types['macros']['host'][] = '{HOST.ID}';
}
if (in_array('agentInterface', $config)) {
$types['macros']['interface'] = ['{IPADDRESS}', '{HOST.IP}', '{HOST.DNS}', '{HOST.CONN}'];
}
if (in_array('interfaceWithoutPort', $config)) {
$types['macros']['interface_without_port'] = ['{IPADDRESS}', '{HOST.IP}', '{HOST.DNS}', '{HOST.CONN}'];
}
if (in_array('user', $config)) {
$types['usermacros'] = true;
}
$macro_values = [];
$macros = ['host' => [], 'interface' => [], 'interface_without_port' => [], 'usermacros' => []];
foreach ($data as $hostid => $texts) {
$matched_macros = self::extractMacros($texts, $types);
if (array_key_exists('macros', $matched_macros)) {
foreach ($matched_macros['macros'] as $sub_type => $macro_data) {