/****************************************************************************** * * * Function: send_proxyhistory * * * * Purpose: send history data to a Zabbix server * * * * Parameters: * * * * Return value: * * * * Author: Alexander Vladishev * * * * Comments: * * * ******************************************************************************/ static void send_proxyhistory(zbx_sock_t *sock) { const char *__function_name = "send_proxyhistory"; struct zbx_json j; zbx_uint64_t lastid; int records; zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name); zbx_json_init(&j, ZBX_JSON_STAT_BUF_LEN); zbx_json_addarray(&j, ZBX_PROTO_TAG_DATA); records = proxy_get_hist_data(&j, &lastid); zbx_json_close(&j); zbx_json_adduint64(&j, ZBX_PROTO_TAG_CLOCK, (int)time(NULL)); if (FAIL == zbx_tcp_send_to(sock, j.buffer, CONFIG_TIMEOUT)) zabbix_log(LOG_LEVEL_WARNING, "Error while sending availability of hosts. %s", zbx_tcp_strerror()); else if (SUCCEED == zbx_recv_response(sock, NULL, 0, CONFIG_TIMEOUT) && 0 != records) proxy_set_hist_lastid(lastid); zbx_json_free(&j); zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __function_name); }
/****************************************************************************** * * * Function: send_proxyhistory * * * * Purpose: send history data to a Zabbix server * * * ******************************************************************************/ static void send_proxyhistory(zbx_socket_t *sock, zbx_timespec_t *ts) { const char *__function_name = "send_proxyhistory"; struct zbx_json j; zbx_uint64_t lastid; int records, ret = FAIL; char *error = NULL; zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name); if (SUCCEED != check_access_passive_proxy(sock, ZBX_DO_NOT_SEND_RESPONSE, "history data request")) { /* do not send any reply to server in this case as the server expects history data */ goto out1; } zbx_json_init(&j, ZBX_JSON_STAT_BUF_LEN); zbx_json_addarray(&j, ZBX_PROTO_TAG_DATA); records = proxy_get_hist_data(&j, &lastid); zbx_json_close(&j); zbx_json_adduint64(&j, ZBX_PROTO_TAG_CLOCK, ts->sec); zbx_json_adduint64(&j, ZBX_PROTO_TAG_NS, ts->ns); if (SUCCEED != zbx_tcp_send_to(sock, j.buffer, CONFIG_TIMEOUT)) { error = zbx_strdup(error, zbx_socket_strerror()); goto out; } if (SUCCEED != zbx_recv_response(sock, CONFIG_TIMEOUT, &error)) goto out; if (0 != records) proxy_set_hist_lastid(lastid); ret = SUCCEED; out: if (SUCCEED != ret) zabbix_log(LOG_LEVEL_WARNING, "cannot send history data to server at \"%s\": %s", sock->peer, error); zbx_json_free(&j); zbx_free(error); out1: zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __function_name); }