diff options
-rw-r--r-- | plugins/check_tcp.c | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c index 8a2dcc5..444166d 100644 --- a/plugins/check_tcp.c +++ b/plugins/check_tcp.c | |||
@@ -82,6 +82,7 @@ char *server_send = NULL; | |||
82 | char *server_quit = NULL; | 82 | char *server_quit = NULL; |
83 | char **server_expect = NULL; | 83 | char **server_expect = NULL; |
84 | int server_expect_count = 0; | 84 | int server_expect_count = 0; |
85 | int maxbytes = 0; | ||
85 | char **warn_codes = NULL; | 86 | char **warn_codes = NULL; |
86 | int warn_codes_count = 0; | 87 | int warn_codes_count = 0; |
87 | char **crit_codes = NULL; | 88 | char **crit_codes = NULL; |
@@ -260,6 +261,8 @@ main (int argc, char **argv) | |||
260 | asprintf (&status, "%s%s", status, buffer); | 261 | asprintf (&status, "%s%s", status, buffer); |
261 | if (buffer[i-2] == '\r' && buffer[i-1] == '\n') | 262 | if (buffer[i-2] == '\r' && buffer[i-1] == '\n') |
262 | break; | 263 | break; |
264 | if (maxbytes>0 && strlen(status)>maxbytes) | ||
265 | break; | ||
263 | } | 266 | } |
264 | 267 | ||
265 | /* return a CRITICAL status if we couldn't read any data */ | 268 | /* return a CRITICAL status if we couldn't read any data */ |
@@ -347,6 +350,7 @@ process_arguments (int argc, char **argv) | |||
347 | {"port", required_argument, 0, 'p'}, | 350 | {"port", required_argument, 0, 'p'}, |
348 | {"send", required_argument, 0, 's'}, | 351 | {"send", required_argument, 0, 's'}, |
349 | {"expect", required_argument, 0, 'e'}, | 352 | {"expect", required_argument, 0, 'e'}, |
353 | {"maxbytes", required_argument, 0, 'm'}, | ||
350 | {"quit", required_argument, 0, 'q'}, | 354 | {"quit", required_argument, 0, 'q'}, |
351 | {"delay", required_argument, 0, 'd'}, | 355 | {"delay", required_argument, 0, 'd'}, |
352 | {"verbose", no_argument, 0, 'v'}, | 356 | {"verbose", no_argument, 0, 'v'}, |
@@ -379,10 +383,10 @@ process_arguments (int argc, char **argv) | |||
379 | while (1) { | 383 | while (1) { |
380 | #ifdef HAVE_GETOPT_H | 384 | #ifdef HAVE_GETOPT_H |
381 | c = | 385 | c = |
382 | getopt_long (argc, argv, "+hVvH:s:e:q:c:w:t:p:C:W:d:S", long_options, | 386 | getopt_long (argc, argv, "+hVvH:s:e:q:m:c:w:t:p:C:W:d:S", long_options, |
383 | &option_index); | 387 | &option_index); |
384 | #else | 388 | #else |
385 | c = getopt (argc, argv, "+hVvH:s:e:q:c:w:t:p:C:W:d:S"); | 389 | c = getopt (argc, argv, "+hVvH:s:e:q:m:c:w:t:p:C:W:d:S"); |
386 | #endif | 390 | #endif |
387 | 391 | ||
388 | if (c == -1 || c == EOF || c == 1) | 392 | if (c == -1 || c == EOF || c == 1) |
@@ -448,6 +452,10 @@ process_arguments (int argc, char **argv) | |||
448 | server_expect = realloc (server_expect, ++server_expect_count); | 452 | server_expect = realloc (server_expect, ++server_expect_count); |
449 | server_expect[server_expect_count - 1] = optarg; | 453 | server_expect[server_expect_count - 1] = optarg; |
450 | break; | 454 | break; |
455 | case 'm': | ||
456 | if (!is_intpos (optarg)) | ||
457 | usage ("Maxbytes must be a positive integer\n"); | ||
458 | maxbytes = atoi (optarg); | ||
451 | case 'q': | 459 | case 'q': |
452 | server_quit = optarg; | 460 | server_quit = optarg; |
453 | break; | 461 | break; |
@@ -481,8 +489,9 @@ void | |||
481 | print_usage (void) | 489 | print_usage (void) |
482 | { | 490 | { |
483 | printf | 491 | printf |
484 | ("Usage: %s -H host -p port [-w warn_time] [-c crit_time] [-s send]\n" | 492 | ("Usage: %s -H host -p port [-w warn_time] [-c crit_time] [-s send_string]\n" |
485 | " [-e expect] [-W wait] [-t to_sec] [-v]\n", progname); | 493 | " [-e expect_string] [-q quit_string] [-m maxbytes] [-W wait]\n" |
494 | " [-t to_sec] [-v]\n", progname); | ||
486 | } | 495 | } |
487 | 496 | ||
488 | 497 | ||
@@ -508,8 +517,12 @@ print_help (void) | |||
508 | " -s, --send=STRING\n" | 517 | " -s, --send=STRING\n" |
509 | " String to send to the server\n" | 518 | " String to send to the server\n" |
510 | " -e, --expect=STRING\n" | 519 | " -e, --expect=STRING\n" |
511 | " String to expect in server response" | 520 | " String to expect in server response\n" |
512 | " -W, --wait=INTEGER\n" | 521 | " -q, --quit=STRING\n" |
522 | " String to send server to initiate a clean close of the connection\n" | ||
523 | " -m, --maxbytes=INTEGER\n" | ||
524 | " Close connection once more than this number of bytes are received\n" | ||
525 | " -d, --delay=INTEGER\n" | ||
513 | " Seconds to wait between sending string and polling for response\n" | 526 | " Seconds to wait between sending string and polling for response\n" |
514 | " -w, --warning=DOUBLE\n" | 527 | " -w, --warning=DOUBLE\n" |
515 | " Response time to result in warning status (seconds)\n" | 528 | " Response time to result in warning status (seconds)\n" |
@@ -525,6 +538,12 @@ print_help (void) | |||
525 | " Print version information\n", DEFAULT_SOCKET_TIMEOUT); | 538 | " Print version information\n", DEFAULT_SOCKET_TIMEOUT); |
526 | } | 539 | } |
527 | 540 | ||
541 | /* | ||
542 | " -W, --warning-codes=STRING\n" | ||
543 | " \n" | ||
544 | " -C, --critical-code=STRING\n" | ||
545 | " \n" | ||
546 | */ | ||
528 | 547 | ||
529 | #ifdef HAVE_SSL | 548 | #ifdef HAVE_SSL |
530 | int | 549 | int |