Code

1.4.15 prep
[nagiosplug.git] / plugins / check_tcp.c
index 3ffa4cd62019edaa43f81303e0e52858429a1373..178bd5688dec52abeeb72667b595ba7c65709ab5 100644 (file)
@@ -1,41 +1,45 @@
 /*****************************************************************************
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
- $Id$
+* 
+* Nagios check_tcp plugin
+* 
+* License: GPL
+* Copyright (c) 1999-2008 Nagios Plugins Development Team
+* 
+* Description:
+* 
+* This file contains the check_tcp plugin
+* 
+* 
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+* 
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU General Public License for more details.
+* 
+* You should have received a copy of the GNU General Public License
+* along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*
+* $Id$
+* 
 *****************************************************************************/
 
 /* progname "check_tcp" changes depending on symlink called */
 char *progname;
-const char *revision = "$Revision$";
-const char *copyright = "1999-2004";
+const char *copyright = "1999-2008";
 const char *email = "nagiosplug-devel@lists.sourceforge.net";
 
 #include "common.h"
 #include "netutils.h"
 #include "utils.h"
+#include "utils_tcp.h"
 
 #ifdef HAVE_SSL
 static int check_cert = FALSE;
 static int days_till_exp;
-static char *randbuff = "";
-static X509 *server_cert;
-# ifdef USE_OPENSSL
-static int check_certificate (X509 **);
-# endif /* USE_OPENSSL */
 # define my_recv(buf, len) ((flags & FLAG_SSL) ? np_net_ssl_read(buf, len) : read(sd, buf, len))
 # define my_send(buf, len) ((flags & FLAG_SSL) ? np_net_ssl_write(buf, len) : send(sd, buf, len, 0))
 #else
@@ -43,7 +47,6 @@ static int check_certificate (X509 **);
 # define my_send(buf, len) send(sd, buf, len, 0)
 #endif
 
-
 /* int my_recv(char *, size_t); */
 static int process_arguments (int, char **);
 void print_help (void);
@@ -56,7 +59,6 @@ static char *QUIT = NULL;
 static int PROTOCOL = IPPROTO_TCP; /* most common is default */
 static int PORT = 0;
 
-static char timestamp[17] = "";
 static int server_port = 0;
 static char *server_address = NULL;
 static char *server_send = NULL;
@@ -84,6 +86,7 @@ static int expect_mismatch_state = STATE_WARNING;
 #define FLAG_TIME_WARN 0x08
 #define FLAG_TIME_CRIT 0x10
 #define FLAG_HIDE_OUTPUT 0x20
+#define FLAG_MATCH_ALL 0x40
 static size_t flags = FLAG_EXACT_MATCH;
 
 int
@@ -93,7 +96,8 @@ main (int argc, char **argv)
        int i;
        char *status = NULL;
        struct timeval tv;
-       size_t len, match = -1;
+       size_t len;
+       int match = -1;
 
        setlocale (LC_ALL, "");
        bindtextdomain (PACKAGE, LOCALEDIR);
@@ -106,7 +110,7 @@ main (int argc, char **argv)
 
        len = strlen(progname);
        if(len > 6 && !memcmp(progname, "check_", 6)) {
-               SERVICE = progname + 6;
+               SERVICE = strdup(progname + 6);
                for(i = 0; i < len - 6; i++)
                        SERVICE[i] = toupper(SERVICE[i]);
        }
@@ -160,9 +164,9 @@ main (int argc, char **argv)
        }
        else if (!strncmp(SERVICE, "JABBER", 6)) {
                SEND = "<stream:stream to=\'host\' xmlns=\'jabber:client\' xmlns:stream=\'http://etherx.jabber.org/streams\'>\n";
-               EXPECT = "<?xml version=\'1.0\'?><stream:stream xmlns:stream=\'http://etherx.jabber.org/streams\'";
+               EXPECT = "<?xml version=\'1.0\'?><stream:stream xmlns=\'jabber:client\' xmlns:stream=\'http://etherx.jabber.org/streams\'";
                QUIT = "</stream:stream>\n";
-               flags |= FLAG_SSL | FLAG_HIDE_OUTPUT;
+               flags |= FLAG_HIDE_OUTPUT;
                PORT = 5222;
        }
        else if (!strncmp (SERVICE, "NNTPS", 5)) {
@@ -182,6 +186,12 @@ main (int argc, char **argv)
                QUIT = "QUIT\r\n";
                PORT = 119;
        }
