From 61218b2fdc48a4e0961c18fc2d4d467f7d861d1a Mon Sep 17 00:00:00 2001 From: Emmanuel Riviere Date: Thu, 1 Feb 2024 16:08:16 +0100 Subject: check_curl: add haproxy protocol option --- plugins/check_curl.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'plugins') diff --git a/plugins/check_curl.c b/plugins/check_curl.c index 8f9a21d2..fbb197f7 100644 --- a/plugins/check_curl.c +++ b/plugins/check_curl.c @@ -223,6 +223,7 @@ curlhelp_ssl_library ssl_library = CURLHELP_SSL_LIBRARY_UNKNOWN; int curl_http_version = CURL_HTTP_VERSION_NONE; bool automatic_decompression = false; char *cookie_jar_file = NULL; +bool haproxy_protocol = false; bool process_arguments (int, char**); void handle_curl_option_return_code (CURLcode res, const char* option); @@ -520,6 +521,11 @@ check_http (void) handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_CONNECTTIMEOUT, socket_timeout), "CURLOPT_CONNECTTIMEOUT"); handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_TIMEOUT, socket_timeout), "CURLOPT_TIMEOUT"); + /* enable haproxy protocol */ + if (haproxy_protocol) { + handle_curl_option_return_code(curl_easy_setopt(curl, CURLOPT_HAPROXYPROTOCOL, 1L), "CURLOPT_HAPROXYPROTOCOL"); + } + // fill dns resolve cache to make curl connect to the given server_address instead of the host_name, only required for ssl, because we use the host_name later on to make SNI happy if(use_ssl && host_name != NULL) { if ( (res=lookup_host (server_address, addrstr, DEFAULT_BUFFER_SIZE/2)) != 0) { @@ -1384,7 +1390,8 @@ process_arguments (int argc, char **argv) CA_CERT_OPTION, HTTP_VERSION_OPTION, AUTOMATIC_DECOMPRESSION, - COOKIE_JAR + COOKIE_JAR, + HAPROXY_PROTOCOL }; int option = 0; @@ -1431,6 +1438,7 @@ process_arguments (int argc, char **argv) {"http-version", required_argument, 0, HTTP_VERSION_OPTION}, {"enable-automatic-decompression", no_argument, 0, AUTOMATIC_DECOMPRESSION}, {"cookie-jar", required_argument, 0, COOKIE_JAR}, + {"haproxy-protocol", no_argument, 0, HAPROXY_PROTOCOL}, {0, 0, 0, 0} }; @@ -1841,6 +1849,9 @@ process_arguments (int argc, char **argv) case COOKIE_JAR: cookie_jar_file = optarg; break; + case HAPROXY_PROTOCOL: + haproxy_protocol = true; + break; case '?': /* print short usage statement if args not parsable */ usage5 (); @@ -2060,6 +2071,8 @@ print_help (void) printf (" %s\n", _("1.0 = HTTP/1.0, 1.1 = HTTP/1.1, 2.0 = HTTP/2 (HTTP/2 will fail without -S)")); printf (" %s\n", "--enable-automatic-decompression"); printf (" %s\n", _("Enable automatic decompression of body (CURLOPT_ACCEPT_ENCODING).")); + printf(" %s\n", "--haproxy-protocol"); + printf(" %s\n", _("Send HAProxy proxy protocol v1 header (CURLOPT_HAPROXYPROTOCOL).")); printf (" %s\n", "---cookie-jar=FILE"); printf (" %s\n", _("Store cookies in the cookie jar and send them out when requested.")); printf ("\n"); @@ -2144,7 +2157,7 @@ print_usage (void) printf (" [-b proxy_auth] [-f ]\n"); printf (" [-e ] [-d string] [-s string] [-l] [-r | -R ]\n"); printf (" [-P string] [-m :] [-4|-6] [-N] [-M ]\n"); - printf (" [-A string] [-k string] [-S ] [--sni]\n"); + printf (" [-A string] [-k string] [-S ] [--sni] [--haproxy-protocol]\n"); printf (" [-T ] [-j method]\n"); printf (" [--http-version=] [--enable-automatic-decompression]\n"); printf (" [--cookie-jar=\n"); -- cgit v1.2.3-74-g34f1