diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c
index ce4fd31fda539c71c2f75dfe9c94220e198d48fe..a660649cbedc21419beb8fcae0913062a2e366bb 100644 (file)
--- a/plugins/check_tcp.c
+++ b/plugins/check_tcp.c
/*****************************************************************************
-*
-* 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.
-*
+
+ 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.
+
*****************************************************************************/
-/* progname changes depending on symlink called */
-char *progname = "check_tcp";
+/* progname "check_tcp" changes depending on symlink called */
+char *progname;
const char *revision = "$Revision$";
-const char *copyright = "2002-2003";
-const char *authors = "Nagios Plugin Development Team";
+const char *copyright = "1999-2003";
const char *email = "nagiosplug-devel@lists.sourceforge.net";
-const char *summary = "\
-This plugin tests %s connections with the specified host.\n";
-
-const char *option_summary = "\
--H host -p port [-w warn_time] [-c crit_time] [-s send_string]\n\
- [-e expect_string] [-q quit_string] [-m maxbytes] [-d delay]\n\
- [-t to_sec] [-r refuse_state] [-v] [-4|-6]\n";
-
-const char *options = "\
- -H, --hostname=ADDRESS\n\
- Host name argument for servers using host headers (use numeric\n\
- address if possible to bypass DNS lookup).\n\
- -p, --port=INTEGER\n\
- Port number\n\
- -4, --use-ipv4\n\
- Use IPv4 connection\n\
- -6, --use-ipv6\n\
- Use IPv6 connection\n\
- -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\
- -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\
- -w, --warning=DOUBLE\n\
- Response time to result in warning status (seconds)\n\
- -c, --critical=DOUBLE\n\
- Response time to result in critical status (seconds)\n\
- -t, --timeout=INTEGER\n\
- Seconds before connection times out (default: %d)\n\
- -r, --refuse=ok|warn|crit\n\
- Accept tcp refusals with states ok, warn, crit (default: crit)\n\
- -v, --verbose\n\
- Show details for command-line debugging (Nagios may truncate output)\n";
-
-const char *standard_options = "\
- -h, --help\n\
- Print detailed help screen\n\
- -V, --version\n\
- Print version information\n\n";
-
-#include "config.h"
#include "common.h"
#include "netutils.h"
#include "utils.h"
};
int process_arguments (int, char **);
-void print_usage (void);
-void print_help (void);
int my_recv (void);
+void print_help (void);
+void print_usage (void);
char *SERVICE = NULL;
char *SEND = NULL;
char *server_send = NULL;
char *server_quit = NULL;
char **server_expect = NULL;
-int server_expect_count = 0;
+size_t server_expect_count = 0;
int maxbytes = 0;
char **warn_codes = NULL;
-int warn_codes_count = 0;
+size_t warn_codes_count = 0;
char **crit_codes = NULL;
-int crit_codes_count = 0;
-int delay = 0;
+size_t crit_codes_count = 0;
+unsigned int delay = 0;
double warning_time = 0;
int check_warning_time = FALSE;
double critical_time = 0;
int check_critical_time = FALSE;
double elapsed_time = 0;
+long microsec;
int verbose = FALSE;
int use_ssl = FALSE;
int sd = 0;
-char *buffer = "";
+char *buffer;
+
+
+
+
+\f
int
main (int argc, char **argv)
{
int result;
int i;
- char *status = "";
+ char *status;
struct timeval tv;
+ setlocale (LC_ALL, "");
+ bindtextdomain (PACKAGE, LOCALEDIR);
+ textdomain (PACKAGE);
+
if (strstr (argv[0], "check_udp")) {
progname = strdup ("check_udp");
SERVICE = strdup ("UDP");
PORT = 119;
}
else {
- usage ("ERROR: Generic check_tcp called with unknown service\n");
+ progname = strdup ("check_tcp");
+ usage (_("ERROR: Generic check_tcp called with unknown service\n"));
}
server_address = strdup ("127.0.0.1");
server_quit = QUIT;
if (process_arguments (argc, argv) == ERROR)
- usage ("Could not parse arguments\n");
+ usage (_("Could not parse arguments\n"));
/* use default expect if none listed in process_arguments() */
if (EXPECT && server_expect_count == 0) {
asprintf (&server_send, "%s\r\n", server_send);
#ifdef HAVE_SSL
if (use_ssl)
- SSL_write(ssl, server_send, strlen (server_send));
+ SSL_write(ssl, server_send, (int)strlen(server_send));
else
#endif
- send (sd, server_send, strlen (server_send), 0);
+ send (sd, server_send, strlen(server_send), 0);
}
if (delay > 0) {
buffer = malloc (MAXBUF);
memset (buffer, '\0', MAXBUF);
+ status = strdup ("");
/* watch for the expect string */
while ((i = my_recv ()) > 0) {
buffer[i] = '\0';
asprintf (&status, "%s%s", status, buffer);
if (buffer[i-2] == '\r' && buffer[i-1] == '\n')
break;
- if (maxbytes>0 && strlen(status)>=maxbytes)
+ if (maxbytes>0 && strlen(status) >= (unsigned)maxbytes)
break;
}
/* return a CRITICAL status if we couldn't read any data */
if (status == NULL)
- terminate (STATE_CRITICAL, "No data received from host\n");
+ die (STATE_CRITICAL, _("No data received from host\n"));
strip (status);
if (server_expect_count > 0) {
for (i = 0;; i++) {
if (verbose)
- printf ("%d %d\n", i, server_expect_count);
- if (i >= server_expect_count)
- terminate (STATE_WARNING, "Invalid response from host\n");
+ printf ("%d %d\n", i, (int)server_expect_count);
+ if (i >= (int)server_expect_count)
+ die (STATE_WARNING, _("Invalid response from host\n"));
if (strstr (status, server_expect[i]))
break;
}
if (server_quit != NULL) {
#ifdef HAVE_SSL
if (use_ssl) {
- SSL_write (ssl, server_quit, strlen (server_quit));
+ SSL_write (ssl, server_quit, (int)strlen(server_quit));
SSL_shutdown (ssl);
SSL_free (ssl);
SSL_CTX_free (ctx);
if (sd)
close (sd);
- elapsed_time = delta_time (tv);
+ microsec = deltime (tv);
+ elapsed_time = (double)microsec / 1.0e6;
if (check_critical_time == TRUE && elapsed_time > critical_time)
result = STATE_CRITICAL;
alarm (0);
printf
- ("%s %s%s - %.3f second response time on port %d",
+ (_("%s %s%s - %.3f second response time on port %d"),
SERVICE,
state_text (result),
(was_refused) ? " (refused)" : "",
if (status && strlen(status) > 0)
printf (" [%s]", status);
- printf ("|time=%.3f\n", elapsed_time);
+ printf ("|time=%ldus\n", microsec);
return result;
}
{
int c;
- int option_index = 0;
- static struct option long_options[] = {
+ int option = 0;
+ static struct option longopts[] = {
{"hostname", required_argument, 0, 'H'},
{"critical-time", required_argument, 0, 'c'},
{"warning-time", required_argument, 0, 'w'},
while (1) {
c = getopt_long (argc, argv, "+hVv46H:s:e:q:m:c:w:t:p:C:W:d:Sr:",
- long_options, &option_index);
+ longopts, &option);
if (c == -1 || c == EOF || c == 1)
break;
switch (c) {
case '?': /* print short usage statement if args not parsable */
- printf ("%s: Unknown argument: %s\n\n", progname, optarg);
+ printf (_("%s: Unknown argument: %s\n\n"), progname, optarg);
print_usage ();
exit (STATE_UNKNOWN);
case 'h': /* help */
#ifdef USE_IPV6
address_family = AF_INET6;
#else
- usage ("IPv6 support not available\n");
+ usage (_("IPv6 support not available\n"));
#endif
break;
case 'H': /* hostname */
if (is_host (optarg) == FALSE)
- usage2 ("invalid host name or address", optarg);
+ usage2 (_("invalid host name or address"), optarg);
server_address = optarg;
break;
case 'c': /* critical */
if (!is_intnonneg (optarg))
- usage ("Critical threshold must be a nonnegative integer\n");
- critical_time = strtod (optarg, NULL);
+ usage (_("Critical threshold must be a nonnegative integer\n"));
+ else
+ critical_time = strtod (optarg, NULL);
check_critical_time = TRUE;
break;
case 'w': /* warning */
if (!is_intnonneg (optarg))
- usage ("Warning threshold must be a nonnegative integer\n");
- warning_time = strtod (optarg, NULL);
+ usage (_("Warning threshold must be a nonnegative integer\n"));
+ else
+ warning_time = strtod (optarg, NULL);
check_warning_time = TRUE;
break;
case 'C':
break;
case 't': /* timeout */
if (!is_intpos (optarg))
- usage ("Timeout interval must be a positive integer\n");
- socket_timeout = atoi (optarg);
+ usage (_("Timeout interval must be a positive integer\n"));
+ else
+ socket_timeout = atoi (optarg);
break;
case 'p': /* port */
if (!is_intpos (optarg))
- usage ("Server port must be a positive integer\n");
- server_port = atoi (optarg);
+ usage (_("Server port must be a positive integer\n"));
+ else
+ server_port = atoi (optarg);
break;
case 's':
server_send = optarg;
break;
case 'm':
if (!is_intpos (optarg))
- usage ("Maxbytes must be a positive integer\n");
- maxbytes = atoi (optarg);
+ usage (_("Maxbytes must be a positive integer\n"));
+ else
+ maxbytes = atoi (optarg);
case 'q':
server_quit = optarg;
break;
else if (!strncmp(optarg,"crit",4))
econn_refuse_state = STATE_CRITICAL;
else
- usage ("Refuse mut be one of ok, warn, crit\n");
+ usage (_("Refuse mut be one of ok, warn, crit\n"));
break;
case 'd':
if (is_intpos (optarg))
delay = atoi (optarg);
else
- usage ("Delay must be a positive integer\n");
+ usage (_("Delay must be a positive integer\n"));
break;
case 'S':
#ifndef HAVE_SSL
- terminate (STATE_UNKNOWN,
- "SSL support not available. Install OpenSSL and recompile.");
+ die (STATE_UNKNOWN,
+ _("SSL support not available. Install OpenSSL and recompile."));
#endif
use_ssl = TRUE;
break;
}
if (server_address == NULL)
- usage ("You must provide a server address\n");
+ usage (_("You must provide a server address\n"));
return OK;
}
\f
-
-
-void
-print_help (void)
-{
- print_revision (progname, revision);
- printf ("Copyright (c) %s %s\n\t<%s>\n\n", copyright, authors, email);
- printf (summary, SERVICE);
- print_usage ();
- printf ("\nOptions:\n");
- printf (options, DEFAULT_SOCKET_TIMEOUT);
- printf (standard_options);
- support ();
-}
-
-void
-print_usage (void)
-{
- printf ("Usage: %s %s\n", progname, option_summary);
- printf (" %s (-h|--help)\n", progname);
- printf (" %s (-V|--version)\n", progname);
-}
-\f
-
-
-
#ifdef HAVE_SSL
int
connect_SSL (void)
SSL_load_error_strings ();
if ((ctx = SSL_CTX_new (meth)) == NULL)
{
- printf ("ERROR: Cannot create SSL context.\n");
+ printf (_("ERROR: Cannot create SSL context.\n"));
return STATE_CRITICAL;
}
}
else
{
- printf ("ERROR: Cannot initiate SSL handshake.\n");
+ printf (_("ERROR: Cannot initiate SSL handshake.\n"));
}
SSL_free (ssl);
}
return i;
}
+
+
+
+
+
+\f
+void
+print_help (void)
+{
+ print_revision (progname, revision);
+
+ 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"),
+ 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, --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_WARN_CRIT));
+
+ printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
+
+ printf (_(UT_VERBOSE));
+
+ 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>] [-v] [-4|-6]\n"), progname);
+ printf (" %s (-h|--help)\n", progname);
+ printf (" %s (-V|--version)\n", progname);
+}