diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2019-09-07 13:58:09 (GMT) |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2019-09-07 13:58:09 (GMT) |
commit | f546041722b279d947f75523c52bd779ca6344dc (patch) | |
tree | 4748c910d62441ba3828724839e149f3bc662de5 | |
parent | 95ee6ace094109d156286ab61d3c76709e43d642 (diff) | |
download | monitoring-plugins-f546041722b279d947f75523c52bd779ca6344dc.tar.gz |
added --http-version option to check_curl to choose HTTP version
-rw-r--r-- | plugins/check_curl.c | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/plugins/check_curl.c b/plugins/check_curl.c index 3a6f2af..7f1f64c 100644 --- a/plugins/check_curl.c +++ b/plugins/check_curl.c | |||
@@ -203,6 +203,7 @@ int no_body = FALSE; | |||
203 | int maximum_age = -1; | 203 | int maximum_age = -1; |
204 | int address_family = AF_UNSPEC; | 204 | int address_family = AF_UNSPEC; |
205 | curlhelp_ssl_library ssl_library = CURLHELP_SSL_LIBRARY_UNKNOWN; | 205 | curlhelp_ssl_library ssl_library = CURLHELP_SSL_LIBRARY_UNKNOWN; |
206 | int curl_http_version = CURL_HTTP_VERSION_NONE; | ||
206 | 207 | ||
207 | int process_arguments (int, char**); | 208 | int process_arguments (int, char**); |
208 | void handle_curl_option_return_code (CURLcode res, const char* option); | 209 | void handle_curl_option_return_code (CURLcode res, const char* option); |
@@ -386,6 +387,9 @@ check_http (void) | |||
386 | http_method = "GET"; | 387 | http_method = "GET"; |
387 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_URL, server_url), "CURLOPT_URL"); | 388 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_URL, server_url), "CURLOPT_URL"); |
388 | } | 389 | } |
390 | |||
391 | /* set HTTP protocol version */ | ||
392 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_HTTP_VERSION, curl_http_version), "CURLOPT_HTTP_VERSION"); | ||
389 | 393 | ||
390 | /* set HTTP method */ | 394 | /* set HTTP method */ |
391 | if (http_method) { | 395 | if (http_method) { |
@@ -1085,7 +1089,8 @@ process_arguments (int argc, char **argv) | |||
1085 | enum { | 1089 | enum { |
1086 | INVERT_REGEX = CHAR_MAX + 1, | 1090 | INVERT_REGEX = CHAR_MAX + 1, |
1087 | SNI_OPTION, | 1091 | SNI_OPTION, |
1088 | CA_CERT_OPTION | 1092 | CA_CERT_OPTION, |
1093 | HTTP_VERSION_OPTION | ||
1089 | }; | 1094 | }; |
1090 | 1095 | ||
1091 | int option = 0; | 1096 | int option = 0; |
@@ -1125,6 +1130,7 @@ process_arguments (int argc, char **argv) | |||
1125 | {"use-ipv4", no_argument, 0, '4'}, | 1130 | {"use-ipv4", no_argument, 0, '4'}, |
1126 | {"use-ipv6", no_argument, 0, '6'}, | 1131 | {"use-ipv6", no_argument, 0, '6'}, |
1127 | {"extended-perfdata", no_argument, 0, 'E'}, | 1132 | {"extended-perfdata", no_argument, 0, 'E'}, |
1133 | {"http-version", required_argument, 0, HTTP_VERSION_OPTION}, | ||
1128 | {0, 0, 0, 0} | 1134 | {0, 0, 0, 0} |
1129 | }; | 1135 | }; |
1130 | 1136 | ||
@@ -1491,6 +1497,19 @@ process_arguments (int argc, char **argv) | |||
1491 | case 'E': /* show extended perfdata */ | 1497 | case 'E': /* show extended perfdata */ |
1492 | show_extended_perfdata = TRUE; | 1498 | show_extended_perfdata = TRUE; |
1493 | break; | 1499 | break; |
1500 | case HTTP_VERSION_OPTION: | ||
1501 | curl_http_version = CURL_HTTP_VERSION_NONE; | ||
1502 | if (strcmp (optarg, "1.0") == 0) { | ||
1503 | curl_http_version = CURL_HTTP_VERSION_1_0; | ||
1504 | } else if (strcmp (optarg, "1.1") == 0) { | ||
1505 | curl_http_version = CURL_HTTP_VERSION_1_1; | ||
1506 | } else if (strcmp (optarg, "2") == 0) { | ||
1507 | curl_http_version = CURL_HTTP_VERSION_2_0; | ||
1508 | } else { | ||
1509 | fprintf (stderr, "unkown http-version parameter: %s\n", optarg); | ||
1510 | exit (STATE_WARNING); | ||
1511 | } | ||
1512 | break; | ||
1494 | case '?': | 1513 | case '?': |
1495 | /* print short usage statement if args not parsable */ | 1514 | /* print short usage statement if args not parsable */ |
1496 | usage5 (); | 1515 | usage5 (); |
@@ -1693,6 +1712,11 @@ print_help (void) | |||
1693 | printf (" %s\n", _("curl uses CURL_FOLLOWLOCATION built into libcurl.")); | 1712 | printf (" %s\n", _("curl uses CURL_FOLLOWLOCATION built into libcurl.")); |
1694 | printf (" %s\n", "-m, --pagesize=INTEGER<:INTEGER>"); | 1713 | printf (" %s\n", "-m, --pagesize=INTEGER<:INTEGER>"); |
1695 | printf (" %s\n", _("Minimum page size required (bytes) : Maximum page size required (bytes)")); | 1714 | printf (" %s\n", _("Minimum page size required (bytes) : Maximum page size required (bytes)")); |
1715 | printf ("\n"); | ||
1716 | printf (" %s\n", "--http-version=VERSION"); | ||
1717 | printf (" %s\n", _("Connect via specific HTTP protocol.")); | ||
1718 | printf (" %s\n", _("1.0 = HTTP/1.0, 1.1 = HTTP/1.1, 2.0 = HTTP/2 (HTTP/2 will fail without -S)")); | ||
1719 | printf ("\n"); | ||
1696 | 1720 | ||
1697 | printf (UT_WARN_CRIT); | 1721 | printf (UT_WARN_CRIT); |
1698 | 1722 | ||
@@ -1776,6 +1800,7 @@ print_usage (void) | |||
1776 | printf (" [-P string] [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>]\n"); | 1800 | printf (" [-P string] [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>]\n"); |
1777 | printf (" [-A string] [-k string] [-S <version>] [--sni] [-C <warn_age>[,<crit_age>]]\n"); | 1801 | printf (" [-A string] [-k string] [-S <version>] [--sni] [-C <warn_age>[,<crit_age>]]\n"); |
1778 | printf (" [-T <content-type>] [-j method]\n"); | 1802 | printf (" [-T <content-type>] [-j method]\n"); |
1803 | printf (" [--http-version=<version>]\n"); | ||
1779 | printf ("\n"); | 1804 | printf ("\n"); |
1780 | printf ("%s\n", _("WARNING: check_curl is experimental. Please use")); | 1805 | printf ("%s\n", _("WARNING: check_curl is experimental. Please use")); |
1781 | printf ("%s\n\n", _("check_http if you need a stable version.")); | 1806 | printf ("%s\n\n", _("check_http if you need a stable version.")); |