Code

Fix includes for gettext
[nagiosplug.git] / plugins / check_http.c
index 98005d0220edc63a67da83f97daa5d6ad9e4d74d..5f96e31e78b23bc49e5f482f74a8a8850564b841 100644 (file)
  along with this program; if not, write to the Free Software
  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
+ $Id$
 ******************************************************************************/
 /* splint -I. -I../../plugins -I../../lib/ -I/usr/kerberos/include/ ../../plugins/check_http.c */
 
 const char *progname = "check_http";
 const char *revision = "$Revision$";
-const char *copyright = "1999-2001";
+const char *copyright = "1999-2004";
 const char *email = "nagiosplug-devel@lists.sourceforge.net";
 
 #include "common.h"
@@ -144,7 +146,7 @@ main (int argc, char **argv)
                  clean_revstring (revision), VERSION);
 
        if (process_arguments (argc, argv) == ERROR)
-               usage (_("check_http: could not parse arguments\n"));
+               usage4 (_("Could not parse arguments"));
 
        if (strstr (timestamp, ":")) {
                if (strstr (server_url, "?"))
@@ -172,7 +174,7 @@ main (int argc, char **argv)
                        X509_free (server_cert);
                }
                else {
-                       printf (_("ERROR: Cannot retrieve server certificate.\n"));
+                       printf (_("CRITICAL - Cannot retrieve server certificate.\n"));
                        result = STATE_CRITICAL;
                }
                SSL_shutdown (ssl);
@@ -188,7 +190,7 @@ main (int argc, char **argv)
 #endif
        return result;
 }
-\f
+
 
 
 /* process command-line arguments */
