Source
xxxxxxxxxx
/*
** Zabbix
** Copyright (C) 2001-2023 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.
**/
extern unsigned char program_type;
/**********************************************************************************
* *
* Purpose: perform active agent auto registration *
* *
* Parameters: host - [IN] name of the host to be added or updated *
* ip - [IN] IP address of the host *
* port - [IN] port of the host *
* connection_type - [IN] ZBX_TCP_SEC_UNENCRYPTED, *
* ZBX_TCP_SEC_TLS_PSK or ZBX_TCP_SEC_TLS_CERT *
* host_metadata - [IN] host metadata *
* flag - [IN] flag describing interface type *
* interface - [IN] interface value if flag is not default *
* config_timeout - [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, int config_timeout)
{
char dns[ZBX_INTERFACE_DNS_LEN_MAX];
char ip_addr[ZBX_INTERFACE_IP_LEN_MAX];
const char *p;
const char *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();
now = time(NULL);
/* update before changing database in case Zabbix proxy also changed database and then deleted from cache */
DCconfig_update_autoreg_host(host, p_ip, p_dns, port, host_metadata, flag, now);