From 68544fbb90b4a702de4a939d5c62055e453582c6 Mon Sep 17 00:00:00 2001 From: Karl DeBisschop Date: Thu, 16 Jan 2003 06:29:02 +0000 Subject: [PATCH] add option to let regex span newlines git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@248 f882894a-f735-0410-b71e-b25c423dba1c --- plugins/check_http.c | 46 +++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/plugins/check_http.c b/plugins/check_http.c index de7a2db..2259c6f 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c @@ -44,7 +44,7 @@ certificate expiration times.\n" \(-H | -I ) [-u ] [-p ]\n\ [-w ] [-c ] [-t ] [-L]\n\ [-a auth] [-f ] [-e ]\n\ - [-s string] [-r | -R ]\n\ + [-s string] [-l] [-r | -R ]\n\ [-P string]" #define LONGOPTIONS "\ @@ -74,7 +74,7 @@ certificate expiration times.\n" -L, --link=URL\n\ Wrap output in HTML link (obsoleted by urlize)\n\ -f, --onredirect=\n\ - How to handle redirected pages\n%s\ + How to handle redirected pages\n%s%s\ -v, --verbose\n\ Show details for command-line debugging (do not use with nagios server)\n\ -h, --help\n\ @@ -93,6 +93,18 @@ certificate expiration times.\n" #define SSLOPTIONS "" #endif +#ifdef HAVE_REGEX_H +#define REGOPTIONS "\ + -l, --linespan\n\ + Allow regex to span newlines (must precede -r or -R)\n\ + -r, --regex, --ereg=STRING\n\ + Search page for regex STRING\n\ + -R, --eregi=STRING\n\ + Search page for case-insensitive regex STRING\n" +#else +#define REGOPTIONS "" +#endif + #define DESCRIPTION "\ This plugin will attempt to open an HTTP connection with the host. Successul\n\ connects return STATE_OK, refusals and timeouts return STATE_CRITICAL, other\n\ @@ -286,6 +298,7 @@ process_arguments (int argc, char **argv) {"regex", required_argument, 0, 'r'}, {"ereg", required_argument, 0, 'r'}, {"eregi", required_argument, 0, 'R'}, + {"linespan", no_argument, 0, 'l'}, {"onredirect", required_argument, 0, 'f'}, {"certificate", required_argument, 0, 'C'}, {0, 0, 0, 0} @@ -308,7 +321,7 @@ process_arguments (int argc, char **argv) strcpy (argv[c], "-n"); } -#define OPTCHARS "Vvht:c:w:H:P:I:a:e:p:s:R:r:u:f:C:nLS" +#define OPTCHARS "Vvht:c:w:H:P:I:a:e:p:s:R:r:u:f:C:nlLS" while (1) { #ifdef HAVE_GETOPT_H @@ -420,15 +433,19 @@ process_arguments (int argc, char **argv) server_expect[MAX_INPUT_BUFFER - 1] = 0; server_expect_yn = 1; break; - case 'R': /* regex */ -#ifdef HAVE_REGEX_H - cflags = REG_ICASE; -#else +#ifndef HAVE_REGEX_H + case 'l': /* linespan */ + case 'r': /* linespan */ + case 'R': /* linespan */ usage ("check_http: call for regex which was not a compiled option\n"); -#endif + break; +#else + case 'l': /* linespan */ + cflags &= ~REG_NEWLINE; + break; + case 'R': /* regex */ + cflags |= REG_ICASE; case 'r': /* regex */ -#ifdef HAVE_REGEX_H - cflags |= REG_EXTENDED | REG_NOSUB | REG_NEWLINE; strncpy (regexp, optarg, MAX_RE_SIZE - 1); regexp[MAX_RE_SIZE - 1] = 0; errcode = regcomp (&preg, regexp, cflags); @@ -437,10 +454,8 @@ process_arguments (int argc, char **argv) printf ("Could Not Compile Regular Expression: %s", errbuf); return ERROR; } -#else - usage ("check_http: call for regex which was not a compiled option\n"); -#endif break; +#endif case 'v': /* verbose */ verbose = TRUE; break; @@ -449,8 +464,7 @@ process_arguments (int argc, char **argv) c = optind; - if (server_address == NULL && host_name == NULL) { - server_address = strscpy (NULL, argv[c]); + if (server_address == NULL && host_name == NULL) { server_address = strscpy (NULL, argv[c]); host_name = strscpy (NULL, argv[c++]); } @@ -1065,7 +1079,7 @@ print_help (void) print_usage (); printf ("NOTE: One or both of -H and -I must be specified\n"); printf ("\nOptions:\n" LONGOPTIONS "\n", HTTP_EXPECT, HTTP_PORT, - DEFAULT_SOCKET_TIMEOUT, SSLOPTIONS); + DEFAULT_SOCKET_TIMEOUT, SSLOPTIONS, REGOPTIONS); #ifdef HAVE_SSL printf (SSLDESCRIPTION); #endif -- 2.30.2