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
path: root/src
diff options
context:
space:
mode:
authorAlex Kalimulin <aleksandrs.kalimulins@zabbix.com>2021-05-06 19:50:05 +0300
committerAlex Kalimulin <aleksandrs.kalimulins@zabbix.com>2021-05-06 19:55:39 +0300
commit8d7a7dade0fc041099a1d7966944bfd06b66ba39 (patch)
tree36d175682bd517fc3f9766be7342454c36f97962 /src
parentc06370d30836629fc5c594b54e07512aa43895c6 (diff)
........S. [ZBXNEXT-114] refactored range check, dbupgrade patch; tweaked tests, style
Diffstat (limited to 'src')
-rw-r--r--src/libs/zbxdbupgrade/dbupgrade_5030.c36
-rw-r--r--src/libs/zbxserver/evalfunc.c65
2 files changed, 42 insertions, 59 deletions
diff --git a/src/libs/zbxdbupgrade/dbupgrade_5030.c b/src/libs/zbxdbupgrade/dbupgrade_5030.c
index 7a523a3230e..ba3693caba9 100644
--- a/src/libs/zbxdbupgrade/dbupgrade_5030.c
+++ b/src/libs/zbxdbupgrade/dbupgrade_5030.c
@@ -4664,10 +4664,12 @@ static int DBpatch_5030165(void)
{
return DBdrop_foreign_key("valuemap_mapping", 1);
}
+
static int DBpatch_5030166(void)
{
return DBdrop_index("valuemap_mapping", "valuemap_mapping_1");
}
+
static int DBpatch_5030167(void)
{
return DBcreate_index("valuemap_mapping", "valuemap_mapping_1", "valuemapid,value,type", 1);
@@ -4679,6 +4681,7 @@ static int DBpatch_5030168(void)
return DBadd_foreign_key("valuemap_mapping", 1, &field);
}
+
static int DBpatch_5030169(void)
{
const ZBX_FIELD field = {"sortorder", "0", NULL, NULL, 0, ZBX_TYPE_INT, ZBX_NOTNULL, 0};
@@ -4689,41 +4692,38 @@ static int DBpatch_5030169(void)
static int DBpatch_5030170(void)
{
int ret = SUCCEED;
- zbx_uint64_t valuemap_num, i;
DB_ROW row;
DB_RESULT result;
if (0 == (program_type & ZBX_PROGRAM_TYPE_SERVER))
return ret;
- result = DBselect("select max(valuemapid) from valuemap_mapping");
-
- if (NULL != (row = DBfetch(result)))
- ZBX_DBROW2UINT64(valuemap_num, row[0]);
- else
- valuemap_num = 0;
-
- DBfree_result(result);
+ result = DBselect("select valuemapid from valuemap order by valuemapid asc");
- for (i = 0; i <= valuemap_num; i++)
+ while (NULL != (row = DBfetch(result)))
{
- int j = 0;
+ int i = 0;
char *sql = NULL;
+ zbx_uint64_t valuemapid;
size_t sql_alloc = 0, sql_offset = 0;
+ DB_ROW in_row;
+ DB_RESULT in_result;
+
+ ZBX_DBROW2UINT64(valuemapid, row[0]);
DBbegin_multiple_update(&sql, &sql_alloc, &sql_offset);
- result = DBselect("select valuemap_mappingid"
+ in_result = DBselect("select valuemap_mappingid"
" from valuemap_mapping"
" where valuemapid=" ZBX_FS_UI64
- " order by valuemap_mappingid asc", i);
+ " order by valuemap_mappingid asc", valuemapid);
- while (NULL != (row = DBfetch(result)))
+ while (NULL != (in_row = DBfetch(in_result)))
{
zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset,
"update valuemap_mapping set sortorder=%d where valuemap_mappingid=%s;\n",
- j, row[0]);
- j++;
+ i, in_row[0]);
+ i++;
if (SUCCEED != (ret = DBexecute_overflowed_sql(&sql, &sql_alloc, &sql_offset)))
goto out;
@@ -4734,13 +4734,15 @@ static int DBpatch_5030170(void)
if (16 < sql_offset && ZBX_DB_OK > DBexecute("%s", sql))
ret = FAIL;
out:
- DBfree_result(result);
+ DBfree_result(in_result);
zbx_free(sql);
if (FAIL == ret)
break;
}
+ DBfree_result(result);
+
return ret;
}
#endif
diff --git a/src/libs/zbxserver/evalfunc.c b/src/libs/zbxserver/evalfunc.c
index 62fac88349c..af3bff67ec6 100644
--- a/src/libs/zbxserver/evalfunc.c
+++ b/src/libs/zbxserver/evalfunc.c
@@ -3315,7 +3315,7 @@ static void zbx_valuemaps_free(zbx_valuemaps_t *valuemap)
* *
* Parameters: value - value for replacing *
* max_len - maximal length of output value *
- * valuemaps - vector of vales mapped *
+ * valuemaps - vector of values mapped *
* value_type - type of input value *
* *
* Return value: SUCCEED - evaluated successfully, value contains new value *
@@ -3390,7 +3390,7 @@ static int evaluate_value_by_map(char *value, size_t max_len, zbx_vector_valuema
else if (ZBX_VALUEMAP_TYPE_RANGE == valuemap->type)
{
int num, j;
- char *input_ptr, *range_str;
+ char *input_ptr;
input_ptr = valuemap->value;
@@ -3398,63 +3398,43 @@ static int evaluate_value_by_map(char *value, size_t max_len, zbx_vector_valuema
zbx_trim_str_list(input_ptr, '-');
num = num_param(input_ptr);
+ zabbix_log(LOG_LEVEL_DEBUG, "%s: input_ptr: '%s'", __func__, input_ptr);
+
for (j = 0; j < num; j++)
{
int found = 0;
- char *ptr, *threshold_min, *threshold_max, *delimiter_ptr;
- size_t min_size, max_size;
+ char *ptr, *range_str;
+
+ range_str = ptr = get_param_dyn(input_ptr, j + 1, NULL);
- range_str = get_param_dyn(input_ptr, j + 1, NULL);
- ptr = range_str;
- if (1 < strlen(ptr) && '-' == ptr[0])
+ if (1 < strlen(ptr) && '-' == *ptr)
ptr++;
- do
+ while (NULL != (ptr = strchr(ptr, '-')))
{
- delimiter_ptr = strchr(ptr, '-');
- if (NULL != delimiter_ptr &&
- (delimiter_ptr > ptr && 'e' != delimiter_ptr[-1]))
- {
+ if (ptr > range_str && 'e' != ptr[-1] && 'E' != ptr[-1])
break;
- }
- ptr = delimiter_ptr + 1;
- } while (NULL != delimiter_ptr);
+ ptr++;
+ }
- if (NULL == delimiter_ptr)
+ if (NULL == ptr)
{
- threshold_min = zbx_strdup(NULL, range_str);
- threshold_max = NULL;
+ min = evaluate_string_to_double(range_str);
+ found = ZBX_INFINITY != min && SUCCEED == zbx_double_compare(input_value, min);
}
else
{
- min_size = (size_t)(delimiter_ptr - range_str) + 1;
- max_size = strlen(range_str) - (size_t)(delimiter_ptr - range_str);
- threshold_min = zbx_malloc(NULL, min_size);
- threshold_max = zbx_malloc(NULL, max_size);
- memcpy(threshold_min, range_str, min_size - 1);
- threshold_min[min_size - 1] = '\0';
- memcpy(threshold_max, delimiter_ptr + 1, max_size);
- }
-
- zbx_free(range_str);
-
- if (ZBX_INFINITY != (min = evaluate_string_to_double(threshold_min)) &&
- (NULL == threshold_max || ZBX_INFINITY !=
- (max = evaluate_string_to_double(threshold_max))))
- {
- if (NULL != threshold_max && input_value >= min && input_value <= max)
- {
- found = 1;
- }
- else if (NULL == threshold_max &&
- SUCCEED == zbx_double_compare(input_value, min))
+ *ptr = '\0';
+ min = evaluate_string_to_double(range_str);
+ max = evaluate_string_to_double(ptr + 1);
+ if (ZBX_INFINITY != min && ZBX_INFINITY != max &&
+ input_value >= min && input_value <= max)
{
found = 1;
}
}
- zbx_free(threshold_min);
- zbx_free(threshold_max);
+ zbx_free(range_str);
if (0 != found)
goto map_value;
@@ -3471,7 +3451,7 @@ static int evaluate_value_by_map(char *value, size_t max_len, zbx_vector_valuema
goto map_value;
}
map_value:
- if (0 <= i && i < valuemaps->values_num)
+ if (i < valuemaps->values_num)
{
value_tmp = zbx_dsprintf(NULL, "%s (%s)", valuemap->newvalue, value);
zbx_strlcpy_utf8(value, value_tmp, max_len);
@@ -3482,6 +3462,7 @@ map_value:
return ret;
}
+
/******************************************************************************
* *
* Function: replace_value_by_map *