Source
xxxxxxxxxx
* Check if each particular host reference would be linked through at least one functions according to the new
<?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 to convert calculated item keys.
*/
class C52CalculatedItemConverter extends C52TriggerExpressionConverter {
/**
* Item key parser.
*
* @var CItemKey
*/
protected $item_key_parser;
/**
* Function parser.
*
* @var C10FunctionParser
*/
protected $function_parser;
public function __construct() {
$this->parser = new C10TriggerExpression([
'allow_func_only' => true,
'calculated' => true
]);
$this->item_key_parser = new CItemKey();
$this->function_parser = new C10FunctionParser();
$this->standalone_functions = getStandaloneFunctions();
}
/**
* Convert calculated item formula to 5.4 syntax.
*
* @param string $formula Calculated item formula to convert.
*
* @return string
*/
public function convert($item) {
$expression = preg_replace("/[\\r\\n\\t]/", '', $item['params']);
if ($this->parser->parse($expression) === false) {
return $item;
}
$functions = $this->parser->result->getTokensByType(C10TriggerExprParserResult::TOKEN_TYPE_FUNCTION);
$this->hanged_refs = $this->checkHangedFunctionsPerHost($functions);
for ($i = count($functions) - 1; $i >= 0; $i--) {