Source
xxxxxxxxxx
/*
** 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/>.
**/
ZBX_PTR_VECTOR_IMPL(lld_override_operation, zbx_lld_override_operation_t*)
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] lld overrideids, sorted *
* sql - [IN/OUT] sql query buffer *
* sql_alloc - [IN/OUT] sql query buffer size *
* ops - [IN/OUT] 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_lld_override_operation_t *ops)
{
size_t sql_offset = 0;
zbx_db_result_t result;
zbx_db_row_t 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");
zbx_db_add_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 = zbx_db_select("%s", *sql);
while (NULL != (row = zbx_db_fetch(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((const zbx_vector_ptr_t *)ops,
(const void *)&override_operationid, ZBX_DEFAULT_UINT64_PTR_COMPARE_FUNC)))
{
THIS_SHOULD_NEVER_HAPPEN;
continue;
}
op = ops->values[index];
}