/****************************************************************************** * * * Function: zbx_send_response * * * * Purpose: send json SUCCEED or FAIL to socket along with an info message * * * * Parameters: sock - [IN] socket descriptor * * result - [IN] SUCCEED or FAIL * * info - [IN] info message * * timeout - [IN] timeout for this operation * * * * Return value: SUCCEED - data successfully transmited * * NETWORK_ERROR - network related error occurred * * * * Author: Alexander Vladishev, Alexei Vladishev * * * * Comments: * * * ******************************************************************************/ int zbx_send_response_ext(zbx_socket_t *sock, int result, const char *info, int protocol, int timeout) { const char *__function_name = "zbx_send_response"; struct zbx_json json; const char *resp; int ret = SUCCEED; zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name); zbx_json_init(&json, ZBX_JSON_STAT_BUF_LEN); resp = SUCCEED == result ? ZBX_PROTO_VALUE_SUCCESS : ZBX_PROTO_VALUE_FAILED; zbx_json_addstring(&json, ZBX_PROTO_TAG_RESPONSE, resp, ZBX_JSON_TYPE_STRING); if (NULL != info && '\0' != *info) zbx_json_addstring(&json, ZBX_PROTO_TAG_INFO, info, ZBX_JSON_TYPE_STRING); zabbix_log(LOG_LEVEL_DEBUG, "%s() '%s'", __function_name, json.buffer); if (FAIL == (ret = zbx_tcp_send_ext(sock, json.buffer, strlen(json.buffer), protocol, timeout))) { zabbix_log(LOG_LEVEL_DEBUG, "Error sending result back: %s", zbx_socket_strerror()); ret = NETWORK_ERROR; } zbx_json_free(&json); zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret)); return ret; }
/****************************************************************************** * * * Function: send_proxyconfig * * * * Purpose: send configuration tables to the proxy from server * * (for active proxies) * * * * Author: Alexander Vladishev * * * ******************************************************************************/ void send_proxyconfig(zbx_socket_t *sock, struct zbx_json_parse *jp) { char *error = NULL; struct zbx_json j; DC_PROXY proxy; int flags = ZBX_TCP_PROTOCOL; zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__); if (SUCCEED != get_active_proxy_from_request(jp, &proxy, &error)) { zabbix_log(LOG_LEVEL_WARNING, "cannot parse proxy configuration data request from active proxy at" " \"%s\": %s", sock->peer, error); goto out; } if (SUCCEED != zbx_proxy_check_permissions(&proxy, sock, &error)) { zabbix_log(LOG_LEVEL_WARNING, "cannot accept connection from proxy \"%s\" at \"%s\", allowed address:" " \"%s\": %s", proxy.host, sock->peer, proxy.proxy_address, error); goto out; } zbx_update_proxy_data(&proxy, zbx_get_protocol_version(jp), time(NULL), (0 != (sock->protocol & ZBX_TCP_COMPRESS) ? 1 : 0)); if (0 != proxy.auto_compress) flags |= ZBX_TCP_COMPRESS; zbx_json_init(&j, ZBX_JSON_STAT_BUF_LEN); if (SUCCEED != get_proxyconfig_data(proxy.hostid, &j, &error)) { zbx_send_response_ext(sock, FAIL, error, NULL, flags, CONFIG_TIMEOUT); zabbix_log(LOG_LEVEL_WARNING, "cannot collect configuration data for proxy \"%s\" at \"%s\": %s", proxy.host, sock->peer, error); goto clean; } zabbix_log(LOG_LEVEL_WARNING, "sending configuration data to proxy \"%s\" at \"%s\", datalen " ZBX_FS_SIZE_T, proxy.host, sock->peer, (zbx_fs_size_t)j.buffer_size); zabbix_log(LOG_LEVEL_DEBUG, "%s", j.buffer); if (SUCCEED != zbx_tcp_send_ext(sock, j.buffer, strlen(j.buffer), flags, CONFIG_TRAPPER_TIMEOUT)) { zabbix_log(LOG_LEVEL_WARNING, "cannot send configuration data to proxy \"%s\" at \"%s\": %s", proxy.host, sock->peer, zbx_socket_strerror()); } clean: zbx_json_free(&j); out: zbx_free(error); zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __func__); }
int send_data_to_node(int nodeid, zbx_sock_t *sock, const char *data) { int res; if (FAIL == (res = zbx_tcp_send_ext(sock, data, ZBX_TCP_NEW_PROTOCOL))) { zabbix_log(LOG_LEVEL_ERR, "NODE %d: Error while sending data to Node [%d] error: %s", CONFIG_NODEID, nodeid, zbx_tcp_strerror()); } else zabbix_log(LOG_LEVEL_DEBUG, "NODE %d: Sending [%s] to Node [%d]", CONFIG_NODEID, data, nodeid); return res; }