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/>.
**/
void mock_config_free_user_macros(void);
static int mock_um_macro_compare(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);
}
void mock_config_load_user_macros(const char *path)
{
zbx_mock_handle_t hmacros, handle;
zbx_mock_error_t err;
int i, index = 0;
zbx_mock_config_t *mock_config = get_mock_config();
zbx_vector_um_host_create(&(mock_config->um_hosts));
hmacros = zbx_mock_get_parameter_handle(path);
while (ZBX_MOCK_END_OF_VECTOR != (err = (zbx_mock_vector_element(hmacros, &handle))))
{
zbx_um_host_t *host, host_local;
zbx_um_macro_t *macro;
char *name = NULL, *context = NULL;
const char *macro_name, *macro_value;
zbx_mock_handle_t hhostid;
index++;
if (ZBX_MOCK_SUCCESS != err)
fail_msg("Cannot read 'macros' element #%d: %s", index, zbx_mock_error_string(err));
if (ZBX_MOCK_SUCCESS == zbx_mock_object_member(handle, "hostid", &hhostid))