Source
DBadd_condition_alloc(&sql, &sql_alloc, &sql_offset, "groupid", groupids->values, groupids->values_num);
/*
** Zabbix
** Copyright (C) 2001-2022 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** 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 General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
typedef enum
{
ZBX_DISCOVERY_UNSPEC = 0,
ZBX_DISCOVERY_DNS,
ZBX_DISCOVERY_IP,
ZBX_DISCOVERY_VALUE
}
zbx_dcheck_source_t;
/******************************************************************************
* *
* Function: select_discovered_host *
* *
* Purpose: select hostid of discovered host *
* *
* Parameters: dhostid - discovered host id *
* *
* Return value: hostid - existing hostid, 0 - if not found *
* *
* Author: Alexei Vladishev *
* *
******************************************************************************/
static zbx_uint64_t select_discovered_host(const DB_EVENT *event)
{
DB_RESULT result;
DB_ROW row;
zbx_uint64_t hostid = 0, proxy_hostid;
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 = DBselect(
"select dr.proxy_hostid,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 = DBfetch(result)))
{
DBfree_result(result);
goto exit;
}
ZBX_DBROW2UINT64(proxy_hostid, row[0]);
ip_esc = DBdyn_escape_string(row[1]);
DBfree_result(result);
sql = zbx_dsprintf(sql,
"select h.hostid"
" from hosts h,interface i"
" where h.hostid=i.hostid"
" and i.ip='%s'"
" and i.useip=1"
" and h.status in (%d,%d)"
" and h.proxy_hostid%s"
" order by i.hostid",