#include "proxyconfig.h"
#include "proxyconfigwrite/proxyconfigwrite.h"
#include "zbxlog.h"
#include "zbxnix.h"
#include "zbxcachehistory.h"
#include "zbxself.h"
#include "zbxtime.h"
#include "zbxcompress.h"
#include "zbxrtc.h"
#include "zbxcommshigh.h"
#include "zbx_rtc_constants.h"
#include "zbx_host_constants.h"
#include "zbxstr.h"
#include "zbxalgo.h"
static void process_configuration_sync(size_t *data_size, zbx_synced_new_config_t *synced,
const zbx_thread_info_t *thread_info, zbx_thread_proxyconfig_args *args)
{
zbx_socket_t sock;
struct zbx_json_parse jp, jp_kvs_paths = {0};
char value[16], *error = NULL, *buffer = NULL;
size_t buffer_size, reserved;
struct zbx_json j;
int ret = FAIL;
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__);
*data_size = 0;
zbx_json_init(&j, 128);
zbx_json_addstring(&j, "request", ZBX_PROTO_VALUE_PROXY_CONFIG, ZBX_JSON_TYPE_STRING);
zbx_json_addstring(&j, "host", args->config_hostname, ZBX_JSON_TYPE_STRING);
zbx_json_addstring(&j, ZBX_PROTO_TAG_VERSION, ZABBIX_VERSION, ZBX_JSON_TYPE_STRING);
zbx_json_addstring(&j, ZBX_PROTO_TAG_SESSION, zbx_dc_get_session_token(), ZBX_JSON_TYPE_STRING);
zbx_json_adduint64(&j, ZBX_PROTO_TAG_CONFIG_REVISION, zbx_dc_get_received_revision());
if (SUCCEED != zbx_compress(j.buffer, j.buffer_size, &buffer, &buffer_size))
{
zabbix_log(LOG_LEVEL_ERR,"cannot compress data: %s", zbx_compress_strerror());
goto out;
}
reserved = j.buffer_size;
zbx_json_free(&j);
zbx_update_selfmon_counter(thread_info, ZBX_PROCESS_STATE_IDLE);
#define CONFIG_PROXYCONFIG_RETRY 120
if (FAIL == zbx_connect_to_server(&sock, args->config_source_ip, args->config_server_addrs, 600,
args->config_timeout, CONFIG_PROXYCONFIG_RETRY, LOG_LEVEL_WARNING,
args->config_tls))
{
zbx_update_selfmon_counter(thread_info, ZBX_PROCESS_STATE_BUSY);
goto out;
}
#undef CONFIG_PROXYCONFIG_RETRY
zbx_update_selfmon_counter(thread_info, ZBX_PROCESS_STATE_BUSY);
if (SUCCEED != zbx_get_data_from_server(&sock, &buffer, buffer_size, reserved, &error))
{
zabbix_log(LOG_LEVEL_WARNING, "cannot obtain configuration data from server at \"%s\": %s",
sock.peer, error);
goto error;
}
if ('\0' == *sock.buffer)
{
zabbix_log(LOG_LEVEL_WARNING, "cannot obtain configuration data from server at \"%s\": %s",
sock.peer, "empty string received");