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/utils_tcp.c | |
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/utils_tcp.c')
-rw-r--r-- | lib/utils_tcp.c | 60 |
1 files changed, 60 insertions, 0 deletions
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 @@ +/**************************************************************************** +* 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; +} |