Source
size_t pb_autoreg_estimate_row_size(const char *host, const char *host_metadata, const char *ip, const char *dns)
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** 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 Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
static zbx_history_table_t areg = {
"proxy_autoreg_host", "autoreg_host_lastid",
{
{"clock", ZBX_PROTO_TAG_CLOCK, ZBX_JSON_TYPE_INT, NULL},
{"host", ZBX_PROTO_TAG_HOST, ZBX_JSON_TYPE_STRING, NULL},
{"listen_ip", ZBX_PROTO_TAG_IP, ZBX_JSON_TYPE_STRING, ""},
{"listen_dns", ZBX_PROTO_TAG_DNS, ZBX_JSON_TYPE_STRING, ""},
{"listen_port", ZBX_PROTO_TAG_PORT, ZBX_JSON_TYPE_INT, "0"},
{"host_metadata", ZBX_PROTO_TAG_HOST_METADATA, ZBX_JSON_TYPE_STRING, ""},
{"flags", ZBX_PROTO_TAG_FLAGS, ZBX_JSON_TYPE_INT, "0"},
{"tls_accepted", ZBX_PROTO_TAG_TLS_ACCEPTED, ZBX_JSON_TYPE_INT, "0"},
{0}
}
};
static void pb_autoreg_write_host_db(zbx_uint64_t id, const char *host, const char *ip, const char *dns,
unsigned short port, unsigned int connection_type, const char *host_metadata, int flags, int clock)
{
zbx_db_insert_t db_insert;
zbx_db_insert_prepare(&db_insert, "proxy_autoreg_host", "id", "host", "listen_ip", "listen_dns", "listen_port",
"tls_accepted", "host_metadata", "flags", "clock", (char *)NULL);
zbx_db_insert_add_values(&db_insert, id, host, ip, dns, (int)port, (int)connection_type, host_metadata,
flags, clock);
zbx_db_insert_execute(&db_insert);
zbx_db_insert_clean(&db_insert);
}
/******************************************************************************
* *
* Purpose: write host data into autoregistraion data cache *
* *
******************************************************************************/
static int pb_autoreg_get_db(struct zbx_json *j, zbx_uint64_t *lastid, int *more)
{
int records_num = 0;
zbx_uint64_t id;
id = pb_get_lastid(areg.table, areg.lastidfield);
/* get history data in batches by ZBX_MAX_HRECORDS records and stop if: */
/* 1) there are no more data to read */
/* 2) we have retrieved more than the total maximum number of records */
/* 3) we have gathered more than half of the maximum packet size */
while (ZBX_DATA_JSON_BATCH_LIMIT > j->buffer_offset)
{
pb_get_rows_db(j, ZBX_PROTO_TAG_AUTOREGISTRATION, &areg, lastid, &id, &records_num, more);
if (ZBX_PROXY_DATA_DONE == *more || ZBX_MAX_HRECORDS_TOTAL <= records_num)
break;
}
if (0 != records_num)
zbx_json_close(j);
return records_num;
}
/******************************************************************************
* *
* Purpose: free autoregistration record *
* *
******************************************************************************/
void pb_list_free_autoreg(zbx_list_t *list, zbx_pb_autoreg_t *row)