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--src/libs/zbxcommon/str.c82
-rw-r--r--src/libs/zbxdbcache/dbconfig.c2
-rw-r--r--tests/libs/zbxcommon/zbx_token_find.yaml81
-rw-r--r--tests/libs/zbxdbcache/dc_function_calculate_nextcheck_test.c2
-rw-r--r--tests/libs/zbxdbhigh/Makefile.am1
-rw-r--r--tests/libs/zbxtrends/zbx_trends_parse_range.yaml9
6 files changed, 145 insertions, 32 deletions
diff --git a/src/libs/zbxcommon/str.c b/src/libs/zbxcommon/str.c
index bda881b3681..377d330dab4 100644
--- a/src/libs/zbxcommon/str.c
+++ b/src/libs/zbxcommon/str.c
@@ -3649,40 +3649,78 @@ static int zbx_token_parse_lld_macro(const char *expression, const char *macro,
static int zbx_token_parse_expression_macro(const char *expression, const char *macro, zbx_token_t *token)
{
const char *ptr;
- size_t level;
size_t offset;
zbx_token_expression_macro_t *data;
+ int quoted = 0;
- /* find the end of expression macro */
- for (ptr = macro + 2, level = 1; '}' != *ptr || 1 != level; ptr++)
+ for (ptr = macro + 2; '\0' != *ptr ; ptr++)
{
- if ('\0' == *ptr)
- return FAIL;
+ if (0 != quoted)
+ {
+ if ('\\' == *ptr)
+ {
+ if ('\0' == *(++ptr))
+ break;
+ continue;
+ }
+
+ if ('"' == *ptr)
+ quoted = 0;
+
+ continue;
+ }
if ('{' == *ptr)
- level++;
+ {
+ zbx_token_t tmp;
- if ('}' == *ptr)
- level--;
- }
+ /* nested expression macros are not supported */
+ if ('?' == ptr[1])
+ continue;
- /* empty macro */
- if (ptr == macro + 2)
- return FAIL;
+ if (SUCCEED == zbx_token_find(ptr, 0, &tmp, ZBX_TOKEN_SEARCH_BASIC))
+ {
+ switch (tmp.type)
+ {
+ case ZBX_TOKEN_LLD_MACRO:
+ ZBX_FALLTHROUGH;
+ case ZBX_TOKEN_LLD_FUNC_MACRO:
+ ZBX_FALLTHROUGH;
+ case ZBX_TOKEN_USER_MACRO:
+ ZBX_FALLTHROUGH;
+ case ZBX_TOKEN_SIMPLE_MACRO:
+ ptr += tmp.loc.r;
+ break;
+ }
+ }
+ }
+ else if ('}' == *ptr)
+ {
- offset = macro - expression;
+ /* empty macro */
+ if (ptr == macro + 2)
+ return FAIL;
- /* initialize token */
- token->type = ZBX_TOKEN_EXPRESSION_MACRO;
- token->loc.l = offset;
- token->loc.r = offset + (ptr - macro);
+ offset = macro - expression;
- /* initialize token data */
- data = &token->data.expression_macro;
- data->expression.l = offset + 2;
- data->expression.r = token->loc.r - 1;
+ /* initialize token */
+ token->type = ZBX_TOKEN_EXPRESSION_MACRO;
+ token->loc.l = offset;
+ token->loc.r = offset + (ptr - macro);
- return SUCCEED;
+ /* initialize token data */
+ data = &token->data.expression_macro;
+ data->expression.l = offset + 2;
+ data->expression.r = token->loc.r - 1;
+
+ return SUCCEED;
+ }
+ else if ('"' == *ptr)
+ quoted = 1;
+
+ }
+
+ return FAIL;
}
/******************************************************************************
diff --git a/src/libs/zbxdbcache/dbconfig.c b/src/libs/zbxdbcache/dbconfig.c
index a15e07e3195..bda4881c639 100644
--- a/src/libs/zbxdbcache/dbconfig.c
+++ b/src/libs/zbxdbcache/dbconfig.c
@@ -8135,7 +8135,7 @@ void zbx_dc_get_trigger_timers(zbx_vector_ptr_t *timers, int now, int soft_limit
* Comments: Triggers are unlocked by DCconfig_unlock_triggers() *
* *
******************************************************************************/
-void dc_reschedule_trigger_timers(zbx_vector_ptr_t *timers)
+static void dc_reschedule_trigger_timers(zbx_vector_ptr_t *timers)
{
int i;
diff --git a/tests/libs/zbxcommon/zbx_token_find.yaml b/tests/libs/zbxcommon/zbx_token_find.yaml
index b3dac6e8c09..55a636f77c6 100644
--- a/tests/libs/zbxcommon/zbx_token_find.yaml
+++ b/tests/libs/zbxcommon/zbx_token_find.yaml
@@ -473,4 +473,85 @@ out:
token_type: ZBX_TOKEN_EXPRESSION_MACRO
expression: '{$VALUE:"context}"}*2'
return: SUCCEED
+---
+test case: 'Failure: {?}'
+in:
+ expression: '{?}'
+out:
+ return: FAIL
+---
+test case: 'Failure: {?"}'
+in:
+ expression: '{?"}'
+out:
+ return: FAIL
+---
+test case: 'Failure: {?"\"}'
+in:
+ expression: '{?"\"}'
+out:
+ return: FAIL
+---
+test case: 'Success: {?"abc"}'
+in:
+ expression: '{?"abc"}'
+out:
+ token: '{?"abc"}'
+ token_type: ZBX_TOKEN_EXPRESSION_MACRO
+ expression: '"abc"'
+ return: SUCCEED
+---
+test case: 'Success: {?"a\"b\"c"}'
+in:
+ expression: '{?"a\"b\"c"}'
+out:
+ token: '{?"a\"b\"c"}'
+ token_type: ZBX_TOKEN_EXPRESSION_MACRO
+ expression: '"a\"b\"c"'
+ return: SUCCEED
+---
+test case: 'Success: {?"}"}'
+in:
+ expression: '{?"}"}'
+out:
+ token: '{?"}"}'
+ token_type: ZBX_TOKEN_EXPRESSION_MACRO
+ expression: '"}"'
+ return: SUCCEED
+---
+test case: 'Success: {?{?}}'
+in:
+ expression: '{?{?}}'
+out:
+ token: '{?{?}'
+ token_type: ZBX_TOKEN_EXPRESSION_MACRO
+ expression: '{?'
+ return: SUCCEED
+---
+test case: 'Success: {?{host:key.func()}}'
+in:
+ expression: '{?{host:key.func()}}'
+out:
+ token: '{?{host:key.func()}}'
+ token_type: ZBX_TOKEN_EXPRESSION_MACRO
+ expression: '{host:key.func()}'
+ return: SUCCEED
+---
+test case: 'Success: {?{HOST.HOST}}'
+in:
+ expression: '{?{HOST.HOST}}'
+out:
+ token: '{?{HOST.HOST}'
+ token_type: ZBX_TOKEN_EXPRESSION_MACRO
+ expression: '{HOST.HOST'
+ return: SUCCEED
+---
+test case: 'Success: {?{$MACRO}}'
+in:
+ expression: '{?{$MACRO}}'
+out:
+ token: '{?{$MACRO}}'
+ token_type: ZBX_TOKEN_EXPRESSION_MACRO
+ expression: '{$MACRO}'
+ return: SUCCEED
...
diff --git a/tests/libs/zbxdbcache/dc_function_calculate_nextcheck_test.c b/tests/libs/zbxdbcache/dc_function_calculate_nextcheck_test.c
index 018ba0297db..e8689d0ec8d 100644
--- a/tests/libs/zbxdbcache/dc_function_calculate_nextcheck_test.c
+++ b/tests/libs/zbxdbcache/dc_function_calculate_nextcheck_test.c
@@ -1,3 +1,5 @@
+int zbx_dc_function_calculate_nextcheck(const zbx_trigger_timer_t *timer, time_t from, zbx_uint64_t seed);
+
int zbx_dc_function_calculate_nextcheck(const zbx_trigger_timer_t *timer, time_t from, zbx_uint64_t seed)
{
return dc_function_calculate_nextcheck(timer, from, seed);
diff --git a/tests/libs/zbxdbhigh/Makefile.am b/tests/libs/zbxdbhigh/Makefile.am
index 07078f0705f..0aa505b1fc2 100644
--- a/tests/libs/zbxdbhigh/Makefile.am
+++ b/tests/libs/zbxdbhigh/Makefile.am
@@ -16,6 +16,7 @@ COMMON_FLAGS = -I@top_srcdir@/tests
COMMON_LIB = \
$(top_srcdir)/src/libs/zbxserver/libzbxserver.a \
+ $(top_srcdir)/src/libs/zbxtrends/libzbxtrends.a \
$(top_srcdir)/src/libs/zbxhistory/libzbxhistory.a \
$(top_srcdir)/src/libs/zbxmemory/libzbxmemory.a \
$(top_srcdir)/src/libs/zbxexec/libzbxexec.a \
diff --git a/tests/libs/zbxtrends/zbx_trends_parse_range.yaml b/tests/libs/zbxtrends/zbx_trends_parse_range.yaml
index 10219374e6c..852966be369 100644
--- a/tests/libs/zbxtrends/zbx_trends_parse_range.yaml
+++ b/tests/libs/zbxtrends/zbx_trends_parse_range.yaml
@@ -118,15 +118,6 @@ in:
out:
return: FAIL
---
-test case: Invalid period shift 'now/h+1h'
-in:
- period: 1h
- shift: now/h+1h
- timezone: :Europe/Riga
- time: 2020-09-01 00:00:00.000000000 +03:00
-out:
- return: FAIL
----
test case: Valid parameters '1h,now/h-1h'
in:
period: 1h