@@ -249,7 +251,9 @@ process_arguments (int argc, char **argv)
 
                switch (c) {
                case '?': /* usage */
-                       usage3 (_("unknown argument"), optopt);
+                       printf (_("%s: Unknown argument: %s\n\n"), progname, optarg);
+                       print_usage ();
+                       exit (STATE_UNKNOWN);
                        break;
                case 'h': /* help */
                        print_help ();
@@ -267,7 +271,7 @@ process_arguments (int argc, char **argv)
                        break;
                case 'c': /* critical time threshold */
                        if (!is_nonnegative (optarg))
-                               usage2 (_("invalid critical threshold"), optarg);
+                               usage2 (_("Critical threshold must be integer"), optarg);
                        else {
                                critical_time = strtod (optarg, NULL);
                                check_critical_time = TRUE;
@@ -275,7 +279,7 @@ process_arguments (int argc, char **argv)
                        break;
                case 'w': /* warning time threshold */
                        if (!is_nonnegative (optarg))
-                               usage2 (_("invalid warning threshold"), optarg);
+                               usage2 (_("Warning threshold must be integer"), optarg);
                        else {
                                warning_time = strtod (optarg, NULL);
                                check_warning_time = TRUE;
@@ -304,13 +308,13 @@ process_arguments (int argc, char **argv)
                case 'C': /* Check SSL cert validity */
 #ifdef HAVE_SSL
                        if (!is_intnonneg (optarg))
-                               usage2 (_("invalid certificate expiration period"), optarg);
+                               usage2 (_("Invalid certificate expiration period"), optarg);
                        else {
                                days_till_exp = atoi (optarg);
                                check_cert = TRUE;
                        }
 #else
-                       usage (_("check_http: invalid option - SSL is not available\n"));
+                       usage (_("Invalid option - SSL is not available\n"));
 #endif
                        break;
                case 'f': /* onredirect */
@@ -342,7 +346,7 @@ process_arguments (int argc, char **argv)
                        break;
                case 'p': /* Server port */
                        if (!is_intnonneg (optarg))
-                               usage2 (_("invalid port number"), optarg);
+                               usage2 (_("Invalid port number"), optarg);
                        else {
                                server_port = atoi (optarg);
                                specify_port = TRUE;
@@ -373,7 +377,7 @@ process_arguments (int argc, char **argv)
                case 'l': /* linespan */
                case 'r': /* linespan */
                case 'R': /* linespan */
-                       usage (_("check_http: call for regex which was not a compiled option\n"));
+                       usage4 (_("Call for regex which was not a compiled option"));
                        break;
 #else
                case 'l': /* linespan */
@@ -399,7 +403,7 @@ process_arguments (int argc, char **argv)
 #ifdef USE_IPV6
                        address_family = AF_INET6;
 #else
-                       usage (_("IPv6 support not available\n"));
+                       usage4 (_("IPv6 support not available"));
 #endif
                        break;
                case 'v': /* verbose */
@@ -442,7 +446,7 @@ process_arguments (int argc, char **argv)
 
        if (server_address == NULL) {
                if (host_name == NULL)
-                       usage (_("check_http: you must specify a server address or host name\n"));
+                       usage4 (_("You must specify a server address or host name"));
                else
                        server_address = strdup (host_name);
        }
@@ -455,7 +459,7 @@ process_arguments (int argc, char **argv)
 
        return TRUE;
 }
-\f
+
 
 
 /* written by lauri alanko */
@@ -498,8 +502,6 @@ base64 (const char *bin, size_t len)
        buf[i] = '\0';
        return buf;
 }
-\f
-
 
 
 
@@ -613,6 +615,7 @@ parse_time_string (const char *string)
 }
 
 
+
 static void
 check_document_dates (const char *headers)
 {
@@ -673,17 +676,17 @@ check_document_dates (const char *headers)
        } else if (!document_date || !*document_date) {
                die (STATE_CRITICAL, _("Document modification date unknown\n"));
        } else {
-               time_t sd = parse_time_string (server_date);
-               time_t dd = parse_time_string (document_date);
+               time_t srv_data = parse_time_string (server_date);
+               time_t doc_data = parse_time_string (document_date);
 
-               if (sd <= 0) {
+               if (srv_data <= 0) {
                        die (STATE_CRITICAL, _("CRITICAL - Server date \"%100s\" unparsable"), server_date);
-               } else if (dd <= 0) {
+               } else if (doc_data <= 0) {
                        die (STATE_CRITICAL, _("CRITICAL - Document date \"%100s\" unparsable"), document_date);
-               } else if (dd > sd + 30) {
-                       die (STATE_CRITICAL, _("CRITICAL - Document is %d seconds in the future\n"), dd - sd);
-               } else if (dd < sd - maximum_age) {
-               int n = (sd - dd);
+               } else if (doc_data > srv_data + 30) {
+                       die (STATE_CRITICAL, _("CRITICAL - Document is %d seconds in the future\n"), (int)doc_data - (int)srv_data);
+               } else if (doc_data < srv_data - maximum_age) {
+               int n = (srv_data - doc_data);
                if (n > (60 * 60 * 24 * 2))
                        die (STATE_CRITICAL,
                          _("CRITICAL - Last modified %.1f days ago\n"),
@@ -735,7 +738,7 @@ check_http (void)
                        X509_free (server_cert);
                }
                else {
-                       printf (_("ERROR: Cannot retrieve server certificate.\n"));
+                       printf (_("CRITICAL - Cannot retrieve server certificate.\n"));
                        return STATE_CRITICAL;
                }
 
@@ -818,12 +821,12 @@ check_http (void)
                        if ( sslerr == SSL_ERROR_SSL ) {
                                die (STATE_WARNING, _("Client Certificate Required\n"));
                        } else {
-                               die (STATE_CRITICAL, _("Error in recv()\n"));
+                               die (STATE_CRITICAL, _("Error on receive\n"));
                        }
                }
                else {
 #endif
-                       die (STATE_CRITICAL, _("Error in recv()\n"));
+                       die (STATE_CRITICAL, _("Error on receive\n"));
 #ifdef HAVE_SSL
                }
 #endif
@@ -950,7 +953,7 @@ check_http (void)
        microsec = deltime (tv);
        elapsed_time = (double)microsec / 1.0e6;
        asprintf (&msg,
-                 _("HTTP problem: %s - %.3f second response time %s%s|%s %s\n"),
+                 _("HTTP WARNING: %s - %.3f second response time %s%s|%s %s\n"),
                  status_line, elapsed_time, timestamp,
                  (display_html ? "</A>" : ""),
                                                perfd_time (elapsed_time), perfd_size (pagesize));
@@ -1021,7 +1024,6 @@ check_http (void)
 
 
 
-
 /* per RFC 2396 */
 #define HDR_LOCATION "%*[Ll]%*[Oo]%*[Cc]%*[Aa]%*[Tt]%*[Ii]%*[Oo]%*[Nn]: "
 #define URI_HTTP "%[HTPShtps]://"
@@ -1047,11 +1049,11 @@ redir (char *pos, char *status_line)
 
        addr = malloc (MAX_IPV4_HOSTLENGTH + 1);
        if (addr == NULL)
-               die (STATE_UNKNOWN, _("ERROR: could not allocate addr\n"));
+               die (STATE_UNKNOWN, _("Could not allocate addr\n"));
        
        url = malloc (strcspn (pos, "\r\n"));
        if (url == NULL)
-               die (STATE_UNKNOWN, _("ERROR: could not allocate url\n"));
+               die (STATE_UNKNOWN, _("Could not allocate url\n"));
 
        while (pos) {
 
@@ -1071,7 +1073,7 @@ redir (char *pos, char *status_line)
 
                url = realloc (url, strcspn (pos, "\r\n"));
                if (url == NULL)
-                       die (STATE_UNKNOWN, _("ERROR: could not allocate url\n"));
+                       die (STATE_UNKNOWN, _("could not allocate url\n"));
 
                /* URI_HTTP, URI_HOST, URI_PORT, URI_PATH */
                if (sscanf (pos, HD1, type, addr, port, url) == 4) {
@@ -1223,6 +1225,8 @@ int connect_SSL (void)
 }
 #endif
 
+
+
 #ifdef HAVE_SSL
 int
 check_certificate (X509 ** certificate)
@@ -1298,7 +1302,7 @@ check_certificate (X509 ** certificate)
        return STATE_OK;
 }
 #endif
-\f
+
 
 
 char *perfd_time (double elapsed_time)
@@ -1310,6 +1314,7 @@ char *perfd_time (double elapsed_time)
 }
 
 
+
 char *perfd_size (int page_len)
 {
        return perfdata ("size", page_len, "B",
@@ -1319,6 +1324,7 @@ char *perfd_size (int page_len)
 }
 
 
+
 int
 my_recv (void)
 {
@@ -1337,6 +1343,7 @@ my_recv (void)
 }
 
 
+
 int
 my_close (void)
 {
@@ -1357,9 +1364,6 @@ my_close (void)
 
 
 
-
-
-\f
 void
 print_help (void)
 {
@@ -1372,7 +1376,7 @@ print_help (void)
 This plugin tests the HTTP service on the specified host. It can test\n\
 normal (http) and secure (https) servers, follow redirects, search for\n\
 strings and regular expressions, check connection times, and report on\n\
-certificate expiration times.\n"));
+certificate expiration times.\n\n"));
 
        print_usage ();
 
@@ -1483,16 +1487,14 @@ the certificate is expired.\n"));
 
 
 
-
 void
 print_usage (void)
 {
-       printf (_("\
-Usage: %s (-H <vhost> | -I <IP-address>) [-u <uri>] [-p <port>]\n\
-  [-w <warn time>] [-c <critical time>] [-t <timeout>] [-L]\n\
-  [-a auth] [-f <ok | warn | critcal | follow>] [-e <expect>]\n\
-  [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]\n\
-  [-P string] [-m min_pg_size] [-4|-6] [-N] [-M <age>] [-A string]\n\
-  [-k string]\n"), progname);
-       printf (_(UT_HLP_VRS), progname, progname);
+       printf ("\
+Usage: %s -H <vhost> | -I <IP-address>) [-u <uri>] [-p <port>]\n\
+                  [-w <warn time>] [-c <critical time>] [-t <timeout>] [-L]\n\
+                  [-a auth] [-f <ok | warn | critcal | follow>] [-e <expect>]\n\
+                  [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]\n\
+                  [-P string] [-m min_pg_size] [-4|-6] [-N] [-M <age>]\n\
+                  [-A string] [-k string]\n", progname);
 }