X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=plugins%2Fcheck_tcp.c;h=178bd5688dec52abeeb72667b595ba7c65709ab5;hb=0aa751937455c4af4e49ccf6ba469c0b4ca8a4d0;hp=d8fc26e7d3e7aee3f273c3f536ac0c8b27111ccf;hpb=8c3e7428ae21999e813b288c3d55d3870c9ef258;p=nagiosplug.git
diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c
index d8fc26e..178bd56 100644
--- a/plugins/check_tcp.c
+++ b/plugins/check_tcp.c
@@ -1,32 +1,41 @@
/*****************************************************************************
-
- 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 .
+*
+* $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;
@@ -54,8 +63,6 @@ static int server_port = 0;
static char *server_address = NULL;
static char *server_send = NULL;
static char *server_quit = NULL;
-char *lineend = "";
-char *lineendquit = "\r\n";
static char **server_expect;
static size_t server_expect_count = 0;
static size_t maxbytes = 0;
@@ -79,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
@@ -88,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);
@@ -101,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]);
}
@@ -155,9 +164,9 @@ main (int argc, char **argv)
}
else if (!strncmp(SERVICE, "JABBER", 6)) {
SEND = "\n";
- EXPECT = "\n");
printf (COPYRIGHT, copyright, email);
@@ -597,62 +599,59 @@ print_help (void)
print_usage ();
- printf (_(UT_HELP_VRSN));
-
- printf (_(UT_HOST_PORT), 'p', "none");
-
- printf (_(UT_IPv46));
-
- printf (_("\
- -l, --lineend=b|e|n|r\n\
- Ending on -s and -q strings. b - both: style, e - empty no\n\
- end, n - newline: newline end, r - return: carriage return end\n\
- Default is \"-l e -s -l b -q \".\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"));
-
- 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 ] [-c ]\n\
- [-s ] [-e ] [-q ]\n\
- [-m ] [-d ] [-t ]\n\
- [-r ] [-M ] [-v] [-4|-6] [-j]\n\
- [-D ] [-S