diff options
author | Aleksejs Sestakovs <aleksejs.sestakovs@zabbix.com> | 2021-10-29 10:38:53 +0300 |
---|---|---|
committer | Aleksejs Sestakovs <aleksejs.sestakovs@zabbix.com> | 2021-10-29 10:38:53 +0300 |
commit | cfa6a85e07a1ad1f2f62696ccf6ad90e2c57f01d (patch) | |
tree | 7c1ccb13d9fd043e6d980ce780deaa3e6b54fb17 | |
parent | 4a42c07a0366684f6bd0f16a4a833b28cc9c493a (diff) |
...G...... [ZBXNEXT-6936] added possibility to reload user parameters without restarting Zabbix Agent
-rw-r--r-- | ChangeLog.d/feature/ZBXNEXT-6936 | 1 | ||||
-rw-r--r-- | include/common.h | 4 | ||||
-rw-r--r-- | include/sysinfo.h | 1 | ||||
-rw-r--r-- | man/zabbix_agentd.man | 5 | ||||
-rw-r--r-- | src/libs/zbxnix/control.c | 6 | ||||
-rw-r--r-- | src/libs/zbxnix/daemon.c | 4 | ||||
-rw-r--r-- | src/libs/zbxsysinfo/sysinfo.c | 30 | ||||
-rw-r--r-- | src/zabbix_agent/active.c | 25 | ||||
-rw-r--r-- | src/zabbix_agent/listener.c | 26 | ||||
-rw-r--r-- | src/zabbix_agent/zabbix_agentd.c | 5 | ||||
-rw-r--r-- | src/zabbix_agent/zbxconf.c | 37 | ||||
-rw-r--r-- | src/zabbix_agent/zbxconf.h | 1 |
12 files changed, 143 insertions, 2 deletions
diff --git a/ChangeLog.d/feature/ZBXNEXT-6936 b/ChangeLog.d/feature/ZBXNEXT-6936 new file mode 100644 index 00000000000..83d5ab23399 --- /dev/null +++ b/ChangeLog.d/feature/ZBXNEXT-6936 @@ -0,0 +1 @@ +...G...... [ZBXNEXT-6936] added possibility to reload user parameters without restarting Zabbix Agent (asestakovs) diff --git a/include/common.h b/include/common.h index d988fe61e5c..9b83feececd 100644 --- a/include/common.h +++ b/include/common.h @@ -447,7 +447,8 @@ zbx_graph_yaxis_types_t; #define ZBX_LOG_LEVEL_DECREASE "log_level_decrease" #define ZBX_SNMP_CACHE_RELOAD "snmp_cache_reload" #define ZBX_DIAGINFO "diaginfo" -#define ZBX_TRIGGER_HOUSEKEEPER_EXECUTE "trigger_housekeeper_execute" +#define ZBX_TRIGGER_HOUSEKEEPER_EXECUTE "trigger_housekeeper_execute" +#define ZBX_USER_PARAMETERS_RELOAD "userparameter_reload" /* value for not supported items */ #define ZBX_NOTSUPPORTED "ZBX_NOTSUPPORTED" @@ -975,6 +976,7 @@ zbx_task_t; #define ZBX_RTC_SECRETS_RELOAD 11 #define ZBX_RTC_SERVICE_CACHE_RELOAD 12 #define ZBX_RTC_TRIGGER_HOUSEKEEPER_EXECUTE 13 +#define ZBX_RTC_USER_PARAMETERS_RELOAD 14 typedef enum { diff --git a/include/sysinfo.h b/include/sysinfo.h index f7c4bc5610f..86b1bde3127 100644 --- a/include/sysinfo.h +++ b/include/sysinfo.h @@ -216,6 +216,7 @@ int process(const char *in_command, unsigned flags, AGENT_RESULT *result); void set_user_parameter_dir(const char *path); int add_user_parameter(const char *itemkey, char *command, char *error, size_t max_error_len); +void remove_user_parameters(void); int add_user_module(const char *key, int (*function)(void)); void test_parameters(void); void test_parameter(const char *key); diff --git a/man/zabbix_agentd.man b/man/zabbix_agentd.man index 2bee4c11985..4ec3ae591b5 100644 --- a/man/zabbix_agentd.man +++ b/man/zabbix_agentd.man @@ -76,6 +76,11 @@ Perform administrative functions according to \fIruntime\-option\fR. Runtime control options .RS 4 .TP 4 +\fBuserparameter_reload +Reload user parameters from the configuration file +.RE +.RS 4 +.TP 4 \fBlog_level_increase\fR[=\fItarget\fR] Increase log level, affects all processes if target is not specified .RE diff --git a/src/libs/zbxnix/control.c b/src/libs/zbxnix/control.c index 0e48c817407..6f4cf49833a 100644 --- a/src/libs/zbxnix/control.c +++ b/src/libs/zbxnix/control.c @@ -231,6 +231,12 @@ int parse_rtc_options(const char *opt, unsigned char program_type, int *message) scope = 0; data = 0; } + else if (0 != (program_type & (ZBX_PROGRAM_TYPE_AGENTD)) && 0 == strcmp(opt, ZBX_USER_PARAMETERS_RELOAD)) + { + command = ZBX_RTC_USER_PARAMETERS_RELOAD; + scope = 0; + data = 0; + } else { zbx_error("invalid runtime control option: %s", opt); diff --git a/src/libs/zbxnix/daemon.c b/src/libs/zbxnix/daemon.c index 3fe8dc3b239..593a63718dd 100644 --- a/src/libs/zbxnix/daemon.c +++ b/src/libs/zbxnix/daemon.c @@ -255,6 +255,10 @@ static void user1_signal_handler(int sig, siginfo_t *siginfo, void *context) case ZBX_RTC_SERVICE_CACHE_RELOAD: zbx_signal_process_by_type(ZBX_PROCESS_TYPE_SERVICEMAN, ZBX_RTC_GET_DATA(flags), flags); break; + case ZBX_RTC_USER_PARAMETERS_RELOAD: + zbx_signal_process_by_type(ZBX_PROCESS_TYPE_ACTIVE_CHECKS, ZBX_RTC_GET_DATA(flags), flags); + zbx_signal_process_by_type(ZBX_PROCESS_TYPE_LISTENER, ZBX_RTC_GET_DATA(flags), flags); + break; default: if (NULL != zbx_sigusr_handler) zbx_sigusr_handler(flags); diff --git a/src/libs/zbxsysinfo/sysinfo.c b/src/libs/zbxsysinfo/sysinfo.c index 872ed360218..b2f5a6f2947 100644 --- a/src/libs/zbxsysinfo/sysinfo.c +++ b/src/libs/zbxsysinfo/sysinfo.c @@ -200,6 +200,36 @@ int add_user_parameter(const char *itemkey, char *command, char *error, size_t m return ret; } + +void remove_user_parameters(void) +{ + int i, usr = -1; + + if (NULL == commands) + return; + + for (i = 0; NULL != commands[i].key; i++) + { + if (0 != (CF_USERPARAMETER & commands[i].flags)) + { + zbx_free(commands[i].key); + zbx_free(commands[i].test_param); + + if (0 > usr) + usr = i; + } + } + + if (0 < usr) + { + commands = (ZBX_METRIC *)zbx_realloc(commands, ((unsigned int)usr + 1) * sizeof(ZBX_METRIC)); + memset(&commands[usr], 0, sizeof(ZBX_METRIC)); + } + else if (0 == usr) + { + zbx_free(commands); + } +} #endif void init_metrics(void) diff --git a/src/zabbix_agent/active.c b/src/zabbix_agent/active.c index bb9ca25357f..a8ae612d081 100644 --- a/src/zabbix_agent/active.c +++ b/src/zabbix_agent/active.c @@ -50,6 +50,10 @@ static ZBX_THREAD_LOCAL zbx_vector_ptr_t regexps; static ZBX_THREAD_LOCAL char *session_token; static ZBX_THREAD_LOCAL zbx_uint64_t last_valueid = 0; +#ifndef _WINDOWS +static volatile sig_atomic_t need_update_userparam = 0; +#endif + static void init_active_metrics(void) { size_t sz; @@ -1254,6 +1258,14 @@ static void update_schedule(int delta) buffer.lastsent += delta; } +#ifndef _WINDOWS +static void zbx_active_checks_sigusr_handler(int flags) +{ + if (ZBX_RTC_USER_PARAMETERS_RELOAD == ZBX_RTC_GET_MSG(flags)) + need_update_userparam = 1; +} +#endif + ZBX_THREAD_ENTRY(active_checks_thread, args) { ZBX_THREAD_ACTIVECHK_ARGS activechk_args; @@ -1283,8 +1295,21 @@ ZBX_THREAD_ENTRY(active_checks_thread, args) #endif init_active_metrics(); +#ifndef _WINDOWS + zbx_set_sigusr_handler(zbx_active_checks_sigusr_handler); +#endif + while (ZBX_IS_RUNNING()) { +#ifndef _WINDOWS + if (1 == need_update_userparam) + { + zbx_setproctitle("active checks #%d [reloading user parameters]", process_num); + reload_user_parameters(); + need_update_userparam = 0; + } +#endif + zbx_update_env(zbx_time()); if ((now = time(NULL)) >= nextsend) diff --git a/src/zabbix_agent/listener.c b/src/zabbix_agent/listener.c index 243836bb568..3733bdfd39a 100644 --- a/src/zabbix_agent/listener.c +++ b/src/zabbix_agent/listener.c @@ -40,6 +40,10 @@ extern ZBX_THREAD_LOCAL int server_num, process_num; #include "zbxcrypto.h" #include "../libs/zbxcrypto/tls_tcp_active.h" +#ifndef _WINDOWS +static volatile sig_atomic_t need_update_userparam = 0; +#endif + static void process_listener(zbx_socket_t *s) { AGENT_RESULT result; @@ -99,6 +103,14 @@ static void process_listener(zbx_socket_t *s) zabbix_log(LOG_LEVEL_DEBUG, "Process listener error: %s", zbx_socket_strerror()); } +#ifndef _WINDOWS +static void zbx_listener_sigusr_handler(int flags) +{ + if (ZBX_RTC_USER_PARAMETERS_RELOAD == ZBX_RTC_GET_MSG(flags)) + need_update_userparam = 1; +} +#endif + ZBX_THREAD_ENTRY(listener_thread, args) { #if defined(HAVE_GNUTLS) || defined(HAVE_OPENSSL) @@ -124,8 +136,22 @@ ZBX_THREAD_ENTRY(listener_thread, args) #if defined(HAVE_GNUTLS) || defined(HAVE_OPENSSL) zbx_tls_init_child(); #endif + +#ifndef _WINDOWS + zbx_set_sigusr_handler(zbx_listener_sigusr_handler); +#endif + while (ZBX_IS_RUNNING()) { +#ifndef _WINDOWS + if (1 == need_update_userparam) + { + zbx_setproctitle("listener #%d [reloading user parameters]", process_num); + reload_user_parameters(); + need_update_userparam = 0; + } +#endif + zbx_setproctitle("listener #%d [waiting for connection]", process_num); ret = zbx_tcp_accept(&s, configured_tls_accept_modes); zbx_update_env(zbx_time()); diff --git a/src/zabbix_agent/zabbix_agentd.c b/src/zabbix_agent/zabbix_agentd.c index 9d517a4162c..612303e7f3f 100644 --- a/src/zabbix_agent/zabbix_agentd.c +++ b/src/zabbix_agent/zabbix_agentd.c @@ -187,6 +187,7 @@ const char *help_message[] = { " -R --runtime-control runtime-option Perform administrative functions", "", " Runtime control options:", + " " ZBX_USER_PARAMETERS_RELOAD " Reload user parameters from the configuration file", " " ZBX_LOG_LEVEL_INCREASE "=target Increase log level, affects all processes if", " target is not specified", " " ZBX_LOG_LEVEL_DECREASE "=target Decrease log level, affects all processes if", @@ -1113,6 +1114,9 @@ int MAIN_ZABBIX_ENTRY(int flags) exit(EXIT_FAILURE); } #endif + + load_user_parameters(CONFIG_USER_PARAMETERS); + if (0 != CONFIG_PASSIVE_FORKS) { if (FAIL == zbx_tcp_listen(&listen_sock, CONFIG_LISTEN_IP, (unsigned short)CONFIG_LISTEN_PORT)) @@ -1451,7 +1455,6 @@ int main(int argc, char **argv) default: zbx_load_config(ZBX_CFG_FILE_REQUIRED, &t); set_user_parameter_dir(CONFIG_USER_PARAMETER_DIR); - load_user_parameters(CONFIG_USER_PARAMETERS); load_aliases(CONFIG_ALIASES); break; } diff --git a/src/zabbix_agent/zbxconf.c b/src/zabbix_agent/zbxconf.c index 6bf3c7ff1fd..041dfbe0864 100644 --- a/src/zabbix_agent/zbxconf.c +++ b/src/zabbix_agent/zbxconf.c @@ -230,6 +230,43 @@ void load_perf_counters(const char **def_lines, const char **eng_lines) break; } } +#else +/****************************************************************************** + * * + * Function: load_config_user_params * + * * + * Purpose: load user parameters from configuration file * + * * + ******************************************************************************/ +static void load_config_user_params(void) +{ + struct cfg_line cfg[] = + { + /* PARAMETER, VAR, TYPE, + MANDATORY, MIN, MAX */ + {"UserParameter", &CONFIG_USER_PARAMETERS, TYPE_MULTISTRING, + PARM_OPT, 0, 0}, + {NULL} + }; + + parse_cfg_file(CONFIG_FILE, cfg, ZBX_CFG_FILE_REQUIRED, ZBX_CFG_NOT_STRICT); +} + +/****************************************************************************** + * * + * Function: reload_user_parameters * + * * + * Purpose: reload user parameters * + * * + ******************************************************************************/ +void reload_user_parameters(void) +{ + remove_user_parameters(); + zbx_strarr_init(&CONFIG_USER_PARAMETERS); + load_config_user_params(); + load_user_parameters(CONFIG_USER_PARAMETERS); + zbx_strarr_free(CONFIG_USER_PARAMETERS); +} #endif /* _WINDOWS */ #ifdef _AIX diff --git a/src/zabbix_agent/zbxconf.h b/src/zabbix_agent/zbxconf.h index a09e41209c0..32ec455d772 100644 --- a/src/zabbix_agent/zbxconf.h +++ b/src/zabbix_agent/zbxconf.h @@ -61,6 +61,7 @@ extern char *CONFIG_TLS_PSK_FILE; void load_aliases(char **lines); void load_user_parameters(char **lines); int load_key_access_rule(const char *value, const struct cfg_line *cfg); +void reload_user_parameters(void); #ifdef _WINDOWS void load_perf_counters(const char **def_lines, const char **eng_lines); #endif |