diff options
Diffstat (limited to 'plugins/check_curl.c')
-rw-r--r-- | plugins/check_curl.c | 320 |
1 files changed, 301 insertions, 19 deletions
diff --git a/plugins/check_curl.c b/plugins/check_curl.c index 5f6905f..72db27a 100644 --- a/plugins/check_curl.c +++ b/plugins/check_curl.c | |||
@@ -51,17 +51,35 @@ const char *email = "devel@monitoring-plugins.org"; | |||
51 | 51 | ||
52 | #include "picohttpparser.h" | 52 | #include "picohttpparser.h" |
53 | 53 | ||
54 | #include "uriparser/Uri.h" | ||
55 | |||
56 | #include <arpa/inet.h> | ||
57 | |||
54 | #define MAKE_LIBCURL_VERSION(major, minor, patch) ((major)*0x10000 + (minor)*0x100 + (patch)) | 58 | #define MAKE_LIBCURL_VERSION(major, minor, patch) ((major)*0x10000 + (minor)*0x100 + (patch)) |
55 | 59 | ||
56 | #define DEFAULT_BUFFER_SIZE 2048 | 60 | #define DEFAULT_BUFFER_SIZE 2048 |
57 | #define DEFAULT_SERVER_URL "/" | 61 | #define DEFAULT_SERVER_URL "/" |
58 | #define HTTP_EXPECT "HTTP/1." | 62 | #define HTTP_EXPECT "HTTP/1." |
63 | #define DEFAULT_MAX_REDIRS 15 | ||
64 | #define INET_ADDR_MAX_SIZE INET6_ADDRSTRLEN | ||
59 | enum { | 65 | enum { |
66 | MAX_IPV4_HOSTLENGTH = 255, | ||
60 | HTTP_PORT = 80, | 67 | HTTP_PORT = 80, |
61 | HTTPS_PORT = 443, | 68 | HTTPS_PORT = 443, |
62 | MAX_PORT = 65535 | 69 | MAX_PORT = 65535 |
63 | }; | 70 | }; |
64 | 71 | ||
72 | enum { | ||
73 | STICKY_NONE = 0, | ||
74 | STICKY_HOST = 1, | ||
75 | STICKY_PORT = 2 | ||
76 | }; | ||
77 | |||
78 | enum { | ||
79 | FOLLOW_HTTP_CURL = 0, | ||
80 | FOLLOW_LIBCURL = 1 | ||
81 | }; | ||
82 | |||
65 | /* for buffers for header and body */ | 83 | /* for buffers for header and body */ |
66 | typedef struct { | 84 | typedef struct { |
67 | char *buf; | 85 | char *buf; |
@@ -128,6 +146,8 @@ int verbose = 0; | |||
128 | int show_extended_perfdata = FALSE; | 146 | int show_extended_perfdata = FALSE; |
129 | int min_page_len = 0; | 147 | int min_page_len = 0; |
130 | int max_page_len = 0; | 148 | int max_page_len = 0; |
149 | int redir_depth = 0; | ||
150 | int max_depth = DEFAULT_MAX_REDIRS; | ||
131 | char *http_method = NULL; | 151 | char *http_method = NULL; |
132 | char *http_post_data = NULL; | 152 | char *http_post_data = NULL; |
133 | char *http_content_type = NULL; | 153 | char *http_content_type = NULL; |
@@ -155,8 +175,12 @@ char string_expect[MAX_INPUT_BUFFER] = ""; | |||
155 | char server_expect[MAX_INPUT_BUFFER] = HTTP_EXPECT; | 175 | char server_expect[MAX_INPUT_BUFFER] = HTTP_EXPECT; |
156 | int server_expect_yn = 0; | 176 | int server_expect_yn = 0; |
157 | char user_auth[MAX_INPUT_BUFFER] = ""; | 177 | char user_auth[MAX_INPUT_BUFFER] = ""; |
178 | char **http_opt_headers; | ||
179 | int http_opt_headers_count = 0; | ||
158 | int display_html = FALSE; | 180 | int display_html = FALSE; |
159 | int onredirect = STATE_OK; | 181 | int onredirect = STATE_OK; |
182 | int followmethod = FOLLOW_HTTP_CURL; | ||
183 | int followsticky = STICKY_NONE; | ||
160 | int use_ssl = FALSE; | 184 | int use_ssl = FALSE; |
161 | int use_sni = TRUE; | 185 | int use_sni = TRUE; |
162 | int check_cert = FALSE; | 186 | int check_cert = FALSE; |
@@ -181,6 +205,7 @@ curlhelp_ssl_library ssl_library = CURLHELP_SSL_LIBRARY_UNKNOWN; | |||
181 | int process_arguments (int, char**); | 205 | int process_arguments (int, char**); |
182 | void handle_curl_option_return_code (CURLcode res, const char* option); | 206 | void handle_curl_option_return_code (CURLcode res, const char* option); |
183 | int check_http (void); | 207 | int check_http (void); |
208 | void redir (curlhelp_write_curlbuf*); | ||
184 | void print_help (void); | 209 | void print_help (void); |
185 | void print_usage (void); | 210 | void print_usage (void); |
186 | void print_curl_version (void); | 211 | void print_curl_version (void); |
@@ -295,6 +320,8 @@ check_http (void) | |||
295 | { | 320 | { |
296 | int result = STATE_OK; | 321 | int result = STATE_OK; |
297 | int page_len = 0; | 322 | int page_len = 0; |
323 | int i; | ||
324 | char *force_host_header = NULL; | ||
298 | 325 | ||
299 | /* initialize curl */ | 326 | /* initialize curl */ |
300 | if (curl_global_init (CURL_GLOBAL_DEFAULT) != CURLE_OK) | 327 | if (curl_global_init (CURL_GLOBAL_DEFAULT) != CURLE_OK) |
@@ -371,6 +398,28 @@ check_http (void) | |||
371 | snprintf (http_header, DEFAULT_BUFFER_SIZE, "Connection: close"); | 398 | snprintf (http_header, DEFAULT_BUFFER_SIZE, "Connection: close"); |
372 | header_list = curl_slist_append (header_list, http_header); | 399 | header_list = curl_slist_append (header_list, http_header); |
373 | 400 | ||
401 | /* check if Host header is explicitly set in options */ | ||
402 | if (http_opt_headers_count) { | ||
403 | for (i = 0; i < http_opt_headers_count ; i++) { | ||
404 | if (strncmp(http_opt_headers[i], "Host:", 5) == 0) { | ||
405 | force_host_header = http_opt_headers[i]; | ||
406 | } | ||
407 | } | ||
408 | } | ||
409 | |||
410 | /* attach additional headers supplied by the user */ | ||
411 | /* optionally send any other header tag */ | ||
412 | if (http_opt_headers_count) { | ||
413 | for (i = 0; i < http_opt_headers_count ; i++) { | ||
414 | if (force_host_header != http_opt_headers[i]) { | ||
415 | header_list = curl_slist_append (header_list, http_opt_headers[i]); | ||
416 | } | ||
417 | } | ||
418 | /* This cannot be free'd here because a redirection will then try to access this and segfault */ | ||
419 | /* Covered in a testcase in tests/check_http.t */ | ||
420 | /* free(http_opt_headers); */ | ||
421 | } | ||
422 | |||
374 | /* set HTTP headers */ | 423 | /* set HTTP headers */ |
375 | handle_curl_option_return_code (curl_easy_setopt( curl, CURLOPT_HTTPHEADER, header_list ), "CURLOPT_HTTPHEADER"); | 424 | handle_curl_option_return_code (curl_easy_setopt( curl, CURLOPT_HTTPHEADER, header_list ), "CURLOPT_HTTPHEADER"); |
376 | 425 | ||
@@ -481,13 +530,29 @@ check_http (void) | |||
481 | 530 | ||
482 | /* handle redirections */ | 531 | /* handle redirections */ |
483 | if (onredirect == STATE_DEPENDENT) { | 532 | if (onredirect == STATE_DEPENDENT) { |
484 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_FOLLOWLOCATION, 1), "CURLOPT_FOLLOWLOCATION"); | 533 | if( followmethod == FOLLOW_LIBCURL ) { |
485 | /* TODO: handle the following aspects of redirection | 534 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_FOLLOWLOCATION, 1), "CURLOPT_FOLLOWLOCATION"); |
486 | CURLOPT_POSTREDIR: method switch | 535 | |
487 | CURLINFO_REDIRECT_URL: custom redirect option | 536 | /* default -1 is infinite, not good, could lead to zombie plugins! |
488 | CURLOPT_REDIRECT_PROTOCOLS | 537 | Setting it to one bigger than maximal limit to handle errors nicely below |
489 | CURLINFO_REDIRECT_COUNT | 538 | */ |
490 | */ | 539 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_MAXREDIRS, max_depth+1), "CURLOPT_MAXREDIRS"); |
540 | |||
541 | /* for now allow only http and https (we are a http(s) check plugin in the end) */ | ||
542 | #if LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 19, 4) | ||
543 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS), "CURLOPT_REDIRECT_PROTOCOLS"); | ||
544 | #endif /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 19, 4) */ | ||
545 | |||
546 | /* TODO: handle the following aspects of redirection, make them | ||
547 | * command line options too later: | ||
548 | CURLOPT_POSTREDIR: method switch | ||
549 | CURLINFO_REDIRECT_URL: custom redirect option | ||
550 | CURLOPT_REDIRECT_PROTOCOLS: allow people to step outside safe protocols | ||
551 | CURLINFO_REDIRECT_COUNT: get the number of redirects, print it, maybe a range option here is nice like for expected page size? | ||
552 | */ | ||
553 | } else { | ||
554 | // old style redirection is handled below | ||
555 | } | ||
491 | } | 556 | } |
492 | 557 | ||
493 | /* no-body */ | 558 | /* no-body */ |
@@ -533,8 +598,8 @@ check_http (void) | |||
533 | printf ("**** REQUEST CONTENT ****\n%s\n", http_post_data); | 598 | printf ("**** REQUEST CONTENT ****\n%s\n", http_post_data); |
534 | 599 | ||
535 | /* free header and server IP resolve lists, we don't need it anymore */ | 600 | /* free header and server IP resolve lists, we don't need it anymore */ |
536 | curl_slist_free_all (header_list); | 601 | curl_slist_free_all (header_list); header_list = NULL; |
537 | curl_slist_free_all (server_ips); | 602 | curl_slist_free_all (server_ips); server_ips = NULL; |
538 | 603 | ||
539 | /* Curl errors, result in critical Nagios state */ | 604 | /* Curl errors, result in critical Nagios state */ |
540 | if (res != CURLE_OK) { | 605 | if (res != CURLE_OK) { |
@@ -691,18 +756,39 @@ GOT_FIRST_CERT: | |||
691 | /* check redirected page if specified */ | 756 | /* check redirected page if specified */ |
692 | } else if (code >= 300) { | 757 | } else if (code >= 300) { |
693 | if (onredirect == STATE_DEPENDENT) { | 758 | if (onredirect == STATE_DEPENDENT) { |
694 | code = status_line.http_code; | 759 | if( followmethod == FOLLOW_LIBCURL ) { |
760 | code = status_line.http_code; | ||
761 | } else { | ||
762 | /* old check_http style redirection, if we come | ||
763 | * back here, we are in the same status as with | ||
764 | * the libcurl method | ||
765 | */ | ||
766 | redir (&header_buf); | ||
767 | } | ||
768 | } else { | ||
769 | /* this is a specific code in the command line to | ||
770 | * be returned when a redirection is encoutered | ||
771 | */ | ||
695 | } | 772 | } |
696 | result = max_state_alt (onredirect, result); | 773 | result = max_state_alt (onredirect, result); |
697 | /* TODO: make sure the last status line has been | ||
698 | parsed into the status_line structure | ||
699 | */ | ||
700 | /* all other codes are considered ok */ | 774 | /* all other codes are considered ok */ |
701 | } else { | 775 | } else { |
702 | result = STATE_OK; | 776 | result = STATE_OK; |
703 | } | 777 | } |
704 | } | 778 | } |
705 | 779 | ||
780 | /* libcurl redirection internally, handle error states here */ | ||
781 | if( followmethod == FOLLOW_LIBCURL ) { | ||
782 | handle_curl_option_return_code (curl_easy_getinfo (curl, CURLINFO_REDIRECT_COUNT, &redir_depth), "CURLINFO_REDIRECT_COUNT"); | ||
783 | if (verbose >= 2) | ||
784 | printf(_("* curl LIBINFO_REDIRECT_COUNT is %d\n"), redir_depth); | ||
785 | if (redir_depth > max_depth) { | ||
786 | snprintf (msg, DEFAULT_BUFFER_SIZE, "maximum redirection depth %d exceeded in libcurl", | ||
787 | max_depth); | ||
788 | die (STATE_WARNING, "HTTP WARNING - %s", msg); | ||
789 | } | ||
790 | } | ||
791 | |||
706 | /* check status codes, set exit status accordingly */ | 792 | /* check status codes, set exit status accordingly */ |
707 | if( status_line.http_code != code ) { | 793 | if( status_line.http_code != code ) { |
708 | die (STATE_CRITICAL, _("HTTP CRITICAL HTTP/%d.%d %d %s - different HTTP codes (cUrl has %ld)\n"), | 794 | die (STATE_CRITICAL, _("HTTP CRITICAL HTTP/%d.%d %d %s - different HTTP codes (cUrl has %ld)\n"), |
@@ -813,6 +899,188 @@ GOT_FIRST_CERT: | |||
813 | return result; | 899 | return result; |
814 | } | 900 | } |
815 | 901 | ||
902 | int | ||
903 | uri_strcmp (const UriTextRangeA range, const char* s) | ||
904 | { | ||
905 | if (!range.first) return -1; | ||
906 | if (range.afterLast - range.first < strlen (s)) return -1; | ||
907 | return strncmp (s, range.first, min( range.afterLast - range.first, strlen (s))); | ||
908 | } | ||
909 | |||
910 | char* | ||
911 | uri_string (const UriTextRangeA range, char* buf, size_t buflen) | ||
912 | { | ||
913 | if (!range.first) return "(null)"; | ||
914 | strncpy (buf, range.first, max (buflen, range.afterLast - range.first)); | ||
915 | buf[max (buflen, range.afterLast - range.first)] = '\0'; | ||
916 | buf[range.afterLast - range.first] = '\0'; | ||
917 | return buf; | ||
918 | } | ||
919 | |||
920 | void | ||
921 | redir (curlhelp_write_curlbuf* header_buf) | ||
922 | { | ||
923 | char *location = NULL; | ||
924 | curlhelp_statusline status_line; | ||
925 | struct phr_header headers[255]; | ||
926 | size_t nof_headers = 255; | ||
927 | size_t msglen; | ||
928 | char buf[DEFAULT_BUFFER_SIZE]; | ||
929 | char ipstr[INET_ADDR_MAX_SIZE]; | ||
930 | int new_port; | ||
931 | char *new_host; | ||
932 | char *new_url; | ||
933 | |||
934 | int res = phr_parse_response (header_buf->buf, header_buf->buflen, | ||
935 | &status_line.http_minor, &status_line.http_code, &status_line.msg, &msglen, | ||
936 | headers, &nof_headers, 0); | ||
937 | |||
938 | location = get_header_value (headers, nof_headers, "location"); | ||
939 | |||
940 | if (verbose >= 2) | ||
941 | printf(_("* Seen redirect location %s\n"), location); | ||
942 | |||
943 | if (++redir_depth > max_depth) | ||
944 | die (STATE_WARNING, | ||
945 | _("HTTP WARNING - maximum redirection depth %d exceeded - %s\n"), | ||
946 | max_depth, location, (display_html ? "</A>" : "")); | ||
947 | |||
948 | UriParserStateA state; | ||
949 | UriUriA uri; | ||
950 | state.uri = &uri; | ||
951 | if (uriParseUriA (&state, location) != URI_SUCCESS) { | ||
952 | if (state.errorCode == URI_ERROR_SYNTAX) { | ||
953 | die (STATE_UNKNOWN, | ||
954 | _("HTTP UNKNOWN - Could not parse redirect location '%s'%s\n"), | ||
955 | location, (display_html ? "</A>" : "")); | ||
956 | } else if (state.errorCode == URI_ERROR_MALLOC) { | ||
957 | die (STATE_UNKNOWN, _("HTTP UNKNOWN - Could not allocate URL\n")); | ||
958 | } | ||
959 | } | ||
960 | |||
961 | if (verbose >= 2) { | ||
962 | printf (_("** scheme: %s\n"), | ||
963 | uri_string (uri.scheme, buf, DEFAULT_BUFFER_SIZE)); | ||
964 | printf (_("** host: %s\n"), | ||
965 | uri_string (uri.hostText, buf, DEFAULT_BUFFER_SIZE)); | ||
966 | printf (_("** port: %s\n"), | ||
967 | uri_string (uri.portText, buf, DEFAULT_BUFFER_SIZE)); | ||
968 | if (uri.hostData.ip4) { | ||
969 | inet_ntop (AF_INET, uri.hostData.ip4->data, ipstr, sizeof (ipstr)); | ||
970 | printf (_("** IPv4: %s\n"), ipstr); | ||
971 | } | ||
972 | if (uri.hostData.ip6) { | ||
973 | inet_ntop (AF_INET, uri.hostData.ip6->data, ipstr, sizeof (ipstr)); | ||
974 | printf (_("** IPv6: %s\n"), ipstr); | ||
975 | } | ||
976 | if (uri.pathHead) { | ||
977 | printf (_("** path: ")); | ||
978 | const UriPathSegmentA* p = uri.pathHead; | ||
979 | for (; p; p = p->next) { | ||
980 | printf ("/%s", uri_string (p->text, buf, DEFAULT_BUFFER_SIZE)); | ||
981 | } | ||
982 | puts (""); | ||
983 | } | ||
984 | if (uri.query.first) { | ||
985 | printf (_("** query: %s\n"), | ||
986 | uri_string (uri.query, buf, DEFAULT_BUFFER_SIZE)); | ||
987 | } | ||
988 | if (uri.fragment.first) { | ||
989 | printf (_("** fragment: %s\n"), | ||
990 | uri_string (uri.fragment, buf, DEFAULT_BUFFER_SIZE)); | ||
991 | } | ||
992 | } | ||
993 | |||
994 | use_ssl = !uri_strcmp (uri.scheme, "https"); | ||
995 | |||
996 | /* we do a sloppy test here only, because uriparser would have failed | ||
997 | * above, if the port would be invalid, we just check for MAX_PORT | ||
998 | */ | ||
999 | if (uri.portText.first) { | ||
1000 | new_port = atoi (uri_string (uri.portText, buf, DEFAULT_BUFFER_SIZE)); | ||
1001 | } else { | ||
1002 | new_port = HTTP_PORT; | ||
1003 | if (use_ssl) | ||
1004 | new_port = HTTPS_PORT; | ||
1005 | } | ||
1006 | if (new_port > MAX_PORT) | ||
1007 | die (STATE_UNKNOWN, | ||
1008 | _("HTTP UNKNOWN - Redirection to port above %d - %s\n"), | ||
1009 | MAX_PORT, location, display_html ? "</A>" : ""); | ||
1010 | |||
1011 | /* by RFC 7231 relative URLs in Location should be taken relative to | ||
1012 | * the original URL, so wy try to form a new absolute URL here | ||
1013 | */ | ||
1014 | if (!uri.scheme.first && !uri.hostText.first) { | ||
1015 | /* TODO: implement */ | ||
1016 | die (STATE_UNKNOWN, _("HTTP UNKNOWN - non-absolute location, not implemented yet!\n")); | ||
1017 | new_host = strdup (host_name ? host_name : server_address); | ||
1018 | } else { | ||
1019 | new_host = strdup (uri_string (uri.hostText, buf, DEFAULT_BUFFER_SIZE)); | ||
1020 | } | ||
1021 | |||
1022 | new_url = (char *)calloc( 1, DEFAULT_BUFFER_SIZE); | ||
1023 | if (uri.pathHead) { | ||
1024 | const UriPathSegmentA* p = uri.pathHead; | ||
1025 | for (; p; p = p->next) { | ||
1026 | strncat (new_url, "/", DEFAULT_BUFFER_SIZE); | ||
1027 | strncat (new_url, uri_string (p->text, buf, DEFAULT_BUFFER_SIZE), DEFAULT_BUFFER_SIZE); | ||
1028 | } | ||
1029 | } | ||
1030 | |||
1031 | if (server_port==new_port && | ||
1032 | !strncmp(server_address, new_host, MAX_IPV4_HOSTLENGTH) && | ||
1033 | (host_name && !strncmp(host_name, new_host, MAX_IPV4_HOSTLENGTH)) && | ||
1034 | !strcmp(server_url, new_url)) | ||
1035 | die (STATE_WARNING, | ||
1036 | _("HTTP WARNING - redirection creates an infinite loop - %s://%s:%d%s%s\n"), | ||
1037 | use_ssl ? "https" : "http", new_host, new_port, new_url, (display_html ? "</A>" : "")); | ||
1038 | |||
1039 | /* set new values for redirected request */ | ||
1040 | |||
1041 | free (host_name); | ||
1042 | host_name = strndup (new_host, MAX_IPV4_HOSTLENGTH); | ||
1043 | free(new_host); | ||
1044 | |||
1045 | server_port = (unsigned short)new_port; | ||
1046 | |||
1047 | /* reset virtual port */ | ||
1048 | virtual_port = server_port; | ||
1049 | |||
1050 | if (!(followsticky & STICKY_HOST)) { | ||
1051 | free (server_address); | ||
1052 | server_address = strndup (new_host, MAX_IPV4_HOSTLENGTH); | ||
1053 | } | ||
1054 | if (!(followsticky & STICKY_PORT)) { | ||
1055 | server_port = new_port; | ||
1056 | } | ||
1057 | |||
1058 | free (server_url); | ||
1059 | server_url = new_url; | ||
1060 | |||
1061 | uriFreeUriMembersA (&uri); | ||
1062 | |||
1063 | if (verbose) | ||
1064 | printf (_("Redirection to %s://%s:%d%s\n"), use_ssl ? "https" : "http", | ||
1065 | host_name ? host_name : server_address, server_port, server_url); | ||
1066 | |||
1067 | /* TODO: the hash component MUST be taken from the original URL and | ||
1068 | * attached to the URL in Location | ||
1069 | */ | ||
1070 | |||
1071 | check_http (); | ||
1072 | } | ||
1073 | |||
1074 | #if 0 | ||
1075 | |||
1076 | int main(int argc, char *argv[]) { | ||
1077 | |||
1078 | for (; i < argc; i++) { | ||
1079 | |||
1080 | } | ||
1081 | printf("\n"); | ||
1082 | #endif | ||
1083 | |||
816 | /* check whether a file exists */ | 1084 | /* check whether a file exists */ |
817 | void | 1085 | void |
818 | test_file (char *path) | 1086 | test_file (char *path) |
@@ -974,7 +1242,11 @@ process_arguments (int argc, char **argv) | |||
974 | snprintf (user_agent, DEFAULT_BUFFER_SIZE, optarg); | 1242 | snprintf (user_agent, DEFAULT_BUFFER_SIZE, optarg); |
975 | break; | 1243 | break; |
976 | case 'k': /* Additional headers */ | 1244 | case 'k': /* Additional headers */ |
977 | header_list = curl_slist_append(header_list, optarg); | 1245 | if (http_opt_headers_count == 0) |
1246 | http_opt_headers = malloc (sizeof (char *) * (++http_opt_headers_count)); | ||
1247 | else | ||
1248 | http_opt_headers = realloc (http_opt_headers, sizeof (char *) * (++http_opt_headers_count)); | ||
1249 | http_opt_headers[http_opt_headers_count - 1] = optarg; | ||
978 | break; | 1250 | break; |
979 | case 'L': /* show html link */ | 1251 | case 'L': /* show html link */ |
980 | display_html = TRUE; | 1252 | display_html = TRUE; |
@@ -1121,6 +1393,14 @@ process_arguments (int argc, char **argv) | |||
1121 | onredirect = STATE_UNKNOWN; | 1393 | onredirect = STATE_UNKNOWN; |
1122 | else if (!strcmp (optarg, "follow")) | 1394 | else if (!strcmp (optarg, "follow")) |
1123 | onredirect = STATE_DEPENDENT; | 1395 | onredirect = STATE_DEPENDENT; |
1396 | else if (!strcmp (optarg, "stickyport")) | ||
1397 | onredirect = STATE_DEPENDENT, followmethod = FOLLOW_HTTP_CURL, followsticky = STICKY_HOST|STICKY_PORT; | ||
1398 | else if (!strcmp (optarg, "sticky")) | ||
1399 | onredirect = STATE_DEPENDENT, followmethod = FOLLOW_HTTP_CURL, followsticky = STICKY_HOST; | ||
1400 | else if (!strcmp (optarg, "follow")) | ||
1401 | onredirect = STATE_DEPENDENT, followmethod = FOLLOW_HTTP_CURL, followsticky = STICKY_NONE; | ||
1402 | else if (!strcmp (optarg, "curl")) | ||
1403 | onredirect = STATE_DEPENDENT, followmethod = FOLLOW_LIBCURL; | ||
1124 | else usage2 (_("Invalid onredirect option"), optarg); | 1404 | else usage2 (_("Invalid onredirect option"), optarg); |
1125 | if (verbose >= 2) | 1405 | if (verbose >= 2) |
1126 | printf(_("* Following redirects set to %s\n"), state_text(onredirect)); | 1406 | printf(_("* Following redirects set to %s\n"), state_text(onredirect)); |
@@ -1264,7 +1544,6 @@ print_help (void) | |||
1264 | print_revision (progname, NP_VERSION); | 1544 | print_revision (progname, NP_VERSION); |
1265 | 1545 | ||
1266 | printf ("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n"); | 1546 | printf ("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n"); |
1267 | printf ("Copyright (c) 2017 Andreas Baumann <mail@andreasbaumann.cc>\n"); | ||
1268 | printf (COPYRIGHT, copyright, email); | 1547 | printf (COPYRIGHT, copyright, email); |
1269 | 1548 | ||
1270 | printf ("%s\n", _("This plugin tests the HTTP service on the specified host. It can test")); | 1549 | printf ("%s\n", _("This plugin tests the HTTP service on the specified host. It can test")); |
@@ -1365,8 +1644,11 @@ print_help (void) | |||
1365 | printf (" %s\n", _("Print additional performance data")); | 1644 | printf (" %s\n", _("Print additional performance data")); |
1366 | printf (" %s\n", "-L, --link"); | 1645 | printf (" %s\n", "-L, --link"); |
1367 | printf (" %s\n", _("Wrap output in HTML link (obsoleted by urlize)")); | 1646 | printf (" %s\n", _("Wrap output in HTML link (obsoleted by urlize)")); |
1368 | printf (" %s\n", "-f, --onredirect=<ok|warning|critical|follow>"); | 1647 | printf (" %s\n", "-f, --onredirect=<ok|warning|critical|follow|sticky|stickyport|curl>"); |
1369 | printf (" %s\n", _("How to handle redirected pages.")); | 1648 | printf (" %s\n", _("How to handle redirected pages. sticky is like follow but stick to the")); |
1649 | printf (" %s\n", _("specified IP address. stickyport also ensures port stays the same.")); | ||
1650 | printf (" %s\n", _("follow uses the old redirection algorithm of check_http.")); | ||
1651 | printf (" %s\n", _("curl uses CURL_FOLLOWLOCATION built into libcurl.")); | ||
1370 | printf (" %s\n", "-m, --pagesize=INTEGER<:INTEGER>"); | 1652 | printf (" %s\n", "-m, --pagesize=INTEGER<:INTEGER>"); |
1371 | printf (" %s\n", _("Minimum page size required (bytes) : Maximum page size required (bytes)")); | 1653 | printf (" %s\n", _("Minimum page size required (bytes) : Maximum page size required (bytes)")); |
1372 | 1654 | ||
@@ -1436,7 +1718,7 @@ print_usage (void) | |||
1436 | printf (" %s -H <vhost> | -I <IP-address> [-u <uri>] [-p <port>]\n",progname); | 1718 | printf (" %s -H <vhost> | -I <IP-address> [-u <uri>] [-p <port>]\n",progname); |
1437 | printf (" [-J <client certificate file>] [-K <private key>] [--ca-cert <CA certificate file>]\n"); | 1719 | printf (" [-J <client certificate file>] [-K <private key>] [--ca-cert <CA certificate file>]\n"); |
1438 | printf (" [-w <warn time>] [-c <critical time>] [-t <timeout>] [-L] [-E] [-a auth]\n"); | 1720 | printf (" [-w <warn time>] [-c <critical time>] [-t <timeout>] [-L] [-E] [-a auth]\n"); |
1439 | printf (" [-f <ok|warning|critcal|follow>]\n"); | 1721 | printf (" [-f <ok|warning|critcal|follow|sticky|stickyport|curl>]\n"); |
1440 | printf (" [-e <expect>] [-d string] [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]\n"); | 1722 | printf (" [-e <expect>] [-d string] [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]\n"); |
1441 | printf (" [-P string] [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>]\n"); | 1723 | printf (" [-P string] [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>]\n"); |
1442 | printf (" [-A string] [-k string] [-S <version>] [--sni] [-C <warn_age>[,<crit_age>]]\n"); | 1724 | printf (" [-A string] [-k string] [-S <version>] [--sni] [-C <warn_age>[,<crit_age>]]\n"); |
@@ -1739,7 +2021,7 @@ get_content_length (const curlhelp_write_curlbuf* header_buf, const curlhelp_wri | |||
1739 | content_length_s += strspn (content_length_s, " \t"); | 2021 | content_length_s += strspn (content_length_s, " \t"); |
1740 | content_length = atoi (content_length_s); | 2022 | content_length = atoi (content_length_s); |
1741 | if (content_length != body_buf->buflen) { | 2023 | if (content_length != body_buf->buflen) { |
1742 | /* TODO: should we warn if the actual and the reported body length doen't match? */ | 2024 | /* TODO: should we warn if the actual and the reported body length don't match? */ |
1743 | } | 2025 | } |
1744 | 2026 | ||
1745 | if (content_length_s) free (content_length_s); | 2027 | if (content_length_s) free (content_length_s); |