static int trapper_expressions_evaluate_run(const struct zbx_json_parse *jp, struct zbx_json *json, char **error)
#include "trapper_expressions_evaluate.h"
#include "zbxcommshigh.h"
static int trapper_parse_expressions_evaluate(const struct zbx_json_parse *jp, zbx_vector_str_t *expressions,
char buffer[MAX_STRING_LEN];
struct zbx_json_parse jp_data, jp_expressions;
if (FAIL == zbx_get_user_from_json(jp, &user, NULL) || USER_TYPE_ZABBIX_ADMIN > user.type)
*error = zbx_strdup(NULL, "Permission denied.");
if (FAIL == zbx_json_brackets_by_name(jp, ZBX_PROTO_TAG_DATA, &jp_data))
*error = zbx_strdup(NULL, "Missing data field.");
if (FAIL == zbx_json_brackets_by_name(&jp_data, ZBX_PROTO_TAG_EXPRESSIONS, &jp_expressions))
*error = zbx_strdup(NULL, "Missing expressions field.");
for (ptr = NULL; NULL != (ptr = zbx_json_next_value(&jp_expressions, ptr, buffer, sizeof(buffer), NULL));)
zbx_vector_str_append(expressions, zbx_strdup(NULL, buffer));
static int trapper_expression_evaluate(const char *expression, const zbx_timespec_t *ts, double *result,
if (SUCCEED != zbx_eval_parse_expression(&ctx, expression, ZBX_EVAL_PARSE_TRIGGER_EXPRESSION, error))
if (SUCCEED == (ret = zbx_eval_execute(&ctx, ts, &value, error)))
if (SUCCEED == zbx_variant_convert(&value, ZBX_VARIANT_DBL))
*result = value.data.dbl;
*error = zbx_dsprintf(NULL, "invalid result \"%s\" of type \"%s\"",
zbx_variant_value_desc(&value), zbx_variant_type_desc(&value));
zbx_variant_clear(&value);