diff options
| author | Andreas Baumann <mail@andreasbaumann.cc> | 2017-03-17 16:59:44 +0100 |
|---|---|---|
| committer | Andreas Baumann <mail@andreasbaumann.cc> | 2017-03-17 16:59:44 +0100 |
| commit | 470a68b9c08f02e3330fc3e45cb5c58b69367cff (patch) | |
| tree | 828df96bb4f56a6d89cfefb6ac1ba82007f0a56c | |
| parent | 3ae5ab7fab8d79d2edc8b10d50bfe82551483624 (diff) | |
| download | monitoring-plugins-470a68b9c08f02e3330fc3e45cb5c58b69367cff.tar.gz | |
added -m/--pagesize option
| -rw-r--r-- | plugins/check_curl.c | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/plugins/check_curl.c b/plugins/check_curl.c index 0770d905..49b430c0 100644 --- a/plugins/check_curl.c +++ b/plugins/check_curl.c | |||
| @@ -100,6 +100,8 @@ thresholds *thlds; | |||
| 100 | char user_agent[DEFAULT_BUFFER_SIZE]; | 100 | char user_agent[DEFAULT_BUFFER_SIZE]; |
| 101 | int verbose = 0; | 101 | int verbose = 0; |
| 102 | int show_extended_perfdata = FALSE; | 102 | int show_extended_perfdata = FALSE; |
| 103 | int min_page_len = 0; | ||
| 104 | int max_page_len = 0; | ||
| 103 | char *http_method = NULL; | 105 | char *http_method = NULL; |
| 104 | CURL *curl; | 106 | CURL *curl; |
| 105 | struct curl_slist *header_list = NULL; | 107 | struct curl_slist *header_list = NULL; |
| @@ -189,6 +191,7 @@ int | |||
| 189 | check_http (void) | 191 | check_http (void) |
| 190 | { | 192 | { |
| 191 | int result = STATE_OK; | 193 | int result = STATE_OK; |
| 194 | int page_len = 0; | ||
| 192 | 195 | ||
| 193 | /* initialize curl */ | 196 | /* initialize curl */ |
| 194 | if (curl_global_init (CURL_GLOBAL_DEFAULT) != CURLE_OK) | 197 | if (curl_global_init (CURL_GLOBAL_DEFAULT) != CURLE_OK) |
| @@ -467,6 +470,19 @@ check_http (void) | |||
| 467 | } | 470 | } |
| 468 | } | 471 | } |
| 469 | 472 | ||
| 473 | /* make sure the page is of an appropriate size | ||
| 474 | * TODO: as far I can tell check_http gets the full size of header and | ||
| 475 | * if -N is not given header+body. Does this make sense? | ||
| 476 | */ | ||
| 477 | page_len = header_buf.buflen + body_buf.buflen; | ||
| 478 | if ((max_page_len > 0) && (page_len > max_page_len)) { | ||
| 479 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("%spage size %d too large, "), msg, page_len); | ||
| 480 | result = max_state_alt(STATE_WARNING, result); | ||
| 481 | } else if ((min_page_len > 0) && (page_len < min_page_len)) { | ||
| 482 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("%spage size %d too small, "), msg, page_len); | ||
| 483 | result = max_state_alt(STATE_WARNING, result); | ||
| 484 | } | ||
| 485 | |||
| 470 | /* -w, -c: check warning and critical level */ | 486 | /* -w, -c: check warning and critical level */ |
| 471 | result = max_state_alt(get_status(total_time, thlds), result); | 487 | result = max_state_alt(get_status(total_time, thlds), result); |
| 472 | 488 | ||
| @@ -530,6 +546,7 @@ process_arguments (int argc, char **argv) | |||
| 530 | {"useragent", required_argument, 0, 'A'}, | 546 | {"useragent", required_argument, 0, 'A'}, |
| 531 | {"header", required_argument, 0, 'k'}, | 547 | {"header", required_argument, 0, 'k'}, |
| 532 | {"no-body", no_argument, 0, 'N'}, | 548 | {"no-body", no_argument, 0, 'N'}, |
| 549 | {"pagesize", required_argument, 0, 'm'}, | ||
| 533 | {"invert-regex", no_argument, NULL, INVERT_REGEX}, | 550 | {"invert-regex", no_argument, NULL, INVERT_REGEX}, |
| 534 | {"extended-perfdata", no_argument, 0, 'E'}, | 551 | {"extended-perfdata", no_argument, 0, 'E'}, |
| 535 | {0, 0, 0, 0} | 552 | {0, 0, 0, 0} |
| @@ -539,7 +556,7 @@ process_arguments (int argc, char **argv) | |||
| 539 | return ERROR; | 556 | return ERROR; |
| 540 | 557 | ||
| 541 | while (1) { | 558 | while (1) { |
| 542 | c = getopt_long (argc, argv, "Vvht:c:w:A:k:H:j:I:a:p:s:R:r:u:f:C:J:K:S::NE", longopts, &option); | 559 | c = getopt_long (argc, argv, "Vvht:c:w:A:k:H:j:I:a:p:s:R:r:u:f:C:J:K:S::m:NE", longopts, &option); |
| 543 | if (c == -1 || c == EOF || c == 1) | 560 | if (c == -1 || c == EOF || c == 1) |
| 544 | break; | 561 | break; |
| 545 | 562 | ||
| @@ -724,6 +741,28 @@ process_arguments (int argc, char **argv) | |||
| 724 | case INVERT_REGEX: | 741 | case INVERT_REGEX: |
| 725 | invert_regex = 1; | 742 | invert_regex = 1; |
| 726 | break; | 743 | break; |
| 744 | case 'm': /* min_page_length */ | ||
| 745 | { | ||
| 746 | char *tmp; | ||
| 747 | if (strchr(optarg, ':') != (char *)NULL) { | ||
| 748 | /* range, so get two values, min:max */ | ||
| 749 | tmp = strtok(optarg, ":"); | ||
| 750 | if (tmp == NULL) { | ||
| 751 | printf("Bad format: try \"-m min:max\"\n"); | ||
| 752 | exit (STATE_WARNING); | ||
| 753 | } else | ||
| 754 | min_page_len = atoi(tmp); | ||
| 755 | |||
| 756 | tmp = strtok(NULL, ":"); | ||
| 757 | if (tmp == NULL) { | ||
| 758 | printf("Bad format: try \"-m min:max\"\n"); | ||
| 759 | exit (STATE_WARNING); | ||
| 760 | } else | ||
| 761 | max_page_len = atoi(tmp); | ||
| 762 | } else | ||
| 763 | min_page_len = atoi (optarg); | ||
| 764 | break; | ||
| 765 | } | ||
| 727 | case 'N': /* no-body */ | 766 | case 'N': /* no-body */ |
| 728 | no_body = TRUE; | 767 | no_body = TRUE; |
| 729 | break; | 768 | break; |
| @@ -859,6 +898,8 @@ print_help (void) | |||
| 859 | printf (" %s\n", _("Print additional performance data")); | 898 | printf (" %s\n", _("Print additional performance data")); |
| 860 | printf (" %s\n", "-f, --onredirect=<ok|warning|critical|follow>"); | 899 | printf (" %s\n", "-f, --onredirect=<ok|warning|critical|follow>"); |
| 861 | printf (" %s\n", _("How to handle redirected pages.")); | 900 | printf (" %s\n", _("How to handle redirected pages.")); |
| 901 | printf (" %s\n", "-m, --pagesize=INTEGER<:INTEGER>"); | ||
| 902 | printf (" %s\n", _("Minimum page size required (bytes) : Maximum page size required (bytes)")); | ||
| 862 | 903 | ||
| 863 | printf (UT_WARN_CRIT); | 904 | printf (UT_WARN_CRIT); |
| 864 | 905 | ||
| @@ -928,6 +969,7 @@ print_usage (void) | |||
| 928 | printf (" [-w <warn time>] [-c <critical time>] [-t <timeout>] [-E] [-a auth]\n"); | 969 | printf (" [-w <warn time>] [-c <critical time>] [-t <timeout>] [-E] [-a auth]\n"); |
| 929 | printf (" [-f <ok|warning|critcal|follow>]\n"); | 970 | printf (" [-f <ok|warning|critcal|follow>]\n"); |
| 930 | printf (" [-s string] [-r <regex> | -R <case-insensitive regex>]\n"); | 971 | printf (" [-s string] [-r <regex> | -R <case-insensitive regex>]\n"); |
| 972 | printf (" [-m <min_pg_size>:<max_pg_size>] [-N]\n"); | ||
| 931 | printf (" [-N]\n"); | 973 | printf (" [-N]\n"); |
| 932 | printf (" [-A string] [-k string] [-S <version>] [-C]\n"); | 974 | printf (" [-A string] [-k string] [-S <version>] [-C]\n"); |
| 933 | printf (" [-v verbose]\n", progname); | 975 | printf (" [-v verbose]\n", progname); |
