diff options
author | Andrejs Kozlovs <andrejs.kozlovs@zabbix.com> | 2022-04-27 11:52:01 +0300 |
---|---|---|
committer | Andrejs Kozlovs <andrejs.kozlovs@zabbix.com> | 2022-04-27 11:52:01 +0300 |
commit | 8b793fd1ea026c3801e23522b9dcd5177372bd96 (patch) | |
tree | 87db3c6c4a765fdfaa5d20911ceef6b6079fe12b /src | |
parent | 8d4af0bb9523cb42e26d5b185daae1900a6ce20c (diff) |
.......PS. [ZBXNEXT-7604] fixed after review
Diffstat (limited to 'src')
-rw-r--r-- | src/libs/zbxeval/calc.c | 15 | ||||
-rw-r--r-- | src/libs/zbxprometheus/zbxprometheus.c | 3 |
2 files changed, 14 insertions, 4 deletions
diff --git a/src/libs/zbxeval/calc.c b/src/libs/zbxeval/calc.c index 00b9dd18304..eca034ae5f7 100644 --- a/src/libs/zbxeval/calc.c +++ b/src/libs/zbxeval/calc.c @@ -739,15 +739,26 @@ int zbx_eval_calc_max(zbx_vector_dbl_t *values, double *result, char **error) * * * Parameters: values - [IN] non-empty vector with input data * * result - [OUT] calculated value * + * error - [OUT] dynamically allocated error message * * * ******************************************************************************/ -void zbx_eval_calc_sum(zbx_vector_dbl_t *values, double *result) +int zbx_eval_calc_sum(zbx_vector_dbl_t *values, double *result, char **error) { - double value = 0; + double value; int i; + if (0 == values->values_num) + { + *error = zbx_strdup(*error, "not enough data"); + return FAIL; + } + + value = 0; + for (i = 0; i < values->values_num; i++) value += values->values[i]; *result = value; + + return SUCCEED; } diff --git a/src/libs/zbxprometheus/zbxprometheus.c b/src/libs/zbxprometheus/zbxprometheus.c index 0e3f015317d..14413121b97 100644 --- a/src/libs/zbxprometheus/zbxprometheus.c +++ b/src/libs/zbxprometheus/zbxprometheus.c @@ -1540,8 +1540,7 @@ static int prometheus_aggregate_values(const zbx_vector_ptr_t *rows, const char } else if (0 == strcmp(function, "sum")) { - zbx_eval_calc_sum(&values, &value_dbl); - ret = SUCCEED; + ret = zbx_eval_calc_sum(&values, &value_dbl, error); } else if (0 == strcmp(function, "count")) { |