Source
xxxxxxxxxx
void um_cache_resolve(const zbx_um_cache_t *cache, const zbx_uint64_t *hostids, int hostids_num, const char *macro,
/*
** 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(um_macro, zbx_um_macro_t *)
ZBX_PTR_VECTOR_IMPL(um_host, zbx_um_host_t *)
typedef enum
{
ZBX_UM_UPDATE_HOST,
ZBX_UM_UPDATE_MACRO
}
zbx_um_update_cause_t;
/*********************************************************************************
* *
* Purpose: create duplicate user macro cache *
* *
* Parameters: cache - [IN] the user macro cache to duplicate *
* *
* Return value: The duplicated user macro cache. *
* *
* Comments: The internal structures are duplicated copying references of *
* cached objects and incrementing their reference counters. *
* *
*********************************************************************************/
static zbx_um_cache_t *um_cache_dup(zbx_um_cache_t *cache)
{
zbx_um_cache_t *dup;
zbx_um_host_t **phost;
zbx_hashset_iter_t iter;
dup = (zbx_um_cache_t *)dbconfig_shmem_malloc_func(NULL, sizeof(zbx_um_cache_t));
dup->refcount = 1;
zbx_hashset_copy(&dup->hosts, &cache->hosts, sizeof(zbx_um_host_t *));
zbx_hashset_iter_reset(&dup->hosts, &iter);
while (NULL != (phost = (zbx_um_host_t **)zbx_hashset_iter_next(&iter)))
(*phost)->refcount++;
return dup;
}
/* macro sorting */
static int um_macro_compare_by_name_context(const void *d1, const void *d2)
{
const zbx_um_macro_t *m1 = *(const zbx_um_macro_t * const *)d1;
const zbx_um_macro_t *m2 = *(const zbx_um_macro_t * const *)d2;
int ret;
if (0 != (ret = strcmp(m1->name, m2->name)))
return ret;
/* ZBX_CONDITION_OPERATOR_EQUAL (0) has higher priority than ZBX_CONDITION_OPERATOR_REGEXP (8) */
ZBX_RETURN_IF_NOT_EQUAL(m1->context_op, m2->context_op);
return zbx_strcmp_null(m1->context, m2->context);
}
/* host hashset support */
static zbx_hash_t um_host_hash(const void *d)
{
const zbx_um_host_t *host = *(const zbx_um_host_t * const *)d;
return ZBX_DEFAULT_UINT64_HASH_FUNC(&host->hostid);