+       else if (!strncmp(SERVICE, "CLAMD", 5)) {
+               SEND = "PING";
+               EXPECT = "PONG";
+               QUIT = NULL;
+               PORT = 3310;
+       }
        /* fallthrough check, so it's supposed to use reverse matching */
        else if (strcmp (SERVICE, "TCP"))
                usage (_("CRITICAL - Generic check_tcp called with unknown service\n"));
@@ -192,18 +202,25 @@ main (int argc, char **argv)
        server_quit = QUIT;
        status = NULL;
 
+       /* Parse extra opts if any */
+       argv=np_extra_opts (&argc, argv, progname);
+
        if (process_arguments (argc, argv) == ERROR)
                usage4 (_("Could not parse arguments"));
 
        if(flags & FLAG_VERBOSE) {
                printf("Using service %s\n", SERVICE);
-               printf("Port: %d\n", PORT);
-               printf("flags: 0x%x\n", flags);
+               printf("Port: %d\n", server_port);
+               printf("flags: 0x%x\n", (int)flags);
        }
 
        if(EXPECT && !server_expect_count)
                server_expect_count++;
 
+       if(PROTOCOL==IPPROTO_UDP && !(server_expect_count && server_send)){
+               usage(_("With UDP checks, a send/expect string must be specified."));
+       }
+
        /* set up the timer */
        signal (SIGALRM, socket_timeout_alarm_handler);
        alarm (socket_timeout);
@@ -217,34 +234,19 @@ main (int argc, char **argv)
 #ifdef HAVE_SSL
        if (flags & FLAG_SSL){
                result = np_net_ssl_init(sd);
-               if(result != STATE_OK) return result;
-               /* XXX does np_net_ssl take care of printing an error?
-                       die (STATE_CRITICAL,_("CRITICAL - Could not make SSL connection\n"));
-               */
-       }
-#  ifdef USE_OPENSSL /* XXX gnutls does cert checking differently */
-       /*
-       if (flags & FLAG_SSL && check_cert == TRUE) {
-               if ((server_cert = SSL_get_peer_certificate (ssl)) != NULL) {
-                       result = check_certificate (&server_cert);
-                       X509_free(server_cert);
-               }
-               else {
-                       printf(_("CRITICAL - Cannot retrieve server certificate.\n"));
-                       result = STATE_CRITICAL;
+               if (result == STATE_OK && check_cert == TRUE) {
+                       result = np_net_ssl_check_cert(days_till_exp);
+                       if(result != STATE_OK) {
+                               printf(_("CRITICAL - Cannot retrieve server certificate.\n"));
+                       }
                }
        }
-       */
-#  endif /* USE_OPENSSL */
-#endif
-
        if(result != STATE_OK){
-#ifdef HAVE_SSL
                np_net_ssl_cleanup();
-#endif
                if(sd) close(sd);
                return result;
        }
+#endif /* HAVE_SSL */
 
        if (server_send != NULL) {              /* Something to send? */
                my_send(server_send, strlen(server_send));
@@ -256,7 +258,13 @@ main (int argc, char **argv)
        }
 
        if(flags & FLAG_VERBOSE) {
-               printf("server_expect_count: %d\n", server_expect_count);
+               if (server_send) {
+                       printf("Send string: %s\n", server_send);
+               }
+               if (server_quit) {
+                       printf("Quit string: %s\n", server_quit);
+               }
+               printf("server_expect_count: %d\n", (int)server_expect_count);
                for(i = 0; i < server_expect_count; i++)
                        printf("\t%d: %s\n", i, server_expect[i]);
        }
@@ -288,25 +296,15 @@ main (int argc, char **argv)
                /* print raw output if we're debugging */
                if(flags & FLAG_VERBOSE)
                        printf("received %d bytes from host\n#-raw-recv-------#\n%s\n#-raw-recv-------#\n",
-                              len + 1, status);
+                              (int)len + 1, status);
                while(isspace(status[len])) status[len--] = '\0';
 
