Bläddra i källkod

Merge pull request #777 from nagios-plugins/767-check_dig-exact-match

check_dig Exact Match
Sebastian Wolf 1 år sedan
förälder
incheckning
cbc30d099c
2 ändrade filer med 14 tillägg och 3 borttagningar
  1. 4 0
      NEWS
  2. 10 3
      plugins/check_dig.c

+ 4 - 0
NEWS

@@ -7,6 +7,10 @@ This file documents the major additions and syntax changes between releases.
 	TESTS
 	Update majority of the test suite to working condition
 
+2.4.10 2024-XX-XX
+	FIXES
+	check_dig: Fixed issue where exact matching broke backwards compatability, and added new option to enforce exact matching (#777)
+
 2.4.9 2024-03-21
 	FIXES
 	check_snmp: Robustly fixes incorrect integer return value parsing (#749)

+ 10 - 3
plugins/check_dig.c

@@ -57,6 +57,7 @@ char *dns_server = NULL;
 char *dig_args = "";
 char *query_transport = "";
 int verbose = FALSE;
+int exact = FALSE;
 int server_port = DEFAULT_PORT;
 int number_tries = DEFAULT_TRIES;
 double warning_interval = UNDEFINED;
@@ -150,7 +151,7 @@ main (int argc, char **argv)
         }
 
         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 )) || (strcmp( t, ex ) == 0) ) {
           result = STATE_OK;
           msg = chld_out.line[i];
           break;
@@ -225,6 +226,7 @@ process_arguments (int argc, char **argv)
     {"verbose", no_argument, 0, 'v'},
     {"version", no_argument, 0, 'V'},
     {"help", no_argument, 0, 'h'},
+    {"exact", no_argument, 0, 'e'},
     {"record_type", required_argument, 0, 'T'},
     {"expected_address", required_argument, 0, 'a'},
     {"port", required_argument, 0, 'p'},
@@ -237,7 +239,7 @@ process_arguments (int argc, char **argv)
     return ERROR;
 
   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)
       break;
@@ -297,6 +299,9 @@ process_arguments (int argc, char **argv)
     case 'v':                 /* verbose */
       verbose = TRUE;
       break;
+    case 'e':
+      exact = TRUE;
+      break;
     case 'T':
       record_type = optarg;
       break;
@@ -383,6 +388,8 @@ print_help (void)
   printf ("    %s\n",_("Pass STRING as argument(s) to dig"));
   printf (" %s\n","-r, --retries=INTEGER");
   printf ("    %s\n",_("Number of retries passed to dig, timeout is divided by this value (Default: 3)"));
+  printf (" %s\n","-e, --exact");
+  printf ("    %s\n",_("Match records exactly. If not set, fuzzy matches."));
   printf (UT_WARN_CRIT);
   printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
   printf (UT_VERBOSE);
@@ -404,4 +411,4 @@ print_usage (void)
   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 <timeout>] [-r <retries>] [-a <expected answer address>] [-v]\n");
-}
+}