فهرست منبع

fix: added exact match argument to check_dig, fuzzy match if not provided

Griffin Westerman 1 سال پیش
والد
کامیت
811cdfd776
1فایلهای تغییر یافته به همراه8 افزوده شده و 3 حذف شده
  1. 8 3
      plugins/check_dig.c

+ 8 - 3
plugins/check_dig.c

@@ -57,6 +57,7 @@ char *dns_server = NULL;
 char *dig_args = "";
 char *dig_args = "";
 char *query_transport = "";
 char *query_transport = "";
 int verbose = FALSE;
 int verbose = FALSE;
+int exact = FALSE;
 int server_port = DEFAULT_PORT;
 int server_port = DEFAULT_PORT;
 int number_tries = DEFAULT_TRIES;
 int number_tries = DEFAULT_TRIES;
 double warning_interval = UNDEFINED;
 double warning_interval = UNDEFINED;
@@ -150,7 +151,7 @@ main (int argc, char **argv)
         }
         }
 
 
         t = tt; /* consider the right-side token, does it match ex? */
         t = tt; /* consider the right-side token, does it match ex? */
-        if ( (strcasestr( t, ex ) == t) && (strlen( t ) == strlen( ex )) ) {
+        if ( (!exact && strcasestr( t, ex)) || ((strcasestr( t, ex ) == t) && (strlen( t ) == strlen( ex ))) ) {
           result = STATE_OK;
           result = STATE_OK;
           msg = chld_out.line[i];
           msg = chld_out.line[i];
           break;
           break;
@@ -225,6 +226,7 @@ process_arguments (int argc, char **argv)
     {"verbose", no_argument, 0, 'v'},
     {"verbose", no_argument, 0, 'v'},
     {"version", no_argument, 0, 'V'},
     {"version", no_argument, 0, 'V'},
     {"help", no_argument, 0, 'h'},
     {"help", no_argument, 0, 'h'},
+    {"exact", no_argument, 0, 'e'},
     {"record_type", required_argument, 0, 'T'},
     {"record_type", required_argument, 0, 'T'},
     {"expected_address", required_argument, 0, 'a'},
     {"expected_address", required_argument, 0, 'a'},
     {"port", required_argument, 0, 'p'},
     {"port", required_argument, 0, 'p'},
@@ -237,7 +239,7 @@ process_arguments (int argc, char **argv)
     return ERROR;
     return ERROR;
 
 
   while (1) {
   while (1) {
-    c = getopt_long (argc, argv, "hVvt:l:H:w:c:T:p:a:A:46r:", longopts, &option);
+    c = getopt_long (argc, argv, "hVvt:l:H:w:c:T:p:a:A:46r:e", longopts, &option);
 
 
     if (c == -1 || c == EOF)
     if (c == -1 || c == EOF)
       break;
       break;
@@ -297,6 +299,9 @@ process_arguments (int argc, char **argv)
     case 'v':                 /* verbose */
     case 'v':                 /* verbose */
       verbose = TRUE;
       verbose = TRUE;
       break;
       break;
+    case 'e':
+      exact = TRUE;
+      break;
     case 'T':
     case 'T':
       record_type = optarg;
       record_type = optarg;
       break;
       break;
@@ -404,4 +409,4 @@ print_usage (void)
   printf ("%s -l <query_address> [-H <host>] [-p <server port>]\n", progname);
   printf ("%s -l <query_address> [-H <host>] [-p <server port>]\n", progname);
   printf (" [-T <query type>] [-w <warning interval>] [-c <critical interval>]\n");
   printf (" [-T <query type>] [-w <warning interval>] [-c <critical interval>]\n");
   printf (" [-t <timeout>] [-r <retries>] [-a <expected answer address>] [-v]\n");
   printf (" [-t <timeout>] [-r <retries>] [-a <expected answer address>] [-v]\n");
-}
+}