Source
xxxxxxxxxx
protected static function getItemMacros(array $macros, array $macro_values, array $triggers = [], array $options = []) {
<?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 CMacrosResolverGeneral {
/**
* Interface priorities.
*
* @var array
*/
protected const interfacePriorities = [
INTERFACE_TYPE_AGENT => 4,
INTERFACE_TYPE_SNMP => 3,
INTERFACE_TYPE_JMX => 2,
INTERFACE_TYPE_IPMI => 1
];
protected const aggr_triggers_macros = ['{TRIGGER.EVENTS.ACK}', '{TRIGGER.EVENTS.PROBLEM.ACK}',
'{TRIGGER.EVENTS.PROBLEM.UNACK}', '{TRIGGER.EVENTS.UNACK}', '{TRIGGER.PROBLEM.EVENTS.PROBLEM.ACK}',
'{TRIGGER.PROBLEM.EVENTS.PROBLEM.UNACK}', '{TRIGGERS.UNACK}', '{TRIGGERS.PROBLEM.UNACK}', '{TRIGGERS.ACK}',
'{TRIGGERS.PROBLEM.ACK}'];
/**
* Get reference macros for trigger.
* If macro reference non existing value it expands to empty string.
*
* @param string $expression
* @param array $references
*
* @return array
*/
protected static function resolveTriggerReferences($expression, $references) {
$values = [];
$expression_parser = new CExpressionParser([
'usermacros' => true,
'lldmacros' => true,
'collapsed_expression' => true
]);
if ($expression_parser->parse($expression) == CParser::PARSE_SUCCESS) {
foreach ($expression_parser->getResult()->getTokens() as $token) {
switch ($token['type']) {
case CExpressionParserResult::TOKEN_TYPE_NUMBER:
case CExpressionParserResult::TOKEN_TYPE_USER_MACRO:
$values[] = $token['match'];
break;
case CExpressionParserResult::TOKEN_TYPE_STRING:
$values[] = CExpressionParser::unquoteString($token['match']);
break;