Source
zbx_db_execute("update dservices set status=%d,lastup=%d,lastdown=%d,value='%s' where dserviceid=" ZBX_FS_UI64,
/*
** 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 zbx_db_result_t discovery_get_dhost_by_value(zbx_uint64_t dcheckid, const char *value)
{
zbx_db_result_t result;
char *value_esc;
value_esc = zbx_db_dyn_escape_field("dservices", "value", value);
result = zbx_db_select(
"select dh.dhostid,dh.status,dh.lastup,dh.lastdown"
" from dhosts dh,dservices ds"
" where ds.dhostid=dh.dhostid"
" and ds.dcheckid=" ZBX_FS_UI64
" and ds.value" ZBX_SQL_STRCMP
" order by dh.dhostid",
dcheckid, ZBX_SQL_STRVAL_EQ(value_esc));
zbx_free(value_esc);
return result;
}
static zbx_db_result_t discovery_get_dhost_by_ip_port(zbx_uint64_t druleid, const char *ip, int port)
{
zbx_db_result_t result;
char *ip_esc;
ip_esc = zbx_db_dyn_escape_field("dservices", "ip", ip);
result = zbx_db_select(
"select dh.dhostid,dh.status,dh.lastup,dh.lastdown"
" from dhosts dh,dservices ds"
" where ds.dhostid=dh.dhostid"
" and dh.druleid=" ZBX_FS_UI64
" and ds.ip" ZBX_SQL_STRCMP
" and ds.port=%d"
" order by dh.dhostid",
druleid, ZBX_SQL_STRVAL_EQ(ip_esc), port);
zbx_free(ip_esc);
return result;
}
/******************************************************************************
* *
* Purpose: separates multiple-IP hosts *
* *
* Parameters: *
* druleid - [IN] host ip address *
* dhost - [OUT] *
* ip - [IN] *
* *
******************************************************************************/
static void discovery_separate_host(zbx_uint64_t druleid, zbx_db_dhost *dhost, const char *ip)
{
zbx_db_result_t result;
char *ip_esc, *sql = NULL;
zbx_uint64_t dhostid;
zabbix_log(LOG_LEVEL_DEBUG, "In %s() ip:'%s'", __func__, ip);
ip_esc = zbx_db_dyn_escape_field("dservices", "ip", ip);
sql = zbx_dsprintf(sql,
"select dserviceid"
" from dservices"
" where dhostid=" ZBX_FS_UI64
" and ip" ZBX_SQL_STRCMP,
dhost->dhostid, ZBX_SQL_STRVAL_NE(ip_esc));