[Pkg-nagios-devel] Bug#375096: check_http: invert match

Robert Millan [ackstorm] rmillan at ackstorm.es
Fri Jun 23 09:47:41 UTC 2006


Package: nagios-plugins
Severity: wishlist
Tags: patch

This patch adds an option to check_http to invert string matches (much like
grep -v).

-- 
Robert Millan
sat at ackstorm.es
Departamento de Asistencia Técnica

Oficina central: (+34) 902 888 345
Asistencia técnica: (+34) 902 888 408

ACK STORM, S.L.
http://www.ackstorm.es

Este mensaje electrónico contiene información de ACK STORM, S.L. que es privada
y confidencial, siendo para el uso exclusivo de las personas o entidades arriba
mencionadas. Si usted no es el destinatario señalado, le informamos que
cualquier divulgación, copia, distribución o uso de los contenidos está
prohibida. Si usted ha recibido este mensaje por error, por favor borre su
contenido y comuníquenoslo en la dirección ackstorm at ackstorm.es
--------------------------------------------------
-------------- next part --------------
--- ../../old/nagios-plugins-1.4.3/plugins/check_http.c	2006-04-05 09:58:27.000000000 +0200
+++ check_http.c	2006-06-23 11:45:26.000000000 +0200
@@ -49,6 +49,7 @@
 #  define my_send(buf, len) send(sd, buf, len, 0)
 #endif /* HAVE_SSL */
 int no_body = FALSE;
+int invert_match = FALSE;
 int maximum_age = -1;
 
 #ifdef HAVE_REGEX_H
@@ -174,6 +175,7 @@
     {"ereg", required_argument, 0, 'r'},
     {"eregi", required_argument, 0, 'R'},
     {"linespan", no_argument, 0, 'l'},
+    {"invert-match", no_argument, 0, 'i'},
     {"onredirect", required_argument, 0, 'f'},
     {"certificate", required_argument, 0, 'C'},
     {"useragent", required_argument, 0, 'A'},
@@ -204,7 +206,7 @@
   }
 
   while (1) {
-    c = getopt_long (argc, argv, "Vvh46t:c:w:A:k:H:P:T:I:a:e:p:s:R:r:u:f:C:nlLSm:M:N", longopts, &option);
+    c = getopt_long (argc, argv, "Vvh46t:c:w:A:k:H:P:T:I:a:e:p:s:R:r:iu:f:C:nlLSm:M:N", longopts, &option);
     if (c == -1 || c == EOF)
       break;
 
@@ -333,6 +335,9 @@
     case 'T': /* Content-type */
       asprintf (&http_content_type, "%s", optarg);
       break;
+    case 'i': /* invert-match */
+      invert_match = TRUE;
+      break;
 #ifndef HAVE_REGEX_H
     case 'l': /* linespan */
     case 'r': /* linespan */
@@ -978,7 +983,7 @@
   /* these checks should be last */
 
   if (strlen (string_expect)) {
-    if (strstr (page, string_expect)) {
+    if (strstr (page, string_expect) && !invert_match) {
       printf (_("HTTP OK %s - %.3f second response time %s%s|%s %s\n"),
               status_line, elapsed_time,
               timestamp, (display_html ? "</A>" : ""),
@@ -986,7 +991,7 @@
       exit (STATE_OK);
     }
     else {
-      printf (_("CRITICAL - string not found%s|%s %s\n"),
+      printf (invert_match ? _("CRITICAL - string found%s|%s %s\n") : _("CRITICAL - string not found%s|%s %s\n"),
               (display_html ? "</A>" : ""),
               perfd_time (elapsed_time), perfd_size (pagesize));
       exit (STATE_CRITICAL);
@@ -995,6 +1000,15 @@
 #ifdef HAVE_REGEX_H
   if (strlen (regexp)) {
     errcode = regexec (&preg, page, REGS, pmatch, 0);
+
+    if (invert_match)
+      {
+        if (errcode == 0)
+          errcode = REG_NOMATCH;
+        else if (errcode == REG_NOMATCH)
+          errcode = 0;
+      }
+
     if (errcode == 0) {
       printf (_("HTTP OK %s - %.3f second response time %s%s|%s %s\n"),
               status_line, elapsed_time,
@@ -1004,7 +1018,7 @@
     }
     else {
       if (errcode == REG_NOMATCH) {
-        printf (_("CRITICAL - pattern not found%s|%s %s\n"),
+        printf (invert_match ? _("CRITICAL - pattern found%s|%s %s\n") : _("CRITICAL - pattern not found%s|%s %s\n"),
                 (display_html ? "</A>" : ""),
                 perfd_time (elapsed_time), perfd_size (pagesize));
         exit (STATE_CRITICAL);
@@ -1268,7 +1282,9 @@
    Warn if document is more than SECONDS old. the number can also be of \n\
    the form \"10m\" for minutes, \"10h\" for hours, or \"10d\" for days.\n\
  -T, --content-type=STRING\n\
-   specify Content-Type header media type when POSTing\n"), HTTP_EXPECT);
+   specify Content-Type header media type when POSTing\n\
+ -i, --invert-match\n\
+   Select non-matching lines.\n"), HTTP_EXPECT);
 
 #ifdef HAVE_REGEX_H
   printf (_("\


More information about the Pkg-nagios-devel mailing list