-               for (i = 0; i < server_expect_count; i++) {
-                       match = -2;             /* tag it so we know if we tried and failed */
-                       if (flags & FLAG_VERBOSE)
-                               printf ("looking for [%s] %s [%s]\n", server_expect[i],
-                                       (flags & FLAG_EXACT_MATCH) ? "in beginning of" : "anywhere in",
-                                       status);
-
-                       /* match it. math first in short-circuit */
-                       if ((flags & FLAG_EXACT_MATCH && !strncmp(status, server_expect[i], strlen(server_expect[i]))) ||
-                           (!(flags & FLAG_EXACT_MATCH) && strstr(status, server_expect[i])))
-                       {
-                               if(flags & FLAG_VERBOSE) puts("found it");
-                               match = i;
-                               break;
-                       }
-               }
+               match = np_expect_match(status,
+                                server_expect,
+                                server_expect_count,
+                                (flags & FLAG_MATCH_ALL ? TRUE : FALSE),
+                                (flags & FLAG_EXACT_MATCH ? TRUE : FALSE),
+                                (flags & FLAG_VERBOSE ? TRUE : FALSE));
        }
 
        if (server_quit != NULL) {
@@ -314,7 +312,7 @@ main (int argc, char **argv)
        }
 #ifdef HAVE_SSL
        np_net_ssl_cleanup();
-#endif 
+#endif
        if (sd) close (sd);
 
        microsec = deltime (tv);
@@ -326,8 +324,8 @@ main (int argc, char **argv)
                result = STATE_WARNING;
 
        /* did we get the response we hoped? */
-       if(match == -2 && result != STATE_CRITICAL)
-               result = STATE_WARNING;
+       if(match == FALSE && result != STATE_CRITICAL)
+               result = expect_mismatch_state;
 
        /* reset the alarm */
        alarm (0);
@@ -335,29 +333,43 @@ main (int argc, char **argv)
        /* this is a bit stupid, because we don't want to print the
         * response time (which can look ok to the user) if we didn't get
         * the response we were looking for. if-else */
-       printf(_("%s %s - "), SERVICE, state_text(result));
-
-       if(match == -2 && len && !(flags & FLAG_HIDE_OUTPUT))
-               printf("Unexpected response from host: %s", status);
-       else
-               printf("%.3f second response time on port %d",
-                      elapsed_time, server_port);
+       printf("%s %s - ", SERVICE, state_text(result));
+
+       if(match == FALSE && len && !(flags & FLAG_HIDE_OUTPUT))
+               printf("Unexpected response from host/socket: %s", status);
+       else {
+               if(match == FALSE)
+                       printf("Unexpected response from host/socket on ");
+               else
+                       printf("%.3f second response time on ", elapsed_time);
+               if(server_address[0] != '/')
+                       printf("port %d", server_port);
+               else
+                       printf("socket %s", server_address);
+       }
 
-       if (match != -2 && !(flags & FLAG_HIDE_OUTPUT) && len)
+       if (match != FALSE && !(flags & FLAG_HIDE_OUTPUT) && len)
                printf (" [%s]", status);
 
        /* perf-data doesn't apply when server doesn't talk properly,
-        * so print all zeroes on warn and crit */
-       if(match == -2)
-               printf ("|time=%fs;0.0;0.0;0.0;0.0", elapsed_time);
+        * so print all zeroes on warn and crit. Use fperfdata since
+        * localisation settings can make different outputs */
+       if(match == FALSE)
+               printf ("|%s",
+                               fperfdata ("time", elapsed_time, "s",
+                               (flags & FLAG_TIME_WARN ? TRUE : FALSE), 0,
+                               (flags & FLAG_TIME_CRIT ? TRUE : FALSE), 0,
+                               TRUE, 0,
+                               TRUE, socket_timeout)
+                       );
        else
                printf("|%s",
                                fperfdata ("time", elapsed_time, "s",
-                                  TRUE, warning_time,
-                                  TRUE, critical_time,
-                                  TRUE, 0,
-                                  TRUE, socket_timeout)
-                     );
+                               (flags & FLAG_TIME_WARN ? TRUE : FALSE), warning_time,
+                               (flags & FLAG_TIME_CRIT ? TRUE : FALSE), critical_time,
+                               TRUE, 0,
+                               TRUE, socket_timeout)
+                       );
 
        putchar('\n');
        return result;
