Source
******************************************************************************************************************/
/*
** Zabbix
** Copyright (C) 2001-2023 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
typedef struct
{
unsigned char initialized;
zbx_vector_ptr_t dbinserts;
}
zbx_sql_writer_t;
static zbx_sql_writer_t writer;
typedef void (*vc_str2value_func_t)(zbx_history_value_t *value, zbx_db_row_t row);
/* history table data */
typedef struct
{
/* table name */
const char *name;
/* field list */
const char *fields;
/* string to value converter function, used to convert string value of DB row */
/* to the value of appropriate type */
vc_str2value_func_t rtov;
}
zbx_vc_history_table_t;
/* row to value converters for all value types */
static void row2value_str(zbx_history_value_t *value, zbx_db_row_t row)
{
value->str = zbx_strdup(NULL, row[0]);
}
static void row2value_dbl(zbx_history_value_t *value, zbx_db_row_t row)
{
value->dbl = atof(row[0]);
}
static void row2value_ui64(zbx_history_value_t *value, zbx_db_row_t row)
{
ZBX_STR2UINT64(value->ui64, row[0]);
}
/* timestamp, logeventid, severity, source, value */
static void row2value_log(zbx_history_value_t *value, zbx_db_row_t row)
{
value->log = (zbx_log_value_t *)zbx_malloc(NULL, sizeof(zbx_log_value_t));
value->log->timestamp = atoi(row[0]);
value->log->logeventid = atoi(row[1]);
value->log->severity = atoi(row[2]);
value->log->source = '\0' == *row[3] ? NULL : zbx_strdup(NULL, row[3]);
value->log->value = zbx_strdup(NULL, row[4]);
}
/* value_type - history table data mapping */
static zbx_vc_history_table_t vc_history_tables[] = {
{"history", "value", row2value_dbl},
{"history_str", "value", row2value_str},
{"history_log", "timestamp,logeventid,severity,source,value", row2value_log},
{"history_uint", "value", row2value_ui64},
{"history_text", "value", row2value_str},
{"history_bin", "value", row2value_str}
};
/******************************************************************************************************************