Skip to content

Commit

Permalink
.......... [DEV-2324] refactored zbxconf private agent library
Browse files Browse the repository at this point in the history
  • Loading branch information
arimdjonokszabbix committed Aug 21, 2023
1 parent be3aa63 commit 676ab81
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 60 deletions.
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2073,6 +2073,7 @@ AC_CONFIG_FILES([
src/zabbix_agent/Makefile
src/zabbix_agent/logfiles/Makefile
src/zabbix_agent/active_checks/Makefile
src/zabbix_agent/agent_conf/Makefile
src/zabbix_agent/listener/Makefile
src/zabbix_get/Makefile
src/zabbix_java/Makefile
Expand Down
6 changes: 3 additions & 3 deletions src/zabbix_agent/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
SUBDIRS = \
listener \
active_checks \
agent_conf \
logfiles

EXTRA_DIST = \
Expand All @@ -13,9 +14,7 @@ sbin_PROGRAMS = zabbix_agentd
noinst_LIBRARIES = libzbxagent.a

libzbxagent_a_SOURCES = \
metrics.h \
zbxconf.c \
zbxconf.h
metrics.h

libzbxagent_a_CFLAGS = \
-DZABBIX_DAEMON \
Expand All @@ -27,6 +26,7 @@ zabbix_agentd_LDADD = \
libzbxagent.a \
active_checks/libzbxactive_checks.a \
listener/libzbxlistener.a \
agent_conf/libagent_conf.a \
logfiles/libzbxlogfiles.a \
$(top_builddir)/src/libs/zbxsysinfo/libzbxagentsysinfo.a \
$(top_builddir)/src/libs/zbxsysinfo/$(ARCH)/libfunclistsysinfo.a \
Expand Down
23 changes: 13 additions & 10 deletions src/zabbix_agent/active_checks/active_checks.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#include "active_checks.h"

#include "../zbxconf.h"
#include "../agent_conf/agent_conf.h"
#include "../logfiles/logfiles.h"
#include "../logfiles/persistent_state.h"

Expand Down Expand Up @@ -842,7 +842,8 @@ static void process_config_item(struct zbx_json *json, const char *config, size_
******************************************************************************/
static int refresh_active_checks(zbx_vector_addr_ptr_t *addrs, const zbx_config_tls_t *config_tls,
zbx_uint32_t *config_revision_local, int config_timeout, const char *config_source_ip,
const char *config_hostname, const char *config_host_metadata, const char *config_host_metadata_item,
const char *config_listen_ip, int config_listen_port, const char *config_hostname,
const char *config_host_metadata, const char *config_host_metadata_item,
const char *config_host_interface, const char *config_host_interface_item)
{
static ZBX_THREAD_LOCAL int last_ret = SUCCEED;
Expand Down Expand Up @@ -880,21 +881,21 @@ static int refresh_active_checks(zbx_vector_addr_ptr_t *addrs, const zbx_config_
config_host_metadata_item);
}

if (NULL != CONFIG_LISTEN_IP)
if (NULL != config_listen_ip)
{
char *p;

if (NULL != (p = strchr(CONFIG_LISTEN_IP, ',')))
if (NULL != (p = strchr(config_listen_ip, ',')))
*p = '\0';

zbx_json_addstring(&json, ZBX_PROTO_TAG_IP, CONFIG_LISTEN_IP, ZBX_JSON_TYPE_STRING);
zbx_json_addstring(&json, ZBX_PROTO_TAG_IP, config_listen_ip, ZBX_JSON_TYPE_STRING);

if (NULL != p)
*p = ',';
}

if (ZBX_DEFAULT_AGENT_PORT != CONFIG_LISTEN_PORT)
zbx_json_adduint64(&json, ZBX_PROTO_TAG_PORT, (zbx_uint64_t)CONFIG_LISTEN_PORT);
if (ZBX_DEFAULT_AGENT_PORT != config_listen_port)
zbx_json_adduint64(&json, ZBX_PROTO_TAG_PORT, (zbx_uint64_t)config_listen_port);

zbx_json_adduint64(&json, ZBX_PROTO_TAG_CONFIG_REVISION, (zbx_uint64_t)*config_revision_local);
zbx_json_addstring(&json, ZBX_PROTO_TAG_SESSION, session_token, ZBX_JSON_TYPE_STRING);
Expand Down Expand Up @@ -1887,7 +1888,8 @@ ZBX_THREAD_ENTRY(active_checks_thread, args)
if (1 == need_update_userparam)
{
zbx_setproctitle("active checks #%d [reloading user parameters]", process_num);
reload_user_parameters(process_type, process_num, activechks_args_in->config_file);
reload_user_parameters(process_type, process_num, activechks_args_in->config_file,
activechks_args_in->config_user_parameters);
need_update_userparam = 0;
}
#endif
Expand Down Expand Up @@ -1917,7 +1919,8 @@ ZBX_THREAD_ENTRY(active_checks_thread, args)

if (FAIL == refresh_active_checks(&activechk_args.addrs, activechks_args_in->zbx_config_tls,
&config_revision_local, activechks_args_in->config_timeout,
activechks_args_in->config_source_ip, config_hostname,
activechks_args_in->config_source_ip, activechks_args_in->config_listen_ip,
activechks_args_in->config_listen_port, config_hostname,
activechks_args_in->config_host_metadata,
activechks_args_in->config_host_metadata_item,
activechks_args_in->config_host_interface,
Expand All @@ -1927,7 +1930,7 @@ ZBX_THREAD_ENTRY(active_checks_thread, args)
}
else
{
nextrefresh = time(NULL) + CONFIG_REFRESH_ACTIVE_CHECKS;
nextrefresh = time(NULL) + activechks_args_in->config_refresh_active_checks;
nextcheck = 0;
}
#if !defined(_WINDOWS) && !defined(__MINGW32__)
Expand Down
4 changes: 4 additions & 0 deletions src/zabbix_agent/active_checks/active_checks.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ typedef struct
char *config_file;
int config_timeout;
const char *config_source_ip;
const char *config_listen_ip;
int config_listen_port;
const char *config_hostname;
const char *config_host_metadata;
const char *config_host_metadata_item;
Expand All @@ -44,6 +46,8 @@ typedef struct
int config_buffer_send;
int config_buffer_size;
int config_eventlog_max_lines_per_second;
int config_refresh_active_checks;
char **config_user_parameters;
}
zbx_thread_activechk_args;

Expand Down
9 changes: 9 additions & 0 deletions src/zabbix_agent/agent_conf/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## Process this file with automake to produce Makefile.in

noinst_LIBRARIES = libagent_conf.a

libagent_conf_a_SOURCES = \
agent_conf.c \
agent_conf.h

libagent_conf_a_CFLAGS = $(TLS_CFLAGS)
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/

#include "zbxconf.h"
#include "agent_conf.h"

#include "zbxsysinfo.h"
#include "zbxstr.h"
Expand Down Expand Up @@ -219,28 +219,29 @@ void load_perf_counters(const char **def_lines, const char **eng_lines)
* Purpose: load user parameters from configuration file *
* *
******************************************************************************/
static int load_config_user_params(const char *config_file)
static int load_config_user_params(const char *config_file, char **config_user_parameters)
{
struct cfg_line cfg[] =
{
/* PARAMETER, VAR, TYPE,
MANDATORY, MIN, MAX */
{"UserParameter", &CONFIG_USER_PARAMETERS, TYPE_MULTISTRING,
{"UserParameter", &config_user_parameters, TYPE_MULTISTRING,
PARM_OPT, 0, 0},
{NULL}
};

return parse_cfg_file(config_file, cfg, ZBX_CFG_FILE_REQUIRED, ZBX_CFG_NOT_STRICT, ZBX_CFG_NO_EXIT_FAILURE);
}

void reload_user_parameters(unsigned char process_type, int process_num, const char *config_file)
void reload_user_parameters(unsigned char process_type, int process_num, const char *config_file,
char **config_user_parameters)
{
char *error = NULL;
zbx_metric_t *metrics_fallback = NULL;

zbx_strarr_init(&CONFIG_USER_PARAMETERS);
zbx_strarr_init(&config_user_parameters);

if (FAIL == load_config_user_params(config_file))
if (FAIL == load_config_user_params(config_file, config_user_parameters))
{
zabbix_log(LOG_LEVEL_ERR, "cannot reload user parameters [%s #%d]: error processing configuration file",
get_process_type_string(process_type), process_num);
Expand All @@ -250,7 +251,7 @@ void reload_user_parameters(unsigned char process_type, int process_num, const c
zbx_get_metrics_copy(&metrics_fallback);
zbx_remove_user_parameters();

if (FAIL == load_user_parameters(CONFIG_USER_PARAMETERS, &error))
if (FAIL == load_user_parameters(config_user_parameters, &error))
{
zbx_set_metrics(metrics_fallback);
zabbix_log(LOG_LEVEL_ERR, "cannot reload user parameters [%s #%d], %s",
Expand All @@ -263,7 +264,7 @@ void reload_user_parameters(unsigned char process_type, int process_num, const c
zabbix_log(LOG_LEVEL_INFORMATION, "user parameters reloaded [%s #%d]", get_process_type_string(process_type),
process_num);
out:
zbx_strarr_free(&CONFIG_USER_PARAMETERS);
zbx_strarr_free(&config_user_parameters);
}
#endif /* _WINDOWS */

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,28 @@
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/

#ifndef ZABBIX_ZBXCONF_H
#define ZABBIX_ZBXCONF_H
#ifndef ZABBIX_AGENT_CONF_H
#define ZABBIX_AGENT_CONF_H

#include "cfg.h"

extern char *CONFIG_HOSTS_ALLOWED;
extern int CONFIG_LISTEN_PORT;
extern int CONFIG_REFRESH_ACTIVE_CHECKS;
extern char *CONFIG_LISTEN_IP;
extern int CONFIG_MAX_LINES_PER_SECOND;
extern char **CONFIG_ALIASES;
extern char **CONFIG_USER_PARAMETERS;
#ifdef _WINDOWS
extern char **CONFIG_PERF_COUNTERS;
extern char **CONFIG_PERF_COUNTERS_EN;
#endif
/* extern char *CONFIG_HOSTS_ALLOWED; */
/* extern int CONFIG_LISTEN_PORT; */
/* extern int CONFIG_REFRESH_ACTIVE_CHECKS; */
/* extern char *CONFIG_LISTEN_IP; */
/* extern int CONFIG_MAX_LINES_PER_SECOND; */
/* extern char **CONFIG_ALIASES; */
/* extern char **CONFIG_USER_PARAMETERS; */
/* #ifdef _WINDOWS */
/* extern char **CONFIG_PERF_COUNTERS; */
/* extern char **CONFIG_PERF_COUNTERS_EN; */
/* #endif */

void load_aliases(char **lines);
int load_user_parameters(char **lines, char **err);
int load_key_access_rule(const char *value, const struct cfg_line *cfg);
void reload_user_parameters(unsigned char process_type, int process_num, const char *config_file);
void reload_user_parameters(unsigned char process_type, int process_num, const char *config_file,
char **config_user_parameters);
#ifdef _WINDOWS
void load_perf_counters(const char **def_lines, const char **eng_lines);
#endif
Expand All @@ -46,4 +47,4 @@ void load_perf_counters(const char **def_lines, const char **eng_lines);
void tl_version(void);
#endif

#endif /* ZABBIX_ZBXCONF_H */
#endif /* ZABBIX_AGENT_CONF_H */
9 changes: 5 additions & 4 deletions src/zabbix_agent/listener/listener.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

#include "listener.h"

#include "../zbxconf.h"
#include "../agent_conf/agent_conf.h"

#include "zbxsysinfo.h"
#include "zbxlog.h"
#include "zbxstr.h"
Expand Down Expand Up @@ -139,7 +140,7 @@ ZBX_THREAD_ENTRY(listener_thread, args)
if (1 == need_update_userparam)
{
zbx_setproctitle("listener #%d [reloading user parameters]", process_num);
reload_user_parameters(process_type, process_num, init_child_args_in->config_file);
reload_user_parameters(process_type, process_num, init_child_args_in->config_file, init_child_args_in->config_user_parameters);
need_update_userparam = 0;
}
#endif
Expand All @@ -155,8 +156,8 @@ ZBX_THREAD_ENTRY(listener_thread, args)
{
zbx_setproctitle("listener #%d [processing request]", process_num);

if ('\0' != *CONFIG_HOSTS_ALLOWED &&
SUCCEED == (ret = zbx_tcp_check_allowed_peers(&s, CONFIG_HOSTS_ALLOWED)))
if ('\0' != *(init_child_args_in->config_hosts_allowed) &&
SUCCEED == (ret = zbx_tcp_check_allowed_peers(&s, init_child_args_in->config_hosts_allowed)))
{
#if defined(HAVE_GNUTLS) || defined(HAVE_OPENSSL)
if (ZBX_TCP_SEC_TLS_CERT != s.connection_type ||
Expand Down
4 changes: 3 additions & 1 deletion src/zabbix_agent/listener/listener.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ typedef struct
zbx_socket_t *listen_sock;
zbx_config_tls_t *zbx_config_tls;
zbx_get_program_type_f zbx_get_program_type_cb_arg;
char *config_file;
const char *config_file;
int config_timeout;
const char *config_hosts_allowed;
char **config_user_parameters;
}
zbx_thread_listener_args;

Expand Down
Loading

0 comments on commit 676ab81

Please sign in to comment.