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/>.
**/
/*************************************************************************************
* *
* Purpose: performs active agent auto registration *
* *
* Parameters: *
* host - [IN] name of host to be added or updated *
* ip - [IN] IP address of host *
* port - [IN] port of host *
* connection_type - [IN] ZBX_TCP_SEC_UNENCRYPTED, *
* ZBX_TCP_SEC_TLS_PSK or ZBX_TCP_SEC_TLS_CERT *
* flag *
* host_metadata - [IN] *
* flag - [IN] flag describing interface type *
* interface - [IN] interface value if flag is not default *
* events_cbs - [IN] *
* config_timeout - [IN] *
* autoreg_update_host_func_cb - [IN] *
* *
* Comments: helper function for get_hostid_by_host *
* *
*************************************************************************************/
static void db_register_host(const char *host, const char *ip, unsigned short port, unsigned int connection_type,
const char *host_metadata, zbx_conn_flags_t flag, const char *interface,
const zbx_events_funcs_t *events_cbs, int config_timeout,
zbx_autoreg_update_host_func_t autoreg_update_host_func_cb)
{
char dns[ZBX_INTERFACE_DNS_LEN_MAX], ip_addr[ZBX_INTERFACE_IP_LEN_MAX];
const char *p, *p_ip, *p_dns;
int now;
p_ip = ip;
p_dns = dns;
if (ZBX_CONN_DEFAULT == flag)
p = ip;
else if (ZBX_CONN_IP == flag)
p_ip = p = interface;
zbx_alarm_on(config_timeout);
if (ZBX_CONN_DEFAULT == flag || ZBX_CONN_IP == flag)
{
if (0 == strncmp("::ffff:", p, 7) && SUCCEED == zbx_is_ip4(p + 7))
p += 7;
zbx_gethost_by_ip(p, dns, sizeof(dns));
}
else if (ZBX_CONN_DNS == flag)
{
zbx_getip_by_host(interface, ip_addr, sizeof(ip_addr));
p_ip = ip_addr;
p_dns = interface;
}
zbx_alarm_off();