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
path: root/src
diff options
context:
space:
mode:
authorArtjoms Rimdjonoks <artjoms.rimdjonoks@zabbix.com>2022-04-01 16:10:25 +0300
committerArtjoms Rimdjonoks <artjoms.rimdjonoks@zabbix.com>2022-04-01 16:10:25 +0300
commit97a1ae85bf1bcedab0506d71be1a8fed100b3780 (patch)
tree3fbedf73f258a8c4d8c39e481f8dddf98fdb945c /src
parent8ddcecc460313cf7e0128e1f5e76e3385f40300a (diff)
parent76b8b2e914778d623afb067cdc994c89a7a24824 (diff)
.......... [DEV-2124] updated to the latest master
Diffstat (limited to 'src')
-rw-r--r--src/libs/zbxcomms/Makefile.am1
-rw-r--r--src/libs/zbxcomms/comms.c1
-rw-r--r--src/libs/zbxcomms/comms.h43
-rw-r--r--src/libs/zbxcomms/telnet.c30
-rw-r--r--src/libs/zbxdbcache/dbcache.c3
-rw-r--r--src/libs/zbxdbcache/dbconfig.c34
-rw-r--r--src/libs/zbxserver/evalfunc.c1
-rw-r--r--src/libs/zbxsysinfo/simple/simple.c3
-rw-r--r--src/zabbix_server/alerter/alert_manager.c2
-rw-r--r--src/zabbix_server/ipmi/ipmi_manager.c11
-rw-r--r--src/zabbix_server/poller/checks_telnet.c7
-rw-r--r--src/zabbix_server/preprocessor/preproc_manager.c3
-rw-r--r--src/zabbix_server/reporter/report_manager.c53
13 files changed, 140 insertions, 52 deletions
diff --git a/src/libs/zbxcomms/Makefile.am b/src/libs/zbxcomms/Makefile.am
index 6821cd8a8a0..77105624244 100644
--- a/src/libs/zbxcomms/Makefile.am
+++ b/src/libs/zbxcomms/Makefile.am
@@ -3,6 +3,7 @@
noinst_LIBRARIES = libzbxcomms.a
libzbxcomms_a_SOURCES = \
+ comms.h \
comms.c \
telnet.c
diff --git a/src/libs/zbxcomms/comms.c b/src/libs/zbxcomms/comms.c
index 151ecb6aec4..a66a5d803fa 100644
--- a/src/libs/zbxcomms/comms.c
+++ b/src/libs/zbxcomms/comms.c
@@ -18,6 +18,7 @@
**/
#include "zbxcomms.h"
+#include "comms.h"
#include "common.h"
#include "base64.h"
diff --git a/src/libs/zbxcomms/comms.h b/src/libs/zbxcomms/comms.h
new file mode 100644
index 00000000000..f862b2ee63b
--- /dev/null
+++ b/src/libs/zbxcomms/comms.h
@@ -0,0 +1,43 @@
+/*
+** Zabbix
+** Copyright (C) 2001-2022 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.
+**/
+
+#ifndef ZABBIX_COMMS_H
+#define ZABBIX_COMMS_H
+
+#include "config.h"
+
+#ifdef _WINDOWS
+# define ZBX_TCP_WRITE(s, b, bl) ((ssize_t)send((s), (b), (int)(bl), 0))
+# define ZBX_TCP_READ(s, b, bl) ((ssize_t)recv((s), (b), (int)(bl), 0))
+# define zbx_socket_close(s) if (ZBX_SOCKET_ERROR != (s)) closesocket(s)
+# define zbx_bind(s, a, l) (bind((s), (a), (int)(l)))
+# define zbx_sendto(fd, b, n, f, a, l) (sendto((fd), (b), (int)(n), (f), (a), (l)))
+# define ZBX_PROTO_AGAIN WSAEINTR
+# define ZBX_SOCKET_ERROR INVALID_SOCKET
+#else
+# define ZBX_TCP_WRITE(s, b, bl) ((ssize_t)write((s), (b), (bl)))
+# define ZBX_TCP_READ(s, b, bl) ((ssize_t)read((s), (b), (bl)))
+# define zbx_socket_close(s) if (ZBX_SOCKET_ERROR != (s)) close(s)
+# define zbx_bind(s, a, l) (bind((s), (a), (l)))
+# define zbx_sendto(fd, b, n, f, a, l) (sendto((fd), (b), (n), (f), (a), (l)))
+# define ZBX_PROTO_AGAIN EINTR
+# define ZBX_SOCKET_ERROR -1
+#endif
+
+#endif /* ZABBIX_COMMS_H */
diff --git a/src/libs/zbxcomms/telnet.c b/src/libs/zbxcomms/telnet.c
index 79c7ddf714a..c5ca664173c 100644
--- a/src/libs/zbxcomms/telnet.c
+++ b/src/libs/zbxcomms/telnet.c
@@ -17,11 +17,22 @@
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
-#include "telnet.h"
+#include "zbxcomms.h"
+#include "comms.h"
#include "common.h"
#include "log.h"
+#define WAIT_READ 0
+#define WAIT_WRITE 1
+
+#define CMD_IAC 255
+#define CMD_WILL 251
+#define CMD_WONT 252
+#define CMD_DO 253
+#define CMD_DONT 254
+#define OPT_SGA 3
+
static char prompt_char = '\0';
static int telnet_waitsocket(ZBX_SOCKET socket_fd, int mode)
@@ -125,6 +136,9 @@ static ssize_t telnet_socket_write(ZBX_SOCKET socket_fd, const void *buf, size_t
return rc;
}
+#undef WAIT_READ
+#undef WAIT_WRITE
+
static ssize_t telnet_read(ZBX_SOCKET socket_fd, char *buf, size_t *buf_left, size_t *buf_offset)
{
unsigned char c, c1, c2, c3;
@@ -208,6 +222,13 @@ end:
return rc;
}
+#undef CMD_IAC
+#undef CMD_WILL
+#undef CMD_WONT
+#undef CMD_DO
+#undef CMD_DONT
+#undef OPT_SGA
+
/******************************************************************************
* *
* Comments: converts CR+LF to Unix LF and clears CR+NUL *
@@ -305,7 +326,7 @@ static void telnet_rm_prompt(const char *buf, size_t *offset)
}
}
-int telnet_test_login(ZBX_SOCKET socket_fd)
+int zbx_telnet_test_login(ZBX_SOCKET socket_fd)
{
char buf[MAX_BUFFER_LEN];
size_t sz, offset;
@@ -332,7 +353,7 @@ int telnet_test_login(ZBX_SOCKET socket_fd)
return ret;
}
-int telnet_login(ZBX_SOCKET socket_fd, const char *username, const char *password, AGENT_RESULT *result)
+int zbx_telnet_login(ZBX_SOCKET socket_fd, const char *username, const char *password, AGENT_RESULT *result)
{
char buf[MAX_BUFFER_LEN], c;
size_t sz, offset;
@@ -407,7 +428,7 @@ fail:
return ret;
}
-int telnet_execute(ZBX_SOCKET socket_fd, const char *command, AGENT_RESULT *result, const char *encoding)
+int zbx_telnet_execute(ZBX_SOCKET socket_fd, const char *command, AGENT_RESULT *result, const char *encoding)
{
char buf[MAX_BUFFER_LEN];
size_t sz, offset;
@@ -433,6 +454,7 @@ int telnet_execute(ZBX_SOCKET socket_fd, const char *command, AGENT_RESULT *resu
sz = sizeof(buf);
offset = 0;
+
while (ZBX_PROTO_ERROR != (rc = telnet_read(socket_fd, buf, &sz, &offset)))
{
if (prompt_char == telnet_lastchar(buf, offset))
diff --git a/src/libs/zbxdbcache/dbcache.c b/src/libs/zbxdbcache/dbcache.c
index f924d6f4a5f..ade22f81743 100644
--- a/src/libs/zbxdbcache/dbcache.c
+++ b/src/libs/zbxdbcache/dbcache.c
@@ -1898,6 +1898,9 @@ static void normalize_item_value(const DC_ITEM *item, ZBX_DC_HISTORY *hdata)
zbx_variant_set_str(&value_var, hdata->value.log->value);
hdata->value.log->value = NULL;
break;
+ default:
+ THIS_SHOULD_NEVER_HAPPEN;
+ return;
}
dc_history_set_value(hdata, item->value_type, &value_var);
diff --git a/src/libs/zbxdbcache/dbconfig.c b/src/libs/zbxdbcache/dbconfig.c
index a7a6990dbfd..1bc60ade728 100644
--- a/src/libs/zbxdbcache/dbconfig.c
+++ b/src/libs/zbxdbcache/dbconfig.c
@@ -5405,25 +5405,28 @@ static void DCsync_item_preproc(zbx_dbsync_t *sync, int timestamp)
if (NULL == preprocitem || itemid != preprocitem->itemid)
{
- if (NULL == (preprocitem = (ZBX_DC_PREPROCITEM *)zbx_hashset_search(&config->preprocitems, &itemid)))
+ if (NULL == (preprocitem = (ZBX_DC_PREPROCITEM *)zbx_hashset_search(&config->preprocitems,
+ &itemid)))
{
ZBX_DC_PREPROCITEM preprocitem_local;
preprocitem_local.itemid = itemid;
+ preprocitem_local.update_time = timestamp;
- preprocitem = (ZBX_DC_PREPROCITEM *)zbx_hashset_insert(&config->preprocitems, &preprocitem_local,
- sizeof(preprocitem_local));
-
- zbx_vector_ptr_create_ext(&preprocitem->preproc_ops, __config_shmem_malloc_func,
+ zbx_vector_ptr_create_ext(&preprocitem_local.preproc_ops, __config_shmem_malloc_func,
__config_shmem_realloc_func, __config_shmem_free_func);
- }
- preprocitem->update_time = timestamp;
+ preprocitem = (ZBX_DC_PREPROCITEM *)zbx_hashset_insert(&config->preprocitems,
+ &preprocitem_local, sizeof(preprocitem_local));
+ }
+ else
+ preprocitem->update_time = timestamp;
}
ZBX_STR2UINT64(item_preprocid, row[0]);
- op = (zbx_dc_preproc_op_t *)DCfind_id(&config->preprocops, item_preprocid, sizeof(zbx_dc_preproc_op_t), &found);
+ op = (zbx_dc_preproc_op_t *)DCfind_id(&config->preprocops, item_preprocid, sizeof(zbx_dc_preproc_op_t),
+ &found);
ZBX_STR2UCHAR(op->type, row[2]);
DCstrpool_replace(found, &op->params, row[3]);
@@ -5447,7 +5450,8 @@ static void DCsync_item_preproc(zbx_dbsync_t *sync, int timestamp)
if (NULL == (op = (zbx_dc_preproc_op_t *)zbx_hashset_search(&config->preprocops, &rowid)))
continue;
- if (NULL != (preprocitem = (ZBX_DC_PREPROCITEM *)zbx_hashset_search(&config->preprocitems, &op->itemid)))
+ if (NULL != (preprocitem = (ZBX_DC_PREPROCITEM *)zbx_hashset_search(&config->preprocitems,
+ &op->itemid)))
{
if (FAIL != (index = zbx_vector_ptr_search(&preprocitem->preproc_ops, op,
ZBX_DEFAULT_PTR_COMPARE_FUNC)))
@@ -13549,16 +13553,18 @@ zbx_data_session_t *zbx_dc_get_or_create_data_session(zbx_uint64_t hostid, const
if (NULL == session)
{
+ session_local.last_valueid = 0;
+ session_local.lastaccess = now;
+ session_local.token = dc_strdup(token);
+
WRLOCK_CACHE;
+
session = (zbx_data_session_t *)zbx_hashset_insert(&config->data_sessions, &session_local,
sizeof(session_local));
- session->token = dc_strdup(token);
UNLOCK_CACHE;
-
- session->last_valueid = 0;
}
-
- session->lastaccess = now;
+ else
+ session->lastaccess = now;
return session;
}
diff --git a/src/libs/zbxserver/evalfunc.c b/src/libs/zbxserver/evalfunc.c
index 290bad8d960..c38d616a39f 100644
--- a/src/libs/zbxserver/evalfunc.c
+++ b/src/libs/zbxserver/evalfunc.c
@@ -2623,6 +2623,7 @@ static int trends_eval_stl(const char *table, zbx_uint64_t itemid, int start, in
zbx_history_record_t val;
val.timestamp.sec = period_counter;
+ val.timestamp.ns = 0;
if (FAIL == zbx_trends_eval_avg(table, itemid, period_counter, period_counter, &tmp_res, NULL))
{
diff --git a/src/libs/zbxsysinfo/simple/simple.c b/src/libs/zbxsysinfo/simple/simple.c
index 469fbf7fbab..5ed55af6f2c 100644
--- a/src/libs/zbxsysinfo/simple/simple.c
+++ b/src/libs/zbxsysinfo/simple/simple.c
@@ -24,7 +24,6 @@
#include "zbxcomms.h"
#include "log.h"
#include "cfg.h"
-#include "telnet.h"
#include "../common/net.h"
#include "ntp.h"
@@ -238,7 +237,7 @@ static int check_telnet(const char *host, unsigned short port, int timeout, int
zbx_strerror(errno));
}
#endif
- if (SUCCEED == telnet_test_login(s.socket))
+ if (SUCCEED == zbx_telnet_test_login(s.socket))
*value_int = 1;
else
zabbix_log(LOG_LEVEL_DEBUG, "Telnet check error: no login prompt");
diff --git a/src/zabbix_server/alerter/alert_manager.c b/src/zabbix_server/alerter/alert_manager.c
index 36f72f754ad..cb0530fa827 100644
--- a/src/zabbix_server/alerter/alert_manager.c
+++ b/src/zabbix_server/alerter/alert_manager.c
@@ -2199,8 +2199,8 @@ static void am_process_diag_top_sources(zbx_am_t *manager, zbx_ipc_client_t *cli
if (NULL == (source = zbx_hashset_search(&sources, &source_local)))
{
+ source_local.alerts_num = 0;
source = zbx_hashset_insert(&sources, &source_local, sizeof(source_local));
- source->alerts_num = 0;
zbx_vector_ptr_append(&view, source);
}
source->alerts_num++;
diff --git a/src/zabbix_server/ipmi/ipmi_manager.c b/src/zabbix_server/ipmi/ipmi_manager.c
index 1f8cf3ab1a4..6dba5990aa7 100644
--- a/src/zabbix_server/ipmi/ipmi_manager.c
+++ b/src/zabbix_server/ipmi/ipmi_manager.c
@@ -588,13 +588,14 @@ static zbx_ipmi_manager_host_t *ipmi_manager_cache_host(zbx_ipmi_manager_t *mana
zbx_ipmi_manager_host_t host_local;
host_local.hostid = hostid;
- host = (zbx_ipmi_manager_host_t *)zbx_hashset_insert(&manager->hosts, &host_local, sizeof(host_local));
+ host_local.disable_until = 0;
+ host_local.poller = ipmi_manager_get_host_poller(manager);
+ host_local.lastcheck = now;
- host->disable_until = 0;
- host->poller = ipmi_manager_get_host_poller(manager);
+ host = (zbx_ipmi_manager_host_t *)zbx_hashset_insert(&manager->hosts, &host_local, sizeof(host_local));
}
-
- host->lastcheck = now;
+ else
+ host->lastcheck = now;
return host;
}
diff --git a/src/zabbix_server/poller/checks_telnet.c b/src/zabbix_server/poller/checks_telnet.c
index e736c0d33a4..e0c011de7d9 100644
--- a/src/zabbix_server/poller/checks_telnet.c
+++ b/src/zabbix_server/poller/checks_telnet.c
@@ -19,7 +19,6 @@
#include "checks_telnet.h"
-#include "telnet.h"
#include "zbxcomms.h"
#include "log.h"
@@ -57,10 +56,10 @@ static int telnet_run(DC_ITEM *item, AGENT_RESULT *result, const char *encoding)
zbx_strerror(errno)));
}
- if (FAIL == telnet_login(s.socket, item->username, item->password, result))
+ if (FAIL == zbx_telnet_login(s.socket, item->username, item->password, result))
goto tcp_close;
- if (FAIL == telnet_execute(s.socket, item->params, result, encoding))
+ if (FAIL == zbx_telnet_execute(s.socket, item->params, result, encoding))
goto tcp_close;
ret = SUCCEED;
@@ -123,3 +122,5 @@ out:
return ret;
}
+
+#undef TELNET_RUN_KEY
diff --git a/src/zabbix_server/preprocessor/preproc_manager.c b/src/zabbix_server/preprocessor/preproc_manager.c
index 19f21b5c3f5..004eda81111 100644
--- a/src/zabbix_server/preprocessor/preproc_manager.c
+++ b/src/zabbix_server/preprocessor/preproc_manager.c
@@ -1300,9 +1300,10 @@ static void preprocessor_update_history(zbx_preprocessing_manager_t *manager, zb
zbx_preproc_history_t history_local;
history_local.itemid = itemid;
+ zbx_vector_ptr_create(&history_local.history);
+
vault = (zbx_preproc_history_t *)zbx_hashset_insert(&manager->history_cache, &history_local,
sizeof(history_local));
- zbx_vector_ptr_create(&vault->history);
}
zbx_vector_ptr_append_array(&vault->history, history->values, history->values_num);
diff --git a/src/zabbix_server/reporter/report_manager.c b/src/zabbix_server/reporter/report_manager.c
index d1485f0859f..1c1e8dcdbe6 100644
--- a/src/zabbix_server/reporter/report_manager.c
+++ b/src/zabbix_server/reporter/report_manager.c
@@ -1056,21 +1056,30 @@ static void rm_update_cache_reports(zbx_rm_t *manager, int now)
if (NULL == (report = (zbx_rm_report_t *)zbx_hashset_search(&manager->reports, &reportid)))
{
report_local.reportid = reportid;
+ ZBX_STR2UINT64(report_local.userid, row[1]);
+ ZBX_STR2UINT64(report_local.dashboardid, row[3]);
+ report_local.name = zbx_strdup(NULL, row[2]);
+ report_local.timezone = zbx_strdup(NULL, tz);
+ report_local.error = zbx_strdup(NULL, row[12]);
+ ZBX_STR2UCHAR(report_local.period, row[4]);
+ ZBX_STR2UCHAR(report_local.cycle, row[5]);
+ ZBX_STR2UCHAR(report_local.weekdays, row[6]);
+ ZBX_STR2UCHAR(report_local.status, row[14]);
+ report_local.start_time = atoi(row[7]);
+ ZBX_STR2UCHAR(report_local.state, row[11]);
+ report_local.flags = 0;
+ report_local.nextcheck = 0;
+ report_local.active_since = atoi(row[8]);
+ report_local.active_till = atoi(row[9]);
+ report_local.lastsent = atoi(row[13]);
+ zbx_vector_ptr_pair_create(&report_local.params);
+ zbx_vector_recipient_create(&report_local.usergroups);
+ zbx_vector_recipient_create(&report_local.users);
+ zbx_vector_uint64_create(&report_local.users_excl);
+
report = (zbx_rm_report_t *)zbx_hashset_insert(&manager->reports, &report_local,
sizeof(report_local));
- zbx_vector_ptr_pair_create(&report->params);
- zbx_vector_recipient_create(&report->usergroups);
- zbx_vector_recipient_create(&report->users);
- zbx_vector_uint64_create(&report->users_excl);
- report->name = zbx_strdup(NULL, row[2]);
- report->timezone = zbx_strdup(NULL, tz);
- report->nextcheck = 0;
- ZBX_STR2UCHAR(report->state, row[11]);
- report->error = zbx_strdup(NULL, row[12]);
- report->lastsent = atoi(row[13]);
- report->flags = 0;
-
reschedule = 1;
}
else
@@ -1090,17 +1099,17 @@ static void rm_update_cache_reports(zbx_rm_t *manager, int now)
report->timezone = zbx_strdup(report->timezone, tz);
reschedule = 1;
}
- }
- ZBX_STR2UINT64(report->userid, row[1]);
- ZBX_STR2UINT64(report->dashboardid, row[3]);
- ZBX_STR2UCHAR(report->period, row[4]);
- ZBX_STR2UCHAR(report->cycle, row[5]);
- ZBX_STR2UCHAR(report->weekdays, row[6]);
- report->start_time = atoi(row[7]);
- report->active_since = atoi(row[8]);
- report->active_till = atoi(row[9]);
- ZBX_STR2UCHAR(report->status, row[14]);
+ ZBX_STR2UINT64(report->userid, row[1]);
+ ZBX_STR2UINT64(report->dashboardid, row[3]);
+ ZBX_STR2UCHAR(report->period, row[4]);
+ ZBX_STR2UCHAR(report->cycle, row[5]);
+ ZBX_STR2UCHAR(report->weekdays, row[6]);
+ report->start_time = atoi(row[7]);
+ report->active_since = atoi(row[8]);
+ report->active_till = atoi(row[9]);
+ ZBX_STR2UCHAR(report->status, row[14]);
+ }
if (ZBX_REPORT_STATUS_DISABLED == report->status)
{