diff options
-rw-r--r-- | ChangeLog.d/bugfix/ZBX-20638 | 1 | ||||
-rw-r--r-- | include/db.h | 2 | ||||
-rw-r--r-- | include/zbxdb.h | 7 | ||||
-rw-r--r-- | include/zbxhistory.h | 2 | ||||
-rw-r--r-- | src/libs/zbxdb/db.c | 12 | ||||
-rw-r--r-- | src/libs/zbxdbhigh/db.c | 82 | ||||
-rw-r--r-- | src/libs/zbxhistory/history.c | 4 | ||||
-rw-r--r-- | src/libs/zbxhistory/history.h | 2 | ||||
-rw-r--r-- | src/libs/zbxhistory/history_elastic.c | 46 | ||||
-rw-r--r-- | src/zabbix_proxy/proxy.c | 30 | ||||
-rw-r--r-- | src/zabbix_server/server.c | 40 | ||||
-rw-r--r-- | tests/zbxmocktest.c | 2 | ||||
-rw-r--r-- | ui/app/partials/administration.system.info.php | 46 | ||||
-rw-r--r-- | ui/include/defines.inc.php | 14 |
14 files changed, 187 insertions, 103 deletions
diff --git a/ChangeLog.d/bugfix/ZBX-20638 b/ChangeLog.d/bugfix/ZBX-20638 new file mode 100644 index 00000000000..e304073e81e --- /dev/null +++ b/ChangeLog.d/bugfix/ZBX-20638 @@ -0,0 +1 @@ +..F....PS. [ZBX-20638] fixed handling of db version higher than supported (agriscenko, dgoloscapov) diff --git a/include/db.h b/include/db.h index 0a229773850..e2a192fd56c 100644 --- a/include/db.h +++ b/include/db.h @@ -945,4 +945,6 @@ void zbx_db_trigger_get_itemids(const DB_TRIGGER *trigger, zbx_vector_uint64_t * int DBselect_ids_names(const char *sql, zbx_vector_uint64_t *ids, zbx_vector_str_t *names); +int DBcheck_version_info(struct zbx_db_version_info_t *info, int allow_unsupported); + #endif diff --git a/include/zbxdb.h b/include/zbxdb.h index 4bdf66eb568..751ccc969d0 100644 --- a/include/zbxdb.h +++ b/include/zbxdb.h @@ -177,7 +177,8 @@ int zbx_db_strlen_n(const char *text_loc, size_t maxlen); #define ZBX_ORACLE_MAX_VERSION_FRIENDLY "Database 21c Release 21.x.x" #define ZBX_ELASTIC_MIN_VERSION 70000 -#define ZBX_ELASTIC_MIN_VERSION_FRIENDLY "7.x" +#define ZBX_ELASTIC_SUPPORTED_VERSION_FRIENDLY "7.x" +#define ZBX_ELASTIC_MAX_VERSION 79999 #define ZBX_DBVERSION_UNDEFINED 0 @@ -188,7 +189,9 @@ typedef enum DB_VERSION_HIGHER_THAN_MAXIMUM, DB_VERSION_FAILED_TO_RETRIEVE, DB_VERSION_NOT_SUPPORTED_ERROR, - DB_VERSION_NOT_SUPPORTED_WARNING + DB_VERSION_NOT_SUPPORTED_WARNING, + DB_VERSION_HIGHER_THAN_MAXIMUM_ERROR, + DB_VERSION_HIGHER_THAN_MAXIMUM_WARNING, } zbx_db_version_status_t; diff --git a/include/zbxhistory.h b/include/zbxhistory.h index 8f3e85cfb0b..d0fdaa7d157 100644 --- a/include/zbxhistory.h +++ b/include/zbxhistory.h @@ -61,7 +61,7 @@ int zbx_history_get_values(zbx_uint64_t itemid, int value_type, int start, int c zbx_vector_history_record_t *values); int zbx_history_requires_trends(int value_type); -void zbx_history_check_version(struct zbx_json *json); +void zbx_history_check_version(struct zbx_json *json, int *result); #define FLUSH_SUCCEED 0 #define FLUSH_FAIL -1 diff --git a/src/libs/zbxdb/db.c b/src/libs/zbxdb/db.c index a5a461bb9e2..0ec070cea26 100644 --- a/src/libs/zbxdb/db.c +++ b/src/libs/zbxdb/db.c @@ -64,15 +64,15 @@ struct zbx_db_result #endif }; -static int txn_level = 0; /* transaction level, nested transactions are not supported */ -static int txn_error = ZBX_DB_OK; /* failed transaction */ -static int txn_end_error = ZBX_DB_OK; /* transaction result */ +static int txn_level = 0; /* transaction level, nested transactions are not supported */ +static int txn_error = ZBX_DB_OK; /* failed transaction */ +static int txn_end_error = ZBX_DB_OK; /* transaction result */ -static char *last_db_strerror = NULL; /* last database error message */ +static char *last_db_strerror = NULL; /* last database error message */ -extern int CONFIG_LOG_SLOW_QUERIES; +extern int CONFIG_LOG_SLOW_QUERIES; -static int db_auto_increment; +static int db_auto_increment; #if defined(HAVE_MYSQL) static MYSQL *conn = NULL; diff --git a/src/libs/zbxdbhigh/db.c b/src/libs/zbxdbhigh/db.c index 10cc3f670c6..8728afda42e 100644 --- a/src/libs/zbxdbhigh/db.c +++ b/src/libs/zbxdbhigh/db.c @@ -820,6 +820,88 @@ void DBflush_version_requirements(const char *version) zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __func__); } +/********************************************************************************* + * * + * Purpose: verify that Zabbix server/proxy will start with provided DB version * + * and configuration * + * * + * Parameters: allow_unsupported - [IN] value of AllowUnsupportedDBVersions flag * + * * + *********************************************************************************/ +int DBcheck_version_info(struct zbx_db_version_info_t *info, int allow_unsupported) +{ + DBextract_version_info(info); + + if (DB_VERSION_NOT_SUPPORTED_ERROR == info->flag || + DB_VERSION_HIGHER_THAN_MAXIMUM == info->flag || DB_VERSION_LOWER_THAN_MINIMUM == info->flag) + { + const char *program_type_s; + int server_db_deprecated; + + program_type_s = get_program_type_string(program_type); + + server_db_deprecated = (DB_VERSION_LOWER_THAN_MINIMUM == info->flag && + 0 != (program_type & ZBX_PROGRAM_TYPE_SERVER)); + + if (0 == allow_unsupported || 0 != server_db_deprecated) + { + zabbix_log(LOG_LEVEL_ERR, " "); + zabbix_log(LOG_LEVEL_ERR, "Unable to start Zabbix %s due to unsupported %s database" + " version (%s).", program_type_s, info->database, + info->friendly_current_version); + + if (DB_VERSION_HIGHER_THAN_MAXIMUM == info->flag) + { + zabbix_log(LOG_LEVEL_ERR, "Must not be higher than (%s).", + info->friendly_max_version); + info->flag = DB_VERSION_HIGHER_THAN_MAXIMUM_ERROR; + } + else + { + zabbix_log(LOG_LEVEL_ERR, "Must be at least (%s).", + info->friendly_min_supported_version); + } + + zabbix_log(LOG_LEVEL_ERR, "Use of supported database version is highly recommended."); + + if (0 == server_db_deprecated) + { + zabbix_log(LOG_LEVEL_ERR, "Override by setting AllowUnsupportedDBVersions=1" + " in Zabbix %s configuration file at your own risk.", program_type_s); + } + + zabbix_log(LOG_LEVEL_ERR, " "); + + return FAIL; + } + else + { + zabbix_log(LOG_LEVEL_ERR, " "); + zabbix_log(LOG_LEVEL_ERR, "Warning! Unsupported %s database version (%s).", + info->database, info->friendly_current_version); + + if (DB_VERSION_HIGHER_THAN_MAXIMUM == info->flag) + { + zabbix_log(LOG_LEVEL_ERR, "Should not be higher than (%s).", + info->friendly_max_version); + info->flag = DB_VERSION_HIGHER_THAN_MAXIMUM_WARNING; + } + else + { + zabbix_log(LOG_LEVEL_ERR, "Should be at least (%s).", + info->friendly_min_supported_version); + info->flag = DB_VERSION_NOT_SUPPORTED_WARNING; + } + + zabbix_log(LOG_LEVEL_ERR, "Use of supported database version is highly recommended."); + zabbix_log(LOG_LEVEL_ERR, " "); + } + } + + return SUCCEED; +} + + /****************************************************************************** * * * Purpose: checks DBMS for optional features and exit if is not suitable * diff --git a/src/libs/zbxhistory/history.c b/src/libs/zbxhistory/history.c index 4b364e88202..25e617b0f11 100644 --- a/src/libs/zbxhistory/history.c +++ b/src/libs/zbxhistory/history.c @@ -435,8 +435,8 @@ void zbx_history_value2variant(const history_value_t *value, unsigned char value * functions * * * ******************************************************************************/ -void zbx_history_check_version(struct zbx_json *json) +void zbx_history_check_version(struct zbx_json *json, int *result) { if (NULL != CONFIG_HISTORY_STORAGE_URL) - zbx_elastic_version_extract(json); + zbx_elastic_version_extract(json, result); } diff --git a/src/libs/zbxhistory/history.h b/src/libs/zbxhistory/history.h index 948e81e0e01..7d84a98fe17 100644 --- a/src/libs/zbxhistory/history.h +++ b/src/libs/zbxhistory/history.h @@ -57,7 +57,7 @@ int zbx_history_sql_init(zbx_history_iface_t *hist, unsigned char value_type, ch /* elastic hist */ int zbx_history_elastic_init(zbx_history_iface_t *hist, unsigned char value_type, char **error); -void zbx_elastic_version_extract(struct zbx_json *json); +void zbx_elastic_version_extract(struct zbx_json *json, int *result); zbx_uint32_t zbx_elastic_version_get(void); #endif diff --git a/src/libs/zbxhistory/history_elastic.c b/src/libs/zbxhistory/history_elastic.c index 85fd5390359..28f68b152b3 100644 --- a/src/libs/zbxhistory/history_elastic.c +++ b/src/libs/zbxhistory/history_elastic.c @@ -37,6 +37,7 @@ const char *value_type_str[] = {"dbl", "str", "log", "uint", "text"}; extern char *CONFIG_HISTORY_STORAGE_URL; extern int CONFIG_HISTORY_STORAGE_PIPELINES; +extern int CONFIG_ALLOW_UNSUPPORTED_DB_VERSIONS; static zbx_uint32_t ZBX_ELASTIC_SVERSION = ZBX_DBVERSION_UNDEFINED; @@ -997,7 +998,7 @@ int zbx_history_elastic_init(zbx_history_iface_t *hist, unsigned char value_type * the response string * * * ************************************************************************************/ -void zbx_elastic_version_extract(struct zbx_json *json) +void zbx_elastic_version_extract(struct zbx_json *json, int *result) { #define RIGHT2(x) ((int)((zbx_uint32_t)(x) - ((zbx_uint32_t)((x)/100))*100)) zbx_httppage_t page; @@ -1089,11 +1090,45 @@ out: db_version_info.database = "ElasticDB"; db_version_info.friendly_current_version = version_friendly; - db_version_info.friendly_min_version = ZBX_ELASTIC_MIN_VERSION_FRIENDLY; - db_version_info.friendly_max_version = ""; + db_version_info.friendly_min_version = ZBX_ELASTIC_SUPPORTED_VERSION_FRIENDLY; + db_version_info.friendly_max_version = ZBX_ELASTIC_SUPPORTED_VERSION_FRIENDLY; db_version_info.friendly_min_supported_version = NULL; + db_version_info.flag = zbx_db_version_check(db_version_info.database, version, ZBX_ELASTIC_MIN_VERSION, - ZBX_DBVERSION_UNDEFINED, ZBX_DBVERSION_UNDEFINED); + ZBX_ELASTIC_MAX_VERSION, ZBX_DBVERSION_UNDEFINED); + + if (DB_VERSION_HIGHER_THAN_MAXIMUM == db_version_info.flag) + { + if (0 == CONFIG_ALLOW_UNSUPPORTED_DB_VERSIONS) + { + zabbix_log(LOG_LEVEL_ERR, " "); + zabbix_log(LOG_LEVEL_ERR, "Unable to start Zabbix server due to unsupported %s database server" + " version (%s).", db_version_info.database, + db_version_info.friendly_current_version); + + zabbix_log(LOG_LEVEL_ERR, "Must be up to (%s).", + db_version_info.friendly_max_version); + + zabbix_log(LOG_LEVEL_ERR, "Use of supported database version is highly recommended."); + zabbix_log(LOG_LEVEL_ERR, "Override by setting AllowUnsupportedDBVersions=1" + " in Zabbix server configuration file at your own risk."); + zabbix_log(LOG_LEVEL_ERR, " "); + + db_version_info.flag = DB_VERSION_HIGHER_THAN_MAXIMUM_ERROR; + *result = FAIL; + } + else + { + zabbix_log(LOG_LEVEL_ERR, " "); + zabbix_log(LOG_LEVEL_ERR, "Warning! Unsupported %s database server version (%s).", + db_version_info.database, db_version_info.friendly_current_version); + zabbix_log(LOG_LEVEL_ERR, "Use of supported database version is highly recommended."); + zabbix_log(LOG_LEVEL_ERR, " "); + + db_version_info.flag = DB_VERSION_HIGHER_THAN_MAXIMUM_WARNING; + } + } + db_version_info.history_pk = 0; zbx_db_version_json_create(json, &db_version_info); @@ -1120,9 +1155,10 @@ int zbx_history_elastic_init(zbx_history_iface_t *hist, unsigned char value_type return FAIL; } -void zbx_elastic_version_extract(struct zbx_json *json) +void zbx_elastic_version_extract(struct zbx_json *json, int *result) { ZBX_UNUSED(json); + ZBX_UNUSED(result); } zbx_uint32_t zbx_elastic_version_get(void) diff --git a/src/zabbix_proxy/proxy.c b/src/zabbix_proxy/proxy.c index 1cc1e191c0b..650ce7eb359 100644 --- a/src/zabbix_proxy/proxy.c +++ b/src/zabbix_proxy/proxy.c @@ -1040,34 +1040,10 @@ static void zbx_check_db(void) { struct zbx_db_version_info_t db_version_info; - DBextract_version_info(&db_version_info); - - if (DB_VERSION_NOT_SUPPORTED_ERROR == db_version_info.flag) + if (FAIL == DBcheck_version_info(&db_version_info, CONFIG_ALLOW_UNSUPPORTED_DB_VERSIONS)) { - if (0 == CONFIG_ALLOW_UNSUPPORTED_DB_VERSIONS) - { - zabbix_log(LOG_LEVEL_ERR, " "); - zabbix_log(LOG_LEVEL_ERR, "Unable to start Zabbix proxy due to unsupported %s database server" - " version (%s)", db_version_info.database, - db_version_info.friendly_current_version); - zabbix_log(LOG_LEVEL_ERR, "Must be at least (%s)", - db_version_info.friendly_min_supported_version); - zabbix_log(LOG_LEVEL_ERR, "Use of supported database version is highly recommended."); - zabbix_log(LOG_LEVEL_ERR, "Override by setting AllowUnsupportedDBVersions=1" - " in Zabbix proxy configuration file at your own risk."); - zabbix_log(LOG_LEVEL_ERR, " "); - exit(EXIT_FAILURE); - } - else - { - zabbix_log(LOG_LEVEL_ERR, " "); - zabbix_log(LOG_LEVEL_ERR, "Warning! Unsupported %s database server version (%s)", - db_version_info.database, db_version_info.friendly_current_version); - zabbix_log(LOG_LEVEL_ERR, "Should be at least (%s)", - db_version_info.friendly_min_supported_version); - zabbix_log(LOG_LEVEL_ERR, "Use of supported database version is highly recommended."); - zabbix_log(LOG_LEVEL_ERR, " "); - } + zbx_free(db_version_info.friendly_current_version); + exit(EXIT_FAILURE); } zbx_free(db_version_info.friendly_current_version); diff --git a/src/zabbix_server/server.c b/src/zabbix_server/server.c index 85eea5ce8ae..e9647901308 100644 --- a/src/zabbix_server/server.c +++ b/src/zabbix_server/server.c @@ -1094,43 +1094,7 @@ static void zbx_check_db(void) struct zbx_json db_version_json; int result = SUCCEED; - DBextract_version_info(&db_version_info); - - if (db_version_info.current_version < db_version_info.min_version) - { - zabbix_log(LOG_LEVEL_ERR, "Error! Current %s database server version is too old (%s)", - db_version_info.database, db_version_info.friendly_current_version); - zabbix_log(LOG_LEVEL_ERR, "Must be a least %s", db_version_info.friendly_min_version); - result = FAIL; - } - else if (DB_VERSION_NOT_SUPPORTED_ERROR == db_version_info.flag) - { - if (0 == CONFIG_ALLOW_UNSUPPORTED_DB_VERSIONS) - { - zabbix_log(LOG_LEVEL_ERR, " "); - zabbix_log(LOG_LEVEL_ERR, "Unable to start Zabbix server due to unsupported %s database server" - " version (%s)", db_version_info.database, - db_version_info.friendly_current_version); - zabbix_log(LOG_LEVEL_ERR, "Must be at least (%s)", - db_version_info.friendly_min_supported_version); - zabbix_log(LOG_LEVEL_ERR, "Use of supported database version is highly recommended."); - zabbix_log(LOG_LEVEL_ERR, "Override by setting AllowUnsupportedDBVersions=1" - " in Zabbix server configuration file at your own risk."); - zabbix_log(LOG_LEVEL_ERR, " "); - result = FAIL; - } - else - { - zabbix_log(LOG_LEVEL_ERR, " "); - zabbix_log(LOG_LEVEL_ERR, "Warning! Unsupported %s database server version (%s)", - db_version_info.database, db_version_info.friendly_current_version); - zabbix_log(LOG_LEVEL_ERR, "Should be at least (%s)", - db_version_info.friendly_min_supported_version); - zabbix_log(LOG_LEVEL_ERR, "Use of supported database version is highly recommended."); - zabbix_log(LOG_LEVEL_ERR, " "); - db_version_info.flag = DB_VERSION_NOT_SUPPORTED_WARNING; - } - } + result = DBcheck_version_info(&db_version_info, CONFIG_ALLOW_UNSUPPORTED_DB_VERSIONS); if(SUCCEED == result && (SUCCEED != DBcheck_capabilities(db_version_info.current_version) || SUCCEED != DBcheck_version())) @@ -1157,7 +1121,7 @@ static void zbx_check_db(void) zbx_db_version_json_create(&db_version_json, &db_version_info); if (SUCCEED == result) - zbx_history_check_version(&db_version_json); + zbx_history_check_version(&db_version_json, &result); DBflush_version_requirements(db_version_json.buffer); zbx_json_free(&db_version_json); diff --git a/tests/zbxmocktest.c b/tests/zbxmocktest.c index bc42f2fc478..59dd2f8cc88 100644 --- a/tests/zbxmocktest.c +++ b/tests/zbxmocktest.c @@ -135,6 +135,8 @@ int CONFIG_PROXYPOLLER_FORKS = 1; /* parameters for passive proxies */ int CONFIG_PROXYCONFIG_FREQUENCY = 0; int CONFIG_PROXYDATA_FREQUENCY = 1; /* 1s */ +int CONFIG_ALLOW_UNSUPPORTED_DB_VERSIONS = 0; + char *CONFIG_LOAD_MODULE_PATH = NULL; char **CONFIG_LOAD_MODULE = NULL; diff --git a/ui/app/partials/administration.system.info.php b/ui/app/partials/administration.system.info.php index 57edd77da06..294586952b9 100644 --- a/ui/app/partials/administration.system.info.php +++ b/ui/app/partials/administration.system.info.php @@ -135,39 +135,55 @@ if (array_key_exists('history_pk', $data['system_info']) && !$data['system_info' // Check DB version. if ($data['user_type'] == USER_TYPE_SUPER_ADMIN) { foreach ($data['system_info']['dbversion_status'] as $dbversion) { - if ($dbversion['flag'] == DB_VERSION_SUPPORTED) { - continue; - } - switch ($dbversion['flag']) { case DB_VERSION_LOWER_THAN_MINIMUM: - $error = _s('Minimum required %1$s database version is %2$s.', $dbversion['database'], - $dbversion['min_version'] - ); + $error = _s('Error! Unable to start Zabbix server.').' '. + _s('Minimum required %1$s database version is %2$s.', $dbversion['database'], + $dbversion['min_version'] + ); break; case DB_VERSION_HIGHER_THAN_MAXIMUM: - $error = _s('Maximum required %1$s database version is %2$s.', $dbversion['database'], - $dbversion['max_version'] - ); + $error = _s('Error! Unable to start Zabbix server.').' '. + _s('Maximum required %1$s database version is %2$s.', $dbversion['database'], + $dbversion['max_version'] + ); break; case DB_VERSION_FAILED_TO_RETRIEVE: - $error = _('Unable to retrieve database version.'); + $error = _('Warning! Unable to retrieve database version.'); $dbversion['current_version'] = ''; break; case DB_VERSION_NOT_SUPPORTED_ERROR: - $error = _s('Error! Unable to start Zabbix server due to unsupported %1$s database server version. Must be at least (%2$s)', - $dbversion['database'], $dbversion['min_supported_version'] - ); + $error = _s('Error! Unable to start Zabbix server.').' '. + _s('Unsupported %1$s database server version. Must be at least %2$s.', $dbversion['database'], + $dbversion['min_supported_version'] + ); break; case DB_VERSION_NOT_SUPPORTED_WARNING: - $error = _s('Warning! Unsupported %1$s database server version. Should be at least (%2$s)', + $error = _s('Warning! Unsupported %1$s database server version. Should be at least %2$s.', $dbversion['database'], $dbversion['min_supported_version'] ); break; + + case DB_VERSION_HIGHER_THAN_MAXIMUM_ERROR: + $error = _s('Error! Unable to start Zabbix server.').' '. + _s('Unsupported %1$s database server version. Must not be higher than %2$s.', + $dbversion['database'], $dbversion['max_version'] + ); + break; + + case DB_VERSION_HIGHER_THAN_MAXIMUM_WARNING: + $error = _s('Warning! Unsupported %1$s database server version. Should not be higher than %2$s.', + $dbversion['database'], $dbversion['max_version'] + ); + break; + + case DB_VERSION_SUPPORTED: + default: + continue 2; } $info_table->addRow( diff --git a/ui/include/defines.inc.php b/ui/include/defines.inc.php index 9a98800c194..ab614c47714 100644 --- a/ui/include/defines.inc.php +++ b/ui/include/defines.inc.php @@ -24,12 +24,14 @@ define('ZABBIX_EXPORT_VERSION', '6.0'); define('ZABBIX_DB_VERSION', 6000000); -define('DB_VERSION_SUPPORTED', 0); -define('DB_VERSION_LOWER_THAN_MINIMUM', 1); -define('DB_VERSION_HIGHER_THAN_MAXIMUM', 2); -define('DB_VERSION_FAILED_TO_RETRIEVE', 3); -define('DB_VERSION_NOT_SUPPORTED_ERROR', 4); -define('DB_VERSION_NOT_SUPPORTED_WARNING', 5); +define('DB_VERSION_SUPPORTED', 0); +define('DB_VERSION_LOWER_THAN_MINIMUM', 1); +define('DB_VERSION_HIGHER_THAN_MAXIMUM', 2); +define('DB_VERSION_FAILED_TO_RETRIEVE', 3); +define('DB_VERSION_NOT_SUPPORTED_ERROR', 4); +define('DB_VERSION_NOT_SUPPORTED_WARNING', 5); +define('DB_VERSION_HIGHER_THAN_MAXIMUM_ERROR', 6); +define('DB_VERSION_HIGHER_THAN_MAXIMUM_WARNING', 7); define('ZABBIX_COPYRIGHT_FROM', '2001'); define('ZABBIX_COPYRIGHT_TO', '2022'); |