[Nagiosplug-devel] Patch for check_dns.c

Thiago Figueiro TFigueiro at au.westfield.com
Mon Nov 26 07:47:33 CET 2007


            Hi.  I use round-robin settings on my DNS, which renders the
"-a" (check address) option useless.  This is because you can't predict
the order in which the DNS will respond to your DNS queries.

 

            I've patched check_dns.c v 1.4.10 to include a "-o" option,
allowing you to sort the DNS response.  This way you always know what
order the response will come in.

 

            I'm attaching the patched file to this message and pasting
the diff on the message, below my sig.  Hope it helps other people.

 

Regards,

________________
 
 Thiago Figueiro
 Technical Operations Manager
 
 Digital Business
 T +61 9358 7123
 F +61 9358 7690
 W westfield.com
 E tfigueiro at au.westfield.com 

 

 

--- /tmp/nagios-plugins-1.4.10/plugins/check_dns.c      Mon Jan 29
08:46:41 2007

+++ check_dns.c Mon Nov 26 17:29:59 2007

@@ -62,6 +62,9 @@

 int expect_authority = FALSE;

 thresholds *time_thresholds = NULL;

 

+#define IPV4_SIZE 16*sizeof(char)

+int order_results = FALSE;

+

 int

 main (int argc, char **argv)

 {

@@ -178,6 +181,56 @@

          _("DNS CRITICAL - '%s' msg parsing exited with no address\n"),

          NSLOOKUP_COMMAND);

 

+  /* Order the results from DNS server */

+  if (order_results) {

+    int num_result = 1; /* No commas?  only one address */

+    int i = 0;

+    char *ipv4_sort = NULL;

+    char *pstrtmp;

+    char *pstrtok;

+

+    pstrtmp = strchr(address, ',');

+    while (pstrtmp) {

+      num_result++;

+      pstrtmp += sizeof(char);

+      pstrtmp = strchr(pstrtmp, ',');

+    }

+

+    if (num_result > 1) {

+      ipv4_sort = malloc(IPV4_SIZE*num_result);

+      if (NULL == ipv4_sort)

+      die (STATE_UNKNOWN,

+         _("DNS UNKNOWN - Failed allocating %d bytes for ordering
results\n"),

+         IPV4_SIZE*num_result);

+

+      memset(ipv4_sort, 0, IPV4_SIZE*num_result);

+      pstrtmp = strdup(address);

+      pstrtok = strtok(pstrtmp, ",");

+      i = 0;

+      while (pstrtok) {

+        strncpy(ipv4_sort+(i*IPV4_SIZE), pstrtok, IPV4_SIZE);

+        pstrtok = strtok(NULL, ",");

+        i++;

+      }

+      free(pstrtmp);

+

+      qsort(ipv4_sort, num_result, IPV4_SIZE, strcmp);

+

+      pstrtmp = address;

+      for (i = 0; i < num_result; i++) {

+        strcpy(pstrtmp, ipv4_sort+(i*IPV4_SIZE));

+        pstrtmp += (strlen(pstrtmp));

+        if (i+1 < num_result) {

+          *pstrtmp = ',';

+          pstrtmp += sizeof(char);

+        }

+        *pstrtmp = '\0';

+      }

+

+      free(ipv4_sort);

+    }

+  }

+

   /* compare to expected address */

   if (result == STATE_OK && match_expected_address && strcmp(address,
expected_address)) {

     result = STATE_CRITICAL;

@@ -316,7 +369,7 @@

       strcpy (argv[c], "-t");

 

   while (1) {

-    c = getopt_long (argc, argv, "hVvAt:H:s:r:a:w:c:", long_opts,
&opt_index);

+    c = getopt_long (argc, argv, "hVvAot:H:s:r:a:w:c:", long_opts,
&opt_index);

 

     if (c == -1 || c == EOF)

       break;

@@ -331,6 +384,9 @@

     case 'v': /* version */

       verbose = TRUE;

       break;

+    case 'o':

+      order_results = TRUE;

+    break;

     case 't': /* timeout period */

       timeout_interval = atoi (optarg);

       break;

@@ -431,6 +487,8 @@

   printf ("    %s\n", _("Optional IP-ADDRESS you expect the DNS server
to return. HOST must end with ."));

   printf (" -A, --expect-authority\n");

   printf ("    %s\n", _("Optionally expect the DNS server to be
authoritative for the lookup"));

+  printf (" -o\n");

+  printf ("    %s\n", _("Order the results from DNS server. Useful for
round-robind setups."));

   printf (" -w, --warning=seconds\n");

   printf ("    %s\n", _("Return warning if elapsed time exceeds value.
Default off"));

   printf (" -c, --critical=seconds\n");

 


______________________________________________________
    CONFIDENTIALITY NOTICE    
This electronic mail message, including any and/or all attachments, is for the sole use of the intended recipient(s), and may contain confidential and/or privileged information, pertaining to business conducted under the direction and supervision of the sending organization. All electronic mail messages, which may have been established as expressed views and/or opinions (stated either within the electronic mail message or any of its attachments), are left to the sole responsibility of that of the sender, and are not necessarily attributed to the sending organization. Unauthorized interception, review, use, disclosure or distribution of any such information contained within this electronic mail message and/or its attachment(s), is (are) strictly prohibited. If you are not the intended recipient, please contact the sender by replying to this electronic mail message, along with the destruction all copies of the original electronic mail message (along with any attachments).
______________________________________________________
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.monitoring-plugins.org/archive/devel/attachments/20071126/f048503c/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: check_dns.c
Type: application/octet-stream
Size: 16083 bytes
Desc: check_dns.c
URL: <https://www.monitoring-plugins.org/archive/devel/attachments/20071126/f048503c/attachment.obj>


More information about the Devel mailing list