Source
xxxxxxxxxx
* @param bool $options['events'] (optional) Resolve {ITEM.VALUE} macro using 'clock' and 'ns'
<?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/>.
**/
/**
* Helper class that simplifies working with CMacrosResolver class.
*/
class CMacrosResolverHelper {
/**
* Resolve macros.
*
* @param array $options
*
* @return array
*/
public static function resolve(array $options) {
return CMacrosResolver::resolve($options);
}
/**
* Resolve macros in http test name.
*
* @param int $hostId
* @param string $name
*
* @return string
*/
public static function resolveHttpTestName($hostId, $name) {
$macros = CMacrosResolver::resolve([
'config' => 'httpTestName',
'data' => [$hostId => [$name]]
]);
return $macros[$hostId][0];
}
/**
* Resolve macros in host interfaces.
*
* @param array $interfaces
* @param string $interfaces[n]['hostid']
* @param string $interfaces[n]['type']
* @param string $interfaces[n]['main']
* @param string $interfaces[n]['ip']
* @param string $interfaces[n]['dns']
* @param string $interfaces[n]['port']
* @param array $interfaces[n]['details'] (optional)
* @param string $interfaces[n]['details']['securityname'] (optional)
* @param string $interfaces[n]['details']['authpassphrase'] (optional)
* @param string $interfaces[n]['details']['privpassphrase'] (optional)
* @param string $interfaces[n]['details']['contextname'] (optional)
* @param string $interfaces[n]['details']['community'] (optional)
*
* @return array
*/
public static function resolveHostInterfaces(array $interfaces) {
// agent primary ip and dns
$data = [];
foreach ($interfaces as $interface) {
if ($interface['type'] == INTERFACE_TYPE_AGENT && $interface['main'] == INTERFACE_PRIMARY) {
$data[$interface['hostid']][] = $interface['ip'];
$data[$interface['hostid']][] = $interface['dns'];
}
}
$resolvedData = CMacrosResolver::resolve([
'config' => 'hostInterfaceIpDnsAgentPrimary',
'data' => $data
]);
foreach ($resolvedData as $hostId => $texts) {
$n = 0;
foreach ($interfaces as &$interface) {
if ($interface['type'] == INTERFACE_TYPE_AGENT && $interface['main'] == INTERFACE_PRIMARY
&& $interface['hostid'] == $hostId) {
$interface['ip'] = $texts[$n];
$n++;