@@ -370,22 +382,25 @@ static int
 process_arguments (int argc, char **argv)
 {
        int c;
+       int escape = 0;
 
        int option = 0;
        static struct option longopts[] = {
                {"hostname", required_argument, 0, 'H'},
-               {"critical-time", required_argument, 0, 'c'},
-               {"warning-time", required_argument, 0, 'w'},
+               {"critical", required_argument, 0, 'c'},
+               {"warning", required_argument, 0, 'w'},
                {"critical-codes", required_argument, 0, 'C'},
                {"warning-codes", required_argument, 0, 'W'},
                {"timeout", required_argument, 0, 't'},
-               {"protocol", required_argument, 0, 'P'},
+               {"protocol", required_argument, 0, 'P'}, /* FIXME: Unhandled */
                {"port", required_argument, 0, 'p'},
+               {"escape", no_argument, 0, 'E'},
+               {"all", no_argument, 0, 'A'},
                {"send", required_argument, 0, 's'},
                {"expect", required_argument, 0, 'e'},
                {"maxbytes", required_argument, 0, 'm'},
                {"quit", required_argument, 0, 'q'},
-               {"jail", required_argument, 0, 'j'},
+               {"jail", no_argument, 0, 'j'},
                {"delay", required_argument, 0, 'd'},
                {"refuse", required_argument, 0, 'r'},
                {"mismatch", required_argument, 0, 'M'},
@@ -394,10 +409,8 @@ process_arguments (int argc, char **argv)
                {"verbose", no_argument, 0, 'v'},
                {"version", no_argument, 0, 'V'},
                {"help", no_argument, 0, 'h'},
-#ifdef HAVE_SSL
                {"ssl", no_argument, 0, 'S'},
                {"certificate", required_argument, 0, 'D'},
-#endif
                {0, 0, 0, 0}
        };
 
@@ -422,7 +435,7 @@ process_arguments (int argc, char **argv)
        }
 
        while (1) {
-               c = getopt_long (argc, argv, "+hVv46H:s:e:q:m:c:w:t:p:C:W:d:Sr:jD:M:",
+               c = getopt_long (argc, argv, "+hVv46EAH:s:e:q:m:c:w:t:p:C:W:d:Sr:jD:M:",
                                 longopts, &option);
 
                if (c == -1 || c == EOF || c == 1)
@@ -430,12 +443,12 @@ process_arguments (int argc, char **argv)
 
                switch (c) {
                case '?':                 /* print short usage statement if args not parsable */
-                       usage2 (_("Unknown argument"), optarg);
+                       usage5 ();
                case 'h':                 /* help */
                        print_help ();
                        exit (STATE_OK);
                case 'V':                 /* version */
-                       print_revision (progname, revision);
+                       print_revision (progname, NP_VERSION);
                        exit (STATE_OK);
                case 'v':                 /* verbose mode */
                        flags |= FLAG_VERBOSE;
@@ -451,25 +464,17 @@ process_arguments (int argc, char **argv)
 #endif
                        break;
                case 'H':                 /* hostname */
-                       if (is_host (optarg) == FALSE)
-                               usage2 (_("Invalid hostname/address"), optarg);
                        server_address = optarg;
                        break;
                case 'c':                 /* critical */
-                       if (!is_intnonneg (optarg))
-                               usage4 (_("Critical threshold must be a positive integer"));
-                       else
-                               critical_time = strtod (optarg, NULL);
+                       critical_time = strtod (optarg, NULL);
                        flags |= FLAG_TIME_CRIT;
                        break;
                case 'j':                 /* hide output */
                        flags |= FLAG_HIDE_OUTPUT;
                        break;
                case 'w':                 /* warning */
-                       if (!is_intnonneg (optarg))
-                               usage4 (_("Warning threshold must be a positive integer"));
-                       else
-                               warning_time = strtod (optarg, NULL);
+                       warning_time = strtod (optarg, NULL);
                        flags |= FLAG_TIME_WARN;
                        break;
                case 'C':
@@ -492,11 +497,16 @@ process_arguments (int argc, char **argv)
                        else
                                server_port = atoi (optarg);
                        break;
+               case 'E':
+                       escape = 1;
+                       break;
                case 's':
-                       server_send = optarg;
+                       if (escape)
+                               server_send = np_escaped_string(optarg);
+                       else
+                               asprintf(&server_send, "%s", optarg);
                        break;
                case 'e': /* expect string (may be repeated) */
-                       EXPECT = NULL;
                        flags &= ~FLAG_EXACT_MATCH;
                        if (server_expect_count == 0)
                                server_expect = malloc (sizeof (char *) * (++server_expect_count));
@@ -509,8 +519,12 @@ process_arguments (int argc, char **argv)
                                usage4 (_("Maxbytes must be a positive integer"));
                        else
                                maxbytes = strtol (optarg, NULL, 0);
+                       break;
                case 'q':
-                       asprintf(&server_quit, "%s\r\n", optarg);
+                       if (escape)
+                               server_quit = np_escaped_string(optarg);
+                       else
+                               asprintf(&server_quit, "%s\r\n", optarg);
                        break;
                case 'r':
                        if (!strncmp(optarg,"ok",2))
@@ -557,161 +571,87 @@ process_arguments (int argc, char **argv)
                        die (STATE_UNKNOWN, _("Invalid option - SSL is not available"));
 #endif
                        break;
+               case 'A':
+                       flags |= FLAG_MATCH_ALL;
+                       break;
                }
        }
 
        if (server_address == NULL)
                usage4 (_("You must provide a server address"));
+       else if (server_address[0] != '/' && is_host (server_address) == FALSE)
+               die (STATE_CRITICAL, "%s %s - %s: %s\n", SERVICE, state_text(STATE_CRITICAL), _("Invalid hostname, address or socket"), server_address);
 
        return TRUE;
 }
 
 
