[Nagiosplug-checkins] SF.net SVN: nagiosplug: [1886] nagiosplug/trunk

psychotrahe at users.sourceforge.net psychotrahe at users.sourceforge.net
Sat Jan 5 02:06:37 CET 2008


Revision: 1886
          http://nagiosplug.svn.sourceforge.net/nagiosplug/?rev=1886&view=rev
Author:   psychotrahe
Date:     2008-01-04 17:06:36 -0800 (Fri, 04 Jan 2008)

Log Message:
-----------
check_dns now sorts addresses for -a support with multiple address replies (Matthias Urlichs #1724052)

Modified Paths:
--------------
    nagiosplug/trunk/NEWS
    nagiosplug/trunk/THANKS.in
    nagiosplug/trunk/plugins/check_dns.c

Modified: nagiosplug/trunk/NEWS
===================================================================
--- nagiosplug/trunk/NEWS	2008-01-04 22:10:37 UTC (rev 1885)
+++ nagiosplug/trunk/NEWS	2008-01-05 01:06:36 UTC (rev 1886)
@@ -4,6 +4,7 @@
 	Added ./check_nt -v INSTANCES to count number of instances (Alessandro Ren)
 	check_tcp now returns UNKNOWN with invalid hostname
 	New check_icmp -s option to specify the source IP address
+	check_dns now sorts addresses for testing results for more than one returned IP (Matthias Urlichs)
 
 1.4.11 13th December 2007
 	Fixed check_http regression in 1.4.10 where following redirects to

Modified: nagiosplug/trunk/THANKS.in
===================================================================
--- nagiosplug/trunk/THANKS.in	2008-01-04 22:10:37 UTC (rev 1885)
+++ nagiosplug/trunk/THANKS.in	2008-01-05 01:06:36 UTC (rev 1886)
@@ -231,3 +231,4 @@
 Tom Payerle
 Alessandro Ren
 Harald Jenny
+Matthias Urlichs

Modified: nagiosplug/trunk/plugins/check_dns.c
===================================================================
--- nagiosplug/trunk/plugins/check_dns.c	2008-01-04 22:10:37 UTC (rev 1885)
+++ nagiosplug/trunk/plugins/check_dns.c	2008-01-05 01:06:36 UTC (rev 1886)
@@ -62,12 +62,24 @@
 int expect_authority = FALSE;
 thresholds *time_thresholds = NULL;
 
+static int
+qstrcmp(const void *p1, const void *p2)
+{
+	/* The actual arguments to this function are "pointers to
+	   pointers to char", but strcmp() arguments are "pointers
+	   to char", hence the following cast plus dereference */
+	return strcmp(* (char * const *) p1, * (char * const *) p2);
+}
+
+
 int
 main (int argc, char **argv)
 {
   char *command_line = NULL;
   char input_buffer[MAX_INPUT_BUFFER];
   char *address = NULL;
+  char **addresses = NULL;
+  int n_addresses = 0;
   char *msg = NULL;
   char *temp_buffer = NULL;
   int non_authoritative = FALSE;
@@ -141,16 +153,17 @@
              NSLOOKUP_COMMAND);
       }
 
-      if (address == NULL)
-        address = strdup (temp_buffer);
-      else
-        asprintf(&address, "%s,%s", address, temp_buffer);
+      if (addresses == NULL) 
+	addresses = malloc(sizeof(*addresses)*10);
+      else if (!(n_addresses % 10))
+	addresses = realloc(addresses,sizeof(*addresses) * (n_addresses + 10));
+      addresses[n_addresses++] = strdup(temp_buffer);
     }
-
     else if (strstr (chld_out.line[i], _("Non-authoritative answer:"))) {
       non_authoritative = TRUE;
     }
 
+
     result = error_scan (chld_out.line[i]);
     if (result != STATE_OK) {
       msg = strchr (chld_out.line[i], ':');
@@ -171,9 +184,21 @@
     }
   }
 
-  /* If we got here, we should have an address string,
-   * and we can segfault if we do not */
-  if (address==NULL || strlen(address)==0)
+  if (addresses) {
+    int i,slen;
+    char *adrp;
+    qsort(addresses, n_addresses, sizeof(*addresses), qstrcmp);
+    for(i=0, slen=1; i < n_addresses; i++) {
+      slen += strlen(addresses[i])+1;
+    }
+    adrp = address = malloc(slen);
+    for(i=0; i < n_addresses; i++) {
+      if (i) *adrp++ = ',';
+      strcpy(adrp, addresses[i]);
+      adrp += strlen(addresses[i]);
+    }
+    *adrp = 0;
+  } else
     die (STATE_CRITICAL,
          _("DNS CRITICAL - '%s' msg parsing exited with no address\n"),
          NSLOOKUP_COMMAND);
@@ -429,6 +454,7 @@
   printf ("    %s\n", _("Optional DNS server you want to use for the lookup"));
   printf (" -a, --expected-address=IP-ADDRESS|HOST\n");
   printf ("    %s\n", _("Optional IP-ADDRESS you expect the DNS server to return. HOST must end with ."));
+  printf ("    %s\n", _("Multiple addresses can be separated with commas, and need to be sorted."));
   printf (" -A, --expect-authority\n");
   printf ("    %s\n", _("Optionally expect the DNS server to be authoritative for the lookup"));
   printf (" -w, --warning=seconds\n");


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Commits mailing list