Source
xxxxxxxxxx
/*
** Zabbix
** 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 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.
**/
void zbx_lld_override_operation_free(zbx_lld_override_operation_t *override_operation)
{
zbx_vector_db_tag_ptr_clear_ext(&override_operation->tags, zbx_db_tag_free);
zbx_vector_db_tag_ptr_destroy(&override_operation->tags);
zbx_vector_uint64_destroy(&override_operation->templateids);
zbx_free(override_operation->value);
zbx_free(override_operation->delay);
zbx_free(override_operation->history);
zbx_free(override_operation->trends);
zbx_free(override_operation);
}
/******************************************************************************
* *
* Purpose: load tag override operations from database *
* *
* Parameters: overrideids - [IN] the lld overrideids, sorted *
* sql - [IN/OUT] the sql query buffer *
* sql_alloc - [IN/OUT] the sql query buffer size *
* ops - [IN/OUT] the lld override operations, sorted by *
* override_operationid *
* *
******************************************************************************/
static void lld_override_operations_load_tags(const zbx_vector_uint64_t *overrideids, char **sql, size_t *sql_alloc,
zbx_vector_ptr_t *ops)
{
size_t sql_offset = 0;
DB_RESULT result;
DB_ROW row;
zbx_lld_override_operation_t *op = NULL;
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__);
zbx_strcpy_alloc(sql, sql_alloc, &sql_offset,
"select o.lld_override_operationid,ot.tag,ot.value"
" from lld_override_operation o,lld_override_optag ot"
" where o.lld_override_operationid=ot.lld_override_operationid"
" and");
DBadd_condition_alloc(sql, sql_alloc, &sql_offset, "o.lld_overrideid", overrideids->values,
overrideids->values_num);
zbx_snprintf_alloc(sql, sql_alloc, &sql_offset, " and o.operationobject in (%d,%d,%d)",
ZBX_LLD_OVERRIDE_OP_OBJECT_TRIGGER, ZBX_LLD_OVERRIDE_OP_OBJECT_HOST,
ZBX_LLD_OVERRIDE_OP_OBJECT_ITEM);
zbx_strcpy_alloc(sql, sql_alloc, &sql_offset, " order by o.lld_override_operationid");
result = DBselect("%s", *sql);
while (NULL != (row = DBfetch(result)))
{
zbx_uint64_t override_operationid;
zbx_db_tag_t *tag;
ZBX_STR2UINT64(override_operationid, row[0]);
if (NULL == op || op->override_operationid != override_operationid)
{
int index;
if (FAIL == (index = zbx_vector_ptr_bsearch(ops, &override_operationid,
ZBX_DEFAULT_UINT64_PTR_COMPARE_FUNC)))
{
THIS_SHOULD_NEVER_HAPPEN;
continue;
}
op = (zbx_lld_override_operation_t *)ops->values[index];