diff options
23 files changed, 268 insertions, 62 deletions
diff --git a/.gitignore b/.gitignore index 179cd23f2a5..a3c166293d2 100644 --- a/.gitignore +++ b/.gitignore @@ -224,6 +224,7 @@ tests/libs/zbxcommon/zbx_tm_sub tests/libs/zbxcommon/zbx_tm_round_up tests/libs/zbxcommon/zbx_tm_round_down tests/libs/zbxtrends/zbx_trends_parse_range +tests/libs/zbxsysinfo/process_http tests/zabbix_server/preprocessor/item_preproc_csv_to_json tests/zabbix_server/preprocessor/item_preproc_xpath tests/zabbix_server/preprocessor/zbx_item_preproc diff --git a/ChangeLog.d/bugfix/ZBX-20008 b/ChangeLog.d/bugfix/ZBX-20008 new file mode 100644 index 00000000000..4edd09352fd --- /dev/null +++ b/ChangeLog.d/bugfix/ZBX-20008 @@ -0,0 +1 @@ +...G...... [ZBX-20008] removed curl and ldap linkage from agent2 (yurii) diff --git a/configure.ac b/configure.ac index fe511c7f236..deafc17c4c1 100644 --- a/configure.ac +++ b/configure.ac @@ -1669,6 +1669,9 @@ PROXY_LIBS="$PROXY_LIBS $ZLIB_LIBS $LIBPTHREAD_LIBS" AGENT_LDFLAGS="$AGENT_LDFLAGS $ZLIB_LDFLAGS $LIBPTHREAD_LDFLAGS" AGENT_LIBS="$AGENT_LIBS $ZLIB_LIBS $LIBPTHREAD_LIBS" +AGENT2_LDFLAGS="$AGENT2_LDFLAGS $ZLIB_LDFLAGS $LIBPTHREAD_LDFLAGS" +AGENT2_LIBS="$AGENT2_LIBS $ZLIB_LIBS $LIBPTHREAD_LIBS" + ZBXGET_LDFLAGS="$ZBXGET_LDFLAGS $ZLIB_LDFLAGS $LIBPTHREAD_LDFLAGS" ZBXGET_LIBS="$ZBXGET_LIBS $ZLIB_LIBS $LIBPTHREAD_LIBS" @@ -1761,6 +1764,9 @@ PROXY_LIBS="$PROXY_LIBS $TLS_LIBS" AGENT_LDFLAGS="$AGENT_LDFLAGS $TLS_LDFLAGS" AGENT_LIBS="$AGENT_LIBS $TLS_LIBS" +AGENT2_LDFLAGS="$AGENT2_LDFLAGS $TLS_LDFLAGS" +AGENT2_LIBS="$AGENT2_LIBS $TLS_LIBS" + ZBXGET_LDFLAGS="$ZBXGET_LDFLAGS $TLS_LDFLAGS" ZBXGET_LIBS="$ZBXGET_LIBS $TLS_LIBS" @@ -1917,6 +1923,9 @@ AC_SUBST(PROXY_LIBS) AC_SUBST(AGENT_LDFLAGS) AC_SUBST(AGENT_LIBS) +AC_SUBST(AGENT2_LDFLAGS) +AC_SUBST(AGENT2_LIBS) + if test "x$HAVE_START_GROUP" = "xyes"; then LD_START_GROUP=-Wl,--start-group LD_END_GROUP=-Wl,--end-group @@ -1924,7 +1933,7 @@ fi if test "x$agent2" = "xyes"; then CGO_CFLAGS=$TLS_CFLAGS - CGO_LDFLAGS="$AGENT_LDFLAGS $LD_START_GROUP \ + CGO_LDFLAGS="$AGENT2_LDFLAGS $LD_START_GROUP \ \${abs_top_builddir}/src/zabbix_agent/logfiles/libzbxlogfiles.a \ \${abs_top_builddir}/src/libs/zbxcomms/libzbxcomms.a \ \${abs_top_builddir}/src/libs/zbxcommon/libzbxcommon.a \ @@ -1943,7 +1952,7 @@ if test "x$agent2" = "xyes"; then \${abs_top_builddir}/src/libs/zbxexec/libzbxexec.a \ \${abs_top_builddir}/src/libs/zbxalgo/libzbxalgo.a \ \${abs_top_builddir}/src/libs/zbxjson/libzbxjson.a \ - $LIBS $AGENT_LIBS $LD_END_GROUP" + $LIBS $AGENT2_LIBS $LD_END_GROUP" AC_SUBST(CGO_CFLAGS) AC_SUBST(CGO_LDFLAGS) diff --git a/src/libs/zbxsysinfo/Makefile.am b/src/libs/zbxsysinfo/Makefile.am index 7bfedfeedbd..6ac138b4fbb 100644 --- a/src/libs/zbxsysinfo/Makefile.am +++ b/src/libs/zbxsysinfo/Makefile.am @@ -34,6 +34,7 @@ noinst_LIBRARIES = \ libzbxagentsysinfo_a_CFLAGS = \ -DWITH_AGENT_METRICS \ -DWITH_COMMON_METRICS \ + -DWITH_HTTP_METRICS \ -DWITH_SIMPLE_METRICS \ -DWITH_SPECIFIC_METRICS \ -DWITH_HOSTNAME_METRIC @@ -53,6 +54,7 @@ libzbxagent2sysinfo_a_SOURCES = \ # SERVER version of sysinfo library libzbxserversysinfo_a_CFLAGS = \ -DWITH_COMMON_METRICS \ + -DWITH_HTTP_METRICS \ -DWITH_SIMPLE_METRICS libzbxserversysinfo_a_SOURCES = \ @@ -61,6 +63,7 @@ libzbxserversysinfo_a_SOURCES = \ # PROXY version of sysinfo library libzbxproxysysinfo_a_CFLAGS = \ -DWITH_COMMON_METRICS \ + -DWITH_HTTP_METRICS \ -DWITH_SIMPLE_METRICS \ -DWITH_HOSTNAME_METRIC diff --git a/src/libs/zbxsysinfo/common/Makefile.am b/src/libs/zbxsysinfo/common/Makefile.am index c63ec6be318..d6326a28ab2 100644 --- a/src/libs/zbxsysinfo/common/Makefile.am +++ b/src/libs/zbxsysinfo/common/Makefile.am @@ -1,6 +1,6 @@ ## Process this file with automake to produce Makefile.in -noinst_LIBRARIES = libcommonsysinfo.a +noinst_LIBRARIES = libcommonsysinfo.a libcommonsysinfo_http.a libcommonsysinfo_httpmetrics.a libcommonsysinfo_a_CFLAGS = -I@top_srcdir@/src/zabbix_agent/ @@ -15,11 +15,17 @@ libcommonsysinfo_a_SOURCES = \ dns.h \ file.c \ file.h \ - http.c \ - http.h \ net.c \ net.h \ system.c \ system.h \ zabbix_stats.c \ zabbix_stats.h + +libcommonsysinfo_http_a_SOURCES = \ + http.c \ + http.h + +libcommonsysinfo_httpmetrics_a_SOURCES = \ + http_metrics.c \ + http_metrics.h diff --git a/src/libs/zbxsysinfo/common/common.c b/src/libs/zbxsysinfo/common/common.c index 9fa1705fe30..89016fbafcf 100644 --- a/src/libs/zbxsysinfo/common/common.c +++ b/src/libs/zbxsysinfo/common/common.c @@ -24,7 +24,6 @@ #include "file.h" #include "dir.h" -#include "http.h" #include "net.h" #include "dns.h" #include "system.h" @@ -60,10 +59,6 @@ ZBX_METRIC parameters_common[] = {"system.localtime", CF_HAVEPARAMS, SYSTEM_LOCALTIME, "utc"}, {"system.run", CF_HAVEPARAMS, SYSTEM_RUN, "echo test"}, - {"web.page.get", CF_HAVEPARAMS, WEB_PAGE_GET, "localhost,,80"}, - {"web.page.perf", CF_HAVEPARAMS, WEB_PAGE_PERF, "localhost,,80"}, - {"web.page.regexp", CF_HAVEPARAMS, WEB_PAGE_REGEXP, "localhost,,80,OK"}, - {"vfs.file.size", CF_HAVEPARAMS, VFS_FILE_SIZE, VFS_TEST_FILE}, {"vfs.file.time", CF_HAVEPARAMS, VFS_FILE_TIME, VFS_TEST_FILE ",modify"}, {"vfs.file.exists", CF_HAVEPARAMS, VFS_FILE_EXISTS, VFS_TEST_FILE}, diff --git a/src/libs/zbxsysinfo/common/http_metrics.c b/src/libs/zbxsysinfo/common/http_metrics.c new file mode 100644 index 00000000000..5d41a0f3d14 --- /dev/null +++ b/src/libs/zbxsysinfo/common/http_metrics.c @@ -0,0 +1,30 @@ +/* +** Zabbix +** Copyright (C) 2001-2021 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 "http.h" + +ZBX_METRIC parameters_common_http[] = +/* KEY FLAG FUNCTION TEST PARAMETERS */ +{ + {"web.page.get", CF_HAVEPARAMS, WEB_PAGE_GET, "localhost,,80"}, + {"web.page.perf", CF_HAVEPARAMS, WEB_PAGE_PERF, "localhost,,80"}, + {"web.page.regexp", CF_HAVEPARAMS, WEB_PAGE_REGEXP, "localhost,,80,OK"}, + + {NULL} +}; diff --git a/src/libs/zbxsysinfo/common/http_metrics.h b/src/libs/zbxsysinfo/common/http_metrics.h new file mode 100644 index 00000000000..8799a0d455c --- /dev/null +++ b/src/libs/zbxsysinfo/common/http_metrics.h @@ -0,0 +1,27 @@ +/* +** Zabbix +** Copyright (C) 2001-2021 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 "sysinfo.h" + +#ifndef ZABBIX_SYSINFO_COMMON_HTTP_METRICS_H +#define ZABBIX_SYSINFO_COMMON_HTTP_METRICS_H + +extern ZBX_METRIC parameters_common_http[]; + +#endif /* ZABBIX_SYSINFO_COMMON_HTTP_METRICS_H */ diff --git a/src/libs/zbxsysinfo/sysinfo.c b/src/libs/zbxsysinfo/sysinfo.c index 1cdec05eb76..872ed360218 100644 --- a/src/libs/zbxsysinfo/sysinfo.c +++ b/src/libs/zbxsysinfo/sysinfo.c @@ -38,6 +38,10 @@ # include "common/common.h" #endif +#ifdef WITH_HTTP_METRICS +# include "common/http_metrics.h" +#endif + #ifdef WITH_SIMPLE_METRICS # include "simple/simple.h" #endif @@ -241,6 +245,17 @@ void init_metrics(void) } #endif +#ifdef WITH_HTTP_METRICS + for (i = 0; NULL != parameters_common_http[i].key; i++) + { + if (SUCCEED != add_metric(¶meters_common_http[i], error, sizeof(error))) + { + zabbix_log(LOG_LEVEL_CRIT, "cannot add item key: %s", error); + exit(EXIT_FAILURE); + } + } +#endif + #ifdef WITH_SPECIFIC_METRICS for (i = 0; NULL != parameters_specific[i].key; i++) { diff --git a/src/zabbix_agent/Makefile.am b/src/zabbix_agent/Makefile.am index 55aa04c00d4..d53a732b716 100644 --- a/src/zabbix_agent/Makefile.am +++ b/src/zabbix_agent/Makefile.am @@ -47,6 +47,8 @@ zabbix_agentd_LDADD = \ $(top_builddir)/src/libs/zbxsysinfo/$(ARCH)/libspechostnamesysinfo.a \ $(top_builddir)/src/libs/zbxsysinfo/agent/libagentsysinfo.a \ $(top_builddir)/src/libs/zbxsysinfo/common/libcommonsysinfo.a \ + $(top_builddir)/src/libs/zbxsysinfo/common/libcommonsysinfo_httpmetrics.a \ + $(top_builddir)/src/libs/zbxsysinfo/common/libcommonsysinfo_http.a \ $(top_builddir)/src/libs/zbxsysinfo/simple/libsimplesysinfo.a \ $(top_builddir)/src/libs/zbxlog/libzbxlog.a \ $(top_builddir)/src/libs/zbxregexp/libzbxregexp.a \ diff --git a/src/zabbix_proxy/Makefile.am b/src/zabbix_proxy/Makefile.am index e9953bc6027..d38d8249bf6 100644 --- a/src/zabbix_proxy/Makefile.am +++ b/src/zabbix_proxy/Makefile.am @@ -47,6 +47,8 @@ zabbix_proxy_LDADD = \ $(top_builddir)/src/zabbix_server/availability/libavailability.a \ $(top_builddir)/src/libs/zbxsysinfo/libzbxproxysysinfo.a \ $(top_builddir)/src/libs/zbxsysinfo/common/libcommonsysinfo.a \ + $(top_builddir)/src/libs/zbxsysinfo/common/libcommonsysinfo_httpmetrics.a \ + $(top_builddir)/src/libs/zbxsysinfo/common/libcommonsysinfo_http.a \ $(top_builddir)/src/libs/zbxsysinfo/simple/libsimplesysinfo.a \ $(top_builddir)/src/libs/zbxsysinfo/$(ARCH)/libspechostnamesysinfo.a \ $(top_builddir)/src/libs/zbxlog/libzbxlog.a \ diff --git a/src/zabbix_server/Makefile.am b/src/zabbix_server/Makefile.am index 6c2a565f9a8..9790ad6d39f 100644 --- a/src/zabbix_server/Makefile.am +++ b/src/zabbix_server/Makefile.am @@ -78,6 +78,8 @@ zabbix_server_LDADD = \ $(top_builddir)/src/libs/zbxprometheus/libzbxprometheus.a \ $(top_builddir)/src/libs/zbxsysinfo/libzbxserversysinfo.a \ $(top_builddir)/src/libs/zbxsysinfo/common/libcommonsysinfo.a \ + $(top_builddir)/src/libs/zbxsysinfo/common/libcommonsysinfo_httpmetrics.a \ + $(top_builddir)/src/libs/zbxsysinfo/common/libcommonsysinfo_http.a \ $(top_builddir)/src/libs/zbxsysinfo/simple/libsimplesysinfo.a \ $(top_builddir)/src/libs/zbxlog/libzbxlog.a \ $(top_builddir)/src/libs/zbxdbcache/libzbxdbcache.a \ diff --git a/tests/libs/zbxcommon/Makefile.am b/tests/libs/zbxcommon/Makefile.am index 38383a6dea9..e2c3585d578 100644 --- a/tests/libs/zbxcommon/Makefile.am +++ b/tests/libs/zbxcommon/Makefile.am @@ -66,6 +66,8 @@ COMMON_LIB_FILES = \ $(top_srcdir)/src/libs/zbxserver/libzbxserver.a \ $(top_srcdir)/src/libs/zbxsysinfo/libzbxserversysinfo.a \ $(top_srcdir)/src/libs/zbxsysinfo/common/libcommonsysinfo.a \ + $(top_srcdir)/src/libs/zbxsysinfo/common/libcommonsysinfo_httpmetrics.a \ + $(top_srcdir)/src/libs/zbxsysinfo/common/libcommonsysinfo_http.a \ $(top_srcdir)/src/libs/zbxsysinfo/simple/libsimplesysinfo.a \ $(top_srcdir)/src/libs/zbxdbcache/libzbxdbcache.a \ $(top_srcdir)/src/libs/zbxmemory/libzbxmemory.a \ diff --git a/tests/libs/zbxdbcache/Makefile.am b/tests/libs/zbxdbcache/Makefile.am index 42bf097c01d..2ecf31ca331 100644 --- a/tests/libs/zbxdbcache/Makefile.am +++ b/tests/libs/zbxdbcache/Makefile.am @@ -51,6 +51,8 @@ CACHE_LIBS = \ $(top_srcdir)/src/libs/zbxsysinfo/libzbxserversysinfo.a \ $(top_srcdir)/src/libs/zbxxml/libzbxxml.a \ $(top_srcdir)/src/libs/zbxsysinfo/common/libcommonsysinfo.a \ + $(top_srcdir)/src/libs/zbxsysinfo/common/libcommonsysinfo_httpmetrics.a \ + $(top_srcdir)/src/libs/zbxsysinfo/common/libcommonsysinfo_http.a \ $(top_srcdir)/src/libs/zbxsysinfo/simple/libsimplesysinfo.a \ $(top_srcdir)/src/libs/zbxhistory/libzbxhistory.a \ $(top_srcdir)/src/libs/zbxmodules/libzbxmodules.a \ diff --git a/tests/libs/zbxdbhigh/Makefile.am b/tests/libs/zbxdbhigh/Makefile.am index 5cd66d01ee6..17e6c42c3c9 100644 --- a/tests/libs/zbxdbhigh/Makefile.am +++ b/tests/libs/zbxdbhigh/Makefile.am @@ -76,10 +76,14 @@ SERVER_COMMON_LIB = \ $(top_srcdir)/src/zabbix_server/preprocessor/libpreprocessor.a \ $(top_srcdir)/src/libs/zbxsysinfo/libzbxserversysinfo.a \ $(top_srcdir)/src/libs/zbxsysinfo/common/libcommonsysinfo.a \ + $(top_srcdir)/src/libs/zbxsysinfo/common/libcommonsysinfo_httpmetrics.a \ + $(top_srcdir)/src/libs/zbxsysinfo/common/libcommonsysinfo_http.a \ $(top_srcdir)/src/libs/zbxsysinfo/simple/libsimplesysinfo.a \ $(top_srcdir)/src/libs/zbxserver/libzbxserver.a \ $(top_srcdir)/src/libs/zbxsysinfo/libzbxserversysinfo.a \ $(top_srcdir)/src/libs/zbxsysinfo/common/libcommonsysinfo.a \ + $(top_srcdir)/src/libs/zbxsysinfo/common/libcommonsysinfo_httpmetrics.a \ + $(top_srcdir)/src/libs/zbxsysinfo/common/libcommonsysinfo_http.a \ $(top_srcdir)/src/libs/zbxsysinfo/simple/libsimplesysinfo.a \ $(top_srcdir)/src/libs/zbxdbcache/libzbxdbcache.a \ $(top_srcdir)/src/libs/zbxeval/libzbxeval.a \ @@ -130,6 +134,8 @@ PROXY_COMMON_LIB = \ $(top_srcdir)/src/zabbix_proxy/libzbxproxy.a \ $(top_srcdir)/src/libs/zbxsysinfo/libzbxproxysysinfo.a \ $(top_srcdir)/src/libs/zbxsysinfo/common/libcommonsysinfo.a \ + $(top_srcdir)/src/libs/zbxsysinfo/common/libcommonsysinfo_httpmetrics.a \ + $(top_srcdir)/src/libs/zbxsysinfo/common/libcommonsysinfo_http.a \ $(top_srcdir)/src/libs/zbxsysinfo/simple/libsimplesysinfo.a \ $(top_srcdir)/src/libs/zbxsysinfo/linux/libspechostnamesysinfo.a \ $(COMMON_LIB) diff --git a/tests/libs/zbxserver/Makefile.am b/tests/libs/zbxserver/Makefile.am index 9149eedfcca..48bcd7a0228 100755 --- a/tests/libs/zbxserver/Makefile.am +++ b/tests/libs/zbxserver/Makefile.am @@ -33,6 +33,15 @@ COMMON_LIB_FILES = \ $(top_srcdir)/src/zabbix_server/odbc/libzbxodbc.a \ $(top_srcdir)/src/zabbix_server/scripts/libzbxscripts.a \ $(top_srcdir)/src/zabbix_server/preprocessor/libpreprocessor.a \ + $(top_srcdir)/src/libs/zbxserver/libzbxserver.a \ + $(top_srcdir)/src/libs/zbxdbcache/libzbxdbcache.a \ + $(top_srcdir)/src/libs/zbxtrends/libzbxtrends.a \ + $(top_srcdir)/src/libs/zbxsysinfo/libzbxserversysinfo.a \ + $(top_srcdir)/src/libs/zbxsysinfo/common/libcommonsysinfo.a \ + $(top_srcdir)/src/libs/zbxsysinfo/common/libcommonsysinfo_httpmetrics.a \ + $(top_srcdir)/src/libs/zbxsysinfo/common/libcommonsysinfo_http.a \ + $(top_srcdir)/src/libs/zbxsysinfo/simple/libsimplesysinfo.a \ + $(top_srcdir)/src/libs/zbxmemory/libzbxmemory.a \ $(top_srcdir)/src/libs/zbxself/libzbxself.a \ $(top_srcdir)/src/libs/zbxalgo/libzbxalgo.a \ $(top_srcdir)/src/libs/zbxsys/libzbxsys.a \ diff --git a/tests/libs/zbxsysinfo/Makefile.am b/tests/libs/zbxsysinfo/Makefile.am index a721aa4bbcb..17de2bbc969 100644 --- a/tests/libs/zbxsysinfo/Makefile.am +++ b/tests/libs/zbxsysinfo/Makefile.am @@ -9,6 +9,7 @@ endif if AGENT AGENT_tests = \ process \ + process_http \ check_key_access_rules endif @@ -49,6 +50,8 @@ parse_item_key_LDADD = \ $(top_srcdir)/src/libs/zbxserver/libzbxserver.a \ $(top_srcdir)/src/libs/zbxsysinfo/libzbxserversysinfo.a \ $(top_srcdir)/src/libs/zbxsysinfo/common/libcommonsysinfo.a \ + $(top_srcdir)/src/libs/zbxsysinfo/common/libcommonsysinfo_httpmetrics.a \ + $(top_srcdir)/src/libs/zbxsysinfo/common/libcommonsysinfo_http.a \ $(top_srcdir)/src/libs/zbxsysinfo/simple/libsimplesysinfo.a \ $(top_srcdir)/src/libs/zbxdbcache/libzbxdbcache.a \ $(top_srcdir)/src/libs/zbxhistory/libzbxhistory.a \ @@ -96,6 +99,7 @@ COMMON_LIB_FILES = \ $(top_srcdir)/src/libs/zbxsysinfo/agent/libagentsysinfo.a \ $(top_srcdir)/src/libs/zbxsysinfo/simple/libsimplesysinfo.a \ $(top_srcdir)/src/libs/zbxsysinfo/common/libcommonsysinfo.a \ + $(top_srcdir)/src/libs/zbxsysinfo/common/libcommonsysinfo_httpmetrics.a \ $(top_srcdir)/src/libs/zbxlog/libzbxlog.a \ $(top_srcdir)/src/libs/zbxregexp/libzbxregexp.a \ $(top_srcdir)/src/libs/zbxalgo/libzbxalgo.a \ @@ -118,13 +122,12 @@ process_SOURCES = \ process.c \ ../../zbxmocktest.h -process_LDADD = $(COMMON_LIB_FILES) +process_LDADD = $(COMMON_LIB_FILES) \ + $(top_srcdir)/src/libs/zbxsysinfo/common/libcommonsysinfo_http.a \ + $(top_srcdir)/src/libs/zbxhttp/libzbxhttp.a process_WRAP_FUNCS = \ -Wl,--wrap=SYSTEM_LOCALTIME \ - -Wl,--wrap=WEB_PAGE_GET \ - -Wl,--wrap=WEB_PAGE_PERF \ - -Wl,--wrap=WEB_PAGE_REGEXP \ -Wl,--wrap=VFS_FILE_SIZE \ -Wl,--wrap=VFS_FILE_TIME \ -Wl,--wrap=VFS_FILE_EXISTS \ @@ -144,6 +147,25 @@ process_LDFLAGS = @AGENT_LDFLAGS@ $(process_WRAP_FUNCS) process_CFLAGS = -DZABBIX_DAEMON -I@top_srcdir@/tests +# process_http + +process_http_SOURCES = \ + process_http.c \ + ../../zbxmocktest.h + +process_http_LDADD = $(COMMON_LIB_FILES) + +process_http_WRAP_FUNCS = \ + -Wl,--wrap=WEB_PAGE_GET \ + -Wl,--wrap=WEB_PAGE_PERF \ + -Wl,--wrap=WEB_PAGE_REGEXP + +process_http_LDADD += @AGENT_LIBS@ + +process_http_LDFLAGS = @AGENT_LDFLAGS@ + +process_http_CFLAGS = $(process_http_WRAP_FUNCS) -I@top_srcdir@/tests + # check_key_access_rules check_key_access_rules_SOURCES = \ @@ -152,6 +174,7 @@ check_key_access_rules_SOURCES = \ check_key_access_rules_LDADD = $(COMMON_LIB_FILES) \ $(top_srcdir)/src/libs/zbxjson/libzbxjson.a \ + $(top_srcdir)/src/libs/zbxsysinfo/common/libcommonsysinfo_http.a \ $(top_srcdir)/src/libs/zbxhttp/libzbxhttp.a check_key_access_rules_LDADD += @AGENT_LIBS@ diff --git a/tests/libs/zbxsysinfo/common/Makefile.am b/tests/libs/zbxsysinfo/common/Makefile.am index d6f7fa874be..b66785e1c36 100644 --- a/tests/libs/zbxsysinfo/common/Makefile.am +++ b/tests/libs/zbxsysinfo/common/Makefile.am @@ -18,6 +18,8 @@ COMMON_LIB_FILES = \ $(top_srcdir)/src/libs/zbxsysinfo/agent/libagentsysinfo.a \ $(top_srcdir)/src/libs/zbxsysinfo/simple/libsimplesysinfo.a \ $(top_srcdir)/src/libs/zbxsysinfo/common/libcommonsysinfo.a \ + $(top_srcdir)/src/libs/zbxsysinfo/common/libcommonsysinfo_httpmetrics.a \ + $(top_srcdir)/src/libs/zbxsysinfo/common/libcommonsysinfo_http.a \ $(top_srcdir)/src/libs/zbxlog/libzbxlog.a \ $(top_srcdir)/src/libs/zbxregexp/libzbxregexp.a \ $(top_srcdir)/src/libs/zbxalgo/libzbxalgo.a \ diff --git a/tests/libs/zbxsysinfo/linux/Makefile.am b/tests/libs/zbxsysinfo/linux/Makefile.am index 93ad477029f..38112ac4c52 100644 --- a/tests/libs/zbxsysinfo/linux/Makefile.am +++ b/tests/libs/zbxsysinfo/linux/Makefile.am @@ -26,6 +26,8 @@ COMMON_LIB_FILES = \ $(top_srcdir)/src/libs/zbxsysinfo/agent/libagentsysinfo.a \ $(top_srcdir)/src/libs/zbxsysinfo/simple/libsimplesysinfo.a \ $(top_srcdir)/src/libs/zbxsysinfo/common/libcommonsysinfo.a \ + $(top_srcdir)/src/libs/zbxsysinfo/common/libcommonsysinfo_httpmetrics.a \ + $(top_srcdir)/src/libs/zbxsysinfo/common/libcommonsysinfo_http.a \ $(top_srcdir)/src/libs/zbxlog/libzbxlog.a \ $(top_srcdir)/src/libs/zbxregexp/libzbxregexp.a \ $(top_srcdir)/src/libs/zbxalgo/libzbxalgo.a \ diff --git a/tests/libs/zbxsysinfo/process.c b/tests/libs/zbxsysinfo/process.c index c208b82ed56..048bd9dbc4e 100644 --- a/tests/libs/zbxsysinfo/process.c +++ b/tests/libs/zbxsysinfo/process.c @@ -29,9 +29,6 @@ static char *called_key = NULL; int __wrap_SYSTEM_LOCALTIME(const char *command, AGENT_RESULT *result); -int __wrap_WEB_PAGE_GET(const char *command, AGENT_RESULT *result); -int __wrap_WEB_PAGE_PERF(const char *command, AGENT_RESULT *result); -int __wrap_WEB_PAGE_REGEXP(const char *command, AGENT_RESULT *result); int __wrap_VFS_FILE_SIZE(const char *command, AGENT_RESULT *result); int __wrap_VFS_FILE_TIME(const char *command, AGENT_RESULT *result); int __wrap_VFS_FILE_EXISTS(const char *command, AGENT_RESULT *result); @@ -95,36 +92,6 @@ int __wrap_SYSTEM_LOCALTIME(const char *command, AGENT_RESULT *result) return SUCCEED; } -int __wrap_WEB_PAGE_GET(const char *command, AGENT_RESULT *result) -{ - ZBX_UNUSED(command); - ZBX_UNUSED(result); - - called_key = "web.page.get"; - - return SUCCEED; -} - -int __wrap_WEB_PAGE_PERF(const char *command, AGENT_RESULT *result) -{ - ZBX_UNUSED(command); - ZBX_UNUSED(result); - - called_key = "web.page.perf"; - - return SUCCEED; -} - -int __wrap_WEB_PAGE_REGEXP(const char *command, AGENT_RESULT *result) -{ - ZBX_UNUSED(command); - ZBX_UNUSED(result); - - called_key = "web.page.regexp"; - - return SUCCEED; -} - int __wrap_VFS_FILE_SIZE(const char *command, AGENT_RESULT *result) { ZBX_UNUSED(command); diff --git a/tests/libs/zbxsysinfo/process.yaml b/tests/libs/zbxsysinfo/process.yaml index 25181ebb6b8..49655beebed 100644 --- a/tests/libs/zbxsysinfo/process.yaml +++ b/tests/libs/zbxsysinfo/process.yaml @@ -4,21 +4,6 @@ in: in_command: system.localtime[utc] flags: 4 --- -test case: successfully called WEB_PAGE_GET function -in: - in_command: web.page.get[localhost,,80] - flags: 4 ---- -test case: successfully called WEB_PAGE_PERF function -in: - in_command: web.page.perf[localhost,,80] - flags: 4 ---- -test case: successfully called WEB_PAGE_REGEXP function -in: - in_command: web.page.regexp[localhost,,80,OK] - flags: 4 ---- test case: successfully called VFS_FILE_SIZE function in: in_command: vfs.file.size[/etc/passwd] diff --git a/tests/libs/zbxsysinfo/process_http.c b/tests/libs/zbxsysinfo/process_http.c new file mode 100644 index 00000000000..f29e35544af --- /dev/null +++ b/tests/libs/zbxsysinfo/process_http.c @@ -0,0 +1,99 @@ +/* +** Zabbix +** Copyright (C) 2001-2021 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 "db.h" +#include "sysinfo.h" + +static char *called_key = NULL; + +int __wrap_WEB_PAGE_GET(const char *command, AGENT_RESULT *result); +int __wrap_WEB_PAGE_PERF(const char *command, AGENT_RESULT *result); +int __wrap_WEB_PAGE_REGEXP(const char *command, AGENT_RESULT *result); + +void zbx_mock_test_entry(void **state) +{ + zbx_mock_error_t error; + zbx_mock_handle_t in_command, in_flags; + const char *in_command_string, *flags_string, *p; + char key[ITEM_KEY_LEN]; + unsigned flags_uint32; + AGENT_RESULT result; + + ZBX_UNUSED(state); + + if (ZBX_MOCK_SUCCESS != (error = zbx_mock_in_parameter("in_command", &in_command)) || + ZBX_MOCK_SUCCESS != (error = zbx_mock_string(in_command, &in_command_string))) + { + fail_msg("Cannot get in_command from test case data: %s", zbx_mock_error_string(error)); + } + + if (ZBX_MOCK_SUCCESS != (error = zbx_mock_in_parameter("flags", &in_flags)) || + ZBX_MOCK_SUCCESS != (error = zbx_mock_string(in_flags, &flags_string))) + { + fail_msg("Cannot get flags from test case data: %s", zbx_mock_error_string(error)); + } + if (SUCCEED != is_uint32(flags_string, &flags_uint32)) + fail_msg("Cannot convert flags to unsigned 32 bit integer."); + + init_metrics(); + + process(in_command_string, flags_uint32, &result); + + if (NULL != (p = strchr(in_command_string, '['))) + zbx_strlcpy(key, in_command_string, p - in_command_string + 1); + + if (called_key == NULL || 0 != strcmp((NULL == p ? in_command_string : key), called_key)) + { + fail_msg("Unexpected called item '%s' instead of '%s' as a key.", + ZBX_NULL2STR(called_key), in_command_string); + } +} + +int __wrap_WEB_PAGE_GET(const char *command, AGENT_RESULT *result) +{ + ZBX_UNUSED(command); + ZBX_UNUSED(result); + + called_key = "web.page.get"; + + return SUCCEED; +} + +int __wrap_WEB_PAGE_PERF(const char *command, AGENT_RESULT *result) +{ + ZBX_UNUSED(command); + ZBX_UNUSED(result); + + called_key = "web.page.perf"; + + return SUCCEED; +} + +int __wrap_WEB_PAGE_REGEXP(const char *command, AGENT_RESULT *result) +{ + ZBX_UNUSED(command); + ZBX_UNUSED(result); + + called_key = "web.page.regexp"; + + return SUCCEED; +} diff --git a/tests/libs/zbxsysinfo/process_http.yaml b/tests/libs/zbxsysinfo/process_http.yaml new file mode 100644 index 00000000000..b2fd1b62caf --- /dev/null +++ b/tests/libs/zbxsysinfo/process_http.yaml @@ -0,0 +1,16 @@ +--- +test case: successfully called WEB_PAGE_GET function +in: + in_command: web.page.get[localhost,,80] + flags: 4 +--- +test case: successfully called WEB_PAGE_PERF function +in: + in_command: web.page.perf[localhost,,80] + flags: 4 +--- +test case: successfully called WEB_PAGE_REGEXP function +in: + in_command: web.page.regexp[localhost,,80,OK] + flags: 4 +... |