diff options
author | Dmitrijs Goloscapovs <dmitrijs.goloscapovs@zabbix.com> | 2021-05-07 10:06:59 +0300 |
---|---|---|
committer | Dmitrijs Goloscapovs <dmitrijs.goloscapovs@zabbix.com> | 2021-05-07 10:09:37 +0300 |
commit | 72a1333026bbe002da23ed93486bd2ea94ffd397 (patch) | |
tree | f184466fc290453be4e9de01ea930f1a8f518d23 /src | |
parent | 67846bcf5817cb0690746136a1b8caa99c832487 (diff) | |
parent | 75eec1586e0426f1fc503d6e4e5b307d5b96e0b6 (diff) |
.......... [ZBXNEXT-6546] Merge branch 'feature/ZBXNEXT-6452-5.3' into feature/ZBXNEXT-6546-5.3
Diffstat (limited to 'src')
-rw-r--r-- | src/libs/zbxdbupgrade/dbupgrade_5030.c | 47 | ||||
-rw-r--r-- | src/libs/zbxserver/evalfunc2.c | 16 | ||||
-rw-r--r-- | src/zabbix_agent/logfiles/logfiles.c | 156 | ||||
-rw-r--r-- | src/zabbix_server/reporter/report_manager.c | 7 |
4 files changed, 173 insertions, 53 deletions
diff --git a/src/libs/zbxdbupgrade/dbupgrade_5030.c b/src/libs/zbxdbupgrade/dbupgrade_5030.c index d707e0da460..58642d87a83 100644 --- a/src/libs/zbxdbupgrade/dbupgrade_5030.c +++ b/src/libs/zbxdbupgrade/dbupgrade_5030.c @@ -25,6 +25,7 @@ #include "zbxalgo.h" #include "zbxjson.h" #include "../zbxalgo/vectorimpl.h" +#include "sysinfo.h" /* * 5.4 development database patches @@ -5129,6 +5130,7 @@ static void dbpatch_update_func_bitand(zbx_dbpatch_function_t *function, const z char **replace) { char *parameter = NULL, *mask = NULL; + int secnum = 0; if (2 <= params->values_num && '\0' != function->parameter[params->values[1].l]) { @@ -5139,8 +5141,20 @@ static void dbpatch_update_func_bitand(zbx_dbpatch_function_t *function, const z else *replace = zbx_dsprintf(NULL, "bitand({" ZBX_FS_UI64 "})", function->functionid); + if (0 < params->values_num) + { + char *param; + + param = zbx_substr_unquote(function->parameter, params->values[0].l, params->values[0].r); + + if ('#' != *param && '{' != *param) + secnum = -1; + + zbx_free(param); + } + dbpatch_convert_params(¶meter, function->parameter, params, - ZBX_DBPATCH_ARG_HIST, 0, 2, + ZBX_DBPATCH_ARG_HIST, secnum, 2, ZBX_DBPATCH_ARG_NONE); dbpatch_update_function(function, "last", parameter, ZBX_DBPATCH_FUNCTION_UPDATE); @@ -5309,9 +5323,17 @@ static void dbpatch_convert_function(zbx_dbpatch_function_t *function, char **re { int secnum = 0; - if (0 < params.values_num && '#' != function->parameter[params.values[0].l] && - '{' != function->parameter[params.values[0].l]) - secnum = -1; + if (0 < params.values_num) + { + char *param; + + param = zbx_substr_unquote(function->parameter, params.values[0].l, params.values[0].r); + + if ('#' != *param && '{' != *param) + secnum = -1; + + zbx_free(param); + } dbpatch_convert_params(¶meter, function->parameter, ¶ms, ZBX_DBPATCH_ARG_HIST, secnum, 1, @@ -5324,9 +5346,24 @@ static void dbpatch_convert_function(zbx_dbpatch_function_t *function, char **re } else if (0 == strcmp(function->name, "strlen")) { + int secnum = 0; + + if (0 < params.values_num) + { + char *param; + + param = zbx_substr_unquote(function->parameter, params.values[0].l, params.values[0].r); + + if ('#' != *param && '{' != *param) + secnum = -1; + + zbx_free(param); + } + dbpatch_convert_params(¶meter, function->parameter, ¶ms, - ZBX_DBPATCH_ARG_HIST, 0, 1, + ZBX_DBPATCH_ARG_HIST, secnum, 1, ZBX_DBPATCH_ARG_NONE); + dbpatch_update_func_strlen(function, parameter, replace); } else if (0 == strcmp(function->name, "logeventid") || 0 == strcmp(function->name, "logsource")) diff --git a/src/libs/zbxserver/evalfunc2.c b/src/libs/zbxserver/evalfunc2.c index 60b09da7a6e..9b0a16f26eb 100644 --- a/src/libs/zbxserver/evalfunc2.c +++ b/src/libs/zbxserver/evalfunc2.c @@ -706,7 +706,7 @@ static void count_one_str(int *count, int op, const char *value, const char *pat * (3) value to compare with (optional) * * Becomes mandatory for numeric items if 3rd * * parameter is specified and is not "regexp" * - * or "iregexp". With "band" can take one of * + * or "iregexp". With "bitand" can take one of * * 2 forms: * * - value_to_compare_with/mask * * - mask * @@ -739,7 +739,7 @@ static int evaluate_COUNT(zbx_variant_t *value, DC_ITEM *item, const char *param numeric_search = (ITEM_VALUE_TYPE_UINT64 == item->value_type || ITEM_VALUE_TYPE_FLOAT == item->value_type); - if (4 < (nparams = num_param(parameters))) + if (3 < (nparams = num_param(parameters))) { *error = zbx_strdup(*error, "invalid number of parameters"); goto out; @@ -790,7 +790,7 @@ static int evaluate_COUNT(zbx_variant_t *value, DC_ITEM *item, const char *param op = OP_REGEXP; else if (0 == strcmp(operator, "iregexp")) op = OP_IREGEXP; - else if (0 == strcmp(operator, "band")) + else if (0 == strcmp(operator, "bitand")) op = OP_BITAND; if (OP_UNKNOWN == op) @@ -1810,7 +1810,7 @@ out: /****************************************************************************** * * - * Function: evaluate_BAND * + * Function: evaluate_BITAND * * * * Purpose: evaluate logical bitwise function 'and' for the item * * * @@ -1829,7 +1829,7 @@ out: * FAIL - failed to evaluate function * * * ******************************************************************************/ -static int evaluate_BAND(zbx_variant_t *value, DC_ITEM *item, const char *parameters, const zbx_timespec_t *ts, +static int evaluate_BITAND(zbx_variant_t *value, DC_ITEM *item, const char *parameters, const zbx_timespec_t *ts, char **error) { char *last_parameters = NULL; @@ -2347,9 +2347,9 @@ int evaluate_function2(zbx_variant_t *value, DC_ITEM *item, const char *function { ret = evaluate_LOGSOURCE(value, item, parameter, ts, error); } - else if (0 == strcmp(function, "band")) + else if (0 == strcmp(function, "bitand")) { - ret = evaluate_BAND(value, item, parameter, ts, error); + ret = evaluate_BITAND(value, item, parameter, ts, error); } else if (0 == strcmp(function, "forecast")) { @@ -2391,7 +2391,7 @@ int evaluate_function2(zbx_variant_t *value, DC_ITEM *item, const char *function int zbx_is_trigger_function(const char *name, size_t len) { char *functions[] = {"last", "min", "max", "avg", "sum", "percentile", "count", "nodata", "change", "find", - "fuzzytime", "logeventid", "logseverity", "logsource", "band", "forecast", "timeleft", + "fuzzytime", "logeventid", "logseverity", "logsource", "bitand", "forecast", "timeleft", "trendavg", "trendcount", "trendmax", "trendmin", "trendsum", NULL}; char **ptr; diff --git a/src/zabbix_agent/logfiles/logfiles.c b/src/zabbix_agent/logfiles/logfiles.c index 667ce6ec8ce..94cb722d0d8 100644 --- a/src/zabbix_agent/logfiles/logfiles.c +++ b/src/zabbix_agent/logfiles/logfiles.c @@ -218,7 +218,7 @@ static int split_filename(const char *filename, char **directory, char **filenam if (0 == S_ISDIR(buf.st_mode)) { - *err_msg = zbx_dsprintf(*err_msg, "Base path \"%s\" is not a directory.", *directory); + *err_msg = zbx_dsprintf(*err_msg, "Base path \"%s\" is not a directory.", ZBX_NULL2STR(*directory)); zbx_free(*directory); zbx_free(*filename_regexp); goto out; @@ -595,6 +595,8 @@ static int examine_md5_and_place(const md5_byte_t *buf1, const md5_byte_t *buf2, * use_ino - [IN] 0 - do not use inodes in comparison, * * 1 - use up to 64-bit inodes in comparison, * * 2 - use 128-bit inodes in comparison. * + * new_files - [IN] new file list * + * num_new - [IN] number of elements in the new file list * * err_msg - [IN/OUT] error message why an item became * * NOTSUPPORTED * * * @@ -610,9 +612,10 @@ static int examine_md5_and_place(const md5_byte_t *buf1, const md5_byte_t *buf2, * * ******************************************************************************/ static int is_same_file_logcpt(const struct st_logfile *old_file, const struct st_logfile *new_file, int use_ino, - char **err_msg) + const struct st_logfile *new_files, int num_new, char **err_msg) { - int is_same_place; + int is_same_place, ret = ZBX_SAME_FILE_NO, found_matching_md5 = 0, same_name_in_new_list = 0, i, f; + md5_byte_t md5tmp[MD5_DIGEST_SIZE]; if (old_file->mtime > new_file->mtime) return ZBX_SAME_FILE_NO; @@ -631,47 +634,102 @@ static int is_same_file_logcpt(const struct st_logfile *old_file, const struct s is_same_place); } - if (0 < old_file->md5size && 0 < new_file->md5size) + if (0 == old_file->md5size || 0 == new_file->md5size) + return ZBX_SAME_FILE_NO; + + /* MD5 sums have been calculated from initial blocks of different sizes */ + + if (old_file->md5size < new_file->md5size) { - /* MD5 sums have been calculated from initial blocks of different sizes */ + if (-1 == (f = open_file_helper(new_file->filename, err_msg))) + return ZBX_SAME_FILE_ERROR; - const struct st_logfile *p_smaller, *p_larger; - int f, ret; - md5_byte_t md5tmp[MD5_DIGEST_SIZE]; + if (SUCCEED == file_start_md5(f, old_file->md5size, md5tmp, new_file->filename, err_msg)) + ret = examine_md5_and_place(old_file->md5buf, md5tmp, sizeof(md5tmp), is_same_place); + else + ret = ZBX_SAME_FILE_ERROR; - if (old_file->md5size < new_file->md5size) + if (0 != close(f) && ZBX_SAME_FILE_ERROR != ret) { - p_smaller = old_file; - p_larger = new_file; + *err_msg = zbx_dsprintf(*err_msg, "Cannot close file \"%s\": %s", + new_file->filename, zbx_strerror(errno)); + ret = ZBX_SAME_FILE_ERROR; } - else + + return ret; + } + + /* old_file->md5size > new_file->md5size. */ + + /* Now it is necessary to read the first 'new_file->md5size' bytes of */ + /* the old file to calculate MD5 sum to compare. Unfortunately we */ + /* cannot reliably use 'old_file->filename' to open the file because: */ + /* - being from the old list it might be no longer available, */ + /* - it can have a different name in the new file list; */ + /* - 'old_file->filename' can be the same as 'new_file->filename' */ + /* (see ZBX-18883) making comparison pointless. */ + + for (i = 0; i < num_new; i++) + { + if ((zbx_uint64_t)new_file->md5size > new_files[i].size) + continue; + + if (0 == strcmp(old_file->filename, new_file->filename) || + 0 == strcmp(new_files[i].filename, new_file->filename)) /* do not compare with self */ { - p_smaller = new_file; - p_larger = old_file; + same_name_in_new_list = 1; + continue; } - if (-1 == (f = open_file_helper(p_larger->filename, err_msg))) + if (-1 == (f = open_file_helper(new_files[i].filename, err_msg))) return ZBX_SAME_FILE_ERROR; - if (SUCCEED == file_start_md5(f, p_smaller->md5size, md5tmp, p_larger->filename, err_msg)) - ret = examine_md5_and_place(p_smaller->md5buf, md5tmp, sizeof(md5tmp), is_same_place); + if (SUCCEED == file_start_md5(f, new_file->md5size, md5tmp, new_files[i].filename, err_msg)) + { + ret = examine_md5_and_place(new_file->md5buf, md5tmp, sizeof(md5tmp), + compare_file_places(old_file, new_files + i, use_ino)); + + if (ZBX_SAME_FILE_YES == ret || ZBX_SAME_FILE_COPY == ret) + found_matching_md5 = 1; + } else ret = ZBX_SAME_FILE_ERROR; - if (0 != close(f)) + if (0 != close(f) && ZBX_SAME_FILE_ERROR != ret) { - if (ZBX_SAME_FILE_ERROR != ret) - { - *err_msg = zbx_dsprintf(*err_msg, "Cannot close file \"%s\": %s", p_larger->filename, - zbx_strerror(errno)); - ret = ZBX_SAME_FILE_ERROR; - } + *err_msg = zbx_dsprintf(*err_msg, "Cannot close file \"%s\": %s", new_files[i].filename, + zbx_strerror(errno)); + ret = ZBX_SAME_FILE_ERROR; } - return ret; + if (0 != found_matching_md5) + break; } - return ZBX_SAME_FILE_NO; + if (0 == found_matching_md5 && 0 == same_name_in_new_list) + { + /* last try - opening file with the name from the old list */ + + if (-1 == (f = open_file_helper(old_file->filename, err_msg))) + return ZBX_SAME_FILE_NO; /* not an error if it is no longer available */ + + if (SUCCEED == file_start_md5(f, new_file->md5size, md5tmp, old_file->filename, err_msg)) + { + ret = examine_md5_and_place(new_file->md5buf, md5tmp, sizeof(md5tmp), + compare_file_places(old_file, new_file, use_ino)); + } + else + ret = ZBX_SAME_FILE_NO; + + if (0 != close(f)) + { + *err_msg = zbx_dsprintf(*err_msg, "Cannot close file \"%s\": %s", old_file->filename, + zbx_strerror(errno)); + ret = ZBX_SAME_FILE_ERROR; + } + } + + return ret; } /****************************************************************************** @@ -688,6 +746,8 @@ static int is_same_file_logcpt(const struct st_logfile *old_file, const struct s * 1 - use up to 64-bit inodes in comparison, * * 2 - use 128-bit inodes in comparison. * * options - [IN] log rotation options * + * new_files - [IN] new file list * + * num_new - [IN] number of elements in the new file list * * err_msg - [IN/OUT] error message why an item became * * NOTSUPPORTED * * * @@ -704,10 +764,10 @@ static int is_same_file_logcpt(const struct st_logfile *old_file, const struct s * * ******************************************************************************/ static int is_same_file_logrt(const struct st_logfile *old_file, const struct st_logfile *new_file, int use_ino, - zbx_log_rotation_options_t options, char **err_msg) + zbx_log_rotation_options_t options, const struct st_logfile *new_files, int num_new, char **err_msg) { if (ZBX_LOG_ROTATION_LOGCPT == options) - return is_same_file_logcpt(old_file, new_file, use_ino, err_msg); + return is_same_file_logcpt(old_file, new_file, use_ino, new_files, num_new, err_msg); if (ZBX_FILE_PLACE_OTHER == compare_file_places(old_file, new_file, use_ino)) { @@ -1187,7 +1247,8 @@ static char *create_old2new_and_copy_of(zbx_log_rotation_options_t rotation_type { for (j = 0; j < num_new; j++) { - switch (is_same_file_logrt(old_files + i, new_files + j, use_ino, rotation_type, err_msg)) + switch (is_same_file_logrt(old_files + i, new_files + j, use_ino, rotation_type, new_files, + num_new, err_msg)) { case ZBX_SAME_FILE_NO: p[j] = '0'; @@ -1821,7 +1882,7 @@ static char *buf_find_newline(char *p, char **p_next, const char *p_end, const c /****************************************************************************** * * - * Function: update_new_list_from_old * + * Function: zbx_read2 * * * * Comments: Thread-safe * * * @@ -2182,10 +2243,10 @@ static int process_log(unsigned char flags, const char *filename, zbx_uint64_t * const char *server, unsigned short port, const char *hostname, const char *key, zbx_uint64_t *processed_bytes, zbx_uint64_t seek_offset) { - int f, ret = FAIL; + int f, ret = FAIL; - zabbix_log(LOG_LEVEL_DEBUG, "In %s() filename:'%s' lastlogsize:" ZBX_FS_UI64 " mtime:%d", - __func__, filename, *lastlogsize, NULL != mtime ? *mtime : 0); + zabbix_log(LOG_LEVEL_DEBUG, "In %s() filename:'%s' lastlogsize:" ZBX_FS_UI64 " mtime:%d seek_offset:" + ZBX_FS_UI64, __func__, filename, *lastlogsize, NULL != mtime ? *mtime : 0, seek_offset); if (-1 == (f = open_file_helper(filename, err_msg))) goto out; @@ -3150,7 +3211,36 @@ int process_logrt(unsigned char flags, const char *filename, zbx_uint64_t *lastl *mtime = logfiles[i].mtime; if (start_idx != i) + { *lastlogsize = logfiles[i].processed_size; + } + else + { + /* When agent starts it can receive from server an out-of-date lastlogsize value, */ + /* larger than current log file size. */ + + if (*lastlogsize > logfiles[i].size) + { + int j, found = 0; + + /* check if there are other log files with the same mtime and size */ + /* greater or equal to lastlogsize */ + for (j = 0; j < logfiles_num; j++) + { + if (i == j || logfiles[i].mtime != logfiles[j].mtime) + continue; + + if (*lastlogsize <= logfiles[j].size) + { + found = 1; + break; + } + } + + if (0 == found) + *lastlogsize = logfiles[i].processed_size; + } + } if (0 == *skip_old_data) { diff --git a/src/zabbix_server/reporter/report_manager.c b/src/zabbix_server/reporter/report_manager.c index fa6faee22cf..6c76cbb73ad 100644 --- a/src/zabbix_server/reporter/report_manager.c +++ b/src/zabbix_server/reporter/report_manager.c @@ -1569,13 +1569,6 @@ static void zbx_report_dst_free(zbx_report_dst_t *dst) zbx_free(dst); } -typedef struct -{ - const char *name; - int min_width; -} -zbx_rm_widget_t; - #define ZBX_REPORT_DEFAULT_WIDTH 1920 #define ZBX_REPORT_DEFAULT_HEIGHT 1080 #define ZBX_REPORT_ROW_HEIGHT 70 |