summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_tcp.c36
1 files changed, 28 insertions, 8 deletions
diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c
index 7d8d814..b922536 100644
--- a/plugins/check_tcp.c
+++ b/plugins/check_tcp.c
@@ -99,8 +99,8 @@ int verbose = FALSE;
99int use_ssl = FALSE; 99int use_ssl = FALSE;
100int sd = 0; 100int sd = 0;
101char *buffer; 101char *buffer;
102 102int expect_mismatch_state = STATE_WARNING;
103 103int exact_matching = TRUE;
104 104
105int 105int
106main (int argc, char **argv) 106main (int argc, char **argv)
@@ -332,9 +332,15 @@ main (int argc, char **argv)
332 if (verbose) 332 if (verbose)
333 printf ("%d %d\n", i, (int)server_expect_count); 333 printf ("%d %d\n", i, (int)server_expect_count);
334 if (i >= (int)server_expect_count) 334 if (i >= (int)server_expect_count)
335 die (STATE_WARNING, _("Invalid response from host\n")); 335 die (expect_mismatch_state, _("Unexpected response from host: %s\n"), status);
336 if (strstr (status, server_expect[i])) 336 /* default expect gets exact matching */
337 break; 337 if (exact_matching) {
338 if (strncmp(status, server_expect[i], strlen(server_expect[i])) == 0)
339 break;
340 } else {
341 if (strstr (status, server_expect[i]))
342 break;
343 }
338 } 344 }
339 } 345 }
340 } 346 }
@@ -414,6 +420,7 @@ process_arguments (int argc, char **argv)
414 {"jail", required_argument, 0, 'j'}, 420 {"jail", required_argument, 0, 'j'},
415 {"delay", required_argument, 0, 'd'}, 421 {"delay", required_argument, 0, 'd'},
416 {"refuse", required_argument, 0, 'r'}, 422 {"refuse", required_argument, 0, 'r'},
423 {"mismatch", required_argument, 0, 'M'},
417 {"use-ipv4", no_argument, 0, '4'}, 424 {"use-ipv4", no_argument, 0, '4'},
418 {"use-ipv6", no_argument, 0, '6'}, 425 {"use-ipv6", no_argument, 0, '6'},
419 {"verbose", no_argument, 0, 'v'}, 426 {"verbose", no_argument, 0, 'v'},
@@ -447,7 +454,7 @@ process_arguments (int argc, char **argv)
447 } 454 }
448 455
449 while (1) { 456 while (1) {
450 c = getopt_long (argc, argv, "+hVv46H:s:e:q:m:c:w:t:p:C:W:d:Sr:jD:", 457 c = getopt_long (argc, argv, "+hVv46H:s:e:q:m:c:w:t:p:C:W:d:Sr:jD:M:",
451 longopts, &option); 458 longopts, &option);
452 459
453 if (c == -1 || c == EOF || c == 1) 460 if (c == -1 || c == EOF || c == 1)
@@ -524,6 +531,7 @@ process_arguments (int argc, char **argv)
524 break; 531 break;
525 case 'e': /* expect string (may be repeated) */ 532 case 'e': /* expect string (may be repeated) */
526 EXPECT = NULL; 533 EXPECT = NULL;
534 exact_matching = FALSE;
527 if (server_expect_count == 0) 535 if (server_expect_count == 0)
528 server_expect = malloc (sizeof (char *) * (++server_expect_count)); 536 server_expect = malloc (sizeof (char *) * (++server_expect_count));
529 else 537 else
@@ -548,6 +556,16 @@ process_arguments (int argc, char **argv)
548 else 556 else
549 usage4 (_("Refuse must be one of ok, warn, crit")); 557 usage4 (_("Refuse must be one of ok, warn, crit"));
550 break; 558 break;
559 case 'M':
560 if (!strncmp(optarg,"ok",2))
561 expect_mismatch_state = STATE_OK;
562 else if (!strncmp(optarg,"warn",4))
563 expect_mismatch_state = STATE_WARNING;
564 else if (!strncmp(optarg,"crit",4))
565 expect_mismatch_state = STATE_CRITICAL;
566 else
567 usage4 (_("Mismatch must be one of ok, warn, crit"));
568 break;
551 case 'd': 569 case 'd':
552 if (is_intpos (optarg)) 570 if (is_intpos (optarg))
553 delay = atoi (optarg); 571 delay = atoi (optarg);
@@ -764,6 +782,8 @@ print_help (void)
764 printf (_("\ 782 printf (_("\
765 -r, --refuse=ok|warn|crit\n\ 783 -r, --refuse=ok|warn|crit\n\
766 Accept tcp refusals with states ok, warn, crit (default: crit)\n\ 784 Accept tcp refusals with states ok, warn, crit (default: crit)\n\
785 -M, --mismatch=ok|warn|crit\n\
786 Accept expected string mismatches with states ok, warn, crit (default: warn)\n\
767 -j, --jail\n\ 787 -j, --jail\n\
768 Hide output from TCP socket\n\ 788 Hide output from TCP socket\n\
769 -m, --maxbytes=INTEGER\n\ 789 -m, --maxbytes=INTEGER\n\
@@ -797,6 +817,6 @@ print_usage (void)
797Usage: %s -H host -p port [-w <warning time>] [-c <critical time>]\n\ 817Usage: %s -H host -p port [-w <warning time>] [-c <critical time>]\n\
798 [-s <send string>] [-e <expect string>] [-q <quit string>]\n\ 818 [-s <send string>] [-e <expect string>] [-q <quit string>]\n\
799 [-m <maximum bytes>] [-d <delay>] [-t <timeout seconds>]\n\ 819 [-m <maximum bytes>] [-d <delay>] [-t <timeout seconds>]\n\
800 [-r <refuse state>] [-v] [-4|-6] [-j] [-D <days to cert expiry>]\n\ 820 [-r <refuse state>] [-M <mismatch state>] [-v] [-4|-6] [-j]\n\
801 [-S <use SSL>]\n", progname); 821 [-D <days to cert expiry>] [-S <use SSL>]\n", progname);
802} 822}