Source
xxxxxxxxxx
zbx_rtc_subscribe(process_type, process_num, rtc_msgs, ARRSIZE(rtc_msgs), housekeeper_args_in->config_timeout,
/*
** 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.
**/
/* the maximum number of housekeeping periods to be removed per single housekeeping cycle */
/******************************************************************************
* *
* Purpose: remove outdated information from historical table *
* *
* Parameters: now - current timestamp *
* *
* Return value: number of rows records *
* *
******************************************************************************/
static int delete_history(const char *table, const char *fieldname, int now)
{
DB_RESULT result;
DB_ROW row;
int records = 0;
zbx_uint64_t lastid, maxid;
char *condition = NULL;
zabbix_log(LOG_LEVEL_DEBUG, "In %s() table:'%s' now:%d", __func__, table, now);
zbx_db_begin();
result = zbx_db_select(
"select nextid"
" from ids"
" where table_name='%s'"
" and field_name='%s'",
table, fieldname);
if (NULL == (row = zbx_db_fetch(result)))
goto rollback;
ZBX_STR2UINT64(lastid, row[0]);
zbx_db_free_result(result);
result = zbx_db_select("select max(id) from %s",
table);
if (NULL == (row = zbx_db_fetch(result)) || SUCCEED == zbx_db_is_null(row[0]))
goto rollback;
ZBX_STR2UINT64(maxid, row[0]);
zbx_db_free_result(result);
if (0 != CONFIG_PROXY_LOCAL_BUFFER)
condition = zbx_dsprintf(NULL, " and clock<%d", now - CONFIG_PROXY_LOCAL_BUFFER * SEC_PER_HOUR);
records = zbx_db_execute(
"delete from %s"
" where id<" ZBX_FS_UI64
" and (clock<%d"
" or (id<=" ZBX_FS_UI64 "%s))",
table, maxid,
now - CONFIG_PROXY_OFFLINE_BUFFER * SEC_PER_HOUR,
lastid,
ZBX_NULL2EMPTY_STR(condition));
zbx_free(condition);
zbx_db_commit();