-/* SSL-specific functions */
-#ifdef HAVE_SSL
-#  ifdef USE_OPENSSL /* XXX */
-static int
-check_certificate (X509 ** certificate)
-{
-  ASN1_STRING *tm;
-  int offset;
-  struct tm stamp;
-  int days_left;
-
-
-  /* Retrieve timestamp of certificate */
-  tm = X509_get_notAfter (*certificate);
-
-  /* Generate tm structure to process timestamp */
-  if (tm->type == V_ASN1_UTCTIME) {
-    if (tm->length < 10) {
-      printf (_("CRITICAL - Wrong time format in certificate.\n"));
-      return STATE_CRITICAL;
-    }
-    else {
-      stamp.tm_year = (tm->data[0] - '0') * 10 + (tm->data[1] - '0');
-      if (stamp.tm_year < 50)
-       stamp.tm_year += 100;
-      offset = 0;
-    }
-  }
-  else {
-    if (tm->length < 12) {
-      printf (_("CRITICAL - Wrong time format in certificate.\n"));
-      return STATE_CRITICAL;
-    }
-    else {
-                        stamp.tm_year =
-                         (tm->data[0] - '0') * 1000 + (tm->data[1] - '0') * 100 +
-                         (tm->data[2] - '0') * 10 + (tm->data[3] - '0');
-                        stamp.tm_year -= 1900;
-                        offset = 2;
-    }
-  }
-        stamp.tm_mon =
-         (tm->data[2 + offset] - '0') * 10 + (tm->data[3 + offset] - '0') - 1;
-        stamp.tm_mday =
-         (tm->data[4 + offset] - '0') * 10 + (tm->data[5 + offset] - '0');
-        stamp.tm_hour =
-         (tm->data[6 + offset] - '0') * 10 + (tm->data[7 + offset] - '0');
-        stamp.tm_min =
-         (tm->data[8 + offset] - '0') * 10 + (tm->data[9 + offset] - '0');
-        stamp.tm_sec = 0;
-        stamp.tm_isdst = -1;
-
-        days_left = (mktime (&stamp) - time (NULL)) / 86400;
-        snprintf
-         (timestamp, 16, "%02d/%02d/%04d %02d:%02d",
-          stamp.tm_mon + 1,
-          stamp.tm_mday, stamp.tm_year + 1900, stamp.tm_hour, stamp.tm_min);
-
-        if (days_left > 0 && days_left <= days_till_exp) {
-         printf (_("Certificate expires in %d day(s) (%s).\n"), days_left, timestamp);
-         return STATE_WARNING;
-        }
-        if (days_left < 0) {
-         printf (_("Certificate expired on %s.\n"), timestamp);
-         return STATE_CRITICAL;
-        }
-
-        if (days_left == 0) {
-         printf (_("Certificate expires today (%s).\n"), timestamp);
-         return STATE_WARNING;
-        }
-
-        printf (_("Certificate will expire on %s.\n"), timestamp);
-
-        return STATE_OK;
-}
-#  endif /* USE_OPENSSL */
-#endif /* HAVE_SSL */
-
-
 void
 print_help (void)
 {
-       print_revision (progname, revision);
+       print_revision (progname, NP_VERSION);
 
        printf ("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n");
        printf (COPYRIGHT, copyright, email);
 
-       printf (_("This plugin tests %s connections with the specified host.\n\n"),
+       printf (_("This plugin tests %s connections with the specified host (or unix socket).\n\n"),
                SERVICE);
 
        print_usage ();
 
-       printf (_(UT_HELP_VRSN));
-
-       printf (_(UT_HOST_PORT), 'p', "none");
-
-       printf (_(UT_IPv46));
-
-       printf (_("\
- -s, --send=STRING\n\
-    String to send to the server\n\
- -e, --expect=STRING\n\
-    String to expect in server response\n\
- -q, --quit=STRING\n\
-    String to send server to initiate a clean close of the connection\n"));
-
-       printf (_("\
- -r, --refuse=ok|warn|crit\n\
-    Accept tcp refusals with states ok, warn, crit (default: crit)\n\
- -M, --mismatch=ok|warn|crit\n\
-    Accept expected string mismatches with states ok, warn, crit (default: warn)\n\
- -j, --jail\n\
-    Hide output from TCP socket\n\
- -m, --maxbytes=INTEGER\n\
-    Close connection once more than this number of bytes are received\n\
- -d, --delay=INTEGER\n\
-    Seconds to wait between sending string and polling for response\n"));
+       printf (UT_HELP_VRSN);
+       printf (UT_EXTRA_OPTS);
+
+       printf (UT_HOST_PORT, 'p', "none");
+
+       printf (UT_IPv46);
+
+       printf (" %s\n", "-E, --escape");
+  printf ("    %s\n", _("Can use \\n, \\r, \\t or \\ in send or quit string. Must come before send or quit option"));
+  printf ("    %s\n", _("Default: nothing added to send, \\r\\n added to end of quit"));
+  printf (" %s\n", "-s, --send=STRING");
+  printf ("    %s\n", _("String to send to the server"));
+  printf (" %s\n", "-e, --expect=STRING");
+  printf ("    %s %s\n", _("String to expect in server response"), _("(may be repeated)"));
+  printf (" %s\n", "-A, --all");
+  printf ("    %s\n", _("All expect strings need to occur in server response. Default is any"));
+  printf (" %s\n", "-q, --quit=STRING");
+  printf ("    %s\n", _("String to send server to initiate a clean close of the connection"));
+  printf (" %s\n", "-r, --refuse=ok|warn|crit");
+  printf ("    %s\n", _("Accept TCP refusals with states ok, warn, crit (default: crit)"));
+  printf (" %s\n", "-M, --mismatch=ok|warn|crit");
+  printf ("    %s\n", _("Accept expected string mismatches with states ok, warn, crit (default: warn)"));
+  printf (" %s\n", "-j, --jail");
+  printf ("    %s\n", _("Hide output from TCP socket"));
+  printf (" %s\n", "-m, --maxbytes=INTEGER");
+  printf ("    %s\n", _("Close connection once more than this number of bytes are received"));
+  printf (" %s\n", "-d, --delay=INTEGER");
+  printf ("    %s\n", _("Seconds to wait between sending string and polling for response"));
 
 #ifdef HAVE_SSL
-       printf (_("\
- -D, --certificate=INTEGER\n\
-    Minimum number of days a certificate has to be valid.\n\
- -S, --ssl\n\
-    Use SSL for the connection.\n"));
+       printf (" %s\n", "-D, --certificate=INTEGER");
+  printf ("    %s\n", _("Minimum number of days a certificate has to be valid."));
+  printf (" %s\n", "-S, --ssl");
+  printf ("    %s\n", _("Use SSL for the connection."));
 #endif
 
-       printf (_(UT_WARN_CRIT));
+       printf (UT_WARN_CRIT);
 
-       printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
+       printf (UT_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
 
-       printf (_(UT_VERBOSE));
+       printf (UT_VERBOSE);
 
-       printf (_(UT_SUPPORT));
+       printf (UT_SUPPORT);
 }
 
 
 void
 print_usage (void)
 {
-       printf ("\
-Usage: %s -H host -p port [-w <warning time>] [-c <critical time>]\n\
-                  [-s <send string>] [-e <expect string>] [-q <quit string>]\n\
-                  [-m <maximum bytes>] [-d <delay>] [-t <timeout seconds>]\n\
-                  [-r <refuse state>] [-M <mismatch state>] [-v] [-4|-6] [-j]\n\
-                  [-D <days to cert expiry>] [-S <use SSL>]\n", progname);
+       printf ("%s\n", _("Usage:"));
+  printf ("%s -H host -p port [-w <warning time>] [-c <critical time>] [-s <send string>]\n",progname);
+  printf ("[-e <expect string>] [-q <quit string>][-m <maximum bytes>] [-d <delay>]\n");
+  printf ("[-t <timeout seconds>] [-r <refuse state>] [-M <mismatch state>] [-v] [-4|-6] [-j]\n");
+  printf ("[-D <days to cert expiry>] [-S <use SSL>] [-E]\n");
 }