summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_tcp.c193
1 files changed, 98 insertions, 95 deletions
diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c
index afb1a68..872a3cc 100644
--- a/plugins/check_tcp.c
+++ b/plugins/check_tcp.c
@@ -88,8 +88,86 @@ char *buffer = "";
88char *progname = "check_tcp"; 88char *progname = "check_tcp";
89const char *revision = "$Revision$"; 89const char *revision = "$Revision$";
90const char *copyright = "2002-2003"; 90const char *copyright = "2002-2003";
91const char *authors = "Nagios Plugin Development Team";
92const char *email = "nagiosplug-devel@lists.sourceforge.net"; 91const char *email = "nagiosplug-devel@lists.sourceforge.net";
92
93
94
95
96void
97print_usage (void)
98{
99 printf (_("\
100Usage: %s -H host -p port [-w <warning time>] [-c <critical time>]\n\
101 [-s <send string>] [-e <expect string>] [-q <quit string>]\n\
102 [-m <maximum bytes>] [-d <delay>] [-t <timeout seconds>]\n\
103 [-r <refuse state>] [-v] [-4|-6]\n"), progname);
104 printf (" %s (-h|--help)\n", progname);
105 printf (" %s (-V|--version)\n", progname);
106}
107
108void
109print_help (void)
110{
111 print_revision (progname, revision);
112
113 printf (_("\
114Copyright (c) %s Nagios Plugin Development Team\n\
115\t<%s>\n\n"),
116 copyright, email);
117
118 printf (_("\
119This plugin tests %s connections with the specified host.\n\n"),
120 SERVICE);
121
122 print_usage ();
123
124 printf (_("\
125\nOptions:\n\
126 -H, --hostname=ADDRESS\n\
127 Host name argument for servers using host headers (use numeric\n\
128 address if possible to bypass DNS lookup).\n\
129 -p, --port=INTEGER\n\
130 Port number\n\
131 -4, --use-ipv4\n\
132 Use IPv4 connection\n\
133 -6, --use-ipv6\n\
134 Use IPv6 connection\n"));
135
136 printf (_("\
137 -s, --send=STRING\n\
138 String to send to the server\n\
139 -e, --expect=STRING\n\
140 String to expect in server response\n\
141 -q, --quit=STRING\n\
142 String to send server to initiate a clean close of the connection\n"));
143
144 printf (_("\
145 -r, --refuse=ok|warn|crit\n\
146 Accept tcp refusals with states ok, warn, crit (default: crit)\n\
147 -m, --maxbytes=INTEGER\n\
148 Close connection once more than this number of bytes are received\n\
149 -d, --delay=INTEGER\n\
150 Seconds to wait between sending string and polling for response\n\
151 -w, --warning=DOUBLE\n\
152 Response time to result in warning status (seconds)\n\
153 -c, --critical=DOUBLE\n\
154 Response time to result in critical status (seconds)\n"));
155
156 printf (_("\
157 -t, --timeout=INTEGER\n\
158 Seconds before connection times out (default: %d)\n\
159 -v, --verbose\n\
160 Show details for command-line debugging (Nagios may truncate output)\n\
161 -h, --help\n\
162 Print detailed help screen\n\
163 -V, --version\n\
164 Print version information\n\n"),
165 DEFAULT_SOCKET_TIMEOUT);
166
167 support ();
168}
169
170
93 171
94int 172int
95main (int argc, char **argv) 173main (int argc, char **argv)
@@ -193,7 +271,7 @@ main (int argc, char **argv)
193 PORT = 119; 271 PORT = 119;
194 } 272 }
195 else { 273 else {
196 usage ("ERROR: Generic check_tcp called with unknown service\n"); 274 usage (_("ERROR: Generic check_tcp called with unknown service\n"));
197 } 275 }
198 276
199 server_address = strdup ("127.0.0.1"); 277 server_address = strdup ("127.0.0.1");
@@ -202,7 +280,7 @@ main (int argc, char **argv)
202 server_quit = QUIT; 280 server_quit = QUIT;
203 281
204 if (process_arguments (argc, argv) == ERROR) 282 if (process_arguments (argc, argv) == ERROR)
205 usage ("Could not parse arguments\n"); 283 usage (_("Could not parse arguments\n"));
206 284
207 /* use default expect if none listed in process_arguments() */ 285 /* use default expect if none listed in process_arguments() */
208 if (EXPECT && server_expect_count == 0) { 286 if (EXPECT && server_expect_count == 0) {
@@ -265,7 +343,7 @@ main (int argc, char **argv)
265 343
266 /* return a CRITICAL status if we couldn't read any data */ 344 /* return a CRITICAL status if we couldn't read any data */
267 if (status == NULL) 345 if (status == NULL)
268 terminate (STATE_CRITICAL, "No data received from host\n"); 346 terminate (STATE_CRITICAL, _("No data received from host\n"));
269 347
270 strip (status); 348 strip (status);
271 349
@@ -277,7 +355,7 @@ main (int argc, char **argv)
277 if (verbose) 355 if (verbose)
278 printf ("%d %d\n", i, server_expect_count); 356 printf ("%d %d\n", i, server_expect_count);
279 if (i >= server_expect_count) 357 if (i >= server_expect_count)
280 terminate (STATE_WARNING, "Invalid response from host\n"); 358 terminate (STATE_WARNING, _("Invalid response from host\n"));
281 if (strstr (status, server_expect[i])) 359 if (strstr (status, server_expect[i]))
282 break; 360 break;
283 } 361 }
@@ -315,7 +393,7 @@ main (int argc, char **argv)
315 alarm (0); 393 alarm (0);
316 394
317 printf 395 printf
318 ("%s %s%s - %.3f second response time on port %d", 396 (_("%s %s%s - %.3f second response time on port %d"),
319 SERVICE, 397 SERVICE,
320 state_text (result), 398 state_text (result),
321 (was_refused) ? " (refused)" : "", 399 (was_refused) ? " (refused)" : "",
@@ -391,7 +469,7 @@ process_arguments (int argc, char **argv)
391 469
392 switch (c) { 470 switch (c) {
393 case '?': /* print short usage statement if args not parsable */ 471 case '?': /* print short usage statement if args not parsable */
394 printf ("%s: Unknown argument: %s\n\n", progname, optarg); 472 printf (_("%s: Unknown argument: %s\n\n"), progname, optarg);
395 print_usage (); 473 print_usage ();
396 exit (STATE_UNKNOWN); 474 exit (STATE_UNKNOWN);
397 case 'h': /* help */ 475 case 'h': /* help */
@@ -410,23 +488,23 @@ process_arguments (int argc, char **argv)
410#ifdef USE_IPV6 488#ifdef USE_IPV6
411 address_family = AF_INET6; 489 address_family = AF_INET6;
412#else 490#else
413 usage ("IPv6 support not available\n"); 491 usage (_("IPv6 support not available\n"));
414#endif 492#endif
415 break; 493 break;
416 case 'H': /* hostname */ 494 case 'H': /* hostname */
417 if (is_host (optarg) == FALSE) 495 if (is_host (optarg) == FALSE)
418 usage2 ("invalid host name or address", optarg); 496 usage2 (_("invalid host name or address"), optarg);
419 server_address = optarg; 497 server_address = optarg;
420 break; 498 break;
421 case 'c': /* critical */ 499 case 'c': /* critical */
422 if (!is_intnonneg (optarg)) 500 if (!is_intnonneg (optarg))
423 usage ("Critical threshold must be a nonnegative integer\n"); 501 usage (_("Critical threshold must be a nonnegative integer\n"));
424 critical_time = strtod (optarg, NULL); 502 critical_time = strtod (optarg, NULL);
425 check_critical_time = TRUE; 503 check_critical_time = TRUE;
426 break; 504 break;
427 case 'w': /* warning */ 505 case 'w': /* warning */
428 if (!is_intnonneg (optarg)) 506 if (!is_intnonneg (optarg))
429 usage ("Warning threshold must be a nonnegative integer\n"); 507 usage (_("Warning threshold must be a nonnegative integer\n"));
430 warning_time = strtod (optarg, NULL); 508 warning_time = strtod (optarg, NULL);
431 check_warning_time = TRUE; 509 check_warning_time = TRUE;
432 break; 510 break;
@@ -440,12 +518,12 @@ process_arguments (int argc, char **argv)
440 break; 518 break;
441 case 't': /* timeout */ 519 case 't': /* timeout */
442 if (!is_intpos (optarg)) 520 if (!is_intpos (optarg))
443 usage ("Timeout interval must be a positive integer\n"); 521 usage (_("Timeout interval must be a positive integer\n"));
444 socket_timeout = atoi (optarg); 522 socket_timeout = atoi (optarg);
445 break; 523 break;
446 case 'p': /* port */ 524 case 'p': /* port */
447 if (!is_intpos (optarg)) 525 if (!is_intpos (optarg))
448 usage ("Server port must be a positive integer\n"); 526 usage (_("Server port must be a positive integer\n"));
449 server_port = atoi (optarg); 527 server_port = atoi (optarg);
450 break; 528 break;
451 case 's': 529 case 's':
@@ -461,7 +539,7 @@ process_arguments (int argc, char **argv)
461 break; 539 break;
462 case 'm': 540 case 'm':
463 if (!is_intpos (optarg)) 541 if (!is_intpos (optarg))
464 usage ("Maxbytes must be a positive integer\n"); 542 usage (_("Maxbytes must be a positive integer\n"));
465 maxbytes = atoi (optarg); 543 maxbytes = atoi (optarg);
466 case 'q': 544 case 'q':
467 server_quit = optarg; 545 server_quit = optarg;
@@ -474,18 +552,18 @@ process_arguments (int argc, char **argv)
474 else if (!strncmp(optarg,"crit",4)) 552 else if (!strncmp(optarg,"crit",4))
475 econn_refuse_state = STATE_CRITICAL; 553 econn_refuse_state = STATE_CRITICAL;
476 else 554 else
477 usage ("Refuse mut be one of ok, warn, crit\n"); 555 usage (_("Refuse mut be one of ok, warn, crit\n"));
478 break; 556 break;
479 case 'd': 557 case 'd':
480 if (is_intpos (optarg)) 558 if (is_intpos (optarg))
481 delay = atoi (optarg); 559 delay = atoi (optarg);
482 else 560 else
483 usage ("Delay must be a positive integer\n"); 561 usage (_("Delay must be a positive integer\n"));
484 break; 562 break;
485 case 'S': 563 case 'S':
486#ifndef HAVE_SSL 564#ifndef HAVE_SSL
487 terminate (STATE_UNKNOWN, 565 terminate (STATE_UNKNOWN,
488 "SSL support not available. Install OpenSSL and recompile."); 566 _("SSL support not available. Install OpenSSL and recompile."));
489#endif 567#endif
490 use_ssl = TRUE; 568 use_ssl = TRUE;
491 break; 569 break;
@@ -493,87 +571,12 @@ process_arguments (int argc, char **argv)
493 } 571 }
494 572
495 if (server_address == NULL) 573 if (server_address == NULL)
496 usage ("You must provide a server address\n"); 574 usage (_("You must provide a server address\n"));
497 575
498 return OK; 576 return OK;
499} 577}
500 578
501 579
502
503
504void
505print_help (void)
506{
507 print_revision (progname, revision);
508
509 printf ("Copyright (c) %s %s\n\t<%s>\n\n", copyright, authors, email);
510
511 printf (_("\
512This plugin tests %s connections with the specified host.\n"), SERVICE);
513
514 print_usage ();
515
516 printf ("\nOptions:\n");
517
518 printf (_("\
519 -H, --hostname=ADDRESS\n\
520 Host name argument for servers using host headers (use numeric\n\
521 address if possible to bypass DNS lookup).\n\
522 -p, --port=INTEGER\n\
523 Port number\n\
524 -4, --use-ipv4\n\
525 Use IPv4 connection\n\
526 -6, --use-ipv6\n\
527 Use IPv6 connection\n"));
528
529 printf (_("\
530 -s, --send=STRING\n\
531 String to send to the server\n\
532 -e, --expect=STRING\n\
533 String to expect in server response\n\
534 -q, --quit=STRING\n\
535 String to send server to initiate a clean close of the connection\n"));
536
537 printf (_("\
538 -r, --refuse=ok|warn|crit\n\
539 Accept tcp refusals with states ok, warn, crit (default: crit)\n\
540 -m, --maxbytes=INTEGER\n\
541 Close connection once more than this number of bytes are received\n\
542 -d, --delay=INTEGER\n\
543 Seconds to wait between sending string and polling for response\n\
544 -w, --warning=DOUBLE\n\
545 Response time to result in warning status (seconds)\n\
546 -c, --critical=DOUBLE\n\
547 Response time to result in critical status (seconds)\n"));
548
549 printf (_("\
550 -t, --timeout=INTEGER\n\
551 Seconds before connection times out (default: %d)\n\
552 -v, --verbose\n\
553 Show details for command-line debugging (Nagios may truncate output)\n\
554 -h, --help\n\
555 Print detailed help screen\n\
556 -V, --version\n\
557 Print version information\n\n"),
558 DEFAULT_SOCKET_TIMEOUT);
559
560 support ();
561}
562
563void
564print_usage (void)
565{
566 printf ("Usage: %s %s\n", progname, _("\
567-H host -p port [-w warn_time] [-c crit_time] [-s send_string]\n\
568 [-e expect_string] [-q quit_string] [-m maxbytes] [-d delay]\n\
569 [-t to_sec] [-r refuse_state] [-v] [-4|-6]\n"));
570 printf (" %s (-h|--help)\n", progname);
571 printf (" %s (-V|--version)\n", progname);
572}
573
574
575
576
577#ifdef HAVE_SSL 580#ifdef HAVE_SSL
578int 581int
579connect_SSL (void) 582connect_SSL (void)
@@ -586,7 +589,7 @@ connect_SSL (void)
586 SSL_load_error_strings (); 589 SSL_load_error_strings ();
587 if ((ctx = SSL_CTX_new (meth)) == NULL) 590 if ((ctx = SSL_CTX_new (meth)) == NULL)
588 { 591 {
589 printf ("ERROR: Cannot create SSL context.\n"); 592 printf (_("ERROR: Cannot create SSL context.\n"));
590 return STATE_CRITICAL; 593 return STATE_CRITICAL;
591 } 594 }
592 595
@@ -612,7 +615,7 @@ connect_SSL (void)
612 } 615 }
613 else 616 else
614 { 617 {
615 printf ("ERROR: Cannot initiate SSL handshake.\n"); 618 printf (_("ERROR: Cannot initiate SSL handshake.\n"));
616 } 619 }
617 SSL_free (ssl); 620 SSL_free (ssl);
618 } 621 }