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:
authorArtjoms Rimdjonoks <artjoms.rimdjonoks@zabbix.com>2020-04-23 15:20:50 +0300
committerArtjoms Rimdjonoks <artjoms.rimdjonoks@zabbix.com>2020-04-23 15:20:50 +0300
commit754a06bcf9ab65c02aed1cb0dbb18b4ac7e7a002 (patch)
treeb32c1d86105dd3cbd361b895d7bfd108531d9755
parentc3a59774f488db4bc97bd0e903ede89206563294 (diff)
........S. [ZBXNEXT-702] remove redundant code
-rw-r--r--.gitignore2
-rw-r--r--include/zbxserver.h4
-rw-r--r--src/libs/zbxdbcache/dbconfig.c7
-rw-r--r--src/libs/zbxdbcache/dbconfig.h4
-rw-r--r--src/libs/zbxdbcache/dbsync.c10
-rw-r--r--src/libs/zbxserver/expression.c19
-rw-r--r--src/zabbix_server/poller/checks_calculated.c18
-rw-r--r--tests/libs/zbxdbcache/Makefile.am10
-rw-r--r--tests/libs/zbxdbcache/zbx_dc_expand_user_macros_in_expression.c (renamed from tests/libs/zbxdbcache/zbx_dc_expand_user_macros_for_triggers_and_calc_items.c)2
-rw-r--r--tests/libs/zbxdbcache/zbx_dc_expand_user_macros_in_expression.yaml (renamed from tests/libs/zbxdbcache/zbx_dc_expand_user_macros_for_triggers_and_calc_items.yaml)0
10 files changed, 22 insertions, 54 deletions
diff --git a/.gitignore b/.gitignore
index fba31174e9d..d21a22d54fd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -132,7 +132,7 @@ tests/libs/zbxdbcache/is_item_processed_by_server
tests/libs/zbxdbcache/zbx_vc_add_values
tests/libs/zbxdbcache/zbx_vc_get_value
tests/libs/zbxdbcache/zbx_vc_get_values
-tests/libs/zbxdbcache/zbx_dc_expand_user_macros_for_triggers_and_calc_items
+tests/libs/zbxdbcache/zbx_dc_expand_user_macros_in_expression
tests/libs/zbxdbhigh/DBadd_condition_alloc
tests/libs/zbxdbhigh/DBselect_uint64
tests/libs/zbxhistory/zbx_history_get_values
diff --git a/include/zbxserver.h b/include/zbxserver.h
index 4fa19aa297d..4b0a2259930 100644
--- a/include/zbxserver.h
+++ b/include/zbxserver.h
@@ -32,7 +32,6 @@
#define MACRO_TYPE_TRIGGER_DESCRIPTION 0x00000010 /* name */
#define MACRO_TYPE_TRIGGER_COMMENTS 0x00000020 /* description */
#define MACRO_TYPE_ITEM_KEY 0x00000040
-#define MACRO_TYPE_ITEM_EXPRESSION 0x00000080
#define MACRO_TYPE_INTERFACE_ADDR 0x00000100
#define MACRO_TYPE_COMMON 0x00000400
#define MACRO_TYPE_PARAMS_FIELD 0x00000800
@@ -55,8 +54,7 @@
#define STR_CONTAINS_MACROS(str) (NULL != strchr(str, '{'))
-char *zbx_dc_expand_user_macros_for_triggers_and_calc_items(const char *text, zbx_uint64_t *hostids,
- int hostids_num);
+char *zbx_dc_expand_user_macros_in_expression(const char *text, zbx_uint64_t *hostids, int hostids_num);
int get_N_functionid(const char *expression, int N_functionid, zbx_uint64_t *functionid, const char **end);
void get_functionids(zbx_vector_uint64_t *functionids, const char *expression);
diff --git a/src/libs/zbxdbcache/dbconfig.c b/src/libs/zbxdbcache/dbconfig.c
index 0a3c7d95bd7..0b717c590b4 100644
--- a/src/libs/zbxdbcache/dbconfig.c
+++ b/src/libs/zbxdbcache/dbconfig.c
@@ -9669,7 +9669,7 @@ char *zbx_dc_expand_user_macros(const char *text, zbx_uint64_t *hostids, int hos
/******************************************************************************
* *
- * Function: zbx_dc_expand_user_macros_for_triggers_and_calc_items *
+ * Function: zbx_dc_expand_user_macros_in_expression *
* *
* Purpose: expand user macros for triggers and calculated items in the *
* specified text value and autoquote macros that are not already *
@@ -9683,10 +9683,9 @@ char *zbx_dc_expand_user_macros(const char *text, zbx_uint64_t *hostids, int hos
* macros will be left unresolved. *
* *
* Comments: The returned value must be freed by the caller. *
- * This function must be used only by configuration syncer *
* *
******************************************************************************/
-char *zbx_dc_expand_user_macros_for_triggers_and_calc_items(const char *text, zbx_uint64_t *hostids, int hostids_num)
+char *zbx_dc_expand_user_macros_in_expression(const char *text, zbx_uint64_t *hostids, int hostids_num)
{
zbx_token_t token;
int pos = 0, last_pos = 0, cur_token_inside_quote = 0, prev_token_loc_r = -1, len;
@@ -9808,7 +9807,7 @@ static char *dc_expression_expand_user_macros(const char *expression)
get_functionids(&functionids, expression);
zbx_dc_get_hostids_by_functionids(functionids.values, functionids.values_num, &hostids);
- out = zbx_dc_expand_user_macros_for_triggers_and_calc_items(expression, hostids.values, hostids.values_num);
+ out = zbx_dc_expand_user_macros_in_expression(expression, hostids.values, hostids.values_num);
if (NULL != strstr(out, "{$"))
{
diff --git a/src/libs/zbxdbcache/dbconfig.h b/src/libs/zbxdbcache/dbconfig.h
index 5cf1b43639f..b2223379ff9 100644
--- a/src/libs/zbxdbcache/dbconfig.h
+++ b/src/libs/zbxdbcache/dbconfig.h
@@ -842,8 +842,8 @@ extern zbx_rwlock_t config_lock;
* *
* zbx_dc_expand_user_macros - has no autoquoting *
* for triggers and calculated items use *
- * zbx_dc_expand_user_macros_for_triggers_and_calc_items - which autoquotes *
- * macros that are not already quoted and cannot be casted to a double *
+ * zbx_dc_expand_user_macros_in_expression - which autoquotes macros that are *
+ * not already quoted and cannot be casted to a double *
* *
******************************************************************************/
char *zbx_dc_expand_user_macros(const char *text, zbx_uint64_t *hostids, int hostids_num);
diff --git a/src/libs/zbxdbcache/dbsync.c b/src/libs/zbxdbcache/dbsync.c
index a8ab6fb42e7..d617e412da1 100644
--- a/src/libs/zbxdbcache/dbsync.c
+++ b/src/libs/zbxdbcache/dbsync.c
@@ -2116,16 +2116,10 @@ static char **dbsync_trigger_preproc_row(char **row)
/* expand user macros */
if (0 != (flags & ZBX_DBSYNC_TRIGGER_COLUMN_EXPRESSION))
- {
- row[2] = zbx_dc_expand_user_macros_for_triggers_and_calc_items(row[2], hostids.values,
- hostids.values_num);
- }
+ row[2] = zbx_dc_expand_user_macros_in_expression(row[2], hostids.values, hostids.values_num);
if (0 != (flags & ZBX_DBSYNC_TRIGGER_COLUMN_RECOVERY_EXPRESSION))
- {
- row[11] = zbx_dc_expand_user_macros_for_triggers_and_calc_items(row[11], hostids.values,
- hostids.values_num);
- }
+ row[11] = zbx_dc_expand_user_macros_in_expression(row[11], hostids.values, hostids.values_num);
zbx_vector_uint64_destroy(&functionids);
zbx_vector_uint64_destroy(&hostids);
diff --git a/src/libs/zbxserver/expression.c b/src/libs/zbxserver/expression.c
index 6a1b61a8a7c..bbf6d11328f 100644
--- a/src/libs/zbxserver/expression.c
+++ b/src/libs/zbxserver/expression.c
@@ -2822,7 +2822,7 @@ static int substitute_simple_macros_impl(zbx_uint64_t *actionid, const DB_EVENT
{
char c, *replace_to = NULL, sql[64];
const char *m;
- int N_functionid, indexed_macro, require_numeric, require_address, ret, res = SUCCEED,
+ int N_functionid, indexed_macro, require_address, ret, res = SUCCEED,
pos = 0, found,
raw_value;
size_t data_alloc, data_len;
@@ -2856,7 +2856,6 @@ static int substitute_simple_macros_impl(zbx_uint64_t *actionid, const DB_EVENT
found = zbx_token_find(*data, pos, &token, token_search))
{
indexed_macro = 0;
- require_numeric = 0;
require_address = 0;
N_functionid = 1;
raw_value = 0;
@@ -4232,15 +4231,6 @@ static int substitute_simple_macros_impl(zbx_uint64_t *actionid, const DB_EVENT
pos = token.loc.r;
}
}
- else if (0 != (macro_type & MACRO_TYPE_ITEM_EXPRESSION))
- {
- if (ZBX_TOKEN_USER_MACRO == token.type)
- {
- require_numeric = 1;
- DCget_user_macro(&dc_host->hostid, 1, m, &replace_to);
- pos = token.loc.r;
- }
- }
else if (0 == indexed_macro && 0 != (macro_type & MACRO_TYPE_SCRIPT))
{
if (ZBX_TOKEN_USER_MACRO == token.type)
@@ -4551,12 +4541,7 @@ static int substitute_simple_macros_impl(zbx_uint64_t *actionid, const DB_EVENT
if (NULL != replace_to)
{
- if (1 == require_numeric)
- {
- if (SUCCEED == is_double_suffix(replace_to, ZBX_FLAG_DOUBLE_SUFFIX))
- wrap_negative_double_suffix(&replace_to, NULL);
- }
- else if (1 == require_address && NULL != strstr(replace_to, "{$"))
+ if (1 == require_address && NULL != strstr(replace_to, "{$"))
{
/* Macros should be already expanded. An unexpanded user macro means either unknown */
/* macro or macro value validation failure. */
diff --git a/src/zabbix_server/poller/checks_calculated.c b/src/zabbix_server/poller/checks_calculated.c
index 3ed98c00bdc..e759710ceab 100644
--- a/src/zabbix_server/poller/checks_calculated.c
+++ b/src/zabbix_server/poller/checks_calculated.c
@@ -86,10 +86,9 @@ static int calcitem_add_function(expression_t *exp, char *host, char *key, char
static int calcitem_parse_expression(DC_ITEM *dc_item, expression_t *exp, char *error, int max_error_len)
{
- char *e, *buf = NULL;
- size_t exp_alloc = 128, exp_offset = 0, f_pos, par_l, par_r;
- int ret = NOTSUPPORTED;
- zbx_vector_uint64_t hostids;
+ char *e, *buf = NULL;
+ size_t exp_alloc = 128, exp_offset = 0, f_pos, par_l, par_r;
+ int ret = NOTSUPPORTED;
zabbix_log(LOG_LEVEL_DEBUG, "In %s() expression:'%s'", __func__, dc_item->params);
@@ -153,18 +152,11 @@ static int calcitem_parse_expression(DC_ITEM *dc_item, expression_t *exp, char *
zabbix_log(LOG_LEVEL_DEBUG, "%s() expression:'%s'", __func__, exp->exp);
- zbx_vector_uint64_create(&hostids);
- zbx_vector_uint64_append(&hostids, dc_item->host.hostid);
- exp->exp = zbx_dc_expand_user_macros_for_triggers_and_calc_items(exp->exp, hostids.values, 1);
+ exp->exp = zbx_dc_expand_user_macros_in_expression(exp->exp, &dc_item->host.hostid, 1);
- if (SUCCEED == substitute_simple_macros(NULL, NULL, NULL, NULL, NULL, &dc_item->host, NULL, NULL, NULL,
- &exp->exp, MACRO_TYPE_ITEM_EXPRESSION, error, max_error_len))
- {
- ret = SUCCEED;
- }
+ ret = SUCCEED;
out:
zbx_free(buf);
- zbx_vector_uint64_destroy(&hostids);
zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __func__, zbx_result_string(ret));
diff --git a/tests/libs/zbxdbcache/Makefile.am b/tests/libs/zbxdbcache/Makefile.am
index ed972d40a81..519d45d11ee 100644
--- a/tests/libs/zbxdbcache/Makefile.am
+++ b/tests/libs/zbxdbcache/Makefile.am
@@ -7,7 +7,7 @@ SERVER_tests = \
dc_check_maintenance_period \
is_item_processed_by_server \
dc_item_poller_type_update \
- zbx_dc_expand_user_macros_for_triggers_and_calc_items
+ zbx_dc_expand_user_macros_in_expression
endif
noinst_PROGRAMS = $(SERVER_tests)
@@ -148,12 +148,12 @@ dc_item_poller_type_update_LDADD = $(CACHE_LIBS) @SERVER_LIBS@
dc_item_poller_type_update_LDFLAGS = @SERVER_LDFLAGS@
dc_item_poller_type_update_CFLAGS = -I@top_srcdir@/tests -I@top_srcdir@/src/libs/zbxdbcache
-zbx_dc_expand_user_macros_for_triggers_and_calc_items_CFLAGS = \
+zbx_dc_expand_user_macros_in_expression_CFLAGS = \
-I@top_srcdir@/tests \
-I@top_srcdir@/src/libs/zbxdbcache \
-Wl,--wrap=zbx_hashset_search
-zbx_dc_expand_user_macros_for_triggers_and_calc_items_SOURCES = zbx_dc_expand_user_macros_for_triggers_and_calc_items.c
-zbx_dc_expand_user_macros_for_triggers_and_calc_items_LDADD = $(CACHE_LIBS) @SERVER_LIBS@
-zbx_dc_expand_user_macros_for_triggers_and_calc_items_LDFLAGS = @SERVER_LDFLAGS@
+zbx_dc_expand_user_macros_in_expression_SOURCES = zbx_dc_expand_user_macros_in_expression.c
+zbx_dc_expand_user_macros_in_expression_LDADD = $(CACHE_LIBS) @SERVER_LIBS@
+zbx_dc_expand_user_macros_in_expression_LDFLAGS = @SERVER_LDFLAGS@
endif
diff --git a/tests/libs/zbxdbcache/zbx_dc_expand_user_macros_for_triggers_and_calc_items.c b/tests/libs/zbxdbcache/zbx_dc_expand_user_macros_in_expression.c
index a0db7b6fe09..4312f74e6cc 100644
--- a/tests/libs/zbxdbcache/zbx_dc_expand_user_macros_for_triggers_and_calc_items.c
+++ b/tests/libs/zbxdbcache/zbx_dc_expand_user_macros_in_expression.c
@@ -154,7 +154,7 @@ void zbx_mock_test_entry(void **state)
/* the macro expansion relies on wrapped zbx_hashset_search which returns mocked */
/* macros when used with global macro index hashset */
- returned_expression = zbx_dc_expand_user_macros_for_triggers_and_calc_items(expression, NULL, 0);
+ returned_expression = zbx_dc_expand_user_macros_in_expression(expression, NULL, 0);
zbx_mock_assert_str_eq("Expanded expression", expected_expression, returned_expression);
zbx_free(returned_expression);
diff --git a/tests/libs/zbxdbcache/zbx_dc_expand_user_macros_for_triggers_and_calc_items.yaml b/tests/libs/zbxdbcache/zbx_dc_expand_user_macros_in_expression.yaml
index f0d195176fd..f0d195176fd 100644
--- a/tests/libs/zbxdbcache/zbx_dc_expand_user_macros_for_triggers_and_calc_items.yaml
+++ b/tests/libs/zbxdbcache/zbx_dc_expand_user_macros_in_expression.yaml