@cryptotaxi247 / netdata-1 / commits / 4febd31c5

Claiming proxy defaults and additonal log info (#19098)

add proxy information when libcurl fails; the default proxy should always be env

Costa Tsaousis committed Nov 28, 2024 at 01:18 UTC 4febd31c5c695ce68231602d1e7bd227482c38d1
1 file changed +13 -6
src/claim/claim-with-api.c
+13 -6
@@ -240,15 +240,21 @@ static bool send_curl_request(const char *machine_guid, const char *hostname, co
240
241 // Proxy configuration
242 if (proxy) {
243 - if (!*proxy || strcmp(proxy, "none") == 0)
243 + if (!*proxy || strcmp(proxy, "none") == 0) {
244 // disable proxy configuration in libcurl
245 curl_easy_setopt(curl, CURLOPT_PROXY, "");
246 + proxy = "none";
247 + }
248
247 - else if (strcmp(proxy, "env") != 0)
249 + else if (strcmp(proxy, "env") != 0) {
250 // set the custom proxy for libcurl
251 curl_easy_setopt(curl, CURLOPT_PROXY, proxy);
252 + }
253
251 - // otherwise, libcurl will use its own proxy environment variables
254 + else {
255 + // otherwise, libcurl will use its own proxy environment variables
256 + proxy = "env";
257 + }
258 }
259
260 // Insecure option
@@ -264,7 +270,8 @@ static bool send_curl_request(const char *machine_guid, const char *hostname, co
270 // execute the request
271 res = curl_easy_perform(curl);
272 if (res != CURLE_OK) {
267 - claim_agent_failure_reason_set("Request failed with error: %s", curl_easy_strerror(res));
273 + claim_agent_failure_reason_set("Request failed with error: %s (proxy is set to '%s')",
274 + curl_easy_strerror(res), proxy);
275 curl_easy_cleanup(curl);
276 curl_slist_free_all(headers);
277 *can_retry = true;
@@ -392,7 +399,7 @@ bool claim_agent_from_environment(void) {
399
400 const char *proxy = getenv("NETDATA_CLAIM_PROXY");
401 if(!proxy || !*proxy)
395 - proxy = "";
402 + proxy = "env";
403
404 bool insecure = CONFIG_BOOLEAN_NO;
405 const char *from_env = getenv("NETDATA_EXTRA_CLAIM_OPTS");
@@ -418,7 +425,7 @@ bool claim_agent_from_claim_conf(void) {
425 const char *url = appconfig_get(&claim_config, CONFIG_SECTION_GLOBAL, "url", DEFAULT_CLOUD_BASE_URL);
426 const char *token = appconfig_get(&claim_config, CONFIG_SECTION_GLOBAL, "token", "");
427 const char *rooms = appconfig_get(&claim_config, CONFIG_SECTION_GLOBAL, "rooms", "");
421 - const char *proxy = appconfig_get(&claim_config, CONFIG_SECTION_GLOBAL, "proxy", "");
428 + const char *proxy = appconfig_get(&claim_config, CONFIG_SECTION_GLOBAL, "proxy", "env");
429 bool insecure = appconfig_get_boolean(&claim_config, CONFIG_SECTION_GLOBAL, "insecure", CONFIG_BOOLEAN_NO);
430
431 if(token && *token && url && *url)