Source
zbx_db_add_condition_alloc(&sql, &sql_alloc, &sql_offset, "groupid", groupids->values, groupids->values_num);
/*
** 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/>.
**/
typedef enum
{
ZBX_DISCOVERY_UNSPEC = 0,
ZBX_DISCOVERY_DNS,
ZBX_DISCOVERY_IP,
ZBX_DISCOVERY_VALUE
}
zbx_dcheck_source_t;
typedef enum
{
ZBX_OP_HOST_TAGS_ADD,
ZBX_OP_HOST_TAGS_DEL
}
zbx_host_tag_op_t;
/******************************************************************************
* *
* Purpose: selects hostid of discovered host *
* *
* Parameters: event - [IN] source event data *
* hostname - [OUT] hostname where event occurred *
* *
* Return value: hostid - existing hostid, *
* 0 - if not found *
* *
******************************************************************************/
static zbx_uint64_t select_discovered_host(const zbx_db_event *event, char **hostname)
{
zbx_db_result_t result;
zbx_db_row_t row;
zbx_uint64_t hostid = 0, proxyid;
char *sql = NULL, *ip_esc;
zabbix_log(LOG_LEVEL_DEBUG, "In %s() eventid:" ZBX_FS_UI64, __func__, event->eventid);
switch (event->object)
{
case EVENT_OBJECT_DHOST:
case EVENT_OBJECT_DSERVICE:
result = zbx_db_select(
"select dr.proxyid,ds.ip"
" from drules dr,dchecks dc,dservices ds"
" where dc.druleid=dr.druleid"
" and ds.dcheckid=dc.dcheckid"
" and ds.%s=" ZBX_FS_UI64,
EVENT_OBJECT_DSERVICE == event->object ? "dserviceid" : "dhostid",
event->objectid);
if (NULL == (row = zbx_db_fetch(result)))
{
zbx_db_free_result(result);
goto exit;
}
ZBX_DBROW2UINT64(proxyid, row[0]);
ip_esc = zbx_db_dyn_escape_string(row[1]);
zbx_db_free_result(result);
sql = zbx_dsprintf(sql,
"select h.hostid,h.name"