1 /*
2 ** Zabbix
3 ** Copyright (C) 2001-2021 Zabbix SIA
4 **
5 ** This program is free software; you can redistribute it and/or modify
6 ** it under the terms of the GNU General Public License as published by
7 ** the Free Software Foundation; either version 2 of the License, or
8 ** (at your option) any later version.
9 **
10 ** This program is distributed in the hope that it will be useful,
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ** GNU General Public License for more details.
14 **
15 ** You should have received a copy of the GNU General Public License
16 ** along with this program; if not, write to the Free Software
17 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 **/
19
20 #include "common.h"
21 #include "db.h"
22 #include "log.h"
23 #include "proxy.h"
24 #include "dbcache.h"
25
26 #include "proxyhosts.h"
27
28 /******************************************************************************
29 * *
30 * Function: recv_host_availability *
31 * *
32 * Purpose: update hosts availability, monitored by proxies *
33 * *
34 * Author: Alexander Vladishev *
35 * *
36 ******************************************************************************/
recv_host_availability(zbx_socket_t * sock,struct zbx_json_parse * jp)37 void recv_host_availability(zbx_socket_t *sock, struct zbx_json_parse *jp)
38 {
39 const char *__function_name = "recv_host_availability";
40
41 char *error = NULL;
42 int ret = FAIL;
43 DC_PROXY proxy;
44
45 zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);
46
47 if (SUCCEED != get_active_proxy_from_request(jp, &proxy, &error))
48 {
49 zabbix_log(LOG_LEVEL_WARNING, "cannot parse host availability data from active proxy at \"%s\": %s",
50 sock->peer, error);
51 goto out;
52 }
53
54 if (SUCCEED != zbx_proxy_check_permissions(&proxy, sock, &error))
55 {
56 zabbix_log(LOG_LEVEL_WARNING, "cannot accept connection from proxy \"%s\" at \"%s\", allowed address:"
57 " \"%s\": %s", proxy.host, sock->peer, proxy.proxy_address, error);
58 goto out;
59 }
60
61 zbx_update_proxy_data(&proxy, zbx_get_protocol_version(jp), time(NULL),
62 (0 != (sock->protocol & ZBX_TCP_COMPRESS) ? 1 : 0));
63
64 if (SUCCEED != zbx_check_protocol_version(&proxy))
65 {
66 goto out;
67 }
68
69 if (SUCCEED != (ret = process_host_availability(jp, &error)))
70 {
71 zabbix_log(LOG_LEVEL_WARNING, "received invalid host availability data from proxy \"%s\" at \"%s\": %s",
72 proxy.host, sock->peer, error);
73 }
74 out:
75 zbx_send_response(sock, ret, error, CONFIG_TIMEOUT);
76
77 zbx_free(error);
78
79 zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __function_name);
80 }
81
82 /******************************************************************************
83 * *
84 * Function: send_host_availability *
85 * *
86 * Purpose: send hosts availability data from proxy *
87 * *
88 ******************************************************************************/
send_host_availability(zbx_socket_t * sock)89 void send_host_availability(zbx_socket_t *sock)
90 {
91 const char *__function_name = "send_host_availability";
92
93 zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);
94
95 /* do not send any reply to server in this case as the server expects host availability data */
96 if (SUCCEED == check_access_passive_proxy(sock, ZBX_DO_NOT_SEND_RESPONSE, "host availability data request"))
97 zbx_send_proxy_response(sock, FAIL, "Deprecated request", CONFIG_TIMEOUT);
98
99 zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __function_name);
100 }
101