summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Eble <psychotrahe@users.sourceforge.net>2008-01-05 01:06:36 +0000
committerMatthias Eble <psychotrahe@users.sourceforge.net>2008-01-05 01:06:36 +0000
commitf83981580eced39b10e096b8eb9a6c4e6434e772 (patch)
treeb477c9a54cacc6d5f631ab7ad4afdafe3a2f8473
parent446b89f8399d3cec3a53115c6197e9b87c24296a (diff)
downloadmonitoring-plugins-f83981580eced39b10e096b8eb9a6c4e6434e772.tar.gz
check_dns now sorts addresses for -a support with multiple address replies (Matthias Urlichs #1724052)
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1886 f882894a-f735-0410-b71e-b25c423dba1c
-rw-r--r--NEWS1
-rw-r--r--THANKS.in1
-rw-r--r--plugins/check_dns.c42
3 files changed, 36 insertions, 8 deletions
diff --git a/NEWS b/NEWS
index 8efceba1..485693af 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,7 @@ This file documents the major additions and syntax changes between releases.
4 Added ./check_nt -v INSTANCES to count number of instances (Alessandro Ren) 4 Added ./check_nt -v INSTANCES to count number of instances (Alessandro Ren)
5 check_tcp now returns UNKNOWN with invalid hostname 5 check_tcp now returns UNKNOWN with invalid hostname
6 New check_icmp -s option to specify the source IP address 6 New check_icmp -s option to specify the source IP address
7 check_dns now sorts addresses for testing results for more than one returned IP (Matthias Urlichs)
7 8
81.4.11 13th December 2007 91.4.11 13th December 2007
9 Fixed check_http regression in 1.4.10 where following redirects to 10 Fixed check_http regression in 1.4.10 where following redirects to
diff --git a/THANKS.in b/THANKS.in
index 36ae0b9f..abec771d 100644
--- a/THANKS.in
+++ b/THANKS.in
@@ -231,3 +231,4 @@ fabiodds
231Tom Payerle 231Tom Payerle
232Alessandro Ren 232Alessandro Ren
233Harald Jenny 233Harald Jenny
234Matthias Urlichs
diff --git a/plugins/check_dns.c b/plugins/check_dns.c
index 454f813b..8ae48cd4 100644
--- a/plugins/check_dns.c
+++ b/plugins/check_dns.c
@@ -62,12 +62,24 @@ int match_expected_address = FALSE;
62int expect_authority = FALSE; 62int expect_authority = FALSE;
63thresholds *time_thresholds = NULL; 63thresholds *time_thresholds = NULL;
64 64
65static int
66qstrcmp(const void *p1, const void *p2)
67{
68 /* The actual arguments to this function are "pointers to
69 pointers to char", but strcmp() arguments are "pointers
70 to char", hence the following cast plus dereference */
71 return strcmp(* (char * const *) p1, * (char * const *) p2);
72}
73
74
65int 75int
66main (int argc, char **argv) 76main (int argc, char **argv)
67{ 77{
68 char *command_line = NULL; 78 char *command_line = NULL;
69 char input_buffer[MAX_INPUT_BUFFER]; 79 char input_buffer[MAX_INPUT_BUFFER];
70 char *address = NULL; 80 char *address = NULL;
81 char **addresses = NULL;
82 int n_addresses = 0;
71 char *msg = NULL; 83 char *msg = NULL;
72 char *temp_buffer = NULL; 84 char *temp_buffer = NULL;
73 int non_authoritative = FALSE; 85 int non_authoritative = FALSE;
@@ -141,16 +153,17 @@ main (int argc, char **argv)
141 NSLOOKUP_COMMAND); 153 NSLOOKUP_COMMAND);
142 } 154 }
143 155
144 if (address == NULL) 156 if (addresses == NULL)
145 address = strdup (temp_buffer); 157 addresses = malloc(sizeof(*addresses)*10);
146 else 158 else if (!(n_addresses % 10))
147 asprintf(&address, "%s,%s", address, temp_buffer); 159 addresses = realloc(addresses,sizeof(*addresses) * (n_addresses + 10));
160 addresses[n_addresses++] = strdup(temp_buffer);
148 } 161 }
149
150 else if (strstr (chld_out.line[i], _("Non-authoritative answer:"))) { 162 else if (strstr (chld_out.line[i], _("Non-authoritative answer:"))) {
151 non_authoritative = TRUE; 163 non_authoritative = TRUE;
152 } 164 }
153 165
166
154 result = error_scan (chld_out.line[i]); 167 result = error_scan (chld_out.line[i]);
155 if (result != STATE_OK) { 168 if (result != STATE_OK) {
156 msg = strchr (chld_out.line[i], ':'); 169 msg = strchr (chld_out.line[i], ':');
@@ -171,9 +184,21 @@ main (int argc, char **argv)
171 } 184 }
172 } 185 }
173 186
174 /* If we got here, we should have an address string, 187 if (addresses) {
175 * and we can segfault if we do not */ 188 int i,slen;
176 if (address==NULL || strlen(address)==0) 189 char *adrp;
190 qsort(addresses, n_addresses, sizeof(*addresses), qstrcmp);
191 for(i=0, slen=1; i < n_addresses; i++) {
192 slen += strlen(addresses[i])+1;
193 }
194 adrp = address = malloc(slen);
195 for(i=0; i < n_addresses; i++) {
196 if (i) *adrp++ = ',';
197 strcpy(adrp, addresses[i]);
198 adrp += strlen(addresses[i]);
199 }
200 *adrp = 0;
201 } else
177 die (STATE_CRITICAL, 202 die (STATE_CRITICAL,
178 _("DNS CRITICAL - '%s' msg parsing exited with no address\n"), 203 _("DNS CRITICAL - '%s' msg parsing exited with no address\n"),
179 NSLOOKUP_COMMAND); 204 NSLOOKUP_COMMAND);
@@ -429,6 +454,7 @@ print_help (void)
429 printf (" %s\n", _("Optional DNS server you want to use for the lookup")); 454 printf (" %s\n", _("Optional DNS server you want to use for the lookup"));
430 printf (" -a, --expected-address=IP-ADDRESS|HOST\n"); 455 printf (" -a, --expected-address=IP-ADDRESS|HOST\n");
431 printf (" %s\n", _("Optional IP-ADDRESS you expect the DNS server to return. HOST must end with .")); 456 printf (" %s\n", _("Optional IP-ADDRESS you expect the DNS server to return. HOST must end with ."));
457 printf (" %s\n", _("Multiple addresses can be separated with commas, and need to be sorted."));
432 printf (" -A, --expect-authority\n"); 458 printf (" -A, --expect-authority\n");
433 printf (" %s\n", _("Optionally expect the DNS server to be authoritative for the lookup")); 459 printf (" %s\n", _("Optionally expect the DNS server to be authoritative for the lookup"));
434 printf (" -w, --warning=seconds\n"); 460 printf (" -w, --warning=seconds\n");