diff options
-rw-r--r-- | plugins/check_http.c | 94 |
1 files changed, 84 insertions, 10 deletions
diff --git a/plugins/check_http.c b/plugins/check_http.c index 6e767062..53284751 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c | |||
@@ -114,6 +114,7 @@ int use_ssl = FALSE; | |||
114 | int verbose = FALSE; | 114 | int verbose = FALSE; |
115 | int sd; | 115 | int sd; |
116 | int min_page_len = 0; | 116 | int min_page_len = 0; |
117 | int max_page_len = 0; | ||
117 | int redir_depth = 0; | 118 | int redir_depth = 0; |
118 | int max_depth = 15; | 119 | int max_depth = 15; |
119 | char *http_method; | 120 | char *http_method; |
@@ -222,7 +223,7 @@ process_arguments (int argc, char **argv) | |||
222 | {"no-body", no_argument, 0, 'N'}, | 223 | {"no-body", no_argument, 0, 'N'}, |
223 | {"max-age", required_argument, 0, 'M'}, | 224 | {"max-age", required_argument, 0, 'M'}, |
224 | {"content-type", required_argument, 0, 'T'}, | 225 | {"content-type", required_argument, 0, 'T'}, |
225 | {"min", required_argument, 0, 'm'}, | 226 | {"minmax", required_argument, 0, 'm'}, |
226 | {"use-ipv4", no_argument, 0, '4'}, | 227 | {"use-ipv4", no_argument, 0, '4'}, |
227 | {"use-ipv6", no_argument, 0, '6'}, | 228 | {"use-ipv6", no_argument, 0, '6'}, |
228 | {0, 0, 0, 0} | 229 | {0, 0, 0, 0} |
@@ -408,8 +409,27 @@ process_arguments (int argc, char **argv) | |||
408 | verbose = TRUE; | 409 | verbose = TRUE; |
409 | break; | 410 | break; |
410 | case 'm': /* min_page_length */ | 411 | case 'm': /* min_page_length */ |
411 | min_page_len = atoi (optarg); | 412 | { |
413 | char *tmp; | ||
414 | if (strchr(optarg, ':') != (char *)NULL) { | ||
415 | /* range, so get two values, min:max */ | ||
416 | tmp = strtok(optarg, ":"); | ||
417 | if (tmp == NULL) { | ||
418 | printf("Bad format: try \"-m min:max\"\n"); | ||
419 | exit (STATE_WARNING); | ||
420 | } else | ||
421 | min_page_len = atoi(tmp); | ||
422 | |||
423 | tmp = strtok(NULL, ":"); | ||
424 | if (tmp == NULL) { | ||
425 | printf("Bad format: try \"-m min:max\"\n"); | ||
426 | exit (STATE_WARNING); | ||
427 | } else | ||
428 | max_page_len = atoi(tmp); | ||
429 | } else | ||
430 | min_page_len = atoi (optarg); | ||
412 | break; | 431 | break; |
432 | } | ||
413 | case 'N': /* no-body */ | 433 | case 'N': /* no-body */ |
414 | no_body = TRUE; | 434 | no_body = TRUE; |
415 | break; | 435 | break; |
@@ -427,7 +447,7 @@ process_arguments (int argc, char **argv) | |||
427 | maximum_age = atoi (optarg); | 447 | maximum_age = atoi (optarg); |
428 | else { | 448 | else { |
429 | fprintf (stderr, "unparsable max-age: %s\n", optarg); | 449 | fprintf (stderr, "unparsable max-age: %s\n", optarg); |
430 | exit (1); | 450 | exit (STATE_WARNING); |
431 | } | 451 | } |
432 | } | 452 | } |
433 | break; | 453 | break; |
@@ -700,7 +720,55 @@ check_document_dates (const char *headers) | |||
700 | } | 720 | } |
701 | } | 721 | } |
702 | 722 | ||
723 | int | ||
724 | get_content_length (const char *headers) | ||
725 | { | ||
726 | const char *s; | ||
727 | int content_length = 0; | ||
728 | |||
729 | s = headers; | ||
730 | while (*s) { | ||
731 | const char *field = s; | ||
732 | const char *value = 0; | ||
733 | |||
734 | /* Find the end of the header field */ | ||
735 | while (*s && !isspace(*s) && *s != ':') | ||
736 | s++; | ||
737 | |||
738 | /* Remember the header value, if any. */ | ||
739 | if (*s == ':') | ||
740 | value = ++s; | ||
741 | |||
742 | /* Skip to the end of the header, including continuation lines. */ | ||
743 | while (*s && !(*s == '\n' && (s[1] != ' ' && s[1] != '\t'))) | ||
744 | s++; | ||
745 | s++; | ||
746 | |||
747 | /* Process this header. */ | ||
748 | if (value && value > field+2) { | ||
749 | char *ff = (char *) malloc (value-field); | ||
750 | char *ss = ff; | ||
751 | while (field < value-1) | ||
752 | *ss++ = tolower(*field++); | ||
753 | *ss++ = 0; | ||
703 | 754 | ||
755 | if (!strcmp (ff, "content-length")) { | ||
756 | const char *e; | ||
757 | while (*value && isspace (*value)) | ||
758 | value++; | ||
759 | for (e = value; *e && *e != '\r' && *e != '\n'; e++) | ||
760 | ; | ||
761 | ss = (char *) malloc (e - value + 1); | ||
762 | strncpy (ss, value, e - value); | ||
763 | ss[e - value] = 0; | ||
764 | content_length = atoi(ss); | ||
765 | free (ss); | ||
766 | } | ||
767 | free (ff); | ||
768 | } | ||
769 | } | ||
770 | return (content_length); | ||
771 | } | ||
704 | 772 | ||
705 | int | 773 | int |
706 | check_http (void) | 774 | check_http (void) |
@@ -774,6 +842,7 @@ check_http (void) | |||
774 | } else { | 842 | } else { |
775 | asprintf (&buf, "%sContent-Type: application/x-www-form-urlencoded\r\n", buf); | 843 | asprintf (&buf, "%sContent-Type: application/x-www-form-urlencoded\r\n", buf); |
776 | } | 844 | } |
845 | |||
777 | asprintf (&buf, "%sContent-Length: %i\r\n\r\n", buf, strlen (http_post_data)); | 846 | asprintf (&buf, "%sContent-Length: %i\r\n\r\n", buf, strlen (http_post_data)); |
778 | asprintf (&buf, "%s%s%s", buf, http_post_data, CRLF); | 847 | asprintf (&buf, "%s%s%s", buf, http_post_data, CRLF); |
779 | } | 848 | } |
@@ -1005,8 +1074,13 @@ check_http (void) | |||
1005 | #endif | 1074 | #endif |
1006 | 1075 | ||
1007 | /* make sure the page is of an appropriate size */ | 1076 | /* make sure the page is of an appropriate size */ |
1008 | page_len = strlen (page); | 1077 | /* page_len = get_content_length(header); */ |
1009 | if ((min_page_len > 0) && (page_len < min_page_len)) { | 1078 | page_len = pagesize; |
1079 | if ((max_page_len > 0) && (page_len > max_page_len)) { | ||
1080 | printf (_("HTTP WARNING: page size %d too large%s|%s\n"), | ||
1081 | page_len, (display_html ? "</A>" : ""), perfd_size (page_len) ); | ||
1082 | exit (STATE_WARNING); | ||
1083 | } else if ((min_page_len > 0) && (page_len < min_page_len)) { | ||
1010 | printf (_("HTTP WARNING: page size %d too small%s|%s\n"), | 1084 | printf (_("HTTP WARNING: page size %d too small%s|%s\n"), |
1011 | page_len, (display_html ? "</A>" : ""), perfd_size (page_len) ); | 1085 | page_len, (display_html ? "</A>" : ""), perfd_size (page_len) ); |
1012 | exit (STATE_WARNING); | 1086 | exit (STATE_WARNING); |
@@ -1442,8 +1516,8 @@ certificate expiration times.\n\n")); | |||
1442 | Wrap output in HTML link (obsoleted by urlize)\n\ | 1516 | Wrap output in HTML link (obsoleted by urlize)\n\ |
1443 | -f, --onredirect=<ok|warning|critical|follow>\n\ | 1517 | -f, --onredirect=<ok|warning|critical|follow>\n\ |
1444 | How to handle redirected pages\n\ | 1518 | How to handle redirected pages\n\ |
1445 | -m, --min=INTEGER\n\ | 1519 | -m, --minmax=INTEGER<:INTEGER>\n\ |
1446 | Minimum page size required (bytes)\n")); | 1520 | Minimum page size required (bytes) : Maximum page size required (bytes)\n")); |
1447 | 1521 | ||
1448 | printf (_(UT_WARN_CRIT)); | 1522 | printf (_(UT_WARN_CRIT)); |
1449 | 1523 | ||
@@ -1489,10 +1563,10 @@ void | |||
1489 | print_usage (void) | 1563 | print_usage (void) |
1490 | { | 1564 | { |
1491 | printf ("\ | 1565 | printf ("\ |
1492 | Usage: %s -H <vhost> | -I <IP-address>) [-u <uri>] [-p <port>]\n\ | 1566 | Usage: %s -H <vhost> | -I <IP-address> [-u <uri>] [-p <port>]\n\ |
1493 | [-w <warn time>] [-c <critical time>] [-t <timeout>] [-L]\n\ | 1567 | [-w <warn time>] [-c <critical time>] [-t <timeout>] [-L]\n\ |
1494 | [-a auth] [-f <ok | warn | critcal | follow>] [-e <expect>]\n\ | 1568 | [-a auth] [-f <ok | warn | critcal | follow>] [-e <expect>]\n\ |
1495 | [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]\n\ | 1569 | [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]\n\ |
1496 | [-P string] [-m min_pg_size] [-4|-6] [-N] [-M <age>]\n\ | 1570 | [-P string] [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] \n\ |
1497 | [-A string] [-k string]\n", progname); | 1571 | [-M <age>] [-A string] [-k string]\n", progname); |
1498 | } | 1572 | } |