summaryrefslogtreecommitdiffstats
path: root/plugins/t
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/t')
0 files changed, 0 insertions, 0 deletions
diff --git a/plugins/check_http.c b/plugins/check_http.c
index 2f69332..c1016bb 100644
--- a/plugins/check_http.c
+++ b/plugins/check_http.c
@@ -24,115 +24,139 @@
24 *****************************************************************************/ 24 *****************************************************************************/
25 25
26const char *progname = "check_http"; 26const char *progname = "check_http";
27#define REVISION "$Revision$" 27const char *revision = "$Revision$";
28#define COPYRIGHT "1999-2001" 28const char *copyright = "1999-2001";
29#define AUTHORS "Ethan Galstad/Karl DeBisschop" 29const char *email = "nagiosplug-devel@lists.sourceforge.net";
30#define EMAIL "kdebisschop@users.sourceforge.net"
31 30
32#include "config.h"
33#include "common.h" 31#include "common.h"
34#include "netutils.h" 32#include "netutils.h"
35#include "utils.h" 33#include "utils.h"
36 34
37#define SUMMARY "\ 35#define HTTP_EXPECT "HTTP/1."
36enum {
37 MAX_IPV4_HOSTLENGTH = 255,
38 HTTP_PORT = 80,
39 HTTPS_PORT = 443
40};
41
42void
43print_usage (void)
44{
45 printf (_("\
46Usage: %s (-H <vhost> | -I <IP-address>) [-u <uri>] [-p <port>]\n\
47 [-w <warn time>] [-c <critical time>] [-t <timeout>] [-L]\n\
48 [-a auth] [-f <ok | warn | critcal | follow>] [-e <expect>]\n\
49 [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]\n\
50 [-P string] [-m min_pg_size] [-4|-6]\n"), progname);
51 printf (_(UT_HLP_VRS), progname, progname);
52}
53
54void
55print_help (void)
56{
57 print_revision (progname, revision);
58
59 printf (_(COPYRIGHT), copyright, email);
60
61 printf (_("\
38This plugin tests the HTTP service on the specified host. It can test\n\ 62This plugin tests the HTTP service on the specified host. It can test\n\
39normal (http) and secure (https) servers, follow redirects, search for\n\ 63normal (http) and secure (https) servers, follow redirects, search for\n\
40strings and regular expressions, check connection times, and report on\n\ 64strings and regular expressions, check connection times, and report on\n\
41certificate expiration times.\n" 65certificate expiration times.\n"));
66
67 print_usage ();
42 68
43#define OPTIONS "\ 69 printf (_("NOTE: One or both of -H and -I must be specified\n"));
44(-H <vhost> | -I <IP-address>) [-u <uri>] [-p <port>]\n\
45 [-w <warn time>] [-c <critical time>] [-t <timeout>] [-L]\n\
46 [-a auth] [-f <ok | warn | critcal | follow>] [-e <expect>]\n\
47 [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]\n\
48 [-P string] [-m min_pg_size] [-4|-6]"
49 70
50#define LONGOPTIONS "\ 71 printf (_(UT_HELP_VRSN));
72
73 printf (_("\
51 -H, --hostname=ADDRESS\n\ 74 -H, --hostname=ADDRESS\n\
52 Host name argument for servers using host headers (virtual host)\n\ 75 Host name argument for servers using host headers (virtual host)\n\
53 -I, --IP-address=ADDRESS\n\ 76 -I, --IP-address=ADDRESS\n\
54 IP address or name (use numeric address if possible to bypass DNS lookup).\n\ 77 IP address or name (use numeric address if possible to bypass DNS lookup).\n\
55 -4, --use-ipv4\n\
56 Use IPv4 protocol\n\
57 -6, --use-ipv6\n\
58 Use IPv6 protocol\n\
59 -e, --expect=STRING\n\
60 String to expect in first (status) line of server response (default: %s)\n\
61 If specified skips all other status line logic (ex: 3xx, 4xx, 5xx processing)\n\
62 -s, --string=STRING\n\
63 String to expect in the content\n\
64 -u, --url=PATH\n\
65 URL to GET or POST (default: /)\n\
66 -p, --port=INTEGER\n\ 78 -p, --port=INTEGER\n\
67 Port number (default: %d)\n\ 79 Port number (default: %d)\n"), HTTP_PORT);
68 -P, --post=STRING\n\ 80
69 URL encoded http POST data\n\ 81 printf (_(UT_IPv46));
70 -w, --warning=INTEGER\n\
71 Response time to result in warning status (seconds)\n\
72 -c, --critical=INTEGER\n\
73 Response time to result in critical status (seconds)\n\
74 -t, --timeout=INTEGER\n\
75 Seconds before connection times out (default: %d)\n\
76 -a, --authorization=AUTH_PAIR\n\
77 Username:password on sites with basic authentication\n\
78 -L, --link=URL\n\
79 Wrap output in HTML link (obsoleted by urlize)\n\
80 -f, --onredirect=<ok|warning|critical|follow>\n\
81 How to handle redirected pages\n%s%s\
82-m, --min=INTEGER\n\
83 Minimum page size required (bytes)\n\
84 -v, --verbose\n\
85 Show details for command-line debugging (do not use with nagios server)\n\
86 -h, --help\n\
87 Print detailed help screen\n\
88 -V, --version\n\
89 Print version information\n"
90 82
91#ifdef HAVE_SSL 83#ifdef HAVE_SSL
92#define SSLOPTIONS "\ 84 printf (_("\
93 -S, --ssl\n\ 85 -S, --ssl\n\
94 Connect via SSL\n\ 86 Connect via SSL\n\
95 -C, --certificate=INTEGER\n\ 87 -C, --certificate=INTEGER\n\
96 Minimum number of days a certificate has to be valid.\n\ 88 Minimum number of days a certificate has to be valid.\n\
97 (when this option is used the url is not checked.)\n" 89 (when this option is used the url is not checked.)\n"));
98#else
99#define SSLOPTIONS ""
100#endif 90#endif
101 91
92 printf (_("\
93 -e, --expect=STRING\n\
94 String to expect in first (status) line of server response (default: %s)\n\
95 If specified skips all other status line logic (ex: 3xx, 4xx, 5xx processing)\n\
96 -s, --string=STRING\n\
97 String to expect in the content\n\
98 -u, --url=PATH\n\
99 URL to GET or POST (default: /)\n\
100 -P, --post=STRING\n\
101 URL encoded http POST data\n"), HTTP_EXPECT);
102
102#ifdef HAVE_REGEX_H 103#ifdef HAVE_REGEX_H
103#define REGOPTIONS "\ 104 printf (_("\
104 -l, --linespan\n\ 105 -l, --linespan\n\
105 Allow regex to span newlines (must precede -r or -R)\n\ 106 Allow regex to span newlines (must precede -r or -R)\n\
106 -r, --regex, --ereg=STRING\n\ 107 -r, --regex, --ereg=STRING\n\
107 Search page for regex STRING\n\ 108 Search page for regex STRING\n\
108 -R, --eregi=STRING\n\ 109 -R, --eregi=STRING\n\
109 Search page for case-insensitive regex STRING\n" 110 Search page for case-insensitive regex STRING\n"));
110#else
111#define REGOPTIONS ""
112#endif 111#endif
113 112
114#define DESCRIPTION "\ 113 printf (_("\
115This plugin will attempt to open an HTTP connection with the host. Successul\n\ 114 -a, --authorization=AUTH_PAIR\n\
115 Username:password on sites with basic authentication\n\
116 -L, --link=URL\n\
117 Wrap output in HTML link (obsoleted by urlize)\n\
118 -f, --onredirect=<ok|warning|critical|follow>\n\
119 How to handle redirected pages\n\
120 -m, --min=INTEGER\n\
121 Minimum page size required (bytes)\n"));
122
123 printf (_(UT_WARN_CRIT));
124
125 printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
126
127 printf (_(UT_VERBOSE));
128
129 printf (_("\
130This plugin will attempt to open an HTTP connection with the host. Successful\n\
116connects return STATE_OK, refusals and timeouts return STATE_CRITICAL, other\n\ 131connects return STATE_OK, refusals and timeouts return STATE_CRITICAL, other\n\
117errors return STATE_UNKNOWN. Successful connects, but incorrect reponse\n\ 132errors return STATE_UNKNOWN. Successful connects, but incorrect reponse\n\
118messages from the host result in STATE_WARNING return values. If you are\n\ 133messages from the host result in STATE_WARNING return values. If you are\n\
119checking a virtual server that uses \"host headers\" you must supply the FQDN\n\ 134checking a virtual server that uses 'host headers' you must supply the FQDN\n\
120\(fully qualified domain name) as the [host_name] argument.\n" 135(fully qualified domain name) as the [host_name] argument.\n"));
121 136
122#define SSLDESCRIPTION "\ 137#ifdef HAVE_SSL
138 printf (_("\n\
123This plugin can also check whether an SSL enabled web server is able to\n\ 139This plugin can also check whether an SSL enabled web server is able to\n\
124serve content (optionally within a specified time) or whether the X509 \n\ 140serve content (optionally within a specified time) or whether the X509 \n\
125certificate is still valid for the specified number of days.\n\n\ 141certificate is still valid for the specified number of days.\n"));
142 printf (_("\n\
126CHECK CONTENT: check_http -w 5 -c 10 --ssl www.verisign.com\n\n\ 143CHECK CONTENT: check_http -w 5 -c 10 --ssl www.verisign.com\n\n\
127When the 'www.verisign.com' server returns its content within 5 seconds, a\n\ 144When the 'www.verisign.com' server returns its content within 5 seconds, a\n\
128STATE_OK will be returned. When the server returns its content but exceeds\n\ 145STATE_OK will be returned. When the server returns its content but exceeds\n\
129the 5-second threshold, a STATE_WARNING will be returned. When an error occurs,\n\ 146the 5-second threshold, a STATE_WARNING will be returned. When an error occurs,\n\
130a STATE_CRITICAL will be returned.\n\n\ 147a STATE_CRITICAL will be returned.\n\n"));
148
149 printf (_("\
131CHECK CERTIFICATE: check_http www.verisign.com -C 14\n\n\ 150CHECK CERTIFICATE: check_http www.verisign.com -C 14\n\n\
132When the certificate of 'www.verisign.com' is valid for more than 14 days, a\n\ 151When the certificate of 'www.verisign.com' is valid for more than 14 days, a\n\
133STATE_OK is returned. When the certificate is still valid, but for less than\n\ 152STATE_OK is returned. When the certificate is still valid, but for less than\n\
13414 days, a STATE_WARNING is returned. A STATE_CRITICAL will be returned when\n\ 15314 days, a STATE_WARNING is returned. A STATE_CRITICAL will be returned when\n\
135the certificate is expired.\n" 154the certificate is expired.\n"));
155#endif
156
157 printf (_(UT_SUPPORT));
158
159}
136 160
137#ifdef HAVE_SSL_H 161#ifdef HAVE_SSL_H
138#include <rsa.h> 162#include <rsa.h>
@@ -194,13 +218,6 @@ struct timeval tv;
194#define URI_PORT ":%[0123456789]" 218#define URI_PORT ":%[0123456789]"
195#define URI_PATH "%[-_.!~*'();/?:@&=+$,%#abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]" 219#define URI_PATH "%[-_.!~*'();/?:@&=+$,%#abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]"
196 220
197enum {
198 MAX_IPV4_HOSTLENGTH = 255,
199 HTTP_PORT = 80,
200 HTTPS_PORT = 443
201};
202
203#define HTTP_EXPECT "HTTP/1."
204#define HTTP_URL "/" 221#define HTTP_URL "/"
205#define CRLF "\r\n" 222#define CRLF "\r\n"
206 223
@@ -231,8 +248,6 @@ char *http_method = "GET";
231char *http_post_data = ""; 248char *http_post_data = "";
232char buffer[MAX_INPUT_BUFFER]; 249char buffer[MAX_INPUT_BUFFER];
233 250
234void print_usage (void);
235void print_help (void);
236int process_arguments (int, char **); 251int process_arguments (int, char **);
237static char *base64 (char *bin, int len); 252static char *base64 (char *bin, int len);
238int check_http (void); 253int check_http (void);
@@ -249,7 +264,7 @@ main (int argc, char **argv)
249 server_url_length = strlen(server_url); 264 server_url_length = strlen(server_url);
250 265
251 if (process_arguments (argc, argv) == ERROR) 266 if (process_arguments (argc, argv) == ERROR)
252 usage ("check_http: could not parse arguments\n"); 267 usage (_("check_http: could not parse arguments\n"));
253 268
254 if (strstr (timestamp, ":")) { 269 if (strstr (timestamp, ":")) {
255 if (strstr (server_url, "?")) 270 if (strstr (server_url, "?"))
@@ -271,13 +286,13 @@ main (int argc, char **argv)
271 if (use_ssl && check_cert == TRUE) { 286 if (use_ssl && check_cert == TRUE) {
272 if (connect_SSL () != OK) 287 if (connect_SSL () != OK)
273 terminate (STATE_CRITICAL, 288 terminate (STATE_CRITICAL,
274 "HTTP CRITICAL - Could not make SSL connection\n"); 289 _("HTTP CRITICAL - Could not make SSL connection\n"));
275 if ((server_cert = SSL_get_peer_certificate (ssl)) != NULL) { 290 if ((server_cert = SSL_get_peer_certificate (ssl)) != NULL) {
276 result = check_certificate (&server_cert); 291 result = check_certificate (&server_cert);
277 X509_free (server_cert); 292 X509_free (server_cert);
278 } 293 }
279 else { 294 else {
280 printf ("ERROR: Cannot retrieve server certificate.\n"); 295 printf (_("ERROR: Cannot retrieve server certificate.\n"));
281 result = STATE_CRITICAL; 296 result = STATE_CRITICAL;
282 } 297 }
283 SSL_shutdown (ssl); 298 SSL_shutdown (ssl);
@@ -348,30 +363,30 @@ process_arguments (int argc, char **argv)
348 363
349 switch (c) { 364 switch (c) {
350 case '?': /* usage */ 365 case '?': /* usage */
351 usage3 ("unknown argument", optopt); 366 usage3 (_("unknown argument"), optopt);
352 break; 367 break;
353 case 'h': /* help */ 368 case 'h': /* help */
354 print_help (); 369 print_help ();
355 exit (STATE_OK); 370 exit (STATE_OK);
356 break; 371 break;
357 case 'V': /* version */ 372 case 'V': /* version */
358 print_revision (progname, REVISION); 373 print_revision (progname, revision);
359 exit (STATE_OK); 374 exit (STATE_OK);
360 break; 375 break;
361 case 't': /* timeout period */ 376 case 't': /* timeout period */
362 if (!is_intnonneg (optarg)) 377 if (!is_intnonneg (optarg))
363 usage2 ("timeout interval must be a non-negative integer", optarg); 378 usage2 (_("timeout interval must be a non-negative integer"), optarg);
364 socket_timeout = atoi (optarg); 379 socket_timeout = atoi (optarg);
365 break; 380 break;
366 case 'c': /* critical time threshold */ 381 case 'c': /* critical time threshold */
367 if (!is_intnonneg (optarg)) 382 if (!is_intnonneg (optarg))
368 usage2 ("invalid critical threshold", optarg); 383 usage2 (_("invalid critical threshold"), optarg);
369 critical_time = strtod (optarg, NULL); 384 critical_time = strtod (optarg, NULL);
370 check_critical_time = TRUE; 385 check_critical_time = TRUE;
371 break; 386 break;
372 case 'w': /* warning time threshold */ 387 case 'w': /* warning time threshold */
373 if (!is_intnonneg (optarg)) 388 if (!is_intnonneg (optarg))
374 usage2 ("invalid warning threshold", optarg); 389 usage2 (_("invalid warning threshold"), optarg);
375 warning_time = strtod (optarg, NULL); 390 warning_time = strtod (optarg, NULL);
376 check_warning_time = TRUE; 391 check_warning_time = TRUE;
377 break; 392 break;
@@ -383,7 +398,7 @@ process_arguments (int argc, char **argv)
383 break; 398 break;
384 case 'S': /* use SSL */ 399 case 'S': /* use SSL */
385#ifndef HAVE_SSL 400#ifndef HAVE_SSL
386 usage ("check_http: invalid option - SSL is not available\n"); 401 usage (_("check_http: invalid option - SSL is not available\n"));
387#endif 402#endif
388 use_ssl = TRUE; 403 use_ssl = TRUE;
389 if (specify_port == FALSE) 404 if (specify_port == FALSE)
@@ -392,11 +407,11 @@ process_arguments (int argc, char **argv)
392 case 'C': /* Check SSL cert validity */ 407 case 'C': /* Check SSL cert validity */
393#ifdef HAVE_SSL 408#ifdef HAVE_SSL
394 if (!is_intnonneg (optarg)) 409 if (!is_intnonneg (optarg))
395 usage2 ("invalid certificate expiration period", optarg); 410 usage2 (_("invalid certificate expiration period"), optarg);
396 days_till_exp = atoi (optarg); 411 days_till_exp = atoi (optarg);
397 check_cert = TRUE; 412 check_cert = TRUE;
398#else 413#else
399 usage ("check_http: invalid option - SSL is not available\n"); 414 usage (_("check_http: invalid option - SSL is not available\n"));
400#endif 415#endif
401 break; 416 break;
402 case 'f': /* onredirect */ 417 case 'f': /* onredirect */
@@ -411,7 +426,7 @@ process_arguments (int argc, char **argv)
411 if (!strcmp (optarg, "critical")) 426 if (!strcmp (optarg, "critical"))
412 onredirect = STATE_CRITICAL; 427 onredirect = STATE_CRITICAL;
413 if (verbose) 428 if (verbose)
414 printf("option f:%d \n", onredirect); 429 printf(_("option f:%d \n"), onredirect);
415 break; 430 break;
416 /* Note: H, I, and u must be malloc'd or will fail on redirects */ 431 /* Note: H, I, and u must be malloc'd or will fail on redirects */
417 case 'H': /* Host Name (virtual host) */ 432 case 'H': /* Host Name (virtual host) */
@@ -426,7 +441,7 @@ process_arguments (int argc, char **argv)
426 break; 441 break;
427 case 'p': /* Host or server */ 442 case 'p': /* Host or server */
428 if (!is_intnonneg (optarg)) 443 if (!is_intnonneg (optarg))
429 usage2 ("invalid port number", optarg); 444 usage2 (_("invalid port number"), optarg);
430 server_port = atoi (optarg); 445 server_port = atoi (optarg);
431 specify_port = TRUE; 446 specify_port = TRUE;
432 break; 447 break;
@@ -451,7 +466,7 @@ process_arguments (int argc, char **argv)
451 case 'l': /* linespan */ 466 case 'l': /* linespan */
452 case 'r': /* linespan */ 467 case 'r': /* linespan */
453 case 'R': /* linespan */ 468 case 'R': /* linespan */
454 usage ("check_http: call for regex which was not a compiled option\n"); 469 usage (_("check_http: call for regex which was not a compiled option\n"));
455 break; 470 break;
456#else 471#else
457 case 'l': /* linespan */ 472 case 'l': /* linespan */
@@ -465,7 +480,7 @@ process_arguments (int argc, char **argv)
465 errcode = regcomp (&preg, regexp, cflags); 480 errcode = regcomp (&preg, regexp, cflags);
466 if (errcode != 0) { 481 if (errcode != 0) {
467 (void) regerror (errcode, &preg, errbuf, MAX_INPUT_BUFFER); 482 (void) regerror (errcode, &preg, errbuf, MAX_INPUT_BUFFER);
468 printf ("Could Not Compile Regular Expression: %s", errbuf); 483 printf (_("Could Not Compile Regular Expression: %s"), errbuf);
469 return ERROR; 484 return ERROR;
470 } 485 }
471 break; 486 break;
@@ -477,7 +492,7 @@ process_arguments (int argc, char **argv)
477#ifdef USE_IPV6 492#ifdef USE_IPV6
478 address_family = AF_INET6; 493 address_family = AF_INET6;
479#else 494#else
480 usage ("IPv6 support not available\n"); 495 usage (_("IPv6 support not available\n"));
481#endif 496#endif
482 break; 497 break;
483 case 'v': /* verbose */ 498 case 'v': /* verbose */
@@ -499,7 +514,7 @@ process_arguments (int argc, char **argv)
499 514
500 if (strcmp (server_address ,"") == 0) { 515 if (strcmp (server_address ,"") == 0) {
501 if (strcmp (host_name, "") == 0) 516 if (strcmp (host_name, "") == 0)
502 usage ("check_http: you must specify a server address or host name\n"); 517 usage (_("check_http: you must specify a server address or host name\n"));
503 else 518 else
504 asprintf (&server_address, "%s", host_name); 519 asprintf (&server_address, "%s", host_name);
505 } 520 }
@@ -580,14 +595,14 @@ check_http (void)
580 if (use_ssl == TRUE) { 595 if (use_ssl == TRUE) {
581 596
582 if (connect_SSL () != OK) { 597 if (connect_SSL () != OK) {
583 terminate (STATE_CRITICAL, "Unable to open TCP socket"); 598 terminate (STATE_CRITICAL, _("Unable to open TCP socket"));
584 } 599 }
585 600
586 if ((server_cert = SSL_get_peer_certificate (ssl)) != NULL) { 601 if ((server_cert = SSL_get_peer_certificate (ssl)) != NULL) {
587 X509_free (server_cert); 602 X509_free (server_cert);
588 } 603 }
589 else { 604 else {
590 printf ("ERROR: Cannot retrieve server certificate.\n"); 605 printf (_("ERROR: Cannot retrieve server certificate.\n"));
591 return STATE_CRITICAL; 606 return STATE_CRITICAL;
592 } 607 }
593 608
@@ -595,7 +610,7 @@ check_http (void)
595 else { 610 else {
596#endif 611#endif
597 if (my_tcp_connect (server_address, server_port, &sd) != STATE_OK) 612 if (my_tcp_connect (server_address, server_port, &sd) != STATE_OK)
598 terminate (STATE_CRITICAL, "Unable to open TCP socket"); 613 terminate (STATE_CRITICAL, _("Unable to open TCP socket"));
599#ifdef HAVE_SSL 614#ifdef HAVE_SSL
600 } 615 }
601#endif 616#endif
@@ -608,7 +623,7 @@ check_http (void)
608 623
609 /* send user agent */ 624 /* send user agent */
610 asprintf (&buf, "%sUser-Agent: check_http/%s (nagios-plugins %s)\r\n", 625 asprintf (&buf, "%sUser-Agent: check_http/%s (nagios-plugins %s)\r\n",
611 buf, clean_revstring (REVISION), PACKAGE_VERSION); 626 buf, clean_revstring (revision), VERSION);
612 627
613 /* optionally send the authentication info */ 628 /* optionally send the authentication info */
614 if (strcmp (user_auth, "")) { 629 if (strcmp (user_auth, "")) {
@@ -653,14 +668,14 @@ check_http (void)
653 if (use_ssl) { 668 if (use_ssl) {
654 sslerr=SSL_get_error(ssl, i); 669 sslerr=SSL_get_error(ssl, i);
655 if ( sslerr == SSL_ERROR_SSL ) { 670 if ( sslerr == SSL_ERROR_SSL ) {
656 terminate (STATE_WARNING, "Client Certificate Required\n"); 671 terminate (STATE_WARNING, _("Client Certificate Required\n"));
657 } else { 672 } else {
658 terminate (STATE_CRITICAL, "Error in recv()"); 673 terminate (STATE_CRITICAL, _("Error in recv()"));
659 } 674 }
660 } 675 }
661 else { 676 else {
662#endif 677#endif
663 terminate (STATE_CRITICAL, "Error in recv()"); 678 terminate (STATE_CRITICAL, _("Error in recv()"));
664#ifdef HAVE_SSL 679#ifdef HAVE_SSL
665 } 680 }
666#endif 681#endif
@@ -668,7 +683,7 @@ check_http (void)
668 683
669 /* return a CRITICAL status if we couldn't read any data */ 684 /* return a CRITICAL status if we couldn't read any data */
670 if (pagesize == (size_t) 0) 685 if (pagesize == (size_t) 0)
671 terminate (STATE_CRITICAL, "No data received %s", timestamp); 686 terminate (STATE_CRITICAL, _("No data received %s"), timestamp);
672 687
673 /* close the connection */ 688 /* close the connection */
674 my_close (); 689 my_close ();
@@ -711,10 +726,10 @@ check_http (void)
711 /* make sure the status line matches the response we are looking for */ 726 /* make sure the status line matches the response we are looking for */
712 if (!strstr (status_line, server_expect)) { 727 if (!strstr (status_line, server_expect)) {
713 if (server_port == HTTP_PORT) 728 if (server_port == HTTP_PORT)
714 asprintf (&msg, "Invalid HTTP response received from host\n"); 729 asprintf (&msg, _("Invalid HTTP response received from host\n"));
715 else 730 else
716 asprintf (&msg, 731 asprintf (&msg,
717 "Invalid HTTP response received from host on port %d\n", 732 _("Invalid HTTP response received from host on port %d\n"),
718 server_port); 733 server_port);
719 terminate (STATE_CRITICAL, msg); 734 terminate (STATE_CRITICAL, msg);
720 } 735 }
@@ -722,7 +737,7 @@ check_http (void)
722 737
723 /* Exit here if server_expect was set by user and not default */ 738 /* Exit here if server_expect was set by user and not default */
724 if ( server_expect_yn ) { 739 if ( server_expect_yn ) {
725 asprintf (&msg, "HTTP OK: Status line output matched \"%s\"\n", 740 asprintf (&msg, _("HTTP OK: Status line output matched \"%s\"\n"),
726 server_expect); 741 server_expect);
727 if (verbose) 742 if (verbose)
728 printf ("%s\n",msg); 743 printf ("%s\n",msg);
@@ -737,7 +752,7 @@ check_http (void)
737 strstr (status_line, "501") || 752 strstr (status_line, "501") ||
738 strstr (status_line, "502") || 753 strstr (status_line, "502") ||
739 strstr (status_line, "503")) { 754 strstr (status_line, "503")) {
740 terminate (STATE_CRITICAL, "HTTP CRITICAL: %s\n", status_line); 755 terminate (STATE_CRITICAL, _("HTTP CRITICAL: %s\n"), status_line);
741 } 756 }
742 757
743 /* client errors result in a warning state */ 758 /* client errors result in a warning state */
@@ -746,7 +761,7 @@ check_http (void)
746 strstr (status_line, "402") || 761 strstr (status_line, "402") ||
747 strstr (status_line, "403") || 762 strstr (status_line, "403") ||
748 strstr (status_line, "404")) { 763 strstr (status_line, "404")) {
749 terminate (STATE_WARNING, "HTTP WARNING: %s\n", status_line); 764 terminate (STATE_WARNING, _("HTTP WARNING: %s\n"), status_line);
750 } 765 }
751 766
752 /* check redirected page if specified */ 767 /* check redirected page if specified */
@@ -763,12 +778,12 @@ check_http (void)
763 server_address = realloc (server_address, MAX_IPV4_HOSTLENGTH + 1); 778 server_address = realloc (server_address, MAX_IPV4_HOSTLENGTH + 1);
764 if (server_address == NULL) 779 if (server_address == NULL)
765 terminate (STATE_UNKNOWN, 780 terminate (STATE_UNKNOWN,
766 "HTTP UNKNOWN: could not allocate server_address"); 781 _("HTTP UNKNOWN: could not allocate server_address"));
767 if (strcspn (pos, "\r\n") > server_url_length) { 782 if (strcspn (pos, "\r\n") > (size_t)server_url_length) {
768 server_url = realloc (server_url, strcspn (pos, "\r\n")); 783 server_url = realloc (server_url, strcspn (pos, "\r\n"));
769 if (server_url == NULL) 784 if (server_url == NULL)
770 terminate (STATE_UNKNOWN, 785 terminate (STATE_UNKNOWN,
771 "HTTP UNKNOWN: could not allocate server_url"); 786 _("HTTP UNKNOWN: could not allocate server_url"));
772 server_url_length = strcspn (pos, "\r\n"); 787 server_url_length = strcspn (pos, "\r\n");
773 } 788 }
774 if (sscanf (pos, HDR_LOCATION URI_HTTP URI_HOST URI_PORT URI_PATH, server_type, server_address, server_port_text, server_url) == 4) { 789 if (sscanf (pos, HDR_LOCATION URI_HTTP URI_HOST URI_PORT URI_PATH, server_type, server_address, server_port_text, server_url) == 4) {
@@ -807,21 +822,21 @@ check_http (void)
807 pos += (size_t) strcspn (pos, "\r\n"); 822 pos += (size_t) strcspn (pos, "\r\n");
808 pos += (size_t) strspn (pos, "\r\n"); 823 pos += (size_t) strspn (pos, "\r\n");
809 } /* end while (pos) */ 824 } /* end while (pos) */
810 printf ("UNKNOWN - Could not find redirect location - %s%s", 825 printf (_("UNKNOWN - Could not find redirect location - %s%s"),
811 status_line, (display_html ? "</A>" : "")); 826 status_line, (display_html ? "</A>" : ""));
812 exit (STATE_UNKNOWN); 827 exit (STATE_UNKNOWN);
813 } /* end if (onredirect == STATE_DEPENDENT) */ 828 } /* end if (onredirect == STATE_DEPENDENT) */
814 829
815 else if (onredirect == STATE_UNKNOWN) 830 else if (onredirect == STATE_UNKNOWN)
816 printf ("UNKNOWN"); 831 printf (_("UNKNOWN"));
817 else if (onredirect == STATE_OK) 832 else if (onredirect == STATE_OK)
818 printf ("OK"); 833 printf (_("OK"));
819 else if (onredirect == STATE_WARNING) 834 else if (onredirect == STATE_WARNING)
820 printf ("WARNING"); 835 printf (_("WARNING"));
821 else if (onredirect == STATE_CRITICAL) 836 else if (onredirect == STATE_CRITICAL)
822 printf ("CRITICAL"); 837 printf (_("CRITICAL"));
823 elapsed_time = delta_time (tv); 838 elapsed_time = delta_time (tv);
824 asprintf (&msg, " - %s - %.3f second response time %s%s|time=%.3f\n", 839 asprintf (&msg, _(" - %s - %.3f second response time %s%s|time=%.3f\n"),
825 status_line, elapsed_time, timestamp, 840 status_line, elapsed_time, timestamp,
826 (display_html ? "</A>" : ""), elapsed_time); 841 (display_html ? "</A>" : ""), elapsed_time);
827 terminate (onredirect, msg); 842 terminate (onredirect, msg);
@@ -833,7 +848,7 @@ check_http (void)
833 848
834 /* check elapsed time */ 849 /* check elapsed time */
835 elapsed_time = delta_time (tv); 850 elapsed_time = delta_time (tv);
836 asprintf (&msg, "HTTP problem: %s - %.3f second response time %s%s|time=%.3f\n", 851 asprintf (&msg, _("HTTP problem: %s - %.3f second response time %s%s|time=%.3f\n"),
837 status_line, elapsed_time, timestamp, 852 status_line, elapsed_time, timestamp,
838 (display_html ? "</A>" : ""), elapsed_time); 853 (display_html ? "</A>" : ""), elapsed_time);
839 if (check_critical_time == TRUE && elapsed_time > critical_time) 854 if (check_critical_time == TRUE && elapsed_time > critical_time)
@@ -846,13 +861,13 @@ check_http (void)
846 861
847 if (strlen (string_expect)) { 862 if (strlen (string_expect)) {
848 if (strstr (page, string_expect)) { 863 if (strstr (page, string_expect)) {
849 printf ("HTTP OK %s - %.3f second response time %s%s|time=%.3f\n", 864 printf (_("HTTP OK %s - %.3f second response time %s%s|time=%.3f\n"),
850 status_line, elapsed_time, 865 status_line, elapsed_time,
851 timestamp, (display_html ? "</A>" : ""), elapsed_time); 866 timestamp, (display_html ? "</A>" : ""), elapsed_time);
852 exit (STATE_OK); 867 exit (STATE_OK);
853 } 868 }
854 else { 869 else {
855 printf ("CRITICAL - string not found%s|time=%.3f\n", 870 printf (_("CRITICAL - string not found%s|time=%.3f\n"),
856 (display_html ? "</A>" : ""), elapsed_time); 871 (display_html ? "</A>" : ""), elapsed_time);
857 exit (STATE_CRITICAL); 872 exit (STATE_CRITICAL);
858 } 873 }
@@ -861,20 +876,20 @@ check_http (void)
861 if (strlen (regexp)) { 876 if (strlen (regexp)) {
862 errcode = regexec (&preg, page, REGS, pmatch, 0); 877 errcode = regexec (&preg, page, REGS, pmatch, 0);
863 if (errcode == 0) { 878 if (errcode == 0) {
864 printf ("HTTP OK %s - %.3f second response time %s%s|time=%.3f\n", 879 printf (_("HTTP OK %s - %.3f second response time %s%s|time=%.3f\n"),
865 status_line, elapsed_time, 880 status_line, elapsed_time,
866 timestamp, (display_html ? "</A>" : ""), elapsed_time); 881 timestamp, (display_html ? "</A>" : ""), elapsed_time);
867 exit (STATE_OK); 882 exit (STATE_OK);
868 } 883 }
869 else { 884 else {
870 if (errcode == REG_NOMATCH) { 885 if (errcode == REG_NOMATCH) {
871 printf ("CRITICAL - pattern not found%s|time=%.3f\n", 886 printf (_("CRITICAL - pattern not found%s|time=%.3f\n"),
872 (display_html ? "</A>" : ""), elapsed_time); 887 (display_html ? "</A>" : ""), elapsed_time);
873 exit (STATE_CRITICAL); 888 exit (STATE_CRITICAL);
874 } 889 }
875 else { 890 else {
876 regerror (errcode, &preg, errbuf, MAX_INPUT_BUFFER); 891 regerror (errcode, &preg, errbuf, MAX_INPUT_BUFFER);
877 printf ("CRITICAL - Execute Error: %s\n", errbuf); 892 printf (_("CRITICAL - Execute Error: %s\n"), errbuf);
878 exit (STATE_CRITICAL); 893 exit (STATE_CRITICAL);
879 } 894 }
880 } 895 }
@@ -884,12 +899,12 @@ check_http (void)
884 /* make sure the page is of an appropriate size */ 899 /* make sure the page is of an appropriate size */
885 page_len = strlen (page); 900 page_len = strlen (page);
886 if ((min_page_len > 0) && (page_len < min_page_len)) { 901 if ((min_page_len > 0) && (page_len < min_page_len)) {
887 printf ("HTTP WARNING: page size too small%s|size=%i\n", 902 printf (_("HTTP WARNING: page size too small%s|size=%i\n"),
888 (display_html ? "</A>" : ""), page_len ); 903 (display_html ? "</A>" : ""), page_len );
889 exit (STATE_WARNING); 904 exit (STATE_WARNING);
890 } 905 }
891 /* We only get here if all tests have been passed */ 906 /* We only get here if all tests have been passed */
892 asprintf (&msg, "HTTP OK %s - %.3f second response time %s%s|time=%.3f\n", 907 asprintf (&msg, _("HTTP OK %s - %.3f second response time %s%s|time=%.3f\n"),
893 status_line, (float)elapsed_time, 908 status_line, (float)elapsed_time,
894 timestamp, (display_html ? "</A>" : ""), elapsed_time); 909 timestamp, (display_html ? "</A>" : ""), elapsed_time);
895 terminate (STATE_OK, msg); 910 terminate (STATE_OK, msg);
@@ -906,14 +921,14 @@ int connect_SSL (void)
906 asprintf (&randbuff, "%s", "qwertyuiopasdfghjklqwertyuiopasdfghjkl"); 921 asprintf (&randbuff, "%s", "qwertyuiopasdfghjklqwertyuiopasdfghjkl");
907 RAND_seed (randbuff, strlen (randbuff)); 922 RAND_seed (randbuff, strlen (randbuff));
908 if (verbose) 923 if (verbose)
909 printf("SSL seeding: %s\n", (RAND_status()==1 ? "OK" : "Failed") ); 924 printf(_("SSL seeding: %s\n"), (RAND_status()==1 ? _("OK") : _("Failed")) );
910 925
911 /* Initialize SSL context */ 926 /* Initialize SSL context */
912 SSLeay_add_ssl_algorithms (); 927 SSLeay_add_ssl_algorithms ();
913 meth = SSLv23_client_method (); 928 meth = SSLv23_client_method ();
914 SSL_load_error_strings (); 929 SSL_load_error_strings ();
915 if ((ctx = SSL_CTX_new (meth)) == NULL) { 930 if ((ctx = SSL_CTX_new (meth)) == NULL) {
916 printf ("CRITICAL - Cannot create SSL context.\n"); 931 printf (_("CRITICAL - Cannot create SSL context.\n"));
917 return STATE_CRITICAL; 932 return STATE_CRITICAL;
918 } 933 }
919 934
@@ -937,7 +952,7 @@ int connect_SSL (void)
937 ERR_print_errors_fp (stderr); 952 ERR_print_errors_fp (stderr);
938 } 953 }
939 else { 954 else {
940 printf ("CRITICAL - Cannot initiate SSL handshake.\n"); 955 printf (_("CRITICAL - Cannot initiate SSL handshake.\n"));
941 } 956 }
942 SSL_free (ssl); 957 SSL_free (ssl);
943 } 958 }
@@ -965,7 +980,7 @@ check_certificate (X509 ** certificate)
965 /* Generate tm structure to process timestamp */ 980 /* Generate tm structure to process timestamp */
966 if (tm->type == V_ASN1_UTCTIME) { 981 if (tm->type == V_ASN1_UTCTIME) {
967 if (tm->length < 10) { 982 if (tm->length < 10) {
968 printf ("CRITICAL - Wrong time format in certificate.\n"); 983 printf (_("CRITICAL - Wrong time format in certificate.\n"));
969 return STATE_CRITICAL; 984 return STATE_CRITICAL;
970 } 985 }
971 else { 986 else {
@@ -977,7 +992,7 @@ check_certificate (X509 ** certificate)
977 } 992 }
978 else { 993 else {
979 if (tm->length < 12) { 994 if (tm->length < 12) {
980 printf ("CRITICAL - Wrong time format in certificate.\n"); 995 printf (_("CRITICAL - Wrong time format in certificate.\n"));
981 return STATE_CRITICAL; 996 return STATE_CRITICAL;
982 } 997 }
983 else { 998 else {
@@ -1006,20 +1021,20 @@ check_certificate (X509 ** certificate)
1006 stamp.tm_mday, stamp.tm_year + 1900, stamp.tm_hour, stamp.tm_min); 1021 stamp.tm_mday, stamp.tm_year + 1900, stamp.tm_hour, stamp.tm_min);
1007 1022
1008 if (days_left > 0 && days_left <= days_till_exp) { 1023 if (days_left > 0 && days_left <= days_till_exp) {
1009 printf ("WARNING - Certificate expires in %d day(s) (%s).\n", days_left, timestamp); 1024 printf (_("WARNING - Certificate expires in %d day(s) (%s).\n"), days_left, timestamp);
1010 return STATE_WARNING; 1025 return STATE_WARNING;
1011 } 1026 }
1012 if (days_left < 0) { 1027 if (days_left < 0) {
1013 printf ("CRITICAL - Certificate expired on %s.\n", timestamp); 1028 printf (_("CRITICAL - Certificate expired on %s.\n"), timestamp);
1014 return STATE_CRITICAL; 1029 return STATE_CRITICAL;
1015 } 1030 }
1016 1031
1017 if (days_left == 0) { 1032 if (days_left == 0) {
1018 printf ("WARNING - Certificate expires today (%s).\n", timestamp); 1033 printf (_("WARNING - Certificate expires today (%s).\n"), timestamp);
1019 return STATE_WARNING; 1034 return STATE_WARNING;
1020 } 1035 }
1021 1036
1022 printf ("OK - Certificate will expire on %s.\n", timestamp); 1037 printf (_("OK - Certificate will expire on %s.\n"), timestamp);
1023 1038
1024 return STATE_OK; 1039 return STATE_OK;
1025} 1040}
@@ -1062,33 +1077,3 @@ my_close (void)
1062 } 1077 }
1063#endif 1078#endif
1064} 1079}
1065
1066
1067
1068void
1069print_help (void)
1070{
1071 print_revision (progname, REVISION);
1072 printf
1073 ("Copyright (c) %s %s <%s>\n\n%s\n",
1074 COPYRIGHT, AUTHORS, EMAIL, SUMMARY);
1075 print_usage ();
1076 printf ("NOTE: One or both of -H and -I must be specified\n");
1077 printf ("\nOptions:\n" LONGOPTIONS "\n", HTTP_EXPECT, HTTP_PORT,
1078 DEFAULT_SOCKET_TIMEOUT, SSLOPTIONS, REGOPTIONS);
1079#ifdef HAVE_SSL
1080 printf (SSLDESCRIPTION);
1081#endif
1082}
1083
1084
1085void
1086print_usage (void)
1087{
1088 printf ("\
1089Usage:\n\
1090 %s %s\n\
1091 %s (-h | --help) for detailed help\n\
1092 %s (-V | --version) for version information\n",
1093 progname, OPTIONS, progname, progname);
1094}