#include "zbxhistory.h"
#include "history.h"
#include "log.h"
#include "zbxalgo.h"
#include "zbxdb.h"
#include "zbxstr.h"
#include "zbxnum.h"
#include "zbxvariant.h"
#include "zbx_dbversion_constants.h"
#if defined(HAVE_LIBCURL) && LIBCURL_VERSION_NUM >= 0x071c00
#define ZBX_HISTORY_STORAGE_DOWN 10000
#define ZBX_IDX_JSON_ALLOCATE 256
#define ZBX_JSON_ALLOCATE 2048
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;
typedef struct
{
char *base_url;
char *post_url;
char *buf;
CURL *handle;
}
zbx_elastic_data_t;
typedef struct
{
unsigned char initialized;
zbx_vector_ptr_t ifaces;
CURLM *handle;
}
zbx_elastic_writer_t;
static zbx_elastic_writer_t writer;
typedef struct
{
char *data;
size_t alloc;
size_t offset;
}
zbx_httppage_t;
static zbx_httppage_t page_r;
typedef struct
{
zbx_httppage_t page;
char errbuf[CURL_ERROR_SIZE];
}
zbx_curlpage_t;
static zbx_curlpage_t page_w[ITEM_VALUE_TYPE_MAX];
static size_t curl_write_cb(void *ptr, size_t size, size_t nmemb, void *userdata)
{
size_t r_size = size * nmemb;
zbx_httppage_t *page = (zbx_httppage_t *)userdata;