From 3b3bcb51117fa60afe901de4a20a373e4e8bde13 Mon Sep 17 00:00:00 2001 From: Andris Zeila Date: Mon, 22 Oct 2018 12:59:38 +0000 Subject: ........S. [ZBXNEXT-4724] reworked preprocessing step history storage to support multiple history based steps --- .../zabbix_server/preprocessor/zbx_item_preproc.c | 44 ++++++++++++++++------ .../preprocessor/zbx_item_preproc.yaml | 30 +++++++++++++++ 2 files changed, 63 insertions(+), 11 deletions(-) (limited to 'tests/zabbix_server') diff --git a/tests/zabbix_server/preprocessor/zbx_item_preproc.c b/tests/zabbix_server/preprocessor/zbx_item_preproc.c index 42eef3902e2..8c5dd999295 100644 --- a/tests/zabbix_server/preprocessor/zbx_item_preproc.c +++ b/tests/zabbix_server/preprocessor/zbx_item_preproc.c @@ -90,13 +90,13 @@ static int str_to_preproc_error_handler(const char *str) return FAIL; } -static void read_value(const char *path, unsigned char *value_type, zbx_timespec_t *ts, - zbx_variant_t *value) +static void read_value(const char *path, unsigned char *value_type, zbx_variant_t *value, zbx_timespec_t *ts) { zbx_mock_handle_t handle; handle = zbx_mock_get_parameter_handle(path); - *value_type = zbx_mock_str_to_value_type(zbx_mock_get_object_member_string(handle, "value_type")); + if (NULL != value_type) + *value_type = zbx_mock_str_to_value_type(zbx_mock_get_object_member_string(handle, "value_type")); zbx_strtime_to_timespec(zbx_mock_get_object_member_string(handle, "time"), ts); zbx_variant_set_str(value, zbx_strdup(NULL, zbx_mock_get_object_member_string(handle, "data"))); } @@ -126,27 +126,30 @@ static void read_step(const char *path, zbx_preproc_op_t *op) void zbx_mock_test_entry(void **state) { - zbx_variant_t value; + zbx_variant_t value, history_value; unsigned char value_type; - zbx_timespec_t ts; - zbx_item_history_value_t history, *phistory = NULL; + zbx_timespec_t ts, history_ts, expected_history_ts; zbx_preproc_op_t op; int returned_ret, expected_ret; char *error = NULL; ZBX_UNUSED(state); - read_value("in.value", &value_type, &ts, &value); + read_value("in.value", &value_type, &value, &ts); read_step("in.step", &op); if (ZBX_MOCK_SUCCESS == zbx_mock_parameter_exists("in.history")) { - history.itemid = 0; - read_value("in.history", &history.value_type, &history.timestamp, &history.value); - phistory = &history; + read_value("in.history", NULL, &history_value, &history_ts); + } + else + { + zbx_variant_set_none(&history_value); + history_ts.sec = 0; + history_ts.ns = 0; } - returned_ret = zbx_item_preproc(0, value_type, &value, &ts, &op, phistory, &error); + returned_ret = zbx_item_preproc(0, value_type, &value, &ts, &op, &history_value, &history_ts, &error); expected_ret = zbx_mock_str_to_return_code(zbx_mock_get_parameter_string("out.return")); zbx_mock_assert_result_eq("zbx_item_preproc() return", expected_ret, returned_ret); @@ -167,6 +170,25 @@ void zbx_mock_test_entry(void **state) if (ZBX_VARIANT_NONE != value.type) fail_msg("expected empty value, but got %s", zbx_variant_value_desc(&value)); } + + if (ZBX_MOCK_SUCCESS == zbx_mock_parameter_exists("out.history")) + { + if (ZBX_VARIANT_NONE == history_value.type) + fail_msg("preprocessing history was empty value"); + + zbx_variant_convert(&history_value, ZBX_VARIANT_STR); + del_zeros(history_value.data.str); + zbx_mock_assert_str_eq("preprocessing step history value", + zbx_mock_get_parameter_string("out.history.data"), history_value.data.str); + + zbx_strtime_to_timespec(zbx_mock_get_parameter_string("out.history.time"), &expected_history_ts); + zbx_mock_assert_timespec_eq("preprocessing step history time", &expected_history_ts, &history_ts); + } + else + { + if (ZBX_VARIANT_NONE != history_value.type) + fail_msg("expected empty value, but got %s", zbx_variant_value_desc(&history_value)); + } } if (FAIL == returned_ret && ZBX_MOCK_SUCCESS == zbx_mock_parameter_exists("out.error")) diff --git a/tests/zabbix_server/preprocessor/zbx_item_preproc.yaml b/tests/zabbix_server/preprocessor/zbx_item_preproc.yaml index d1c5f09ca4f..127ccbe057b 100644 --- a/tests/zabbix_server/preprocessor/zbx_item_preproc.yaml +++ b/tests/zabbix_server/preprocessor/zbx_item_preproc.yaml @@ -577,6 +577,9 @@ in: out: return: SUCCEED value: 5 + history: + data: 10 + time: 2017-10-29 03:15:00 +03:00 --- test case: deltavalue(-4.5, 5.5) in: @@ -593,6 +596,9 @@ in: out: return: SUCCEED value: 10 + history: + time: 2017-10-29 03:15:00 +03:00 + data: 5.5 --- test case: deltavalue(10, 10) in: @@ -609,6 +615,9 @@ in: out: return: SUCCEED value: 0 + history: + time: 2017-10-29 03:15:00 +03:00 + data: 10 --- test case: deltavalue(10, 9) in: @@ -624,6 +633,9 @@ in: type: ZBX_PREPROC_DELTA_VALUE out: return: SUCCEED + history: + time: 2017-10-29 03:15:00 +03:00 + data: 0 --- test case: deltavalue(0, 1.5) in: @@ -640,6 +652,9 @@ in: out: return: SUCCEED value: 1.5 + history: + time: 2017-10-29 03:15:00 +03:00 + data: 1.5 --- test case: deltaspeed(2, 1, 10s) in: @@ -655,6 +670,9 @@ in: type: ZBX_PREPROC_DELTA_SPEED out: return: SUCCEED + history: + time: 2017-10-29 03:15:00 +03:00 + data: 1 --- test case: deltaspeed(1, 2, -10s) in: @@ -670,6 +688,9 @@ in: type: ZBX_PREPROC_DELTA_SPEED out: return: SUCCEED + history: + time: 2017-10-29 03:15:00 +03:00 + data: 2 --- test case: deltaspeed(1, 2, 10s) in: @@ -686,6 +707,9 @@ in: out: return: SUCCEED value: 0.1 + history: + time: 2017-10-29 03:15:00 +03:00 + data: 2 --- test case: deltaspeed(2, 3, 10s) in: @@ -702,6 +726,9 @@ in: out: return: SUCCEED value: 0 + history: + time: 2017-10-29 03:15:00 +03:00 + data: 3 --- test case: deltaspeed(2, 3, 1s) in: @@ -718,6 +745,9 @@ in: out: return: SUCCEED value: 1 + history: + time: 2017-10-29 03:15:00 +03:00 + data: 3 --- test case: xpath1 in: -- cgit v1.2.3