diff --git a/src/zabbix_server/poller/checks_http.c b/src/zabbix_server/poller/checks_http.c index 2f1af89852..da3f7aa23f 100644 --- a/src/zabbix_server/poller/checks_http.c +++ b/src/zabbix_server/poller/checks_http.c @@ -219,11 +219,30 @@ int get_value_http(const DC_ITEM *item, AGENT_RESULT *result) size_t (*curl_body_cb)(void *ptr, size_t size, size_t nmemb, void *userdata); char application_json[] = {"Content-Type: application/json"}; char application_xml[] = {"Content-Type: application/xml"}; + AGENT_REQUEST request; + const char *encoding = NULL; zabbix_log(LOG_LEVEL_DEBUG, "In %s() request method '%s' URL '%s%s' headers '%s' message body '%s'", __func__, zbx_request_string(item->request_method), item->url, item->query_fields, item->headers, item->posts); + init_request(&request); + + if (SUCCEED != parse_item_key(item->key, &request)) + { + SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid item key format")); + goto clean; + } + + if (1 < get_rparams_num(&request)) + { + SET_MSG_RESULT(result, zbx_strdup(NULL, "Too many arguments")); + goto clean; + } + + if (1 == get_rparams_num(&request)) + encoding = get_rparam(&request, 0); + if (NULL == (easyhandle = curl_easy_init())) { SET_MSG_RESULT(result, zbx_strdup(NULL, "Cannot initialize cURL library")); @@ -407,6 +426,17 @@ int get_value_http(const DC_ITEM *item, AGENT_RESULT *result) goto clean; } + if (NULL != encoding) + { + char *utf8; + + if (NULL != (utf8 = convert_to_utf8(body.data, strlen(body.data), encoding))) + { + zbx_free(body.data); + body.data = utf8; + } + } + if (FAIL == zbx_is_utf8(body.data)) { SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Server returned invalid UTF-8 sequence")); @@ -425,6 +455,17 @@ int get_value_http(const DC_ITEM *item, AGENT_RESULT *result) } break; case ZBX_RETRIEVE_MODE_HEADERS: + if (NULL != encoding) + { + char *utf8; + + if (NULL != (utf8 = convert_to_utf8(header.data, strlen(header.data), encoding))) + { + zbx_free(header.data); + header.data = utf8; + } + } + if (FAIL == zbx_is_utf8(header.data)) { SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Server returned invalid UTF-8 sequence")); @@ -451,6 +492,24 @@ int get_value_http(const DC_ITEM *item, AGENT_RESULT *result) } break; case ZBX_RETRIEVE_MODE_BOTH: + if (NULL != encoding) + { + char *utf8; + + if (NULL != (utf8 = convert_to_utf8(header.data, strlen(header.data), encoding))) + { + zbx_free(header.data); + header.data = utf8; + } + + if (NULL != body.data && + NULL != (utf8 = convert_to_utf8(body.data, strlen(body.data), encoding))) + { + zbx_free(body.data); + body.data = utf8; + } + } + if (FAIL == zbx_is_utf8(header.data) || (NULL != body.data && FAIL == zbx_is_utf8(body.data))) { SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Server returned invalid UTF-8 sequence")); @@ -478,6 +537,7 @@ clean: curl_easy_cleanup(easyhandle); zbx_free(body.data); zbx_free(header.data); + free_request(&request); zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __func__, zbx_result_string(ret)); return ret;