Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog.d/bugfix/ZBX-202991
-rw-r--r--ui/app/controllers/CControllerPopupItemTest.php82
-rw-r--r--ui/app/controllers/CControllerPopupItemTestEdit.php37
3 files changed, 78 insertions, 42 deletions
diff --git a/ChangeLog.d/bugfix/ZBX-20299 b/ChangeLog.d/bugfix/ZBX-20299
new file mode 100644
index 00000000000..6669ddc4c00
--- /dev/null
+++ b/ChangeLog.d/bugfix/ZBX-20299
@@ -0,0 +1 @@
+..F....... [ZBX-20299] fixed not detecting user macros by "Test item" dialog if they are used in the calculated item formula (rdetlavs)
diff --git a/ui/app/controllers/CControllerPopupItemTest.php b/ui/app/controllers/CControllerPopupItemTest.php
index c532f15e8ef..0eb6f3d3a6b 100644
--- a/ui/app/controllers/CControllerPopupItemTest.php
+++ b/ui/app/controllers/CControllerPopupItemTest.php
@@ -1057,13 +1057,12 @@ abstract class CControllerPopupItemTest extends CController {
/**
* Resolve macros used in the calculates item formula.
*
- * @param string $formula Calculated item formula.
+ * @param string $formula Calculated item formula.
+ * @param array $macros_posted Macros.
*
- * @return array
+ * @return string
*/
- private function resolveCalcFormulaMacros(string $formula) {
- $macros_posted = $this->getInput('macros', []);
-
+ private function resolveCalcFormulaMacros(string $formula, array $macros_posted): string {
if (!$macros_posted) {
return $formula;
}
@@ -1090,51 +1089,74 @@ abstract class CControllerPopupItemTest extends CController {
CExpressionParserResult::TOKEN_TYPE_STRING,
CExpressionParserResult::TOKEN_TYPE_HIST_FUNCTION
]);
+
foreach ($tokens as $token) {
+ if ($pos_left != $token['pos']) {
+ $expression[] = substr($formula, $pos_left, $token['pos'] - $pos_left);
+ }
+ $pos_left = $token['pos'] + $token['length'];
+
switch ($token['type']) {
case CExpressionParserResult::TOKEN_TYPE_USER_MACRO:
case CExpressionParserResult::TOKEN_TYPE_LLD_MACRO:
- if ($pos_left != $token['pos']) {
- $expression[] = substr($formula, $pos_left, $token['pos'] - $pos_left);
- }
- $pos_left = $token['pos'] + $token['length'];
-
$expression[] = array_key_exists($token['match'], $macros_posted)
? CExpressionParser::quoteString($macros_posted[$token['match']], false)
: $token['match'];
break;
case CExpressionParserResult::TOKEN_TYPE_STRING:
- if ($pos_left != $token['pos']) {
- $expression[] = substr($formula, $pos_left, $token['pos'] - $pos_left);
- }
- $pos_left = $token['pos'] + $token['length'];
-
$string = strtr(CExpressionParser::unquoteString($token['match']), $macros_posted);
$expression[] = CExpressionParser::quoteString($string, false, true);
break;
case CExpressionParserResult::TOKEN_TYPE_HIST_FUNCTION:
- foreach ($token['data']['parameters'][0]['data']['filter']['tokens'] as $filter_token) {
- switch ($filter_token['type']) {
- case CFilterParser::TOKEN_TYPE_USER_MACRO:
- case CFilterParser::TOKEN_TYPE_LLD_MACRO:
- if ($pos_left != $filter_token['pos']) {
- $expression[] = substr($formula, $pos_left, $filter_token['pos'] - $pos_left);
+ $pos_left = $token['pos'];
+
+ foreach ($token['data']['parameters'] as $parameter) {
+ if ($pos_left != $parameter['pos']) {
+ $expression[] = substr($formula, $pos_left, $parameter['pos'] - $pos_left);
+ }
+ $pos_left = $parameter['pos'] + $parameter['length'];
+
+ switch ($parameter['type']) {
+ case CHistFunctionParser::PARAM_TYPE_QUERY:
+ $pos_left = $parameter['pos'];
+
+ foreach ($parameter['data']['filter']['tokens'] as $filter_token) {
+ if ($pos_left != $filter_token['pos']) {
+ $expression[] = substr($formula, $pos_left, $filter_token['pos'] - $pos_left);
+ }
+ $pos_left = $filter_token['pos'] + $filter_token['length'];
+
+ switch ($filter_token['type']) {
+ case CFilterParser::TOKEN_TYPE_USER_MACRO:
+ case CFilterParser::TOKEN_TYPE_LLD_MACRO:
+ $string = strtr($filter_token['match'], $macros_posted);
+ $expression[] = CFilterParser::quoteString($string);
+ break;
+
+ case CFilterParser::TOKEN_TYPE_STRING:
+ $string = strtr(CFilterParser::unquoteString($filter_token['match']),
+ $macros_posted
+ );
+ $expression[] = CFilterParser::quoteString($string);
+ break;
+ }
}
- $pos_left = $filter_token['pos'] + $filter_token['length'];
+ break;
- $string = strtr($filter_token['match'], $macros_posted);
- $expression[] = CFilterParser::quoteString($string);
+ case CHistFunctionParser::PARAM_TYPE_PERIOD:
+ $string = strtr($parameter['match'], $macros_posted);
+ $expression[] = $string;
break;
- case CFilterParser::TOKEN_TYPE_STRING:
- if ($pos_left != $filter_token['pos']) {
- $expression[] = substr($formula, $pos_left, $filter_token['pos'] - $pos_left);
- }
- $pos_left = $filter_token['pos'] + $filter_token['length'];
+ case CHistFunctionParser::PARAM_TYPE_QUOTED:
+ $string = strtr(CFilterParser::unquoteString($parameter['match']), $macros_posted);
+ $expression[] = CFilterParser::quoteString($string);
+ break;
- $string = strtr(CFilterParser::unquoteString($filter_token['match']), $macros_posted);
+ case CHistFunctionParser::PARAM_TYPE_UNQUOTED:
+ $string = strtr($parameter['match'], $macros_posted);
$expression[] = CFilterParser::quoteString($string);
break;
}
diff --git a/ui/app/controllers/CControllerPopupItemTestEdit.php b/ui/app/controllers/CControllerPopupItemTestEdit.php
index 5fa7c2edb26..5abc5d7cc59 100644
--- a/ui/app/controllers/CControllerPopupItemTestEdit.php
+++ b/ui/app/controllers/CControllerPopupItemTestEdit.php
@@ -198,20 +198,33 @@ class CControllerPopupItemTestEdit extends CControllerPopupItemTest {
break;
case CExpressionParserResult::TOKEN_TYPE_HIST_FUNCTION:
- foreach ($token['data']['parameters'][0]['data']['filter']['tokens'] as $filter_token) {
- switch ($filter_token['type']) {
- case CFilterParser::TOKEN_TYPE_USER_MACRO:
- $texts_support_user_macros[] = $filter_token['match'];
+ foreach ($token['data']['parameters'] as $parameter) {
+ switch ($parameter['type']) {
+ case CHistFunctionParser::PARAM_TYPE_QUERY:
+ foreach ($parameter['data']['filter']['tokens'] as $filter_token) {
+ switch ($filter_token['type']) {
+ case CFilterParser::TOKEN_TYPE_USER_MACRO:
+ $texts_support_user_macros[] = $filter_token['match'];
+ break;
+
+ case CFilterParser::TOKEN_TYPE_LLD_MACRO:
+ $texts_support_lld_macros[] = $filter_token['match'];
+ break;
+
+ case CFilterParser::TOKEN_TYPE_STRING:
+ $text = CFilterParser::unquoteString($filter_token['match']);
+ $texts_support_user_macros[] = $text;
+ $texts_support_lld_macros[] = $text;
+ break;
+ }
+ }
break;
- case CFilterParser::TOKEN_TYPE_LLD_MACRO:
- $texts_support_lld_macros[] = $filter_token['match'];
- break;
-
- case CFilterParser::TOKEN_TYPE_STRING:
- $text = CFilterParser::unquoteString($filter_token['match']);
- $texts_support_user_macros[] = $text;
- $texts_support_lld_macros[] = $text;
+ case CHistFunctionParser::PARAM_TYPE_PERIOD:
+ case CHistFunctionParser::PARAM_TYPE_QUOTED:
+ case CHistFunctionParser::PARAM_TYPE_UNQUOTED:
+ $texts_support_user_macros[] = $parameter['match'];
+ $texts_support_lld_macros[] = $parameter['match'] ;
break;
}
}