7cef8bb92b8cb180aea81eec6707b3a450f72fc8
1 /*****************************************************************************
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2 of the License, or
6 (at your option) any later version.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 *****************************************************************************/
19 /* progname "check_tcp" changes depending on symlink called */
20 char *progname;
21 const char *revision = "$Revision$";
22 const char *copyright = "1999-2003";
23 const char *email = "nagiosplug-devel@lists.sourceforge.net";
25 #include "common.h"
26 #include "netutils.h"
27 #include "utils.h"
29 #ifdef HAVE_SSL_H
30 # include <rsa.h>
31 # include <crypto.h>
32 # include <x509.h>
33 # include <pem.h>
34 # include <ssl.h>
35 # include <err.h>
36 #else
37 # ifdef HAVE_OPENSSL_SSL_H
38 # include <openssl/rsa.h>
39 # include <openssl/crypto.h>
40 # include <openssl/x509.h>
41 # include <openssl/pem.h>
42 # include <openssl/ssl.h>
43 # include <openssl/err.h>
44 # endif
45 #endif
47 #ifdef HAVE_SSL
48 int check_cert = FALSE;
49 int days_till_exp;
50 char *randbuff = "";
51 SSL_CTX *ctx;
52 SSL *ssl;
53 X509 *server_cert;
54 int connect_SSL (void);
55 int check_certificate (X509 **);
56 #endif
58 enum {
59 TCP_PROTOCOL = 1,
60 UDP_PROTOCOL = 2,
61 MAXBUF = 1024
62 };
64 int process_arguments (int, char **);
65 int my_recv (void);
66 void print_help (void);
67 void print_usage (void);
69 char *SERVICE = NULL;
70 char *SEND = NULL;
71 char *EXPECT = NULL;
72 char *QUIT = NULL;
73 int PROTOCOL = 0;
74 int PORT = 0;
76 char timestamp[17] = "";
77 int server_port = 0;
78 char *server_address = NULL;
79 char *server_send = NULL;
80 char *server_quit = NULL;
81 char **server_expect = NULL;
82 size_t server_expect_count = 0;
83 int maxbytes = 0;
84 char **warn_codes = NULL;
85 size_t warn_codes_count = 0;
86 char **crit_codes = NULL;
87 size_t crit_codes_count = 0;
88 unsigned int delay = 0;
89 double warning_time = 0;
90 int check_warning_time = FALSE;
91 double critical_time = 0;
92 int check_critical_time = FALSE;
93 int hide_output = FALSE;
94 double elapsed_time = 0;
95 long microsec;
96 int verbose = FALSE;
97 int use_ssl = FALSE;
98 int sd = 0;
99 char *buffer;
105 \f
106 int
107 main (int argc, char **argv)
108 {
109 int result;
110 int i;
111 char *status;
112 struct timeval tv;
114 setlocale (LC_ALL, "");
115 bindtextdomain (PACKAGE, LOCALEDIR);
116 textdomain (PACKAGE);
118 if (strstr (argv[0], "check_udp")) {
119 progname = strdup ("check_udp");
120 SERVICE = strdup ("UDP");
121 SEND = NULL;
122 EXPECT = NULL;
123 QUIT = NULL;
124 PROTOCOL = UDP_PROTOCOL;
125 PORT = 0;
126 }
127 else if (strstr (argv[0], "check_tcp")) {
128 progname = strdup ("check_tcp");
129 SERVICE = strdup ("TCP");
130 SEND = NULL;
131 EXPECT = NULL;
132 QUIT = NULL;
133 PROTOCOL = TCP_PROTOCOL;
134 PORT = 0;
135 }
136 else if (strstr (argv[0], "check_ftp")) {
137 progname = strdup ("check_ftp");
138 SERVICE = strdup ("FTP");
139 SEND = NULL;
140 EXPECT = strdup ("220");
141 QUIT = strdup ("QUIT\r\n");
142 PROTOCOL = TCP_PROTOCOL;
143 PORT = 21;
144 }
145 else if (strstr (argv[0], "check_smtp")) {
146 progname = strdup ("check_smtp");
147 SERVICE = strdup ("SMTP");
148 SEND = NULL;
149 EXPECT = strdup ("220");
150 QUIT = strdup ("QUIT\r\n");
151 PROTOCOL = TCP_PROTOCOL;
152 PORT = 25;
153 }
154 else if (strstr (argv[0], "check_pop")) {
155 progname = strdup ("check_pop");
156 SERVICE = strdup ("POP");
157 SEND = NULL;
158 EXPECT = strdup ("+OK");
159 QUIT = strdup ("QUIT\r\n");
160 PROTOCOL = TCP_PROTOCOL;
161 PORT = 110;
162 }
163 else if (strstr (argv[0], "check_imap")) {
164 progname = strdup ("check_imap");
165 SERVICE = strdup ("IMAP");
166 SEND = NULL;
167 EXPECT = strdup ("* OK");
168 QUIT = strdup ("a1 LOGOUT\r\n");
169 PROTOCOL = TCP_PROTOCOL;
170 PORT = 143;
171 }
172 #ifdef HAVE_SSL
173 else if (strstr(argv[0],"check_simap")) {
174 progname = strdup ("check_simap");
175 SERVICE = strdup ("SIMAP");
176 SEND=NULL;
177 EXPECT = strdup ("* OK");
178 QUIT = strdup ("a1 LOGOUT\r\n");
179 PROTOCOL=TCP_PROTOCOL;
180 use_ssl=TRUE;
181 PORT=993;
182 }
183 else if (strstr(argv[0],"check_spop")) {
184 progname = strdup ("check_spop");
185 SERVICE = strdup ("SPOP");
186 SEND=NULL;
187 EXPECT = strdup ("+OK");
188 QUIT = strdup ("QUIT\r\n");
189 PROTOCOL=TCP_PROTOCOL;
190 use_ssl=TRUE;
191 PORT=995;
192 }
193 else if (strstr(argv[0],"check_jabber")) {
194 progname = strdup("check_jabber");
195 SERVICE = strdup("JABBER");
196 SEND = strdup("<stream:stream to=\'host\' xmlns=\'jabber:client\' xmlns:stream=\'http://etherx.jabber.org/streams\'>\n");
197 EXPECT = strdup("<?xml version=\'1.0\'?><stream:stream xmlns:stream=\'http://etherx.jabber.org/streams\'");
198 QUIT = strdup("</stream:stream>\n");
199 PROTOCOL=TCP_PROTOCOL;
200 use_ssl=TRUE;
201 PORT = 5222;
202 }
203 else if (strstr (argv[0], "check_nntps")) {
204 progname = strdup("check_nntps");
205 SERVICE = strdup("NNTPS");
206 SEND = NULL;
207 EXPECT = NULL;
208 server_expect = realloc (server_expect, ++server_expect_count);
209 asprintf (&server_expect[server_expect_count - 1], "200");
210 server_expect = realloc (server_expect, ++server_expect_count);
211 asprintf (&server_expect[server_expect_count - 1], "201");
212 QUIT = strdup("QUIT\r\n");
213 PROTOCOL = TCP_PROTOCOL;
214 use_ssl=TRUE;
215 PORT = 563;
216 }
218 #endif
219 else if (strstr (argv[0], "check_nntp")) {
220 progname = strdup ("check_nntp");
221 SERVICE = strdup ("NNTP");
222 SEND = NULL;
223 EXPECT = NULL;
224 server_expect = realloc (server_expect, sizeof (char *) * (++server_expect_count));
225 asprintf (&server_expect[server_expect_count - 1], "200");
226 server_expect = realloc (server_expect, sizeof (char *) * (++server_expect_count));
227 asprintf (&server_expect[server_expect_count - 1], "201");
228 asprintf (&QUIT, "QUIT\r\n");
229 PROTOCOL = TCP_PROTOCOL;
230 PORT = 119;
231 }
232 else {
233 progname = strdup ("check_tcp");
234 usage (_("ERROR: Generic check_tcp called with unknown service\n"));
235 }
237 server_address = strdup ("127.0.0.1");
238 server_port = PORT;
239 server_send = SEND;
240 server_quit = QUIT;
241 status = strdup ("");
243 if (process_arguments (argc, argv) == ERROR)
244 usage (_("Could not parse arguments\n"));
246 /* use default expect if none listed in process_arguments() */
247 if (EXPECT && server_expect_count == 0) {
248 server_expect = malloc (sizeof (char *) * (++server_expect_count));
249 server_expect[server_expect_count - 1] = EXPECT;
250 }
252 /* initialize alarm signal handling */
253 signal (SIGALRM, socket_timeout_alarm_handler);
255 /* set socket timeout */
256 alarm (socket_timeout);
258 /* try to connect to the host at the given port number */
259 gettimeofday (&tv, NULL);
260 #ifdef HAVE_SSL
261 if (use_ssl && check_cert == TRUE) {
262 if (connect_SSL () != OK)
263 die (STATE_CRITICAL,"TCP CRITICAL - Could not make SSL connection\n");
264 if ((server_cert = SSL_get_peer_certificate (ssl)) != NULL) {
265 result = check_certificate (&server_cert);
266 X509_free(server_cert);
267 }
268 else {
269 printf("ERROR: Cannot retrieve server certificate.\n");
270 result = STATE_CRITICAL;
271 }
272 SSL_shutdown (ssl);
273 SSL_free (ssl);
274 SSL_CTX_free (ctx);
275 close (sd);
276 return result;
277 }
278 else if (use_ssl)
279 result = connect_SSL ();
280 else
281 #endif
282 {
283 if (PROTOCOL == UDP_PROTOCOL)
284 result = my_udp_connect (server_address, server_port, &sd);
285 else
286 /* default is TCP */
287 result = my_tcp_connect (server_address, server_port, &sd);
288 }
290 if (result == STATE_CRITICAL)
291 return STATE_CRITICAL;
293 if (server_send != NULL) { /* Something to send? */
294 asprintf (&server_send, "%s\r\n", server_send);
295 #ifdef HAVE_SSL
296 if (use_ssl)
297 SSL_write(ssl, server_send, (int)strlen(server_send));
298 else
299 #endif
300 send (sd, server_send, strlen(server_send), 0);
301 }
303 if (delay > 0) {
304 tv.tv_sec += delay;
305 sleep (delay);
306 }
308 if (server_send || server_expect_count > 0) {
310 buffer = malloc (MAXBUF);
311 memset (buffer, '\0', MAXBUF);
312 /* watch for the expect string */
313 while ((i = my_recv ()) > 0) {
314 buffer[i] = '\0';
315 asprintf (&status, "%s%s", status, buffer);
316 if (buffer[i-2] == '\r' && buffer[i-1] == '\n')
317 break;
318 if (maxbytes>0 && strlen(status) >= (unsigned)maxbytes)
319 break;
320 }
322 /* return a CRITICAL status if we couldn't read any data */
323 if (strlen(status) == 0)
324 die (STATE_CRITICAL, _("No data received from host\n"));
326 strip (status);
328 if (status && verbose)
329 printf ("%s\n", status);
331 if (server_expect_count > 0) {
332 for (i = 0;; i++) {
333 if (verbose)
334 printf ("%d %d\n", i, (int)server_expect_count);
335 if (i >= (int)server_expect_count)
336 die (STATE_WARNING, _("Invalid response from host\n"));
337 if (strstr (status, server_expect[i]))
338 break;
339 }
340 }
341 }
343 if (server_quit != NULL) {
344 #ifdef HAVE_SSL
345 if (use_ssl) {
346 SSL_write (ssl, server_quit, (int)strlen(server_quit));
347 SSL_shutdown (ssl);
348 SSL_free (ssl);
349 SSL_CTX_free (ctx);
350 }
351 else {
352 #endif
353 send (sd, server_quit, strlen (server_quit), 0);
354 #ifdef HAVE_SSL
355 }
356 #endif
357 }
359 /* close the connection */
360 if (sd)
361 close (sd);
363 microsec = deltime (tv);
364 elapsed_time = (double)microsec / 1.0e6;
366 if (check_critical_time == TRUE && elapsed_time > critical_time)
367 result = STATE_CRITICAL;
368 else if (check_warning_time == TRUE && elapsed_time > warning_time)
369 result = STATE_WARNING;
371 /* reset the alarm */
372 alarm (0);
374 printf
375 (_("%s %s%s - %.3f second response time on port %d"),
376 SERVICE,
377 state_text (result),
378 (was_refused) ? " (refused)" : "",
379 elapsed_time, server_port);
381 if (hide_output == FALSE && status && strlen(status) > 0)
382 printf (" [%s]", status);
384 printf (" |%s\n", fperfdata ("time", elapsed_time, "s",
385 TRUE, warning_time,
386 TRUE, critical_time,
387 TRUE, 0,
388 TRUE, socket_timeout));
390 return result;
391 }
392 \f
396 /* process command-line arguments */
397 int
398 process_arguments (int argc, char **argv)
399 {
400 int c;
402 int option = 0;
403 static struct option longopts[] = {
404 {"hostname", required_argument, 0, 'H'},
405 {"critical-time", required_argument, 0, 'c'},
406 {"warning-time", required_argument, 0, 'w'},
407 {"critical-codes", required_argument, 0, 'C'},
408 {"warning-codes", required_argument, 0, 'W'},
409 {"timeout", required_argument, 0, 't'},
410 {"protocol", required_argument, 0, 'P'},
411 {"port", required_argument, 0, 'p'},
412 {"send", required_argument, 0, 's'},
413 {"expect", required_argument, 0, 'e'},
414 {"maxbytes", required_argument, 0, 'm'},
415 {"quit", required_argument, 0, 'q'},
416 {"jail", required_argument, 0, 'j'},
417 {"delay", required_argument, 0, 'd'},
418 {"refuse", required_argument, 0, 'r'},
419 {"use-ipv4", no_argument, 0, '4'},
420 {"use-ipv6", no_argument, 0, '6'},
421 {"verbose", no_argument, 0, 'v'},
422 {"version", no_argument, 0, 'V'},
423 {"help", no_argument, 0, 'h'},
424 #ifdef HAVE_SSL
425 {"ssl", no_argument, 0, 'S'},
426 {"certificate", required_argument, 0, 'D'},
427 #endif
428 {0, 0, 0, 0}
429 };
431 if (argc < 2)
432 usage ("No arguments found\n");
434 /* backwards compatibility */
435 for (c = 1; c < argc; c++) {
436 if (strcmp ("-to", argv[c]) == 0)
437 strcpy (argv[c], "-t");
438 else if (strcmp ("-wt", argv[c]) == 0)
439 strcpy (argv[c], "-w");
440 else if (strcmp ("-ct", argv[c]) == 0)
441 strcpy (argv[c], "-c");
442 }
444 if (!is_option (argv[1])) {
445 server_address = argv[1];
446 argv[1] = argv[0];
447 argv = &argv[1];
448 argc--;
449 }
451 while (1) {
452 c = getopt_long (argc, argv, "+hVv46H:s:e:q:m:c:w:t:p:C:W:d:Sr:j",
453 longopts, &option);
455 if (c == -1 || c == EOF || c == 1)
456 break;
458 switch (c) {
459 case '?': /* print short usage statement if args not parsable */
460 printf (_("%s: Unknown argument: %s\n\n"), progname, optarg);
461 print_usage ();
462 exit (STATE_UNKNOWN);
463 case 'h': /* help */
464 print_help ();
465 exit (STATE_OK);
466 case 'V': /* version */
467 print_revision (progname, "$Revision$");
468 exit (STATE_OK);
469 case 'v': /* verbose mode */
470 verbose = TRUE;
471 break;
472 case '4':
473 address_family = AF_INET;
474 break;
475 case '6':
476 #ifdef USE_IPV6
477 address_family = AF_INET6;
478 #else
479 usage (_("IPv6 support not available\n"));
480 #endif
481 break;
482 case 'H': /* hostname */
483 if (is_host (optarg) == FALSE)
484 usage2 (_("invalid host name or address"), optarg);
485 server_address = optarg;
486 break;
487 case 'c': /* critical */
488 if (!is_intnonneg (optarg))
489 usage (_("Critical threshold must be a nonnegative integer\n"));
490 else
491 critical_time = strtod (optarg, NULL);
492 check_critical_time = TRUE;
493 break;
494 case 'j': /* hide output */
495 hide_output = TRUE;
496 break;
497 case 'w': /* warning */
498 if (!is_intnonneg (optarg))
499 usage (_("Warning threshold must be a nonnegative integer\n"));
500 else
501 warning_time = strtod (optarg, NULL);
502 check_warning_time = TRUE;
503 break;
504 case 'C':
505 crit_codes = realloc (crit_codes, ++crit_codes_count);
506 crit_codes[crit_codes_count - 1] = optarg;
507 break;
508 case 'W':
509 warn_codes = realloc (warn_codes, ++warn_codes_count);
510 warn_codes[warn_codes_count - 1] = optarg;
511 break;
512 case 't': /* timeout */
513 if (!is_intpos (optarg))
514 usage (_("Timeout interval must be a positive integer\n"));
515 else
516 socket_timeout = atoi (optarg);
517 break;
518 case 'p': /* port */
519 if (!is_intpos (optarg))
520 usage (_("Server port must be a positive integer\n"));
521 else
522 server_port = atoi (optarg);
523 break;
524 case 's':
525 server_send = optarg;
526 break;
527 case 'e': /* expect string (may be repeated) */
528 EXPECT = NULL;
529 if (server_expect_count == 0)
530 server_expect = malloc (sizeof (char *) * (++server_expect_count));
531 else
532 server_expect = realloc (server_expect, sizeof (char *) * (++server_expect_count));
533 server_expect[server_expect_count - 1] = optarg;
534 break;
535 case 'm':
536 if (!is_intpos (optarg))
537 usage (_("Maxbytes must be a positive integer\n"));
538 else
539 maxbytes = atoi (optarg);
540 case 'q':
541 asprintf(&server_quit, "%s\r\n", optarg);
542 break;
543 case 'r':
544 if (!strncmp(optarg,"ok",2))
545 econn_refuse_state = STATE_OK;
546 else if (!strncmp(optarg,"warn",4))
547 econn_refuse_state = STATE_WARNING;
548 else if (!strncmp(optarg,"crit",4))
549 econn_refuse_state = STATE_CRITICAL;
550 else
551 usage (_("Refuse mut be one of ok, warn, crit\n"));
552 break;
553 case 'd':
554 if (is_intpos (optarg))
555 delay = atoi (optarg);
556 else
557 usage (_("Delay must be a positive integer\n"));
558 break;
559 case 'D': /* Check SSL cert validity - days 'til certificate expiration */
560 #ifdef HAVE_SSL
561 if (!is_intnonneg (optarg))
562 usage2 ("invalid certificate expiration period", optarg);
563 days_till_exp = atoi (optarg);
564 check_cert = TRUE;
565 use_ssl = TRUE;
566 break;
567 case 'S':
568 use_ssl = TRUE;
569 #else
570 die (STATE_UNKNOWN, "SSL support not available. Install OpenSSL and recompile.");
571 #endif
572 break;
573 }
574 }
576 if (server_address == NULL)
577 usage (_("You must provide a server address\n"));
579 return OK;
580 }
581 \f
583 #ifdef HAVE_SSL
584 int
585 connect_SSL (void)
586 {
587 SSL_METHOD *meth;
589 /* Initialize SSL context */
590 SSLeay_add_ssl_algorithms ();
591 meth = SSLv23_client_method ();
592 SSL_load_error_strings ();
593 OpenSSL_add_all_algorithms();
594 if ((ctx = SSL_CTX_new (meth)) == NULL)
595 {
596 printf (_("ERROR: Cannot create SSL context.\n"));
597 return STATE_CRITICAL;
598 }
600 /* Initialize alarm signal handling */
601 signal (SIGALRM, socket_timeout_alarm_handler);
603 /* Set socket timeout */
604 alarm (socket_timeout);
606 /* Save start time */
607 time (&start_time);
609 /* Make TCP connection */
610 if (my_tcp_connect (server_address, server_port, &sd) == STATE_OK && was_refused == FALSE)
611 {
612 /* Do the SSL handshake */
613 if ((ssl = SSL_new (ctx)) != NULL)
614 {
615 SSL_set_fd (ssl, sd);
616 if (SSL_connect(ssl) == 1)
617 return OK;
618 /* ERR_print_errors_fp (stderr); */
619 printf (_("ERROR: Cannot make SSL connection "));
620 ERR_print_errors_fp (stdout);
621 /* printf("\n"); */
622 }
623 else
624 {
625 printf (_("ERROR: Cannot initiate SSL handshake.\n"));
626 }
627 SSL_free (ssl);
628 }
630 SSL_CTX_free (ctx);
631 close (sd);
633 return STATE_CRITICAL;
634 }
635 #endif
637 #ifdef HAVE_SSL
638 int
639 check_certificate (X509 ** certificate)
640 {
641 ASN1_STRING *tm;
642 int offset;
643 struct tm stamp;
644 int days_left;
647 /* Retrieve timestamp of certificate */
648 tm = X509_get_notAfter (*certificate);
650 /* Generate tm structure to process timestamp */
651 if (tm->type == V_ASN1_UTCTIME) {
652 if (tm->length < 10) {
653 printf ("ERROR: Wrong time format in certificate.\n");
654 return STATE_CRITICAL;
655 }
656 else {
657 stamp.tm_year = (tm->data[0] - '0') * 10 + (tm->data[1] - '0');
658 if (stamp.tm_year < 50)
659 stamp.tm_year += 100;
660 offset = 0;
661 }
662 }
663 else {
664 if (tm->length < 12) {
665 printf ("ERROR: Wrong time format in certificate.\n");
666 return STATE_CRITICAL;
667 }
668 else {
669 stamp.tm_year =
670 (tm->data[0] - '0') * 1000 + (tm->data[1] - '0') * 100 +
671 (tm->data[2] - '0') * 10 + (tm->data[3] - '0');
672 stamp.tm_year -= 1900;
673 offset = 2;
674 }
675 }
676 stamp.tm_mon =
677 (tm->data[2 + offset] - '0') * 10 + (tm->data[3 + offset] - '0') - 1;
678 stamp.tm_mday =
679 (tm->data[4 + offset] - '0') * 10 + (tm->data[5 + offset] - '0');
680 stamp.tm_hour =
681 (tm->data[6 + offset] - '0') * 10 + (tm->data[7 + offset] - '0');
682 stamp.tm_min =
683 (tm->data[8 + offset] - '0') * 10 + (tm->data[9 + offset] - '0');
684 stamp.tm_sec = 0;
685 stamp.tm_isdst = -1;
687 days_left = (mktime (&stamp) - time (NULL)) / 86400;
688 snprintf
689 (timestamp, 16, "%02d/%02d/%04d %02d:%02d",
690 stamp.tm_mon + 1,
691 stamp.tm_mday, stamp.tm_year + 1900, stamp.tm_hour, stamp.tm_min);
693 if (days_left > 0 && days_left <= days_till_exp) {
694 printf ("Certificate expires in %d day(s) (%s).\n", days_left, timestamp);
695 return STATE_WARNING;
696 }
697 if (days_left < 0) {
698 printf ("Certificate expired on %s.\n", timestamp);
699 return STATE_CRITICAL;
700 }
702 if (days_left == 0) {
703 printf ("Certificate expires today (%s).\n", timestamp);
704 return STATE_WARNING;
705 }
707 printf ("Certificate will expire on %s.\n", timestamp);
709 return STATE_OK;
710 }
711 #endif
713 int
714 my_recv (void)
715 {
716 int i;
718 #ifdef HAVE_SSL
719 if (use_ssl) {
720 i = SSL_read (ssl, buffer, MAXBUF - 1);
721 }
722 else {
723 #endif
724 i = read (sd, buffer, MAXBUF - 1);
725 #ifdef HAVE_SSL
726 }
727 #endif
729 return i;
730 }
736 \f
737 void
738 print_help (void)
739 {
740 print_revision (progname, revision);
742 printf (_("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n"));
743 printf (_(COPYRIGHT), copyright, email);
745 printf (_("This plugin tests %s connections with the specified host.\n\n"),
746 SERVICE);
748 print_usage ();
750 printf (_(UT_HELP_VRSN));
752 printf (_(UT_HOST_PORT), 'p', "none");
754 printf (_(UT_IPv46));
756 printf (_("\
757 -s, --send=STRING\n\
758 String to send to the server\n\
759 -e, --expect=STRING\n\
760 String to expect in server response\n\
761 -q, --quit=STRING\n\
762 String to send server to initiate a clean close of the connection\n"));
764 printf (_("\
765 -r, --refuse=ok|warn|crit\n\
766 Accept tcp refusals with states ok, warn, crit (default: crit)\n\
767 -j, --jail\n\
768 Hide output from TCP socket\n\
769 -m, --maxbytes=INTEGER\n\
770 Close connection once more than this number of bytes are received\n\
771 -d, --delay=INTEGER\n\
772 Seconds to wait between sending string and polling for response\n"));
774 #ifdef HAVE_SSL
775 printf (_("\
776 -D, --certificate=INTEGER\n\
777 Minimum number of days a certificate has to be valid.\n\
778 -S, --ssl\n\
779 Use SSL for the connection.\n"));
780 #endif
782 printf (_(UT_WARN_CRIT));
784 printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
786 printf (_(UT_VERBOSE));
788 printf (_(UT_SUPPORT));
789 }
794 void
795 print_usage (void)
796 {
797 printf (_("\
798 Usage: %s -H host -p port [-w <warning time>] [-c <critical time>]\n\
799 [-s <send string>] [-e <expect string>] [-q <quit string>]\n\
800 [-m <maximum bytes>] [-d <delay>] [-t <timeout seconds>]\n\
801 [-r <refuse state>] [-v] [-4|-6] [-j] [-D <days to cert expiry>]\n\
802 [-S <use SSL>]\n"), progname);
803 printf (" %s (-h|--help)\n", progname);
804 printf (" %s (-V|--version)\n", progname);
805 }