Source
xxxxxxxxxx
int get_value_internal(const zbx_dc_item_t *item, AGENT_RESULT *result, const zbx_config_comms_args_t *config_comms,
/*
** 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/>.
**/
static int compare_interfaces(const void *p1, const void *p2)
{
const zbx_dc_interface2_t *i1 = (const zbx_dc_interface2_t *)p1, *i2 = (const zbx_dc_interface2_t *)p2;
if (i1->type > i2->type) /* 1st criterion: 'type' in ascending order */
return 1;
if (i1->type < i2->type)
return -1;
if (i1->main > i2->main) /* 2nd criterion: 'main' in descending order */
return -1;
if (i1->main < i2->main)
return 1;
if (i1->interfaceid > i2->interfaceid) /* 3rd criterion: 'interfaceid' in ascending order */
return 1;
if (i1->interfaceid < i2->interfaceid)
return -1;
return 0;
}
/******************************************************************************
* *
* Purpose: Gets data of all network interfaces for a host from configuration *
* cache and packs it into JSON for LLD. *
* *
* Parameter: hostid - [IN] *
* j - [OUT] JSON with interface data *
* error - [OUT] error message *
* *
* Return value: SUCCEED - interface data in JSON *
* FAIL - host not found, 'error' message allocated *
* *
* Comments: If host is found but has no interfaces (should not happen) an *
* empty JSON {"data":[]} is returned. *
* *
******************************************************************************/
static int zbx_host_interfaces_discovery(zbx_uint64_t hostid, struct zbx_json *j, char **error)
{
zbx_dc_interface2_t *interfaces = NULL;
int n = 0; /* number of interfaces */
/* get interface data from configuration cache */
if (SUCCEED != zbx_dc_get_host_interfaces(hostid, &interfaces, &n))
{
*error = zbx_strdup(*error, "host not found in configuration cache");
return FAIL;
}
/* sort results in a predictable order */