From 613cb60c96e21eaafb82b80a6b6d84b1b1f9729f Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Wed, 8 Apr 2026 17:21:44 +0200 Subject: check_curl: Clean up (#2252) * check_curl: remove unused variables * check_curl: run formatter on related files * check_curl_helpers: make code a bit more understandable * check_curl helpers: general api cleanup and code style --- plugins/check_curl.c | 88 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 56 insertions(+), 32 deletions(-) (limited to 'plugins/check_curl.c') diff --git a/plugins/check_curl.c b/plugins/check_curl.c index f63cdea2..b168cbcd 100644 --- a/plugins/check_curl.c +++ b/plugins/check_curl.c @@ -247,8 +247,9 @@ mp_subcheck check_http(const check_curl_config config, check_curl_working_state printf("**** REQUEST CONTENT ****\n%s\n", workingState.http_post_data); } - // curl_state is updated after curl_easy_perform, and with updated curl_state certificate checks can be done - // Check_http tries to check certs as early as possible, and exits with certificate check result by default. Behave similarly. + // curl_state is updated after curl_easy_perform, and with updated curl_state certificate checks + // can be done Check_http tries to check certs as early as possible, and exits with certificate + // check result by default. Behave similarly. #ifdef LIBCURL_FEATURE_SSL if (workingState.use_ssl && config.check_cert) { if (verbose > 1) { @@ -1546,8 +1547,8 @@ void print_help(void) { printf(" %s\n", "-I, --IP-address=ADDRESS"); printf(" %s\n", "IP address or name (use numeric address if possible to bypass DNS lookup)."); - printf(" %s\n", - "This overwrites the network address of the target while leaving everything else (HTTP headers) as they are"); + printf(" %s\n", "This overwrites the network address of the target while leaving everything " + "else (HTTP headers) as they are"); printf(" %s\n", "-p, --port=INTEGER"); printf(" %s", _("Port number (default: ")); printf("%d)\n", HTTP_PORT); @@ -1611,7 +1612,8 @@ void print_help(void) { printf(" %s\n", _("String to expect in the content")); printf(" %s\n", "-u, --url=PATH"); printf(" %s\n", _("URL to GET or POST (default: /)")); - printf(" %s\n", _("This is the part after the address in a URL, so for \"https://example.com/index.html\" it would be '-u /index.html'")); + printf(" %s\n", _("This is the part after the address in a URL, so for " + "\"https://example.com/index.html\" it would be '-u /index.html'")); printf(" %s\n", "-P, --post=STRING"); printf(" %s\n", _("URL decoded http POST data")); printf(" %s\n", @@ -1643,11 +1645,12 @@ void print_help(void) { printf(" %s\n", _("If port is not specified, libcurl defaults to 1080")); printf(" %s\n", _("This value will be set as CURLOPT_PROXY")); printf(" %s\n", "--noproxy=COMMA_SEPARATED_LIST"); - printf(" %s\n", _("Specify hostnames, addresses and subnets where proxy should not be used")); + printf(" %s\n", + _("Specify hostnames, addresses and subnets where proxy should not be used")); printf(" %s\n", _("Example usage: \"example.com,::1,1.1.1.1,localhost,192.168.0.0/16\"")); printf(" %s\n", _("Do not use brackets when specifying IPv6 addresses")); printf(" %s\n", _("Special case when an item is '*' : matches all hosts/addresses " - "and effectively disables proxy.")); + "and effectively disables proxy.")); printf(" %s\n", _("This value will be set as CURLOPT_NOPROXY")); printf(" %s\n", "-a, --authorization=AUTH_PAIR"); printf(" %s\n", _("Username:password on sites with basic authentication")); @@ -1757,38 +1760,59 @@ void print_help(void) { #endif printf("\n %s\n", "CHECK WEBSERVER CONTENT VIA PROXY:"); - printf(" %s\n", _("Proxies are specified or disabled for certain hosts/addresses using environment variables" - " or -x/--proxy and --noproxy arguments:")); - printf(" %s\n", _("Checked environment variables: all_proxy, http_proxy, https_proxy, no_proxy")); - printf(" %s\n", _("Environment variables can also be given in uppercase, but the lowercase ones will " - "take predence if both are defined.")); - printf(" %s\n", _("The environment variables are overwritten by -x/--proxy and --noproxy arguments:")); + printf(" %s\n", _("Proxies are specified or disabled for certain hosts/addresses using " + "environment variables" + " or -x/--proxy and --noproxy arguments:")); + printf(" %s\n", + _("Checked environment variables: all_proxy, http_proxy, https_proxy, no_proxy")); + printf(" %s\n", + _("Environment variables can also be given in uppercase, but the lowercase ones will " + "take predence if both are defined.")); + printf(" %s\n", + _("The environment variables are overwritten by -x/--proxy and --noproxy arguments:")); printf(" %s\n", _("all_proxy/ALL_PROXY environment variables are read first, but protocol " - "specific environment variables override them.")); - printf(" %s\n", _("If SSL is enabled and used, https_proxy/HTTPS_PROXY will be checked and overwrite " - "http_proxy/HTTPS_PROXY.")); - printf(" %s\n", _("Curl accepts proxies using http, https, socks4, socks4a, socks5 and socks5h schemes.")); - printf(" %s\n", _("http_proxy=http://192.168.100.35:3128 ./check_curl -H www.monitoring-plugins.org")); - printf(" %s\n", _("http_proxy=http://used.proxy.com HTTP_PROXY=http://ignored.proxy.com ./check_curl -H www.monitoring-plugins.org")); + "specific environment variables override them.")); + printf(" %s\n", + _("If SSL is enabled and used, https_proxy/HTTPS_PROXY will be checked and overwrite " + "http_proxy/HTTPS_PROXY.")); + printf( + " %s\n", + _("Curl accepts proxies using http, https, socks4, socks4a, socks5 and socks5h schemes.")); + printf(" %s\n", + _("http_proxy=http://192.168.100.35:3128 ./check_curl -H www.monitoring-plugins.org")); + printf(" %s\n", _("http_proxy=http://used.proxy.com HTTP_PROXY=http://ignored.proxy.com " + "./check_curl -H www.monitoring-plugins.org")); printf(" %s\n", _(" Lowercase http_proxy takes predence over uppercase HTTP_PROXY")); printf(" %s\n", _("./check_curl -H www.monitoring-plugins.org -x http://192.168.100.35:3128")); - printf(" %s\n", _("http_proxy=http://unused.proxy1.com HTTP_PROXY=http://unused.proxy2.com ./check_curl " - "-H www.monitoring-plugins.org --proxy http://used.proxy")); - printf(" %s\n", _(" Proxy specified by --proxy overrides any proxy specified by environment variable.")); + printf(" %s\n", + _("http_proxy=http://unused.proxy1.com HTTP_PROXY=http://unused.proxy2.com ./check_curl " + "-H www.monitoring-plugins.org --proxy http://used.proxy")); + printf( + " %s\n", + _(" Proxy specified by --proxy overrides any proxy specified by environment variable.")); printf(" %s\n", _(" Curl uses port 1080 by default as port is not specified")); - printf(" %s\n", _("HTTPS_PROXY=http://192.168.100.35:3128 ./check_curl -H www.monitoring-plugins.org --ssl")); + printf(" %s\n", _("HTTPS_PROXY=http://192.168.100.35:3128 ./check_curl -H " + "www.monitoring-plugins.org --ssl")); printf(" %s\n", _(" HTTPS_PROXY is read as --ssl is toggled")); - printf(" %s\n", _("./check_curl -H www.monitoring-plugins.org --proxy socks5h://192.168.122.21")); - printf(" %s\n", _("./check_curl -H www.monitoring-plugins.org -x http://unused.proxy.com --noproxy '*'")); + printf(" %s\n", + _("./check_curl -H www.monitoring-plugins.org --proxy socks5h://192.168.122.21")); + printf( + " %s\n", + _("./check_curl -H www.monitoring-plugins.org -x http://unused.proxy.com --noproxy '*'")); printf(" %s\n", _(" Disabled proxy for all hosts by using '*' in no_proxy .")); - printf(" %s\n", _("NO_PROXY=www.monitoring-plugins.org ./check_curl -H www.monitoring-plugins.org -x http://unused.proxy.com")); + printf(" %s\n", _("NO_PROXY=www.monitoring-plugins.org ./check_curl -H " + "www.monitoring-plugins.org -x http://unused.proxy.com")); printf(" %s\n", _(" Exact matches with the hostname/address work.")); - printf(" %s\n", _("no_proxy=192.168.178.0/24 ./check_curl -I 192.168.178.10 -x http://proxy.acme.org")); - printf(" %s\n", _("no_proxy=acme.org ./check_curl -H nonpublic.internalwebapp.acme.org -x http://proxy.acme.org")); - printf(" %s\n", _(" Do not use proxy when accessing internal domains/addresses, but use a default proxy when accessing public web.")); - printf(" %s\n", _(" IMPORTANT: Check_curl can not always determine whether itself or the proxy will " - "resolve a hostname before sending a request and getting an answer." - "This can lead to DNS resolvation issues if hostname is only resolvable over proxy.")); + printf(" %s\n", + _("no_proxy=192.168.178.0/24 ./check_curl -I 192.168.178.10 -x http://proxy.acme.org")); + printf(" %s\n", _("no_proxy=acme.org ./check_curl -H nonpublic.internalwebapp.acme.org -x " + "http://proxy.acme.org")); + printf(" %s\n", _(" Do not use proxy when accessing internal domains/addresses, but use a " + "default proxy when accessing public web.")); + printf(" %s\n", + _(" IMPORTANT: Check_curl can not always determine whether itself or the proxy will " + "resolve a hostname before sending a request and getting an answer." + "This can lead to DNS resolvation issues if hostname is only resolvable over proxy.")); printf(" %s\n", _("Legacy proxy requests in check_http style still work:")); printf(" %s\n", _("check_curl -I 192.168.100.35 -p 3128 -u http://www.monitoring-plugins.org/ " "-H www.monitoring-plugins.org")); -- cgit v1.2.3-74-g34f1