4
0
Эх сурвалжийг харах

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
Karl DeBisschop 23 жил өмнө
parent
commit
68544fbb90
1 өөрчлөгдсөн 30 нэмэгдсэн , 16 устгасан
  1. 30 16
      plugins/check_http.c

+ 30 - 16
plugins/check_http.c

@@ -44,7 +44,7 @@ certificate expiration times.\n"
 \(-H <vhost> | -I <IP-address>) [-u <uri>] [-p <port>]\n\
 \(-H <vhost> | -I <IP-address>) [-u <uri>] [-p <port>]\n\
             [-w <warn time>] [-c <critical time>] [-t <timeout>] [-L]\n\
             [-w <warn time>] [-c <critical time>] [-t <timeout>] [-L]\n\
             [-a auth] [-f <ok | warn | critcal | follow>] [-e <expect>]\n\
             [-a auth] [-f <ok | warn | critcal | follow>] [-e <expect>]\n\
-            [-s string] [-r <regex> | -R <case-insensitive regex>]\n\
+            [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]\n\
             [-P string]"
             [-P string]"
 
 
 #define LONGOPTIONS "\
 #define LONGOPTIONS "\
@@ -74,7 +74,7 @@ certificate expiration times.\n"
  -L, --link=URL\n\
  -L, --link=URL\n\
    Wrap output in HTML link (obsoleted by urlize)\n\
    Wrap output in HTML link (obsoleted by urlize)\n\
  -f, --onredirect=<ok|warning|critical|follow>\n\
  -f, --onredirect=<ok|warning|critical|follow>\n\
-   How to handle redirected pages\n%s\
+   How to handle redirected pages\n%s%s\
  -v, --verbose\n\
  -v, --verbose\n\
     Show details for command-line debugging (do not use with nagios server)\n\
     Show details for command-line debugging (do not use with nagios server)\n\
  -h, --help\n\
  -h, --help\n\
@@ -93,6 +93,18 @@ certificate expiration times.\n"
 #define SSLOPTIONS ""
 #define SSLOPTIONS ""
 #endif
 #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 "\
 #define DESCRIPTION "\
 This plugin will attempt to open an HTTP connection with the host. Successul\n\
 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\
 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'},
 		{"regex", required_argument, 0, 'r'},
 		{"ereg", required_argument, 0, 'r'},
 		{"ereg", required_argument, 0, 'r'},
 		{"eregi", required_argument, 0, 'R'},
 		{"eregi", required_argument, 0, 'R'},
+ 		{"linespan", no_argument, 0, 'l'},
 		{"onredirect", required_argument, 0, 'f'},
 		{"onredirect", required_argument, 0, 'f'},
 		{"certificate", required_argument, 0, 'C'},
 		{"certificate", required_argument, 0, 'C'},
 		{0, 0, 0, 0}
 		{0, 0, 0, 0}
@@ -308,7 +321,7 @@ process_arguments (int argc, char **argv)
 			strcpy (argv[c], "-n");
 			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) {
 	while (1) {
 #ifdef HAVE_GETOPT_H
 #ifdef HAVE_GETOPT_H
@@ -420,15 +433,19 @@ process_arguments (int argc, char **argv)
 			server_expect[MAX_INPUT_BUFFER - 1] = 0;
 			server_expect[MAX_INPUT_BUFFER - 1] = 0;
 			server_expect_yn = 1;
 			server_expect_yn = 1;
 			break;
 			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");
 			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 */
 		case 'r': /* regex */
-#ifdef HAVE_REGEX_H
-			cflags |= REG_EXTENDED | REG_NOSUB | REG_NEWLINE;
 			strncpy (regexp, optarg, MAX_RE_SIZE - 1);
 			strncpy (regexp, optarg, MAX_RE_SIZE - 1);
 			regexp[MAX_RE_SIZE - 1] = 0;
 			regexp[MAX_RE_SIZE - 1] = 0;
 			errcode = regcomp (&preg, regexp, cflags);
 			errcode = regcomp (&preg, regexp, cflags);
@@ -437,10 +454,8 @@ process_arguments (int argc, char **argv)
 				printf ("Could Not Compile Regular Expression: %s", errbuf);
 				printf ("Could Not Compile Regular Expression: %s", errbuf);
 				return ERROR;
 				return ERROR;
 			}
 			}
-#else
-			usage ("check_http: call for regex which was not a compiled option\n");
-#endif
 			break;
 			break;
+#endif
 		case 'v': /* verbose */
 		case 'v': /* verbose */
 			verbose = TRUE;
 			verbose = TRUE;
 			break;
 			break;
@@ -449,8 +464,7 @@ process_arguments (int argc, char **argv)
 
 
 	c = optind;
 	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++]);
 		host_name = strscpy (NULL, argv[c++]);
 	}
 	}
 
 
@@ -1065,7 +1079,7 @@ print_help (void)
 	print_usage ();
 	print_usage ();
 	printf ("NOTE: One or both of -H and -I must be specified\n");
 	printf ("NOTE: One or both of -H and -I must be specified\n");
 	printf ("\nOptions:\n" LONGOPTIONS "\n", HTTP_EXPECT, HTTP_PORT,
 	printf ("\nOptions:\n" LONGOPTIONS "\n", HTTP_EXPECT, HTTP_PORT,
-	        DEFAULT_SOCKET_TIMEOUT, SSLOPTIONS);
+	        DEFAULT_SOCKET_TIMEOUT, SSLOPTIONS, REGOPTIONS);
 #ifdef HAVE_SSL
 #ifdef HAVE_SSL
 	printf (SSLDESCRIPTION);
 	printf (SSLDESCRIPTION);
 #endif
 #endif