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:
authorAndris Zeila <andris.zeila@zabbix.com>2018-10-19 10:52:10 +0300
committerAndris Zeila <andris.zeila@zabbix.com>2018-10-19 10:52:10 +0300
commit4a41d695e07d9364d1730c8442b7cf0a753ebc0e (patch)
treebc818f881773a154b9ddf59c0fbb9381f7e2ea4d /tests/zabbix_server
parentbdc9ff21f2c7c431700620950365e055ba6130ba (diff)
.......... [ZBXNEXT-4724] added item preprocessing test suite and removed old (cunit) xpath tests
Diffstat (limited to 'tests/zabbix_server')
-rw-r--r--tests/zabbix_server/Makefile.am2
-rw-r--r--tests/zabbix_server/preprocessor/Makefile.am32
-rw-r--r--tests/zabbix_server/preprocessor/zbx_item_preproc.c178
-rw-r--r--tests/zabbix_server/preprocessor/zbx_item_preproc.yaml1132
4 files changed, 1344 insertions, 0 deletions
diff --git a/tests/zabbix_server/Makefile.am b/tests/zabbix_server/Makefile.am
new file mode 100644
index 00000000000..48defec4f66
--- /dev/null
+++ b/tests/zabbix_server/Makefile.am
@@ -0,0 +1,2 @@
+SUBDIRS = \
+ preprocessor
diff --git a/tests/zabbix_server/preprocessor/Makefile.am b/tests/zabbix_server/preprocessor/Makefile.am
new file mode 100644
index 00000000000..372ec85b33b
--- /dev/null
+++ b/tests/zabbix_server/preprocessor/Makefile.am
@@ -0,0 +1,32 @@
+noinst_PROGRAMS = zbx_item_preproc
+
+JSON_LIBS = \
+ $(top_srcdir)/tests/libzbxmocktest.a \
+ $(top_srcdir)/tests/libzbxmockdata.a \
+ $(top_srcdir)/src/libs/zbxjson/libzbxjson.a \
+ $(top_srcdir)/src/libs/zbxalgo/libzbxalgo.a \
+ $(top_srcdir)/src/libs/zbxcommon/libzbxcommon.a \
+ $(top_srcdir)/src/libs/zbxcomms/libzbxcomms.a \
+ $(top_srcdir)/src/libs/zbxcompress/libzbxcompress.a \
+ $(top_srcdir)/src/libs/zbxcommon/libzbxcommon.a \
+ $(top_srcdir)/src/libs/zbxregexp/libzbxregexp.a \
+ $(top_srcdir)/src/libs/zbxnix/libzbxnix.a \
+ $(top_srcdir)/src/libs/zbxcrypto/libzbxcrypto.a \
+ $(top_srcdir)/src/libs/zbxsys/libzbxsys.a \
+ $(top_srcdir)/src/libs/zbxlog/libzbxlog.a \
+ $(top_srcdir)/src/libs/zbxsys/libzbxsys.a \
+ $(top_srcdir)/src/libs/zbxconf/libzbxconf.a \
+ $(top_srcdir)/tests/libzbxmockdata.a
+
+zbx_item_preproc_SOURCES = \
+ ../../../src/zabbix_server/preprocessor/item_preproc.c \
+ zbx_item_preproc.c
+
+zbx_item_preproc_LDADD = $(JSON_LIBS)
+
+if SERVER
+zbx_item_preproc_LDADD += @SERVER_LIBS@
+zbx_item_preproc_LDFLAGS = @SERVER_LDFLAGS@
+endif
+
+zbx_item_preproc_CFLAGS = -I@top_srcdir@/tests @LIBXML2_CFLAGS@
diff --git a/tests/zabbix_server/preprocessor/zbx_item_preproc.c b/tests/zabbix_server/preprocessor/zbx_item_preproc.c
new file mode 100644
index 00000000000..42eef3902e2
--- /dev/null
+++ b/tests/zabbix_server/preprocessor/zbx_item_preproc.c
@@ -0,0 +1,178 @@
+/*
+** Zabbix
+** Copyright (C) 2001-2018 Zabbix SIA
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+**/
+
+#include "zbxmocktest.h"
+#include "zbxmockdata.h"
+#include "zbxmockassert.h"
+#include "zbxmockutil.h"
+
+#include "common.h"
+#include "zbxjson.h"
+#include "dbcache.h"
+
+#include "../../../src/zabbix_server/preprocessor/item_preproc.h"
+
+static int str_to_preproc_type(const char *str)
+{
+ if (0 == strcmp(str, "ZBX_PREPROC_MULTIPLIER"))
+ return ZBX_PREPROC_MULTIPLIER;
+ if (0 == strcmp(str, "ZBX_PREPROC_RTRIM"))
+ return ZBX_PREPROC_RTRIM;
+ if (0 == strcmp(str, "ZBX_PREPROC_LTRIM"))
+ return ZBX_PREPROC_LTRIM;
+ if (0 == strcmp(str, "ZBX_PREPROC_TRIM"))
+ return ZBX_PREPROC_TRIM;
+ if (0 == strcmp(str, "ZBX_PREPROC_REGSUB"))
+ return ZBX_PREPROC_REGSUB;
+ if (0 == strcmp(str, "ZBX_PREPROC_BOOL2DEC"))
+ return ZBX_PREPROC_BOOL2DEC;
+ if (0 == strcmp(str, "ZBX_PREPROC_OCT2DEC"))
+ return ZBX_PREPROC_OCT2DEC;
+ if (0 == strcmp(str, "ZBX_PREPROC_HEX2DEC"))
+ return ZBX_PREPROC_HEX2DEC;
+ if (0 == strcmp(str, "ZBX_PREPROC_DELTA_VALUE"))
+ return ZBX_PREPROC_DELTA_VALUE;
+ if (0 == strcmp(str, "ZBX_PREPROC_DELTA_SPEED"))
+ return ZBX_PREPROC_DELTA_SPEED;
+ if (0 == strcmp(str, "ZBX_PREPROC_XPATH"))
+ return ZBX_PREPROC_XPATH;
+ if (0 == strcmp(str, "ZBX_PREPROC_JSONPATH"))
+ return ZBX_PREPROC_JSONPATH;
+ if (0 == strcmp(str, "ZBX_PREPROC_VALIDATE_RANGE"))
+ return ZBX_PREPROC_VALIDATE_RANGE;
+ if (0 == strcmp(str, "ZBX_PREPROC_VALIDATE_REGEX"))
+ return ZBX_PREPROC_VALIDATE_REGEX;
+ if (0 == strcmp(str, "ZBX_PREPROC_VALIDATE_NOT_REGEX"))
+ return ZBX_PREPROC_VALIDATE_NOT_REGEX;
+ if (0 == strcmp(str, "ZBX_PREPROC_ERROR_FIELD_JSON"))
+ return ZBX_PREPROC_ERROR_FIELD_JSON;
+ if (0 == strcmp(str, "ZBX_PREPROC_ERROR_FIELD_XML"))
+ return ZBX_PREPROC_ERROR_FIELD_XML;
+ if (0 == strcmp(str, "ZBX_PREPROC_ERROR_FIELD_REGEX"))
+ return ZBX_PREPROC_ERROR_FIELD_REGEX;
+ if (0 == strcmp(str, "ZBX_PREPROC_THROTTLE_VALUE"))
+ return ZBX_PREPROC_THROTTLE_VALUE;
+ if (0 == strcmp(str, "ZBX_PREPROC_THROTTLE_TIMED_VALUE"))
+ return ZBX_PREPROC_THROTTLE_TIMED_VALUE;
+
+ fail_msg("unknow preprocessing step type: %s", str);
+ return FAIL;
+}
+
+static int str_to_preproc_error_handler(const char *str)
+{
+ if (0 == strcmp(str, "ZBX_PREPROC_FAIL_DEFAULT"))
+ return ZBX_PREPROC_FAIL_DEFAULT;
+ if (0 == strcmp(str, "ZBX_PREPROC_FAIL_DISCARD_VALUE"))
+ return ZBX_PREPROC_FAIL_DISCARD_VALUE;
+ if (0 == strcmp(str, "ZBX_PREPROC_FAIL_SET_VALUE"))
+ return ZBX_PREPROC_FAIL_SET_VALUE;
+ if (0 == strcmp(str, "ZBX_PREPROC_FAIL_SET_ERROR"))
+ return ZBX_PREPROC_FAIL_SET_ERROR;
+
+ fail_msg("unknow preprocessing error handler: %s", str);
+ return FAIL;
+}
+
+static void read_value(const char *path, unsigned char *value_type, zbx_timespec_t *ts,
+ zbx_variant_t *value)
+{
+ 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"));
+ 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")));
+}
+
+static void read_step(const char *path, zbx_preproc_op_t *op)
+{
+ zbx_mock_handle_t hop, hop_params, herror, herror_params;
+
+ hop = zbx_mock_get_parameter_handle(path);
+ op->type = str_to_preproc_type(zbx_mock_get_object_member_string(hop, "type"));
+
+ if (ZBX_MOCK_SUCCESS == zbx_mock_object_member(hop, "params", &hop_params))
+ op->params = (char *)zbx_mock_get_object_member_string(hop, "params");
+ else
+ op->params = "";
+
+ if (ZBX_MOCK_SUCCESS == zbx_mock_object_member(hop, "error_handler", &herror))
+ op->error_handler = str_to_preproc_error_handler(zbx_mock_get_object_member_string(hop, "error_handler"));
+ else
+ op->error_handler = ZBX_PREPROC_FAIL_DEFAULT;
+
+ if (ZBX_MOCK_SUCCESS == zbx_mock_object_member(hop, "error_handler_params", &herror_params))
+ op->error_handler_params = (char *)zbx_mock_get_object_member_string(hop, "error_handler_params");
+ else
+ op->error_handler_params = "";
+}
+
+void zbx_mock_test_entry(void **state)
+{
+ zbx_variant_t value;
+ unsigned char value_type;
+ zbx_timespec_t ts;
+ zbx_item_history_value_t history, *phistory = NULL;
+ 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_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;
+ }
+
+ returned_ret = zbx_item_preproc(0, value_type, &value, &ts, &op, phistory, &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);
+
+ if (SUCCEED == returned_ret)
+ {
+ if (ZBX_MOCK_SUCCESS == zbx_mock_parameter_exists("out.value"))
+ {
+ if (ZBX_VARIANT_NONE == value.type)
+ fail_msg("preprocessing result was empty value");
+
+ zbx_variant_convert(&value, ZBX_VARIANT_STR);
+ del_zeros(value.data.str);
+ zbx_mock_assert_str_eq("processed value", zbx_mock_get_parameter_string("out.value"),
+ value.data.str);
+ }
+ else
+ {
+ if (ZBX_VARIANT_NONE != value.type)
+ fail_msg("expected empty value, but got %s", zbx_variant_value_desc(&value));
+ }
+ }
+
+ if (FAIL == returned_ret && ZBX_MOCK_SUCCESS == zbx_mock_parameter_exists("out.error"))
+ zbx_mock_assert_str_eq("error message", zbx_mock_get_parameter_string("out.error"), error);
+
+ zbx_variant_clear(&value);
+ zbx_free(error);
+
+}
diff --git a/tests/zabbix_server/preprocessor/zbx_item_preproc.yaml b/tests/zabbix_server/preprocessor/zbx_item_preproc.yaml
new file mode 100644
index 00000000000..8ed7a0f0680
--- /dev/null
+++ b/tests/zabbix_server/preprocessor/zbx_item_preproc.yaml
@@ -0,0 +1,1132 @@
+---
+test case: string(10) * 10
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: 10
+ step:
+ type: ZBX_PREPROC_MULTIPLIER
+ params: 10
+out:
+ return: SUCCEED
+ value: 100
+---
+test case: string(10x) * 10
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: 10x
+ step:
+ type: ZBX_PREPROC_MULTIPLIER
+ params: 10
+out:
+ return: FAIL
+---
+test case: string(10) * abc
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: 10
+ step:
+ type: ZBX_PREPROC_MULTIPLIER
+ params: abc
+out:
+ return: FAIL
+---
+test case: string(1.5) * 3
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: 1.5
+ step:
+ type: ZBX_PREPROC_MULTIPLIER
+ params: 3
+out:
+ return: SUCCEED
+ value: 4.5
+---
+test case: uint64(1.5) * 3
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_UINT64
+ time: 2017-10-29 03:15:00 +03:00
+ data: 1.5
+ step:
+ type: ZBX_PREPROC_MULTIPLIER
+ params: 3
+out:
+ return: SUCCEED
+ value: 3
+---
+test case: uint64(3) * 1.5
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_UINT64
+ time: 2017-10-29 03:15:00 +03:00
+ data: 3
+ step:
+ type: ZBX_PREPROC_MULTIPLIER
+ params: 1.5
+out:
+ return: SUCCEED
+ value: 4
+---
+test case: float(1.5) * 3
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_FLOAT
+ time: 2017-10-29 03:15:00 +03:00
+ data: 1.5
+ step:
+ type: ZBX_PREPROC_MULTIPLIER
+ params: 3
+out:
+ return: SUCCEED
+ value: 4.5
+---
+test case: float(3) * 1.5
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_FLOAT
+ time: 2017-10-29 03:15:00 +03:00
+ data: 3
+ step:
+ type: ZBX_PREPROC_MULTIPLIER
+ params: 1.5
+out:
+ return: SUCCEED
+ value: 4.5
+---
+test case: rtrim(01abc01, 01)
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: 01abc01
+ step:
+ type: ZBX_PREPROC_RTRIM
+ params: 01
+out:
+ return: SUCCEED
+ value: 01abc
+---
+test case: rtrim(01abc01, abc)
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: 01abc01
+ step:
+ type: ZBX_PREPROC_RTRIM
+ params: abc
+out:
+ return: SUCCEED
+ value: 01abc01
+---
+test case: ltrim(01abc01, 01)
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: 01abc01
+ step:
+ type: ZBX_PREPROC_LTRIM
+ params: 01
+out:
+ return: SUCCEED
+ value: abc01
+---
+test case: ltrim(01abc01, abc)
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: 01abc01
+ step:
+ type: ZBX_PREPROC_LTRIM
+ params: abc
+out:
+ return: SUCCEED
+ value: 01abc01
+---
+test case: trim(01abc01, 01)
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: 01abc01
+ step:
+ type: ZBX_PREPROC_TRIM
+ params: 01
+out:
+ return: SUCCEED
+ value: abc
+---
+test case: trim(01abc01, abc)
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: 01abc01
+ step:
+ type: ZBX_PREPROC_TRIM
+ params: abc
+out:
+ return: SUCCEED
+ value: 01abc01
+---
+test case: regsub("test 123 number", "([0-9]+", 1)
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: test 123 number
+ step:
+ type: ZBX_PREPROC_REGSUB
+ params: "([0-9]+\n\\1"
+out:
+ return: FAIL
+---
+test case: regsub("test 123 number", "([0-9]+)", \1)
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: test 123 number
+ step:
+ type: ZBX_PREPROC_REGSUB
+ params: "([0-9]+)\n\\1"
+out:
+ return: SUCCEED
+ value: 123
+---
+test case: regsub("test 123 number", "([0-9]+)", x\1y)
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: test 123 number
+ step:
+ type: ZBX_PREPROC_REGSUB
+ params: "([0-9]+)\nx\\1y"
+out:
+ return: SUCCEED
+ value: x123y
+---
+test case: regsub("test 123 number", "([0-9]+)", )
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: test 123 number
+ step:
+ type: ZBX_PREPROC_REGSUB
+ params: "([0-9]+)"
+out:
+ return: FAIL
+---
+test case: regsub("test abc number", "([0-9]+)", \1)
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: test abc number
+ step:
+ type: ZBX_PREPROC_REGSUB
+ params: "([0-9]+)\n\\1"
+out:
+ return: FAIL
+---
+test case: regsub("", "([0-9]+)", \1)
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data:
+ step:
+ type: ZBX_PREPROC_REGSUB
+ params: "([0-9]+)\n\\1"
+out:
+ return: FAIL
+---
+test case: regsub("", "^$", ok)
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: ""
+ step:
+ type: ZBX_PREPROC_REGSUB
+ params: "^$\nok"
+out:
+ return: SUCCEED
+ value: ok
+---
+test case: bool2dec()
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: ""
+ step:
+ type: ZBX_PREPROC_BOOL2DEC
+out:
+ return: FAIL
+---
+test case: bool2dec(abc)
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: "abc"
+ step:
+ type: ZBX_PREPROC_BOOL2DEC
+out:
+ return: FAIL
+---
+test case: bool2dec(1)
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: "1"
+ step:
+ type: ZBX_PREPROC_BOOL2DEC
+out:
+ return: SUCCEED
+ value: 1
+---
+test case: bool2dec(0)
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: "0"
+ step:
+ type: ZBX_PREPROC_BOOL2DEC
+out:
+ return: SUCCEED
+ value: 0
+---
+test case: bool2dec(true)
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: "true"
+ step:
+ type: ZBX_PREPROC_BOOL2DEC
+out:
+ return: SUCCEED
+ value: 1
+---
+test case: bool2dec(t)
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: "t"
+ step:
+ type: ZBX_PREPROC_BOOL2DEC
+out:
+ return: SUCCEED
+ value: 1
+---
+test case: bool2dec(yes)
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: "yes"
+ step:
+ type: ZBX_PREPROC_BOOL2DEC
+out:
+ return: SUCCEED
+ value: 1
+---
+test case: bool2dec(y)
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: "y"
+ step:
+ type: ZBX_PREPROC_BOOL2DEC
+out:
+ return: SUCCEED
+ value: 1
+---
+test case: bool2dec(ok)
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: "ok"
+ step:
+ type: ZBX_PREPROC_BOOL2DEC
+out:
+ return: SUCCEED
+ value: 1
+---
+test case: bool2dec(on)
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: "on"
+ step:
+ type: ZBX_PREPROC_BOOL2DEC
+out:
+ return: SUCCEED
+ value: 1
+---
+test case: bool2dec(false)
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: "false"
+ step:
+ type: ZBX_PREPROC_BOOL2DEC
+out:
+ return: SUCCEED
+ value: 0
+---
+test case: bool2dec(f)
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: "f"
+ step:
+ type: ZBX_PREPROC_BOOL2DEC
+out:
+ return: SUCCEED
+ value: 0
+---
+test case: bool2dec(no)
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: "no"
+ step:
+ type: ZBX_PREPROC_BOOL2DEC
+out:
+ return: SUCCEED
+ value: 0
+---
+test case: bool2dec(n)
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: "n"
+ step:
+ type: ZBX_PREPROC_BOOL2DEC
+out:
+ return: SUCCEED
+ value: 0
+---
+test case: bool2dec(err)
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: "err"
+ step:
+ type: ZBX_PREPROC_BOOL2DEC
+out:
+ return: SUCCEED
+ value: 0
+---
+test case: bool2dec(off)
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: "off"
+ step:
+ type: ZBX_PREPROC_BOOL2DEC
+out:
+ return: SUCCEED
+ value: 0
+---
+test case: oct2dec(0)
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: 0
+ step:
+ type: ZBX_PREPROC_OCT2DEC
+out:
+ return: SUCCEED
+ value: 0
+---
+test case: oct2dec(7)
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: 7
+ step:
+ type: ZBX_PREPROC_OCT2DEC
+out:
+ return: SUCCEED
+ value: 7
+---
+test case: oct2dec(10)
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: 10
+ step:
+ type: ZBX_PREPROC_OCT2DEC
+out:
+ return: SUCCEED
+ value: 8
+---
+test case: oct2dec(8)
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: 8
+ step:
+ type: ZBX_PREPROC_OCT2DEC
+out:
+ return: FAIL
+---
+test case: hex2dec(F)
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: F
+ step:
+ type: ZBX_PREPROC_HEX2DEC
+out:
+ return: SUCCEED
+ value: 15
+---
+test case: hex2dec(a)
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: a
+ step:
+ type: ZBX_PREPROC_HEX2DEC
+out:
+ return: SUCCEED
+ value: 10
+---
+test case: hex2dec(10)
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: 10
+ step:
+ type: ZBX_PREPROC_HEX2DEC
+out:
+ return: SUCCEED
+ value: 16
+---
+test case: hex2dec(g)
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: g
+ step:
+ type: ZBX_PREPROC_HEX2DEC
+out:
+ return: FAIL
+---
+test case: hex2dec(ff ff)
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: ff ff
+ step:
+ type: ZBX_PREPROC_HEX2DEC
+out:
+ return: SUCCEED
+ value: 65535
+---
+test case: deltavalue(5, 10)
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: 10
+ history:
+ value_type: ITEM_VALUE_TYPE_FLOAT
+ time: 2017-10-29 03:14:00 +03:00
+ data: 5
+ step:
+ type: ZBX_PREPROC_DELTA_VALUE
+out:
+ return: SUCCEED
+ value: 5
+---
+test case: deltavalue(-4.5, 5.5)
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: 5.5
+ history:
+ value_type: ITEM_VALUE_TYPE_FLOAT
+ time: 2017-10-29 03:14:00 +03:00
+ data: -4.5
+ step:
+ type: ZBX_PREPROC_DELTA_VALUE
+out:
+ return: SUCCEED
+ value: 10
+---
+test case: deltavalue(10, 10)
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: 10
+ history:
+ value_type: ITEM_VALUE_TYPE_FLOAT
+ time: 2017-10-29 03:14:00 +03:00
+ data: 10
+ step:
+ type: ZBX_PREPROC_DELTA_VALUE
+out:
+ return: SUCCEED
+ value: 0
+---
+test case: deltavalue(10, 9)
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: 0
+ history:
+ value_type: ITEM_VALUE_TYPE_FLOAT
+ time: 2017-10-29 03:14:00 +03:00
+ data: 10
+ step:
+ type: ZBX_PREPROC_DELTA_VALUE
+out:
+ return: SUCCEED
+---
+test case: deltavalue(0, 1.5)
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: 1.5
+ history:
+ value_type: ITEM_VALUE_TYPE_FLOAT
+ time: 2017-10-29 03:14:00 +03:00
+ data: 0
+ step:
+ type: ZBX_PREPROC_DELTA_VALUE
+out:
+ return: SUCCEED
+ value: 1.5
+---
+test case: deltaspeed(2, 1, 10s)
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: 1
+ history:
+ value_type: ITEM_VALUE_TYPE_FLOAT
+ time: 2017-10-29 03:14:50 +03:00
+ data: 2
+ step:
+ type: ZBX_PREPROC_DELTA_SPEED
+out:
+ return: SUCCEED
+---
+test case: deltaspeed(1, 2, -10s)
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: 2
+ history:
+ value_type: ITEM_VALUE_TYPE_FLOAT
+ time: 2017-10-29 03:15:10 +03:00
+ data: 1
+ step:
+ type: ZBX_PREPROC_DELTA_SPEED
+out:
+ return: SUCCEED
+---
+test case: deltaspeed(1, 2, 10s)
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_FLOAT
+ time: 2017-10-29 03:15:00 +03:00
+ data: 2
+ history:
+ value_type: ITEM_VALUE_TYPE_FLOAT
+ time: 2017-10-29 03:14:50 +03:00
+ data: 1
+ step:
+ type: ZBX_PREPROC_DELTA_SPEED
+out:
+ return: SUCCEED
+ value: 0.1
+---
+test case: deltaspeed(2, 3, 10s)
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_UINT64
+ time: 2017-10-29 03:15:00 +03:00
+ data: 3
+ history:
+ value_type: ITEM_VALUE_TYPE_UINT64
+ time: 2017-10-29 03:14:50 +03:00
+ data: 2
+ step:
+ type: ZBX_PREPROC_DELTA_SPEED
+out:
+ return: SUCCEED
+ value: 0
+---
+test case: deltaspeed(2, 3, 1s)
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_UINT64
+ time: 2017-10-29 03:15:00 +03:00
+ data: 3
+ history:
+ value_type: ITEM_VALUE_TYPE_UINT64
+ time: 2017-10-29 03:14:59 +03:00
+ data: 2
+ step:
+ type: ZBX_PREPROC_DELTA_SPEED
+out:
+ return: SUCCEED
+ value: 1
+---
+test case: xpath1
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: ""
+ step:
+ type: ZBX_PREPROC_XPATH
+ params: ""
+out:
+ return: FAIL
+---
+test case: xpath2
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: <a/>
+ step:
+ type: ZBX_PREPROC_XPATH
+ params: ""
+out:
+ return: FAIL
+---
+test case: xpath3
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: <a/>
+ step:
+ type: ZBX_PREPROC_XPATH
+ params: |-
+ /a["]
+out:
+ return: FAIL
+---
+test case: xpath4
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: <a/>
+ step:
+ type: ZBX_PREPROC_XPATH
+ params: 1 div 0
+out:
+ return: FAIL
+---
+test case: xpath5
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: <a/>
+ step:
+ type: ZBX_PREPROC_XPATH
+ params: -a
+out:
+ return: FAIL
+---
+test case: xpath6
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: <a/>
+ step:
+ type: ZBX_PREPROC_XPATH
+ params: /b
+out:
+ return: SUCCEED
+ value: ""
+---
+test case: xpath7
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: <a/>
+ step:
+ type: ZBX_PREPROC_XPATH
+ params: 3 div 2
+out:
+ return: SUCCEED
+ value: 1.5
+---
+test case: xpath8
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: <a/>
+ step:
+ type: ZBX_PREPROC_XPATH
+ params: /a
+out:
+ return: SUCCEED
+ value: <a/>
+---
+test case: xpath9
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: <a>1</a>
+ step:
+ type: ZBX_PREPROC_XPATH
+ params: /a/text()
+out:
+ return: SUCCEED
+ value: 1
+---
+test case: xpath10
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: <a>1</a>
+ step:
+ type: ZBX_PREPROC_XPATH
+ params: string(/a)
+out:
+ return: SUCCEED
+ value: 1
+---
+test case: xpath11
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: <a b="10">1</a>
+ step:
+ type: ZBX_PREPROC_XPATH
+ params: string(/a/@b)
+out:
+ return: SUCCEED
+ value: 10
+---
+test case: xpath12
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: <a><b x="1"/><c x="2"/><d x="1"/></a>
+ step:
+ type: ZBX_PREPROC_XPATH
+ params: //*[@x="1"]
+out:
+ return: SUCCEED
+ value: <b x="1"/><d x="1"/>
+---
+test case: jsonpath1
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: abc
+ step:
+ type: ZBX_PREPROC_JSONPATH
+ params:
+out:
+ return: FAIL
+---
+test case: jsonpath2
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: |-
+ {"a":{"b":[1, 2, 3]}}
+ step:
+ type: ZBX_PREPROC_JSONPATH
+ params: $abc
+out:
+ return: FAIL
+---
+test case: jsonpath3
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: |-
+ {"a":{"b":[1, 2, 3]}}
+ step:
+ type: ZBX_PREPROC_JSONPATH
+ params: $.abc
+out:
+ return: FAIL
+---
+test case: jsonpath4
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: |-
+ {"a":{"b":[1, 2, 3]}}
+ step:
+ type: ZBX_PREPROC_JSONPATH
+ params: $.a
+out:
+ return: SUCCEED
+ value: |-
+ {"b":[1, 2, 3]}
+---
+test case: jsonpath5
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: |-
+ {"a":{"b":[1, 2, 3]}}
+ step:
+ type: ZBX_PREPROC_JSONPATH
+ params: $.a['b']
+out:
+ return: SUCCEED
+ value: |-
+ [1, 2, 3]
+---
+test case: jsonpath6
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: |-
+ {"a":{"b":[1, 2, 3]}}
+ step:
+ type: ZBX_PREPROC_JSONPATH
+ params: $.a['b'][1]
+out:
+ return: SUCCEED
+ value: 2
+---
+test case: validate_range(1, 5, 10)
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: 1
+ step:
+ type: ZBX_PREPROC_VALIDATE_RANGE
+ params: |-
+ 5
+ 10
+out:
+ return: FAIL
+---
+test case: validate_range(5, 5, 10)
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: 5
+ step:
+ type: ZBX_PREPROC_VALIDATE_RANGE
+ params: |-
+ 5
+ 10
+out:
+ return: SUCCEED
+ value: 5
+---
+test case: validate_range(10, 5, 10)
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: 10
+ step:
+ type: ZBX_PREPROC_VALIDATE_RANGE
+ params: |-
+ 5
+ 10
+out:
+ return: SUCCEED
+ value: 10
+---
+test case: validate_range(10.1, 5, 10)
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: 10.1
+ step:
+ type: ZBX_PREPROC_VALIDATE_RANGE
+ params: |-
+ 5
+ 10
+out:
+ return: FAIL
+---
+test case: validate_regex(abc 123 xyz, ([0-9+))
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: abc 123 xyz
+ step:
+ type: ZBX_PREPROC_VALIDATE_REGEX
+ params: ([0-9+)
+out:
+ return: FAIL
+---
+test case: validate_regex(abc opq xyz, ([0-9]+))
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: abc opq xyz
+ step:
+ type: ZBX_PREPROC_VALIDATE_REGEX
+ params: ([0-9]+)
+out:
+ return: FAIL
+---
+test case: validate_regex(abc 123 xyz, ([0-9]+))
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: abc 123 xyz
+ step:
+ type: ZBX_PREPROC_VALIDATE_REGEX
+ params: ([0-9]+)
+out:
+ return: SUCCEED
+ value: abc 123 xyz
+---
+test case: validate_regex(abc 123 xyz, ([0-9+))
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: abc 123 xyz
+ step:
+ type: ZBX_PREPROC_VALIDATE_NOT_REGEX
+ params: ([0-9+)
+out:
+ return: FAIL
+---
+test case: validate_regex(abc opq xyz, ([0-9]+))
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: abc opq xyz
+ step:
+ type: ZBX_PREPROC_VALIDATE_NOT_REGEX
+ params: ([0-9]+)
+out:
+ return: SUCCEED
+ value: abc opq xyz
+---
+test case: validate_regex(abc 123 xyz, ([0-9]+))
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: abc 123 xyz
+ step:
+ type: ZBX_PREPROC_VALIDATE_NOT_REGEX
+ params: ([0-9]+)
+out:
+ return: FAIL
+---
+test case: string(10) * 10 (discard)
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: x
+ step:
+ type: ZBX_PREPROC_MULTIPLIER
+ params: 10
+ error_handler: ZBX_PREPROC_FAIL_DISCARD_VALUE
+out:
+ return: SUCCEED
+---
+test case: string(10) * 10 (set value)
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: x
+ step:
+ type: ZBX_PREPROC_MULTIPLIER
+ params: 10
+ error_handler: ZBX_PREPROC_FAIL_SET_VALUE
+ error_handler_params: invalid
+out:
+ return: SUCCEED
+ value: invalid
+---
+test case: string(10) * 10 (set error)
+in:
+ value:
+ value_type: ITEM_VALUE_TYPE_STR
+ time: 2017-10-29 03:15:00 +03:00
+ data: x
+ step:
+ type: ZBX_PREPROC_MULTIPLIER
+ params: 10
+ error_handler: ZBX_PREPROC_FAIL_SET_ERROR
+ error_handler_params: custom error
+out:
+ return: FAIL
+ error: custom error
+...
+
+