diff options
| author | Matthias Eble <psychotrahe@users.sourceforge.net> | 2007-06-03 14:40:13 +0000 |
|---|---|---|
| committer | Matthias Eble <psychotrahe@users.sourceforge.net> | 2007-06-03 14:40:13 +0000 |
| commit | d059eeb2948f9d24d801f930e99e81fdf96d5c37 (patch) | |
| tree | 472b15ce9785983d6e1389d5b16577c96c7a402f /lib | |
| parent | 0a73efe7cad3c3bfd423b65be3a3b9d3049be545 (diff) | |
| download | monitoring-plugins-d059eeb2948f9d24d801f930e99e81fdf96d5c37.tar.gz | |
Moved check_tcp's expect string testing into utils_tcp for testing purposes.
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
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/Makefile.am | 4 | ||||
| -rw-r--r-- | lib/utils_tcp.c | 60 | ||||
| -rw-r--r-- | lib/utils_tcp.h | 4 |
3 files changed, 66 insertions, 2 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am index 3909bb9b..5d0f6352 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am | |||
| @@ -5,8 +5,8 @@ SUBDIRS = tests | |||
| 5 | noinst_LIBRARIES = libnagiosplug.a | 5 | noinst_LIBRARIES = libnagiosplug.a |
| 6 | 6 | ||
| 7 | 7 | ||
| 8 | libnagiosplug_a_SOURCES = utils_base.c utils_disk.c | 8 | libnagiosplug_a_SOURCES = utils_base.c utils_disk.c utils_tcp.c |
| 9 | EXTRA_DIST = utils_base.h utils_disk.h | 9 | EXTRA_DIST = utils_base.h utils_disk.h utils_tcp.h |
| 10 | 10 | ||
| 11 | INCLUDES = -I$(srcdir) -I$(top_srcdir)/gl -I$(top_srcdir)/intl -I$(top_srcdir)/plugins | 11 | INCLUDES = -I$(srcdir) -I$(top_srcdir)/gl -I$(top_srcdir)/intl -I$(top_srcdir)/plugins |
| 12 | 12 | ||
diff --git a/lib/utils_tcp.c b/lib/utils_tcp.c new file mode 100644 index 00000000..b7075197 --- /dev/null +++ b/lib/utils_tcp.c | |||
| @@ -0,0 +1,60 @@ | |||
| 1 | /**************************************************************************** | ||
| 2 | * Utils for check_tcp | ||
| 3 | * | ||
| 4 | * License: GPL | ||
| 5 | * Copyright (c) 1999-2007 nagios-plugins team | ||
| 6 | * | ||
| 7 | * Last Modified: $Date$ | ||
| 8 | * | ||
| 9 | * Description: | ||
| 10 | * | ||
| 11 | * This file contains utilities for check_tcp. These are tested by libtap | ||
| 12 | * | ||
| 13 | * License Information: | ||
| 14 | * | ||
| 15 | * This program is free software; you can redistribute it and/or modify | ||
| 16 | * it under the terms of the GNU General Public License as published by | ||
| 17 | * the Free Software Foundation; either version 2 of the License, or | ||
| 18 | * (at your option) any later version. | ||
| 19 | * | ||
| 20 | * This program is distributed in the hope that it will be useful, | ||
| 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 23 | * GNU General Public License for more details. | ||
| 24 | * | ||
| 25 | * You should have received a copy of the GNU General Public License | ||
| 26 | * along with this program; if not, write to the Free Software | ||
| 27 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
| 28 | * | ||
| 29 | * $Id$ | ||
| 30 | * | ||
| 31 | *****************************************************************************/ | ||
| 32 | |||
| 33 | #include "common.h" | ||
| 34 | #include "utils_tcp.h" | ||
| 35 | |||
| 36 | int | ||
| 37 | np_expect_match(char* status, char** server_expect, int expect_count, int all, int exact_match, int verbose) | ||
| 38 | { | ||
| 39 | int match = 0; | ||
| 40 | int i; | ||
| 41 | for (i = 0; i < expect_count; i++) { | ||
| 42 | if (verbose) | ||
| 43 | printf ("looking for [%s] %s [%s]\n", server_expect[i], | ||
| 44 | (exact_match) ? "in beginning of" : "anywhere in", | ||
| 45 | status); | ||
| 46 | |||
| 47 | if ((exact_match && !strncmp(status, server_expect[i], strlen(server_expect[i]))) || | ||
| 48 | (! exact_match && strstr(status, server_expect[i]))) | ||
| 49 | { | ||
| 50 | if(verbose) puts("found it"); | ||
| 51 | match += 1; | ||
| 52 | } else | ||
| 53 | if(verbose) puts("couldn't find it"); | ||
| 54 | } | ||
| 55 | if ((all == true && match == expect_count) || | ||
| 56 | (! all && match >= 1)) { | ||
| 57 | return true; | ||
| 58 | } else | ||
| 59 | return false; | ||
| 60 | } | ||
diff --git a/lib/utils_tcp.h b/lib/utils_tcp.h new file mode 100644 index 00000000..06506f32 --- /dev/null +++ b/lib/utils_tcp.h | |||
| @@ -0,0 +1,4 @@ | |||
| 1 | /* Header file for utils_disk */ | ||
| 2 | |||
| 3 | int np_expect_match(char* status, char** server_expect, int server_expect_count, | ||
| 4 | int all, int exact_match, int verbose); | ||
