summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 0a73efe)
raw | patch | inline | side by side (parent: 0a73efe)
author | Matthias Eble <psychotrahe@users.sourceforge.net> | |
Sun, 3 Jun 2007 14:40:13 +0000 (14:40 +0000) | ||
committer | Matthias Eble <psychotrahe@users.sourceforge.net> | |
Sun, 3 Jun 2007 14:40:13 +0000 (14:40 +0000) |
Added -A/--all flag to test for every expect string passed.
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1729 f882894a-f735-0410-b71e-b25c423dba1c
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1729 f882894a-f735-0410-b71e-b25c423dba1c
NEWS | patch | blob | history | |
lib/Makefile.am | patch | blob | history | |
lib/utils_tcp.c | [new file with mode: 0644] | patch | blob |
lib/utils_tcp.h | [new file with mode: 0644] | patch | blob |
plugins/check_tcp.c | patch | blob | history |
index 0664fa91809b80b3825b34293d4bdff1a5148684..4d3a0d91a481546f35518eeb5e3dad20585d4430 100644 (file)
--- a/NEWS
+++ b/NEWS
Make check_http output more consistent
Fix possible check_http segfaults when following HTTP redirects
check_snmp don't warn anymore if something is printed on stderr
+ Fix check_tcp segfault when multiple expect strings are given
+ New option for check_tcp: -A/--all to test if all given expect strings match
1.4.8 11th April 2007
Respects --without-world-permissions for setuid plugins
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 3909bb9bf0a54fc307988d9800d4c7827f028efb..5d0f6352a3f1b4c964be466014de5fdf5d976c0b 100644 (file)
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
noinst_LIBRARIES = libnagiosplug.a
-libnagiosplug_a_SOURCES = utils_base.c utils_disk.c
-EXTRA_DIST = utils_base.h utils_disk.h
+libnagiosplug_a_SOURCES = utils_base.c utils_disk.c utils_tcp.c
+EXTRA_DIST = utils_base.h utils_disk.h utils_tcp.h
INCLUDES = -I$(srcdir) -I$(top_srcdir)/gl -I$(top_srcdir)/intl -I$(top_srcdir)/plugins
diff --git a/lib/utils_tcp.c b/lib/utils_tcp.c
--- /dev/null
+++ b/lib/utils_tcp.c
@@ -0,0 +1,60 @@
+/****************************************************************************
+* Utils for check_tcp
+*
+* License: GPL
+* Copyright (c) 1999-2007 nagios-plugins team
+*
+* Last Modified: $Date$
+*
+* Description:
+*
+* This file contains utilities for check_tcp. These are tested by libtap
+*
+* License Information:
+*
+* 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$
+*
+*****************************************************************************/
+
+#include "common.h"
+#include "utils_tcp.h"
+
+int
+np_expect_match(char* status, char** server_expect, int expect_count, int all, int exact_match, int verbose)
+{
+ int match = 0;
+ int i;
+ for (i = 0; i < expect_count; i++) {
+ if (verbose)
+ printf ("looking for [%s] %s [%s]\n", server_expect[i],
+ (exact_match) ? "in beginning of" : "anywhere in",
+ status);
+
+ if ((exact_match && !strncmp(status, server_expect[i], strlen(server_expect[i]))) ||
+ (! exact_match && strstr(status, server_expect[i])))
+ {
+ if(verbose) puts("found it");
+ match += 1;
+ } else
+ if(verbose) puts("couldn't find it");
+ }
+ if ((all == true && match == expect_count) ||
+ (! all && match >= 1)) {
+ return true;
+ } else
+ return false;
+}
diff --git a/lib/utils_tcp.h b/lib/utils_tcp.h
--- /dev/null
+++ b/lib/utils_tcp.h
@@ -0,0 +1,4 @@
+/* Header file for utils_disk */
+
+int np_expect_match(char* status, char** server_expect, int server_expect_count,
+ int all, int exact_match, int verbose);
diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c
index 315c75255ccb16e2ed490f621d6b74cae3525256..e502c0d1e52eacbe2f021478413a4602e8ef045d 100644 (file)
--- a/plugins/check_tcp.c
+++ b/plugins/check_tcp.c
#include "common.h"
#include "netutils.h"
#include "utils.h"
+#include "utils_tcp.h"
#ifdef HAVE_SSL
static int check_cert = FALSE;
#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
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);
(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) {
result = STATE_WARNING;
/* did we get the response we hoped? */
- if(match == -2 && result != STATE_CRITICAL)
+ if(match == FALSE && result != STATE_CRITICAL)
result = expect_mismatch_state;
/* reset the alarm */
* the response we were looking for. if-else */
printf("%s %s - ", SERVICE, state_text(result));
- if(match == -2 && len && !(flags & FLAG_HIDE_OUTPUT))
+ if(match == FALSE && len && !(flags & FLAG_HIDE_OUTPUT))
printf("Unexpected response from host/socket: %s", status);
else {
- if(match == -2)
+ if(match == FALSE)
printf("Unexpected response from host/socket on ");
else
printf("%.3f second response time on ", elapsed_time);
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. Use fperfdata since
* localisation settings can make different outputs */
- if(match == -2)
+ if(match == FALSE)
printf ("|%s",
fperfdata ("time", elapsed_time, "s",
(flags & FLAG_TIME_WARN ? TRUE : FALSE), 0,
{"protocol", required_argument, 0, 'P'},
{"port", required_argument, 0, 'p'},
{"escape", required_argument, 0, 'E'},
+ {"all", required_argument, 0, 'A'},
{"send", required_argument, 0, 's'},
{"expect", required_argument, 0, 'e'},
{"maxbytes", required_argument, 0, 'm'},
}
while (1) {
- c = getopt_long (argc, argv, "+hVv46EH: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)
die (STATE_UNKNOWN, _("Invalid option - SSL is not available"));
#endif
break;
+ case 'A':
+ flags |= FLAG_MATCH_ALL;
+ break;
}
}
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", "-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)"));